A minimal, read-only Python project that simulates DEX arbitrage opportunities using real on-chain state. This tool provides theoretical profit calculations only—no transaction execution, signing, or MEV.
- ✅ Connects to public RPC endpoints (Arbitrum by default)
- ✅ Reads pool reserves via
getReserves()from Uniswap V2-style AMMs - ✅ Implements constant-product swap math with configurable fees
- ✅ Simulates A → B arbitrage between two DEX pools
- ✅ Sweeps input sizes to find optimal trade size
- ✅ Clear console output with profit calculations
- ✅ Block number logging
- ✅ Gas breakeven placeholder
- ✅ Optional CSV output
- Python 3.10 or higher
- Libraries:
web3,eth-abi,numpy
- Clone the repository:
git clone https://github.com/fbl-vol/DEX-Arbitrage.git
cd DEX-Arbitrage- Install dependencies:
pip install -r requirements.txtTry the demo mode first (no RPC connection needed):
python simulate.py --demoRun the simulation script with real on-chain data:
python simulate.pyThe script will:
- Connect to the configured RPC endpoint
- Read current reserves from two DEX pools
- Simulate arbitrage opportunities across a range of input amounts
- Display the optimal trade size and expected profit
All configuration is done in the simulate.py file at the top in the CONFIGURATION SECTION:
# RPC endpoint
RPC_URL = "https://arb1.arbitrum.io/rpc"
# Pool addresses (modify with your target pools)
POOL_1_ADDRESS = "0x905dfCD5649217c42684f23958568e533C711Aa3"
POOL_2_ADDRESS = "0x8e295789c9465487074a65b1ae9Ce0351172393f"
# Token configuration
TOKEN_A_ADDRESS = "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1" # WETH
TOKEN_B_ADDRESS = "0xaf88d065e77c8cC2239327C5EDb3A432268e5831" # USDC
TOKEN_A_DECIMALS = 18
TOKEN_B_DECIMALS = 6
# Fee tier (in basis points)
FEE_BPS = 30 # 0.3%
# Sweep parameters
MIN_INPUT_AMOUNT = 0.01
MAX_INPUT_AMOUNT = 10.0
SWEEP_STEPS = 100To find Uniswap V2-style pools on Arbitrum with the same token pair:
Option 1: Use DEX Analytics Sites
- Sushiswap Analytics - Find Sushiswap V2 pools
- DexScreener - Search across multiple DEXes
- Look for pairs with same tokens (e.g., WETH/USDC) on different platforms
Option 2: On-Chain Exploration
- Use factory contracts to find pair addresses:
- Sushiswap Factory:
0xc35DADB65012eC5796536bD9864eD8773aBc74C4 - Call
getPair(token0, token1)to get pool address
- Sushiswap Factory:
- Verify the pool has
getReserves()method (Uniswap V2 interface)
Common V2-style DEXes on Arbitrum:
- Sushiswap (V2 pools)
- Camelot (V2-style)
- Solidly forks
Important Notes:
- Both pools must have the same token pair (e.g., WETH/USDC.e)
- Both pools must implement the Uniswap V2 interface (
getReserves(),token0(),token1()) - For real arbitrage, use pools from different DEXes (price differences unlikely on same DEX)
- Arbitrum has two USDC tokens:
- USDC.e (bridged):
0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8- Most V2 liquidity - USDC (native):
0xaf88d065e77c8cC2239327C5EDb3A432268e5831- Newer, less V2 liquidity - The default config uses USDC.e as it has more V2 pool options
- USDC.e (bridged):
To analyze different token pairs:
- Update
POOL_1_ADDRESSandPOOL_2_ADDRESSwith your target pools - Update
TOKEN_A_ADDRESSandTOKEN_B_ADDRESSwith the token addresses - Update
TOKEN_A_DECIMALSandTOKEN_B_DECIMALSaccordingly - Verify both pools support
getReserves()by testing in demo mode first
Enable CSV output by setting:
ENABLE_CSV_OUTPUT = TrueAdjust gas cost estimation:
GAS_COST_ETH = 0.001 # Estimated gas cost in ETH======================================================================
DEX ARBITRAGE SIMULATION RESULTS
======================================================================
Block Number: 12345678
--- Pool Reserves Snapshot ---
Pool 1:
Token A Reserve: 1,234.56
Token B Reserve: 2,345,678.90
Pool 2:
Token A Reserve: 1,240.00
Token B Reserve: 2,350,000.00
--- Optimal Arbitrage Opportunity ---
Direction: Pool2→Pool1
Optimal Input Amount (Token A): 5.2500
Gross Profit (Token A): 0.012345
Net Profit (after gas, Token A): 0.011345
Profit Percentage: 0.24%
✅ Profitable arbitrage opportunity detected!
--- Configuration ---
Fee (basis points): 30 (0.3%)
Gas Cost Estimate: 0.001 ETH
======================================================================
- ✅ Read-only simulation of arbitrage opportunities
- ✅ Uniswap V2-style AMMs only
- ✅ Single chain analysis (Arbitrum by default)
- ✅ Two DEX pools, one token pair
- ✅ Theoretical profit calculations
- ❌ No transaction execution
- ❌ No flashloans
- ❌ No mempool access
- ❌ No subgraph queries
- ❌ No private RPCs required
- ❌ No signing or wallet integration
- ❌ No MEV integration
- ✅ Script runs without errors on valid pool addresses
- ✅ Output changes when reserves change (test with different blocks)
- ✅ Profit calculations disappear when fees are set to zero (as expected with constant product)
- ✅ No on-chain state mutations (read-only operations)
- ✅ Easy to modify pair addresses via configuration section
The script uses the Uniswap V2 constant product formula with fees:
amountOut = (amountIn * (10000 - fee) * reserveOut) / (reserveIn * 10000 + amountIn * (10000 - fee))
Where fee is in basis points (e.g., 30 = 0.3%).
The simulation performs bidirectional arbitrage detection:
- Direction 1: Pool1 (Token A → Token B) then Pool2 (Token B → Token A)
- Direction 2: Pool2 (Token A → Token B) then Pool1 (Token B → Token A)
- The script automatically selects the more profitable direction
- Calculate profit: Final Token A - Initial Token A
The script sweeps through multiple input amounts to find the optimal trade size that maximizes profit for the chosen direction.
This codebase is designed to be easily extended for actual trade execution:
- Add wallet/account management
- Add transaction building and signing
- Add gas price optimization
- Add slippage protection
- Add flashloan integration
- Add mempool monitoring
MIT
This is a minimal proof-of-concept. Contributions are welcome for:
- Additional DEX support (Uniswap V3, Curve, etc.)
- Multi-hop arbitrage
- Better optimization algorithms
- Real-time monitoring
- Additional chain support
This tool is for educational and research purposes only. Arbitrage trading involves significant risk. Always test thoroughly before executing real trades. No warranty is provided.