Vault

Vault

  • Responsible for following actions on USDs:

    • Mint USDs token

    • Redeem USDs token

    • Carry out rebase for USDs token

    • Allocate collateral to strategies

    • Withdraw collateral from strategies ?

Contract documentation

Git Source

Inherits: Initializable, OwnableUpgradeable, ReentrancyGuardUpgradeable

Author: Sperax Foundation

This contract enables users to mint and redeem USDs with allowed collaterals.

It also allocates collateral to strategies based on the Collateral Manager contract.

State Variables

feeVault

address public feeVault;

yieldReceiver

address public yieldReceiver;

collateralManager

address public collateralManager;

feeCalculator

address public feeCalculator;

oracle

address public oracle;

rebaseManager

address public rebaseManager;

Functions

constructor

constructor();

initialize

function initialize() external initializer;

updateFeeVault

Updates the address receiving fee.

function updateFeeVault(address _feeVault) external onlyOwner;

Parameters

updateYieldReceiver

Updates the address receiving yields from strategies.

function updateYieldReceiver(address _yieldReceiver) external onlyOwner;

Parameters

updateCollateralManager

Updates the address having the configuration for collaterals.

function updateCollateralManager(address _collateralManager) external onlyOwner;

Parameters

updateRebaseManager

Updates the address having the configuration for rebases.

function updateRebaseManager(address _rebaseManager) external onlyOwner;

Parameters

updateFeeCalculator

Updates the fee calculator library.

function updateFeeCalculator(address _feeCalculator) external onlyOwner;

Parameters

updateOracle

Updates the price oracle address.

function updateOracle(address _oracle) external onlyOwner;

Parameters

allocate

Allocates _amount of _collateral to _strategy.

function allocate(address _collateral, address _strategy, uint256 _amount) external nonReentrant;

Parameters

mint

Mint USDs by depositing collateral.

function mint(address _collateral, uint256 _collateralAmt, uint256 _minUSDSAmt, uint256 _deadline)
    external
    nonReentrant;

Parameters

mintBySpecifyingCollateralAmt

Mint USDs by depositing collateral (backward compatibility).

This function is for backward compatibility.

function mintBySpecifyingCollateralAmt(
    address _collateral,
    uint256 _collateralAmt,
    uint256 _minUSDSAmt,
    uint256,
    uint256 _deadline
) external nonReentrant;

Parameters

redeem

Redeem USDs for _collateral.

In case where there is not sufficient collateral available in the vault, the collateral is withdrawn from the default strategy configured for the collateral.

function redeem(address _collateral, uint256 _usdsAmt, uint256 _minCollAmt, uint256 _deadline) external nonReentrant;

Parameters

redeem

Redeem USDs for _collateral from a specific strategy.

function redeem(address _collateral, uint256 _usdsAmt, uint256 _minCollAmt, uint256 _deadline, address _strategy)
    external
    nonReentrant;

Parameters

redeemView

Get the expected redeem result.

function redeemView(address _collateral, uint256 _usdsAmt)
    external
    view
    returns (
        uint256 calculatedCollateralAmt,
        uint256 usdsBurnAmt,
        uint256 feeAmt,
        uint256 vaultAmt,
        uint256 strategyAmt
    );

Parameters

Returns

redeemView

Get the expected redeem result from a specific strategy.

function redeemView(address _collateral, uint256 _usdsAmt, address _strategyAddr)
    external
    view
    returns (
        uint256 calculatedCollateralAmt,
        uint256 usdsBurnAmt,
        uint256 feeAmt,
        uint256 vaultAmt,
        uint256 strategyAmt
    );

Parameters

Returns

rebase

Rebase USDs to share earned yield with the USDs holders.

If Rebase manager returns a non-zero value, it calls the rebase function on the USDs contract.

function rebase() public;

mintView

Get the expected mint result (USDs amount, fee).

function mintView(address _collateral, uint256 _collateralAmt) public view returns (uint256, uint256);

Parameters

Returns

_mint

Mint USDs by depositing collateral.

Mints USDs by locking collateral based on user input, ensuring a minimum expected minted amount is met.

If the minimum expected amount is not met, the transaction will revert.

Fee is collected, and collateral is transferred accordingly.

A rebase operation is triggered after minting.

function _mint(address _collateral, uint256 _collateralAmt, uint256 _minUSDSAmt, uint256 _deadline) private;

Parameters

_redeem

Redeem USDs for collateral.

Redeems USDs for collateral, ensuring a minimum expected collateral amount is met.

If the minimum expected collateral amount is not met, the transaction will revert.

Fee is collected, collateral is transferred, and a rebase operation is triggered.

function _redeem(
    address _collateral,
    uint256 _usdsAmt,
    uint256 _minCollateralAmt,
    uint256 _deadline,
    address _strategyAddr
) private;

Parameters

_redeemView

Get the expected redeem result.

Calculates the expected results of a redemption, including collateral amount, fees, and strategy-specific details.

Ensures that the redemption is allowed for the specified collateral.

Calculates fees, burn amounts, and collateral amounts based on prices and conversion factors.

Determines if collateral needs to be withdrawn from a strategy, and if so, checks the availability of collateral in the strategy.

function _redeemView(address _collateral, uint256 _usdsAmt, address _strategyAddr)
    private
    view
    returns (
        uint256 calculatedCollateralAmt,
        uint256 usdsBurnAmt,
        uint256 feeAmt,
        uint256 vaultAmt,
        uint256 strategyAmt,
        IStrategy strategy
    );

Parameters

Returns

Events

FeeVaultUpdated

event FeeVaultUpdated(address newFeeVault);

YieldReceiverUpdated

event YieldReceiverUpdated(address newYieldReceiver);

CollateralManagerUpdated

event CollateralManagerUpdated(address newCollateralManager);

FeeCalculatorUpdated

event FeeCalculatorUpdated(address newFeeCalculator);

RebaseManagerUpdated

event RebaseManagerUpdated(address newRebaseManager);

OracleUpdated

event OracleUpdated(address newOracle);

Minted

event Minted(
    address indexed wallet, address indexed collateralAddr, uint256 usdsAmt, uint256 collateralAmt, uint256 feeAmt
);

Redeemed

event Redeemed(
    address indexed wallet, address indexed collateralAddr, uint256 usdsAmt, uint256 collateralAmt, uint256 feeAmt
);

RebasedUSDs

event RebasedUSDs(uint256 rebaseAmt);

Allocated

event Allocated(address indexed collateral, address indexed strategy, uint256 amount);

Errors

AllocationNotAllowed

error AllocationNotAllowed(address collateral, address strategy, uint256 amount);

RedemptionPausedForCollateral

error RedemptionPausedForCollateral(address collateral);

InsufficientCollateral

error InsufficientCollateral(address collateral, address strategy, uint256 amount, uint256 availableAmount);

InvalidStrategy

error InvalidStrategy(address _collateral, address _strategyAddr);

MintFailed

error MintFailed();