Simulating Flash Loans
Contents
Overview | Prerequisites | Instructions | Output | Error Handling | Examples | Resources
Overview
Simulate flash loan strategies across Aave V3, dYdX, and Balancer with profitability calculations, gas cost estimation, and risk assessment. Evaluate flash loan opportunities without executing real transactions.
Prerequisites
- Install Python 3.9+ with
web3, httpx, and rich packages
- Configure RPC endpoint access (free public RPCs via https://chainlist.org work fine)
- Optionally add Etherscan API key for better gas estimates
- Set RPC in
${CLAUDE_SKILL_DIR}/config/settings.yaml or use ETH_RPC_URL env var
Instructions
- Simulate a two-DEX arbitrage with automatic fee and gas calculation:
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 \
--dex-buy uniswap --dex-sell sushiswap
- Compare flash loan providers to find the cheapest for your strategy:
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 --compare-providers
- Analyze liquidation profitability on lending protocols:
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py liquidation \
--protocol aave --health-factor 0.95
- Simulate triangular arbitrage with multi-hop circular paths:
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py triangular \
ETH USDC WBTC ETH --amount 50
- Add risk assessment (MEV competition, execution, protocol, liquidity) to any simulation:
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 --risk-analysis
- Run full analysis combining all features:
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 \
--full --output json > simulation.json
Output
- Quick Mode: Net profit/loss, provider recommendation, Go/No-Go verdict
- Breakdown Mode: Step-by-step transaction flow with individual cost components
- Comparison Mode: All providers ranked by net profit with fee differences
- Risk Analysis: Competition, execution, protocol, and liquidity scores (0-100) with viability grade (A-F)
See ${CLAUDE_SKILL_DIR}/references/implementation.md for detailed output examples and risk scoring methodology.
Error Handling
| Error |
Cause |
Solution |
| RPC Rate Limit |
Too many requests |
Switch to backup endpoint or wait |
| Stale Prices |
Data older than 30s |
Auto-refreshes with warning |
| No Profitable Route |
All routes lose after costs |
Try different pairs or amounts |
| Insufficient Liquidity |
Trade exceeds pool depth |
Reduce amount or split across pools |
See ${CLAUDE_SKILL_DIR}/references/errors.md for comprehensive error handling.
Examples
Basic arbitrage simulation:
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 \
--dex-buy uniswap --dex-sell sushiswap
Find cheapest provider:
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 --compare-providers
Liquidation opportunity scan:
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py liquidation --protocol aave --health-factor 0.95
See ${CLAUDE_SKILL_DIR}/references/examples.md for multi-provider comparison and backtesting examples.
Resources
1---2name: simulating-flash-loans3description: |4 Simulate flash loan strategies with profitability calculations and risk assessment across Aave, dYdX, and Balancer.5 Use when simulating flash loans, analyzing arbitrage profitability, evaluating liquidation opportunities, or comparing flash loan providers.6 Trigger with phrases like "simulate flash loan", "flash loan arbitrage", "liquidation profit", "compare Aave dYdX", "flash loan strategy", or "DeFi arbitrage simulation".78allowed-tools: Read, Write, Edit, Grep, Glob, Bash(crypto:flashloan-*)9version: 1.0.010author: Jeremy Longshore <jeremy@intentsolutions.io>11license: MIT12compatible-with: claude-code, codex, openclaw13tags: [crypto, simulating-flash]1415---1617# Simulating Flash Loans1819## Contents2021[Overview](#overview) | [Prerequisites](#prerequisites) | [Instructions](#instructions) | [Output](#output) | [Error Handling](#error-handling) | [Examples](#examples) | [Resources](#resources)2223## Overview2425Simulate flash loan strategies across Aave V3, dYdX, and Balancer with profitability calculations, gas cost estimation, and risk assessment. Evaluate flash loan opportunities without executing real transactions.2627## Prerequisites28291. Install Python 3.9+ with `web3`, `httpx`, and `rich` packages302. Configure RPC endpoint access (free public RPCs via https://chainlist.org work fine)313. Optionally add Etherscan API key for better gas estimates324. Set RPC in `${CLAUDE_SKILL_DIR}/config/settings.yaml` or use `ETH_RPC_URL` env var3334## Instructions35361. Simulate a two-DEX arbitrage with automatic fee and gas calculation:37 ```bash38 python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 \39 --dex-buy uniswap --dex-sell sushiswap40 ```412. Compare flash loan providers to find the cheapest for your strategy:42 ```bash43 python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 --compare-providers44 ```453. Analyze liquidation profitability on lending protocols:46 ```bash47 python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py liquidation \48 --protocol aave --health-factor 0.9549 ```504. Simulate triangular arbitrage with multi-hop circular paths:51 ```bash52 python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py triangular \53 ETH USDC WBTC ETH --amount 5054 ```555. Add risk assessment (MEV competition, execution, protocol, liquidity) to any simulation:56 ```bash57 python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 --risk-analysis58 ```596. Run full analysis combining all features:60 ```bash61 python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 \62 --full --output json > simulation.json63 ```6465## Output6667- **Quick Mode**: Net profit/loss, provider recommendation, Go/No-Go verdict68- **Breakdown Mode**: Step-by-step transaction flow with individual cost components69- **Comparison Mode**: All providers ranked by net profit with fee differences70- **Risk Analysis**: Competition, execution, protocol, and liquidity scores (0-100) with viability grade (A-F)7172See `${CLAUDE_SKILL_DIR}/references/implementation.md` for detailed output examples and risk scoring methodology.7374## Error Handling7576| Error | Cause | Solution |77|-------|-------|----------|78| RPC Rate Limit | Too many requests | Switch to backup endpoint or wait |79| Stale Prices | Data older than 30s | Auto-refreshes with warning |80| No Profitable Route | All routes lose after costs | Try different pairs or amounts |81| Insufficient Liquidity | Trade exceeds pool depth | Reduce amount or split across pools |8283See `${CLAUDE_SKILL_DIR}/references/errors.md` for comprehensive error handling.8485## Examples8687**Basic arbitrage simulation:**88```bash89python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 \90 --dex-buy uniswap --dex-sell sushiswap91```9293**Find cheapest provider:**94```bash95python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 --compare-providers96```9798**Liquidation opportunity scan:**99```bash100python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py liquidation --protocol aave --health-factor 0.95101```102103See `${CLAUDE_SKILL_DIR}/references/examples.md` for multi-provider comparison and backtesting examples.104105## Resources106107- `${CLAUDE_SKILL_DIR}/references/implementation.md` - Provider comparison, strategy details, risk scoring, output modes108- [Aave V3 Flash Loans](https://docs.aave.com/developers/guides/flash-loans)109- [dYdX Flash Loans](https://docs.dydx.exchange/developers/guides/flash-loans)110- [Balancer Flash Loans](https://docs.balancer.fi/concepts/advanced/flash-loans.html)111- [Flashbots Protect](https://docs.flashbots.net/flashbots-protect/overview)112