Design and implement an ERC-4626 compliant tokenized vault for yield-bearing DeFi strategies.
You are a DeFi vault architect who has built ERC-4626 compliant vaults for yield aggregators and lending protocols. You understand the standard deeply, including its security considerations and the subtle implementation details that trip up most developers. CONTEXT: I am building a yield aggregation protocol that deploys user funds into multiple DeFi strategies. I want to use the ERC-4626 tokenized vault standard for each strategy vault. This standard provides composability — other protocols can integrate with my vaults easily. I need to implement the standard correctly, handle edge cases, and build a strategy execution layer on top. TASK: Design and implement an ERC-4626 vault system: 1. ERC-4626 standard deep dive: explain every function in the standard (asset, totalAssets, convertToShares, convertToAssets, maxDeposit, maxMint, maxWithdraw, maxRedeem, previewDeposit, previewMint, previewWithdraw, previewRedeem, deposit, mint, withdraw, redeem) and the subtle differences between them. Highlight the preview vs. actual execution distinction and why it matters. 2. Share price calculation: the relationship between shares and assets, how to handle the initial deposit (inflation attack prevention using virtual shares/assets or minimum deposit), rounding direction rules (always round in the vault's favor), and how to handle strategies that can lose value (negative yield scenario). 3. Strategy integration architecture: how the vault interacts with external DeFi protocols (deposit into Aave, stake in Lido, LP on Curve), harvesting yield and compounding, multi-strategy vault design with allocation weights, and emergency withdrawal from strategies. 4. Security considerations specific to ERC-4626: the share inflation attack (donation attack) and how to prevent it, reentrancy risks during deposit/withdraw, front-running of harvest transactions, and manipulation of totalAssets to affect share price. Provide concrete mitigation for each. 5. Fee implementation: how to charge management fees (time-based) and performance fees (high-water mark) within the ERC-4626 framework without breaking the standard's invariants. Compare fee-on-mint vs. fee-on-withdrawal vs. share dilution approaches. 6. Testing checklist: list the critical test cases for an ERC-4626 vault including: deposit/withdraw roundtrip accuracy, share price manipulation resistance, multi-user scenarios (large depositor effect on small depositors), and integration tests with the actual DeFi protocols used by the strategy.
Or press ⌘C to copy