erc20analyzer

package
v0.0.0-...-daf6a28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultFeeAndGasUpdateFrequency = 5 * time.Minute
	DefaultMinTokenUpdateInterval   = 60 * time.Minute
	DefaultInitializeRequestTimeout = 20 * time.Second
)

Functions

This section is empty.

Types

type Analyzer

type Analyzer struct {
	// contains filtered or unexported fields
}

Analyzer is the central orchestrator for processing token data.

func NewAnalyzer

func NewAnalyzer(ctx context.Context, cfg Config) (*Analyzer, error)

NewAnalyzer creates and starts a new Analyzer instance.

func (*Analyzer) View

func (a *Analyzer) View() []token.TokenView

type BlockExtractor

type BlockExtractor interface {
	// Run starts the main log extraction process.
	//
	// It is a blocking call that continuously listens for new blocks on the
	// eventer channel and handles them. It is designed to be run in a separate
	// goroutine.
	//
	// The process can be gracefully shut down by canceling the provided context.
	//
	// Parameters:
	//   - ctx: The context for managing the lifecycle of the Run loop.
	//   - eventer: A read-only channel that provides new blocks to be processed.
	//   - logsHandler: A callback function that is invoked with any logs found
	//     in a block that matches the filtering criteria.
	//   - errHandler: A callback function for handling any non-terminal errors
	//     that occur during the process.
	Run(
		ctx context.Context,
		eventer <-chan *types.Block,
		logsHandler func(context.Context, []types.Log) error,
		errHandler func(error),
	)
}

BlockExtractor defines the contract for a service that extracts logs. It provides a standardized way to start, run, and shut down a log extraction process, abstracting away the specific implementation details.

type Config

type Config struct {
	NewBlockEventer          <-chan *types.Block
	TokenStore               TokenStore
	TokenInitializer         TokenInitializer
	BlockExtractor           BlockExtractor
	TokenHolderAnalyzer      TokenHolderAnalyzer
	FeeAndGasRequester       FeeAndGasRequester
	FeeAndGasUpdateFrequency time.Duration
	MinTokenUpdateInterval   time.Duration
	ErrorHandler             func(error)
	Logger                   Logger
}

Config holds the dependencies required to initialize an Analyzer.

type FeeAndGasRequester

type FeeAndGasRequester interface {
	// RequestAll takes a map of tokens to their respective holders and returns
	// a map of tokens to their fee/gas results. It should handle requests
	// concurrently for efficiency.
	RequestAll(
		ctx context.Context,
		tokensByHolder map[common.Address]common.Address,
	) (map[common.Address]FeeAndGasResult, error)
}

FeeAndGasRequester defines the contract for a component that can fetch fee and gas data for a batch of tokens.

type FeeAndGasResult

type FeeAndGasResult struct {
	Fee   float64
	Gas   uint64
	Error error // Holds an error if this specific request failed.
}

FeeAndGasResult holds the outcome of a fee/gas request for a single token. It includes an Error field to allow for partial success in batch operations.

type Logger

type Logger interface {
	Debug(msg string, args ...any)
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
	Error(msg string, args ...any)
}

Logger defines a standard interface for structured, leveled logging, compatible with the standard library's slog.

type TokenHolderAnalyzer

type TokenHolderAnalyzer interface {
	// Update processes a new batch of logs to update its internal state.
	Update(logs []types.Log)

	// TokenByMaxKnownHolder returns a map of the current "max holder" for each token.
	TokenByMaxKnownHolder() map[common.Address]common.Address
}

TokenHolderAnalyzer defines the contract for any component that can analyze logs to determine the primary holder of a token based on its own internal strategy.

type TokenInitializer

type TokenInitializer interface {
	Initialize(ctx context.Context, tokenAddress common.Address, store TokenStore) (token.TokenView, error)
}

type TokenStore

type TokenStore interface {
	AddToken(addr common.Address, name, symbol string, decimals uint8) (uint64, error)
	DeleteToken(idToDelete uint64) error
	UpdateToken(id uint64, fee float64, gas uint64) error
	View() []token.TokenView
	GetTokenByID(id uint64) (token.TokenView, error)
	GetTokenByAddress(addr common.Address) (token.TokenView, error)
}

TokenStore defines the interface for a system that stores and manages ERC20 token data. This allows the analyzer to remain decoupled from the specific database or storage implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL