5.1 KiB
Comprehensive Profit Calculation Audit Report
Date: November 3, 2025 Status: CRITICAL - No arbitrage opportunities detected
Executive Summary
The MEV bot is running with proper pool detection (bindings integration successful) but detecting ZERO arbitrage opportunities. This indicates fundamental issues with profit calculations.
Current Issues Identified
1. Pool Detection Status ✅
- Working: Contract bindings successfully integrated
- Working: Pool type detection (UniswapV2/V3, Algebra variants)
- Working: Blacklisting of invalid pools
- Issue: Some pools still causing "execution reverted" errors
2. Arbitrage Detection Status ❌
- Critical: 0 opportunities detected in hours of operation
- Stats: Detected: 0, Executed: 0, Successful: 0
- Root Cause: Likely profit calculation or threshold issues
Root Cause Analysis
1. Decimal Precision Issues
Problem: Token decimals not properly handled
- WETH has 18 decimals
- USDC/USDT have 6 decimals
- WBTC has 8 decimals
Current Code Issue:
// Incorrect: Treating all amounts as 18 decimals
amountInFloat, _ = new(big.Float).Quo(new(big.Float).SetInt(swapInfo.AmountIn), big.NewFloat(1e18)).Float64()
Fix Required:
// Correct: Use actual token decimals
decimals := tokenDecimals[tokenAddress]
divisor := new(big.Float).SetFloat64(math.Pow(10, float64(decimals)))
amountInFloat, _ = new(big.Float).Quo(new(big.Float).SetInt(swapInfo.AmountIn), divisor).Float64()
2. Fee Calculation Errors
Problem: UniswapV3 fees incorrectly interpreted
- V3 fees are in units of 0.01% (1 = 0.01%, 100 = 1%)
- V2 fees are fixed at 0.3% (30 basis points)
Current Issue:
// Fee from binding is *big.Int but represents basis points
fee := pool.Fee() // Returns 3000 for 0.3% fee
// Need to convert to actual percentage
Fix Required:
feePercent := float64(fee.Int64()) / 1000000.0 // Convert basis points to decimal
3. Profit Threshold Too Conservative
Current Setting: 0.1% minimum profit (from config) Market Reality: Most arbitrage profits are 0.01% - 0.05%
Fix Required:
- Lower threshold to 0.01% (1 basis point)
- Account for gas costs properly
- Consider flash loan fees (0.09% on Aave)
4. Price Calculation Logic
Problem: Not accounting for price impact and slippage
// Current: Simple calculation
profit = amountOut - amountIn
// Should be:
profit = (amountOut * (1 - slippage)) - amountIn - gasCost - flashLoanFee
Immediate Action Plan
Phase 1: Fix Critical Calculations (NOW)
-
Token Decimal Handling
- Create decimal registry for all tokens
- Use correct divisors for each token
-
Fee Conversion Fix
- Convert UniswapV3 fees from basis points
- Handle V2 fixed fees correctly
- Account for protocol fees
-
Lower Profit Threshold
- Reduce from 0.1% to 0.01%
- Make configurable per token pair
Phase 2: Enhanced Calculations
-
Gas Cost Integration
- Fetch current gas price
- Calculate execution cost
- Include in profit calculation
-
Slippage Protection
- Add configurable slippage (0.5% default)
- Calculate minimum output amounts
-
Flash Loan Costs
- Include 0.09% Aave fee
- Calculate break-even points
Phase 3: Testing & Validation
-
Unit Tests for Calculations
- Test with different decimals
- Verify fee calculations
- Validate profit thresholds
-
Integration Testing
- Fork mainnet for testing
- Replay historical transactions
- Verify profit calculations match reality
Code Locations to Fix
-
pkg/profitcalc/profit_calc.go
CalculateProfit()function- Decimal handling logic
- Fee calculations
-
pkg/arbitrage/detection_engine.go
- Profit threshold checks
- Opportunity filtering logic
-
pkg/pricing/engine.go
- Price impact calculations
- Slippage adjustments
-
internal/config/config.go
- Lower MinProfitThreshold
- Add per-pair thresholds
Validation Metrics
After fixes, we should see:
- Opportunities/hour: 10-50 (market dependent)
- Success rate: 20-40% (competition dependent)
- Average profit: 0.02-0.05% per trade
- Daily profit: $50-500 (volume dependent)
Critical Success Factors
- ✅ Detect at least 1 opportunity per minute
- ✅ Calculate profits with 6+ decimal precision
- ✅ Account for all fees and costs
- ✅ Execute profitable trades only
- ✅ Monitor and log all calculations
Next Steps
- Implement decimal fixes immediately
- Deploy with lower thresholds
- Monitor for 1 hour
- Adjust based on results
- Scale up execution
Risk Assessment
- High Risk: Executing with wrong calculations = losses
- Medium Risk: Missing opportunities = no profit
- Low Risk: Over-conservative thresholds = fewer trades
Conclusion
The bot's core infrastructure is working (pool detection, monitoring, bindings) but profit calculations are preventing opportunity detection. Immediate fixes to decimal handling and thresholds should restore functionality.
Estimated Time to Fix: 2-4 hours Expected Result: 10+ opportunities/hour detected Profit Potential: $50-500/day once operational