Skip to main content

Overview

The Vault 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

Emitted when a user deposits assets.
address
Address of the depositor
uint256
Amount of assets deposited
uint256
Amount of vault shares minted

Withdraw

Emitted when a user withdraws assets.
address
Address of the withdrawer
uint256
Amount of assets withdrawn (after fees)
uint256
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

Deposit assets into the vault and receive shares.
uint256
required
Amount of assets to deposit
uint256
Amount of vault shares minted to the depositor
Requirements:
  • Caller must have approved the vault to transfer amount of asset tokens
  • amount must be greater than 0
Example:

withdraw

Burn shares and withdraw underlying assets. If vault doesn’t have enough liquidity, pulls from strategies.
uint256
required
Amount of shares to burn
uint256
Amount of assets transferred to user (after withdrawal fee)
Requirements:
  • shares must be greater than 0
  • Caller must have sufficient shares
  • Router must be set if strategies need to be tapped
Example:

convertToShares

Convert an asset amount to shares based on current vault state.
uint256
required
Amount of assets
uint256
Equivalent shares amount

convertToAssets

Convert shares to asset amount based on current vault state.
uint256
required
Amount of shares
uint256
Equivalent assets amount

totalAssets

Returns the amount of assets held directly in the vault (not in strategies).
uint256
Amount of assets in vault

totalManagedAssets

Returns total assets under management (vault + all strategies).
uint256
Total assets in vault and all strategies

getNAV

Get Net Asset Value - same as totalManagedAssets().
uint256
Total net asset value

availableLiquidity

Get immediately available liquidity (vault balance only, excluding strategies).
uint256
Available liquidity for instant withdrawals

userGrowth

Calculate absolute profit/loss for a user.
address
required
User address to check
int256
Profit (positive) or loss (negative) in asset units
Formula: (currentValue + totalWithdrawn) - netDeposited

userGrowthPercent

Calculate percentage growth for a user.
address
required
User address to check
int256
Growth percentage scaled by 1e18 (1e18 = 100%)
Example:

Owner Functions

setRouter

Set the StrategyRouter contract address.
address
required
Address of the StrategyRouter contract

Router-Only Functions

moveToStrategy

Move funds from vault to a strategy. Called by StrategyRouter during rebalancing.
address
required
Strategy contract address
uint256
required
Amount of assets to move

receiveFromStrategy

Accounting function called when router pulls funds from strategy back to vault.
uint256
required
Amount received from strategy

handleHarvestProfit

Process harvested profits and apply performance fee.
uint256
required
Amount of profit harvested
Behavior:
  • Calculates fee: fee = profit * performanceFeeBps / 10000
  • Transfers fee to feeRecipient
  • Remaining profit stays in vault to increase share value

Integration Example

Security Considerations

  1. Router Trust: The router has privileged access to move funds. Ensure router contract is audited.
  2. Fee Limits: Consider implementing maximum fee caps (e.g., performanceFeeBps 2000 for 20% max).
  3. Reentrancy: Uses SafeERC20 which provides reentrancy protection.
  4. Share Inflation: First depositor should deposit significant amount to prevent share manipulation attacks.

See Also