Vault Intro
stETH Vault Description
Overview
steth vault is a decentralized ETH leveraged pledge strategy pool. Users can deposit ETH, STETH, and WSETH into the vault to obtain share tokens. The funds in the vault are determined by the cian platform to be allocated to decentralized lending agreements such as AAVE, COMPOUND, and MORPHO, and the leverage strategy of lending ETH to exchange for more STETH increases the holdings of STETH. As time increases, share tokens will be able to redeem more STETH from the vault, thereby realizing user profitability.
Contract overview
Due to the large amount of logic in the vault strategy, a single contract is not enough to meet the required code capacity, so the logic is divided into different functional modules in a way similar to diamond agents. When the strategy contract is called, it will delegate call to different module contracts according to different situations.
The empty contract of the Diamond Proxy integrates the abi of all methods called externally by the strategy, and is compatible with the block browser verification of the EIP-1967 Transparent Proxy contract. When actually calling, it will delegatecall to the corresponding module contract.
The management function module of the strategy contract, including the logic of initializing strategy parameters, adjusting strategy parameters, and appointing a rebalancer.
The leverage function module of the strategy contract includes the functions of adjusting position leverage and deleveraging withdrawal from the strategy leverage pool.
The position migration function module of the strategy contract includes the function of migrating deposits and loans in one lending agreement to another lending agreement at one time.
The user fund entry and exit function module of the strategy contract, the deposit and withdrawal logic of user funds.
The reading function module of the strategy contract is used to read various parameters and position status of the strategy.
Since the abi of each lending agreement is too different, the abi call is unified by writing independent logic that interacts with the lending agreement, and LendingLogic is designed as a replaceable contract to facilitate functional upgrades.
Currently, the most widely used flash loans on the Ethereum mainnet are balancer and aave. Balancer has no flash loan fee, so we will give priority to using it. However, in some cases, there will be a need to complete 1inch exchange and flash loan at the same time in one transaction. If there is a balancer protocol path in the exchange and the balancer flash loan is also used, it will be rejected by the balancer as a reentrant call. Therefore, when a transaction needs to be exchanged with a balancer, the transaction must not use the balancer flash loan. At this time, you can only choose to use aave. The flash loan abi interface of aave and balancer is very different. For the flexibility of contract interaction, FlashloanHelper is used as the transfer contract of flash loan, and the flash loan of which protocol to use is determined by selecting the id.
The entity of the strategy contract, the contract for asset storage and management, when this contract is called, the call logic will delegatecall to each logic contract module.
The implementation logic of the vault contract uses the erc4626 standard.
Entities of the vault contract, use EIP-1967 Transparent Proxy fallback to VaultImplementation.sol In , the user's assets enter and exit through this contract. Provides the function of depositing assets to obtain share tokens and burning share tokens to obtain assets.
Manages upgrades of the Vault.sol contract.
Since the core asset of this vault is STETH, when users need to use other assets to deposit, they need to convert it to STETH first, and the same goes for withdrawing. This contract provides the function of converting ETH, WETH, WSTETH into STETH and depositing them into the vault, and can also be withdrawn as required assets.
Core contract
###Strategy
The management function module of the strategy contract.
initialize
Initialize the performance fee rate, the aggregated steth and debt eth ratio, the mortgage ratio of each lending agreement, the address of the rebalancing executor, the flashloanHelper address, the lendingLogic address, and the address of the performance fee payee.
enterProtocol
Allows interaction with a lending protocol
exitProtocol
Disable interaction with a lending protocol
####setVault
Set the client share management contract of the policy pool
updateFeeReceiver
Update Performance Fee Payee Address
updateLendingLogic
Update the interaction logic of the lending agreement
updateFlashloanHelper
Update flash loan transfer contract
updateRebalancer
Update the address or status of the resizer
updateSafeAggregatedRatio
Update aggregated collateral ratios
updateSafeProtocolRatio
Update the target mortgage rate corresponding to the lending agreement
collectRevenue
Extract the performance fee from the strategy pool
The leverage management function module of the strategy contract.
leverage
Increase the position in the lending agreement, which can be added collateral or increased leverage or both.
deleverage
Reducing a position in a lending agreement can be by reducing collateral or reducing leverage or both.
####deleverageAndWithdraw
The deleveraging method withdraws funds from the lending agreement to the user, and maintains the collateral ratio basically unchanged after completion.
getDeleverageAmount
The amount of WETH that is flash loaned is required to obtain the deleveraging operation.
migrate
Transfer a position from one lending agreement to another.
deposit
The assets of the vault contract enter the policy management contract, which is called when the user deposits assets.
withdraw
The assets of the policy management contract are entered into the vault contract, which is called when the user withdraws the assets.
Contains the basic logic of the strategy contract.
lendingLogic
Interaction Logic Contract of Lending Protocol
flashloanHelper
Intermediary contracts for flash loans
executor
Flash loan anti-re-entry sign
exchangePrice
Strike Prices for Depositing and Withdrawing Assets
executeLendingLogic
Call the delegatecall of the lending protocol interaction to the LendingLogic contract.
updateExchangePrice
Update the exercise price when users perform asset deposits and withdrawals. The exercise price is used to complete the exchange of core assets and share tokens.
getAvailableBorrowsETH
Obtain how much ETH can be lent in a loan agreement without exceeding the ltv. If it is less than this amount, you can avoid using flash loans in the operation to cause additional expenses.
getAvailableWithdrawsStETH
Obtain how much STETH can be withdrawn under the condition that the ltv is not exceeded in a certain loan agreement. If it is less than this amount, the extra overhead caused by the use of flash loans can be avoided in the operation.
getProtocolAccountData
Obtain the amount of collateral and borrowing in the lending agreement
getProtocolNetAssets
Get the net assets in the lending agreement
getProtocolRatio
Obtain the loan and collateral ratio in the lending agreement
getProtocolCollateralRatio
Obtain the value ratio of the loan and collateral in the lending agreement in the oracle of the lending agreement
getProtocolLeverageAmount
Get the amount of ETH you need to flash loan when adjusting leverage and whether you should increase or decrease leverage
getNetAssetsInfo
Obtain the asset status of the overall strategy pool
getNetAssets
Obtain the net assets of the strategy pool
getCurrentExchangePrice
Get the current actual exchange rate
Vault
This contract uses the ERC4626 standard
convertToShares
How many share tokens can be obtained by obtaining the specified amount of STETH
convertToAssets
How much STETH can be obtained by obtaining a specified number of share tokens (withdrawal fees also need to be deducted)
getWithdrawFee
Get the withdrawal fee that will be deducted when withdrawing the specified amount of STETH
getDeleverageWithdrawFee
Obtain the amount of STETH that needs to be swapped when de-leverage withdrawal is required
####totalAssets
ERC4626 standard method for obtaining total assets
deposit
ERC4626 standard method of depositing assets, the incoming parameter is the amount of STETH
withdraw
ERC4626 standard asset extraction method, the input parameter is the number of STETH
####mint
ERC4626 standard deposit asset method, the incoming parameter is the number of share tokens
redeem
ERC4626 standard asset extraction method, the input parameter is the number of share tokens
####deleverageWithdraw
Withdraw STETH from a lending agreement to deleverage
Peripheral contract
VaultStETHWrapper
deposit
The user consumes ETH or WETH to exchange for STETH and deposits it in the vault, which needs to be exchanged through 1inch
withdraw
The user consumes the share token to take out ETH or WETH to the user, which needs to be exchanged through 1inch
depositWstETH
The user consumes WstETH and deposits it into the vault to get the share token, which needs to be unwrapped through the WstETH contract
withdrawWstETH
The user consumes share tokens to withdraw WstETH from the vault, which needs to be wrapped through the WstETH contract
getWithdrawSwapAmount
The amount of STETH that needs to be exchanged for 1inch to get withdrawal ETH or WETH
Last updated