Alluo Explained
Search
K

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
1
/** @dev See {IERC4626-withdraw}. */
2
/// Standard ERC4626 withdraw function but distributes rewards before withdraw
3
// and unstakes from the alluoPool in order to meet collateral commitments
4
function withdraw(
5
uint256 assets,
6
address receiver,
7
address owner
8
) public virtual override returns (uint256) {
9
_distributeReward(_msgSender());
10
require(assets <= maxWithdraw(owner), "ERC4626: withdraw more than max");
11
_unstakeForWithdraw(assets);
12
uint256 shares = previewWithdraw(assets);
13
_withdraw(_msgSender(), receiver, owner, assets, shares);
14
15
return shares;
16
}
17
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. 1.
    Withdraw LP tokens by burning shares in the vault
  2. 2.
    Swap the LP tokens into the exitToken and send this to the user.
AlluoStEthEthVault.sol
1
/// @notice Allows withdrawals in any ERC20 token supported by the Alluo Exchange
2
/// @dev
3
/// @param assets Amount of vault shares to burn
4
/// @param receiver Recipient of the tokens
5
/// @param owner Standrad ERC4626 owner
6
/// @param exitToken Token that you want to receive by burning shares in the vault and the Lp token
7
/// @return uint256 amount of exitToken assets received
8
function withdrawToNonLp(
9
uint256 assets,
10
address receiver,
11
address owner,
12
address exitToken
13
) public returns (uint256) {
14
_distributeReward(_msgSender());
15
require(assets <= maxWithdraw(owner), "ERC4626: withdraw more than max");
16
_unstakeForWithdraw(assets);
17
uint256 shares = previewWithdraw(assets);
18
if (_msgSender() != owner) {
19
_spendAllowance(owner, _msgSender(), shares);
20
}
21
_burn(owner, shares);
22
IERC20MetadataUpgradeable(asset()).safeIncreaseAllowance(address(exchange), shares);
23
shares = exchange.exchange(asset(), exitToken, shares,0);
24
IERC20MetadataUpgradeable(exitToken).safeTransfer(receiver, shares);
25
return shares;
26
}