Files
mev-beta/docs/DEPLOYMENT_GUIDE.md
Krypto Kajun c7142ef671 fix(critical): fix empty token graph + aggressive settings for 24h execution
CRITICAL BUG FIX:
- MultiHopScanner.updateTokenGraph() was EMPTY - adding no pools!
- Result: Token graph had 0 pools, found 0 arbitrage paths
- All opportunities showed estimatedProfitETH: 0.000000

FIX APPLIED:
- Populated token graph with 8 high-liquidity Arbitrum pools:
  * WETH/USDC (0.05% and 0.3% fees)
  * USDC/USDC.e (0.01% - common arbitrage)
  * ARB/USDC, WETH/ARB, WETH/USDT
  * WBTC/WETH, LINK/WETH
- These are REAL verified pool addresses with high volume

AGGRESSIVE THRESHOLD CHANGES:
- Min profit: 0.0001 ETH → 0.00001 ETH (10x lower, ~$0.02)
- Min ROI: 0.05% → 0.01% (5x lower)
- Gas multiplier: 5x → 1.5x (3.3x lower safety margin)
- Max slippage: 3% → 5% (67% higher tolerance)
- Max paths: 100 → 200 (more thorough scanning)
- Cache expiry: 2min → 30sec (fresher opportunities)

EXPECTED RESULTS (24h):
- 20-50 opportunities with profit > $0.02 (was 0)
- 5-15 execution attempts (was 0)
- 1-2 successful executions (was 0)
- $0.02-$0.20 net profit (was $0)

WARNING: Aggressive settings may result in some losses
Monitor closely for first 6 hours and adjust if needed

Target: First profitable execution within 24 hours

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-29 04:18:27 -05:00

11 KiB

Smart Contract Deployment Guide

This guide covers deploying the MEV Bot smart contracts to Arbitrum mainnet and testnet.

📋 Table of Contents


Prerequisites

Required Tools

  1. Foundry (Solidity development toolkit)
curl -L https://foundry.paradigm.xyz | bash
foundryup
  1. Deployer Wallet with ETH on Arbitrum

    • Testnet: Get test ETH from Arbitrum Goerli Faucet
    • Mainnet: Ensure sufficient ETH for gas (~0.01 ETH recommended)
  2. RPC Endpoint

  3. Arbiscan API Key (optional, for verification)

Environment Setup

Create .env.deployment file:

# Deployer private key (NEVER commit this!)
DEPLOYER_PRIVATE_KEY="0x..."

# RPC endpoint
ARBITRUM_RPC_ENDPOINT="https://arb1.arbitrum.io/rpc"

# Arbiscan API key (for verification)
ARBISCAN_API_KEY="YOUR_API_KEY"

⚠️ SECURITY WARNING:

  • NEVER commit private keys to git
  • NEVER share your .env.deployment file
  • Use a dedicated deployer wallet (not your main wallet)
  • Test on testnet before mainnet deployment

Contract Overview

Contracts to Deploy

  1. ProductionArbitrageExecutor (contracts/ProductionArbitrageExecutor.sol)

    • Main arbitrage execution contract
    • Handles flash swaps and multi-DEX arbitrage
    • Access controlled with role-based permissions
    • Emergency pause functionality
  2. FlashLoanReceiver (contracts/balancer/FlashLoanReceiver.sol)

    • Balancer flash loan integration
    • Used for capital-efficient arbitrage
    • Flash loan callback handler

Contract Addresses (Production)

Current deployed addresses (update after deployment):

# Arbitrum Mainnet
ProductionArbitrageExecutor: 0xec2a16d5f8ac850d08c4c7f67efd50051e7cfc0b
FlashLoanReceiver: 0x5801ee5c2f6069e0f11cce7c0f27c2ef88e79a95

Deployment Process

Quick Start

  1. Install dependencies:
forge install OpenZeppelin/openzeppelin-contracts --no-commit
  1. Load environment variables:
source .env.deployment
  1. Deploy contracts:
./scripts/deploy-contracts.sh

Manual Deployment

If you prefer manual control:

1. Compile Contracts

# Set Foundry to use contracts directory
export FOUNDRY_SRC="contracts"
export FOUNDRY_OUT="out"

# Compile
forge build

2. Deploy ProductionArbitrageExecutor

forge create contracts/ProductionArbitrageExecutor.sol:ProductionArbitrageExecutor \
    --rpc-url "$ARBITRUM_RPC_ENDPOINT" \
    --private-key "$DEPLOYER_PRIVATE_KEY"

Save the deployed address!

3. Deploy FlashLoanReceiver

forge create contracts/balancer/FlashLoanReceiver.sol:FlashLoanReceiver \
    --rpc-url "$ARBITRUM_RPC_ENDPOINT" \
    --private-key "$DEPLOYER_PRIVATE_KEY"

4. Verify Contracts (optional)

# Verify ProductionArbitrageExecutor
./scripts/verify-contracts.sh <arbitrage_executor_address> ProductionArbitrageExecutor

# Verify FlashLoanReceiver
./scripts/verify-contracts.sh <flash_loan_receiver_address> FlashLoanReceiver

Testnet Deployment

Arbitrum Goerli Testnet

  1. Get test ETH:
# Visit faucet
open https://faucet.triangleplatform.com/arbitrum/goerli

# Or use bridge from Goerli L1
open https://bridge.arbitrum.io/?l2ChainId=421613
  1. Set testnet RPC:
export ARBITRUM_RPC_ENDPOINT="https://goerli-rollup.arbitrum.io/rpc"
export NETWORK="arbitrum-goerli"
  1. Deploy:
./scripts/deploy-contracts.sh
  1. Test the deployment:
# Check contract is deployed
cast code <contract_address> --rpc-url "$ARBITRUM_RPC_ENDPOINT"

# Should return bytecode (not 0x)

Mainnet Deployment

Pre-Deployment Checklist

  • Contracts audited or thoroughly reviewed
  • Tested on testnet successfully
  • Deployer wallet has sufficient ETH (~0.01 ETH)
  • Environment variables configured correctly
  • .env.deployment file secure and not committed
  • Backup of all deployment scripts

Deployment Steps

  1. Final review:
# Review contracts
cat contracts/ProductionArbitrageExecutor.sol
cat contracts/balancer/FlashLoanReceiver.sol

# Check gas estimation
forge estimate --rpc-url "$ARBITRUM_RPC_ENDPOINT" \
    contracts/ProductionArbitrageExecutor.sol:ProductionArbitrageExecutor
  1. Set mainnet RPC:
export ARBITRUM_RPC_ENDPOINT="https://arb1.arbitrum.io/rpc"
export NETWORK="arbitrum"
export VERIFY="true"  # Enable contract verification
  1. Deploy contracts:
./scripts/deploy-contracts.sh

The script will:

  • Validate environment
  • Compile contracts
  • Deploy both contracts
  • Verify on Arbiscan (if enabled)
  • Update configuration files
  • Save deployment records
  1. Backup deployment data:
# Save deployment logs and addresses
cp -r deployments deployments_backup_$(date +%Y%m%d_%H%M%S)
cp logs/deployment_*.log logs/deployment_backup_$(date +%Y%m%d_%H%M%S).log

Verification

Automatic Verification

Enable during deployment:

export VERIFY="true"
export ARBISCAN_API_KEY="YOUR_API_KEY"
./scripts/deploy-contracts.sh

Manual Verification

If automatic verification fails:

# Verify ProductionArbitrageExecutor
./scripts/verify-contracts.sh <address> ProductionArbitrageExecutor

# Verify FlashLoanReceiver
./scripts/verify-contracts.sh <address> FlashLoanReceiver

Verify Deployment

  1. Check on Arbiscan:
# View contract
open "https://arbiscan.io/address/<contract_address>"
  1. Test contract calls:
# Check contract owner
cast call <contract_address> "hasRole(bytes32,address)(bool)" \
    0x0000000000000000000000000000000000000000000000000000000000000000 \
    <your_deployer_address> \
    --rpc-url "$ARBITRUM_RPC_ENDPOINT"

# Should return: true

Post-Deployment

1. Update Configuration Files

The deployment script automatically updates:

  • .env.production - Contract addresses
  • config/arbitrum_production.yaml - Production config

Verify updates:

grep CONTRACT_ARBITRAGE_EXECUTOR .env.production
grep arbitrage_contract_address config/arbitrum_production.yaml

2. Grant Contract Permissions

Grant necessary roles to the MEV bot:

# Get your bot wallet address
BOT_ADDRESS="0x..."  # From keystore

# Grant EXECUTOR_ROLE to bot
cast send <arbitrage_executor_address> \
    "grantRole(bytes32,address)" \
    $(cast keccak "EXECUTOR_ROLE") \
    "$BOT_ADDRESS" \
    --rpc-url "$ARBITRUM_RPC_ENDPOINT" \
    --private-key "$DEPLOYER_PRIVATE_KEY"

3. Test Contract Integration

# Run bot in test mode
LOG_LEVEL=debug timeout 60 ./bin/mev-beta start

# Check logs for contract initialization
grep "Flash swap executor initialized" logs/mev_bot.log

4. Fund Contracts (if needed)

Some strategies may require initial ETH or token balance:

# Send ETH to arbitrage executor
cast send <arbitrage_executor_address> \
    --value 0.1ether \
    --rpc-url "$ARBITRUM_RPC_ENDPOINT" \
    --private-key "$DEPLOYER_PRIVATE_KEY"

5. Set Up Monitoring

Monitor contract activity:

# Watch for events
cast logs --address <contract_address> \
    --rpc-url "$ARBITRUM_RPC_ENDPOINT" \
    --from-block latest \
    --follow

Troubleshooting

Deployment Fails with "insufficient funds"

Problem: Deployer wallet has insufficient ETH

Solution:

# Check balance
cast balance <deployer_address> --rpc-url "$ARBITRUM_RPC_ENDPOINT"

# Send more ETH to deployer wallet

Verification Fails

Problem: Contract verification on Arbiscan fails

Solution:

# Retry with specific compiler version
forge verify-contract \
    --chain-id 42161 \
    --compiler-version "v0.8.19+commit.7dd6d404" \
    --num-of-optimizations 200 \
    --etherscan-api-key "$ARBISCAN_API_KEY" \
    <contract_address> \
    contracts/ProductionArbitrageExecutor.sol:ProductionArbitrageExecutor

Contract Compilation Errors

Problem: Missing dependencies or Solidity version mismatch

Solution:

# Reinstall dependencies
rm -rf lib
forge install OpenZeppelin/openzeppelin-contracts --no-commit

# Check Solidity version
forge --version

# Update Foundry
foundryup

RPC Connection Issues

Problem: Cannot connect to RPC endpoint

Solution:

# Test RPC connection
cast client --rpc-url "$ARBITRUM_RPC_ENDPOINT"

# Try alternative RPC
export ARBITRUM_RPC_ENDPOINT="https://arbitrum.llamarpc.com"

Gas Estimation Errors

Problem: Transaction gas estimation fails

Solution:

# Get current gas price
cast gas-price --rpc-url "$ARBITRUM_RPC_ENDPOINT"

# Manually set gas limit
forge create ... --gas-limit 5000000

Deployment Checklist

Pre-Deployment

  • Foundry installed and updated
  • Deployer wallet funded with ETH
  • RPC endpoint configured and tested
  • Environment variables set
  • Contracts compiled successfully
  • Testnet deployment tested
  • Security review completed

During Deployment

  • Deployment script executed
  • ProductionArbitrageExecutor deployed
  • FlashLoanReceiver deployed
  • Deployment addresses saved
  • Configuration files updated
  • Contracts verified on Arbiscan

Post-Deployment

  • Contract addresses verified on Arbiscan
  • Permissions granted to bot wallet
  • Test transaction executed successfully
  • Monitoring set up
  • Deployment documentation updated
  • Team notified of deployment
  • Deployment backups created

Additional Resources

Documentation

Support

Security


Deployment Records

All deployments are logged in:

  • deployments/ - Deployment JSONs
  • logs/deployment_*.log - Detailed logs

Example deployment record:

{
  "network": "arbitrum",
  "timestamp": "2025-10-27T16:00:00Z",
  "contracts": {
    "ProductionArbitrageExecutor": {
      "address": "0x...",
      "verified": true
    },
    "FlashLoanReceiver": {
      "address": "0x...",
      "verified": true
    }
  }
}

Need Help? Check the Troubleshooting section or review deployment logs in logs/deployment_*.log.