tokens

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package tokens provides a high-level abstraction for interacting with Ethereum tokens. It offers functionalities to create, manipulate, and query token information using smart contract bindings and Ethereum network clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Descriptor

type Descriptor struct {
	BlockNumber       *big.Int        `json:"block_number"`        // Block number at which the token info was queried.
	Address           common.Address  `json:"address"`             // Ethereum address of the token contract.
	Name              string          `json:"name"`                // Name of the token.
	Symbol            string          `json:"symbol"`              // Symbol of the token.
	Decimals          uint8           `json:"decimals"`            // Decimal precision of the token.
	TotalSupply       *big.Int        `json:"total_supply"`        // Total supply of the token.
	TotalBurnedSupply *big.Int        `json:"total_burned_supply"` // Supply of tokens that have been burned.
	LatestBlockNumber *big.Int        `json:"latest_block_number"` // Latest block number processed by the application.
	Entity            *entities.Token `json:"-"`                   // Associated token entity, not serialized to JSON.
}

Descriptor contains detailed information about a specific Ethereum token. It includes metadata such as the token's address, name, symbol, decimals, total supply, total burned supply, and the latest block number for context.

func (*Descriptor) GetAddress

func (d *Descriptor) GetAddress() common.Address

GetAddress returns the Ethereum address of the token contract.

func (*Descriptor) GetDecimals

func (d *Descriptor) GetDecimals() uint8

GetDecimals returns the decimal precision of the token.

func (*Descriptor) GetEntity

func (d *Descriptor) GetEntity() *entities.Token

GetEntity returns the associated token entity.

func (*Descriptor) GetName

func (d *Descriptor) GetName() string

GetName returns the name of the token.

func (*Descriptor) GetSymbol

func (d *Descriptor) GetSymbol() string

GetSymbol returns the symbol of the token.

func (*Descriptor) GetTotalBurnedSupply

func (d *Descriptor) GetTotalBurnedSupply() *big.Int

GetTotalBurnedSupply returns the total supply of tokens that have been burned.

func (*Descriptor) GetTotalCirculatingSupply

func (d *Descriptor) GetTotalCirculatingSupply() *big.Int

GetTotalCirculatingSupply calculates and returns the total circulating supply of the token, which is the total supply minus the total burned supply.

func (*Descriptor) GetTotalSupply

func (d *Descriptor) GetTotalSupply() *big.Int

GetTotalSupply returns the total supply of the token.

type Token

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

Token encapsulates the necessary details and operations for interacting with an Ethereum token.

func NewToken

func NewToken(ctx context.Context, network utils.Network, address common.Address, bindManager *bindings.Manager, pool *clients.ClientPool) (*Token, error)

NewToken creates a new Token instance with the specified parameters. It prepares the contract bindings and validates the provided inputs.

func (*Token) CalculateTotalBurnedSupply

func (t *Token) CalculateTotalBurnedSupply(ctx context.Context) error

CalculateTotalBurnedSupply updates the TotalBurnedSupply field in the token's descriptor by summing the balances of well-known burn addresses. This method assumes these addresses are where tokens are sent to be "burned" or permanently removed from circulation.

func (*Token) GetBind

func (t *Token) GetBind() *bindings.Token

GetBind returns the smart contract bindings for the token.

func (*Token) GetBindManager

func (t *Token) GetBindManager() *bindings.Manager

GetBindManager returns the contract binding manager associated with the Token.

func (*Token) GetBinding

func (t *Token) GetBinding() *bindings.Token

func (*Token) GetClient

func (t *Token) GetClient() (*clients.Client, error)

GetClient retrieves an Ethereum client from the client pool.

func (*Token) GetClientPool

func (t *Token) GetClientPool() *clients.ClientPool

GetClientPool returns the pool of Ethereum network clients.

func (*Token) GetContext

func (t *Token) GetContext() context.Context

GetContext returns the context associated with the Token instance.

func (*Token) GetDescriptor

func (t *Token) GetDescriptor() *Descriptor

GetDescriptor returns the Descriptor of the token containing its metadata.

func (*Token) GetEntity

func (t *Token) GetEntity() *entities.Token

GetEntity returns the token entity, constructing it if necessary.

func (*Token) GetNetwork

func (t *Token) GetNetwork() utils.Network

GetNetwork returns the blockchain network the token is associated with.

func (*Token) GetNetworkID

func (t *Token) GetNetworkID() utils.NetworkID

GetNetworkID returns the numeric ID of the blockchain network.

func (*Token) GetSimulatorType

func (t *Token) GetSimulatorType() utils.SimulatorType

GetSimulatorType returns the type of simulator used for testing.

func (*Token) GetTokenBind

func (t *Token) GetTokenBind(ctx context.Context, bindManager *bindings.Manager) (*bindings.Token, error)

GetTokenBind connects to a blockchain simulator or live network to create a token binding. It uses bindings.Manager and can target a specific block number.

func (*Token) IsInSimulation

func (t *Token) IsInSimulation() bool

IsInSimulation returns true if the token is currently being simulated.

func (*Token) PrepareBindings

func (t *Token) PrepareBindings(ctx context.Context) error

PrepareBindings initializes the token binding for the Token struct based on the current network and contract address.

func (*Token) ResolveBalance

func (t *Token) ResolveBalance(ctx context.Context, from common.Address, bind *bindings.Token, address common.Address) (*big.Int, error)

ResolveBalance retrieves the balance of a specific address for the token.

func (*Token) ResolveDecimals

func (t *Token) ResolveDecimals(ctx context.Context, from common.Address, bind *bindings.Token) (uint8, error)

ResolveDecimals fetches the decimals property of the token from the blockchain.

func (*Token) ResolveName

func (t *Token) ResolveName(ctx context.Context, from common.Address, bind *bindings.Token) (string, error)

ResolveName fetches the name property of the token from the blockchain.

func (*Token) ResolveSymbol

func (t *Token) ResolveSymbol(ctx context.Context, from common.Address, bind *bindings.Token) (string, error)

ResolveSymbol fetches the symbol property of the token from the blockchain.

func (*Token) ResolveTotalSupply

func (t *Token) ResolveTotalSupply(ctx context.Context, from common.Address, bind *bindings.Token) (*big.Int, error)

ResolveTotalSupply fetches the total supply of the token from the blockchain.

func (*Token) SetInSimulation

func (t *Token) SetInSimulation(inSimulation bool)

SetInSimulation sets the simulation flag for the token.

func (*Token) Unpack

func (t *Token) Unpack(ctx context.Context, atBlock *big.Int) (*Descriptor, error)

Unpack resolves the token's details (name, symbol, decimals, total supply) at a specific block number.

Jump to

Keyboard shortcuts

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