package pools import ( "github.com/ethereum/go-ethereum/common" arbcommon "github.com/fraktal/mev-beta/pkg/arbitrum/common" ) // PoolCacheAdapter adapts PoolDiscovery to implement interfaces.PoolCache // This allows the EventParser to use PoolDiscovery as its pool cache type PoolCacheAdapter struct { discovery *PoolDiscovery } // NewPoolCacheAdapter creates a new adapter wrapping a PoolDiscovery func NewPoolCacheAdapter(discovery *PoolDiscovery) *PoolCacheAdapter { return &PoolCacheAdapter{ discovery: discovery, } } // GetPool retrieves pool information from cache func (a *PoolCacheAdapter) GetPool(address common.Address) *arbcommon.PoolInfo { if a.discovery == nil { return nil } // Get pool from discovery pool, exists := a.discovery.GetPool(address.Hex()) if !exists || pool == nil { return nil } // Convert Pool to PoolInfo return &arbcommon.PoolInfo{ Address: common.HexToAddress(pool.Address), Protocol: parseProtocol(pool.Protocol), PoolType: parsePoolType(pool.Protocol), FactoryAddress: common.HexToAddress(pool.Factory), Token0: common.HexToAddress(pool.Token0), Token1: common.HexToAddress(pool.Token1), Fee: pool.Fee, TotalLiquidity: pool.Liquidity, } } // GetPoolsByTokenPair retrieves pools for a specific token pair func (a *PoolCacheAdapter) GetPoolsByTokenPair(token0, token1 common.Address) []*arbcommon.PoolInfo { if a.discovery == nil { return nil } // PoolDiscovery doesn't have a direct method for this yet // We'll return nil for now and implement this later if needed // This is acceptable as the parser only uses GetPool currently return nil } // parseProtocol converts protocol string to Protocol enum func parseProtocol(protocol string) arbcommon.Protocol { switch protocol { case "uniswap-v2": return arbcommon.ProtocolUniswapV2 case "uniswap-v3": return arbcommon.ProtocolUniswapV3 case "sushiswap", "sushiswap-v2": return arbcommon.ProtocolSushiSwapV2 case "sushiswap-v3": return arbcommon.ProtocolSushiSwapV3 case "camelot", "camelot-v2": return arbcommon.ProtocolCamelotV2 case "camelot-v3": return arbcommon.ProtocolCamelotV3 case "curve": return arbcommon.ProtocolCurve case "balancer", "balancer-v2": return arbcommon.ProtocolBalancerV2 case "balancer-v3": return arbcommon.ProtocolBalancerV3 default: // Default to UniswapV2 for unknown protocols return arbcommon.ProtocolUniswapV2 } } // parsePoolType converts protocol string to PoolType enum func parsePoolType(protocol string) arbcommon.PoolType { switch protocol { case "uniswap-v2", "sushiswap", "sushiswap-v2", "camelot", "camelot-v2": return arbcommon.PoolTypeConstantProduct case "uniswap-v3", "sushiswap-v3", "camelot-v3": return arbcommon.PoolTypeConcentrated case "curve": return arbcommon.PoolTypeStableSwap case "balancer", "balancer-v2", "balancer-v3": return arbcommon.PoolTypeWeighted default: return arbcommon.PoolTypeConstantProduct } }