Withdraw

With this function, the user can redeem its funds plus the yield that has been accumulated. The user will need to call the function, send the LP tokens it has and receive the funds it is entitled to. Because most funds are locked up in different protocols on different chains and layer 2s a full withdrawal is not always possible immediately. There is a parameter liquidityPerc controlled by the DAO which reserves a percentage of all underlying funds on a particular chain/ layer 2 (apart from earlier deposits during the same period) to make immediate withdrawals possible. There are 2 scenarios:

  1. The full amount the user wants to withdraw is available in the vault due to earlier deposits or the liquidityPerc.

  2. The full amount is not available on the chain/ layer 2 the user wants to perform the withdraw.

In scenario 1 the user can withdraw its funds by calling the following function in one of our deployed vaults:

function withdraw(uint256 _amount) external nonReentrant returns(uint256 value)

Where _amount is the amount of LP tokens in the correct scale (always the same scale as the underlying vault currency scale, 10^6 in the case of the USDC vault).

In the 2nd scenario, the user can make a withdrawalRequest. In this case the user sends the LP tokens and gets an allowance which can be withdrawn after the next rebalance. To do this the user has to call the function in one of our deployed vaults:

function withdrawalRequest(uint256 _amount) external nonReentrant returns(uint256 value)

Where _amount is the amount of LP tokens in the correct scale (always the same scale as the underlying vault currency scale, 10^6 in the case of the USDC vault). After rebalancing the user can call the following function to withdraw its funds:

function withdrawAllowance() external nonReentrant returns(uint256 value)

The value the user receives depends on the exchangeRate and is calculated accordingly:

value = _amount * exchangeRate / LPScale;

Where the exchangeRate is expressed in underlying/ LPtoken in the scale of the underlying vault currency and LPScale is the amount of decimals of the LP token in the same scale (10^6).

The exchangeRate is calculated based on the exposures on all the underlyings on all the different chains and layer 2s. Therefore, it's not feasible to calculate the actual exchangeRate every time a withdrawal is made. Instead, the exchangeRate is calculated and stored during rebalancing and the last known exchangeRate is used during withdrawal.

Last updated