Skip to content

MySmartContracts/erc4626-tokenized-vault

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ERC-4626 Tokenized Vault

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.


📌 What this project does

  • 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)

🧠 Key Concepts

Asset

The underlying ERC-20 token deposited into the vault (e.g. USDC).

Shares

ERC-20 tokens minted by the vault that represent ownership in the total assets managed by the vault.

Yield

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.


🔁 Vault Flow

Deposit

  1. User deposits assets
  2. Vault mints shares based on current exchange rate
  3. Assets are forwarded to the underlying strategy

Withdraw / Redeem

  1. User burns shares (directly or implicitly)
  2. Vault withdraws assets from the strategy
  3. Assets are transferred back to the user

🔀 Withdraw vs Redeem

Function User specifies Guaranteed Typical use case
withdraw Assets Exact assets Payments, precise transfers
redeem Shares Exact shares burned Full exit, accounting

🧮 Share Accounting

Exchange rate is defined as:

shares = assets * totalSupply / totalAssets
assets = shares * totalAssets / totalSupply

Special case:

  • If totalSupply == 0, then shares = assets

This ensures fair initial deposits and correct yield accrual.


🏗️ Project Structure

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

🔐 Security Considerations

  • 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


📚 References

  • ERC-4626 Specification (EIP-4626)
  • OpenZeppelin ERC-4626 implementation
  • Yearn V3 vault architecture

⚠️ Disclaimer

This code is for educational purposes. It has not been audited and should not be used in production without proper security review.


🧠 Summary

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.🚀

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors