Documentation
¶
Index ¶
- type Keeper
- func (k Keeper) BalanceOf(ctx sdk.Context, abi abi.ABI, contract, account common.Address) *big.Int
- func (k Keeper) ConvertCoin(goCtx context.Context, msg *types.MsgConvertCoin) (*types.MsgConvertCoinResponse, error)
- func (k Keeper) ConvertCoinNativeERC20(ctx sdk.Context, pair types.TokenPair, amount math.Int, ...) error
- func (k Keeper) ConvertCoinToERC20FromPacket(ctx sdk.Context, data transfertypes.FungibleTokenPacketData) error
- func (k Keeper) ConvertERC20(goCtx context.Context, msg *types.MsgConvertERC20) (*types.MsgConvertERC20Response, error)
- func (k Keeper) CreateCoinMetadata(ctx sdk.Context, contract common.Address) (*banktypes.Metadata, error)
- func (k Keeper) CreateNewTokenPair(ctx sdk.Context, denom string) (types.TokenPair, error)
- func (k Keeper) DeleteAllowance(ctx sdk.Context, erc20 common.Address, owner common.Address, ...) error
- func (k Keeper) DeleteDynamicPrecompile(ctx sdk.Context, precompile common.Address)
- func (k Keeper) DeleteNativePrecompile(ctx sdk.Context, precompile common.Address)
- func (k Keeper) DeleteTokenPair(ctx sdk.Context, tokenPair types.TokenPair)
- func (k Keeper) DeployERC20Contract(ctx sdk.Context, coinMetadata banktypes.Metadata) (common.Address, error)
- func (k Keeper) EnableDynamicPrecompile(ctx sdk.Context, address common.Address) error
- func (k Keeper) EnableNativePrecompile(ctx sdk.Context, addr common.Address) error
- func (k Keeper) GetAllowance(ctx sdk.Context, erc20 common.Address, owner common.Address, ...) (*big.Int, error)
- func (k Keeper) GetAllowances(ctx sdk.Context) []types.Allowance
- func (k Keeper) GetCoinAddress(ctx sdk.Context, denom string) (common.Address, error)
- func (k Keeper) GetDenomMap(ctx sdk.Context, denom string) []byte
- func (k Keeper) GetDynamicPrecompiles(ctx sdk.Context) []string
- func (k Keeper) GetERC20Map(ctx sdk.Context, erc20 common.Address) []byte
- func (k Keeper) GetERC20PrecompileInstance(ctx sdk.Context, address common.Address) (contract vm.PrecompiledContract, found bool, err error)
- func (k Keeper) GetNativePrecompiles(ctx sdk.Context) []string
- func (k Keeper) GetParams(ctx sdk.Context) (params types.Params)
- func (k Keeper) GetTokenDenom(ctx sdk.Context, tokenAddress common.Address) (string, error)
- func (k Keeper) GetTokenPair(ctx sdk.Context, id []byte) (types.TokenPair, bool)
- func (k Keeper) GetTokenPairID(ctx sdk.Context, token string) []byte
- func (k Keeper) GetTokenPairs(ctx sdk.Context) []types.TokenPair
- func (k Keeper) InstantiateERC20Precompile(ctx sdk.Context, contractAddr common.Address, hasWrappedMethods bool) (vm.PrecompiledContract, error)
- func (k Keeper) IsDenomRegistered(ctx sdk.Context, denom string) bool
- func (k Keeper) IsDynamicPrecompileAvailable(ctx sdk.Context, precompile common.Address) bool
- func (k Keeper) IsERC20Enabled(ctx sdk.Context) bool
- func (k Keeper) IsERC20Registered(ctx sdk.Context, erc20 common.Address) bool
- func (k Keeper) IsNativePrecompileAvailable(ctx sdk.Context, precompile common.Address) bool
- func (k Keeper) IsTokenPairRegistered(ctx sdk.Context, id []byte) bool
- func (k Keeper) IterateAllowances(ctx sdk.Context, cb func(allowance types.Allowance) (stop bool))
- func (k Keeper) IterateTokenPairs(ctx sdk.Context, cb func(tokenPair types.TokenPair) (stop bool))
- func (k Keeper) Logger(ctx sdk.Context) log.Logger
- func (k Keeper) MintingEnabled(ctx sdk.Context, sender, receiver sdk.AccAddress, token string) (types.TokenPair, error)
- func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, _ channeltypes.Packet, ...) error
- func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, ack exported.Acknowledgement) exported.Acknowledgement
- func (k Keeper) OnTimeoutPacket(ctx sdk.Context, _ channeltypes.Packet, ...) error
- func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error)
- func (k Keeper) QueryERC20(ctx sdk.Context, contract common.Address) (types.ERC20Data, error)
- func (k Keeper) RegisterCodeHash(ctx sdk.Context, addr common.Address, pType PrecompileType) error
- func (k *Keeper) RegisterERC20(goCtx context.Context, req *types.MsgRegisterERC20) (*types.MsgRegisterERC20Response, error)
- func (k Keeper) RegisterERC20CodeHash(ctx sdk.Context, erc20Addr common.Address) error
- func (k Keeper) RegisterERC20Extension(ctx sdk.Context, denom string) (*types.TokenPair, error)
- func (k Keeper) SetAllowance(ctx sdk.Context, erc20 common.Address, owner common.Address, ...) error
- func (k Keeper) SetDenomMap(ctx sdk.Context, denom string, id []byte)
- func (k Keeper) SetDynamicPrecompile(ctx sdk.Context, precompile common.Address)
- func (k Keeper) SetERC20Map(ctx sdk.Context, erc20 common.Address, id []byte)
- func (k Keeper) SetNativePrecompile(ctx sdk.Context, precompile common.Address)
- func (k Keeper) SetParams(ctx sdk.Context, newParams types.Params) error
- func (k Keeper) SetPermissionlessRegistration(ctx sdk.Context, permissionlessRegistration bool)
- func (k *Keeper) SetToken(ctx sdk.Context, pair types.TokenPair) error
- func (k Keeper) SetTokenPair(ctx sdk.Context, tokenPair types.TokenPair)
- func (k *Keeper) ToggleConversion(goCtx context.Context, req *types.MsgToggleConversion) (*types.MsgToggleConversionResponse, error)
- func (k Keeper) TokenPair(c context.Context, req *types.QueryTokenPairRequest) (*types.QueryTokenPairResponse, error)
- func (k Keeper) TokenPairs(c context.Context, req *types.QueryTokenPairsRequest) (*types.QueryTokenPairsResponse, error)
- func (k Keeper) UnRegisterERC20CodeHash(ctx sdk.Context, erc20Addr common.Address) error
- func (k Keeper) UnsafeSetAllowance(ctx sdk.Context, erc20 common.Address, owner common.Address, ...) error
- func (k *Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error)
- type PrecompileType
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 types.BankKeeper, evmKeeper types.EVMKeeper, sk types.StakingKeeper, 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) ConvertCoin ¶ added in v0.2.0
func (k Keeper) ConvertCoin( goCtx context.Context, msg *types.MsgConvertCoin, ) (*types.MsgConvertCoinResponse, error)
ConvertCoin converts native Cosmos coins into ERC20 tokens for both Cosmos-native and ERC20 TokenPair Owners
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 ¶
CreateNewTokenPair creates a new token pair and stores it in the state.
func (Keeper) DeleteAllowance ¶ added in v0.2.0
func (k Keeper) DeleteAllowance( ctx sdk.Context, erc20 common.Address, owner common.Address, spender common.Address, ) error
DeleteAllowance deletes the allowance of the given owner and spender on the given erc20 precompile address.
func (Keeper) DeleteDynamicPrecompile ¶ added in v0.3.0
func (Keeper) DeleteNativePrecompile ¶ added in v0.3.0
func (Keeper) DeleteTokenPair ¶
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) EnableDynamicPrecompile ¶ added in v0.3.0
EnableDynamicPrecompile adds the address of the given precompile to the prefix store
func (Keeper) EnableNativePrecompile ¶ added in v0.3.0
EnableNativePrecompile adds the address of the given precompile to the prefix store
func (Keeper) GetAllowance ¶ added in v0.2.0
func (k Keeper) GetAllowance( ctx sdk.Context, erc20 common.Address, owner common.Address, spender common.Address, ) (*big.Int, error)
GetAllowance returns the allowance of the given owner and spender on the given erc20 precompile address.
func (Keeper) GetAllowances ¶ added in v0.2.0
GetAllowances returns all allowances stored on the given erc20 precompile address.
func (Keeper) GetCoinAddress ¶
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 Denom Path.
func (Keeper) GetDenomMap ¶
GetDenomMap returns the token pair id for the given denomination.
func (Keeper) GetDynamicPrecompiles ¶ added in v0.3.0
Only to be used by ExportGenesis, not to be directly used
func (Keeper) GetERC20Map ¶
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) GetNativePrecompiles ¶ added in v0.3.0
Only to be used by ExportGenesis, not to be directly used
func (Keeper) GetTokenDenom ¶
GetTokenDenom returns the denom associated with the tokenAddress or an error if the TokenPair does not exist.
func (Keeper) GetTokenPair ¶
GetTokenPair gets a registered token pair from the identifier.
func (Keeper) GetTokenPairID ¶
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 ¶
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) IsDenomRegistered ¶
IsDenomRegistered check if registered coin denom is registered.
func (Keeper) IsDynamicPrecompileAvailable ¶ added in v0.3.0
func (Keeper) IsERC20Enabled ¶
IsERC20Enabled returns true if the module logic is enabled
func (Keeper) IsERC20Registered ¶
IsERC20Registered check if registered ERC20 token is registered.
func (Keeper) IsNativePrecompileAvailable ¶ added in v0.3.0
func (Keeper) IsTokenPairRegistered ¶
IsTokenPairRegistered - check if registered token tokenPair is registered.
func (Keeper) IterateAllowances ¶ added in v0.2.0
func (k Keeper) IterateAllowances( ctx sdk.Context, cb func(allowance types.Allowance) (stop bool), )
IterateAllowances iterates through all allowances stored on the given erc20 precompile address.
func (Keeper) IterateTokenPairs ¶
IterateTokenPairs iterates over all the stored token pairs.
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 ¶
func (k Keeper) OnAcknowledgementPacket( ctx sdk.Context, _ channeltypes.Packet, data transfertypes.FungibleTokenPacketData, ack channeltypes.Acknowledgement, ) error
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. If the ERC20 conversion fails for whatever reason, such as an attempt to call a self-destructed ERC20 contract or an invalid function, OnAcknowledgementPacket still succeeds, but the user receives the corresponding bank token from the TokenPair instead. A user may then manually re-attempt the conversion.
func (Keeper) OnRecvPacket ¶
func (k Keeper) OnRecvPacket( ctx sdk.Context, packet channeltypes.Packet, ack exported.Acknowledgement, ) exported.Acknowledgement
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 ¶
func (k Keeper) OnTimeoutPacket(ctx sdk.Context, _ channeltypes.Packet, data transfertypes.FungibleTokenPacketData) error
OnTimeoutPacket converts the IBC coin to ERC20 after refunding the sender since the original packet sent was never received and has been timed out. If the ERC20 conversion fails for whatever reason, such as an attempt to call a self-destructed ERC20 contract or an invalid function, OnTimeoutPacket still succeeds, but the user receives the corresponding bank token from the TokenPair instead. A user may then manually re-attempt the conversion.
func (Keeper) Params ¶
func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error)
Params returns the params of the erc20 module
func (Keeper) QueryERC20 ¶
QueryERC20 returns the data of a deployed ERC20 contract
func (Keeper) RegisterCodeHash ¶ added in v0.3.0
RegisterCodeHash checks if a new precompile already exists and registers the code hash it is not
func (*Keeper) RegisterERC20 ¶
func (k *Keeper) RegisterERC20(goCtx context.Context, req *types.MsgRegisterERC20) (*types.MsgRegisterERC20Response, error)
RegisterERC20 implements the gRPC MsgServer interface. Any account can permissionlessly register a native ERC20 contract to map to a Cosmos Coin.
func (Keeper) RegisterERC20CodeHash ¶
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 ¶
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) SetAllowance ¶ added in v0.2.0
func (k Keeper) SetAllowance( ctx sdk.Context, erc20 common.Address, owner common.Address, spender common.Address, value *big.Int, ) error
SetAllowance sets the allowance of the given owner and spender on the given erc20 precompile address.
func (Keeper) SetDenomMap ¶
SetDenomMap sets the token pair id for the denomination.
func (Keeper) SetDynamicPrecompile ¶ added in v0.3.0
func (Keeper) SetERC20Map ¶
SetERC20Map sets the token pair id for the given address.
func (Keeper) SetNativePrecompile ¶ added in v0.3.0
func (Keeper) SetPermissionlessRegistration ¶ added in v0.3.0
func (Keeper) SetTokenPair ¶
SetTokenPair stores a token pair.
func (*Keeper) ToggleConversion ¶
func (k *Keeper) ToggleConversion(goCtx context.Context, req *types.MsgToggleConversion) (*types.MsgToggleConversionResponse, error)
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 ¶
func (k Keeper) TokenPair(c context.Context, req *types.QueryTokenPairRequest) (*types.QueryTokenPairResponse, error)
TokenPair returns a given registered token pair
func (Keeper) TokenPairs ¶
func (k Keeper) TokenPairs(c context.Context, req *types.QueryTokenPairsRequest) (*types.QueryTokenPairsResponse, error)
TokenPairs returns all registered pairs
func (Keeper) UnRegisterERC20CodeHash ¶
UnRegisterERC20CodeHash sets the codehash for the account to an empty one
func (Keeper) UnsafeSetAllowance ¶ added in v0.2.0
func (k Keeper) UnsafeSetAllowance( ctx sdk.Context, erc20 common.Address, owner common.Address, spender common.Address, value *big.Int, ) error
UnsafeSetAllowance sets the allowance of the given owner and spender with validation. It allows setting allowance for disabled token pairs. This should only be used in InitGenesis.
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
type PrecompileType ¶ added in v0.3.0
type PrecompileType int
const ( PrecompileTypeNative PrecompileType = iota PrecompileTypeDynamic )