ERC-4626 · Final · ERC · 2021-12-22
ERC-4626: Tokenized Vaults
A standard interface for yield-bearing vaults: deposit one ERC-20 asset, receive ERC-20 shares, and redeem them later, so aggregators and protocols can plug into any vault the same way.
What problem does it solve?
Lending markets, yield aggregators and interest-bearing tokens all do the same basic thing: take a token, put it to work, and give the depositor a receipt that grows in value. Before ERC-4626, each protocol shaped that receipt differently, so integrators had to write and audit a custom adapter per vault.
ERC-4626 standardizes the vault API. A vault is itself an ERC-20 token whose units are shares in an underlying asset, plus a fixed set of functions to deposit, withdraw and price those shares.
How it works
The vault manages one underlying ERC-20 asset(). Its own ERC-20 balance represents shares. On top of that it exposes four matching groups of functions:
| Action | You specify | Mutating | Simulate | Limit |
|---|---|---|---|---|
| Deposit | assets in | deposit(assets, receiver) |
previewDeposit |
maxDeposit |
| Mint | shares out | mint(shares, receiver) |
previewMint |
maxMint |
| Withdraw | assets out | withdraw(assets, receiver, owner) |
previewWithdraw |
maxWithdraw |
| Redeem | shares in | redeem(shares, receiver, owner) |
previewRedeem |
maxRedeem |
Plus accounting views:
totalAssets(): all underlying the vault manages, including accrued yield and net of fees.convertToShares/convertToAssets: an ideal, fee-free, caller-independent exchange rate for display. Always rounds down.preview*: the exact result of doing the action now in the same transaction, including fees.
Events Deposit(sender, owner, assets, shares) and Withdraw(sender, receiver, owner, assets, shares) are required. Vaults must implement ERC-20 metadata and may add ERC-2612 permit. How the vault invests the assets is deliberately left unspecified.
Sample code
Depositing into and redeeming from a vault with ethers v6:
import { Contract, Wallet, JsonRpcProvider, parseUnits } from "ethers";
const provider = new JsonRpcProvider(process.env.RPC_URL);
const wallet = new Wallet(process.env.PRIVATE_KEY!, provider);
const vault = new Contract(process.env.VAULT!, [
"function asset() view returns (address)",
"function previewDeposit(uint256) view returns (uint256)",
"function deposit(uint256 assets, address receiver) returns (uint256)",
"function balanceOf(address) view returns (uint256)",
"function previewRedeem(uint256) view returns (uint256)",
"function redeem(uint256 shares, address receiver, address owner) returns (uint256)",
], wallet);
const asset = new Contract(await vault.asset(), [
"function approve(address,uint256) returns (bool)",
], wallet);
const amount = parseUnits("100", 6); // e.g. a 6-decimal stablecoin
await (await asset.approve(await vault.getAddress(), amount)).wait();
console.log("expected shares:", await vault.previewDeposit(amount));
await (await vault.deposit(amount, wallet.address)).wait();
const shares = await vault.balanceOf(wallet.address);
console.log("would receive:", await vault.previewRedeem(shares));
await (await vault.redeem(shares, wallet.address, wallet.address)).wait();
In Solidity, most projects inherit an audited base such as OpenZeppelin's or Solmate's ERC4626 and override totalAssets() plus deposit/withdraw hooks.
Things to know
- Status is Final and the standard is widely adopted across DeFi.
- Rounding must favor the vault: round down when giving shares or assets to the user, round up when computing what the user must provide. Getting this wrong can let users drain value.
preview*values reflect current on-chain state and can be manipulated; the spec warns they are not safe as price oracles.convertTo*may be implemented more robustly (e.g. time-weighted).- Empty or nearly empty vaults are vulnerable to the well-known "inflation" or donation attack on the first depositor. Mitigations include virtual shares/offsets or seeding the vault at deployment.
- EOAs calling
deposit/redeemdirectly get no slippage protection; consider a router that checks a minimum output. - Extensions: ERC-7540 (asynchronous requests), ERC-7575 (multi-asset vaults), ERC-7535 (native ETH as the asset).
- Integrators should still review each vault: a malicious contract can match the interface while ignoring the spec.