ERC-4626 is a tokenized vault with a single underlying EIP-20 token.
First of all, it is an ERC-20 based proposal and fully compatible with it.
Secondly, understand the concept of a vault, which is not a treasury. The treasury currently on the market is basically a contract wallet, most of which are Gnosis Safe, which mainly provides safe fund entry and exit functions. But for an organization, in addition to the inflow and outflow of funds, the flow of funds can also generate income.
The motivation for this proposal: The lack of standards for tokenized vaults has resulted in different implementation details of many vaults on the market, such as lending markets, aggregators, interest-bearing tokens, etc. This makes integrating aggregators and plugins at the protocol level difficult, error-prone, and a waste of development resources.
When the current status of this proposal is Final, it means it is a relatively stable standard.
Tokens that follow ERC-4626 must fully implement ERC-20, which is used to represent shares. Here are a few simple concepts.
Slippage is the difference between the expected price of a trade and the actual execution price. Slippage occurs when there is a delay between placing a trade and executing it, and the price of the asset being traded changes.
For example, if you find 20 ETH and 80 USDT in the AMM pool, your expected ETH price is 4 USDT/ETH. However, if you plan to spend 20 USDT to swap in the pool, you will only end up with 4 ETH instead of the expected 5 ETH, which means you suffer a slippage loss of 1 USDT/ETH. Your actual purchase price will be 5 USDT, not the expected 4 USDT.
Slippage is particularly common in fast-moving markets or high-volatility assets, as well as long-tail assets with constrained liquidity. Regardless, it has a significant impact on trading performance and it is important to consider slippage when placing trades.
The contract code comes from the OpenZeppelin smart contract code library:
The ERC-4626 contract inherits from ERC-20. This part will not be summarized. It is also an abstract contract itself. The interfaces that the contract must implement are as follows:
The interfaces are quite rich, most of them are relatively simple and can be divided into two categories: read and write.
The main interfaces for writing data are deposit, mint, withdraw, and redeem.
In fact, due to the existence of slippage, using the preview method to view the expected numbers may be inaccurate, which is also a common problem in the industry and may cause some security issues, which will be discussed later.
The several preview methods mentioned earlier, as well as the public convertToShares and convertToAssets, actually call the _convertToShares and _convertToAssets methods internally.
These two core methods are to calculate the proportional relationship between assets and shares. The variables involved include share supply, current total assets, number of decimal points, and decimal point rounding methods.
The above is the basic implementation of the ERC-4626 abstract contract. The actual vault contract is much more complicated than it.
For the vault contract, there are two relatively important functions to implement. One is the deposit and withdrawal function, the conversion of assets and shares; the other is the way to obtain income, which will be explained with examples below.
Similar to some other popular EIPs, ERC-4626 also has an alliance ecosystem (https://erc4626.info/) maintained by dedicated personnel, which collects some lending protocols and applications currently on the market that are compatible with ERC-4626, and there are also news, open source libraries, security and other information. If your vault is adapted to ERC-4626, you can also submit an application there.
Below we analyze an application example, Aladdin DAO’s AladdinCRVV2 vault (https://concentrator.aladdin.club/vaults/). Aladdin DAO has many vault contracts, and this is just one of the more active ones.
The vault earns income by staking cvxCRV tokens.
(https://etherscan.io/address/0x2b95A1Dcc3D405535f9ed33c219ab38E8d7e0884). And you can check through the github code that the previous version is not compatible with ERC-4626
The above is the basic analysis of the vault contract with relatively rich functions. Its essence is to stake assets to earn interest. Why is it designed like this? The main reason lies in the design of the cvxCrvStaking contract. The description of the income from staking cvxCRV is “By staking cvxCRV, you’ re earn the usual rewards from veCRV (3crv governance fee distribution from Curve + any airdrop), plus a share of 10% of the Convex LPs’ boosted CRV earnings, and CVX tokens on top of that.” The greater the number of tokens, the greater the benefits.
For ERC-4626 vaults, the main security issue is protection against inflation attacks.
When a user deposits tokens, according to the share calculation formula (shares = assets * totalSupply / totalAssets), the calculation result has a decimal point and is generally rounded down.
As you can see from the figure below, when a user deposits 500 tokens in assets, the amount of assets lost due to decimal rounding depends on the exchange rate (correspondence between per share and token assets). If the exchange rate is that of the orange curve, we get less than 1 share and lose 100%. However, if the exchange rate is that of the green curve and 5000 shares are obtained, the rounding loss is limited to a maximum of 0.02%.
Then if we focus on limiting losses to a maximum of 0.5%, we need to acquire at least 200 shares. The green rate requires only 20 tokens, but the orange rate requires 200,000 tokens.
Through several examples, it can be analyzed that the blue and green curves are safer than the yellow and orange curves, and are designed to be safer vaults.
Therefore, the main method of inflation attack is to use certain means to move the interest rate curve to the right, causing a small number of depositors to lose their share, thereby achieving the purpose of the attack.
Inflation attacks are mainly through donations.
There are three ways to defend against attacks:
The specific implementation is to rewrite the _decimalsOffset() method of the standard library code provided by OpenZeppelin. This method does not require setting slippage or injecting sufficient initial funds. It is a very good way to resist inflation attacks.
As a relatively basic vault proposal, RC-4626 cannot meet all needs. Some proposals have also scaled it, such as ERC-7535 and EIP-7540.
As mentioned earlier, ERC-4626 can only use ERC-20 as the underlying asset. This proposal mainly allows native assets to be used as underlying assets, such as ETH in the vault.
This extension to ERC-4626 introduces support for asynchronous deposit and redemption processes (called “requests”). It includes new methods for starting and checking the status of these requests. Existing methods from ERC-4626, such as deposit, mint, withdraw, and redeem, are used to execute claimable requests. It is at the implementer’s discretion as to whether to add asynchronous processes for deposits, redemptions, or both.
Potential use cases:
The above is the complete analysis of ERC-4626.
Due to historical reasons, many vaults currently in the market do not comply with ERC-4626 and continue to operate, such as dForce, but they cannot be applied more widely. Some vaults have already been upgraded to comply with ERC-4626, such as some contracts from Aladdin DAO (https://github.com/AladdinDAO/deployments/blob/main/deployments.mainnet.md).
In addition to earning interest through staking, vault applications can also lend out shares as collateral or stake them again to generate income. Furthermore, fundraising through vaults is also a good application scenario, as some of its basic functions can provide excellent support.
The essence of this proposal is to improve the integration efficiency between vaults and the DeFi ecosystem, and reduce development costs. The role of vaults themselves still has more room for exploration as the DeFi market grows.
ERC-4626 is a tokenized vault with a single underlying EIP-20 token.
First of all, it is an ERC-20 based proposal and fully compatible with it.
Secondly, understand the concept of a vault, which is not a treasury. The treasury currently on the market is basically a contract wallet, most of which are Gnosis Safe, which mainly provides safe fund entry and exit functions. But for an organization, in addition to the inflow and outflow of funds, the flow of funds can also generate income.
The motivation for this proposal: The lack of standards for tokenized vaults has resulted in different implementation details of many vaults on the market, such as lending markets, aggregators, interest-bearing tokens, etc. This makes integrating aggregators and plugins at the protocol level difficult, error-prone, and a waste of development resources.
When the current status of this proposal is Final, it means it is a relatively stable standard.
Tokens that follow ERC-4626 must fully implement ERC-20, which is used to represent shares. Here are a few simple concepts.
Slippage is the difference between the expected price of a trade and the actual execution price. Slippage occurs when there is a delay between placing a trade and executing it, and the price of the asset being traded changes.
For example, if you find 20 ETH and 80 USDT in the AMM pool, your expected ETH price is 4 USDT/ETH. However, if you plan to spend 20 USDT to swap in the pool, you will only end up with 4 ETH instead of the expected 5 ETH, which means you suffer a slippage loss of 1 USDT/ETH. Your actual purchase price will be 5 USDT, not the expected 4 USDT.
Slippage is particularly common in fast-moving markets or high-volatility assets, as well as long-tail assets with constrained liquidity. Regardless, it has a significant impact on trading performance and it is important to consider slippage when placing trades.
The contract code comes from the OpenZeppelin smart contract code library:
The ERC-4626 contract inherits from ERC-20. This part will not be summarized. It is also an abstract contract itself. The interfaces that the contract must implement are as follows:
The interfaces are quite rich, most of them are relatively simple and can be divided into two categories: read and write.
The main interfaces for writing data are deposit, mint, withdraw, and redeem.
In fact, due to the existence of slippage, using the preview method to view the expected numbers may be inaccurate, which is also a common problem in the industry and may cause some security issues, which will be discussed later.
The several preview methods mentioned earlier, as well as the public convertToShares and convertToAssets, actually call the _convertToShares and _convertToAssets methods internally.
These two core methods are to calculate the proportional relationship between assets and shares. The variables involved include share supply, current total assets, number of decimal points, and decimal point rounding methods.
The above is the basic implementation of the ERC-4626 abstract contract. The actual vault contract is much more complicated than it.
For the vault contract, there are two relatively important functions to implement. One is the deposit and withdrawal function, the conversion of assets and shares; the other is the way to obtain income, which will be explained with examples below.
Similar to some other popular EIPs, ERC-4626 also has an alliance ecosystem (https://erc4626.info/) maintained by dedicated personnel, which collects some lending protocols and applications currently on the market that are compatible with ERC-4626, and there are also news, open source libraries, security and other information. If your vault is adapted to ERC-4626, you can also submit an application there.
Below we analyze an application example, Aladdin DAO’s AladdinCRVV2 vault (https://concentrator.aladdin.club/vaults/). Aladdin DAO has many vault contracts, and this is just one of the more active ones.
The vault earns income by staking cvxCRV tokens.
(https://etherscan.io/address/0x2b95A1Dcc3D405535f9ed33c219ab38E8d7e0884). And you can check through the github code that the previous version is not compatible with ERC-4626
The above is the basic analysis of the vault contract with relatively rich functions. Its essence is to stake assets to earn interest. Why is it designed like this? The main reason lies in the design of the cvxCrvStaking contract. The description of the income from staking cvxCRV is “By staking cvxCRV, you’ re earn the usual rewards from veCRV (3crv governance fee distribution from Curve + any airdrop), plus a share of 10% of the Convex LPs’ boosted CRV earnings, and CVX tokens on top of that.” The greater the number of tokens, the greater the benefits.
For ERC-4626 vaults, the main security issue is protection against inflation attacks.
When a user deposits tokens, according to the share calculation formula (shares = assets * totalSupply / totalAssets), the calculation result has a decimal point and is generally rounded down.
As you can see from the figure below, when a user deposits 500 tokens in assets, the amount of assets lost due to decimal rounding depends on the exchange rate (correspondence between per share and token assets). If the exchange rate is that of the orange curve, we get less than 1 share and lose 100%. However, if the exchange rate is that of the green curve and 5000 shares are obtained, the rounding loss is limited to a maximum of 0.02%.
Then if we focus on limiting losses to a maximum of 0.5%, we need to acquire at least 200 shares. The green rate requires only 20 tokens, but the orange rate requires 200,000 tokens.
Through several examples, it can be analyzed that the blue and green curves are safer than the yellow and orange curves, and are designed to be safer vaults.
Therefore, the main method of inflation attack is to use certain means to move the interest rate curve to the right, causing a small number of depositors to lose their share, thereby achieving the purpose of the attack.
Inflation attacks are mainly through donations.
There are three ways to defend against attacks:
The specific implementation is to rewrite the _decimalsOffset() method of the standard library code provided by OpenZeppelin. This method does not require setting slippage or injecting sufficient initial funds. It is a very good way to resist inflation attacks.
As a relatively basic vault proposal, RC-4626 cannot meet all needs. Some proposals have also scaled it, such as ERC-7535 and EIP-7540.
As mentioned earlier, ERC-4626 can only use ERC-20 as the underlying asset. This proposal mainly allows native assets to be used as underlying assets, such as ETH in the vault.
This extension to ERC-4626 introduces support for asynchronous deposit and redemption processes (called “requests”). It includes new methods for starting and checking the status of these requests. Existing methods from ERC-4626, such as deposit, mint, withdraw, and redeem, are used to execute claimable requests. It is at the implementer’s discretion as to whether to add asynchronous processes for deposits, redemptions, or both.
Potential use cases:
The above is the complete analysis of ERC-4626.
Due to historical reasons, many vaults currently in the market do not comply with ERC-4626 and continue to operate, such as dForce, but they cannot be applied more widely. Some vaults have already been upgraded to comply with ERC-4626, such as some contracts from Aladdin DAO (https://github.com/AladdinDAO/deployments/blob/main/deployments.mainnet.md).
In addition to earning interest through staking, vault applications can also lend out shares as collateral or stake them again to generate income. Furthermore, fundraising through vaults is also a good application scenario, as some of its basic functions can provide excellent support.
The essence of this proposal is to improve the integration efficiency between vaults and the DeFi ecosystem, and reduce development costs. The role of vaults themselves still has more room for exploration as the DeFi market grows.