# ๐Ÿ“‹ DeFi Strategy Testing Scenarios This directory contains example scenarios for testing DeFi strategies using the DeFi Strategy Testing CLI. --- ## ๐Ÿ“š Example Scenarios ### ๐Ÿฆ Aave v3 #### ๐Ÿ“ˆ Leveraged Long Strategy **File**: `leveraged-long.yml` A leveraged long strategy using Aave v3: - โœ… Supplies WETH as collateral - โœ… Borrows USDC - โœ… Swaps USDC to WETH to increase exposure - โœ… Validates health factor remains safe #### ๐Ÿ’ฅ Liquidation Drill **File**: `liquidation-drill.yml` Tests liquidation scenarios: - โœ… Sets up a position near liquidation threshold - โœ… Applies oracle shock - โœ… Validates health factor drops below 1.0 - โœ… Repays debt to recover ### ๐Ÿ›๏ธ Compound v3 #### ๐Ÿ’ฐ Supply and Borrow **File**: `supply-borrow.yml` Basic Compound v3 supply and borrow: - โœ… Supplies WETH as collateral - โœ… Borrows USDC (base asset) - โœ… Validates borrow balance - โœ… Repays part of debt --- ## ๐Ÿš€ Running Scenarios ### Basic Run ```bash # Run a scenario pnpm run strat:run scenarios/aave/leveraged-long.yml ``` ### With Custom Network ```bash # Run with custom network pnpm run strat:run scenarios/aave/leveraged-long.yml --network base ``` ### Generate Reports ```bash # Generate JSON and HTML reports pnpm run strat:run scenarios/aave/leveraged-long.yml \ --report out/run.json \ --html out/report.html ``` --- ## ๐Ÿ“ Scenario Format Scenarios are defined in YAML or JSON format: ```yaml version: 1 network: mainnet protocols: [aave-v3, uniswap-v3] assumptions: baseCurrency: USD slippageBps: 30 minHealthFactor: 1.05 accounts: trader: funded: - token: WETH amount: "5" steps: - name: Supply WETH action: aave-v3.supply args: asset: WETH amount: "5" onBehalfOf: $accounts.trader assert: - aave-v3.healthFactor >= 1.5 ``` --- ## ๐Ÿ”Œ Supported Actions ### ๐Ÿฆ Aave v3 | Action | Description | |--------|-------------| | `aave-v3.supply` | Supply assets to Aave | | `aave-v3.withdraw` | Withdraw assets from Aave | | `aave-v3.borrow` | Borrow assets from Aave | | `aave-v3.repay` | Repay borrowed assets | | `aave-v3.flashLoanSimple` | Execute a flash loan | ### ๐Ÿ›๏ธ Compound v3 | Action | Description | |--------|-------------| | `compound-v3.supply` | Supply collateral to Compound v3 | | `compound-v3.withdraw` | Withdraw collateral or base asset | | `compound-v3.borrow` | Borrow base asset (withdraws base asset) | | `compound-v3.repay` | Repay debt (supplies base asset) | ### ๐Ÿ”„ Uniswap v3 | Action | Description | |--------|-------------| | `uniswap-v3.exactInputSingle` | Execute an exact input swap | | `uniswap-v3.exactOutputSingle` | Execute an exact output swap | ### ๐Ÿ’ฐ ERC20 | Action | Description | |--------|-------------| | `erc20.approve` | Approve token spending | ### ๐Ÿ’ฅ Failure Injection | Action | Description | |--------|-------------| | `failure.oracleShock` | Inject an oracle price shock | | `failure.timeTravel` | Advance time | | `failure.setTimestamp` | Set block timestamp | | `failure.liquidityShock` | Move liquidity | | `failure.setBaseFee` | Set gas price | | `failure.pauseReserve` | Pause a reserve (Aave) | | `failure.capExhaustion` | Simulate cap exhaustion | --- ## โœ… Assertions Assertions can be added to any step: ```yaml steps: - name: Check health factor action: assert args: expression: "aave-v3.healthFactor >= 1.05" ``` ### Supported Assertion Formats | Format | Example | Description | |--------|---------|-------------| | Protocol views | `aave-v3.healthFactor >= 1.05` | Compare protocol view values | | Comparisons | `>=`, `<=`, `>`, `<`, `==`, `!=` | Standard comparison operators | --- ## ๐ŸŒ Network Support | Network | Chain ID | Status | |---------|----------|--------| | Ethereum Mainnet | 1 | โœ… | | Base | 8453 | โœ… | | Arbitrum One | 42161 | โœ… | | Optimism | 10 | โœ… | | Polygon | 137 | โœ… | > ๐Ÿ’ก Or use chain IDs directly: `--network 1` for mainnet. --- ## ๐Ÿ“– Next Steps - ๐Ÿ“š Read the [Strategy Testing Guide](../docs/STRATEGY_TESTING.md) for comprehensive documentation - ๐ŸŽฏ Explore example scenarios in this directory - ๐Ÿงช Try running scenarios with different parameters - ๐Ÿ’ฅ Experiment with failure injection scenarios