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
IERC20
required
Immutable. The underlying asset token (e.g., USDC, LINK) that users deposit.
uint256
required
Performance fee in basis points (10000 = 100%). Applied to harvested profits.
address
required
Address that receives performance and withdrawal fees.
uint256
required
Withdrawal fee in basis points (10000 = 100%). Applied when users withdraw.
address
required
Address of the StrategyRouter contract that manages yield strategies.
mapping(address => uint256)
required
Tracks total deposits per user for growth calculation.
mapping(address => uint256)
required
Tracks total withdrawals per user for growth calculation.
Events
Deposit
address
Address of the depositor
uint256
Amount of assets deposited
Amount of vault shares minted
Withdraw
address
Address of the withdrawer
uint256
Amount of assets withdrawn (after fees)
Amount of vault shares burned
Constructor
address
required
Address of the underlying asset token
address
required
Address to receive fees
uint256
required
Performance fee in basis points (e.g., 1000 = 10%)
uint256
required
Withdrawal fee in basis points (e.g., 50 = 0.5%)
Public Functions
deposit
uint256
required
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
uint256
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
uint256
required
Amount of assets
Equivalent shares amount
convertToAssets
Amount of shares
uint256
Equivalent assets amount
totalAssets
uint256
Amount of assets in vault
totalManagedAssets
uint256
Total assets in vault and all strategies
getNAV
totalManagedAssets().
Total net asset value
availableLiquidity
uint256
Available liquidity for instant withdrawals
userGrowth
address
required
User address to check
int256
Profit (positive) or loss (negative) in asset units
(currentValue + totalWithdrawn) - netDeposited
userGrowthPercent
address
required
User address to check
int256
Growth percentage scaled by 1e18 (1e18 = 100%)
Owner Functions
setRouter
address
required
Address of the StrategyRouter contract
Router-Only Functions
moveToStrategy
address
required
Strategy contract address
uint256
required
Amount of assets to move
receiveFromStrategy
uint256
required
Amount received from strategy
handleHarvestProfit
uint256
required
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