keeper

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2025 License: Apache-2.0 Imports: 39 Imported by: 24

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Keeper

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

Keeper of this module maintains collections of erc20.

func NewKeeper

func NewKeeper(
	storeKey storetypes.StoreKey,
	cdc codec.BinaryCodec,
	authority sdk.AccAddress,
	ak types.AccountKeeper,
	bk bankkeeper.Keeper,
	evmKeeper types.EVMKeeper,
	sk types.StakingKeeper,
	authzKeeper authzkeeper.Keeper,
	transferKeeper *transferkeeper.Keeper,
) Keeper

NewKeeper creates new instances of the erc20 Keeper

func (Keeper) BalanceOf

func (k Keeper) BalanceOf(
	ctx sdk.Context,
	abi abi.ABI,
	contract, account common.Address,
) *big.Int

BalanceOf queries an account's balance for a given ERC20 contract

func (Keeper) ConvertCoinNativeERC20

func (k Keeper) ConvertCoinNativeERC20(
	ctx sdk.Context,
	pair types.TokenPair,
	amount math.Int,
	receiver common.Address,
	sender sdk.AccAddress,
) error

ConvertCoinNativeERC20 handles the coin conversion for a native ERC20 token pair:

  • escrow Coins on module account
  • unescrow Tokens that have been previously escrowed with ConvertERC20 and send to receiver
  • burn escrowed Coins
  • check if token balance increased by amount
  • check for unexpected `Approval` event in logs

func (Keeper) ConvertCoinToERC20FromPacket

func (k Keeper) ConvertCoinToERC20FromPacket(ctx sdk.Context, data transfertypes.FungibleTokenPacketData) error

ConvertCoinToERC20FromPacket converts the IBC coin to ERC20 after refunding the sender This function is only executed when IBC timeout or an Error ACK happens.

func (Keeper) ConvertERC20

func (k Keeper) ConvertERC20(
	goCtx context.Context,
	msg *types.MsgConvertERC20,
) (*types.MsgConvertERC20Response, error)

ConvertERC20 converts ERC20 tokens into native Cosmos coins for both Cosmos-native and ERC20 TokenPair Owners

func (Keeper) CreateCoinMetadata

func (k Keeper) CreateCoinMetadata(
	ctx sdk.Context,
	contract common.Address,
) (*banktypes.Metadata, error)

CreateCoinMetadata generates the metadata to represent the ERC20 token on evmos.

func (*Keeper) CreateNewTokenPair

func (k *Keeper) CreateNewTokenPair(ctx sdk.Context, denom string) (types.TokenPair, error)

CreateNewTokenPair creates a new token pair and stores it in the state.

func (Keeper) DeleteTokenPair

func (k Keeper) DeleteTokenPair(ctx sdk.Context, tokenPair types.TokenPair)

DeleteTokenPair removes a token pair.

func (Keeper) DeployERC20Contract

func (k Keeper) DeployERC20Contract(
	ctx sdk.Context,
	coinMetadata banktypes.Metadata,
) (common.Address, error)

DeployERC20Contract creates and deploys an ERC20 contract on the EVM with the erc20 module account as owner.

func (Keeper) EnableDynamicPrecompiles

func (k Keeper) EnableDynamicPrecompiles(ctx sdk.Context, addresses ...common.Address) error

EnableDynamicPrecompiles appends the addresses of the given Precompiles to the list of active dynamic precompiles.

func (Keeper) GetCoinAddress

func (k Keeper) GetCoinAddress(ctx sdk.Context, denom string) (common.Address, error)

GetCoinAddress returns the corresponding ERC-20 contract address for the given denom. If the denom is not registered and its an IBC voucher, it returns the address from the hash of the ICS20's DenomTrace Path.

func (Keeper) GetDenomMap

func (k Keeper) GetDenomMap(ctx sdk.Context, denom string) []byte

GetDenomMap returns the token pair id for the given denomination.

func (Keeper) GetERC20Map

func (k Keeper) GetERC20Map(ctx sdk.Context, erc20 common.Address) []byte

GetERC20Map returns the token pair id for the given address.

func (Keeper) GetERC20PrecompileInstance

func (k Keeper) GetERC20PrecompileInstance(
	ctx sdk.Context,
	address common.Address,
) (contract vm.PrecompiledContract, found bool, err error)

GetERC20PrecompileInstance returns the precompile instance for the given address.

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) (params types.Params)

GetParams returns the total set of erc20 parameters.

func (Keeper) GetTokenDenom

func (k Keeper) GetTokenDenom(ctx sdk.Context, tokenAddress common.Address) (string, error)

GetTokenDenom returns the denom associated with the tokenAddress or an error if the TokenPair does not exist.

func (Keeper) GetTokenPair

func (k Keeper) GetTokenPair(ctx sdk.Context, id []byte) (types.TokenPair, bool)

GetTokenPair gets a registered token pair from the identifier.

func (Keeper) GetTokenPairID

func (k Keeper) GetTokenPairID(ctx sdk.Context, token string) []byte

GetTokenPairID returns the pair id for the specified token. Hex address or Denom can be used as token argument. If the token is not registered empty bytes are returned.

func (Keeper) GetTokenPairs

func (k Keeper) GetTokenPairs(ctx sdk.Context) []types.TokenPair

GetTokenPairs gets all registered token tokenPairs.

func (Keeper) InstantiateERC20Precompile

func (k Keeper) InstantiateERC20Precompile(ctx sdk.Context, contractAddr common.Address, hasWrappedMethods bool) (vm.PrecompiledContract, error)

InstantiateERC20Precompile returns an ERC20 precompile instance for the given contract address. If the `hasWrappedMethods` boolean is true, the ERC20 instance returned exposes methods for `withdraw` and `deposit` as it is common for wrapped tokens.

func (Keeper) IsAvailableERC20Precompile

func (k Keeper) IsAvailableERC20Precompile(params *types.Params, address common.Address) bool

IsAvailableERC20Precompile returns true if the given precompile address is contained in the params of the erc20 module. The available ERC-20 precompiles consist of the dynamic precompiles and the native ones.

func (Keeper) IsDenomRegistered

func (k Keeper) IsDenomRegistered(ctx sdk.Context, denom string) bool

IsDenomRegistered check if registered coin denom is registered.

func (Keeper) IsERC20Enabled

func (k Keeper) IsERC20Enabled(ctx sdk.Context) bool

IsERC20Enabled returns true if the module logic is enabled

func (Keeper) IsERC20Registered

func (k Keeper) IsERC20Registered(ctx sdk.Context, erc20 common.Address) bool

IsERC20Registered check if registered ERC20 token is registered.

func (Keeper) IsTokenPairRegistered

func (k Keeper) IsTokenPairRegistered(ctx sdk.Context, id []byte) bool

IsTokenPairRegistered - check if registered token tokenPair is registered.

func (Keeper) IterateTokenPairs

func (k Keeper) IterateTokenPairs(ctx sdk.Context, cb func(tokenPair types.TokenPair) (stop bool))

IterateTokenPairs iterates over all the stored token pairs.

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

Logger returns a module-specific logger.

func (Keeper) MintingEnabled

func (k Keeper) MintingEnabled(
	ctx sdk.Context,
	sender, receiver sdk.AccAddress,
	token string,
) (types.TokenPair, error)

MintingEnabled checks that:

  • the global parameter for erc20 conversion is enabled
  • minting is enabled for the given (erc20,coin) token pair
  • recipient address is not on the blocked list
  • bank module transfers are enabled for the Cosmos coin

func (Keeper) OnAcknowledgementPacket

OnAcknowledgementPacket responds to the success or failure of a packet acknowledgement written on the receiving chain. If the acknowledgement was a success then nothing occurs. If the acknowledgement failed, then the sender is refunded and then the IBC Coins are converted to ERC20.

func (Keeper) OnRecvPacket

OnRecvPacket performs the ICS20 middleware receive callback for automatically converting an IBC Coin to their ERC20 representation. For the conversion to succeed, the IBC denomination must have previously been registered via governance. Note that the native staking denomination (e.g. "aatom"), is excluded from the conversion.

CONTRACT: This middleware MUST be executed transfer after the ICS20 OnRecvPacket Return acknowledgement and continue with the next layer of the IBC middleware stack if: - ERC20s are disabled - Denomination is native staking token - The base denomination is not registered as ERC20

func (Keeper) OnTimeoutPacket

OnTimeoutPacket converts the IBC coin to ERC20 after refunding the sender since the original packet sent was never received and has been timed out.

func (Keeper) Params

Params returns the params of the erc20 module

func (Keeper) QueryERC20

func (k Keeper) QueryERC20(
	ctx sdk.Context,
	contract common.Address,
) (types.ERC20Data, error)

QueryERC20 returns the data of a deployed ERC20 contract

func (*Keeper) RegisterERC20

func (k *Keeper) RegisterERC20(goCtx context.Context, req *types.MsgRegisterERC20) (*types.MsgRegisterERC20Response, error)

RegisterERC20 implements the gRPC MsgServer interface. After a successful governance vote it updates creates the token pair for an ERC20 contract if the requested authority is the Cosmos SDK governance module account

func (Keeper) RegisterERC20CodeHash

func (k Keeper) RegisterERC20CodeHash(ctx sdk.Context, erc20Addr common.Address) error

RegisterERC20CodeHash sets the codehash for the erc20 precompile account if the bytecode for the erc20 codehash does not exists, it stores it.

func (Keeper) RegisterERC20Extension

func (k Keeper) RegisterERC20Extension(ctx sdk.Context, denom string) (*types.TokenPair, error)

RegisterERC20Extension creates and adds an ERC20 precompile interface for an IBC Coin.

It derives the ERC-20 address from the token denomination and registers the EVM extension as an active dynamic precompile.

CONTRACT: This must ONLY be called if there is no existing token pair for the given denom.

func (Keeper) RegisterOrUnregisterERC20CodeHashes

func (k Keeper) RegisterOrUnregisterERC20CodeHashes(ctx sdk.Context, oldPrecompiles, newPrecompiles []string) error

RegisterOrUnregisterERC20CodeHashes takes two arrays of precompiles as its argument:

  • previously registered precompiles
  • new set of precompiles to be registered

It then compares the two arrays and registers the code hash for all precompiles that are newly added and unregisters the code hash for all precompiles that are removed from the list.

func (Keeper) SetDenomMap

func (k Keeper) SetDenomMap(ctx sdk.Context, denom string, id []byte)

SetDenomMap sets the token pair id for the denomination.

func (Keeper) SetERC20Map

func (k Keeper) SetERC20Map(ctx sdk.Context, erc20 common.Address, id []byte)

SetERC20Map sets the token pair id for the given address.

func (Keeper) SetParams

func (k Keeper) SetParams(ctx sdk.Context, newParams types.Params) error

SetParams sets the erc20 parameters to the param space.

func (*Keeper) SetToken

func (k *Keeper) SetToken(ctx sdk.Context, pair types.TokenPair)

SetToken stores a token pair, denom map and erc20 map.

func (Keeper) SetTokenPair

func (k Keeper) SetTokenPair(ctx sdk.Context, tokenPair types.TokenPair)

SetTokenPair stores a token pair.

func (*Keeper) ToggleConversion

ToggleConversion implements the gRPC MsgServer interface.

After a successful governance vote it adjusts the possibility of converting tokens between their conversions according to the outcome of the vote.

func (Keeper) TokenPair

TokenPair returns a given registered token pair

func (Keeper) TokenPairs

TokenPairs returns all registered pairs

func (Keeper) UnRegisterERC20CodeHash

func (k Keeper) UnRegisterERC20CodeHash(ctx sdk.Context, erc20Addr common.Address) error

UnRegisterERC20CodeHash sets the codehash for the account to an empty one

func (Keeper) UpdateCodeHash

func (k Keeper) UpdateCodeHash(ctx sdk.Context, newParams types.Params) error

UpdateCodeHash takes in the updated parameters and compares the new set of native and dynamic precompiles to the current parameter set.

If there is a diff, the ERC-20 code hash for all precompiles that are removed from the list will be removed from the store. Meanwhile, for all newly added precompiles the code hash will be registered.

func (*Keeper) UpdateParams

func (k *Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error)

UpdateParams implements the gRPC MsgServer interface. After a successful governance vote it updates the parameters in the keeper only if the requested authority is the Cosmos SDK governance module account

Jump to

Keyboard shortcuts

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