Completed clean root directory structure: - Root now contains only: .git, .env, docs/, orig/ - Moved all remaining files and directories to orig/: - Config files (.claude, .dockerignore, .drone.yml, etc.) - All .env variants (except active .env) - Git config (.gitconfig, .github, .gitignore, etc.) - Tool configs (.golangci.yml, .revive.toml, etc.) - Documentation (*.md files, @prompts) - Build files (Dockerfiles, Makefile, go.mod, go.sum) - Docker compose files - All source directories (scripts, tests, tools, etc.) - Runtime directories (logs, monitoring, reports) - Dependency files (node_modules, lib, cache) - Special files (--delete) - Removed empty runtime directories (bin/, data/) V2 structure is now clean: - docs/planning/ - V2 planning documents - orig/ - Complete V1 codebase preserved - .env - Active environment config (not in git) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
388 lines
11 KiB
Bash
Executable File
388 lines
11 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# MEV Bot Smart Contract Deployment Script
|
|
# Deploys ArbitrageExecutor and FlashLoanReceiver contracts to Arbitrum
|
|
|
|
set -euo pipefail # Exit on error, undefined vars, pipe failures
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Configuration
|
|
NETWORK="${NETWORK:-arbitrum}"
|
|
VERIFY="${VERIFY:-false}"
|
|
DEPLOYMENT_LOG="logs/deployment_$(date +%Y%m%d_%H%M%S).log"
|
|
|
|
# Contract source directory (Mev-Alpha project)
|
|
CONTRACTS_DIR="${CONTRACTS_DIR:-/home/administrator/projects/Mev-Alpha}"
|
|
|
|
# Create logs directory
|
|
mkdir -p logs deployments
|
|
|
|
echo -e "${BLUE}================================${NC}"
|
|
echo -e "${BLUE}MEV Bot Contract Deployment${NC}"
|
|
echo -e "${BLUE}================================${NC}"
|
|
echo ""
|
|
|
|
# Function to print colored messages
|
|
log_info() {
|
|
echo -e "${BLUE}[INFO]${NC} $1"
|
|
echo "[INFO] $1" >> "$DEPLOYMENT_LOG"
|
|
}
|
|
|
|
log_success() {
|
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
echo "[SUCCESS] $1" >> "$DEPLOYMENT_LOG"
|
|
}
|
|
|
|
log_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
echo "[WARNING] $1" >> "$DEPLOYMENT_LOG"
|
|
}
|
|
|
|
log_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
echo "[ERROR] $1" >> "$DEPLOYMENT_LOG"
|
|
}
|
|
|
|
# Validate environment variables
|
|
validate_env() {
|
|
log_info "Validating environment variables..."
|
|
|
|
local missing_vars=()
|
|
|
|
if [ -z "$PRIVATE_KEY" ] && [ -z "$DEPLOYER_PRIVATE_KEY" ]; then
|
|
missing_vars+=("PRIVATE_KEY or DEPLOYER_PRIVATE_KEY")
|
|
fi
|
|
|
|
if [ -z "$ARBITRUM_RPC_ENDPOINT" ]; then
|
|
missing_vars+=("ARBITRUM_RPC_ENDPOINT")
|
|
fi
|
|
|
|
if [ ${#missing_vars[@]} -ne 0 ]; then
|
|
log_error "Missing required environment variables:"
|
|
for var in "${missing_vars[@]}"; do
|
|
log_error " - $var"
|
|
done
|
|
echo ""
|
|
log_info "Please set these variables:"
|
|
echo " export PRIVATE_KEY=<your_deployer_private_key>"
|
|
echo " export ARBITRUM_RPC_ENDPOINT=<your_rpc_endpoint>"
|
|
echo ""
|
|
log_info "Optional variables:"
|
|
echo " export ARBISCAN_API_KEY=<your_arbiscan_key> # For contract verification"
|
|
echo " export VERIFY=true # Enable contract verification"
|
|
exit 1
|
|
fi
|
|
|
|
log_success "Environment variables validated"
|
|
}
|
|
|
|
# Set deployer key
|
|
set_deployer_key() {
|
|
if [ -n "$DEPLOYER_PRIVATE_KEY" ]; then
|
|
export PRIVATE_KEY="$DEPLOYER_PRIVATE_KEY"
|
|
fi
|
|
}
|
|
|
|
# Check Foundry installation
|
|
check_foundry() {
|
|
log_info "Checking Foundry installation..."
|
|
|
|
if ! command -v forge &> /dev/null; then
|
|
log_error "Foundry (forge) is not installed"
|
|
log_info "Install Foundry: curl -L https://foundry.paradigm.xyz | bash"
|
|
log_info "Then run: foundryup"
|
|
exit 1
|
|
fi
|
|
|
|
log_success "Foundry is installed: $(forge --version | head -1)"
|
|
}
|
|
|
|
# Install dependencies
|
|
install_dependencies() {
|
|
log_info "Installing contract dependencies..."
|
|
|
|
if [ ! -d "lib/openzeppelin-contracts" ]; then
|
|
log_info "Installing OpenZeppelin contracts..."
|
|
forge install OpenZeppelin/openzeppelin-contracts --no-commit
|
|
else
|
|
log_info "OpenZeppelin contracts already installed"
|
|
fi
|
|
|
|
log_success "Dependencies installed"
|
|
}
|
|
|
|
# Compile contracts
|
|
compile_contracts() {
|
|
log_info "Compiling contracts from $CONTRACTS_DIR..."
|
|
|
|
# Change to contracts directory
|
|
cd "$CONTRACTS_DIR" || {
|
|
log_error "Failed to change to contracts directory: $CONTRACTS_DIR"
|
|
exit 1
|
|
}
|
|
|
|
log_info "Working directory: $(pwd)"
|
|
|
|
# Compile contracts
|
|
forge build 2>&1 | tee -a "$DEPLOYMENT_LOG"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
log_success "Contracts compiled successfully"
|
|
else
|
|
log_error "Contract compilation failed"
|
|
exit 1
|
|
fi
|
|
|
|
# Return to original directory
|
|
cd - > /dev/null
|
|
}
|
|
|
|
# Deploy ArbitrageExecutor contract
|
|
deploy_arbitrage_executor() {
|
|
log_info "Deploying ArbitrageExecutor contract..."
|
|
|
|
cd "$CONTRACTS_DIR" || exit 1
|
|
|
|
local contract_path="src/core/ArbitrageExecutor.sol:ArbitrageExecutor"
|
|
|
|
# Build forge command
|
|
local deploy_cmd="forge create \"$contract_path\" \
|
|
--rpc-url \"$ARBITRUM_RPC_ENDPOINT\" \
|
|
--private-key \"$PRIVATE_KEY\""
|
|
|
|
# Add verification if requested
|
|
if [ "$VERIFY" = "true" ] && [ -n "$ARBISCAN_API_KEY" ]; then
|
|
deploy_cmd="$deploy_cmd --verify --etherscan-api-key \"$ARBISCAN_API_KEY\""
|
|
fi
|
|
|
|
# Execute deployment
|
|
log_info "Executing deployment command..."
|
|
output=$(eval "$deploy_cmd" 2>&1)
|
|
echo "$output" >> "$(pwd)/../../mev-beta/$DEPLOYMENT_LOG"
|
|
|
|
# Extract deployed address
|
|
arbitrage_executor_address=$(echo "$output" | grep "Deployed to:" | awk '{print $3}')
|
|
|
|
cd - > /dev/null
|
|
|
|
if [ -z "$arbitrage_executor_address" ]; then
|
|
log_error "Failed to deploy ArbitrageExecutor"
|
|
echo "$output"
|
|
exit 1
|
|
fi
|
|
|
|
log_success "ArbitrageExecutor deployed to: $arbitrage_executor_address"
|
|
|
|
# Save to deployment file
|
|
cat > "deployments/arbitrage_executor_${NETWORK}.json" <<EOF
|
|
{
|
|
"network": "$NETWORK",
|
|
"contract": "ArbitrageExecutor",
|
|
"address": "$arbitrage_executor_address",
|
|
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
|
|
"deployer": "$(cast wallet address --private-key $PRIVATE_KEY 2>/dev/null || echo 'N/A')",
|
|
"verified": $VERIFY
|
|
}
|
|
EOF
|
|
|
|
echo "$arbitrage_executor_address"
|
|
}
|
|
|
|
# Deploy BaseFlashSwapper contract
|
|
deploy_base_flash_swapper() {
|
|
log_info "Deploying BaseFlashSwapper contract..."
|
|
|
|
cd "$CONTRACTS_DIR" || exit 1
|
|
|
|
local contract_path="src/core/BaseFlashSwapper.sol:BaseFlashSwapper"
|
|
|
|
# Build forge command
|
|
local deploy_cmd="forge create \"$contract_path\" \
|
|
--rpc-url \"$ARBITRUM_RPC_ENDPOINT\" \
|
|
--private-key \"$PRIVATE_KEY\""
|
|
|
|
# Add verification if requested
|
|
if [ "$VERIFY" = "true" ] && [ -n "$ARBISCAN_API_KEY" ]; then
|
|
deploy_cmd="$deploy_cmd --verify --etherscan-api-key \"$ARBISCAN_API_KEY\""
|
|
fi
|
|
|
|
# Execute deployment
|
|
log_info "Executing deployment command..."
|
|
output=$(eval "$deploy_cmd" 2>&1)
|
|
echo "$output" >> "$(pwd)/../../mev-beta/$DEPLOYMENT_LOG"
|
|
|
|
# Extract deployed address
|
|
flash_swapper_address=$(echo "$output" | grep "Deployed to:" | awk '{print $3}')
|
|
|
|
cd - > /dev/null
|
|
|
|
if [ -z "$flash_swapper_address" ]; then
|
|
log_error "Failed to deploy BaseFlashSwapper"
|
|
echo "$output"
|
|
exit 1
|
|
fi
|
|
|
|
log_success "BaseFlashSwapper deployed to: $flash_swapper_address"
|
|
|
|
# Save to deployment file
|
|
cat > "deployments/base_flash_swapper_${NETWORK}.json" <<EOF
|
|
{
|
|
"network": "$NETWORK",
|
|
"contract": "BaseFlashSwapper",
|
|
"address": "$flash_swapper_address",
|
|
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
|
|
"deployer": "$(cast wallet address --private-key $PRIVATE_KEY 2>/dev/null || echo 'N/A')",
|
|
"verified": $VERIFY
|
|
}
|
|
EOF
|
|
|
|
echo "$flash_swapper_address"
|
|
}
|
|
|
|
# Update configuration files
|
|
update_config() {
|
|
local arbitrage_executor=$1
|
|
local flash_swapper=$2
|
|
|
|
log_info "Updating configuration files..."
|
|
|
|
# Update .env.production
|
|
if [ -f ".env.production" ]; then
|
|
# Backup existing file
|
|
cp .env.production .env.production.bak
|
|
|
|
# Update contract addresses
|
|
sed -i "s|CONTRACT_ARBITRAGE_EXECUTOR=.*|CONTRACT_ARBITRAGE_EXECUTOR=\"$arbitrage_executor\"|" .env.production
|
|
sed -i "s|CONTRACT_FLASH_SWAPPER=.*|CONTRACT_FLASH_SWAPPER=\"$flash_swapper\"|" .env.production
|
|
|
|
log_success "Updated .env.production"
|
|
else
|
|
log_warning ".env.production not found, skipping update"
|
|
fi
|
|
|
|
# Update config/arbitrum_production.yaml
|
|
if [ -f "config/arbitrum_production.yaml" ]; then
|
|
# Backup existing file
|
|
cp config/arbitrum_production.yaml config/arbitrum_production.yaml.bak
|
|
|
|
# Update contract addresses in YAML
|
|
sed -i "s|arbitrage_contract_address:.*|arbitrage_contract_address: \"$arbitrage_executor\"|" config/arbitrum_production.yaml
|
|
sed -i "s|flash_swap_contract_address:.*|flash_swap_contract_address: \"$flash_swapper\"|" config/arbitrum_production.yaml
|
|
|
|
log_success "Updated config/arbitrum_production.yaml"
|
|
else
|
|
log_warning "config/arbitrum_production.yaml not found, skipping update"
|
|
fi
|
|
|
|
# Create master deployment file
|
|
cat > "deployments/deployment_${NETWORK}_$(date +%Y%m%d_%H%M%S).json" <<EOF
|
|
{
|
|
"network": "$NETWORK",
|
|
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
|
|
"contracts": {
|
|
"ArbitrageExecutor": {
|
|
"address": "$arbitrage_executor",
|
|
"verified": $VERIFY
|
|
},
|
|
"BaseFlashSwapper": {
|
|
"address": "$flash_swapper",
|
|
"verified": $VERIFY
|
|
}
|
|
},
|
|
"deployer": "$(cast wallet address --private-key $PRIVATE_KEY 2>/dev/null || echo 'N/A')",
|
|
"rpc_endpoint": "$ARBITRUM_RPC_ENDPOINT"
|
|
}
|
|
EOF
|
|
|
|
log_success "Created deployment record"
|
|
}
|
|
|
|
# Generate deployment summary
|
|
generate_summary() {
|
|
local arbitrage_executor=$1
|
|
local flash_swapper=$2
|
|
|
|
echo ""
|
|
echo -e "${GREEN}================================${NC}"
|
|
echo -e "${GREEN}Deployment Complete!${NC}"
|
|
echo -e "${GREEN}================================${NC}"
|
|
echo ""
|
|
echo -e "${BLUE}Network:${NC} $NETWORK"
|
|
echo -e "${BLUE}Timestamp:${NC} $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
echo -e "${BLUE}Contracts Source:${NC} $CONTRACTS_DIR"
|
|
echo ""
|
|
echo -e "${BLUE}Deployed Contracts:${NC}"
|
|
echo -e " ${GREEN}ArbitrageExecutor:${NC} $arbitrage_executor"
|
|
echo -e " ${GREEN}BaseFlashSwapper:${NC} $flash_swapper"
|
|
echo ""
|
|
|
|
if [ "$VERIFY" = "true" ]; then
|
|
echo -e "${GREEN}✓ Contracts verified on Arbiscan${NC}"
|
|
echo -e " View at: https://arbiscan.io/address/$arbitrage_executor"
|
|
echo -e " View at: https://arbiscan.io/address/$flash_swapper"
|
|
echo ""
|
|
fi
|
|
|
|
echo -e "${BLUE}Configuration Updated:${NC}"
|
|
echo -e " ${GREEN}✓${NC} .env.production"
|
|
echo -e " ${GREEN}✓${NC} config/arbitrum_production.yaml"
|
|
echo ""
|
|
echo -e "${BLUE}Next Steps:${NC}"
|
|
echo -e " 1. ${YELLOW}Verify contracts on Arbiscan (if not done)${NC}"
|
|
echo -e " 2. ${YELLOW}Test contracts with testnet funds${NC}"
|
|
echo -e " 3. ${YELLOW}Update MEV bot configuration${NC}"
|
|
echo -e " 4. ${YELLOW}Run: ./scripts/run.sh${NC}"
|
|
echo ""
|
|
echo -e "${BLUE}Deployment log:${NC} $DEPLOYMENT_LOG"
|
|
echo ""
|
|
}
|
|
|
|
# Main deployment flow
|
|
main() {
|
|
log_info "Starting deployment process..."
|
|
log_info "Target network: $NETWORK"
|
|
log_info "Verification: $VERIFY"
|
|
echo ""
|
|
|
|
# Validate and prepare
|
|
validate_env
|
|
set_deployer_key
|
|
check_foundry
|
|
install_dependencies
|
|
compile_contracts
|
|
|
|
echo ""
|
|
log_info "Ready to deploy contracts"
|
|
read -p "Continue with deployment? (y/N): " confirm
|
|
|
|
if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then
|
|
log_warning "Deployment cancelled by user"
|
|
exit 0
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# Deploy contracts
|
|
arbitrage_executor=$(deploy_arbitrage_executor)
|
|
echo ""
|
|
flash_swapper=$(deploy_base_flash_swapper)
|
|
echo ""
|
|
|
|
# Update configuration
|
|
update_config "$arbitrage_executor" "$flash_swapper"
|
|
|
|
# Generate summary
|
|
generate_summary "$arbitrage_executor" "$flash_swapper"
|
|
|
|
log_success "Deployment complete!"
|
|
}
|
|
|
|
# Run main function
|
|
main "$@"
|