chain

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package chain reads an EVM chain and returns ERC20, ERC721 and ERC1155 transfer event logs. The data returned is []*TransferEvent, and it is cleansed and enhanced with TransferType to distinguish the token types.

  • No graph-related logic is applied here, this is pure event log handling.
  • For performance reasons, no additional chain reads are allowed here. It must only be a single log query hitting the chain.

Index

Constants

View Source
const ERC1155_BATCH string = "ERC1155_BATCH"
View Source
const ERC1155_SINGLE string = "ERC1155_SINGLE"
View Source
const ERC20 string = "ERC20"
View Source
const ERC721 string = "ERC721"

Variables

This section is empty.

Functions

func DecodeDataForErc1155Batch

func DecodeDataForErc1155Batch(logData []byte) (ids []*big.Int, values []*big.Int)

DecodeDataForErc1155Batch decodes the log.Data field from a ERC1155 "batch transfer" event log and returns empty slices if any troubles. []ids and []values are guaranteed to have same number of entries, which could be zero.

func DecodeDataForErc1155Single

func DecodeDataForErc1155Single(logData []byte) (id *big.Int, value *big.Int)

DecodeDataForErc1155Single decodes the log.Data field from a ERC1155 "single transfer" event log and returns zeroes if any troubles

Types

type EvmClient

type EvmClient struct {
	Name              string
	ChainId           string
	LatestBlockNumber uint64
	Url               string
	Client            *ethclient.Client
}

func CreateEvmClient

func CreateEvmClient(url string) (EvmClient, error)

CreateEvmClient gets an EVM client and name. The name comes from reading embedded file copied from this JSON https://github.com/DefiLlama/chainlist/blob/main/constants/chainIds.json

type TransferEvent

type TransferEvent struct {
	// Block number
	BlockNumber uint64

	// Block timestamp from chain (enrichment)
	BlockTimestamp time.Time

	// Transaction timestamp estimated as a proportion through whole block time, based transaction index inside block (enrichment)
	TransactionTimestampEstimate time.Time

	// Index at which first seen in dataset, equivalent of TransactionTimestampEstimate
	TransactionTimestampEstimateIndex uint

	// Transaction hash
	TxHash common.Hash

	// Transaction index in the block
	TxIndex uint

	// Log transfer event is ERC20, ERC721, ERC1155
	TransferType string

	// Log index (can be many logs for one transaction)
	LogIndex uint

	// Transfer event log address from
	LogAddressFrom common.Address

	// Transfer event log address to
	LogAddressTo common.Address

	// Transfer event log address from, time first seen in dataset (enrichment)
	LogAddressFromFirstSeen time.Time

	// Transfer event log address to, time first seen in dataset (enrichment)
	LogAddressToFirstSeen time.Time

	// Transfer event log address from, index at which first seen in dataset (enrichment)
	LogAddressFromFirstSeenIndex uint

	// Transfer event log address to, index at which first seen in dataset (enrichment)
	LogAddressToFirstSeenIndex uint

	// Transfer event log, the value of tokens transferred, filled for ERC20, ERC1155, else 0
	LogTokenValue big.Int

	// Transfer event log, the NFT id transferred (natively uint256 on Ethereum), filled for ERC721, ERC1155, else empty
	LogNftId string

	// Transfer event log, for ERC1155 this holds the operator (the address of an account/contract that is approved to make the transfer), else 0x
	LogOperator common.Address

	// The address that emitted the transfer event log
	LogEmitterAddress common.Address
}

func GetTransferEventsByBlock

func GetTransferEventsByBlock(client *ethclient.Client, blockNumberInt uint64,
	onlyThisTokenAddress string) ([]*TransferEvent, error)

func (*TransferEvent) Print

func (event *TransferEvent) Print(title string)

Jump to

Keyboard shortcuts

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