From everything-claude-trading
- Identifying and evaluating arbitrage opportunities between centralized and decentralized exchanges
npx claudepluginhub brainbytes-dev/everything-claude-tradingThis skill uses the workspace's default tool permissions.
- Identifying and evaluating arbitrage opportunities between centralized and decentralized exchanges
Provides Ktor server patterns for routing DSL, plugins (auth, CORS, serialization), Koin DI, WebSockets, services, and testApplication testing.
Conducts multi-source web research with firecrawl and exa MCPs: searches, scrapes pages, synthesizes cited reports. For deep dives, competitive analysis, tech evaluations, or due diligence.
Provides demand forecasting, safety stock optimization, replenishment planning, and promotional lift estimation for multi-location retailers managing 300-800 SKUs.
Price Discrepancy Sources:
Execution Flow:
1. Monitor CEX order books and DEX pool prices simultaneously
2. Detect discrepancy exceeding threshold (gas + fees + slippage)
3. Execute simultaneously:
a. Buy on cheaper venue
b. Sell on more expensive venue
4. Net inventory to zero
Two modes:
- Atomic (DEX-only): single transaction using flash loans, no capital risk
- Non-atomic (CEX-DEX): requires capital on both venues, execution risk between legs
CEX-DEX Specific Challenges:
Bridge Arbitrage:
Types of Cross-Chain Price Discrepancies:
1. Native token pricing: ETH on Ethereum vs ETH on Arbitrum
- Usually tight (<0.1%) due to fast bridging
2. Wrapped/bridged tokens: USDC on Ethereum vs USDC.e on Avalanche
- Can diverge during bridge congestion or depeg events
3. DEX pool pricing: Uniswap (Ethereum) vs Trader Joe (Avalanche)
- Different pool depths create persistent small discrepancies
4. Synthetic assets: cross-chain synthetics may diverge from underlying
Bridge Risk Categories:
Concept: Exploit pricing inconsistencies across three or more trading pairs that form a cycle.
On-Chain Triangular Arbitrage:
Example cycle: ETH -> USDC -> DAI -> ETH
Pool 1 (ETH/USDC): 1 ETH = 2000 USDC
Pool 2 (USDC/DAI): 1 USDC = 1.002 DAI
Pool 3 (DAI/ETH): 2000 DAI = 1.003 ETH
Execution:
1. Start with 10 ETH
2. Swap 10 ETH -> 20,000 USDC (Pool 1)
3. Swap 20,000 USDC -> 20,040 DAI (Pool 2)
4. Swap 20,040 DAI -> 10.03 ETH (Pool 3)
5. Profit: 0.03 ETH minus gas costs
Profitability condition:
product(exchange_rates_around_cycle) > 1 + total_fees + gas_cost/trade_size
Multi-Hop Optimization:
Flash Loan Arbitrage Pattern:
Single transaction:
1. Borrow X tokens from Aave/dYdX (flash loan, no collateral)
2. Execute arbitrage trades across DEX pools
3. Repay loan + fee (0.05% on Aave, 0% on dYdX)
4. Keep profit
Advantages:
- Zero capital requirement (borrow and repay in same tx)
- Zero market risk (atomic execution — all or nothing)
- No inventory to manage
Constraints:
- Must complete within single transaction (single block)
- Cannot cross chains (flash loans are same-chain only)
- Gas costs can be high for complex multi-hop routes
- Competitive — many searchers target same opportunities
Atomic (flash loan) arbitrage:
Net profit = gross_spread * trade_size - gas_cost - flash_loan_fee - slippage
CEX-DEX arbitrage:
Net profit = gross_spread * trade_size - gas_cost - CEX_fees - slippage
- capital_cost * execution_time - hedge_cost
Cross-chain arbitrage:
Net profit = gross_spread * trade_size - gas_cost_chain_A - gas_cost_chain_B
- bridge_fee - slippage - bridge_time_risk_premium
Break-even spread:
min_spread = (total_costs) / trade_size
Competitive advantage sources:
1. Co-located nodes (reduces block propagation latency)
2. Private mempool access (Flashbots, MEV-boost builders)
3. Pre-signed transactions ready to submit
4. Multi-chain node infrastructure
5. Custom DEX routing algorithms
6. Direct builder relationships for bundle inclusion
Latency hierarchy:
- HFT on CEX: microseconds
- MEV searcher on-chain: milliseconds to submit, 12s to confirm
- Cross-chain arb: minutes to hours (bridge dependent)
Position limits:
- Max single arb size: limited by pool depth (aim for <2% price impact)
- Max bridge exposure: never bridge more than you can afford to lose
- Max inventory imbalance: for CEX-DEX, delta-neutral within 5 minutes
Stop conditions:
- Gas price >3x normal: pause (costs eat profits)
- Bridge delays >2x normal: stop bridging (increased risk)
- Failed transaction rate >20%: investigate and halt
- Cumulative loss exceeds daily profit: halt and review
CEX (Binance): ETH/USDT bid = $2,005.00
DEX (Uniswap): ETH/USDC pool price = $2,000.00
Spread: $5.00 (0.25%)
Costs:
- Uniswap fee: 0.05% = $1.00 per ETH
- Gas for DEX swap: $8 (20 ETH batch)
- Binance taker fee: 0.075% = $1.50 per ETH
- Slippage estimate: 0.02% = $0.40 per ETH
Net profit per ETH: $5.00 - $1.00 - $0.40 - $1.50 - $0.40 = $1.70
For 20 ETH batch: $34.00 - $8 gas = $26.00 net
Execution: Buy 20 ETH on Uniswap, sell 20 ETH on Binance simultaneously
Capital required: $40,000 USDC on-chain + 20 ETH on Binance
Annualized return on capital depends on frequency of opportunities.
USDC on Ethereum: $1.000
USDC on Arbitrum (via Curve): $0.997 (slight discount)
Strategy:
1. Buy USDC on Arbitrum Curve pool at $0.997
2. Bridge to Ethereum via native bridge (free, but 7-day delay)
Or use fast bridge (Across, Hop) for ~0.05% fee, 2 min
Fast bridge execution:
- Gross profit: 0.3%
- Bridge fee: 0.05%
- Gas (Arbitrum swap): $0.50
- Gas (Ethereum receive): $5
- Net profit: 0.25% - ($5.50 / trade_size)
Break-even trade size: $5.50 / 0.0025 = $2,200 minimum
For $50,000 trade: $125 - $5.50 = $119.50 profit
Risk: USDC discount could widen during transit. Bridge smart contract risk.
Detected opportunity on Uniswap v3 (Ethereum):
Pool A (WETH/USDC 0.05%): 1 WETH = 2,001 USDC
Pool B (USDC/DAI 0.01%): 1 USDC = 1.0008 DAI
Pool C (DAI/WETH 0.30%): 2,000 DAI = 1.001 WETH
Cycle product: (1/2001) * (1/1.0008) * (2000 * 1.001) = 1.00089
Gross profit per cycle: 0.089%
Flash loan execution:
1. Borrow 100 WETH from Aave
2. Swap 100 WETH -> 200,100 USDC (Pool A, fee: 100 USDC)
3. Swap 200,100 USDC -> 200,260 DAI (Pool B, fee: 20 USDC equiv)
4. Swap 200,260 DAI -> 100.16 WETH (Pool C, fee: 600 DAI equiv)
5. Repay 100 WETH + 0.05 WETH (flash loan fee)
6. Profit: 0.11 WETH (~$220)
7. Gas cost: ~$30
Net profit: ~$190 in a single atomic transaction
Submit via Flashbots to prevent frontrunning.
Before executing arbitrage strategies, verify: