Overview
TheStrategyAaveLeverage 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:
- Supply LINK as collateral
- Borrow WETH against LINK
- Swap WETH → LINK via DEX
- Supply newly acquired LINK
- 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
- Approves pool to spend unlimited tokens
- Approves swap router to spend unlimited WETH
- Sets all immutable references
Core Strategy Functions
invest
uint256
required
Initial amount to invest (already transferred to strategy)
- Strategy must not be paused
- Strategy must hold sufficient token balance
- Only callable by router
- Supply initial
amountas collateral - Loop up to
maxDepthtimes:- Calculate safe borrow amount (limited by pool liquidity)
- Borrow WETH from Aave
- Swap WETH → LINK via DEX
- Supply received LINK as additional collateral
- Update bookkeeping (
deposited,borrowedWETH)
- 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
withdrawToVault
uint256
required
Amount of underlying to withdraw
uint256
Actual amount withdrawn and sent to vault
deleverageAll() first if needed.
Process:
- Attempts to withdraw
amountfrom Aave - Transfers received tokens to vault
- Updates
depositedtracker
harvest
- Gets current aToken balance (collateral including interest)
- Calculates profit:
aBal - deposited - Withdraws profit amount from Aave
- Transfers profit to vault
deleverageAll
uint256
required
Maximum iterations to prevent excessive gas usage
- Check current WETH debt
- Calculate LINK needed to repay (using oracle price + 5% buffer)
- Withdraw LINK from Aave collateral
- Swap LINK → WETH via DEX
- Repay WETH debt to Aave
- Update bookkeeping
- Repeat until debt is zero or maxLoops reached
- Before large withdrawals
- Risk management during volatility
- Emergency deleveraging
strategyBalance
uint256
Net value (collateral + idle - debt)
collateral= Aave supplied amountidle= Token balance on contractdebtValue= WETH debt converted to LINK using oraclenetValue= collateral + idle - debtValue
Configuration Functions
setLeverageParams
uint8
required
Maximum loop iterations (1-6)
uint256
required
Borrow percentage in basis points (max 8000 = 80%)
_maxDepth6 (gas limit protection)_borrowFactor8000 (80% max to maintain safe LTV)
togglePause
invest()revertsdeleverageAll()revertsharvest()andwithdrawToVault()still work (for emergency exits)
View Functions
getLeverageState
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
uint256
LTV ratio scaled by 1e18 (1e18 = 100%)
borrowedWETH * 1e18 / deposited
Example:
isAtRisk
uint256
required
Maximum safe LTV in 1e18 scale (e.g., 0.75e18 = 75%)
bool
True if current LTV exceeds maxSafeLTV
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 loopwithdrawToVault(): ~250k gasstrategyBalance(): ~50k gas (view)
- 3 loops with 60% borrow: ~1.8x exposure
- Base APY 5% → Effective ~9% (before borrow costs)
- Must subtract WETH borrow APY
- Liquidation if LTV exceeds Aave threshold
- DEX slippage on swaps
- Oracle manipulation risk
- Smart contract risk (Aave, DEX, Oracle)
Security Considerations
- Liquidation: Monitor LTV closely. Aave liquidates at ~80-85% LTV.
- Oracle Risk: Relies on oracle for deleverage calculations. Oracle failure could cause incorrect swaps.
- DEX Risk: Swaps use
amountOutMin = 0(no slippage protection in current implementation). - Flash Loan Risk: Vulnerable to oracle manipulation via flash loans.
- Pause Mechanism: Router can pause strategy to prevent new investments during crises.
AI Agent Integration
See Also
- StrategyAave - Simple non-leveraged version
- StrategyRouter - Controls leverage strategies
- Vault - User-facing vault
- Aave V3 Liquidation Docs - Liquidation mechanics