Section 3 of 18
Vault: Share Token (ERC-20 + Permit)
What You Are Building
The vault IS its own ERC-20. The share token is the receipt for a pool stake; users hold it instead of the underlying. Section 4 will build the math that gives those shares value. This section builds the surface that lets users move them: transfer, transferFrom, approve, plus the internal primitives _mint, _burn, _transfer that later sections call from deposit and withdraw. We add EIP-2612 permit so users can approve via a signed message instead of a separate transaction.
We build ERC-20 from scratch, not by inheriting OpenZeppelin. Same choice Uniswap V2 made (UniswapV2ERC20 is hand-written) and Compound V2 made. The reason is pedagogical: every state mutation is visible in this file, no abstraction hides what _mint actually does.
Your Code
Requirements
Sign up free — keep reading + earn 10 Lynx
Zealynx Academy is free. Track your progress, earn Lynx, and climb the leaderboard.
Sign up free to continueAlready have an account? Log in