Skip to main content

Overview

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

Emitted when the strategy list and allocations are updated.

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

Set or update the list of strategies and their target allocations.
address[]
required
Array of strategy contract addresses
uint256[]
required
Array of target allocations in basis points (must sum to 10000)
Requirements:
  • Arrays must have same length
  • No zero addresses allowed
  • Sum of _bps must equal 10000 (100%)
Example:

getStrategies

Get the list of active strategy addresses.
address[]
Array of strategy contract addresses

getStrategyStats

Get detailed statistics for a specific strategy.
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

Get complete portfolio state for all strategies.
address[]
Array of strategy addresses
uint256[]
Current balance in each strategy
uint256[]
Target allocation for each strategy in basis points

Fund Management

moveFundsToStrategy

Manually move funds from vault to a specific strategy and invest them.
address
required
Strategy to receive funds
uint256
required
Amount of assets to move
Example:

moveAllToStrategy

Move all available vault assets to a specific strategy.
address
required
Strategy to receive all funds

withdrawFromStrategies

Withdraw assets from strategies to satisfy vault withdrawal requests. Called by Vault only.
uint256
required
Amount needed by the vault
uint256
Actual amount withdrawn from strategies
Requirements:
  • Only callable by the Vault contract
  • Will iterate through strategies until requested amount is satisfied
  • Reverts if insufficient liquidity across all strategies
Behavior:
  1. Iterates through strategies in order
  2. Calls withdrawToVault() on each strategy
  3. Measures actual amount received (handles strategies that return different amounts)
  4. Continues until requested amount is satisfied or strategies exhausted

Rebalancing

rebalance

Rebalance all strategies to match target allocations. Process:
  1. Calculate current total managed assets
  2. Withdraw excess from overweight strategies
  3. Recalculate total after withdrawals
  4. Deploy funds to underweight strategies
Error Handling:
  • Continues rebalancing other strategies if one fails
  • Emits StrategyWithdrawFailed event for failed operations
Example:

Harvesting

harvestAll

Harvest profits from all strategies and route to vault. Process:
  1. Iterates through all strategies
  2. Calls harvest() on each strategy
  3. Measures profit returned to vault
  4. Calls vault.handleHarvestProfit() to apply performance fees
Error Handling:
  • Continues harvesting other strategies if one fails
  • Emits events for both successes and failures
Example:

Risk Management

triggerDeleverage

Manually trigger deleveraging on a leveraged strategy (e.g., during high volatility).
address
required
Address of the strategy to deleverage
uint256
required
Maximum number of deleverage iterations (gas limit protection)
Use Cases:
  • Market volatility increases liquidation risk
  • Preparing to withdraw large amounts from leveraged strategies
  • Emergency risk reduction
Example:

Integration Example

AI Integration

The StrategyRouter is designed to be controlled by MetaVault AI agents:

Security Considerations

  1. Owner Control: Owner has significant control. Use multisig or timelock.
  2. Strategy Failures: Individual strategy failures don’t brick the router.
  3. Rebalance Ordering: Strategies are processed in array order - consider liquidity.
  4. Gas Limits: Large strategy arrays may hit gas limits in harvestAll() or rebalance().

See Also