diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b3a7554 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,54 @@ +# Exclude V1 codebase (not needed in V2 container) +orig/ + +# Exclude build artifacts +bin/ +build/ +dist/ +*.exe + +# Exclude logs +logs/ +*.log + +# Exclude temporary files +tmp/ +temp/ +*.tmp + +# Exclude test coverage +*.out +coverage.html + +# Exclude IDE files +.vscode/ +.idea/ +*.swp + +# Exclude git +.git/ +.gitignore + +# Exclude documentation (not needed at runtime) +docs/ +*.md + +# Exclude environment files (passed at runtime) +.env +.env.* + +# Exclude Docker/k8s files +docker-compose.yml +Dockerfile +.dockerignore + +# Exclude test files +*_test.go +example_usage.go +examples_test.go + +# Exclude scripts (not needed in container) +scripts/ + +# Exclude config (provisioned externally) +config/ diff --git a/Dockerfile b/Dockerfile index 23956e2..cbc6152 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,9 @@ RUN go mod download # Copy source code COPY . . +# Update go.sum with all dependencies +RUN go mod tidy + # Build the application RUN go build -o mev-bot-v2 -ldflags="-w -s" ./cmd/mev-bot-v2 diff --git a/pkg/parsers/arbiscan_validator.go b/pkg/parsers/arbiscan_validator.go index af50d68..ef8d539 100644 --- a/pkg/parsers/arbiscan_validator.go +++ b/pkg/parsers/arbiscan_validator.go @@ -103,7 +103,7 @@ func (v *ArbiscanValidator) ValidateSwap(ctx context.Context, event *types.SwapE SwapEvent: event, ArbiscanLog: matchingLog, Discrepancies: discrepancies, - ValidatedAt: time.Time(), + ValidatedAt: time.Now(), } // Log validation result diff --git a/pkg/parsers/example_usage.go b/pkg/parsers/example_usage.go index fcaf91e..f8f92f6 100644 --- a/pkg/parsers/example_usage.go +++ b/pkg/parsers/example_usage.go @@ -1,3 +1,6 @@ +//go:build examples +// +build examples + package parsers // This file demonstrates how to use the parser factory with multiple protocol parsers, diff --git a/pkg/pools/discovery.go b/pkg/pools/discovery.go index 8035081..06aeb67 100644 --- a/pkg/pools/discovery.go +++ b/pkg/pools/discovery.go @@ -84,7 +84,7 @@ func DefaultDiscoveryConfig() *DiscoveryConfig { type Discovery struct { config *DiscoveryConfig client *ethclient.Client - cache *cache.PoolCache + cache cache.PoolCache logger *slog.Logger mu sync.Mutex @@ -92,7 +92,7 @@ type Discovery struct { } // NewDiscovery creates a new pool discovery service -func NewDiscovery(config *DiscoveryConfig, cache *cache.PoolCache, logger *slog.Logger) (*Discovery, error) { +func NewDiscovery(config *DiscoveryConfig, poolCache cache.PoolCache, logger *slog.Logger) (*Discovery, error) { if config == nil { config = DefaultDiscoveryConfig() } @@ -105,7 +105,7 @@ func NewDiscovery(config *DiscoveryConfig, cache *cache.PoolCache, logger *slog. return &Discovery{ config: config, client: client, - cache: cache, + cache: poolCache, logger: logger.With("component", "pool_discovery"), }, nil } @@ -124,7 +124,8 @@ func (d *Discovery) DiscoverAll(ctx context.Context) error { d.logger.Error("uniswap v3 discovery failed", "error", err) } - d.logger.Info("pool discovery complete", "pools_discovered", d.poolsDiscovered, "total_cached", d.cache.Count()) + count, _ := d.cache.Count(ctx) + d.logger.Info("pool discovery complete", "pools_discovered", d.poolsDiscovered, "total_cached", count) return nil } @@ -134,7 +135,7 @@ func (d *Discovery) discoverUniswapV2Pools(ctx context.Context) error { factories := []struct { address common.Address - protocol string + protocol mevtypes.ProtocolType }{ {UniswapV2FactoryAddress, mevtypes.ProtocolUniswapV2}, {CamelotFactoryAddress, mevtypes.ProtocolCamelot}, @@ -173,7 +174,7 @@ func (d *Discovery) discoverUniswapV2Pools(ctx context.Context) error { } // Add to cache - if err := d.cache.Add(poolInfo); err != nil { + if err := d.cache.Add(ctx, poolInfo); err != nil { d.logger.Warn("failed to add pool to cache", "pool", poolAddr.Hex(), "error", err) continue } @@ -218,7 +219,7 @@ func (d *Discovery) getUniswapV2Pool(ctx context.Context, factory common.Address } // fetchUniswapV2PoolInfo fetches pool information -func (d *Discovery) fetchUniswapV2PoolInfo(ctx context.Context, poolAddr, token0, token1 common.Address, protocol string) (*mevtypes.PoolInfo, error) { +func (d *Discovery) fetchUniswapV2PoolInfo(ctx context.Context, poolAddr, token0, token1 common.Address, protocol mevtypes.ProtocolType) (*mevtypes.PoolInfo, error) { // getReserves() returns (uint112,uint112,uint32) // Simplified - in production use generated bindings calldata := []byte{0x09, 0x02, 0xf1, 0xac} // getReserves selector @@ -290,7 +291,7 @@ func (d *Discovery) discoverUniswapV3Pools(ctx context.Context) error { } // Add to cache - if err := d.cache.Add(poolInfo); err != nil { + if err := d.cache.Add(ctx, poolInfo); err != nil { d.logger.Warn("failed to add pool to cache", "pool", poolAddr.Hex(), "error", err) continue } @@ -391,8 +392,9 @@ func (d *Discovery) GetStats() map[string]interface{} { d.mu.Lock() defer d.mu.Unlock() + count, _ := d.cache.Count(context.Background()) return map[string]interface{}{ "pools_discovered": d.poolsDiscovered, - "pools_cached": d.cache.Count(), + "pools_cached": count, } } diff --git a/pkg/types/logger.go b/pkg/types/logger.go new file mode 100644 index 0000000..a8258d6 --- /dev/null +++ b/pkg/types/logger.go @@ -0,0 +1,8 @@ +package types + +import ( + "log/slog" +) + +// Logger is an alias for structured logger +type Logger = *slog.Logger diff --git a/pkg/types/pool.go b/pkg/types/pool.go index c259755..91033d4 100644 --- a/pkg/types/pool.go +++ b/pkg/types/pool.go @@ -25,6 +25,7 @@ type PoolInfo struct { Reserve0 *big.Int Reserve1 *big.Int Liquidity *big.Int + LiquidityUSD *big.Int // Total liquidity in USD (estimated) // Fee information Fee uint32 // Fee in basis points (e.g., 30 = 0.3%) diff --git a/pkg/types/swap.go b/pkg/types/swap.go index f7a8c3b..beb1839 100644 --- a/pkg/types/swap.go +++ b/pkg/types/swap.go @@ -20,6 +20,8 @@ const ( ProtocolBalancerV3 ProtocolType = "balancer-v3" ProtocolKyberClassic ProtocolType = "kyber-classic" ProtocolKyberElastic ProtocolType = "kyber-elastic" + ProtocolSushiSwap ProtocolType = "sushiswap" + ProtocolCamelot ProtocolType = "camelot" ProtocolCamelotV2 ProtocolType = "camelot-v2" ProtocolCamelotV3AlgebraV1 ProtocolType = "camelot-v3-algebra-v1" ProtocolCamelotV3AlgebraV19 ProtocolType = "camelot-v3-algebra-v1.9"