Alluo Explained
  • Welcome
    • 🧭 The Basics
  • Getting Started
    • πŸ’» The DeFi Web App
      • ❓ Connecting to the app
      • 🚜 Depositing into the farms
      • πŸ™Œ Other basics
      • 🏦 Importing your Mobile app wallet to Metamask
      • 🧬 Add the polygon network manually in Metamask.
      • ⛓️ Bridging Stablecoins from another chain
    • πŸ“±The Mobile app
      • πŸ—οΈ Setting up your account
      • 🏦 Depositing money into the app
      • πŸ™Œ Other basics
      • πŸ” Exporting your private key
    • πŸ“–Tech deep dive: Contract Address Library
  • Understanding Alluo
    • πŸ’΅ How does Alluo get the yield?
      • 🐰 Going deeper into the Alluo protocol rabbit hole
    • 🧐 FAQ
  • Tokens & Tokenomics
    • πŸͺ™ The tokens
    • πŸ‘¨β€πŸ”¬Tech deep dive: Interest Bearing {asset} token
      • Depositing
      • Withdrawals
      • IbAlluo on different chains
      • StIbAlluo and Superfluid
        • A closer look at the integration between IbAlluo and StIbAlluo
      • Using the IbAlluo contract directly to create streams
      • Liquidity Handler and adapters
        • Deposit process with the Liquidity Handler
        • Withdraw process with the Liquidity Handler
    • πŸ“ˆ Tokenomics
    • πŸ‘¨β€πŸ”¬Tech deep dive: Boosting yield by compounding rewards
      • Deposit into the Vault
      • Withdraw from the Vault
      • Redeem rewards
      • Automatic boosting with Alluo
      • FraxConvex Vaults
      • Managing withdrawal requests in IERC4626
  • Decentralisation and Trust
    • πŸ—³οΈ Trustless governance and execution
    • πŸ‘¨β€πŸ”¬Tech deep dive: Vote Executor Architecture
      • Off chain votes to on chain data
      • Onchain data verifcation
      • Automated execution of votes
        • Tokenomics
        • Liquidity Direction
        • Setting APYs on farms
      • Cross chain execution of votes
      • Manually submitting vote results onchain
    • ↔️Alluo Exchange
      • Interacting with the Exchange
    • vlAlluo Architecture
    • Contracts upgrades
    • Investment strategies
      • πŸ“ˆFrax Convex Finance
        • Adding new pools into the strategy
        • Investing into a pool
  • More Advanced Features
    • πŸ” Repeat payments, streaming IbAlluo
  • Product Updates
    • πŸ‘Œ Product Roadmap: Building the right products
    • πŸ’» Web App releases
    • πŸ“± Mobile App releases
    • 🏎️ Alluo Boost
  • tutorial projects
    • Example: USDC to streaming 1 IbAlluo per second
    • Example: Using IbAlluoUSD and Ricochet to do capital efficient DCA into ETH
Powered by GitBook
On this page
  1. Tokens & Tokenomics
  2. Tech deep dive: Boosting yield by compounding rewards

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;
}
PreviousDeposit into the VaultNextRedeem rewards

Last updated 2 years ago

πŸ‘¨β€πŸ”¬