#!/bin/bash # Test script for forked Arbitrum environment set -e echo "๐Ÿš€ Setting up forked Arbitrum environment for MEV bot testing..." # Check if anvil is available if ! command -v anvil &> /dev/null; then echo "โŒ Anvil not found. Please install Foundry first:" echo "curl -L https://foundry.paradigm.xyz | bash" echo "foundryup" exit 1 fi # Kill any existing anvil processes echo "๐Ÿ”„ Stopping any existing anvil processes..." pkill -f anvil || true sleep 2 # Set up environment variables for forked network export ARBITRUM_RPC_ENDPOINT="https://arbitrum-mainnet.core.chainstack.com/53c30e7a941160679fdcc396c894fc57" export ARBITRUM_WS_ENDPOINT="ws://localhost:8545" export METRICS_ENABLED="false" export MEV_BOT_ENCRYPTION_KEY="test-fork-encryption-key-32-chars" export MEV_BOT_ALLOW_LOCALHOST="true" # Start anvil with Arbitrum fork echo "๐Ÿ”— Starting anvil with Arbitrum One fork..." anvil \ --fork-url "$ARBITRUM_RPC_ENDPOINT" \ --fork-block-number 250000000 \ --host 0.0.0.0 \ --port 8545 \ --accounts 10 \ --balance 1000 \ --gas-limit 30000000 \ --gas-price 100000000 \ --block-time 1 \ --silent & ANVIL_PID=$! echo "๐Ÿ“Š Anvil started with PID: $ANVIL_PID" # Wait for anvil to be ready echo "โณ Waiting for anvil to be ready..." sleep 5 # Verify anvil is running if ! curl -s -X POST \ -H "Content-Type: application/json" \ --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \ http://localhost:8545 > /dev/null; then echo "โŒ Anvil failed to start properly" kill $ANVIL_PID 2>/dev/null || true exit 1 fi echo "โœ… Anvil fork ready on http://localhost:8545" # Update RPC endpoint to use local fork export ARBITRUM_RPC_ENDPOINT="http://localhost:8545" # Build the MEV bot echo "๐Ÿ”จ Building MEV bot..." go build -o bin/mev-bot cmd/mev-bot/main.go if [ $? -ne 0 ]; then echo "โŒ Failed to build MEV bot" kill $ANVIL_PID 2>/dev/null || true exit 1 fi echo "โœ… MEV bot built successfully" # Test the bot with fork echo "๐Ÿงช Testing MEV bot with forked environment..." # Run bot for 30 seconds to test timeout 30 ./bin/mev-bot start || true echo "๐ŸŽฏ Fork test completed" # Cleanup function cleanup() { echo "๐Ÿงน Cleaning up..." kill $ANVIL_PID 2>/dev/null || true wait $ANVIL_PID 2>/dev/null || true echo "โœ… Cleanup completed" } # Set up trap for cleanup trap cleanup EXIT # Keep anvil running if requested if [ "$1" = "--keep-running" ]; then echo "๐Ÿ”„ Keeping anvil running. Press Ctrl+C to stop." echo "๐Ÿ“ Fork URL: http://localhost:8545" echo "๐Ÿ”— Chain ID: 42161 (Arbitrum One)" echo "๐Ÿ’ฐ Test accounts funded with 1000 ETH each" echo "" echo "To test manually:" echo "export ARBITRUM_RPC_ENDPOINT=\"http://localhost:8545\"" echo "export ARBITRUM_WS_ENDPOINT=\"ws://localhost:8545\"" echo "export MEV_BOT_ENCRYPTION_KEY=\"test-fork-encryption-key-32-chars\"" echo "export MEV_BOT_ALLOW_LOCALHOST=\"true\"" echo "./bin/mev-bot start" # Wait for user interrupt wait $ANVIL_PID else echo "๐Ÿ Test completed. Use --keep-running to keep the fork active." fi