Withdraw from the Vault

Here we only cover how to withdraw the initial principal deposited into the Vault. For withdrawing any yield generated by the principal, read the Reward System.

There are two ways you can withdraw your principal:

1. Withdraw the underlying LP token

You can either use the standard ERC4626 Withdraw or Redeem functions.

Here, the Vault distributes rewards first to ensure correct distribution of rewards, unstakes LP tokens to meet the withdrawal and sends the tokens to the user.

Alluo Vault
/** @dev See {IERC4626-withdraw}. */
/// Standard ERC4626 withdraw function but distributes rewards before withdraw
//  and unstakes from the alluoPool in order to meet collateral commitments
function withdraw(
    uint256 assets,
    address receiver,
    address owner
) public virtual override returns (uint256) {
    _distributeReward(_msgSender());
    require(assets <= maxWithdraw(owner), "ERC4626: withdraw more than max");
    _unstakeForWithdraw(assets);
    uint256 shares = previewWithdraw(assets);
    _withdraw(_msgSender(), receiver, owner, assets, shares);

    return shares;
}

Withdraw is withdrawing an exact amount of underlying LP tokens by burning shares in the vault Redeem is withdrawing a number of underlying LP tokens dictated by the exact amount of shares burnt by the user.

2. Withdraw in non LP tokens:

You can use the function below to burn an arbitrary amount of shares to receive an exact amount of LP tokens. Then these LP tokens are swapped through into the exitToken and sent to the receiver.

For this specific StEth-Eth example, there are extra steps to be compatible with native ETH but all Vaults follow this fundamental logic when withdrawing ERC20 tokens that are not the underlying LP token

  1. Withdraw LP tokens by burning shares in the vault

  2. Swap the LP tokens into the exitToken and send this to the user.

AlluoStEthEthVault.sol
 /// @notice Allows withdrawals in any ERC20 token supported by the Alluo Exchange
/// @dev 
/// @param assets  Amount of vault shares to burn
/// @param receiver Recipient of the tokens
/// @param owner Standrad ERC4626 owner 
/// @param exitToken Token that you want to receive by burning shares in the vault and the Lp token
/// @return uint256 amount of exitToken assets received
function withdrawToNonLp(
    uint256 assets,
    address receiver,
    address owner,
    address exitToken
) public returns (uint256) {
    _distributeReward(_msgSender());
    require(assets <= maxWithdraw(owner), "ERC4626: withdraw more than max");
    _unstakeForWithdraw(assets);
    uint256 shares = previewWithdraw(assets);
    if (_msgSender() != owner) {
        _spendAllowance(owner, _msgSender(), shares);
    }
    _burn(owner, shares);
    IERC20MetadataUpgradeable(asset()).safeIncreaseAllowance(address(exchange), shares);
    shares = exchange.exchange(asset(), exitToken, shares,0);
    IERC20MetadataUpgradeable(exitToken).safeTransfer(receiver, shares);
    return shares;
}

Last updated