Skip to main content

Overview

The StrategyRouter manages fund allocation across multiple DeFi strategies, handles rebalancing, and coordinates strategy operations like harvesting and deleveraging.

Contract Architecture

Source: contracts/strategy/StrategyRouter.sol:18-27

Constructor

Source: contracts/strategy/StrategyRouter.sol:36-39

Strategy Management

Set Strategies

Configure strategies and their target allocations:
Source: contracts/strategy/StrategyRouter.sol:45-64
Target allocations must sum to exactly 10000 basis points (100%).

Get Strategy Stats

Source: contracts/strategy/StrategyRouter.sol:70-82

Get Portfolio State

Source: contracts/strategy/StrategyRouter.sol:84-96

Fund Management

Move Funds to Strategy

Source: contracts/strategy/StrategyRouter.sol:105-120

Withdraw from Strategies

Called by vault when liquidity is needed:
Source: contracts/strategy/StrategyRouter.sol:135-170

Rebalancing

Automatic portfolio rebalancing to target allocations:
Source: contracts/strategy/StrategyRouter.sol:176-232

Harvesting

Collect profits from all strategies:
Source: contracts/strategy/StrategyRouter.sol:273-298

Deleveraging

Trigger leverage unwinding for specific strategies:
Source: contracts/strategy/StrategyRouter.sol:246-267

Helper Functions

Compute Total Managed

Source: contracts/strategy/StrategyRouter.sol:238-243

Decode Revert Reason

Source: contracts/strategy/StrategyRouter.sol:302-332

Events

Source: contracts/strategy/StrategyRouter.sol:29-34

Vault Interface

Source: contracts/strategy/StrategyRouter.sol:9-16

Error Handling

The router includes comprehensive error handling:
  • Try-Catch Blocks: All strategy interactions wrapped in try-catch
  • Revert Decoding: Extracts readable error messages from reverts
  • Graceful Degradation: Continues operations even if one strategy fails
  • Event Emissions: Logs all failures for monitoring

Security Features

  1. Access Control: Only owner can manage strategies and rebalance
  2. Vault-Only Withdrawals: Only vault can request fund withdrawals
  3. Strategy Validation: Checks for zero addresses
  4. Allocation Validation: Ensures targets sum to 100%

Integration Example

Next Steps