Protocol trait, enabling deterministic simulation of complex DeFi strategies across multiple protocols.
Supported Protocols
Aave V3
Multi-asset lending with variable debt accrual, liquidations, and dynamic pricing
Lido wstETH
Liquid staking with exchange rate growth and auto-sync with Aave collateral
Uniswap V3
Concentrated liquidity AMM with position management and swaps
Pendle
Principal and yield token splitting with V2 AMM
Hyperliquid
Perpetual futures with margin trading, funding rates, and liquidations
Protocol Trait
All protocols implement a common interface:Key Methods
on_tick: Called each simulation tick to accrue interest, update rates, apply funding, etc.execute: Routes user actions (deposits, borrows, swaps) and returns balance deltasview_user: Returns user position state (deposits, debts, shares, etc.)view_market: Returns protocol-level state (prices, rates, liquidity, etc.)apply_historical: Replays historical events to mutate protocol state before simulation
Registry Setup
Protocols are registered in a map and routed by the Engine:Token Conventions
By convention, token IDs are:1 = ETH2 = USDC3 = wstETH(Lido)4 = SY(Pendle)5 = PT(Pendle)6 = YT(Pendle)7 = LP(Pendle)
Cross-Protocol Strategies
The modular design enables complex cross-protocol strategies:Simulation Lifecycle
- Initialization: Protocols are configured and registered
- Per-tick:
- Engine calls
on_tick()for each protocol (accrual, funding, etc.) - Strategy planner inspects state via
view_user()/view_market() - Engine routes
TxBundleactions to protocols viaexecute() - Balance deltas are applied to user wallets
- Engine calls
- Replay (optional):
apply_historical()mutates protocol state from CSV events
Determinism
All protocols are deterministic:- Time-based accrual is tick-driven (not wall-clock)
- No external oracle calls during simulation
- Prices are set explicitly via actions or oracle CSV
- RNG is not used; all math is fixed-point (RAY/WAD)