utils

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: Apache-2.0 Imports: 17 Imported by: 37

Documentation

Index

Constants

View Source
const (
	AnvilNetwork Network = "anvil"
	Ethereum     Network = "ethereum"
	Bsc          Network = "bsc"
	Polygon      Network = "polygon"
	Avalanche    Network = "avalanche"
	Fantom       Network = "fantom"
	Arbitrum     Network = "arbitrum"
	Optimism     Network = "optimism"

	// Mainnets
	EthereumNetworkID  NetworkID = 1
	BscNetworkID       NetworkID = 56
	PolygonNetworkID   NetworkID = 137
	AvalancheNetworkID NetworkID = 43114
	FantomNetworkID    NetworkID = 250
	ArbitrumNetworkID  NetworkID = 42161
	OptimismNetworkID  NetworkID = 10

	// Special Mainnets
	AnvilMainnetNetworkID NetworkID = 1

	// Testnets
	RopstenNetworkID    NetworkID = 3
	RinkebyNetworkID    NetworkID = 4
	GoerliNetworkID     NetworkID = 5
	KovanNetworkID      NetworkID = 42
	BscTestnetNetworkID NetworkID = 97
	MumbaiNetworkID     NetworkID = 80001
	FujiNetworkID       NetworkID = 43113
	FantomTestNetworkID NetworkID = 4002
	ArbitrumRinkebyID   NetworkID = 421611
	OptimismKovanID     NetworkID = 69

	// Localnets
	AnvilNetworkID NetworkID = 1337
)
View Source
const (
	HeadStrategy    Strategy = "head"
	ArchiveStrategy Strategy = "archive"

	ZeroAddressRecipient AddressType = "zero_address"
	AddressRecipient     AddressType = "address"
	ContractRecipient    AddressType = "contract"

	UnknownTransactionMethodType TransactionMethodType = "unknown"
	ContractCreationType         TransactionMethodType = "contract_creation"
	TransferMethodType           TransactionMethodType = "transfer"
	NoSignatureMethodType        TransactionMethodType = "no_signature"

	UnknownLogEventType  LogEventType = "unknown"
	SwapLogEventType     LogEventType = "swap"
	TransferLogEventType LogEventType = "transfer"
	DepositLogEventType  LogEventType = "deposit"
	WithdrawLogEventType LogEventType = "withdraw"
	MintLogEventType     LogEventType = "mint"
	BurnLogEventType     LogEventType = "burn"

	NoSimulator    SimulatorType = "no_simulator"
	AnvilSimulator SimulatorType = "anvil"
	TraceSimulator SimulatorType = "trace"

	SimulatorAccountType AccountType = "simulator"
	SimpleAccountType    AccountType = "simple"
	KeystoreAccountType  AccountType = "keystore"

	NoExchange    ExchangeType = "no_exchange"
	UniswapV2     ExchangeType = "uniswap_v2"
	UniswapV3     ExchangeType = "uniswap_v3"
	SushiSwap     ExchangeType = "sushiswap"
	PancakeswapV2 ExchangeType = "pancakeswap_v2"

	Erc20TokenType  TokenType = "erc20"
	Erc721TokenType TokenType = "erc721"

	AntiWhalePinksale AntiWhaleType = "pinksale"

	BuyTradeType  TradeType = "buy"
	SellTradeType TradeType = "sell"

	UnknownSafetyState SafetyStateType = "unknown"
	SafeSafetyState    SafetyStateType = "safe"
	WarnSafetyState    SafetyStateType = "warning"
	UnsafeSafetyState  SafetyStateType = "unsafe"

	RugpullBlacklistType          BlacklistType = "rugpull"
	HoneypotBlacklistType         BlacklistType = "honeypot"
	HighTaxTokenBlacklistType     BlacklistType = "high_tax_token"
	PumpAndDumpTokenBlacklistType BlacklistType = "pump_and_dump_token"
	MixerUsageBlacklistType       BlacklistType = "mixer_usage"
)

Constants defining various strategies, address types, transaction method types, etc.

Variables

View Source
var (
	// ZeroAddress represents a zero Ethereum address
	ZeroAddress = common.HexToAddress("0x0000000000000000000000000000000000000000")

	// ZeroHash represents a hash value consisting of all zeros.
	ZeroHash = common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000")
)
View Source
var (
	ZeroSignatureBytes = []byte{0x00, 0x00, 0x00, 0x00}
	ZeroSignature      = "0x00000000"
)

ZeroSignatureBytes and ZeroSignature represent a null signature in Ethereum transactions.

View Source
var ErrRateLimitExceeded = errors.New("rate limit exceeded")

ErrRateLimitExceeded is returned when the rate limit has been exceeded.

Functions

func AddressInSlice added in v0.3.3

func AddressInSlice(addr common.Address, list []common.Address) bool

AddressInSlice checks whether an Ethereum address is present in a slice of addresses.

func ContainsBlacklistType added in v0.3.3

func ContainsBlacklistType(list []BlacklistType, item BlacklistType) bool

ContainsBlacklistType checks whether a BlacklistType item is present in a slice of BlacklistType.

func ContainsTransactionMethodType added in v0.3.3

func ContainsTransactionMethodType(list []TransactionMethodType, item TransactionMethodType) bool

ContainsTransactionMethodType checks whether a TransactionMethodType item is present in a slice of TransactionMethodType.

func ContainsUUID added in v0.3.3

func ContainsUUID(list []uuid.UUID, item uuid.UUID) bool

ContainsUUID checks whether a UUID is present in a slice of UUIDs by comparing their string representations.

func DumpNodeNoExit

func DumpNodeNoExit(whatever any)

DumpNodeNoExit prints a formatted JSON representation of the provided interface without exiting the program. This function is primarily used for debugging purposes.

func DumpNodeWithExit

func DumpNodeWithExit(whatever any)

DumpNodeWithExit prints a formatted JSON representation of the provided interface and exits the program. This function is primarily used for debugging purposes.

func EventToABI added in v0.3.2

func EventToABI(method *abi.Event) (string, error)

EventToABI converts a Event object to its JSON ABI representation.

func FromJSON added in v0.3.3

func FromJSON[T any](data []byte, target *T) error

FromJSON converts JSON data into a Go data structure of type T. It takes a slice of bytes representing the JSON data and a pointer to the type T where the data will be decoded. Returns an error if the decoding fails.

func GetBuildVersionByModule added in v0.3.3

func GetBuildVersionByModule(module string) string

GetBuildVersionByModule retrieves the build version of a specified module from the current application's build information. It parses the build information obtained from the runtime debug package to search for a specific module.

func GetCurrentPath added in v0.3.2

func GetCurrentPath() (string, error)

GetCurrentPath returns the current working directory.

func GetLocalSourcesPath

func GetLocalSourcesPath() string

GetLocalSourcesPath returns the absolute path to the local sources directory.

func IsSemanticVersionGreaterOrEqualTo added in v0.3.1

func IsSemanticVersionGreaterOrEqualTo(versionStr string, version SemanticVersion) bool

IsSemanticVersionGreaterOrEqualTo checks if the version represented by a string is greater than or equal to the provided SemanticVersion. The comparison takes into account the Major, Minor, and Patch components of the semantic version.

func IsSemanticVersionLowerOrEqualTo added in v0.3.1

func IsSemanticVersionLowerOrEqualTo(versionStr string, version SemanticVersion) bool

IsSemanticVersionLowerOrEqualTo checks if the version represented by a string is lower than or equal to the provided SemanticVersion. The comparison considers the Major, Minor, and Patch components of the semantic version.

func Keccak256 added in v0.3.1

func Keccak256(data []byte) []byte

Keccak256 returns the Keccak256 hash of the input data.

func MethodToABI added in v0.3.2

func MethodToABI(method *abi.Method) (string, error)

MethodToABI converts a Method object to its JSON ABI representation.

func PathExists added in v0.3.2

func PathExists(path string) bool

PathExists returns true if the given path exists.

func SimplifyImportPaths

func SimplifyImportPaths(content string) string

SimplifyImportPaths simplifies the paths in import statements as file will already be present in the directory for future consumption and is rather corrupted for import paths to stay the same.

func StringInSlice added in v0.3.3

func StringInSlice(str string, list []string) bool

StringInSlice checks whether a string is present in a slice of strings.

func StripExtraSPDXLines

func StripExtraSPDXLines(content string) string

StripExtraSPDXLines removes the extra SPDX lines from the content. This is used when passing combined source to the solc compiler as it will complain about the extra SPDX lines.

func StripImportPaths

func StripImportPaths(content string) string

StripImportPaths removes the import paths entirely from the content.

func ToABI added in v0.3.2

func ToABI(data []byte) (*abi.ABI, error)

ToABI converts the ABI object into an ethereum/go-ethereum ABI object.

func ToJSON

func ToJSON(data any) ([]byte, error)

ToJSON converts a Go struct to its JSON representation.

func ToJSONPretty

func ToJSONPretty(data any) ([]byte, error)

ToJSONPretty returns a pretty-printed JSON representation of the provided interface. This function is primarily used for debugging purposes.

func ToProtoJSON

func ToProtoJSON(data any) ([]byte, error)

ToProtoJSON converts a Go struct to its JSON representation.

func WriteToFile

func WriteToFile(path string, data []byte) error

WriteToFile writes the provided data byte array to a file at the provided path.

Types

type AccountType added in v0.3.2

type AccountType string

AccountType categorizes the types of accounts used, particularly in simulations. Types include "simulator" for simulated accounts, "simple", and "keystore" for accounts stored in encrypted format.

func (AccountType) String added in v0.3.2

func (t AccountType) String() string

String returns the string representation of an AccountType.

type AddressType added in v0.3.2

type AddressType string

AddressType categorizes Ethereum addresses based on their usage context. Types include "zero_address" for the null address, "address" for standard addresses, and "contract" for contract addresses.

func (AddressType) String added in v0.3.2

func (r AddressType) String() string

String returns the string representation of an AddressType.

type AntiWhaleType added in v0.3.3

type AntiWhaleType string

AntiWhaleType represents types of anti-whale measures, such as "pinksale" for specific project launches with anti-whale features.

func (AntiWhaleType) String added in v0.3.3

func (t AntiWhaleType) String() string

String returns the string representation of an AntiWhaleType.

type ArgumentABI added in v0.3.2

type ArgumentABI struct {
	Name    string `json:"name"`
	Type    string `json:"type"`
	Indexed bool   `json:"indexed,omitempty"`
}

ArgumentABI represents the JSON structure of a method's argument.

type BlacklistType added in v0.3.3

type BlacklistType string

BlacklistType defines types of blacklist categories for tokens or contracts, such as "rugpull", "honeypot", and others related to specific risks.

func (BlacklistType) String added in v0.3.3

func (t BlacklistType) String() string

String returns the string representation of a BlacklistType.

type ExchangeType added in v0.3.3

type ExchangeType string

ExchangeType represents various decentralized exchange (DEX) protocols. Types include "no_exchange", "uniswap_v2", "uniswap_v3", "sushiswap", and "pancakeswap_v2".

func (ExchangeType) String added in v0.3.3

func (t ExchangeType) String() string

String returns the string representation of an ExchangeType.

type LogEventType added in v0.3.2

type LogEventType string

LogEventType represents the type of event logged by Ethereum smart contracts. Types include various events such as "swap", "transfer", "deposit", "withdraw", "mint", and "burn", along with "unknown" for undetermined event types.

func (LogEventType) String added in v0.3.2

func (t LogEventType) String() string

String returns the string representation of a LogEventType.

type MethodABI added in v0.3.2

type MethodABI struct {
	Name            string        `json:"name"`
	Type            string        `json:"type"` // "function", "constructor", etc.
	Inputs          []ArgumentABI `json:"inputs,omitempty"`
	Outputs         []ArgumentABI `json:"outputs,omitempty"`
	StateMutability string        `json:"stateMutability,omitempty"`
	Constant        bool          `json:"constant,omitempty"`
	Payable         bool          `json:"payable,omitempty"`
}

MethodABI represents the JSON structure of a method's ABI.

type NamedAddr added in v0.3.3

type NamedAddr struct {
	Name string         `json:"name"`
	Ens  string         `json:"ens"`
	Tags []string       `json:"tags"`
	Addr common.Address `json:"addr"`
	Type AddressType    `json:"type"`
}

NamedAddr encapsulates detailed information about an Ethereum address along with its metadata. It includes a human-readable name, an optional Ethereum Name Service (ENS) domain, a set of tags for categorization or annotation, the Ethereum address itself, and the type of address which provides additional context about its use or origin.

func NamedAddressInSlice added in v0.3.3

func NamedAddressInSlice(addr common.Address, list []NamedAddr) (*NamedAddr, bool)

NamedAddressInSlice checks whether an Ethereum address is present in a slice of NamedAddr and returns the corresponding NamedAddr if found.

func (NamedAddr) AppendTags added in v0.3.5

func (n NamedAddr) AppendTags(tags ...string) NamedAddr

AppendTags appends unique tags to the named address

func (NamedAddr) IsZeroAddress added in v0.3.5

func (n NamedAddr) IsZeroAddress() bool

IsZeroAddress checks whenever named address is zero address

type Network added in v0.3.2

type Network string

func GetNetworkFromID added in v0.3.3

func GetNetworkFromID(id NetworkID) (Network, error)

func GetNetworkFromString added in v0.3.3

func GetNetworkFromString(network string) (Network, error)

func (Network) String added in v0.3.2

func (n Network) String() string

type NetworkID added in v0.3.2

type NetworkID uint64

func GetNetworkID added in v0.3.2

func GetNetworkID(network Network) NetworkID

func (NetworkID) IsValid added in v0.3.5

func (n NetworkID) IsValid() bool

func (NetworkID) String added in v0.3.3

func (n NetworkID) String() string

func (NetworkID) ToBig added in v0.3.2

func (n NetworkID) ToBig() *big.Int

func (NetworkID) ToNetwork added in v0.3.3

func (n NetworkID) ToNetwork() Network

func (NetworkID) Uint64 added in v0.3.3

func (n NetworkID) Uint64() uint64

type NormalizationInfo added in v0.3.1

type NormalizationInfo struct {
	TypeName   string
	Normalized bool
}

NormalizationInfo represents the result of a type normalization. It includes the normalized type name and a flag indicating whether the type name was actually normalized.

type NormalizeType added in v0.3.1

type NormalizeType struct{}

NormalizeType provides methods for normalizing type names.

func NewNormalizeType added in v0.3.1

func NewNormalizeType() *NormalizeType

NewNormalizeType creates and returns a new NormalizeType instance.

func (*NormalizeType) Normalize added in v0.3.1

func (n *NormalizeType) Normalize(typeName string) NormalizationInfo

Normalize attempts to normalize the given type name. It returns the NormalizationInfo which contains the normalized type name and a flag indicating if the provided type name was actually normalized.

type RateLimiter added in v0.3.4

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

RateLimiter implements a token bucket rate limiting algorithm. It is used to control how frequently events are allowed to happen. The RateLimiter allows a certain number of events to occur within a fixed time frame and refills the tokens at a constant interval.

func NewRateLimiter added in v0.3.4

func NewRateLimiter(capacity int, refillTime time.Duration) *RateLimiter

NewRateLimiter initializes and returns a new RateLimiter with the specified capacity and refill time. The capacity parameter specifies the maximum number of tokens, and refillTime specifies how often the tokens are replenished. A debug message showing the capacity is printed during initialization.

func (*RateLimiter) Allow added in v0.3.4

func (rl *RateLimiter) Allow() bool

Allow checks if at least one token is available. If a token is available, it consumes a token by decrementing the token count and returns true, indicating that the event is allowed to proceed. If no tokens are available, it returns false, indicating that the rate limit has been exceeded. Tokens are refilled based on the elapsed time since the last refill, up to the maximum capacity.

func (*RateLimiter) CheckLimit added in v0.3.5

func (rl *RateLimiter) CheckLimit() error

CheckLimit checks if the rate limit has been reached. If the rate limit has been reached, it returns an error indicating that the rate limit has been exceeded. Otherwise, it returns nil.

func (*RateLimiter) WaitForToken added in v0.3.4

func (rl *RateLimiter) WaitForToken()

WaitForToken blocks the caller until a token becomes available. If no tokens are available upon invoking this method, it waits for a signal from a separate goroutine indicating that tokens have been refilled. This method ensures that events respect the rate limit by waiting for permission to proceed rather than immediately returning false.

type SafetyStateType added in v0.3.3

type SafetyStateType string

SafetyStateType represents the safety state of a transaction or contract, including "unknown", "safe", "warning", and "unsafe".

func (SafetyStateType) String added in v0.3.3

func (t SafetyStateType) String() string

String returns the string representation of a SafetyStateType.

type SemanticVersion added in v0.3.1

type SemanticVersion struct {
	Major  int    `json:"major"`              // Major version, incremented for incompatible API changes.
	Minor  int    `json:"minor"`              // Minor version, incremented for backwards-compatible enhancements.
	Patch  int    `json:"patch"`              // Patch version, incremented for backwards-compatible bug fixes.
	Commit string `json:"revision,omitempty"` // Optional commit revision for tracking specific builds.
}

SemanticVersion represents a semantic version, following the Major.Minor.Patch format. Optionally, a version can include a commit revision as a metadata string appended after a plus sign (+).

func ParseSemanticVersion added in v0.3.1

func ParseSemanticVersion(version string) SemanticVersion

ParseSemanticVersion parses a version string into a SemanticVersion struct. The function supports version strings in the "Major.Minor.Patch" format, with an optional commit revision appended after a plus sign (+). The 'v' prefix in version strings is also supported and ignored during parsing.

func (SemanticVersion) String added in v0.3.3

func (v SemanticVersion) String() string

String returns the string representation of the SemanticVersion, excluding the commit revision. It adheres to the "Major.Minor.Patch" format.

func (SemanticVersion) StringVersion added in v0.3.5

func (v SemanticVersion) StringVersion() string

String returns the string representation of the SemanticVersion, excluding the commit revision. It adheres to the "Major.Minor.Patch" format.

type SimulatorType added in v0.3.2

type SimulatorType string

SimulatorType represents the types of simulators used for transaction execution or testing. Types include "no_simulator", "anvil" for the Anvil Ethereum simulator, and "trace" for simulators that support tracing capabilities.

func (SimulatorType) String added in v0.3.2

func (t SimulatorType) String() string

String returns the string representation of a SimulatorType.

type Strategy added in v0.3.2

type Strategy string

Strategy represents the strategy used in transaction processing or data fetching. Available strategies include "head" for latest data and "archive" for historical data.

func (Strategy) String added in v0.3.2

func (s Strategy) String() string

String returns the string representation of a Strategy.

type TokenType added in v0.3.3

type TokenType string

TokenType categorizes the types of tokens, such as "erc20" for standard fungible tokens and "erc721" for non-fungible tokens (NFTs).

func (TokenType) String added in v0.3.3

func (t TokenType) String() string

String returns the string representation of a TokenType.

type TradeType added in v0.3.3

type TradeType string

TradeType defines the type of trade action, including "buy" and "sell".

func (TradeType) String added in v0.3.3

func (t TradeType) String() string

String returns the string representation of a TradeType.

type TransactionMethodType added in v0.3.2

type TransactionMethodType string

TransactionMethodType defines the type of transaction method used in Ethereum transactions. Types include "unknown" for undetermined, "contract_creation" for contract deployments, "transfer" for token transfers, and "no_signature" for transactions without a signature.

func (TransactionMethodType) String added in v0.3.2

func (t TransactionMethodType) String() string

String returns the string representation of a TransactionMethodType.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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