wrappers

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

README

Wrappers

The wrapper package defines wrappers around Cosmos SDK modules required to handle coins with different representation of the decimals inside the x/evm module.

All wrapper implementations should be used only for transaction executions that involves the EVM. When a keeper is required as a dependency for another Cosmos SDK module, it should be used the original Keeper.

BankWrapper

This package contains the BankWrapper, a wrapper around the Cosmos SDK bank keeper that is designed to manage the EVM denomination with a custom decimal representation. The primary purpose of the BankWrapper is to handle conversions between Cosmos SDK's default decimal system and the 18-decimal representation commonly used in EVM-based systems.

Features

  • Balance Conversion: Automatically converts balances to 18 decimals, the standard for EVM coins.
  • Send and Receive Coins: Handles sending coins between accounts and modules, ensuring proper conversion to and from the 18-decimal system.
  • Mint and Burn Coins: Provides methods for minting and burning coins, with conversions applied as necessary.

Conversion Logic

The wrapper uses helper functions to convert between Cosmos SDK's bank module decimal representation and EVM's 18-decimal standard:

  • mustConvertEvmCoinTo18Decimals: Converts a coin to 18 decimals.
  • convertCoinsFrom18Decimals: Converts coins from 18 decimals to their original representation.

Both methods convert only the evm denom amount.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BankWrapper

type BankWrapper struct {
	types.BankKeeper
}

BankWrapper is a wrapper around the Cosmos SDK bank keeper that is used to manage an evm denom with a custom decimal representation.

func NewBankWrapper

func NewBankWrapper(
	bk types.BankKeeper,
) *BankWrapper

NewBankWrapper creates a new BankWrapper instance.

func (BankWrapper) BurnAmountFromAccount

func (w BankWrapper) BurnAmountFromAccount(ctx context.Context, account sdk.AccAddress, amt *big.Int) error

BurnAmountFromAccount converts the given amount into the evm coin scaling the amount to the original decimals, then burns that quantity from the provided account.

func (BankWrapper) GetBalance

func (w BankWrapper) GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin

GetBalance returns the balance of the given account.

func (BankWrapper) MintAmountToAccount

func (w BankWrapper) MintAmountToAccount(ctx context.Context, recipientAddr sdk.AccAddress, amt *big.Int) error

MintAmountToAccount converts the given amount into the evm coin scaling the amount to the original decimals, then mints that amount to the provided account.

func (BankWrapper) SendCoinsFromAccountToModule

func (w BankWrapper) SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, coins sdk.Coins) error

SendCoinsFromAccountToModule wraps around the Cosmos SDK x/bank module's SendCoinsFromAccountToModule method to convert the evm coin, if present in the input, to its original representation.

func (BankWrapper) SendCoinsFromModuleToAccount

func (w BankWrapper) SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, coins sdk.Coins) error

SendCoinsFromModuleToAccount wraps around the Cosmos SDK x/bank module's SendCoinsFromModuleToAccount method to convert the evm coin, if present in the input, to its original representation.

func (BankWrapper) SpendableCoin added in v0.3.0

func (w BankWrapper) SpendableCoin(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin

SpendableCoin returns the balance of the given account.

type FeeMarketWrapper

type FeeMarketWrapper struct {
	types.FeeMarketKeeper
}

FeeMarketWrapper is a wrapper around the feemarket keeper that is used to manage an evm denom with 6 or 18 decimals. The wrapper makes the corresponding conversions to achieve:

  • With the EVM, the wrapper works always with 18 decimals.
  • With the feemarket module, the wrapper works always with the bank module decimals (either 6 or 18).

func NewFeeMarketWrapper

func NewFeeMarketWrapper(
	fk types.FeeMarketKeeper,
) *FeeMarketWrapper

NewFeeMarketWrapper creates a new feemarket Keeper wrapper instance. The BankWrapper is used to manage an evm denom with 6 or 18 decimals.

func (FeeMarketWrapper) CalculateBaseFee

func (w FeeMarketWrapper) CalculateBaseFee(ctx sdk.Context) *big.Int

CalculateBaseFee returns the calculated base fee converted to 18 decimals.

func (FeeMarketWrapper) GetBaseFee

func (w FeeMarketWrapper) GetBaseFee(ctx sdk.Context) *big.Int

GetBaseFee returns the base fee converted to 18 decimals.

func (FeeMarketWrapper) GetParams

GetParams returns the params with associated fees values converted to 18 decimals.

Directories

Path Synopsis
Package testutil is a generated GoMock package.
Package testutil is a generated GoMock package.

Jump to

Keyboard shortcuts

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