๐Ÿ“Š Ethereum MEV Arbitrage Strategy Guide

October 12, 2025 ยท View on GitHub

Table of Contents


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

  1. Price Discovery: Monitor multiple DEXes simultaneously
  2. Speed: Execute trades before the opportunity disappears
  3. Capital Efficiency: Use flashloans to trade without upfront capital
  4. 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:

  1. Detect large swap transaction in mempool
  2. Front-run: Buy tokens before the large swap
  3. Large swap executes (moves price up)
  4. 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

  1. Price Fetcher

    • Monitors multiple DEX prices
    • Uses WebSocket for real-time data
    • Implements caching to reduce RPC calls
  2. Profit Calculator

    • Estimates potential profit
    • Accounts for all fees (DEX, flashloan, gas)
    • Calculates optimal trade size
  3. Gas Estimator

    • Monitors current gas prices
    • Implements EIP-1559 support
    • Uses multiple data sources
  4. Arbitrage Bot

    • Orchestrates all components
    • Makes execution decisions
    • Manages risk and safety checks
  5. 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

  1. Minimum Profit Threshold

    Only execute if: NetProfit > MinThreshold (e.g., 0.01 ETH)
    
  2. Maximum Gas Price

    Only execute if: GasPrice < MaxGasPrice (e.g., 100 gwei)
    
  3. Slippage Protection

    Set minimum output amount based on slippage tolerance
    
  4. Position Size Limits

    MaxTradeSize = min(AvailableLiquidity ร— 0.8, MaxConfigured)
    
  5. Atomic Transactions

    All trades execute in one transaction
    If any step fails, entire transaction reverts
    No partial execution = No loss risk
    

Risk Factors

RiskMitigation
Gas price volatilityMonitor and set max gas price
Front-runningUse private RPC, optimized routing
SlippageCalculate price impact, set limits
Smart contract bugsAudit code, test extensively
Network congestionAdjust parameters dynamically
Failed transactionsSimulate 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

  1. Increase Trade Size

    • Fixed costs (gas) spread over larger amount
    • Higher absolute profit
  2. Reduce Gas Costs

    • Optimize smart contract
    • Batch multiple arbitrages
    • Choose off-peak times
  3. Find Better Opportunities

    • Monitor more tokens
    • Include more DEXes
    • Use faster detection
  4. 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

  1. Win Rate $ \text{WinRate} = \text{SuccessfulTrades} / \text{TotalAttempts} \times 100% \text{Target}: >90% $

  2. Average Profit Per Trade

    AvgProfit = TotalProfit / SuccessfulTrades
    Target: >0.05 ETH
    
  3. ROI (Return on Investment) $ \text{ROI} = \text{NetProfit} / \text{TotalGasSpent} \times 100% \text{Target}: >200% $

  4. 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.