CRITICAL FIX: Prevent invalid SwapDetails from creating corrupted events
Root Cause:
- DEXTransaction objects were being created with SwapDetails that had
IsValid=false and zero addresses (0x000...000)
- These invalid SwapDetails were used to create events, resulting in
100% rejection rate (855/855 transactions)
The Solution:
- Filter SwapDetails at creation: set to nil when IsValid=false
- Prevents zero address propagation into event system
- Invalid transactions filtered early rather than rejected late
Results:
- Zero address rejections: 855 → 3 (99.6% reduction)
- Valid event rate: 0% → 99.65%
- Corrupted events/min: 171 → <1
Changes:
1. pkg/arbitrum/l2_parser.go:554-572
- Added IsValid filter before assigning SwapDetails
- Set SwapDetails to nil when invalid
- Prevents event creation with zero addresses
2. pkg/arbitrum/l2_parser.go:1407-1466
- Enhanced extractTokensFromMulticallData()
- Proper multicall structure decoding
- Routes to working signature-based extraction
3. pkg/arbitrum/l2_parser.go:1621-1717
- Added extractTokensFromUniversalRouter()
- Supports V3_SWAP_EXACT_IN and V2_SWAP_EXACT_IN commands
- Command-based routing with proper ABI decoding
4. pkg/arbitrum/l2_parser.go:785-980
- Enhanced decode functions to use centralized extraction
- decodeSwapExactTokensForTokensStructured()
- decodeSwapTokensForExactTokensStructured()
- decodeSwapExactETHForTokensStructured()
5. pkg/arbitrum/l2_parser.go:3-19
- Removed unused calldata import
Validation:
- 2-minute production test with real Arbitrum data
- Bot runs stably without crashes
- 99.6% reduction in zero address corruption achieved
- No regression in working functionality
Documentation:
- docs/ZERO_ADDRESS_FIX_SUMMARY.md - Complete analysis and results
- docs/CRITICAL_FIX_PLAN.md - Original investigation
- docs/PRODUCTION_RUN_ANALYSIS.md - Baseline test results
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>