Overview
This guide walks you through running the canonical ANK example: a cross-protocol leverage loop that borrows ETH from Aave, stakes it in Lido for wstETH, deposits the wstETH back to Aave as collateral, and repeats the process to reach a target loan-to-value (LTV) ratio.Create a configuration file
Create a file named
sim.yaml with the following contents:sim.yaml
Configuration breakdown:
steps: Number of ticks to simulate (24 in this example)start_ts: Simulation start time in Unix seconds (plain integer, no underscores)user: User ID for the simulationleverage.target_ltv_bps: Target LTV in basis points (7000 = 70%)leverage.band_bps: Rebalancing band (250 = ±2.5%)
Observe the execution
You should see output similar to:What’s happening:
- Tick 0: Initial
stakeof ETH to receive wstETH, thendepositwstETH to Aave as collateral - Each subsequent tick:
- Sync Aave’s wstETH price from Lido exchange rate × ETH price
- Controller checks current LTV:
- Below band →
borrowETH →staketo Lido →depositwstETH (next tick) - Above band →
repaydebt; if wallet ETH is insufficient →withdrawwstETH →unstake→repay(mandatory unwind)
- Below band →
Review the risk output
Open Key columns:
risk_out.csv to see per-tick metrics:ltv_bps: Current loan-to-value in basis pointshf_bps: Health factor in basis points (10000 = 1.0; below 10000 triggers liquidation)net_value_e18: Wallet + deposits - debt in 1e18 unitsdrawdown_e18: Maximum drawdown from peak net value
Understanding the strategy
The leverage loop strategy automatically manages your LTV:Adding price shocks
You can stress-test your strategy by providing custom price paths:Create a price CSV
Create
prices.csv with the following structure:prices.csv
- Column 1 (
ts): Unix timestamp - Column 2 (
token): Token ID (1 = ETH, 3 = wstETH) - Column 3 (
price_e18): Price in 1e18 units (2000e18 = $2000)
Next steps
Parameter optimization
Use the
optimize binary to sweep target LTV, bands, and initial depositsProtocol reference
Learn about Aave, Lido, Uniswap, and Pendle protocol APIs
Custom strategies
Build your own strategy using the planner closure pattern
Risk analytics
Deep dive into LTV, health factor, drawdown, and volatility calculations