๐ Ethereum MEV Arbitrage Strategy Guide
October 12, 2025 ยท View on GitHub
Table of Contents
- Introduction
- Arbitrage Fundamentals
- Types of MEV Strategies
- Arbitrage Strategy
- Implementation Details
- Risk Management
- Profitability Analysis
- Advanced Techniques
Introduction
MEV (Maximal Extractable Value) refers to the maximum value that can be extracted from block production beyond the standard block reward and gas fees. This bot focuses primarily on DEX arbitrage opportunities across multiple Ethereum decentralized exchanges.
What is Arbitrage?
Arbitrage is the simultaneous purchase and sale of an asset to profit from price differences across different markets. In the context of DeFi, this means exploiting price discrepancies for the same token across different DEXes (Uniswap, SushiSwap, etc.).
Arbitrage Fundamentals
Basic Concept
1. Token price on DEX A: \$100
2. Token price on DEX B: \$105
3. Buy on DEX A โ Sell on DEX B = \$5 profit (minus fees)
Key Components
- Price Discovery: Monitor multiple DEXes simultaneously
- Speed: Execute trades before the opportunity disappears
- Capital Efficiency: Use flashloans to trade without upfront capital
- Gas Optimization: Minimize transaction costs
Types of MEV Strategies
1. ๐ DEX Arbitrage (Current Implementation)
Description: Exploit price differences for the same asset across different DEXes.
Example:
- WETH/USDC on Uniswap: 1 ETH = $2000
- WETH/USDC on SushiSwap: 1 ETH = $2005
- Profit: $5 per ETH (minus fees and gas)
Advantages:
- Lower risk (atomic transactions)
- No inventory required (flashloans)
- Predictable profits
2. ๐ฅช Sandwich Attacks (Future)
Description: Detect large pending trades and place orders before and after them to profit from price impact.
Process:
- Detect large swap transaction in mempool
- Front-run: Buy tokens before the large swap
- Large swap executes (moves price up)
- Back-run: Sell tokens at higher price
Ethical Considerations: โ ๏ธ Controversial - can harm other traders
3. ๐ฏ Liquidation Arbitrage (Future)
Description: Monitor lending protocols (Aave, Compound) for undercollateralized positions and execute liquidations.
Requirements:
- Monitor health factors of all positions
- Quick execution when positions become liquidatable
- Capital for liquidation (or flashloan)
4. ๐ฐ NFT Arbitrage (Future)
Description: Exploit price differences for NFTs across marketplaces.
Arbitrage Strategy
Strategy Flow
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ARBITRAGE EXECUTION FLOW โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1. MONITORING PHASE
โโโ Monitor DEX prices (Uniswap, SushiSwap, etc.)
โโโ Compare prices across all pairs
โโโ Detect price discrepancy > threshold
2. VALIDATION PHASE
โโโ Calculate potential profit
โโโ Estimate gas costs
โโโ Check slippage tolerance
โโโ Validate liquidity depth
โโโ Confirm profit > minimum threshold
3. EXECUTION PHASE (Atomic Transaction)
โโโ Request flashloan from Aave
โโโ Receive borrowed tokens
โโโ Execute Swap 1 (Buy on cheaper DEX)
โโโ Execute Swap 2 (Sell on expensive DEX)
โโโ Repay flashloan + premium
โโโ Keep profit
โโโ Transaction succeeds or reverts (no loss)
4. POST-EXECUTION
โโโ Log transaction details
โโโ Calculate actual profit
โโโ Update statistics
โโโ Send notification
Detailed Execution Steps
Step 1: Price Monitoring
// Monitor prices every N milliseconds
for each token in watchlist:
prices = {
uniswapV2: getPriceFromUniswapV2(token),
sushiswap: getPriceFromSushiSwap(token),
uniswapV3: getPriceFromUniswapV3(token)
}
if (findArbitrageOpportunity(prices)):
validateAndExecute(opportunity)
Step 2: Profit Calculation
Gross Profit = (SellPrice - BuyPrice) ร Amount
DEX Fees = Amount ร 0.003 ร 2 // 0.3% per swap
Flashloan Fee = Amount ร 0.0009 // 0.09% Aave fee
Gas Cost = GasPrice ร GasLimit
Net Profit = Gross Profit - DEX Fees - Flashloan Fee - Gas Cost
Step 3: Flashloan Arbitrage
// Pseudo-code for smart contract
function executeArbitrage(token, amount) {
// 1. Request flashloan
flashloan(token, amount);
}
function onFlashloanReceived(token, amount, premium) {
// 2. Buy on cheaper DEX
swapOnDexA(token, weth, amount);
// 3. Sell on expensive DEX
swapOnDexB(weth, token, receivedAmount);
// 4. Repay flashloan
repay(amount + premium);
// 5. Keep profit
profit = balance - (amount + premium);
require(profit > minProfit, "Insufficient profit");
}
Implementation Details
Architecture Components
-
Price Fetcher
- Monitors multiple DEX prices
- Uses WebSocket for real-time data
- Implements caching to reduce RPC calls
-
Profit Calculator
- Estimates potential profit
- Accounts for all fees (DEX, flashloan, gas)
- Calculates optimal trade size
-
Gas Estimator
- Monitors current gas prices
- Implements EIP-1559 support
- Uses multiple data sources
-
Arbitrage Bot
- Orchestrates all components
- Makes execution decisions
- Manages risk and safety checks
-
Smart Contract
- Executes atomic transactions
- Handles flashloans
- Swaps across multiple DEXes
DEX Integration
Uniswap V2 / SushiSwap
// Uses constant product formula: x * y = k
const reserve0, reserve1 = pair.getReserves();
const price = reserve1 / reserve0;
Uniswap V3
// Uses concentrated liquidity
const amountOut = quoter.quoteExactInputSingle(
tokenIn,
tokenOut,
fee,
amountIn,
sqrtPriceLimitX96
);
Risk Management
Safety Mechanisms
-
Minimum Profit Threshold
Only execute if: NetProfit > MinThreshold (e.g., 0.01 ETH) -
Maximum Gas Price
Only execute if: GasPrice < MaxGasPrice (e.g., 100 gwei) -
Slippage Protection
Set minimum output amount based on slippage tolerance -
Position Size Limits
MaxTradeSize = min(AvailableLiquidity ร 0.8, MaxConfigured) -
Atomic Transactions
All trades execute in one transaction If any step fails, entire transaction reverts No partial execution = No loss risk
Risk Factors
| Risk | Mitigation |
|---|---|
| Gas price volatility | Monitor and set max gas price |
| Front-running | Use private RPC, optimized routing |
| Slippage | Calculate price impact, set limits |
| Smart contract bugs | Audit code, test extensively |
| Network congestion | Adjust parameters dynamically |
| Failed transactions | Simulate before execution |
Profitability Analysis
Cost Breakdown
Example Trade: 10 ETH arbitrage opportunity
Revenue:
Price difference: 0.5% = 0.05 ETH
Costs:
Uniswap fee (0.3%): 0.03 ETH
SushiSwap fee (0.3%): 0.03 ETH
Flashloan fee (0.09%): 0.009 ETH
Gas cost (50 gwei): 0.015 ETH
Total Cost: 0.084 ETH
Net Profit: 0.05 - 0.084 = -0.034 ETH โ
Conclusion: Not profitable
Break-Even Analysis
Minimum price difference needed:
Break-even = DEX Fees + Flashloan Fee + Gas Cost
= 0.6% + 0.09% + 0.15%
= 0.84%
Therefore: Need at least 0.84% price difference to break even
Target: 1-2% difference for good profit margin
Profit Optimization
-
Increase Trade Size
- Fixed costs (gas) spread over larger amount
- Higher absolute profit
-
Reduce Gas Costs
- Optimize smart contract
- Batch multiple arbitrages
- Choose off-peak times
-
Find Better Opportunities
- Monitor more tokens
- Include more DEXes
- Use faster detection
-
Minimize Slippage
- Calculate optimal trade size
- Use DEXes with deeper liquidity
Advanced Techniques
1. Multi-Hop Arbitrage
Trade through multiple token pairs:
ETH โ USDC โ DAI โ ETH
If final ETH > initial ETH โ Profit!
2. Triangular Arbitrage
Exploit inefficiencies in three-way markets:
ETH โ Token A โ Token B โ ETH
3. Statistical Arbitrage
Use historical data and machine learning to predict:
- Optimal trade timing
- Price mean reversion
- Liquidity patterns
4. Cross-Chain Arbitrage
Exploit price differences across different blockchains:
- Ethereum vs. BSC
- Ethereum vs. Polygon
- Requires bridges (slower, more complex)
5. Mempool Analysis
Monitor pending transactions:
- Detect large trades before execution
- Identify arbitrage opportunities early
- Execute with higher gas to front-run
6. Private Transactions
Use Flashbots to:
- Submit transactions directly to miners
- Avoid public mempool
- Prevent being front-run
- Pay with MEV-boost
Key Metrics
Performance Indicators
-
Win Rate
$ \text{WinRate} = \text{SuccessfulTrades} / \text{TotalAttempts} \times 100% \text{Target}: >90% $ -
Average Profit Per Trade
AvgProfit = TotalProfit / SuccessfulTrades Target: >0.05 ETH -
ROI (Return on Investment)
$ \text{ROI} = \text{NetProfit} / \text{TotalGasSpent} \times 100% \text{Target}: >200% $ -
Opportunity Detection Rate
DetectionRate = OpportunitiesFound / TimeRunning Target: >10 per hour
Best Practices
1. Start Small
- Test on testnet first
- Start with small trade sizes
- Gradually increase as confidence grows
2. Monitor Constantly
- Set up alerts for failures
- Track all metrics
- Review logs regularly
3. Optimize Continuously
- Analyze failed trades
- Improve gas estimation
- Update token watchlist
4. Stay Updated
- Follow DeFi news
- Monitor new DEXes
- Adapt to market changes
5. Manage Risk
- Never risk more than you can afford
- Set strict profit thresholds
- Have emergency shutdown procedures
Conclusion
Arbitrage trading on Ethereum requires:
- โ Fast execution
- โ Accurate calculations
- โ Risk management
- โ Continuous optimization
- โ Market awareness
Success Rate: Depends on market conditions, competition, and implementation quality.
Expected Returns: Varies greatly (0.1% - 2% per successful trade)
Recommended: Start with paper trading, then small amounts, scale carefully.
Resources
โ ๏ธ Disclaimer: Trading cryptocurrency involves substantial risk. This bot is for educational purposes. Use at your own risk.