fix(compilation): resolve type system and interface errors

- Add GetPoolsByToken method to cache interface and implementation
- Fix interface pointer types (use interface not *interface)
- Fix SwapEvent.TokenIn/TokenOut usage to use GetInputToken/GetOutputToken methods
- Fix ethereum.CallMsg import and usage
- Fix parser factory and validator initialization in main.go
- Remove unused variables and imports

WIP: Still fixing main.go config struct field mismatches

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Administrator
2025-11-10 19:46:06 +01:00
parent 9982573a8b
commit 688311f1e0
8 changed files with 43 additions and 30 deletions

View File

@@ -271,19 +271,13 @@ func (c *Calculator) calculateSwapOutputCurve(pool *types.PoolInfo, tokenIn, tok
return nil, 0, fmt.Errorf("pool has nil reserves") return nil, 0, fmt.Errorf("pool has nil reserves")
} }
// Determine direction // Determine direction (validate token is in pool)
var reserveIn, reserveOut *big.Int if tokenIn != pool.Token0 && tokenIn != pool.Token1 {
if tokenIn == pool.Token0 {
reserveIn = pool.Reserve0
reserveOut = pool.Reserve1
} else if tokenIn == pool.Token1 {
reserveIn = pool.Reserve1
reserveOut = pool.Reserve0
} else {
return nil, 0, fmt.Errorf("token not in pool") return nil, 0, fmt.Errorf("token not in pool")
} }
// Simplified: assume 1:1 swap with low slippage for stablecoins // Simplified: assume 1:1 swap with low slippage for stablecoins
// TODO: Implement proper Curve StableSwap math using reserves and amp coefficient
// This is a rough approximation - actual Curve math is more complex // This is a rough approximation - actual Curve math is more complex
fee := pool.Fee fee := pool.Fee
if fee == 0 { if fee == 0 {

View File

@@ -56,7 +56,7 @@ type Detector struct {
config *DetectorConfig config *DetectorConfig
pathFinder *PathFinder pathFinder *PathFinder
calculator *Calculator calculator *Calculator
poolCache *cache.PoolCache poolCache cache.PoolCache
logger *slog.Logger logger *slog.Logger
// Statistics // Statistics
@@ -72,7 +72,7 @@ func NewDetector(
config *DetectorConfig, config *DetectorConfig,
pathFinder *PathFinder, pathFinder *PathFinder,
calculator *Calculator, calculator *Calculator,
poolCache *cache.PoolCache, poolCache cache.PoolCache,
logger *slog.Logger, logger *slog.Logger,
) *Detector { ) *Detector {
if config == nil { if config == nil {
@@ -153,7 +153,9 @@ func (d *Detector) DetectOpportunitiesForSwap(ctx context.Context, swapEvent *me
) )
// Get affected tokens // Get affected tokens
tokens := []common.Address{swapEvent.TokenIn, swapEvent.TokenOut} tokenIn, _ := swapEvent.GetInputToken()
tokenOut, _ := swapEvent.GetOutputToken()
tokens := []common.Address{tokenIn, tokenOut}
allOpportunities := make([]*Opportunity, 0) allOpportunities := make([]*Opportunity, 0)

View File

@@ -37,13 +37,13 @@ func DefaultPathFinderConfig() *PathFinderConfig {
// PathFinder finds arbitrage paths between tokens // PathFinder finds arbitrage paths between tokens
type PathFinder struct { type PathFinder struct {
cache *cache.PoolCache cache cache.PoolCache
config *PathFinderConfig config *PathFinderConfig
logger *slog.Logger logger *slog.Logger
} }
// NewPathFinder creates a new path finder // NewPathFinder creates a new path finder
func NewPathFinder(cache *cache.PoolCache, config *PathFinderConfig, logger *slog.Logger) *PathFinder { func NewPathFinder(cache cache.PoolCache, config *PathFinderConfig, logger *slog.Logger) *PathFinder {
if config == nil { if config == nil {
config = DefaultPathFinderConfig() config = DefaultPathFinderConfig()
} }
@@ -427,11 +427,11 @@ func (pf *PathFinder) getCommonTokens(ctx context.Context, baseToken common.Addr
// ARB // ARB
arb := common.HexToAddress("0x912CE59144191C1204E64559FE8253a0e49E6548") arb := common.HexToAddress("0x912CE59144191C1204E64559FE8253a0e49E6548")
common := []common.Address{weth, usdc, usdt, dai, arb} commonTokens := []common.Address{weth, usdc, usdt, dai, arb}
// Filter out the base token itself // Filter out the base token itself
filtered := make([]common.Address, 0) filtered := make([]common.Address, 0)
for _, token := range common { for _, token := range commonTokens {
if token != baseToken { if token != baseToken {
filtered = append(filtered, token) filtered = append(filtered, token)
} }

View File

@@ -24,6 +24,9 @@ type PoolCache interface {
// GetByLiquidity retrieves pools sorted by liquidity (descending) // GetByLiquidity retrieves pools sorted by liquidity (descending)
GetByLiquidity(ctx context.Context, minLiquidity *big.Int, limit int) ([]*types.PoolInfo, error) GetByLiquidity(ctx context.Context, minLiquidity *big.Int, limit int) ([]*types.PoolInfo, error)
// GetPoolsByToken retrieves all pools containing a specific token
GetPoolsByToken(ctx context.Context, token common.Address) ([]*types.PoolInfo, error)
// Add adds or updates a pool in the cache // Add adds or updates a pool in the cache
Add(ctx context.Context, pool *types.PoolInfo) error Add(ctx context.Context, pool *types.PoolInfo) error

View File

@@ -112,6 +112,21 @@ func (c *poolCache) GetByLiquidity(ctx context.Context, minLiquidity *big.Int, l
return pools, nil return pools, nil
} }
// GetPoolsByToken retrieves all pools containing a specific token
func (c *poolCache) GetPoolsByToken(ctx context.Context, token common.Address) ([]*types.PoolInfo, error) {
c.mu.RLock()
defer c.mu.RUnlock()
var pools []*types.PoolInfo
for _, pool := range c.byAddress {
if pool.Token0 == token || pool.Token1 == token {
pools = append(pools, pool)
}
}
return pools, nil
}
// Add adds or updates a pool in the cache // Add adds or updates a pool in the cache
func (c *poolCache) Add(ctx context.Context, pool *types.PoolInfo) error { func (c *poolCache) Add(ctx context.Context, pool *types.PoolInfo) error {
if pool == nil { if pool == nil {

View File

@@ -232,7 +232,7 @@ func (e *Executor) Execute(ctx context.Context, opp *arbitrage.Opportunity) (*Ex
// Calculate actual profit // Calculate actual profit
actualProfit := e.calculateActualProfit(receipt, opp) actualProfit := e.calculateActualProfit(receipt, opp)
gasCost := new(big.Int).Mul(receipt.GasUsed, receipt.EffectiveGasPrice) gasCost := new(big.Int).Mul(big.NewInt(int64(receipt.GasUsed)), receipt.EffectiveGasPrice)
result := &ExecutionResult{ result := &ExecutionResult{
Success: receipt.Status == types.ReceiptStatusSuccessful, Success: receipt.Status == types.ReceiptStatusSuccessful,

View File

@@ -8,8 +8,8 @@ import (
"sync" "sync"
"time" "time"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/your-org/mev-bot/pkg/arbitrage" "github.com/your-org/mev-bot/pkg/arbitrage"
@@ -254,7 +254,7 @@ func (rm *RiskManager) SimulateExecution(
defer cancel() defer cancel()
// Create call message // Create call message
msg := types.CallMsg{ msg := ethereum.CallMsg{
To: &tx.To, To: &tx.To,
Gas: tx.GasLimit, Gas: tx.GasLimit,
GasPrice: tx.MaxFeePerGas, GasPrice: tx.MaxFeePerGas,

View File

@@ -2,7 +2,6 @@ package sequencer
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"log/slog" "log/slog"
"math/big" "math/big"
@@ -66,9 +65,9 @@ type Reader struct {
logger *slog.Logger logger *slog.Logger
// Components // Components
parsers *parsers.Factory parsers parsers.Factory
validator *validation.Validator validator validation.Validator
poolCache *cache.PoolCache poolCache cache.PoolCache
detector *arbitrage.Detector detector *arbitrage.Detector
executor *execution.Executor executor *execution.Executor
@@ -104,9 +103,9 @@ type Reader struct {
// NewReader creates a new sequencer reader // NewReader creates a new sequencer reader
func NewReader( func NewReader(
config *ReaderConfig, config *ReaderConfig,
parsers *parsers.Factory, parsers parsers.Factory,
validator *validation.Validator, validator validation.Validator,
poolCache *cache.PoolCache, poolCache cache.PoolCache,
detector *arbitrage.Detector, detector *arbitrage.Detector,
executor *execution.Executor, executor *execution.Executor,
logger *slog.Logger, logger *slog.Logger,
@@ -333,8 +332,8 @@ func (r *Reader) processTxHash(ctx context.Context, txHash string) error {
parseStart := time.Now() parseStart := time.Now()
// Parse transaction events // Parse transaction events (no receipt for pending transactions)
events, err := r.parsers.ParseTransaction(tx) events, err := r.parsers.ParseTransaction(procCtx, tx, nil)
if err != nil { if err != nil {
r.parseErrors++ r.parseErrors++
return fmt.Errorf("parse failed: %w", err) return fmt.Errorf("parse failed: %w", err)
@@ -347,7 +346,7 @@ func (r *Reader) processTxHash(ctx context.Context, txHash string) error {
r.avgParseLatency = time.Since(parseStart) r.avgParseLatency = time.Since(parseStart)
// Validate events // Validate events
validEvents := r.validator.FilterValid(events) validEvents := r.validator.FilterValid(procCtx, events)
if len(validEvents) == 0 { if len(validEvents) == 0 {
r.validationErrors++ r.validationErrors++
return nil return nil
@@ -358,7 +357,7 @@ func (r *Reader) processTxHash(ctx context.Context, txHash string) error {
// Detect arbitrage opportunities for each swap // Detect arbitrage opportunities for each swap
for _, event := range validEvents { for _, event := range validEvents {
// Get input token from the swap // Get input token from the swap
inputToken := event.GetInputToken() inputToken, _ := event.GetInputToken()
// Detect opportunities starting with this token // Detect opportunities starting with this token
opportunities, err := r.detector.DetectOpportunities(procCtx, inputToken) opportunities, err := r.detector.DetectOpportunities(procCtx, inputToken)