# Arbitrage Executor Hardening Plan ## Overview Replace simulated flash-swap execution paths with on-chain integrations, accurate gas handling, and post-trade reconciliation. The current implementation relies on mock receipts, placeholder calldata, and synthetic pool data. ## Tasks 1. **Contract Integration** - [ ] Add Go bindings for the flash swap/aggregator contract (generate via `abigen` if absent). - [ ] Define canonical calldata struct matching the on-chain function signature (token path, pool info, slippage limits, recipient). 2. **Transaction Submission** - [x] Replace `submitTransaction` with actual contract call using flash swap aggregator binding. - [ ] Implement nonce management and ensure transactions are signed with the configured key manager. 3. **Gas Estimation & Pricing** - [x] Swap placeholder gas limit with `client.EstimateGas` (include calldata and value). - [x] Fetch base fee + priority tip dynamically; tie into Arbitrum fee/tip suggestions. - [ ] Enforce config-driven max fee/tip thresholds (fallback to abort rather than cap to static value). 4. **Confirmation & Reverts** - [ ] Replace simulated receipt in `waitForConfirmation` with polling `TransactionReceipt`, respecting context timeout. - [ ] Decode revert reasons/logs for diagnostics; handle dropped/replace-by-fee scenarios. 5. **Profit/Loss Calculation** - [ ] Update `calculateActualProfit` to parse emitted events/logs for actual amounts in/out. - [ ] Subtract real gas cost from on-chain data; convert to `UniversalDecimal` with correct symbols. - [ ] Emit structured logs/metrics for realized profit, slippage, and gas usage. 6. **Fallback & Simulation** - [ ] Move current simulation helpers into a `*_test.go` or dev-only path; guard with build tags if necessary. 7. **Tests** - [ ] Unit tests using mocked contract interface for success, revert, and timeout. - [ ] Integration test with geth simulated backend or fork network verifying end-to-end flash swap. 8. **Documentation** - [ ] Update `docs/5_development/` and `docs/6_operations/` with new requirements (contract addresses, env vars). - [ ] Note the removal of simulated paths; include troubleshooting steps for on-chain failures. References: - `pkg/arbitrage/executor.go` (simulateFlashSwapArbitrage, executeArbitrage) - `pkg/arbitrage/flash_executor.go` (submitTransaction, waitForConfirmation, calculateActualProfit)