# Flash Loan Arbitrage Contract Deployment ## Quick Deploy (Hardhat/Foundry) ### Using Foundry (Recommended) ```bash # Install Foundry if not installed curl -L https://foundry.paradigm.xyz | bash foundryup # Install dependencies forge install aave/aave-v3-core forge install OpenZeppelin/openzeppelin-contracts # Deploy to Arbitrum forge create --rpc-url https://arb1.arbitrum.io/rpc \ --private-key $PRIVATE_KEY \ --constructor-args 0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb \ contracts/ArbitrageExecutor.sol:ArbitrageExecutor # Verify on Arbiscan forge verify-contract \ --chain-id 42161 \ --constructor-args $(cast abi-encode "constructor(address)" 0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb) \ \ contracts/ArbitrageExecutor.sol:ArbitrageExecutor \ --etherscan-api-key $ARBISCAN_API_KEY ``` ### Using Hardhat ```bash # Install dependencies npm install --save-dev hardhat @nomiclabs/hardhat-ethers ethers npm install @aave/core-v3 @openzeppelin/contracts # Create hardhat.config.js cat > hardhat.config.js << 'EOF' require("@nomiclabs/hardhat-ethers"); module.exports = { solidity: "0.8.10", networks: { arbitrum: { url: "https://arb1.arbitrum.io/rpc", accounts: [process.env.PRIVATE_KEY] } } }; EOF # Create deploy script cat > scripts/deploy.js << 'EOF' async function main() { const ArbitrageExecutor = await ethers.getContractFactory("ArbitrageExecutor"); const executor = await ArbitrageExecutor.deploy( "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb" // Aave V3 Pool Addresses Provider ); await executor.deployed(); console.log("ArbitrageExecutor deployed to:", executor.address); } main(); EOF # Deploy npx hardhat run scripts/deploy.js --network arbitrum ``` ## Contract Addresses on Arbitrum ### Aave V3 - **Pool Addresses Provider**: `0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb` - **Pool**: `0x794a61358D6845594F94dc1DB02A252b5b4814aD` ### DEX Routers - **Uniswap V2 Router**: `0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24` - **Sushiswap Router**: `0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506` - **Camelot Router**: `0xc873fEcbd354f5A56E00E710B90EF4201db2448d` ### Tokens - **WETH**: `0x82aF49447D8a07e3bd95BD0d56f35241523fBab1` - **USDC**: `0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8` - **USDT**: `0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9` - **ARB**: `0x912CE59144191C1204E64559FE8253a0e49E6548` ## Gas Estimates | Operation | Gas Used | Cost @ 0.1 gwei | |-----------|----------|-----------------| | Flash loan request | 50,000 | $0.005 | | First swap | 150,000 | $0.015 | | Second swap | 150,000 | $0.015 | | Repay + profit transfer | 100,000 | $0.010 | | **Total** | **450,000** | **$0.045** | *Note: Arbitrum gas is MUCH cheaper than Ethereum mainnet* ## Testing Before Deployment ```bash # Test on Arbitrum Goerli testnet first forge test --fork-url https://goerli-rollup.arbitrum.io/rpc # Or run local Arbitrum fork anvil --fork-url https://arb1.arbitrum.io/rpc # In another terminal, run tests forge test ``` ## After Deployment 1. **Fund the contract owner address** with a small amount of ETH for gas (~0.01 ETH is plenty) 2. **Update the Go code** with deployed contract address: ```go var ArbitrageExecutorAddress = common.HexToAddress("0xYOUR_DEPLOYED_ADDRESS") ``` 3. **Test with a small arbitrage** first before scaling up ## Security Checklist - [ ] Contract verified on Arbiscan - [ ] Owner address is secure (hardware wallet recommended) - [ ] Emergency withdraw function tested - [ ] Minimum profit threshold set appropriately - [ ] Gas price limits configured - [ ] Monitoring/alerting setup for failures ## Integration with Go Bot Once deployed, update `pkg/execution/flashloan_executor.go`: ```go // Add contract address var ArbitrageExecutorAddress = common.HexToAddress("0xYOUR_ADDRESS") // Add ABI binding // Run: abigen --sol contracts/ArbitrageExecutor.sol --pkg execution --out pkg/execution/arbitrage_executor.go // Update Execute() method to call the contract func (e *FlashLoanExecutor) Execute(ctx context.Context, opp *arbitrage.Opportunity) (*types.Transaction, error) { // Create contract instance contract, err := NewArbitrageExecutor(ArbitrageExecutorAddress, e.client) if err != nil { return nil, err } // Call executeArbitrage tx, err := contract.ExecuteArbitrage( e.executor, opp.InputToken, opp.InputAmount, opp.FirstPool.RouterAddress, // Need to add router addresses to PoolInfo opp.SecondPool.RouterAddress, path1, path2, minProfit, ) return tx, err } ``` ## Profit Sharing (Optional) For production, consider adding a profit-sharing mechanism: - Keep 80% of profits for yourself - Share 20% with flash loan provider (if using private liquidity) - Or donate small % to protocol development ## Monitoring Monitor contract activity: - https://arbiscan.io/address/YOUR_CONTRACT_ADDRESS - Watch for `ArbitrageExecuted` events - Set up alerts for `ArbitrageFailed` events - Track cumulative profits ## Next Steps 1. Deploy contract to Arbitrum mainnet 2. Verify on Arbiscan 3. Generate ABI bindings for Go 4. Connect to MEV bot 5. Start with conservative profit thresholds 6. Monitor and optimize!