#!/bin/bash # Production contract deployment script for Arbitrum set -e echo "🚀 Deploying PRODUCTION MEV arbitrage contracts to Arbitrum..." # Check environment if [ -z "$ARBITRUM_RPC_ENDPOINT" ]; then echo "❌ ARBITRUM_RPC_ENDPOINT not set" exit 1 fi if [ -z "$PRIVATE_KEY" ]; then echo "❌ PRIVATE_KEY not set for deployment" exit 1 fi # Install dependencies if not present if [ ! -d "node_modules" ]; then echo "📦 Installing dependencies..." npm install --save-dev @openzeppelin/contracts hardhat @nomiclabs/hardhat-ethers ethers fi # Create hardhat config for deployment cat > hardhat.config.js << EOF require("@nomiclabs/hardhat-ethers"); module.exports = { solidity: { version: "0.8.19", settings: { optimizer: { enabled: true, runs: 1000000 // Optimize for gas efficiency } } }, networks: { arbitrum: { url: "${ARBITRUM_RPC_ENDPOINT}", accounts: ["${PRIVATE_KEY}"] } } }; EOF # Create deployment script cat > scripts/deploy.js << 'EOF' const { ethers } = require("hardhat"); async function main() { console.log("🏗️ Deploying ProductionArbitrageExecutor..."); const [deployer] = await ethers.getSigners(); console.log("Deploying with account:", deployer.address); const balance = await deployer.getBalance(); console.log("Account balance:", ethers.utils.formatEther(balance), "ETH"); // Deploy ProductionArbitrageExecutor const ArbitrageExecutor = await ethers.getContractFactory("ProductionArbitrageExecutor"); // Estimate gas const deploymentGas = await ArbitrageExecutor.signer.estimateGas( ArbitrageExecutor.getDeployTransaction() ); console.log("Estimated deployment gas:", deploymentGas.toString()); const executor = await ArbitrageExecutor.deploy({ gasLimit: deploymentGas.mul(120).div(100) // 20% buffer }); await executor.deployed(); console.log("✅ ProductionArbitrageExecutor deployed to:", executor.address); // Verify contract is working const minProfit = await executor.minProfitThreshold(); const maxGas = await executor.maxGasPrice(); console.log("📊 Contract Configuration:"); console.log(" Min Profit Threshold:", ethers.utils.formatEther(minProfit), "ETH"); console.log(" Max Gas Price:", ethers.utils.formatUnits(maxGas, "gwei"), "gwei"); // Update config file const fs = require('fs'); const yaml = require('js-yaml'); try { const configPath = 'config/arbitrum_production.yaml'; const config = yaml.load(fs.readFileSync(configPath, 'utf8')); // Update contract addresses config.contracts.arbitrage_executor = executor.address; // Write updated config fs.writeFileSync(configPath, yaml.dump(config)); console.log("✅ Updated config file with contract address"); } catch (error) { console.log("⚠️ Could not update config file:", error.message); console.log("📝 Manual update required:"); console.log(` arbitrage_executor: "${executor.address}"`); } console.log("🎯 Deployment Summary:"); console.log(" Contract Address:", executor.address); console.log(" Network: Arbitrum One (Chain ID: 42161)"); console.log(" Gas Used:", deploymentGas.toString()); console.log(" Status: READY FOR PROFITABLE ARBITRAGE"); } main() .then(() => process.exit(0)) .catch((error) => { console.error("❌ Deployment failed:", error); process.exit(1); }); EOF # Create package.json if not exists if [ ! -f "package.json" ]; then cat > package.json << EOF { "name": "mev-bot-contracts", "version": "1.0.0", "description": "Production MEV arbitrage contracts", "scripts": { "deploy": "hardhat run scripts/deploy.js --network arbitrum" }, "devDependencies": { "@openzeppelin/contracts": "^4.9.0", "hardhat": "^2.17.0", "@nomiclabs/hardhat-ethers": "^2.2.0", "ethers": "^5.7.0", "js-yaml": "^4.1.0" } } EOF fi # Install dependencies echo "📦 Installing contract dependencies..." npm install # Compile contracts echo "🔨 Compiling contracts..." npx hardhat compile # Deploy contracts echo "🚀 Deploying to Arbitrum..." npx hardhat run scripts/deploy.js --network arbitrum echo "" echo "🎉 PRODUCTION CONTRACTS DEPLOYED SUCCESSFULLY!" echo "" echo "⚠️ IMPORTANT: Save these addresses securely!" echo " - Use them in your MEV bot configuration" echo " - Verify on Arbiscan before using with large amounts" echo " - Test thoroughly with small amounts first" echo "" echo "📈 Next steps:" echo "1. Update MEV bot config with new contract address" echo "2. Test arbitrage execution with forked environment" echo "3. Start with small amounts on mainnet" echo "4. Monitor profitability and adjust parameters"