Overview
TheVault contract is the core entry point for users to deposit assets and receive yield. It implements an ERC4626-like vault with share-based accounting, performance fees, and integration with multiple yield strategies through the StrategyRouter.
Contract Address: Deployed per-asset basis
Inherits: ERC20, Ownable
State Variables
Immutable. The underlying asset token (e.g., USDC, LINK) that users deposit.
Performance fee in basis points (10000 = 100%). Applied to harvested profits.
Address that receives performance and withdrawal fees.
Withdrawal fee in basis points (10000 = 100%). Applied when users withdraw.
Address of the StrategyRouter contract that manages yield strategies.
Tracks total deposits per user for growth calculation.
Tracks total withdrawals per user for growth calculation.
Events
Deposit
Address of the depositor
Amount of assets deposited
Amount of vault shares minted
Withdraw
Address of the withdrawer
Amount of assets withdrawn (after fees)
Amount of vault shares burned
Constructor
Address of the underlying asset token
Address to receive fees
Performance fee in basis points (e.g., 1000 = 10%)
Withdrawal fee in basis points (e.g., 50 = 0.5%)
Public Functions
deposit
Amount of assets to deposit
Amount of vault shares minted to the depositor
- Caller must have approved the vault to transfer
amountof asset tokens amountmust be greater than 0
withdraw
Amount of shares to burn
Amount of assets transferred to user (after withdrawal fee)
sharesmust be greater than 0- Caller must have sufficient shares
- Router must be set if strategies need to be tapped
convertToShares
Amount of assets
Equivalent shares amount
convertToAssets
Amount of shares
Equivalent assets amount
totalAssets
Amount of assets in vault
totalManagedAssets
Total assets in vault and all strategies
getNAV
totalManagedAssets().
Total net asset value
availableLiquidity
Available liquidity for instant withdrawals
userGrowth
User address to check
Profit (positive) or loss (negative) in asset units
(currentValue + totalWithdrawn) - netDeposited
userGrowthPercent
User address to check
Growth percentage scaled by 1e18 (1e18 = 100%)
Owner Functions
setRouter
Address of the StrategyRouter contract
Router-Only Functions
moveToStrategy
Strategy contract address
Amount of assets to move
receiveFromStrategy
Amount received from strategy
handleHarvestProfit
Amount of profit harvested
- Calculates fee:
fee = profit * performanceFeeBps / 10000 - Transfers fee to
feeRecipient - Remaining profit stays in vault to increase share value
Integration Example
Security Considerations
- Router Trust: The router has privileged access to move funds. Ensure router contract is audited.
- Fee Limits: Consider implementing maximum fee caps (e.g., performanceFeeBps 2000 for 20% max).
- Reentrancy: Uses SafeERC20 which provides reentrancy protection.
- Share Inflation: First depositor should deposit significant amount to prevent share manipulation attacks.
See Also
- StrategyRouter - Manages strategy allocations
- StrategyAave - Aave lending strategy
- StrategyAaveLeverage - Leveraged Aave strategy