Overview
The Vault contract is the core of MetaVault AI’s asset management system. It implements an ERC-4626-inspired vault that accepts user deposits, mints shares, and manages funds across multiple DeFi strategies.Contract Architecture
The Vault inherits from OpenZeppelin’s battle-tested contracts:contracts/Vault.sol:19-27
Key Features
Share-Based Accounting
The vault uses share-based accounting to track user ownership:- Users deposit assets and receive vault shares
- Share value increases as strategies generate yield
- Shares can be redeemed for proportional assets
Fee Management
- Performance Fee: Charged on harvest profits (default: 10% or 1000 bps)
- Withdrawal Fee: Charged on withdrawals (default: 1% or 100 bps)
Core Functions
Deposit
Accepts user deposits and mints proportional shares:contracts/Vault.sol:89-100
Withdraw
Burns shares and returns assets to users:contracts/Vault.sol:103-148
Share Conversion
Convert between shares and assets:contracts/Vault.sol:57-65
Strategy Integration
Router Connection
The vault connects to a StrategyRouter for fund management:contracts/Vault.sol:154-163
Fund Movement
Only the router can move funds between vault and strategies:contracts/Vault.sol:166-182
Total Managed Assets
Calculate total assets across vault and all strategies:contracts/Vault.sol:196-208
User Analytics
Growth Tracking
Track individual user profit/loss:contracts/Vault.sol:67-85
Profit Harvesting
Handle profits from strategy harvests:contracts/Vault.sol:184-194
Constructor Parameters
Deploy the vault with these parameters:contracts/Vault.sol:33-43
OpenZeppelin Dependencies
The Vault relies on OpenZeppelin v5.4.0:contracts/Vault.sol:4-6
Events
contracts/Vault.sol:30-31
View Functions
Security Considerations
- Access Control: Only router can move funds to strategies
- SafeERC20: All token transfers use OpenZeppelin’s SafeERC20
- Fee Caps: Consider implementing maximum fee limits
- Reentrancy: Protected by CEI pattern (Checks-Effects-Interactions)
Development Best Practices
- Always use
onlyOwneroronlyRoutermodifiers for sensitive functions - Emit events for all state changes
- Use basis points (10000 = 100%) for fee calculations
- Track user history for accurate analytics