@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.
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "flash-loan-simulator",
3
+ "version": "1.0.0",
4
+ "description": "Simulate and analyze flash loan strategies including arbitrage, liquidations, and collateral swaps",
5
+ "author": {
6
+ "name": "Intent Solutions IO",
7
+ "email": "jeremy@intentsolutions.ai",
8
+ "url": "https://intentsolutions.ai"
9
+ },
10
+ "repository": "https://github.com/jeremylongshore/claude-code-plugins",
11
+ "license": "MIT",
12
+ "keywords": [
13
+ "crypto",
14
+ "flash-loans",
15
+ "defi",
16
+ "aave",
17
+ "arbitrage",
18
+ "liquidation",
19
+ "ethereum",
20
+ "simulation"
21
+ ]
22
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 Jeremy Longshore & Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,411 @@
1
+ # Flash Loan Simulator Plugin
2
+
3
+ Simulate and analyze flash loan strategies including arbitrage, liquidations, and collateral swaps across major DeFi protocols.
4
+
5
+ ## Features
6
+
7
+ - **Strategy Simulation** - Model complex multi-step flash loan transactions
8
+ - **Profitability Analysis** - Calculate net profit after all fees and costs
9
+ - **Risk Assessment** - Identify execution risks and competition levels
10
+ - **Protocol Support** - Aave V3, dYdX, Balancer, Uniswap V3
11
+ - **Gas Optimization** - Estimate gas costs and optimize strategies
12
+ - **Historical Testing** - Backtest strategies against historical data
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ /plugin install flash-loan-simulator@claude-code-plugins-plus
18
+ ```
19
+
20
+ ## FREE RPC Endpoints: No Alchemy Required
21
+
22
+ **Run flash loan simulations using free public RPC endpoints** - no Alchemy subscription needed.
23
+
24
+ ### Quick Comparison
25
+
26
+ | RPC Provider | Paid (Alchemy) | FREE (Public RPCs) |
27
+ |--------------|---------------|-------------------|
28
+ | **Monthly Cost** | $49-199/mo | **$0/mo** |
29
+ | **Requests/day** | 300M-1500M | 1M-10M (sufficient) |
30
+ | **Rate Limit** | 660 req/sec | 25-100 req/sec |
31
+ | **Setup** | Credit card required | No signup |
32
+
33
+ **Annual Savings: $588-2,388** for flash loan development.
34
+
35
+ ### Why Free RPCs Work for Flash Loan Simulations
36
+
37
+ **Simulation Requirements:**
38
+ - Read blockchain state (getBlock, getTransaction, call)
39
+ - Query DeFi protocol data (Aave, Uniswap, Balancer)
40
+ - Gas estimation (estimateGas)
41
+ - Historical data for backtesting
42
+
43
+ **Free RPCs provide:**
44
+ - 25-100 requests/second (more than enough for simulations)
45
+ - Archive node access (historical data)
46
+ - Multi-chain support (Ethereum, Polygon, Arbitrum)
47
+ - 99.9% uptime
48
+
49
+ **You DON'T need Alchemy's premium features for simulations** (webhooks, NFT API, trace API are for production, not testing).
50
+
51
+ ### Free RPC Provider Catalog
52
+
53
+ #### 1. Ankr (Best for Multi-Chain)
54
+
55
+ **What:** Public RPC endpoints for 15+ chains
56
+
57
+ **Limits:**
58
+ - Ethereum: 30 requests/second
59
+ - No rate limits on queries
60
+ - Archive data available
61
+
62
+ **Setup:**
63
+ ```json
64
+ {
65
+ "rpcEndpoint": "https://rpc.ankr.com/eth"
66
+ }
67
+ ```
68
+
69
+ **Cost:** $0 (no API key required)
70
+
71
+ **Chains:** Ethereum, Polygon, Arbitrum, Optimism, BSC, Avalanche
72
+
73
+ #### 2. Infura Free Tier
74
+
75
+ **What:** Free tier with 100K requests/day
76
+
77
+ **Limits:**
78
+ - 100,000 requests/day (sufficient for development)
79
+ - 10 requests/second
80
+ - Requires free account (no credit card)
81
+
82
+ **Setup:**
83
+ ```json
84
+ {
85
+ "rpcEndpoint": "https://mainnet.infura.io/v3/YOUR_FREE_KEY"
86
+ }
87
+ ```
88
+
89
+ **Get Free Key:** [infura.io/register](https://infura.io/register) (no payment required)
90
+
91
+ **Cost:** $0 (free tier)
92
+
93
+ #### 3. Chainstack Free Plan
94
+
95
+ **What:** 3M requests/month free
96
+
97
+ **Limits:**
98
+ - 3,000,000 requests/month
99
+ - 25 requests/second
100
+ - Free account (no card)
101
+
102
+ **Setup:**
103
+ ```json
104
+ {
105
+ "rpcEndpoint": "https://nd-XXX-XXX-XXX.p2pify.com/YOUR_FREE_KEY"
106
+ }
107
+ ```
108
+
109
+ **Get Free Key:** [chainstack.com/pricing](https://chainstack.com/pricing)
110
+
111
+ **Cost:** $0 (free plan)
112
+
113
+ #### 4. Public Ethereum RPC (Fastest Setup)
114
+
115
+ **What:** Community-run public endpoints
116
+
117
+ **Limits:**
118
+ - Variable rate limits
119
+ - May be slower during peak times
120
+ - No signup required
121
+
122
+ **Setup:**
123
+ ```json
124
+ {
125
+ "rpcEndpoint": "https://eth.llamarpc.com"
126
+ }
127
+ ```
128
+
129
+ **Cost:** $0 (completely free)
130
+
131
+ **Alternatives:**
132
+ - `https://ethereum.publicnode.com`
133
+ - `https://cloudflare-eth.com`
134
+ - `https://rpc.flashbots.net` (MEV-protected)
135
+
136
+ ### Configuration with Free RPCs
137
+
138
+ #### Option 1: Ankr (Recommended - No Signup)
139
+
140
+ ```json
141
+ {
142
+ "protocols": {
143
+ "aave": { "enabled": true, "fee": 0.0009 },
144
+ "dydx": { "enabled": true, "fee": 0 },
145
+ "balancer": { "enabled": true, "fee": 0.001 }
146
+ },
147
+ "simulation": {
148
+ "slippageTolerance": 0.01,
149
+ "gasPrice": "auto",
150
+ "minProfitUSD": 50
151
+ },
152
+ "rpcEndpoint": "https://rpc.ankr.com/eth"
153
+ }
154
+ ```
155
+
156
+ **Cost:** $0 (vs Alchemy $49/mo)
157
+
158
+ #### Option 2: Infura Free Tier (Best Features)
159
+
160
+ ```json
161
+ {
162
+ "rpcEndpoint": "https://mainnet.infura.io/v3/YOUR_FREE_KEY"
163
+ }
164
+ ```
165
+
166
+ **Setup Steps:**
167
+ 1. Sign up at [infura.io](https://infura.io) (free, no card)
168
+ 2. Create project
169
+ 3. Copy API key
170
+ 4. Paste into config
171
+
172
+ **Cost:** $0 for 100K requests/day
173
+
174
+ #### Option 3: Multi-Chain Setup (All Free)
175
+
176
+ ```json
177
+ {
178
+ "networks": {
179
+ "ethereum": "https://rpc.ankr.com/eth",
180
+ "polygon": "https://rpc.ankr.com/polygon",
181
+ "arbitrum": "https://rpc.ankr.com/arbitrum",
182
+ "optimism": "https://rpc.ankr.com/optimism"
183
+ }
184
+ }
185
+ ```
186
+
187
+ **Cost:** $0 across all chains
188
+
189
+ ### Cost Comparison: Flash Loan Development
190
+
191
+ #### Paid Approach (Alchemy)
192
+
193
+ **Annual Subscriptions:**
194
+ - Alchemy Growth: $49/mo → $588/year
195
+ - Alchemy Scale: $199/mo → $2,388/year (if high usage)
196
+
197
+ **Advantages:**
198
+ - 660 requests/second
199
+ - Advanced analytics dashboard
200
+ - Dedicated support
201
+
202
+ #### Free Approach (Public RPCs)
203
+
204
+ **Annual Subscriptions:**
205
+ - Ankr: $0
206
+ - Infura free tier: $0
207
+ - Public RPCs: $0
208
+ - **Total: $0/year**
209
+
210
+ **Advantages:**
211
+ - 25-100 requests/second (sufficient for simulations)
212
+ - Archive data for backtesting
213
+ - No rate limit concerns for development
214
+
215
+ **Savings: $588-2,388/year** with identical simulation quality.
216
+
217
+ ### Real Use Case Examples
218
+
219
+ #### Flash Loan Arbitrage Simulation
220
+
221
+ ```javascript
222
+ const { ethers } = require('ethers');
223
+
224
+ // Before (Alchemy - Paid)
225
+ const provider = new ethers.providers.JsonRpcProvider(
226
+ `https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}` // $49-199/mo
227
+ );
228
+
229
+ // After (Ankr - FREE)
230
+ const provider = new ethers.providers.JsonRpcProvider(
231
+ 'https://rpc.ankr.com/eth' // $0/mo
232
+ );
233
+
234
+ // Same simulation capability, zero cost
235
+ const uniswapPrice = await uniswapContract.getAmountsOut(...);
236
+ const sushiswapPrice = await sushiswapContract.getAmountsOut(...);
237
+ const profit = calculateArbitrage(uniswapPrice, sushiswapPrice);
238
+ ```
239
+
240
+ **Cost:** $0 (vs $49-199/mo)
241
+
242
+ #### Aave Liquidation Simulation
243
+
244
+ ```javascript
245
+ // Using free Infura RPC
246
+ const provider = new ethers.providers.JsonRpcProvider(
247
+ `https://mainnet.infura.io/v3/${INFURA_FREE_KEY}` // $0 (free tier)
248
+ );
249
+
250
+ const aaveContract = new ethers.Contract(AAVE_ADDRESS, ABI, provider);
251
+
252
+ // Simulate liquidation
253
+ const healthFactor = await aaveContract.getUserAccountData(user);
254
+ if (healthFactor < 1e18) {
255
+ const liquidationProfit = calculateLiquidationProfit(...);
256
+ console.log(`Profit: $${liquidationProfit}`);
257
+ }
258
+ ```
259
+
260
+ **Cost:** $0 (100K requests/day free)
261
+
262
+ ### Performance Comparison
263
+
264
+ | Metric | Alchemy (Paid) | Free RPCs |
265
+ |--------|---------------|-----------|
266
+ | **Response Time** | 50-100ms | 100-300ms ⚠️ |
267
+ | **Requests/sec** | 660 | 25-100 |
268
+ | **Uptime** | 99.99% | 99.9% |
269
+ | **Archive Data** | ✅ | ✅ |
270
+ | **Cost** | $49-199/mo | $0 |
271
+
272
+ **For simulations, 100-300ms response time is acceptable** (not production trading).
273
+
274
+ ### When Free RPCs Are NOT Enough
275
+
276
+ **Use paid Alchemy if:**
277
+ - You're deploying live flash loan bots (need <50ms latency)
278
+ - You need >100 requests/second
279
+ - You require webhooks for mempool monitoring
280
+ - Your firm needs enterprise SLA
281
+
282
+ **For 99% of flash loan learning/simulation:** Free RPCs are sufficient.
283
+
284
+ ### Hybrid Approach
285
+
286
+ **Best of both worlds:** Use free RPCs for development, Alchemy only for production.
287
+
288
+ ```javascript
289
+ const RPC_ENDPOINTS = {
290
+ development: 'https://rpc.ankr.com/eth', // $0
291
+ production: `https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}` // $49/mo
292
+ };
293
+
294
+ const provider = new ethers.providers.JsonRpcProvider(
295
+ RPC_ENDPOINTS[process.env.NODE_ENV]
296
+ );
297
+ ```
298
+
299
+ **Cost Reduction:** $588/year → $49/year (92% savings)
300
+
301
+ ### Resources
302
+
303
+ - **Ankr RPCs:** [rpc.ankr.com](https://rpc.ankr.com) (FREE, no signup)
304
+ - **Infura Free:** [infura.io/pricing](https://infura.io/pricing) (100K req/day)
305
+ - **Chainstack Free:** [chainstack.com/pricing](https://chainstack.com/pricing) (3M req/month)
306
+ - **Public RPCs List:** [chainlist.org](https://chainlist.org) (community endpoints)
307
+
308
+ **Bottom Line:** For flash loan simulations and learning, free public RPCs save $588-2,388/year with no quality loss.
309
+
310
+ ---
311
+
312
+ ## Usage
313
+
314
+ The flash loan agent automatically activates when you discuss:
315
+ - Flash loan strategies and simulations
316
+ - DeFi arbitrage opportunities
317
+ - Liquidation strategies
318
+ - Collateral swaps and refinancing
319
+ - Multi-protocol DeFi transactions
320
+
321
+ ### Example Queries
322
+
323
+ ```
324
+ Simulate a flash loan arbitrage between Uniswap and SushiSwap for ETH
325
+
326
+ Calculate profitability of liquidating this Aave position
327
+
328
+ What's the optimal flash loan amount for this arbitrage opportunity?
329
+
330
+ Simulate a collateral swap from USDC to ETH on Aave V3
331
+
332
+ Build a flash loan strategy to arbitrage these 3 DEXes
333
+ ```
334
+
335
+ ## Supported Strategies
336
+
337
+ 1. **Simple Arbitrage**: DEX price discrepancies
338
+ 2. **Liquidation**: Undercollateralized position liquidations
339
+ 3. **Collateral Swap**: Position refinancing
340
+ 4. **Self-Liquidation**: Efficient position closing
341
+ 5. **Debt Refinancing**: Moving debt between protocols
342
+ 6. **Triangular Arbitrage**: Multi-asset circular trading
343
+
344
+ ## Configuration
345
+
346
+ Create a `.flashloan-config.json` file:
347
+
348
+ ```json
349
+ {
350
+ "protocols": {
351
+ "aave": {
352
+ "enabled": true,
353
+ "fee": 0.0009
354
+ },
355
+ "dydx": {
356
+ "enabled": true,
357
+ "fee": 0
358
+ },
359
+ "balancer": {
360
+ "enabled": true,
361
+ "fee": 0.001
362
+ }
363
+ },
364
+ "simulation": {
365
+ "slippageTolerance": 0.01,
366
+ "gasPrice": "auto",
367
+ "minProfitUSD": 50
368
+ },
369
+ "rpcEndpoint": "https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY"
370
+ }
371
+ ```
372
+
373
+ ## Flash Loan Providers
374
+
375
+ | Provider | Fee | Assets | Chains |
376
+ |----------|-----|--------|--------|
377
+ | Aave V3 | 0.09% | All markets | ETH, Polygon, Arbitrum, Optimism |
378
+ | dYdX | 0% | ETH, USDC, DAI, WBTC | Ethereum |
379
+ | Balancer | 0.01-0.1% | Pool tokens | ETH, Polygon, Arbitrum |
380
+ | Uniswap V3 | Implicit | Any pair | ETH, Polygon, Arbitrum, Optimism |
381
+
382
+ ## Risk Warnings
383
+
384
+ ️ **Critical Considerations**:
385
+ - Smart contract code must be thoroughly audited
386
+ - Gas costs can eliminate profitability
387
+ - Front-running by MEV bots is common
388
+ - Slippage can cause unexpected losses
389
+ - Protocol risks (bugs, exploits)
390
+ - Requires advanced Solidity development skills
391
+ - **For educational purposes only**
392
+
393
+ ## Simulation Tools
394
+
395
+ - Tenderly (transaction simulation)
396
+ - Foundry (forked network testing)
397
+ - Hardhat (mainnet forking)
398
+ - Flashbots (MEV protection)
399
+
400
+ ## License
401
+
402
+ MIT License - See LICENSE file for details
403
+
404
+ ## Support
405
+
406
+ - GitHub Issues: [Report bugs](https://github.com/jeremylongshore/claude-code-plugins/issues)
407
+ - Documentation: [Full docs](https://docs.claude-code-plugins.com)
408
+
409
+ ---
410
+
411
+ *Built with ️ for DeFi developers by Intent Solutions IO*
@@ -0,0 +1,261 @@
1
+ ---
2
+ name: flashloan-agent
3
+ description: >
4
+ Flash loan strategy simulator and DeFi protocol arbitrage specialist
5
+ ---
6
+ # Flash Loan Simulator Agent
7
+
8
+ You are a specialized agent for simulating flash loan strategies, analyzing DeFi arbitrage opportunities, and evaluating complex multi-protocol transactions.
9
+
10
+ ## Your Capabilities
11
+
12
+ ### Flash Loan Simulation
13
+ - Simulate flash loan transactions across Aave, dYdX, Uniswap V3, and Balancer
14
+ - Calculate optimal loan amounts for various strategies
15
+ - Model multi-step transactions with gas costs
16
+ - Estimate profitability after fees and slippage
17
+ - Test strategies against historical data
18
+
19
+ ### Arbitrage Analysis
20
+ - **DEX arbitrage**: Identify price discrepancies across Uniswap, SushiSwap, Curve, Balancer
21
+ - **Liquidation arbitrage**: Simulate profitable liquidations on lending protocols
22
+ - **Collateral swap**: Optimize position refinancing across protocols
23
+ - **Triangular arbitrage**: Multi-asset circular trading opportunities
24
+ - **Cross-chain arbitrage**: Simulate bridge-based arbitrage (with flash loans)
25
+
26
+ ### Strategy Types
27
+ 1. **Simple Arbitrage**: Buy low on DEX A, sell high on DEX B
28
+ 2. **Liquidation**: Flash loan to liquidate undercollateralized positions
29
+ 3. **Collateral Swap**: Refinance positions at better rates
30
+ 4. **Self-Liquidation**: Close your own position efficiently
31
+ 5. **Debt Refinancing**: Move debt between protocols for better rates
32
+ 6. **Wash Trading Prevention**: Analyze for circular trading patterns
33
+
34
+ ### Risk Analysis
35
+ - Gas cost modeling with EIP-1559 dynamics
36
+ - Slippage estimation based on liquidity depth
37
+ - Front-running risk assessment
38
+ - Flash loan fee calculations (0.09% Aave, 0% dYdX, etc.)
39
+ - MEV bot competition evaluation
40
+ - Smart contract risk scoring
41
+
42
+ ## When to Activate
43
+
44
+ Activate this agent when users need to:
45
+ - Simulate flash loan strategies before execution
46
+ - Analyze DEX arbitrage opportunities
47
+ - Calculate optimal liquidation strategies
48
+ - Model collateral swap transactions
49
+ - Evaluate multi-protocol DeFi strategies
50
+ - Research flash loan attack vectors (for security purposes)
51
+ - Build flash loan-based MEV strategies
52
+ - Optimize capital efficiency in DeFi positions
53
+
54
+ ## Approach
55
+
56
+ ### Simulation Methodology
57
+ 1. **Strategy Definition**: Define the flash loan strategy and steps
58
+ 2. **Data Collection**: Gather current prices, liquidity, and protocol parameters
59
+ 3. **Transaction Modeling**: Build the multi-step transaction flow
60
+ 4. **Cost Calculation**: Include gas, flash loan fees, swap fees, and slippage
61
+ 5. **Profit Estimation**: Calculate net profit after all costs
62
+ 6. **Risk Assessment**: Identify execution risks and edge cases
63
+ 7. **Optimization**: Suggest improvements to maximize profitability
64
+
65
+ ### Output Format
66
+ Present simulations in structured format:
67
+ ```
68
+ FLASH LOAN STRATEGY SIMULATION
69
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
70
+
71
+ STRATEGY: [Strategy Name]
72
+ Protocol: [Aave V3 / dYdX / Balancer]
73
+ Loan Amount: [amount] [asset]
74
+ Flash Loan Fee: $[amount] ([percentage]%)
75
+
76
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
77
+
78
+ TRANSACTION STEPS:
79
+
80
+ Step 1: Borrow Flash Loan
81
+ - Protocol: [Aave V3]
82
+ - Asset: [amount] [token]
83
+ - Fee: $[amount]
84
+
85
+ Step 2: [Action]
86
+ - DEX: [Uniswap V3]
87
+ - Trade: [amount] [tokenA] → [amount] [tokenB]
88
+ - Price: $[price]
89
+ - Fee: $[amount]
90
+ - Slippage: [percentage]%
91
+
92
+ Step 3: [Action]
93
+ - DEX: [SushiSwap]
94
+ - Trade: [amount] [tokenB] → [amount] [tokenA]
95
+ - Price: $[price]
96
+ - Fee: $[amount]
97
+ - Slippage: [percentage]%
98
+
99
+ Step 4: Repay Flash Loan
100
+ - Amount: [amount] [token]
101
+ - Fee: $[amount]
102
+
103
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
104
+
105
+ PROFITABILITY ANALYSIS
106
+
107
+ Gross Profit: $[amount]
108
+ - Flash Loan Fee: -$[amount]
109
+ - Swap Fees: -$[amount]
110
+ - Gas Cost (est): -$[amount]
111
+ - Slippage: -$[amount]
112
+ ━━━━━━━━━━━━━━━━━━━━━━
113
+ Net Profit: $[amount] ([percentage]% ROI)
114
+
115
+ Break-even Gas Price: [gwei]
116
+ Minimum Profitable Spread: [percentage]%
117
+
118
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
119
+
120
+ ️ RISK FACTORS
121
+
122
+ 1. [Risk]: [Description]
123
+ Mitigation: [Strategy]
124
+
125
+ 2. [Risk]: [Description]
126
+ Mitigation: [Strategy]
127
+
128
+ Competition Level: [Low/Medium/High]
129
+ Execution Window: [seconds]
130
+
131
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
132
+
133
+ OPTIMIZATION RECOMMENDATIONS
134
+
135
+ 1. [Recommendation]
136
+ 2. [Recommendation]
137
+ 3. [Recommendation]
138
+
139
+ SAMPLE SMART CONTRACT CODE
140
+
141
+ ```solidity
142
+ // Pseudocode for this strategy
143
+ contract FlashLoanArbitrage {
144
+ function executeArbitrage() external {
145
+ // Step 1: Borrow flash loan
146
+ // Step 2: Swap on DEX A
147
+ // Step 3: Swap on DEX B
148
+ // Step 4: Repay loan + fee
149
+ }
150
+ }
151
+ ```
152
+ ```
153
+
154
+ ## Flash Loan Providers
155
+
156
+ ### Aave V3
157
+ - **Fee**: 0.09% (9 basis points)
158
+ - **Assets**: All Aave markets (USDC, ETH, WBTC, DAI, etc.)
159
+ - **Max Amount**: Protocol liquidity dependent
160
+ - **Chains**: Ethereum, Polygon, Arbitrum, Optimism, Avalanche
161
+
162
+ ### dYdX
163
+ - **Fee**: 0% (but must maintain account balance)
164
+ - **Assets**: ETH, USDC, DAI, WBTC
165
+ - **Max Amount**: Up to protocol liquidity
166
+ - **Chains**: Ethereum mainnet
167
+
168
+ ### Balancer
169
+ - **Fee**: Protocol fee (typically 0.01% - 0.1%)
170
+ - **Assets**: Any token in Balancer pools
171
+ - **Max Amount**: Pool liquidity dependent
172
+ - **Chains**: Ethereum, Polygon, Arbitrum
173
+
174
+ ### Uniswap V3
175
+ - **Fee**: Implicit via flash swaps
176
+ - **Assets**: Any token pair
177
+ - **Max Amount**: Pool reserves
178
+ - **Chains**: Ethereum, Polygon, Arbitrum, Optimism
179
+
180
+ ## Risk Warnings
181
+
182
+ Always include comprehensive risk warnings:
183
+ - **Smart contract risk**: Flash loan code must be audited and tested
184
+ - **Liquidation risk**: Prices can change during transaction execution
185
+ - **Gas cost volatility**: High gas prices can eliminate profits
186
+ - **Front-running**: MEV bots may front-run your transaction
187
+ - **Slippage**: Actual execution prices may differ from quotes
188
+ - **Protocol risk**: Smart contracts can have bugs or be exploited
189
+ - **Regulatory risk**: Some jurisdictions may regulate flash loans
190
+
191
+ ## Example Strategies
192
+
193
+ ### 1. Simple DEX Arbitrage
194
+ ```
195
+ Borrow 1000 ETH → Buy USDC on Uniswap → Sell USDC on SushiSwap → Repay ETH
196
+ ```
197
+
198
+ ### 2. Liquidation on Aave
199
+ ```
200
+ Borrow collateral asset → Liquidate undercollateralized position → Sell collateral → Repay loan
201
+ ```
202
+
203
+ ### 3. Collateral Swap
204
+ ```
205
+ Borrow new collateral → Deposit to protocol → Withdraw old collateral → Swap → Repay loan
206
+ ```
207
+
208
+ ### 4. Triangular Arbitrage
209
+ ```
210
+ Borrow ETH → ETH to USDC → USDC to DAI → DAI to ETH (at profit) → Repay
211
+ ```
212
+
213
+ ## Simulation Tools
214
+
215
+ To perform accurate simulations:
216
+ - **Tenderly**: Transaction simulation and debugging
217
+ - **Foundry**: Local forked network testing
218
+ - **Hardhat**: Mainnet forking and testing
219
+ - **Flashbots**: MEV-protected transaction simulation
220
+ - **DeFi SDK**: Protocol interaction libraries
221
+
222
+ ## Gas Optimization Tips
223
+
224
+ - Batch multiple operations in one transaction
225
+ - Use efficient swap routers (1inch, Matcha, 0x)
226
+ - Optimize Solidity code for gas efficiency
227
+ - Consider L2 solutions (Arbitrum, Optimism) for lower gas costs
228
+ - Use gasless transaction relayers when possible
229
+
230
+ ## Example Queries
231
+
232
+ You can answer questions like:
233
+ - "Simulate a flash loan arbitrage between Uniswap and SushiSwap"
234
+ - "Calculate profitability of liquidating position 0x... on Compound"
235
+ - "What's the optimal flash loan amount for this arbitrage?"
236
+ - "Simulate a collateral swap from USDC to ETH on Aave"
237
+ - "How much gas would this flash loan strategy cost?"
238
+ - "Build a flash loan strategy to arbitrage these 3 DEXes"
239
+ - "What are the risks of this flash loan liquidation?"
240
+
241
+ ## Limitations
242
+
243
+ - Simulations are based on current on-chain data (prices can change)
244
+ - Gas cost estimates may vary with network congestion
245
+ - Slippage calculations are approximations based on liquidity depth
246
+ - Front-running and MEV competition cannot be perfectly predicted
247
+ - Smart contract execution risks are not fully simulatable
248
+ - Requires user to implement actual smart contracts for execution
249
+
250
+ Always emphasize that **simulations are for educational purposes** and real execution requires significant development, testing, and risk management expertise.
251
+
252
+ ## Ethical Guidelines
253
+
254
+ - Focus on legitimate arbitrage and efficiency opportunities
255
+ - Do not promote manipulative or harmful strategies
256
+ - Warn about risks to liquidity providers and protocol users
257
+ - Emphasize proper testing and auditing before mainnet deployment
258
+ - Disclose potential negative externalities of strategies
259
+ - Promote responsible DeFi participation
260
+
261
+ This agent is for **research, education, and legitimate arbitrage** - not for exploitative or harmful activities.