A reference implementation of an ERC-4626 tokenized vault that wraps an underlying yield-generating protocol and exposes a standardized interface for deposits, withdrawals, and share-based accounting.
This project is intended for learning, experimentation, and as a starting point for building production-grade DeFi vaults.
- Implements the ERC-4626 Tokenized Vault Standard
- Accepts an underlying ERC-20 asset (e.g. USDC, DAI)
- Issues vault shares representing proportional ownership
- Forwards deposited assets to a yield strategy
- Accrues yield by increasing assets per share
- Allows users to withdraw or redeem at any time (subject to strategy liquidity)
The underlying ERC-20 token deposited into the vault (e.g. USDC).
ERC-20 tokens minted by the vault that represent ownership in the total assets managed by the vault.
Yield is generated outside the vault (lending, staking, LPing, etc.). The vault only performs accounting and ownership tracking.
Shares do not increase — the value of each share increases over time.
- User deposits assets
- Vault mints shares based on current exchange rate
- Assets are forwarded to the underlying strategy
- User burns shares (directly or implicitly)
- Vault withdraws assets from the strategy
- Assets are transferred back to the user
| Function | User specifies | Guaranteed | Typical use case |
|---|---|---|---|
withdraw |
Assets | Exact assets | Payments, precise transfers |
redeem |
Shares | Exact shares burned | Full exit, accounting |
Exchange rate is defined as:
shares = assets * totalSupply / totalAssets
assets = shares * totalAssets / totalSupply
Special case:
- If
totalSupply == 0, thenshares = assets
This ensures fair initial deposits and correct yield accrual.
contracts/
├── Vault.sol # ERC-4626 vault implementation
├── Strategy.sol # (Optional) Yield strategy abstraction
scripts/
├── deploy.ts
test/
├── Vault.t.sol # Deposit / withdraw / invariant tests
README.md
-
Rounding is handled per ERC-4626 spec (user-safe defaults)
-
Withdrawals may fail if the underlying protocol is illiquid
-
Inflation attacks must be mitigated by:
- Seeding initial liquidity, or
- Overriding conversion logic
-
Reentrancy protection is required for withdrawals
- ERC-4626 Specification (EIP-4626)
- OpenZeppelin ERC-4626 implementation
- Yearn V3 vault architecture
This code is for educational purposes. It has not been audited and should not be used in production without proper security review.
ERC-4626 standardizes how yield-bearing vaults work in DeFi. This project demonstrates how to implement a compliant vault while keeping yield generation modular and composable.🚀