A sophisticated arbitrage bot designed for the Base network that monitors Uniswap V3, SushiSwap, Aerodrome, and Balancer V2 DEXes for profitable trading opportunities. The bot features comprehensive safety checks, real-time execution capabilities, and fallback mechanisms for token handling.
- Uniswap V3: Monitors all pools with real-time price data
- SushiSwap: Scans factory pairs for arbitrage opportunities
- Aerodrome: Tracks concentrated liquidity pools
- Real-time price comparison across all three DEXes
- Safe Mode: Restricts trading to small amounts ($5) and safe tokens
- Position Size Limits: Configurable position sizes (default: $5 for testing)
- Profit Range Validation: 1-20% profit thresholds for realistic opportunities
- Liquidity Requirements: Minimum $100k liquidity for safe execution
- Token Validation: Prevents invalid swaps (e.g., WETH-to-WETH)
- Fallback Logic: Handles inaccessible tokens gracefully
- Live Trading Mode: Execute real transactions on Base network
- Simulation Mode: Safe testing without sending transactions
- Token Approvals: Automatic ERC20 approvals for DEX routers
- Gas Optimization: Base network optimized gas settings
- Transaction Monitoring: Real-time transaction status tracking
- Flash Loan Support: Calculates flash loan arbitrage opportunities
- MEV Protection: Accounts for MEV bot costs in profit calculations
- Slippage Protection: Configurable slippage limits (default: 1%)
- Error Handling: Comprehensive error recovery and logging
- Balance Checking: Validates wallet balances before execution
Create a .env file with the following variables:
# Web3 Provider
WEB3_PROVIDER=https://mainnet.base.org
# API Keys
UNISWAP_API_KEY=your_uniswap_api_key
UNISWAP_V3_SUBGRAPH=https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3
AERODROME_SUBGRAPH=https://api.thegraph.com/subgraphs/name/aerodrome-finance/exchange-v2
# Contract Addresses
SUSHI_FACTORY_ADDRESS=0x6B3595068778DD592e39A122f4f5a5cF09C90fE2
# Wallet (for live trading)
PRIVATE_KEY=your_private_key_here# Safe testing configuration
POSITION_SIZE_USD = 5 # $5 position size for testing
MIN_PROFIT_PCT = 1.0 # 1% minimum profit
MAX_PROFIT_PCT = 20.0 # 20% maximum profit
MIN_LIQUIDITY_USD = 100000 # $100k minimum liquidity
SAFE_MODE = True # Enable safety restrictions
SIMULATION_MODE = False # Set to True for simulation only# Clone the repository
git clone <repository-url>
cd Arbitrage-Bot
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .env
# Edit .env with your configuration# Edit config.py to set SIMULATION_MODE = True
python3 scripts/monitoring/arbitrage_bot.py# Edit config.py to set:
# - SIMULATION_MODE = False
# - EXECUTION_MODE = True
# - Add your PRIVATE_KEY to .env
python3 scripts/monitoring/arbitrage_bot.py-
Simulation Mode:
- No real transactions sent
- Safe for testing and learning
- Shows what trades would be executed
-
Live Mode:
- Real transactions on Base network
- Requires funded wallet
- Uses safe position sizes ($5 default)
- Position Size Limits: Maximum $10 for safe testing
- Token Restrictions: Only major tokens (WETH, USDC, etc.)
- Profit Validation: Realistic profit ranges only
- Liquidity Checks: Minimum liquidity requirements
- Balance Validation: Checks wallet balances before execution
- Educational Purpose: This bot is for learning and testing
- Small Amounts: Designed for small position sizes
- Base Network: Optimized for Base network conditions
- No Guarantees: Cryptocurrency trading involves risk
- WETH: 0x4200000000000000000000000000000000000006
- USDC: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
- weETH: 0xd9aa30E1B4c60CAe79FC379ff651abACE84F5AA9
The bot handles token accessibility issues:
- Falls back to WETH if specific tokens are inaccessible
- Prevents invalid swaps (same token to same token)
- Validates token contracts before execution
π Real-Time Arbitrage Bot - Safe Testing Mode
============================================================
π Found 150 Uniswap pools
π Found 89 SushiSwap pools
π Found 67 Aerodrome pools
π₯ Found 3 executable arbitrage opportunities:
1. WETH/weETH (FLASH_LOAN)
Buy on Uniswap @ 1.000123
Sell on SushiSwap @ 1.000456
Profit: 0.33%
Net Profit: $1.23
π Checking available tokens for 0x1234...
β
WETH: 1000000000000000000 wei
β
USDC: 5000000 wei
β weETH: 0 wei
- Multi-DEX price monitoring
- Real-time arbitrage detection
- Safe execution mode with $5 positions
- Token approval and swap execution
- Comprehensive error handling
- Balance validation and fallback logic
- Flash loan profit calculations
- MEV protection cost estimation
- Active Development: Bot is running live with safety features
- Base Network Optimized: Configured for Base network conditions
- Safe Testing Mode: Using small position sizes for validation
- Real Execution: Can execute actual trades (with safety limits)
- Backrun Mode (WIP): We're currently working on an experimental Backrun Mode, which monitors pending transactions (via MEV-Share) and attempts to sandwich them by executing profitable trades after the target transaction. This feature is still under active development and not production-ready yet.
- Additional DEX support (PancakeSwap, etc.)
- Advanced MEV protection strategies
- Automated position sizing based on liquidity
- Web dashboard for monitoring
- Telegram/Discord notifications
- No Financial Advice: This is not investment advice
- Risk Warning: Cryptocurrency trading involves substantial risk
- Small Amounts: Designed for small position sizes only
- Testing Focus: Use simulation mode for learning
- No Guarantees: Past performance doesn't guarantee future results
This project is for educational purposes. Use at your own risk.
Current Version: v2.0 - Base Network Optimized with Safety Features Last Updated: December 2024
The bot now supports flash loan arbitrage for enhanced capital efficiency. Here's how the full flow works:
π Scanning DEXes β π Finding price differences β π Calculating flash loan vs regular profit
- Regular Arbitrage: Uses your own capital (current $5 position size)
- Flash Loan Arbitrage: Borrows large amounts ($100k) for maximum profit
Step 1: Flash Loan Request
# Borrow $100k worth of tokens from Aave
flash_loan_amount = 100000 # USD
flash_loan_token = WETH_BASE # Most liquid token
flash_loan_function = aave_lending_pool.borrow(
flash_loan_token,
flash_loan_amount_wei,
2, # Variable interest rate
0, # Referral code
wallet_address
)Step 2: Arbitrage Execution
# Execute arbitrage with borrowed funds
1. Approve borrowed tokens for buy DEX
2. Buy token on cheaper DEX (e.g., Uniswap)
3. Approve received tokens for sell DEX
4. Sell token on expensive DEX (e.g., SushiSwap)
5. Receive profit + original borrowed amountStep 3: Flash Loan Repayment
# Repay flash loan with fees
flash_loan_fee = 0.09% # Aave flash loan fee
total_repay = borrowed_amount + flash_loan_fee
repay_function = aave_lending_pool.repay(
flash_loan_token,
total_repay_amount,
2, # Variable interest rate
wallet_address
)Regular Arbitrage (Current):
- Position Size: $5
- Profit: ~$0.25 (5% of $5)
- Capital Required: $5
Flash Loan Arbitrage (Enhanced):
- Position Size: $100,000
- Profit: ~$500 (0.5% of $100k)
- Capital Required: $0 (borrowed)
- Flash Loan Fee: $90 (0.09%)
- Net Profit: $410
Flash Loan Safety Features:
- Minimum Profit Threshold: $50 minimum profit to use flash loans
- Maximum Position Size: $100k flash loan limit
- Fee Calculation: 0.09% Aave flash loan fee
- Gas Optimization: Base network low gas costs
- Error Handling: Comprehensive failure recovery
Risk Mitigation:
- Atomic Transactions: All operations in single transaction
- Slippage Protection: 1% maximum slippage
- Liquidity Checks: Minimum $100k pool liquidity
- Token Validation: Only major tokens (WETH, USDC)
Safe Mode (Current):
SAFE_MODE = True
FLASH_LOAN_ENABLED = False # Disabled for safety
# Uses regular arbitrage with $5 positionsFlash Loan Mode (Advanced):
SAFE_MODE = False
FLASH_LOAN_ENABLED = True
# Uses flash loans for $100k positionsScenario: WETH/weETH arbitrage opportunity
π Price Difference Detected:
Uniswap: 1.000123 WETH/weETH
SushiSwap: 1.000456 WETH/weETH
Profit: 0.33%
π Flash Loan Execution:
1. Borrow 40 WETH ($100k) from Aave
2. Buy 40 weETH on Uniswap @ 1.000123
3. Sell 40 weETH on SushiSwap @ 1.000456
4. Receive 40.133 WETH (profit: 0.133 WETH)
5. Repay 40 WETH + 0.036 WETH fee to Aave
6. Keep 0.097 WETH profit (~$242)
π° Net Result:
Gross Profit: $330
Flash Loan Fee: $90
Gas Costs: $2
Net Profit: $238
Flash Loan Contract Integration:
# Aave V3 Lending Pool (Base Network)
AAVE_LENDING_POOL = "0xA238Dd80C259a72e81d7e4664a9801593F98d1c5"
# Flash Loan Settings
FLASH_LOAN_AMOUNT_USD = 100000 # $100k
FLASH_LOAN_FEE_PCT = 0.0009 # 0.09%
FLASH_LOAN_MIN_PROFIT_USD = 50 # $50 minimumExecution Methods:
execute_flash_loan_arbitrage(): Main flash loan executionexecute_flash_loan_operation(): Flash loan request and repaymentexecute_arbitrage_with_flash_loan(): Arbitrage with borrowed fundsrepay_flash_loan(): Flash loan repayment with fees
Flash Loan Execution Logs:
π Executing FLASH LOAN arbitrage: WETH/weETH
Buy on Uniswap @ 1.000123
Sell on SushiSwap @ 1.000456
Expected profit: 0.33%
Flash loan amount: $100,000
π Initiating flash loan for 40000000000000000000 wei...
β
Flash loan requested: 0x1234...
β
Flash loan received!
π Executing arbitrage with flash loaned funds...
β
Arbitrage with flash loan completed!
π° Repaying flash loan...
Original amount: 40000000000000000000 wei
Flash loan fee: 36000000000000000 wei
Total to repay: 40036000000000000000 wei
β
Flash loan repaid successfully!
β
Flash loan arbitrage executed successfully!
Capital Efficiency:
- No Capital Required: Borrow instead of using own funds
- Larger Positions: $100k vs $5 positions
- Higher Profits: Scale with borrowed amount
Risk Management:
- Atomic Execution: All operations in single transaction
- No Liquidation Risk: Flash loans are repaid immediately
- Predictable Costs: Fixed flash loan fees
Profit Optimization:
- MEV Protection: Flash loans are harder to front-run
- Gas Efficiency: Single transaction vs multiple
- Slippage Reduction: Larger orders can get better prices
Current Status: Flash loan functionality is implemented and ready for testing. Currently disabled in safe mode for security.
Your arbitrage bot can be packaged as both desktop and mobile applications!
- Install Node.js: Download from nodejs.org (LTS version for Windows)
- Check Prerequisites: Run
frontend\check-setup.batto verify your setup - Choose Your Platform:
- Desktop: Install Rust from rustup.rs, then run
npm run tauri:dev - Mobile: Install Android Studio, then run
npm run mobile:dev
- Desktop: Install Rust from rustup.rs, then run
- π₯οΈ Desktop App (Tauri): Native Windows/macOS/Linux application
- π± Mobile App (Capacitor): Android/iOS app with native device integration
- π¨ Modern UI: Beautiful React dashboard with real-time charts
- π Real-time Updates: WebSocket connection to your Python bot
- π‘οΈ Security: Simulation mode, safe mode, and secure key handling
See frontend/DESKTOP_MOBILE_SETUP.md for detailed instructions.