werc20

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EventTypeDeposit is the key of the event type for the Deposit transaction.
	EventTypeDeposit = "Deposit"
	// EventTypeWithdrawal is the key of the event type for the Withdraw transaction.
	EventTypeWithdrawal = "Withdrawal"
)
View Source
const (
	// DepositMethod defines the ABI method name for the IWERC20 deposit
	// transaction.
	DepositMethod = "deposit"
	// WithdrawMethod defines the ABI method name for the IWERC20 withdraw
	// transaction.
	WithdrawMethod = "withdraw"
)
View Source
const (
	// DepositRequiredGas defines the gas required for the Deposit transaction.
	DepositRequiredGas uint64 = 23_878
	// WithdrawRequiredGas defines the gas required for the Withdraw transaction.
	WithdrawRequiredGas uint64 = 9207
)

Variables

This section is empty.

Functions

func LoadABI

func LoadABI() (abi.ABI, error)

LoadABI loads the IWERC20 ABI from the embedded abi.json file for the werc20 precompile.

Types

type Erc20Keeper added in v0.2.0

type Erc20Keeper interface {
	GetAllowance(ctx sdk.Context, erc20 common.Address, owner common.Address, spender common.Address) (*big.Int, error)
	SetAllowance(ctx sdk.Context, erc20 common.Address, owner common.Address, spender common.Address, value *big.Int) error
	DeleteAllowance(ctx sdk.Context, erc20 common.Address, owner common.Address, spender common.Address) error
}

type Precompile

type Precompile struct {
	*erc20.Precompile
}

Precompile defines the precompiled contract for WERC20.

func NewPrecompile

func NewPrecompile(
	tokenPair erc20types.TokenPair,
	bankKeeper cmn.BankKeeper,
	erc20Keeper Erc20Keeper,
	transferKeeper transferkeeper.Keeper,
) (*Precompile, error)

NewPrecompile creates a new WERC20 Precompile instance implementing the PrecompiledContract interface. This type wraps around the ERC20 Precompile instance to provide additional methods.

func (Precompile) Address

func (p Precompile) Address() common.Address

Address returns the address of the WERC20 precompiled contract.

func (Precompile) Deposit

func (p Precompile) Deposit(
	ctx sdk.Context,
	contract *vm.Contract,
	stateDB vm.StateDB,
) ([]byte, error)

Deposit handles the payable deposit function. It retrieves the deposited amount and sends it back to the sender using the bank keeper.

func (Precompile) EmitDepositEvent

func (p Precompile) EmitDepositEvent(
	ctx sdk.Context,
	stateDB vm.StateDB,
	caller common.Address,
	amount *big.Int,
) error

EmitDepositEvent creates a new Deposit event emitted after a Deposit transaction.

func (Precompile) EmitWithdrawalEvent

func (p Precompile) EmitWithdrawalEvent(
	ctx sdk.Context,
	stateDB vm.StateDB,
	src common.Address,
	amount *big.Int,
) error

EmitWithdrawalEvent creates a new Withdrawal event emitted after a Withdraw transaction.

func (Precompile) IsTransaction

func (p Precompile) IsTransaction(method *abi.Method) bool

IsTransaction returns true if the given method name correspond to a transaction. Returns false otherwise.

func (Precompile) RequiredGas

func (p Precompile) RequiredGas(input []byte) uint64

RequiredGas calculates the contract gas use.

func (Precompile) Run

func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz []byte, err error)

Run executes the precompiled contract WERC20 methods defined in the ABI.

func (Precompile) Withdraw

func (p Precompile) Withdraw(ctx sdk.Context, contract *vm.Contract, stateDB vm.StateDB, args []interface{}) ([]byte, error)

Withdraw is a no-op and mock function that provides the same interface as the WETH contract to support equality between the native coin and its wrapped ERC-20 (e.g. ATOM and WEVMOS).

Jump to

Keyboard shortcuts

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