#!/usr/bin/env bash set -euo pipefail # run.sh - Run the MEV bot # Builds and starts the MEV bot with production configuration echo "Running MEV bot..." # Set default GO_ENV if not already set (production by default) export GO_ENV="${GO_ENV:-production}" # Build the application first ./scripts/build.sh if [ $? -eq 0 ]; then # Normalize GO_ENV when passed as .env.* style if [[ -n "$GO_ENV" && "$GO_ENV" == .env.* ]]; then GO_ENV="${GO_ENV#.env.}" export GO_ENV fi # Load environment variables based on GO_ENV if [ "$GO_ENV" = "development" ]; then echo "🔧 Development mode: Using .env for local configuration..." if [ -f ".env" ]; then set -a source .env set +a fi else # Production mode requires .env.production if [ -f ".env.production" ]; then echo "🔧 Loading production environment variables from .env.production..." set -a # Automatically export all variables source .env.production set +a # Stop automatically exporting else echo "❌ .env.production file not found! Creating one with defaults..." echo "Please configure .env.production for production deployment" exit 1 fi fi # Validate required environment variables (production mode only) if [ "$GO_ENV" != "development" ]; then if [ -z "${MEV_BOT_ENCRYPTION_KEY:-}" ]; then echo "❌ MEV_BOT_ENCRYPTION_KEY not found in .env.production" echo "Please set this variable for secure operations" exit 1 fi if [ -z "${CONTRACT_ARBITRAGE_EXECUTOR:-}" ]; then echo "❌ CONTRACT_ARBITRAGE_EXECUTOR not found in .env.production" echo "Please set the deployed arbitrage executor contract address" exit 1 fi fi # Set required environment variables with production values export ARBITRUM_RPC_ENDPOINT="${ARBITRUM_RPC_ENDPOINT:-wss://arbitrum-mainnet.core.chainstack.com/53c30e7a941160679fdcc396c894fc57}" export ARBITRUM_WS_ENDPOINT="${ARBITRUM_WS_ENDPOINT:-$ARBITRUM_RPC_ENDPOINT}" export METRICS_ENABLED="${METRICS_ENABLED:-true}" export METRICS_PORT="${METRICS_PORT:-9090}" export MEV_BOT_KEYSTORE_PATH="${MEV_BOT_KEYSTORE_PATH:-keystore/production}" export MEV_BOT_AUDIT_LOG="${MEV_BOT_AUDIT_LOG:-logs/production_audit.log}" export MEV_BOT_BACKUP_PATH="${MEV_BOT_BACKUP_PATH:-backups/production}" mkdir -p "$MEV_BOT_KEYSTORE_PATH" mkdir -p "$MEV_BOT_BACKUP_PATH" mkdir -p "$(dirname "$MEV_BOT_AUDIT_LOG")" echo "Keystore path: $MEV_BOT_KEYSTORE_PATH" env | grep MEV_BOT_KEYSTORE_PATH echo "" if [ "$GO_ENV" = "development" ]; then echo "🚀 DEVELOPMENT MEV BOT STARTUP" echo "===============================" else echo "🚀 PRODUCTION MEV BOT STARTUP" echo "==============================" fi echo "Environment: $GO_ENV" echo "" echo "📡 Network Configuration:" echo " RPC: ${ARBITRUM_RPC_ENDPOINT:-not set}" echo " WS: ${ARBITRUM_WS_ENDPOINT:-not set}" echo " Metrics Port: ${METRICS_PORT:-9090}" echo "" if [ "$GO_ENV" != "development" ] && [ -n "${CONTRACT_ARBITRAGE_EXECUTOR:-}" ]; then echo "📝 Deployed Contracts:" echo " ArbitrageExecutor: $CONTRACT_ARBITRAGE_EXECUTOR" echo " FlashSwapper: ${CONTRACT_FLASH_SWAPPER:-not set}" echo " DataFetcher: ${CONTRACT_DATA_FETCHER:-not set}" echo "" fi if [ -n "${MEV_BOT_ENCRYPTION_KEY:-}" ]; then echo "🔐 Security:" echo " Encryption Key: ${MEV_BOT_ENCRYPTION_KEY:0:8}...***" echo "" fi # Set provider config path if not already set export PROVIDER_CONFIG_PATH="${PROVIDER_CONFIG_PATH:-$PWD/config/providers_runtime.yaml}" echo "📋 Provider Config: $PROVIDER_CONFIG_PATH" echo "" # Run the application ./bin/mev-beta start else echo "Failed to build the application!" exit 1 fi