Skip to main content

Overview

The StrategyAaveLeverage contract implements a sophisticated leveraged yield strategy on Aave V3. It recursively borrows WETH against supplied collateral, swaps to the underlying asset, and re-supplies to amplify returns. This strategy multiplies exposure but also increases risk. Implements: IStrategy Risk Level: High (uses leverage, liquidation risk) Strategy Flow:
  1. Supply LINK as collateral
  2. Borrow WETH against LINK
  3. Swap WETH → LINK via DEX
  4. Supply newly acquired LINK
  5. Repeat (controlled by maxDepth)

State Variables

IERC20
required
Immutable. The underlying asset token (e.g., LINK).
address
required
Immutable. Address of the Vault contract.
address
required
Immutable. Address of the StrategyRouter.
IPool
required
Immutable. Aave V3 Pool contract.
IProtocolDataProvider
required
Immutable. Aave Protocol Data Provider.
ISwapRouterV2
required
Immutable. UniswapV2-style DEX router for token swaps.
address
required
Immutable. WETH token address.
IPriceOracle
required
Immutable. Price oracle for WETH/LINK conversions.
uint256
required
Total principal deposited by vault (tracking).
uint256
required
Total WETH borrowed (approximate tracking).
uint8
required
Maximum leverage loop iterations (default: 3, max: 6).
uint256
required
Borrow amount per loop in basis points (default: 6000 = 60%).
bool
required
Emergency pause flag.

Events

InvestedLeveraged

uint256
Initial amount invested
uint8
Number of leverage loops executed
uint256
Total amount supplied after leverage
uint256
Total WETH borrowed

Deleveraged

Harvested

PauseToggled

LeverageParamsUpdated

Constructor

address
required
Underlying asset (e.g., LINK)
address
required
Vault contract address
address
required
StrategyRouter address
address
required
Aave V3 Pool address
address
required
Aave Protocol Data Provider address
address
required
UniswapV2-compatible router address
address
required
WETH token address
address
required
Price oracle address
Initialization:
  • Approves pool to spend unlimited tokens
  • Approves swap router to spend unlimited WETH
  • Sets all immutable references

Core Strategy Functions

invest

Invest with leverage by recursively borrowing and re-supplying.
uint256
required
Initial amount to invest (already transferred to strategy)
Requirements:
  • Strategy must not be paused
  • Strategy must hold sufficient token balance
  • Only callable by router
Process:
  1. Supply initial amount as collateral
  2. Loop up to maxDepth times:
    • Calculate safe borrow amount (limited by pool liquidity)
    • Borrow WETH from Aave
    • Swap WETH → LINK via DEX
    • Supply received LINK as additional collateral
  3. Update bookkeeping (deposited, borrowedWETH)
Safety Features:
  • Caps borrow to small amounts (0.001 WETH or 1% of pool) to avoid liquidity issues
  • Uses try/catch on all external calls (borrow, swap, supply)
  • Stops looping if any operation fails
  • Attempts to repay borrowed WETH if swap fails
Example:

withdrawToVault

Withdraw underlying assets from Aave position.
uint256
required
Amount of underlying to withdraw
uint256
Actual amount withdrawn and sent to vault
Warning: Withdrawing may fail if position is too leveraged. Call deleverageAll() first if needed. Process:
  1. Attempts to withdraw amount from Aave
  2. Transfers received tokens to vault
  3. Updates deposited tracker

harvest

Harvest accrued interest and send profits to vault. Process:
  1. Gets current aToken balance (collateral including interest)
  2. Calculates profit: aBal - deposited
  3. Withdraws profit amount from Aave
  4. Transfers profit to vault
Note: Keeps principal deposited; only harvests profits above deposited amount.

deleverageAll

Unwind leverage by repaying borrowed WETH.
uint256
required
Maximum iterations to prevent excessive gas usage
Process (each loop):
  1. Check current WETH debt
  2. Calculate LINK needed to repay (using oracle price + 5% buffer)
  3. Withdraw LINK from Aave collateral
  4. Swap LINK → WETH via DEX
  5. Repay WETH debt to Aave
  6. Update bookkeeping
  7. Repeat until debt is zero or maxLoops reached
Use Cases:
  • Before large withdrawals
  • Risk management during volatility
  • Emergency deleveraging
Example:

strategyBalance

Get net asset value of the leveraged position.
uint256
Net value (collateral + idle - debt)
Calculation:
  1. collateral = Aave supplied amount
  2. idle = Token balance on contract
  3. debtValue = WETH debt converted to LINK using oracle
  4. netValue = collateral + idle - debtValue
Example:

Configuration Functions

setLeverageParams

Update leverage parameters.
uint8
required
Maximum loop iterations (1-6)
uint256
required
Borrow percentage in basis points (max 8000 = 80%)
Safety Limits:
  • _maxDepth 6 (gas limit protection)
  • _borrowFactor 8000 (80% max to maintain safe LTV)
Example:

togglePause

Pause or unpause the strategy (emergency control). When Paused:
  • invest() reverts
  • deleverageAll() reverts
  • harvest() and withdrawToVault() still work (for emergency exits)

View Functions

getLeverageState

Get complete leverage state.
uint256
Total deposited principal
uint256
Total WETH borrowed
uint256
Net exposure (deposited - borrowed in asset terms)
uint256
Current maxDepth setting
uint8
Maximum allowed depth

getLTV

Get current Loan-to-Value ratio.
uint256
LTV ratio scaled by 1e18 (1e18 = 100%)
Formula: borrowedWETH * 1e18 / deposited Example:

isAtRisk

Check if position exceeds safe LTV threshold.
uint256
required
Maximum safe LTV in 1e18 scale (e.g., 0.75e18 = 75%)
bool
True if current LTV exceeds maxSafeLTV
Example:

Integration Example

Risk Management

Liquidation Risk

Market Volatility

Emergency Procedures

Performance Characteristics

Gas Costs (approximate per loop):
  • invest(): ~500k gas (3 loops = ~1.5M gas)
  • deleverageAll(): ~400k gas per loop
  • withdrawToVault(): ~250k gas
  • strategyBalance(): ~50k gas (view)
Yield Amplification:
  • 3 loops with 60% borrow: ~1.8x exposure
  • Base APY 5% → Effective ~9% (before borrow costs)
  • Must subtract WETH borrow APY
Risks:
  • Liquidation if LTV exceeds Aave threshold
  • DEX slippage on swaps
  • Oracle manipulation risk
  • Smart contract risk (Aave, DEX, Oracle)

Security Considerations

  1. Liquidation: Monitor LTV closely. Aave liquidates at ~80-85% LTV.
  2. Oracle Risk: Relies on oracle for deleverage calculations. Oracle failure could cause incorrect swaps.
  3. DEX Risk: Swaps use amountOutMin = 0 (no slippage protection in current implementation).
  4. Flash Loan Risk: Vulnerable to oracle manipulation via flash loans.
  5. Pause Mechanism: Router can pause strategy to prevent new investments during crises.

AI Agent Integration

See Also