Overview
TheStrategyRouter contract orchestrates multiple yield strategies, handling allocation rebalancing, harvest operations, and strategy-level fund management. It acts as the intermediary between the Vault and individual Strategy contracts.
Inherits: Ownable
State Variables
IVault
required
Immutable. Reference to the Vault contract that holds user funds.
address[]
required
Dynamic array of active strategy contract addresses.
mapping(address => uint256)
required
Target allocation for each strategy in basis points. Sum must equal 10000 (100%).
Events
StrategiesUpdated
Rebalanced
uint256
Total assets under management after rebalancing
Harvested
address
Strategy address that was harvested
uint256
Amount of profit harvested from the strategy
WithdrawnFromStrategies
uint256
Amount requested by vault
uint256
Actual amount withdrawn from strategies
DeleverageTriggered
address
Strategy being deleveraged
uint256
Maximum deleverage iterations allowed
StrategyWithdrawFailed
address
Strategy that failed
string
Error message describing the failure
Constructor
address
required
Address of the Vault contract
address
required
Address that will own this router contract
Strategy Management
setStrategies
address[]
required
Array of strategy contract addresses
uint256[]
required
Array of target allocations in basis points (must sum to 10000)
- Arrays must have same length
- No zero addresses allowed
- Sum of
_bpsmust equal 10000 (100%)
getStrategies
address[]
Array of strategy contract addresses
getStrategyStats
address
required
Strategy address to query
uint256
Current balance held by the strategy
uint256
Target allocation in basis points
uint256
Actual allocation percentage in basis points
getPortfolioState
address[]
Array of strategy addresses
uint256[]
Current balance in each strategy
uint256[]
Target allocation for each strategy in basis points
Fund Management
moveFundsToStrategy
address
required
Strategy to receive funds
uint256
required
Amount of assets to move
moveAllToStrategy
address
required
Strategy to receive all funds
withdrawFromStrategies
uint256
required
Amount needed by the vault
uint256
Actual amount withdrawn from strategies
- Only callable by the Vault contract
- Will iterate through strategies until requested amount is satisfied
- Reverts if insufficient liquidity across all strategies
- Iterates through strategies in order
- Calls
withdrawToVault()on each strategy - Measures actual amount received (handles strategies that return different amounts)
- Continues until requested amount is satisfied or strategies exhausted
Rebalancing
rebalance
- Calculate current total managed assets
- Withdraw excess from overweight strategies
- Recalculate total after withdrawals
- Deploy funds to underweight strategies
- Continues rebalancing other strategies if one fails
- Emits
StrategyWithdrawFailedevent for failed operations
Harvesting
harvestAll
- Iterates through all strategies
- Calls
harvest()on each strategy - Measures profit returned to vault
- Calls
vault.handleHarvestProfit()to apply performance fees
- Continues harvesting other strategies if one fails
- Emits events for both successes and failures
Risk Management
triggerDeleverage
address
required
Address of the strategy to deleverage
uint256
required
Maximum number of deleverage iterations (gas limit protection)
- Market volatility increases liquidation risk
- Preparing to withdraw large amounts from leveraged strategies
- Emergency risk reduction
Integration Example
AI Integration
The StrategyRouter is designed to be controlled by MetaVault AI agents:Security Considerations
- Owner Control: Owner has significant control. Use multisig or timelock.
- Strategy Failures: Individual strategy failures don’t brick the router.
- Rebalance Ordering: Strategies are processed in array order - consider liquidity.
- Gas Limits: Large strategy arrays may hit gas limits in
harvestAll()orrebalance().
See Also
- Vault - Main vault contract
- IStrategy Interface - Strategy interface specification
- StrategyAave - Basic Aave strategy
- StrategyAaveLeverage - Leveraged strategy