Skip to main content

YieldRouter

The YieldRouter contract manages the allocation of deposited funds to yield-generating DeFi protocols and handles harvesting and rebalancing operations.

Overview

  • Pattern: UUPS Upgradeable Proxy
  • Solidity Version: 0.8.24
  • Dependencies: OpenZeppelin Contracts v5

Key Functions

allocate

function allocate(address token, uint256 amount, uint8 strategyId) external onlyOperator

Allocates deposited funds to a specific yield strategy. Only callable by the platform operator.

Parameters:

  • token -- ERC-20 token to allocate
  • amount -- Amount to allocate
  • strategyId -- Target strategy identifier

Events: Allocated(address token, uint256 amount, uint8 strategyId)

harvest

function harvest(uint8 strategyId) external onlyOperator returns (uint256 yield)

Harvests accrued yield from a strategy. The harvested yield is split according to the revenue share (65% user, 25% platform, 10% insurance).

Parameters:

  • strategyId -- Strategy to harvest from

Returns: Total yield harvested

Events: Harvested(uint8 strategyId, uint256 yield)

rebalance

function rebalance(uint8 fromStrategy, uint8 toStrategy, uint256 amount) external onlyOperator

Moves funds between strategies to optimize yield or manage risk.

Events: Rebalanced(uint8 from, uint8 to, uint256 amount)

getStrategyBalance

function getStrategyBalance(uint8 strategyId) external view returns (uint256)

Returns the total amount deployed to a specific strategy.

Strategies

IDProtocolDescription
1Aave v3Lending pool supply
2Compound v3Comet supply
3LidoETH liquid staking

Adding New Strategies

function addStrategy(
uint8 strategyId,
address adapter,
uint256 maxAllocation
) external onlyOwner

New strategies are added by the contract owner (multi-sig with timelock). Each strategy requires an adapter contract that implements the IYieldAdapter interface.

Security Considerations

  • Only the operator address can allocate, harvest, and rebalance
  • Maximum allocation limits prevent over-concentration
  • Strategy adapters are immutable once deployed (new adapter = new strategy)
  • Emergency withdrawal pulls all funds back to the DepositVault

Next Steps