simulating-flash-loans
Simulate flash loan strategies with profitability calculations and risk assessment across Aave, dYdX, and Balancer. Use when simulating flash loans, analyzing arbitrage profitability, evaluating liquidation opportunities, or comparing flash loan providers. Trigger with phrases like "simulate flash loan", "flash loan arbitrage", "liquidation profit", "compare Aave dYdX", "flash loan strategy", or "DeFi arbitrage simulation".
- License 许可
- MIT
- 最近更新
- 2026-11-13
- Stars
- ★ 2.0k
- Forks
- 234
01 前言 Front Matter
- name
- simulating-flash-loans
- author
- Jeremy Longshore <jeremy@intentsolutions.io>
- license
- MIT
- version
- 1.0.0
- description
- Simulate flash loan strategies with profitability calculations and risk assessment across Aave, dYdX, and Balancer. Use when simulating flash loans, analyzing arbitrage profitability, evaluating liquidation opportunities, or comparing flash loan providers. Trigger with phrases like "simulate flash loan", "flash loan arbitrage", "liquidation profit", "compare Aave dYdX", "flash loan strategy", or "DeFi arbitrage simulation".
- allowed-tools
- Read, Write, Edit, Grep, Glob, Bash(crypto:flashloan-*)
02 资源文件 15
- 参考文档ARD.md21.3 KB
- 参考文档config/settings.yaml9.4 KB
- 许可证LICENSE1.0 KB
- 参考文档PRD.md8.7 KB
- 参考文档references/errors.md6.3 KB
- 参考文档references/examples.md14.8 KB
- 参考文档references/implementation.md1.3 KB
- 脚本scripts/flash_simulator.py15.1 KB
- 脚本scripts/formatters.py17.8 KB
- 脚本scripts/profit_calculator.py9.1 KB
- 脚本scripts/protocol_adapters.py11.9 KB
- 脚本scripts/risk_assessor.py13.0 KB
- 脚本scripts/strategy_engine.py18.9 KB
- 参考文档SOURCE.md421 B
- 参考文档TRUST.auto.yaml2.1 KB
03 SKILL.md 正文
Simulating Flash Loans
Overview
This skill simulates flash loan strategies across major DeFi protocols (Aave V3, dYdX, Balancer) with profitability calculations, gas cost estimation, and risk assessment. It enables developers and researchers to evaluate flash loan opportunities without executing real transactions.
Prerequisites
Before using this skill, ensure you have:
- Python 3.9+ with
web3,httpx, andrichpackages - RPC endpoint access (free public RPCs work fine)
- Understanding of flash loan mechanics and DeFi protocols
- Optional: Etherscan API key for better gas estimates
Instructions
Step 1: Configure RPC Endpoint
Configure your RPC in {baseDir}/config/settings.yaml:
# Free public RPCs (no signup required)
rpc_endpoints:
ethereum: "https://rpc.ankr.com/eth"
polygon: "https://rpc.ankr.com/polygon"
arbitrum: "https://rpc.ankr.com/arbitrum"
Or use environment variable:
export ETH_RPC_URL="https://rpc.ankr.com/eth"
Step 2: Simple Arbitrage Simulation
Simulate a basic two-DEX arbitrage:
python {baseDir}/scripts/flash_simulator.py arbitrage ETH USDC 100 \
--dex-buy uniswap --dex-sell sushiswap
This calculates:
- Gross profit from price difference
- Flash loan fee (provider-specific)
- Gas costs
- Net profit/loss
Step 3: Compare Flash Loan Providers
Find the cheapest provider for your strategy:
python {baseDir}/scripts/flash_simulator.py arbitrage ETH USDC 100 --compare-providers
Output shows:
| Provider | Fee | Net Profit |
|---|---|---|
| dYdX | 0% | $245.30 |
| Balancer | 0.01% | $242.80 |
| Aave V3 | 0.09% | $225.50 |
Step 4: Liquidation Profitability
Analyze liquidation opportunities:
python {baseDir}/scripts/flash_simulator.py liquidation \
--protocol aave --health-factor 0.95
Shows positions below health factor threshold with:
- Collateral value
- Debt value
- Liquidation bonus
- Net profit after costs
Step 5: Triangular Arbitrage
Simulate multi-hop circular arbitrage:
python {baseDir}/scripts/flash_simulator.py triangular \
ETH USDC WBTC ETH --amount 50
Analyzes path profitability:
Path: ETH → USDC → WBTC → ETH
Gross: +0.15 ETH
Fees: -0.045 ETH (3 swaps)
Loan: -0.045 ETH (Aave fee)
Gas: -0.02 ETH
─────────────────────
Net: +0.04 ETH ($101.73)
Step 6: Risk Assessment
Add risk analysis to any simulation:
python {baseDir}/scripts/flash_simulator.py arbitrage ETH USDC 100 --risk-analysis
Risk factors scored:
- MEV Competition: Bot activity on this pair
- Execution Risk: Slippage and timing sensitivity
- Protocol Risk: Smart contract and oracle risks
- Liquidity Risk: Depth available for trade size
Step 7: Full Analysis
Run complete analysis with all features:
python {baseDir}/scripts/flash_simulator.py arbitrage ETH USDC 100 \
--full --output json > simulation.json
Output
The simulator provides:
Quick Mode:
- Net profit/loss
- Provider recommendation
- Go/No-Go verdict
Breakdown Mode:
- Step-by-step transaction flow
- Individual cost components
- Slippage estimates
Comparison Mode:
- All providers ranked
- Fee differences
- Liquidity availability
Risk Analysis:
- Competition score (0-100)
- Execution probability
- Protocol safety rating
- Overall viability grade
Flash Loan Providers
| Provider | Fee | Best For | Chains |
|---|---|---|---|
| dYdX | 0% | Maximum profit | Ethereum |
| Balancer | 0.01% | Pool tokens | ETH, Polygon, Arbitrum |
| Aave V3 | 0.09% | Any token | ETH, Polygon, Arbitrum, Optimism |
| Uniswap V3 | ~0.3% | Specific pairs | ETH, Polygon, Arbitrum |
Supported Strategies
- Simple Arbitrage: Buy on DEX A, sell on DEX B
- Triangular Arbitrage: A→B→C→A circular path
- Liquidation: Repay debt, claim collateral bonus
- Collateral Swap: Replace collateral without closing
- Self-Liquidation: Efficiently close own position
- Debt Refinancing: Move debt to better rates
Error Handling
See {baseDir}/references/errors.md for comprehensive error handling.
Common issues:
- RPC Rate Limit: Switch to backup endpoint or wait
- Stale Prices: Data older than 30s triggers warning
- No Profitable Route: All routes lose money after costs
- Insufficient Liquidity: Trade size exceeds pool depth
Examples
See {baseDir}/references/examples.md for detailed examples including:
- ETH/USDC arbitrage simulation
- Aave liquidation analysis
- Multi-provider comparison
- Historical backtesting
Educational Disclaimer
FOR EDUCATIONAL PURPOSES ONLY
Flash loan strategies involve significant risks:
- Smart contract bugs can cause total loss
- MEV bots compete for same opportunities
- Gas costs can exceed profits
- Protocol exploits may have legal implications
Never deploy unaudited code. Start with testnets. Consult legal counsel.
Resources
04 同仓库更多 Skills
web-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use for complex artifacts requiring state management, routing, or shadcn/ui components - not for simple single-file HTML/JSX artifacts.
webapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
neuropixels-analysis
Neuropixels neural recording analysis. Load SpikeGLX/OpenEphys data, preprocess, motion correction, Kilosort4 spike sorting, quality metrics, Allen/IBL curation, AI-assisted visual analysis, for Neuropixels 1.0/2.0 extracellular electrophysiology. Use when working with neural recordings, spike sorting, extracellular electrophysiology, or when the user mentions Neuropixels, SpikeGLX, Open Ephys, Kilosort, quality metrics, or unit curation.
skill-creator
Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.
notebooklm
Use this skill to query your Google NotebookLM notebooks directly from Claude Code for source-grounded, citation-backed answers from Gemini. Browser automation, library management, persistent auth. Drastically reduced hallucinations through document-only responses.
slack-gif-creator
Knowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."