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 ¶
- type Descriptor
- func (d *Descriptor) GetAddress() common.Address
- func (d *Descriptor) GetDecimals() uint8
- func (d *Descriptor) GetEntity() *entities.Token
- func (d *Descriptor) GetName() string
- func (d *Descriptor) GetSymbol() string
- func (d *Descriptor) GetTotalBurnedSupply() *big.Int
- func (d *Descriptor) GetTotalCirculatingSupply() *big.Int
- func (d *Descriptor) GetTotalSupply() *big.Int
- type Token
- func (t *Token) CalculateTotalBurnedSupply(ctx context.Context) error
- func (t *Token) GetBind() *bindings.Token
- func (t *Token) GetBindManager() *bindings.Manager
- func (t *Token) GetBinding() *bindings.Token
- func (t *Token) GetClient() (*clients.Client, error)
- func (t *Token) GetClientPool() *clients.ClientPool
- func (t *Token) GetContext() context.Context
- func (t *Token) GetDescriptor() *Descriptor
- func (t *Token) GetEntity() *entities.Token
- func (t *Token) GetNetwork() utils.Network
- func (t *Token) GetNetworkID() utils.NetworkID
- func (t *Token) GetSimulatorType() utils.SimulatorType
- func (t *Token) GetTokenBind(ctx context.Context, bindManager *bindings.Manager) (*bindings.Token, error)
- func (t *Token) IsInSimulation() bool
- func (t *Token) PrepareBindings(ctx context.Context) error
- func (t *Token) ResolveBalance(ctx context.Context, from common.Address, bind *bindings.Token, ...) (*big.Int, error)
- func (t *Token) ResolveDecimals(ctx context.Context, from common.Address, bind *bindings.Token) (uint8, error)
- func (t *Token) ResolveName(ctx context.Context, from common.Address, bind *bindings.Token) (string, error)
- func (t *Token) ResolveSymbol(ctx context.Context, from common.Address, bind *bindings.Token) (string, error)
- func (t *Token) ResolveTotalSupply(ctx context.Context, from common.Address, bind *bindings.Token) (*big.Int, error)
- func (t *Token) SetInSimulation(inSimulation bool)
- func (t *Token) Unpack(ctx context.Context, atBlock *big.Int) (*Descriptor, error)
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 ¶
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) GetBindManager ¶
GetBindManager returns the contract binding manager associated with the Token.
func (*Token) GetBinding ¶
func (*Token) GetClientPool ¶
func (t *Token) GetClientPool() *clients.ClientPool
GetClientPool returns the pool of Ethereum network clients.
func (*Token) GetContext ¶
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) GetNetwork ¶
GetNetwork returns the blockchain network the token is associated with.
func (*Token) GetNetworkID ¶
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 ¶
IsInSimulation returns true if the token is currently being simulated.
func (*Token) PrepareBindings ¶
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 ¶
SetInSimulation sets the simulation flag for the token.