@intentsolutionsio/flash-loan-simulator 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +22 -0
- package/LICENSE +21 -0
- package/README.md +411 -0
- package/agents/flashloan-agent.md +261 -0
- package/package.json +43 -0
- package/skills/simulating-flash-loans/ARD.md +454 -0
- package/skills/simulating-flash-loans/PRD.md +239 -0
- package/skills/simulating-flash-loans/SKILL.md +109 -0
- package/skills/simulating-flash-loans/config/settings.yaml +241 -0
- package/skills/simulating-flash-loans/references/errors.md +297 -0
- package/skills/simulating-flash-loans/references/examples.md +532 -0
- package/skills/simulating-flash-loans/references/implementation.md +73 -0
- package/skills/simulating-flash-loans/scripts/flash_simulator.py +492 -0
- package/skills/simulating-flash-loans/scripts/formatters.py +512 -0
- package/skills/simulating-flash-loans/scripts/profit_calculator.py +315 -0
- package/skills/simulating-flash-loans/scripts/protocol_adapters.py +416 -0
- package/skills/simulating-flash-loans/scripts/risk_assessor.py +439 -0
- package/skills/simulating-flash-loans/scripts/strategy_engine.py +596 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# PRD: Flash Loan Simulator
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
**One-liner**: Simulate and analyze flash loan strategies with profitability calculations and risk assessment
|
|
6
|
+
**Domain**: Cryptocurrency / DeFi / Flash Loans
|
|
7
|
+
**Users**: DeFi Developers, Arbitrage Researchers, Smart Contract Auditors
|
|
8
|
+
|
|
9
|
+
## Problem Statement
|
|
10
|
+
|
|
11
|
+
Flash loans are powerful DeFi primitives that allow borrowing any amount without collateral, provided the loan is repaid within the same transaction. However, evaluating flash loan strategies is challenging:
|
|
12
|
+
|
|
13
|
+
1. No easy way to simulate complex multi-step transactions before deployment
|
|
14
|
+
2. Profitability calculations require accounting for gas, fees, and slippage
|
|
15
|
+
3. Competition from MEV bots makes many strategies unprofitable
|
|
16
|
+
4. Risk assessment requires understanding multiple protocols simultaneously
|
|
17
|
+
5. Real execution on mainnet is expensive and risky for testing
|
|
18
|
+
6. Historical backtesting requires archive node access and complex setup
|
|
19
|
+
|
|
20
|
+
## Target Users
|
|
21
|
+
|
|
22
|
+
### Persona 1: DeFi Developer
|
|
23
|
+
- **Profile**: Building flash loan arbitrage bots or liquidation systems
|
|
24
|
+
- **Pain Points**: Testing on mainnet is expensive; needs simulation before deployment
|
|
25
|
+
- **Goals**: Validate profitability; optimize gas usage; identify edge cases
|
|
26
|
+
- **Usage Pattern**: Daily simulation runs during development cycle
|
|
27
|
+
|
|
28
|
+
### Persona 2: Arbitrage Researcher
|
|
29
|
+
- **Profile**: Analyzes DeFi protocols for arbitrage opportunities
|
|
30
|
+
- **Pain Points**: Manual calculation of multi-hop arbitrage is error-prone
|
|
31
|
+
- **Goals**: Quickly evaluate opportunities; backtest historical scenarios
|
|
32
|
+
- **Usage Pattern**: Continuous opportunity scanning and analysis
|
|
33
|
+
|
|
34
|
+
### Persona 3: Smart Contract Auditor
|
|
35
|
+
- **Profile**: Reviews DeFi protocols for vulnerabilities
|
|
36
|
+
- **Pain Points**: Needs to simulate attack vectors without executing them
|
|
37
|
+
- **Goals**: Understand flash loan attack scenarios; verify protocol safety
|
|
38
|
+
- **Usage Pattern**: Deep-dive analysis during security audits
|
|
39
|
+
|
|
40
|
+
## User Stories
|
|
41
|
+
|
|
42
|
+
### Critical (P0)
|
|
43
|
+
|
|
44
|
+
1. **As a DeFi developer**, I want to simulate a flash loan arbitrage between two DEXs, so that I can verify profitability before deploying my contract.
|
|
45
|
+
- **Acceptance Criteria**:
|
|
46
|
+
- Input: Token pair, loan amount, source DEX, target DEX
|
|
47
|
+
- Output: Expected profit/loss after all fees
|
|
48
|
+
- Includes gas cost estimation at current prices
|
|
49
|
+
- Shows breakdown of each transaction step
|
|
50
|
+
|
|
51
|
+
2. **As a researcher**, I want to calculate liquidation profitability on Aave, so that I can identify profitable opportunities.
|
|
52
|
+
- **Acceptance Criteria**:
|
|
53
|
+
- Input: Borrower address or health factor threshold
|
|
54
|
+
- Output: Liquidation bonus minus costs
|
|
55
|
+
- Shows collateral and debt values
|
|
56
|
+
- Estimates competition level
|
|
57
|
+
|
|
58
|
+
3. **As a developer**, I want to compare flash loan providers, so that I can choose the cheapest option.
|
|
59
|
+
- **Acceptance Criteria**:
|
|
60
|
+
- Compare Aave (0.09%), dYdX (0%), Balancer (variable)
|
|
61
|
+
- Account for available liquidity per asset
|
|
62
|
+
- Show total cost including gas differences
|
|
63
|
+
|
|
64
|
+
### Important (P1)
|
|
65
|
+
|
|
66
|
+
4. **As a researcher**, I want to simulate triangular arbitrage, so that I can evaluate multi-hop strategies.
|
|
67
|
+
- **Acceptance Criteria**:
|
|
68
|
+
- Support 3+ DEX paths
|
|
69
|
+
- Calculate cumulative slippage
|
|
70
|
+
- Show optimal route and amounts
|
|
71
|
+
|
|
72
|
+
5. **As a developer**, I want to backtest strategies against historical data, so that I can validate my approach.
|
|
73
|
+
- **Acceptance Criteria**:
|
|
74
|
+
- Input: Strategy parameters, date range
|
|
75
|
+
- Output: Historical profit/loss per opportunity
|
|
76
|
+
- Shows win rate and average profit
|
|
77
|
+
|
|
78
|
+
### Nice-to-Have (P2)
|
|
79
|
+
|
|
80
|
+
6. **As an auditor**, I want to simulate flash loan attack scenarios, so that I can test protocol security.
|
|
81
|
+
- **Acceptance Criteria**:
|
|
82
|
+
- Template attack patterns (price manipulation, governance, etc.)
|
|
83
|
+
- Safe simulation without actual execution
|
|
84
|
+
- Detailed transaction trace
|
|
85
|
+
|
|
86
|
+
## Functional Requirements
|
|
87
|
+
|
|
88
|
+
### Core Features
|
|
89
|
+
|
|
90
|
+
- **REQ-1**: Flash Loan Provider Support
|
|
91
|
+
- Aave V3 (0.09% fee, multi-chain)
|
|
92
|
+
- dYdX (0% fee, ETH mainnet)
|
|
93
|
+
- Balancer (variable fee, multi-chain)
|
|
94
|
+
- Uniswap V3 flash swaps (implicit fee)
|
|
95
|
+
|
|
96
|
+
- **REQ-2**: Strategy Simulation Engine
|
|
97
|
+
- Simple arbitrage (2 DEX)
|
|
98
|
+
- Triangular arbitrage (3+ DEX)
|
|
99
|
+
- Liquidation profitability
|
|
100
|
+
- Collateral swap simulation
|
|
101
|
+
- Debt refinancing analysis
|
|
102
|
+
|
|
103
|
+
- **REQ-3**: Profitability Calculator
|
|
104
|
+
- Gross profit from price differences
|
|
105
|
+
- Flash loan fee deduction
|
|
106
|
+
- Gas cost estimation (EIP-1559)
|
|
107
|
+
- Slippage impact modeling
|
|
108
|
+
- Net profit/loss after all costs
|
|
109
|
+
|
|
110
|
+
- **REQ-4**: Risk Assessment
|
|
111
|
+
- MEV competition analysis
|
|
112
|
+
- Execution risk scoring
|
|
113
|
+
- Protocol risk factors
|
|
114
|
+
- Liquidity depth checks
|
|
115
|
+
|
|
116
|
+
- **REQ-5**: RPC Configuration
|
|
117
|
+
- Free public RPCs (Ankr, Chainstack, Infura)
|
|
118
|
+
- Custom RPC endpoint support
|
|
119
|
+
- Multi-chain configuration
|
|
120
|
+
- Automatic fallback
|
|
121
|
+
|
|
122
|
+
### Supported Strategies
|
|
123
|
+
|
|
124
|
+
| Strategy | Description | Complexity |
|
|
125
|
+
|----------|-------------|------------|
|
|
126
|
+
| Simple Arbitrage | Buy low on DEX A, sell high on DEX B | Low |
|
|
127
|
+
| Triangular Arbitrage | A→B→C→A circular trading | Medium |
|
|
128
|
+
| Liquidation | Repay debt, claim collateral bonus | Medium |
|
|
129
|
+
| Collateral Swap | Replace collateral without closing position | Medium |
|
|
130
|
+
| Self-Liquidation | Efficiently close own position | Low |
|
|
131
|
+
| Debt Refinancing | Move debt to better rates | High |
|
|
132
|
+
|
|
133
|
+
## Non-Goals
|
|
134
|
+
|
|
135
|
+
- **NOT** executing real flash loans (simulation only)
|
|
136
|
+
- **NOT** generating production-ready Solidity code
|
|
137
|
+
- **NOT** real-time opportunity alerts (analysis only)
|
|
138
|
+
- **NOT** MEV protection or Flashbots integration
|
|
139
|
+
- **NOT** managing private keys or signing transactions
|
|
140
|
+
|
|
141
|
+
## API Integrations
|
|
142
|
+
|
|
143
|
+
| API | Purpose | Auth | Rate Limits |
|
|
144
|
+
|-----|---------|------|-------------|
|
|
145
|
+
| Ankr RPC | Free blockchain queries | None | 30 req/sec |
|
|
146
|
+
| Chainstack Free | RPC | API Key | 25 req/sec |
|
|
147
|
+
| DeFiLlama | TVL and protocol data | None | Generous |
|
|
148
|
+
| Etherscan | Gas oracle, contract ABIs | API Key | 5 req/sec |
|
|
149
|
+
| Infura Free | RPC with archive data | API Key | 10 req/sec |
|
|
150
|
+
| The Graph | DEX subgraph queries | None | Varies |
|
|
151
|
+
|
|
152
|
+
## Success Metrics
|
|
153
|
+
|
|
154
|
+
| Metric | Target | Measurement |
|
|
155
|
+
|--------|--------|-------------|
|
|
156
|
+
| Simulation Accuracy | Within 5% of actual profit | Backtest vs. historical |
|
|
157
|
+
| Strategy Coverage | 6 strategy types | Feature completeness |
|
|
158
|
+
| Response Time | <5 seconds per simulation | Performance monitoring |
|
|
159
|
+
| Free RPC Usage | 100% usable without paid tier | User feedback |
|
|
160
|
+
|
|
161
|
+
## UX Flow
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
1. User Input
|
|
165
|
+
├── Strategy type (arbitrage, liquidation, etc.)
|
|
166
|
+
├── Parameters (tokens, amounts, DEXs)
|
|
167
|
+
├── Chain (Ethereum, Polygon, Arbitrum)
|
|
168
|
+
└── RPC endpoint (default: free public)
|
|
169
|
+
|
|
170
|
+
2. Data Collection
|
|
171
|
+
├── Fetch current prices from DEXs
|
|
172
|
+
├── Query protocol state (Aave positions, etc.)
|
|
173
|
+
├── Get gas prices and estimates
|
|
174
|
+
└── Check liquidity depth
|
|
175
|
+
|
|
176
|
+
3. Simulation Engine
|
|
177
|
+
├── Calculate gross profit
|
|
178
|
+
├── Deduct flash loan fees
|
|
179
|
+
├── Subtract gas costs
|
|
180
|
+
├── Apply slippage model
|
|
181
|
+
└── Compute net profit/loss
|
|
182
|
+
|
|
183
|
+
4. Risk Analysis
|
|
184
|
+
├── Score MEV competition risk
|
|
185
|
+
├── Check execution feasibility
|
|
186
|
+
├── Assess protocol risks
|
|
187
|
+
└── Rate overall viability
|
|
188
|
+
|
|
189
|
+
5. Results Output
|
|
190
|
+
├── Profit/loss breakdown
|
|
191
|
+
├── Step-by-step transaction flow
|
|
192
|
+
├── Risk assessment summary
|
|
193
|
+
└── Recommendations
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Constraints & Assumptions
|
|
197
|
+
|
|
198
|
+
### Constraints
|
|
199
|
+
- Free RPC endpoints have rate limits (25-100 req/sec)
|
|
200
|
+
- Historical simulations require archive node access
|
|
201
|
+
- Gas estimates are approximations (actual may vary ±20%)
|
|
202
|
+
- Price data has latency (not real-time MEV-competitive)
|
|
203
|
+
|
|
204
|
+
### Assumptions
|
|
205
|
+
- User understands DeFi and flash loan concepts
|
|
206
|
+
- User has access to RPC endpoint (free or paid)
|
|
207
|
+
- Simulation results are for analysis, not execution
|
|
208
|
+
- Market conditions change; simulations are point-in-time
|
|
209
|
+
|
|
210
|
+
## Risk Assessment
|
|
211
|
+
|
|
212
|
+
| Risk | Likelihood | Impact | Mitigation |
|
|
213
|
+
|------|------------|--------|------------|
|
|
214
|
+
| Stale price data | High | Medium | Clear timestamp warnings |
|
|
215
|
+
| RPC rate limiting | Medium | Low | Multi-provider fallback |
|
|
216
|
+
| Inaccurate gas estimate | Medium | Medium | Add safety margin to calculations |
|
|
217
|
+
| Strategy already exploited | High | Low | Competition scoring in output |
|
|
218
|
+
| Protocol changes | Low | High | Version-aware protocol configs |
|
|
219
|
+
|
|
220
|
+
## Educational Disclaimer
|
|
221
|
+
|
|
222
|
+
**IMPORTANT**: This tool is for **educational and research purposes only**. Flash loan strategies involve significant risks:
|
|
223
|
+
|
|
224
|
+
- Smart contract bugs can cause total loss of funds
|
|
225
|
+
- MEV bots compete for the same opportunities
|
|
226
|
+
- Gas costs can exceed profits
|
|
227
|
+
- Protocol exploits may have legal implications
|
|
228
|
+
|
|
229
|
+
Users should:
|
|
230
|
+
- Never deploy unaudited code
|
|
231
|
+
- Start with testnets before mainnet
|
|
232
|
+
- Understand the risks fully
|
|
233
|
+
- Consult legal counsel if needed
|
|
234
|
+
|
|
235
|
+
## Version History
|
|
236
|
+
|
|
237
|
+
| Version | Date | Author | Changes |
|
|
238
|
+
|---------|------|--------|---------|
|
|
239
|
+
| 1.0.0 | 2025-01-15 | Claude | Initial PRD |
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: simulating-flash-loans
|
|
3
|
+
description: |
|
|
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".
|
|
7
|
+
|
|
8
|
+
allowed-tools: Read, Write, Edit, Grep, Glob, Bash(crypto:flashloan-*)
|
|
9
|
+
version: 1.0.0
|
|
10
|
+
author: Jeremy Longshore <jeremy@intentsolutions.io>
|
|
11
|
+
license: MIT
|
|
12
|
+
compatible-with: claude-code, codex, openclaw
|
|
13
|
+
tags: [crypto, simulating-flash]
|
|
14
|
+
---
|
|
15
|
+
# Simulating Flash Loans
|
|
16
|
+
|
|
17
|
+
## Contents
|
|
18
|
+
|
|
19
|
+
[Overview](#overview) | [Prerequisites](#prerequisites) | [Instructions](#instructions) | [Output](#output) | [Error Handling](#error-handling) | [Examples](#examples) | [Resources](#resources)
|
|
20
|
+
|
|
21
|
+
## Overview
|
|
22
|
+
|
|
23
|
+
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.
|
|
24
|
+
|
|
25
|
+
## Prerequisites
|
|
26
|
+
|
|
27
|
+
1. Install Python 3.9+ with `web3`, `httpx`, and `rich` packages
|
|
28
|
+
2. Configure RPC endpoint access (free public RPCs via https://chainlist.org work fine)
|
|
29
|
+
3. Optionally add Etherscan API key for better gas estimates
|
|
30
|
+
4. Set RPC in `${CLAUDE_SKILL_DIR}/config/settings.yaml` or use `ETH_RPC_URL` env var
|
|
31
|
+
|
|
32
|
+
## Instructions
|
|
33
|
+
|
|
34
|
+
1. Simulate a two-DEX arbitrage with automatic fee and gas calculation:
|
|
35
|
+
```bash
|
|
36
|
+
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 \
|
|
37
|
+
--dex-buy uniswap --dex-sell sushiswap
|
|
38
|
+
```
|
|
39
|
+
2. Compare flash loan providers to find the cheapest for your strategy:
|
|
40
|
+
```bash
|
|
41
|
+
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 --compare-providers
|
|
42
|
+
```
|
|
43
|
+
3. Analyze liquidation profitability on lending protocols:
|
|
44
|
+
```bash
|
|
45
|
+
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py liquidation \
|
|
46
|
+
--protocol aave --health-factor 0.95
|
|
47
|
+
```
|
|
48
|
+
4. Simulate triangular arbitrage with multi-hop circular paths:
|
|
49
|
+
```bash
|
|
50
|
+
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py triangular \
|
|
51
|
+
ETH USDC WBTC ETH --amount 50
|
|
52
|
+
```
|
|
53
|
+
5. Add risk assessment (MEV competition, execution, protocol, liquidity) to any simulation:
|
|
54
|
+
```bash
|
|
55
|
+
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 --risk-analysis
|
|
56
|
+
```
|
|
57
|
+
6. Run full analysis combining all features:
|
|
58
|
+
```bash
|
|
59
|
+
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 \
|
|
60
|
+
--full --output json > simulation.json
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Output
|
|
64
|
+
|
|
65
|
+
- **Quick Mode**: Net profit/loss, provider recommendation, Go/No-Go verdict
|
|
66
|
+
- **Breakdown Mode**: Step-by-step transaction flow with individual cost components
|
|
67
|
+
- **Comparison Mode**: All providers ranked by net profit with fee differences
|
|
68
|
+
- **Risk Analysis**: Competition, execution, protocol, and liquidity scores (0-100) with viability grade (A-F)
|
|
69
|
+
|
|
70
|
+
See `${CLAUDE_SKILL_DIR}/references/implementation.md` for detailed output examples and risk scoring methodology.
|
|
71
|
+
|
|
72
|
+
## Error Handling
|
|
73
|
+
|
|
74
|
+
| Error | Cause | Solution |
|
|
75
|
+
|-------|-------|----------|
|
|
76
|
+
| RPC Rate Limit | Too many requests | Switch to backup endpoint or wait |
|
|
77
|
+
| Stale Prices | Data older than 30s | Auto-refreshes with warning |
|
|
78
|
+
| No Profitable Route | All routes lose after costs | Try different pairs or amounts |
|
|
79
|
+
| Insufficient Liquidity | Trade exceeds pool depth | Reduce amount or split across pools |
|
|
80
|
+
|
|
81
|
+
See `${CLAUDE_SKILL_DIR}/references/errors.md` for comprehensive error handling.
|
|
82
|
+
|
|
83
|
+
## Examples
|
|
84
|
+
|
|
85
|
+
**Basic arbitrage simulation:**
|
|
86
|
+
```bash
|
|
87
|
+
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 \
|
|
88
|
+
--dex-buy uniswap --dex-sell sushiswap
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Find cheapest provider:**
|
|
92
|
+
```bash
|
|
93
|
+
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py arbitrage ETH USDC 100 --compare-providers
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Liquidation opportunity scan:**
|
|
97
|
+
```bash
|
|
98
|
+
python ${CLAUDE_SKILL_DIR}/scripts/flash_simulator.py liquidation --protocol aave --health-factor 0.95
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
See `${CLAUDE_SKILL_DIR}/references/examples.md` for multi-provider comparison and backtesting examples.
|
|
102
|
+
|
|
103
|
+
## Resources
|
|
104
|
+
|
|
105
|
+
- `${CLAUDE_SKILL_DIR}/references/implementation.md` - Provider comparison, strategy details, risk scoring, output modes
|
|
106
|
+
- [Aave V3 Flash Loans](https://docs.aave.com/developers/guides/flash-loans)
|
|
107
|
+
- [dYdX Flash Loans](https://docs.dydx.exchange/developers/guides/flash-loans)
|
|
108
|
+
- [Balancer Flash Loans](https://docs.balancer.fi/concepts/advanced/flash-loans.html)
|
|
109
|
+
- [Flashbots Protect](https://docs.flashbots.net/flashbots-protect/overview)
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# Flash Loan Simulator Configuration
|
|
2
|
+
# ===================================
|
|
3
|
+
# Configure RPC endpoints, providers, and simulation parameters.
|
|
4
|
+
# All settings can be overridden via command-line arguments.
|
|
5
|
+
|
|
6
|
+
# ─────────────────────────────────────────────────────────────────
|
|
7
|
+
# RPC Endpoints
|
|
8
|
+
# ─────────────────────────────────────────────────────────────────
|
|
9
|
+
# Free public RPC endpoints (no signup required).
|
|
10
|
+
# For production use, consider private RPCs (Infura, Alchemy, QuickNode).
|
|
11
|
+
|
|
12
|
+
rpc_endpoints:
|
|
13
|
+
ethereum:
|
|
14
|
+
primary: "https://rpc.ankr.com/eth"
|
|
15
|
+
backup:
|
|
16
|
+
- "https://eth.llamarpc.com"
|
|
17
|
+
- "https://ethereum-rpc.publicnode.com"
|
|
18
|
+
- "https://1rpc.io/eth"
|
|
19
|
+
polygon:
|
|
20
|
+
primary: "https://rpc.ankr.com/polygon"
|
|
21
|
+
backup:
|
|
22
|
+
- "https://polygon-rpc.com"
|
|
23
|
+
arbitrum:
|
|
24
|
+
primary: "https://rpc.ankr.com/arbitrum"
|
|
25
|
+
backup:
|
|
26
|
+
- "https://arb1.arbitrum.io/rpc"
|
|
27
|
+
optimism:
|
|
28
|
+
primary: "https://rpc.ankr.com/optimism"
|
|
29
|
+
backup:
|
|
30
|
+
- "https://mainnet.optimism.io"
|
|
31
|
+
avalanche:
|
|
32
|
+
primary: "https://rpc.ankr.com/avalanche"
|
|
33
|
+
backup:
|
|
34
|
+
- "https://api.avax.network/ext/bc/C/rpc"
|
|
35
|
+
|
|
36
|
+
# ─────────────────────────────────────────────────────────────────
|
|
37
|
+
# Flash Loan Providers
|
|
38
|
+
# ─────────────────────────────────────────────────────────────────
|
|
39
|
+
# Provider configuration with fee rates and contract addresses.
|
|
40
|
+
|
|
41
|
+
providers:
|
|
42
|
+
aave:
|
|
43
|
+
name: "Aave V3"
|
|
44
|
+
fee_rate: 0.0009 # 0.09%
|
|
45
|
+
gas_overhead: 100000
|
|
46
|
+
contracts:
|
|
47
|
+
ethereum: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2"
|
|
48
|
+
polygon: "0x794a61358D6845594F94dc1DB02A252b5b4814aD"
|
|
49
|
+
arbitrum: "0x794a61358D6845594F94dc1DB02A252b5b4814aD"
|
|
50
|
+
optimism: "0x794a61358D6845594F94dc1DB02A252b5b4814aD"
|
|
51
|
+
avalanche: "0x794a61358D6845594F94dc1DB02A252b5b4814aD"
|
|
52
|
+
|
|
53
|
+
dydx:
|
|
54
|
+
name: "dYdX"
|
|
55
|
+
fee_rate: 0.0 # FREE!
|
|
56
|
+
gas_overhead: 150000
|
|
57
|
+
contracts:
|
|
58
|
+
ethereum: "0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e"
|
|
59
|
+
notes: "Ethereum mainnet only, limited asset support"
|
|
60
|
+
|
|
61
|
+
balancer:
|
|
62
|
+
name: "Balancer"
|
|
63
|
+
fee_rate: 0.0001 # 0.01%
|
|
64
|
+
gas_overhead: 80000
|
|
65
|
+
contracts:
|
|
66
|
+
ethereum: "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
|
|
67
|
+
polygon: "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
|
|
68
|
+
arbitrum: "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
|
|
69
|
+
|
|
70
|
+
uniswap:
|
|
71
|
+
name: "Uniswap V3"
|
|
72
|
+
fee_rate: 0.003 # 0.3% (varies by pool)
|
|
73
|
+
gas_overhead: 120000
|
|
74
|
+
contracts:
|
|
75
|
+
ethereum: "0xE592427A0AEce92De3Edee1F18E0157C05861564"
|
|
76
|
+
polygon: "0xE592427A0AEce92De3Edee1F18E0157C05861564"
|
|
77
|
+
arbitrum: "0xE592427A0AEce92De3Edee1F18E0157C05861564"
|
|
78
|
+
optimism: "0xE592427A0AEce92De3Edee1F18E0157C05861564"
|
|
79
|
+
notes: "Flash swap (not flash loan) - fee is pool-dependent"
|
|
80
|
+
|
|
81
|
+
# ─────────────────────────────────────────────────────────────────
|
|
82
|
+
# DEX Configuration
|
|
83
|
+
# ─────────────────────────────────────────────────────────────────
|
|
84
|
+
# Supported DEXes for arbitrage simulations.
|
|
85
|
+
|
|
86
|
+
dexes:
|
|
87
|
+
uniswap:
|
|
88
|
+
name: "Uniswap V3"
|
|
89
|
+
fee_tiers: [0.0001, 0.0005, 0.003, 0.01] # 0.01%, 0.05%, 0.3%, 1%
|
|
90
|
+
router:
|
|
91
|
+
ethereum: "0xE592427A0AEce92De3Edee1F18E0157C05861564"
|
|
92
|
+
polygon: "0xE592427A0AEce92De3Edee1F18E0157C05861564"
|
|
93
|
+
arbitrum: "0xE592427A0AEce92De3Edee1F18E0157C05861564"
|
|
94
|
+
|
|
95
|
+
sushiswap:
|
|
96
|
+
name: "SushiSwap"
|
|
97
|
+
fee_rate: 0.003 # 0.3%
|
|
98
|
+
router:
|
|
99
|
+
ethereum: "0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F"
|
|
100
|
+
polygon: "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506"
|
|
101
|
+
arbitrum: "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506"
|
|
102
|
+
|
|
103
|
+
curve:
|
|
104
|
+
name: "Curve Finance"
|
|
105
|
+
fee_rate: 0.0004 # 0.04% (for stable pools)
|
|
106
|
+
router:
|
|
107
|
+
ethereum: "0x99a58482BD75cbab83b27EC03CA68fF489b5788f"
|
|
108
|
+
|
|
109
|
+
balancer:
|
|
110
|
+
name: "Balancer V2"
|
|
111
|
+
fee_rate: 0.001 # Varies by pool (0.01% - 10%)
|
|
112
|
+
vault:
|
|
113
|
+
ethereum: "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
|
|
114
|
+
|
|
115
|
+
# ─────────────────────────────────────────────────────────────────
|
|
116
|
+
# Simulation Parameters
|
|
117
|
+
# ─────────────────────────────────────────────────────────────────
|
|
118
|
+
# Default parameters for flash loan simulations.
|
|
119
|
+
|
|
120
|
+
simulation:
|
|
121
|
+
# Default market prices (for offline simulation)
|
|
122
|
+
eth_price_usd: 2500.0
|
|
123
|
+
btc_price_usd: 68000.0
|
|
124
|
+
|
|
125
|
+
# Default gas settings
|
|
126
|
+
gas_price_gwei: 30.0
|
|
127
|
+
gas_limit_multiplier: 1.2 # Safety margin
|
|
128
|
+
|
|
129
|
+
# Slippage settings
|
|
130
|
+
default_slippage_percent: 0.5
|
|
131
|
+
max_slippage_percent: 3.0
|
|
132
|
+
|
|
133
|
+
# Request timeout
|
|
134
|
+
rpc_timeout_ms: 30000
|
|
135
|
+
request_delay_ms: 500 # Between API calls to avoid rate limits
|
|
136
|
+
|
|
137
|
+
# ─────────────────────────────────────────────────────────────────
|
|
138
|
+
# Risk Assessment Parameters
|
|
139
|
+
# ─────────────────────────────────────────────────────────────────
|
|
140
|
+
# Weights and thresholds for risk scoring.
|
|
141
|
+
|
|
142
|
+
risk_assessment:
|
|
143
|
+
# Factor weights (must sum to 1.0)
|
|
144
|
+
weights:
|
|
145
|
+
mev_competition: 0.30
|
|
146
|
+
execution_risk: 0.25
|
|
147
|
+
protocol_risk: 0.15
|
|
148
|
+
liquidity_risk: 0.15
|
|
149
|
+
profit_margin: 0.15
|
|
150
|
+
|
|
151
|
+
# Risk thresholds
|
|
152
|
+
thresholds:
|
|
153
|
+
low: 30
|
|
154
|
+
medium: 50
|
|
155
|
+
high: 70
|
|
156
|
+
# Above 70 = CRITICAL
|
|
157
|
+
|
|
158
|
+
# Viability mapping
|
|
159
|
+
viability:
|
|
160
|
+
go_threshold: 30 # Score <= 30 = GO
|
|
161
|
+
caution_threshold: 70 # Score <= 70 = CAUTION
|
|
162
|
+
# Score > 70 = NO-GO
|
|
163
|
+
|
|
164
|
+
# ─────────────────────────────────────────────────────────────────
|
|
165
|
+
# MEV Protection
|
|
166
|
+
# ─────────────────────────────────────────────────────────────────
|
|
167
|
+
# Configuration for MEV protection in production.
|
|
168
|
+
|
|
169
|
+
mev_protection:
|
|
170
|
+
flashbots:
|
|
171
|
+
enabled: false # Enable for production
|
|
172
|
+
relay_url: "https://relay.flashbots.net"
|
|
173
|
+
bundle_simulation: true
|
|
174
|
+
|
|
175
|
+
private_transaction:
|
|
176
|
+
enabled: false
|
|
177
|
+
providers:
|
|
178
|
+
- "flashbots_protect"
|
|
179
|
+
- "eden_network"
|
|
180
|
+
- "bloxroute"
|
|
181
|
+
|
|
182
|
+
# ─────────────────────────────────────────────────────────────────
|
|
183
|
+
# Output Settings
|
|
184
|
+
# ─────────────────────────────────────────────────────────────────
|
|
185
|
+
# Configure output format and verbosity.
|
|
186
|
+
|
|
187
|
+
output:
|
|
188
|
+
default_format: "console" # console, json, markdown
|
|
189
|
+
console_width: 70
|
|
190
|
+
show_warnings: true
|
|
191
|
+
show_recommendations: true
|
|
192
|
+
verbose: false
|
|
193
|
+
|
|
194
|
+
# ─────────────────────────────────────────────────────────────────
|
|
195
|
+
# Supported Tokens
|
|
196
|
+
# ─────────────────────────────────────────────────────────────────
|
|
197
|
+
# Token addresses for common assets (Ethereum mainnet).
|
|
198
|
+
|
|
199
|
+
tokens:
|
|
200
|
+
ETH:
|
|
201
|
+
symbol: "ETH"
|
|
202
|
+
decimals: 18
|
|
203
|
+
addresses:
|
|
204
|
+
ethereum: "native"
|
|
205
|
+
WETH:
|
|
206
|
+
symbol: "WETH"
|
|
207
|
+
decimals: 18
|
|
208
|
+
addresses:
|
|
209
|
+
ethereum: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
|
|
210
|
+
USDC:
|
|
211
|
+
symbol: "USDC"
|
|
212
|
+
decimals: 6
|
|
213
|
+
addresses:
|
|
214
|
+
ethereum: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
215
|
+
USDT:
|
|
216
|
+
symbol: "USDT"
|
|
217
|
+
decimals: 6
|
|
218
|
+
addresses:
|
|
219
|
+
ethereum: "0xdAC17F958D2ee523a2206206994597C13D831ec7"
|
|
220
|
+
DAI:
|
|
221
|
+
symbol: "DAI"
|
|
222
|
+
decimals: 18
|
|
223
|
+
addresses:
|
|
224
|
+
ethereum: "0x6B175474E89094C44Da98b954EescdeCB5AF3696dF"
|
|
225
|
+
WBTC:
|
|
226
|
+
symbol: "WBTC"
|
|
227
|
+
decimals: 8
|
|
228
|
+
addresses:
|
|
229
|
+
ethereum: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"
|
|
230
|
+
|
|
231
|
+
# ─────────────────────────────────────────────────────────────────
|
|
232
|
+
# Educational Disclaimer
|
|
233
|
+
# ─────────────────────────────────────────────────────────────────
|
|
234
|
+
# This configuration is for educational simulation only.
|
|
235
|
+
# Flash loan strategies carry significant risks:
|
|
236
|
+
# - Smart contract bugs can cause total loss
|
|
237
|
+
# - MEV bots compete for the same opportunities
|
|
238
|
+
# - Gas costs can exceed profits
|
|
239
|
+
# - Protocol exploits may have legal implications
|
|
240
|
+
#
|
|
241
|
+
# Never deploy unaudited code. Start with testnets.
|