erc20

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: LGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApproveMethodName  = "approve"
	ApprovalExpiration = time.Hour * 24 * 365 * time.Duration(100) // 100 years
)

ApproveMethodName is the name of the approve method that should match the name in the contract ABI.

View Source
const (
	NameMethodName     = "name"
	SymbolMethodName   = "symbol"
	DecimalsMethodName = "decimals"
)
View Source
const (
	PermitMethodName          = "permit"
	NonceMethodName           = "nonce"
	DomainSeparatorMethodName = "DOMAIN_SEPARATOR"
	PermitTypehashMethodName  = "PERMIT_TYPEHASH"
	PermitTypehash            = "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
)
View Source
const (
	TransferMethodName     = "transfer"
	TransferFromMethodName = "transferFrom"
)
View Source
const (
	AllowanceMethodName = "allowance"
)

AllowanceMethodName is the name of the Allowance method that should match the name in the contract ABI.

View Source
const ApprovalEventName = "Approval"

ApprovalEventName is the name of the Approval event. It matches the name of the event in the contract ABI.

View Source
const BalanceOfMethodName = "balanceOf"

BalanceOfMethodName is the name of the balanceOf method. It matches the name of the method in the contract ABI.

View Source
const TotalSupplyMethodName = "totalSupply"

TotalSupplyMethodName is the name of the totalSupply method. It matches the name of the method in the contract ABI.

View Source
const TransferEventName = "Transfer"

TransferEventName is the name of the Transfer event. It matches the name of the event in the contract ABI.

Variables

View Source
var SendMsgURL = sdk.MsgTypeURL(&banktypes.MsgSend{})

SendMsgURL defines the authorization type for MsgSend

Functions

func BuildDomainSeparator

func BuildDomainSeparator(
	chainID *big.Int,
	name string,
	version string,
	verifyingContract common.Address,
) ([]byte, error)

This functions implements the EIP712 domain separator for the permit function and produces the same result as the Solidity code seen e.g. in the OpenZeppelin lib https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/EIP712.sol#L89 that is used by tBTC token https://github.com/keep-network/tbtc-v2/blob/main/solidity/contracts/token/TBTC.sol#L8

Types

type AllowanceMethod

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

AllowanceMethod is a precompile method that allows users to check how much a spender is allowed to spend on behalf of an owner.

func NewAllowanceMethod

func NewAllowanceMethod(
	authzkeeper authzkeeper.Keeper,
	denom string,
) *AllowanceMethod

func (*AllowanceMethod) MethodName

func (am *AllowanceMethod) MethodName() string

func (*AllowanceMethod) MethodType

func (am *AllowanceMethod) MethodType() precompile.MethodType

func (*AllowanceMethod) Payable

func (am *AllowanceMethod) Payable() bool

func (*AllowanceMethod) RequiredGas

func (am *AllowanceMethod) RequiredGas(_ []byte) (uint64, bool)

func (*AllowanceMethod) Run

Run returns the allowance of the spender for the owner.

type ApprovalEvent

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

ApprovalEvent is the implementation of the Approval event that contains the following arguments: - owner (indexed): the address of ERC20 owner, - to (indexed): the address of spender, - amount (non-indexed): the amount of tokens approved.

func NewApprovalEvent

func NewApprovalEvent(from, to common.Address, amount *big.Int) *ApprovalEvent

func (*ApprovalEvent) Arguments

func (ae *ApprovalEvent) Arguments() []*precompile.EventArgument

func (*ApprovalEvent) EventName

func (ae *ApprovalEvent) EventName() string

type ApproveMethod

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

Sets a `value` amount of tokens as the allowance of `spender` over the caller's tokens.

func NewApproveMethod

func NewApproveMethod(
	bankKeeper bankkeeper.Keeper,
	authzkeeper authzkeeper.Keeper,
	denom string,
) *ApproveMethod

func (*ApproveMethod) MethodName

func (am *ApproveMethod) MethodName() string

func (*ApproveMethod) MethodType

func (am *ApproveMethod) MethodType() precompile.MethodType

func (*ApproveMethod) Payable

func (am *ApproveMethod) Payable() bool

func (*ApproveMethod) RequiredGas

func (am *ApproveMethod) RequiredGas(_ []byte) (uint64, bool)

func (*ApproveMethod) Run

Approve sets the given amount as the allowance of the spender address over the ERC20 token. It returns a boolean value when the operation succeeded.

The Approve method handles the following cases: 1. no authorization, amount 0 -> return error 2. no authorization, amount positive -> create a new authorization 3. authorization exists, amount 0 -> delete authorization 4. authorization exists, amount positive -> update authorization

type BalanceOfMethod

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

BalanceOfMethod is the implementation of the balanceOf method that returns the balance of the ERC20 token for the given account.

The method has the following input arguments: - account: the EVM address of the account for which the balance is returned.

The method returns the ERC20 balance of the account (in the token's precision) if everything goes well. Otherwise, it returns nil and an error.

func NewBalanceOfMethod

func NewBalanceOfMethod(
	bankKeeper bankkeeper.Keeper,
	denom string,
) *BalanceOfMethod

func (*BalanceOfMethod) MethodName

func (bom *BalanceOfMethod) MethodName() string

func (*BalanceOfMethod) MethodType

func (bom *BalanceOfMethod) MethodType() precompile.MethodType

func (*BalanceOfMethod) Payable

func (bom *BalanceOfMethod) Payable() bool

func (*BalanceOfMethod) RequiredGas

func (bom *BalanceOfMethod) RequiredGas(_ []byte) (uint64, bool)

func (*BalanceOfMethod) Run

type DecimalsMethod

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

func NewDecimalsMethod

func NewDecimalsMethod(decimals uint8) *DecimalsMethod

Decimals method returns the number of decimals used to represent the token.

func (*DecimalsMethod) MethodName

func (dm *DecimalsMethod) MethodName() string

func (*DecimalsMethod) MethodType

func (dm *DecimalsMethod) MethodType() precompile.MethodType

func (*DecimalsMethod) Payable

func (dm *DecimalsMethod) Payable() bool

func (*DecimalsMethod) RequiredGas

func (dm *DecimalsMethod) RequiredGas(_ []byte) (uint64, bool)

func (*DecimalsMethod) Run

type DomainSeparatorMethod

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

func NewDomainSeparatorMethod

func NewDomainSeparatorMethod(
	domainSeparator []byte,
) *DomainSeparatorMethod

func (*DomainSeparatorMethod) MethodName

func (dsm *DomainSeparatorMethod) MethodName() string

func (*DomainSeparatorMethod) MethodType

func (dsm *DomainSeparatorMethod) MethodType() precompile.MethodType

func (*DomainSeparatorMethod) Payable

func (dsm *DomainSeparatorMethod) Payable() bool

func (*DomainSeparatorMethod) RequiredGas

func (dsm *DomainSeparatorMethod) RequiredGas(_ []byte) (uint64, bool)

func (*DomainSeparatorMethod) Run

Returns the domain separator.

type NameMethod

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

func NewNameMethod

func NewNameMethod(name string) *NameMethod

Name method returns the name of the token.

func (*NameMethod) MethodName

func (nm *NameMethod) MethodName() string

func (*NameMethod) MethodType

func (nm *NameMethod) MethodType() precompile.MethodType

func (*NameMethod) Payable

func (nm *NameMethod) Payable() bool

func (*NameMethod) RequiredGas

func (nm *NameMethod) RequiredGas(_ []byte) (uint64, bool)

func (*NameMethod) Run

type NonceMethod

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

func NewNonceMethod

func NewNonceMethod(
	evmkeeper evmkeeper.Keeper,
	nonceKey []byte,
) *NonceMethod

func (*NonceMethod) MethodName

func (nm *NonceMethod) MethodName() string

func (*NonceMethod) MethodType

func (nm *NonceMethod) MethodType() precompile.MethodType

func (*NonceMethod) Payable

func (nm *NonceMethod) Payable() bool

func (*NonceMethod) RequiredGas

func (nm *NonceMethod) RequiredGas(_ []byte) (uint64, bool)

func (*NonceMethod) Run

Returns the nonce of the given account.

type PermitMethod

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

PermitMethod is a precompile method that allows users to approve a spender to spend their tokens with a signature.

func NewPermitMethod

func NewPermitMethod(
	bankKeeper bankkeeper.Keeper,
	authzkeeper authzkeeper.Keeper,
	evmkeeper evmkeeper.Keeper,
	denom string,
	domainSeparator []byte,
	nonceKey []byte,
) *PermitMethod

func (*PermitMethod) MethodName

func (am *PermitMethod) MethodName() string

func (*PermitMethod) MethodType

func (am *PermitMethod) MethodType() precompile.MethodType

func (*PermitMethod) Payable

func (am *PermitMethod) Payable() bool

func (*PermitMethod) RequiredGas

func (am *PermitMethod) RequiredGas(_ []byte) (uint64, bool)

func (*PermitMethod) Run

EIP2612 approval made with secp256k1 signature. Users can authorize a transfer of their tokens with a signature conforming EIP712 standard, rather than an on-chain transaction from their address. Anyone can submit this signature on the user's behalf by calling the permit function, paying gas fees, and possibly performing other actions in the same transaction.

type PermitTypehashMethod

type PermitTypehashMethod struct{}

func NewPermitTypehashMethod

func NewPermitTypehashMethod() *PermitTypehashMethod

func (*PermitTypehashMethod) MethodName

func (ptm *PermitTypehashMethod) MethodName() string

func (*PermitTypehashMethod) MethodType

func (ptm *PermitTypehashMethod) MethodType() precompile.MethodType

func (*PermitTypehashMethod) Payable

func (ptm *PermitTypehashMethod) Payable() bool

func (*PermitTypehashMethod) RequiredGas

func (ptm *PermitTypehashMethod) RequiredGas(_ []byte) (uint64, bool)

func (*PermitTypehashMethod) Run

Returns the permit typehash.

type SymbolMethod

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

func NewSymbolMethod

func NewSymbolMethod(symbol string) *SymbolMethod

Symbol method returns the symbol of the token.

func (*SymbolMethod) MethodName

func (sm *SymbolMethod) MethodName() string

func (*SymbolMethod) MethodType

func (sm *SymbolMethod) MethodType() precompile.MethodType

func (*SymbolMethod) Payable

func (sm *SymbolMethod) Payable() bool

func (*SymbolMethod) RequiredGas

func (sm *SymbolMethod) RequiredGas(_ []byte) (uint64, bool)

func (*SymbolMethod) Run

type TotalSupplyMethod

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

TotalSupplyMethod is the implementation of the totalSupply method that returns the total supply of the ERC20 tokens in existence.

func NewTotalSupplyMethod

func NewTotalSupplyMethod(
	bankKeeper bankkeeper.Keeper,
	denom string,
) *TotalSupplyMethod

func (*TotalSupplyMethod) MethodName

func (tsm *TotalSupplyMethod) MethodName() string

func (*TotalSupplyMethod) MethodType

func (tsm *TotalSupplyMethod) MethodType() precompile.MethodType

func (*TotalSupplyMethod) Payable

func (tsm *TotalSupplyMethod) Payable() bool

func (*TotalSupplyMethod) RequiredGas

func (tsm *TotalSupplyMethod) RequiredGas(_ []byte) (uint64, bool)

func (*TotalSupplyMethod) Run

type TransferEvent

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

transferEvent is the implementation of the Transfer event that contains the following arguments: - from (indexed): the address from which the tokens are transferred, - to (indexed): the address to which the tokens are transferred, - value (non-indexed): the amount of tokens transferred.

func NewTransferEvent

func NewTransferEvent(from, to common.Address, value *big.Int) *TransferEvent

func (*TransferEvent) Arguments

func (te *TransferEvent) Arguments() []*precompile.EventArgument

func (*TransferEvent) EventName

func (te *TransferEvent) EventName() string

type TransferFromMethod

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

TransferFromMethod is a precompile method that allows users to pull tokens from an account using the allowance mechanism.

func NewTransferFromMethod

func NewTransferFromMethod(
	bankKeeper bankkeeper.Keeper,
	authzkeeper authzkeeper.Keeper,
	evmKeeper evmkeeper.Keeper,
	denom string,
) *TransferFromMethod

func (*TransferFromMethod) MethodName

func (tfm *TransferFromMethod) MethodName() string

func (*TransferFromMethod) MethodType

func (tfm *TransferFromMethod) MethodType() precompile.MethodType

func (*TransferFromMethod) Payable

func (tfm *TransferFromMethod) Payable() bool

func (*TransferFromMethod) RequiredGas

func (tfm *TransferFromMethod) RequiredGas(_ []byte) (uint64, bool)

func (*TransferFromMethod) Run

type TransferMethod

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

TransferMethod is a precompile method that allows users to transfer tokens from their account to another account.

func NewTransferMethod

func NewTransferMethod(
	bankKeeper bankkeeper.Keeper,
	authzkeeper authzkeeper.Keeper,
	evmKeeper evmkeeper.Keeper,
	denom string,
) *TransferMethod

func (*TransferMethod) MethodName

func (tm *TransferMethod) MethodName() string

func (*TransferMethod) MethodType

func (tm *TransferMethod) MethodType() precompile.MethodType

func (*TransferMethod) Payable

func (tm *TransferMethod) Payable() bool

func (*TransferMethod) RequiredGas

func (tm *TransferMethod) RequiredGas(_ []byte) (uint64, bool)

func (*TransferMethod) Run

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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