Smart Contract Architecture of Levva Vaults
Lear how Smart Contract Architecture of Levva Vault is working.
Last updated
Lear how Smart Contract Architecture of Levva Vault is working.
Last updated
The Levva Vault Smart Contract Architecture architecture consists of three smart contracts:
Vault
ConfigManager
LendingProtocolAdapter (Levva, Aave, EtherFi, Morpho and etc.).
The Vault is an upgradeable smart contract compatible with the ERC-4626 “Tokenized Vault” standard. It references ConfigManager, and lending protocol adapters can be connected to the smart contract. (Currently, there are three adapters implemented for the Levva, Aave, EtherFi protocols.) The vault smart contract invests users' funds in lending protocols via functions implemented in adapter contracts.
User: The end user or smart contract; has access to deposit and withdrawal functions.
AVS: Has access to invest users' funds into lending protocols connected to the vault and to withdraw previously invested funds from these protocols.
Governance: A service role with functions available for contract upgrades, adding lending protocol adapters, and assigning AVS.
All user deposits in the vault are categorized as "free" or "invested" (invested in a lending protocol for profit). The current investment strategy specifies that 10% of all tokens remain free, while the rest are invested in lending protocols.
Deposit/Mint: The user calls the deposit function, agreeing to transfer (following an ERC-20.approve call) an ERC-20 token matching the vault token to the vault smart contract and receiving in exchange an ERC-20 shares token. Upon deposit, the current shares token price is calculated. After deposit, the user's funds remain in the “free” pool (ready for investment or instant withdrawal).
Withdraw/Redeem: The user calls the withdrawal function to exchange their ERC-20 share tokens for vault ERC-20 tokens. Before exchange, the current share token price is calculated. The user can successfully complete the transaction only if there are sufficient “free” funds available for the exchange.
RequestWithdraw: Allows users to request a token withdrawal if there aren’t enough “free” funds available. This function accepts the number of share tokens to be exchanged for the vault token. The request initiates the withdrawal of invested tokens from lending protocols and locks the user’s shares until the exchange is complete.
ExecuteProtocolAction: A function available to the AVS role, which accepts an array of actions and the type of protocol (deposits, withdrawals, withdrawal requests) that the smart contract should perform.
The ConfigManager is an upgradeable smart contract that stores settings for lending protocol adapters for each vault. One ConfigManager contract serves multiple vaults.
Governance: Changes adapter settings, adds/removes Levva pools.
A non-upgradeable smart contract without internal state storage, the adapter implements functions for depositing/withdrawing funds into/from lending protocols(Levva, Aave, and EtherFi) and querying the current balance, including accumulated interest.