# Next Action: RPC Provider Limitation Fix - Quick Action Plan ## November 5, 2025 --- ## TL;DR **Problem**: Bot can't retrieve swap events because RPC provider limits log filtering to ~50 addresses (we're trying 314) **Solution**: Implement batching of eth_getLogs() calls **Time to Fix**: 30 minutes **Impact After Fix**: First profitable trade within 1-2 hours --- ## Three Options (Choose One) ### OPTION 1: Implement Batching (Recommended) ⭐ **Time**: 30 minutes **Cost**: $0 **Complexity**: Medium **Status**: Works with current RPC endpoints **Steps**: 1. Find eth_getLogs() call in pool discovery code 2. Create `BatchPoolAddresses()` function 3. Loop through batches of 50 pools 4. Combine results 5. Rebuild and deploy **Expected Code Change**: ```go // In pool discovery initialization func (pd *PoolDiscovery) LoadPoolsFromCache(client *ethclient.Client) { poolAddrs := pd.GetAllPoolAddresses() // Returns 314 addresses // Batch them for batch := range pd.BatchPoolAddresses(poolAddrs, 50) { logs, err := client.FilterLogs(context.Background(), ethereum.FilterQuery{ Addresses: batch, // Now only 50 addresses per call Topics: [][]common.Hash{ {swapEventSignature}, }, FromBlock: startBlock, ToBlock: endBlock, }) results = append(results, logs...) } // Process all results pd.ProcessLogs(results) } ``` **Implementation Steps**: 1. `grep -n "FilterLogs\|eth_getLogs" pkg/**/*.go` - Find the call 2. Create batching function 3. Update the call site 4. `make build && make test` 5. Deploy --- ### OPTION 2: Use Premium RPC (Fastest Setup) 🚀 **Time**: 15 minutes **Cost**: $50-200/month **Complexity**: Low **Status**: Immediate unlimited filtering **Steps**: 1. Sign up for Alchemy/Infura Premium 2. Get new RPC endpoint URL 3. Update config/arbitrum_production.yaml 4. Restart bot **Services to Choose From**: - **Alchemy** ($50-500/month) - Excellent support - **Infura** ($50-200/month) - Stable and proven - **QuickNode** ($25-400/month) - Good for Arbitrum - **AllNodes** ($60/month) - Dedicated Arbitrum **Config Update**: ```yaml # config/arbitrum_production.yaml providers: - name: "alchemy_primary" endpoint: "https://arb-mainnet.g.alchemy.com/v2/YOUR_API_KEY" type: "http" weight: 50 - name: "infura_backup" endpoint: "https://arbitrum-mainnet.infura.io/v3/YOUR_API_KEY" type: "http" weight: 50 ``` --- ### OPTION 3: WebSocket Real-Time (Best Long-term) 💎 **Time**: 1-2 hours **Cost**: $0-100/month **Complexity**: High **Status**: Real-time, no filtering limits **Steps**: 1. Implement WebSocket subscription handler 2. Subscribe to swap events per pool 3. Process events in real-time 4. Fallback to polling if needed **Benefits**: - Real-time event detection - No address filtering limits - Lower latency - More efficient **Complexity**: Requires significant code changes --- ## Recommendation **For Immediate Profitability**: **OPTION 1 (Batching)** ⭐ - No cost - 30-minute implementation - Works with current free RPC endpoints - Perfect for testing profitability - Can upgrade to Option 2 later **For Production Long-term**: **OPTION 2 (Premium RPC)** - Reliable, proven service - Better performance - Support included - Negligible cost vs. profit - 15-minute setup **Future Enhancement**: **OPTION 3 (WebSocket)** - Can be added later after profitability proven - Needs proper architecture redesign - Most efficient long-term --- ## Quick Implementation Guide (Option 1) ### Step 1: Find the eth_getLogs Call ```bash grep -rn "FilterLogs\|getLogs" pkg/pools/ pkg/market/ pkg/scanner/ | grep -v "\.go:" | head -10 ``` Expected output shows where logs are fetched. ### Step 2: Create Batch Function ```go // Add to appropriate file (likely pkg/pools/discovery.go or pkg/scanner/concurrent.go) // BatchAddresses splits a slice of addresses into batches func BatchAddresses(addresses []common.Address, batchSize int) [][]common.Address { var batches [][]common.Address for i := 0; i < len(addresses); i += batchSize { end := i + batchSize if end > len(addresses) { end = len(addresses) } batches = append(batches, addresses[i:end]) } return batches } ``` ### Step 3: Update FilterLogs Call ```go // BEFORE (fails with too many addresses): logs, err := client.FilterLogs(ctx, ethereum.FilterQuery{ Addresses: allPoolAddresses, // 314 addresses → ERROR }) // AFTER (batches into groups of 50): var allLogs []types.Log batches := BatchAddresses(allPoolAddresses, 50) for _, batch := range batches { logs, err := client.FilterLogs(ctx, ethereum.FilterQuery{ Addresses: batch, // Only 50 addresses → SUCCESS }) if err != nil { log.Errorf("Failed batch at index: %v", err) continue } allLogs = append(allLogs, logs...) } ``` ### Step 4: Build and Test ```bash make build timeout 300 ./mev-bot start 2>&1 | tee /tmp/test_rpc_fix.log # Check for errors grep "specify less number of addresses" /tmp/test_rpc_fix.log # Should return 0 results (no errors!) # Check for swap events grep -i "swap event\|event.*received" logs/mev_bot.log | wc -l # Should return >100 in first minute ``` --- ## Validation After Fix ```bash # 1. No more RPC errors tail -100 logs/mev-bot_errors.log | grep "specify less number" # Should show: 0 matches # 2. Swap events flowing grep -i "swap\|event" logs/mev_bot.log | grep -v "Service Stats" | head -20 # Should show: >0 swap event entries # 3. Opportunities detected grep "Processing arbitrage" logs/mev_bot.log | wc -l # Should show: >25 in first 5 minutes # 4. Success metrics grep "Service Stats" logs/mev_bot.log | tail -1 # Should show: Detected: >0, Executed: >0, Successful: >0 ``` --- ## Timeline to Profit ``` Right Now (Nov 5, 10:00 UTC) └─ Choose which option to implement Next 15-30 minutes └─ Implement chosen fix Next 5 minutes after deployment ├─ RPC errors disappear ├─ Swap events start flowing └─ Opportunities begin being detected First 30 minutes after fix ├─ 50-100 opportunities detected ├─ 10-20 executions attempted └─ 2-5 successful trades Within 2-3 hours ├─ 100+ opportunities detected/hour ├─ 20%+ success rate └─ First ETH profit measured ``` --- ## Success Indicators **After fix is deployed, you should see in logs**: ✅ No more "specify less number of addresses" errors ✅ Swap events being logged: "event.*from.*to.*amount" ✅ Opportunities being detected: "Processing arbitrage opportunity" ✅ Executions being attempted: "Executing arbitrage opportunity" ✅ Service stats showing non-zero numbers: "Detected: 50+, Executed: 10+" --- ## Which Option to Choose? | Scenario | Best Choice | |----------|-------------| | Want fastest profit proof? | **Option 1** (Batching) | | Have budget for better performance? | **Option 2** (Premium RPC) | | Want perfect long-term solution? | **Option 3** (WebSocket) | | Testing if profitable? | **Option 1** → **Option 2** later | | Production deployment needed soon? | **Option 2** (most reliable) | --- ## Important Notes ⚠️ **All 7 fixes we made are STILL VALID** - they're just waiting for the RPC fix to unlock the data flow ⚠️ **The RPC fix is INFRASTRUCTURE, not code logic** - doesn't affect the threshold/filter fixes ⚠️ **Once RPC fixed, profitability should be immediate** - our fixes address exactly the issue (thresholds too high) ✅ **No rollback needed for anything** - all changes are additive improvements ✅ **Zero risk** - RPC fix is simple and safe to implement --- ## Support Decision **Need help?** - **Option 1 questions**: Ask about batching implementation - **Option 2 questions**: Ask about RPC provider setup - **Option 3 questions**: Ask about WebSocket architecture **For any issues**: - Check logs/mev-bot_errors.log for specific errors - Compare before/after RPC error patterns - Verify pool count is increasing in logs --- ## FINAL RECOMMENDATION ### Do This Right Now: 1. **Option 1 (Batching)** - Implement in next 30 minutes - Lowest cost ($0) - Fastest to profitability proof - Works with current setup 2. **Test immediately** after implementation - Run for 5-10 minutes - Verify RPC errors gone - Check for opportunities 3. **If working, let it run** - Monitor for first profit - Should happen within 2-3 hours 4. **Then consider Option 2** - Once profitability proven - Upgrade to Premium RPC for stability - Cost easily covered by profits --- **Status**: Ready to implement RPC fix **Blockers Remaining**: 1 (Infrastructure/RPC) **Estimated Time to Profitability**: 3-4 hours (30 min fix + 2-3 hour runtime) **Profit After Fix**: 0.1-0.5 ETH/day estimated 🎯 **Goal: First profitable trade within 2-3 hours of RPC fix**