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>
11 KiB
Smart Contract Deployment Guide
This guide covers deploying the MEV Bot smart contracts to Arbitrum mainnet and testnet.
📋 Table of Contents
- Prerequisites
- Contract Overview
- Deployment Process
- Testnet Deployment
- Mainnet Deployment
- Verification
- Post-Deployment
- Troubleshooting
Prerequisites
Required Tools
- Foundry (Solidity development toolkit)
curl -L https://foundry.paradigm.xyz | bash
foundryup
-
Deployer Wallet with ETH on Arbitrum
- Testnet: Get test ETH from Arbitrum Goerli Faucet
- Mainnet: Ensure sufficient ETH for gas (~0.01 ETH recommended)
-
RPC Endpoint
- Free: https://arb1.arbitrum.io/rpc
- Recommended: Alchemy, Chainstack, or Infura
-
Arbiscan API Key (optional, for verification)
- Get from: https://arbiscan.io/myapikey
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.deploymentfile - Use a dedicated deployer wallet (not your main wallet)
- Test on testnet before mainnet deployment
Contract Overview
Contracts to Deploy
-
ProductionArbitrageExecutor (
contracts/ProductionArbitrageExecutor.sol)- Main arbitrage execution contract
- Handles flash swaps and multi-DEX arbitrage
- Access controlled with role-based permissions
- Emergency pause functionality
-
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
- Install dependencies:
forge install OpenZeppelin/openzeppelin-contracts --no-commit
- Load environment variables:
source .env.deployment
- 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
- 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
- Set testnet RPC:
export ARBITRUM_RPC_ENDPOINT="https://goerli-rollup.arbitrum.io/rpc"
export NETWORK="arbitrum-goerli"
- Deploy:
./scripts/deploy-contracts.sh
- 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.deploymentfile secure and not committed- Backup of all deployment scripts
Deployment Steps
- 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
- Set mainnet RPC:
export ARBITRUM_RPC_ENDPOINT="https://arb1.arbitrum.io/rpc"
export NETWORK="arbitrum"
export VERIFY="true" # Enable contract verification
- 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
- 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
- Check on Arbiscan:
# View contract
open "https://arbiscan.io/address/<contract_address>"
- 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 addressesconfig/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
- Foundry Book: https://book.getfoundry.sh/
- Arbitrum Docs: https://docs.arbitrum.io/
- Arbiscan: https://arbiscan.io/
Support
- Foundry Discord: https://discord.gg/foundry
- Arbitrum Discord: https://discord.gg/arbitrum
Security
- OpenZeppelin Contracts: https://docs.openzeppelin.com/contracts/
- Smart Contract Security Best Practices: https://consensys.github.io/smart-contract-best-practices/
Deployment Records
All deployments are logged in:
deployments/- Deployment JSONslogs/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.