fix: use pool cache to avoid zero addresses in Uniswap V3 parsing
- Added poolCache field to EventParser struct with PoolCache interface - Modified getPoolTokens() to check cache before returning zero addresses - Created PoolCache interface in pkg/interfaces for clean separation - Added debug logging to identify pools missing from cache - Documented long-term architecture improvements in PARSER_ARCHITECTURE_IMPROVEMENTS.md This fixes the critical issue where Uniswap V3 swap events would show zero addresses for tokens when transaction calldata was unavailable. The parser now falls back to the pool cache which contains previously discovered pool information. Benefits: - Eliminates zero address errors for known pools - Reduces unnecessary RPC calls - Provides visibility into which pools are missing from cache - Lays foundation for per-exchange parser architecture 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -123,7 +123,11 @@ type EventParser struct {
|
||||
|
||||
// CRITICAL FIX: Token extractor interface for working token extraction
|
||||
tokenExtractor interfaces.TokenExtractor
|
||||
logger *logger.Logger
|
||||
|
||||
// CRITICAL FIX: Pool cache to avoid zero addresses for known pools
|
||||
poolCache interfaces.PoolCache
|
||||
|
||||
logger *logger.Logger
|
||||
}
|
||||
|
||||
func (ep *EventParser) logDebug(message string, kv ...interface{}) {
|
||||
@@ -167,6 +171,11 @@ func NewEventParserWithLogger(log *logger.Logger) *EventParser {
|
||||
// NewEventParserWithTokenExtractor instantiates an EventParser with a TokenExtractor for enhanced parsing.
|
||||
// This is the primary constructor for using the working L2 parser logic.
|
||||
func NewEventParserWithTokenExtractor(log *logger.Logger, tokenExtractor interfaces.TokenExtractor) *EventParser {
|
||||
return NewEventParserFull(log, tokenExtractor, nil)
|
||||
}
|
||||
|
||||
// NewEventParserFull instantiates an EventParser with full customization options
|
||||
func NewEventParserFull(log *logger.Logger, tokenExtractor interfaces.TokenExtractor, poolCache interfaces.PoolCache) *EventParser {
|
||||
if log == nil {
|
||||
log = logger.New("info", "text", "")
|
||||
}
|
||||
@@ -174,6 +183,7 @@ func NewEventParserWithTokenExtractor(log *logger.Logger, tokenExtractor interfa
|
||||
parser := &EventParser{
|
||||
logger: log,
|
||||
tokenExtractor: tokenExtractor,
|
||||
poolCache: poolCache,
|
||||
// Official Arbitrum DEX Factory Addresses
|
||||
UniswapV2Factory: common.HexToAddress("0xf1D7CC64Fb4452F05c498126312eBE29f30Fbcf9"), // Official Uniswap V2 Factory on Arbitrum
|
||||
UniswapV3Factory: common.HexToAddress("0x1F98431c8aD98523631AE4a59f267346ea31F984"), // Official Uniswap V3 Factory on Arbitrum
|
||||
@@ -1820,9 +1830,25 @@ func (ep *EventParser) getPoolTokens(poolAddress common.Address, txHash common.H
|
||||
}
|
||||
}
|
||||
|
||||
// Return zero addresses - scanner will enrich with pool cache data if needed
|
||||
// This is acceptable because the comment at concurrent.go:381 says
|
||||
// "Scanner will enrich event with token addresses from cache if missing"
|
||||
// CRITICAL FIX: Use pool cache to get tokens from known pools
|
||||
// This avoids RPC calls and zero addresses for pools we've already discovered
|
||||
if ep.poolCache != nil {
|
||||
poolInfo := ep.poolCache.GetPool(poolAddress)
|
||||
if poolInfo != nil && poolInfo.Token0 != (common.Address{}) && poolInfo.Token1 != (common.Address{}) {
|
||||
ep.logDebug("enriched pool tokens from cache",
|
||||
"pool", poolAddress.Hex()[:10],
|
||||
"token0", poolInfo.Token0.Hex()[:10],
|
||||
"token1", poolInfo.Token1.Hex()[:10])
|
||||
return poolInfo.Token0, poolInfo.Token1
|
||||
}
|
||||
}
|
||||
|
||||
// If pool not in cache, log a warning - this helps identify parsing errors
|
||||
ep.logDebug("pool not found in cache, returning zero addresses",
|
||||
"pool", poolAddress.Hex()[:10],
|
||||
"txHash", txHash.Hex()[:10])
|
||||
|
||||
// Return zero addresses - this will now be logged so we can track which pools are missing
|
||||
return common.Address{}, common.Address{}
|
||||
}
|
||||
|
||||
|
||||
15
pkg/interfaces/pool_cache.go
Normal file
15
pkg/interfaces/pool_cache.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package interfaces
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
arbcommon "github.com/fraktal/mev-beta/pkg/arbitrum/common"
|
||||
)
|
||||
|
||||
// PoolCache provides access to cached pool information
|
||||
type PoolCache interface {
|
||||
// GetPool retrieves pool information from cache
|
||||
GetPool(address common.Address) *arbcommon.PoolInfo
|
||||
|
||||
// GetPoolsByTokenPair retrieves pools for a specific token pair
|
||||
GetPoolsByTokenPair(token0, token1 common.Address) []*arbcommon.PoolInfo
|
||||
}
|
||||
Reference in New Issue
Block a user