keeper

package
v0.0.0-...-2da98db Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BigIntZero                 = big.NewInt(0)
	ZEVMGasLimitDepositAndCall = big.NewInt(1_000_000)

	ZEVMGasLimitConnectorCall = big.NewInt(1_000_000)
)

TODO USE string constant

Functions

func NewMsgServerImpl

func NewMsgServerImpl(keeper Keeper) types.MsgServer

NewMsgServerImpl returns an implementation of the MsgServer interface for the provided Keeper.

Types

type EVMHooks

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

func (EVMHooks) PostTxProcessing

func (h EVMHooks) PostTxProcessing(ctx sdk.Context, _ core.Message, receipt *ethtypes.Receipt) error

PostTxProcessing is a wrapper for calling the EVM PostTxProcessing hook on the module keeper

type Keeper

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

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	storeKey,
	memKey storetypes.StoreKey,
	authKeeper types.AccountKeeper,
	evmKeeper types.EVMKeeper,
	bankKeeper types.BankKeeper,
	observerKeeper types.ObserverKeeper,
	authorityKeeper types.AuthorityKeeper,
) *Keeper

func (Keeper) BalanceOfZRC4

func (k Keeper) BalanceOfZRC4(
	ctx sdk.Context,
	contract, account common.Address,
) (*big.Int, error)

BalanceOfZRC4 queries an account's balance for a given ZRC4 contract

func (Keeper) CallEVM

func (k Keeper) CallEVM(
	ctx sdk.Context,
	abi abi.ABI,
	from, contract common.Address,
	value, gasLimit *big.Int,
	commit bool,
	noEthereumTxEvent bool,
	method string,
	args ...interface{},
) (*evmtypes.MsgEthereumTxResponse, error)

CallEVM performs a smart contract method call using given args returns (msg,err) the EVM execution result if there is any, even if error is non-nil due to contract reverts Furthermore, err!=nil && msg!=nil && msg.Failed() means the contract call reverted.

func (Keeper) CallEVMWithData

func (k Keeper) CallEVMWithData(
	ctx sdk.Context,
	from common.Address,
	contract *common.Address,
	data []byte,
	commit bool,
	noEthereumTxEvent bool,
	value *big.Int,
	gasLimit *big.Int,
) (*evmtypes.MsgEthereumTxResponse, error)

CallEVMWithData performs a smart contract method call using contract data value is the amount of wei to send; gaslimit is the custom gas limit, if nil EstimateGas is used to bisect the correct gas limit (this may sometimes result in insufficient gas limit; not sure why)

noEthereumTxEvent flag is used to control if ethereum_tx events should be emitted which will mean these txs are indexed and available in rpc methods

returns (msg,err) the EVM execution result if there is any, even if error is non-nil due to contract reverts Furthermore, err!=nil && msg!=nil && msg.Failed() means the contract call reverted; in which case msg.Ret gives the RET code if contract revert with REVERT opcode with parameters.

func (Keeper) CallOnReceiveZevmConnector

func (k Keeper) CallOnReceiveZevmConnector(ctx sdk.Context,
	zetaTxSenderAddress []byte,
	sourceChainID *big.Int,
	destinationAddress common.Address,
	zetaValue *big.Int,
	message []byte,
	internalSendHash [32]byte,
) (*evmtypes.MsgEthereumTxResponse, error)

CallOnReceiveZevmConnector calls the onReceive function of the ZevmConnector contract Before calling it mints the zetaValue tokens to the fungible module , and this amount is then provided as value to the onReceive function The onReceive function will then wrap this native zeta into WZETA and call the onReceive function of the destination contract specified by the destinationAddress

func (Keeper) CallOnRevertZevmConnector

func (k Keeper) CallOnRevertZevmConnector(ctx sdk.Context,
	zetaTxSenderAddress common.Address,
	sourceChainID *big.Int,
	destinationAddress []byte,
	destinationChainID *big.Int,
	remainingZetaValue *big.Int,
	message []byte,
	internalSendHash [32]byte,
) (*evmtypes.MsgEthereumTxResponse, error)

CallOnRevertZevmConnector calls the onRevert function of the ZevmConnector contract Before calling it mints the remainingZetaValue tokens to the fungible module , and this amount is then provided as value to the onRevert function The onRevert function will then wrap this native zeta into WZETA and call the onRevert function of the contract specified by the zetaTxSenderAddress Note the destination address is the original destination address of the transaction and not the current destination .

func (*Keeper) CallUniswapV2RouterSwapEthForExactToken

func (k *Keeper) CallUniswapV2RouterSwapEthForExactToken(
	ctx sdk.Context,
	sender ethcommon.Address,
	to ethcommon.Address,
	maxAmountIn *big.Int,
	amountOut *big.Int,
	outZRC4 ethcommon.Address,
) ([]*big.Int, error)

CallUniswapV2RouterSwapEthForExactToken calls the swapETHForExactTokens method of the uniswapv2 router contract

func (*Keeper) CallUniswapV2RouterSwapExactETHForToken

func (k *Keeper) CallUniswapV2RouterSwapExactETHForToken(
	ctx sdk.Context,
	sender ethcommon.Address,
	to ethcommon.Address,
	amountIn *big.Int,
	outZRC4 ethcommon.Address,
	noEthereumTxEvent bool,
) ([]*big.Int, error)

CallUniswapV2RouterSwapExactETHForToken calls the swapExactETHForTokens method of the uniswapv2 router contract

func (*Keeper) CallUniswapV2RouterSwapExactTokensForETH

func (k *Keeper) CallUniswapV2RouterSwapExactTokensForETH(
	ctx sdk.Context,
	sender ethcommon.Address,
	to ethcommon.Address,
	amountIn *big.Int,
	inZRC4 ethcommon.Address,
	noEthereumTxEvent bool,
) (ret []*big.Int, err error)

CallUniswapV2RouterSwapExactTokensForETH calls the swapExactTokensForETH method of the uniswapv2 router contract

func (*Keeper) CallUniswapV2RouterSwapExactTokensForTokens

func (k *Keeper) CallUniswapV2RouterSwapExactTokensForTokens(
	ctx sdk.Context,
	sender ethcommon.Address,
	to ethcommon.Address,
	amountIn *big.Int,
	inZRC4,
	outZRC4 ethcommon.Address,
	noEthereumTxEvent bool,
) (ret []*big.Int, err error)

CallUniswapV2RouterSwapExactTokensForTokens calls the swapExactTokensForETH method of the uniswapv2 router contract to swap tokens to another tokens using wZeta as intermediary

func (*Keeper) CallWZetaDeposit

func (k *Keeper) CallWZetaDeposit(ctx sdk.Context, sender ethcommon.Address, amount *big.Int) error

CallWZetaDeposit calls the deposit method of the wzeta contract

func (*Keeper) CallZRC20Approve

func (k *Keeper) CallZRC20Approve(
	ctx sdk.Context,
	owner ethcommon.Address,
	zrc20address ethcommon.Address,
	spender ethcommon.Address,
	amount *big.Int,
	noEthereumTxEvent bool,
) error

CallZRC20Approve calls the approve method of the zrc20 contract

func (*Keeper) CallZRC20Burn

func (k *Keeper) CallZRC20Burn(
	ctx sdk.Context,
	sender ethcommon.Address,
	zrc20address ethcommon.Address,
	amount *big.Int,
	noEthereumTxEvent bool,
) error

CallZRC20Burn calls the burn method of the zrc20 contract

func (*Keeper) CallZRC20Deposit

func (k *Keeper) CallZRC20Deposit(
	ctx sdk.Context,
	sender ethcommon.Address,
	zrc20address ethcommon.Address,
	to ethcommon.Address,
	amount *big.Int,
) error

CallZRC20Deposit calls the deposit method of the zrc20 contract

func (Keeper) CodeHash

CodeHash returns the code hash of an account if it exists

func (Keeper) DeployConnectorZEVM

func (k Keeper) DeployConnectorZEVM(ctx sdk.Context, wzeta common.Address) (common.Address, error)

func (Keeper) DeployContract

func (k Keeper) DeployContract(
	ctx sdk.Context,
	metadata *bind.MetaData,
	ctorArguments ...interface{},
) (common.Address, error)

DeployContract deploys a new contract in the ZEVM

func (Keeper) DeploySystemContract

func (k Keeper) DeploySystemContract(
	ctx sdk.Context,
	wzeta common.Address,
	v2factory common.Address,
	router02 common.Address,
) (common.Address, error)

func (Keeper) DeployUniswapV2Factory

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

func (Keeper) DeployUniswapV2Router02

func (k Keeper) DeployUniswapV2Router02(
	ctx sdk.Context,
	factory common.Address,
	wzeta common.Address,
) (common.Address, error)

func (Keeper) DeployWZETA

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

func (Keeper) DeployZRC20Contract

func (k Keeper) DeployZRC20Contract(
	ctx sdk.Context,
	name, symbol string,
	decimals uint8,
	chainID int64,
	coinType coin.CoinType,
	erc20Contract string,
	gasLimit *big.Int,
) (common.Address, error)

DeployZRC20Contract creates and deploys an ERC20 contract on the EVM with the erc20 module account as owner. Also adds itself to ForeignCoins fungible module state variable TODO Unit test for these functions https://github.com/zeta-chain/node/issues/864 TODO Remove repetitive code

func (Keeper) DepositCoinZeta

func (k Keeper) DepositCoinZeta(ctx sdk.Context, to eth.Address, amount *big.Int) error

DepositCoinZeta immediately mints ZETA to the EVM account

func (Keeper) DepositCoinsToFungibleModule

func (k Keeper) DepositCoinsToFungibleModule(ctx sdk.Context, amount *big.Int) error

func (Keeper) DepositZRC20

func (k Keeper) DepositZRC20(
	ctx sdk.Context,
	contract common.Address,
	to common.Address,
	amount *big.Int,
) (*evmtypes.MsgEthereumTxResponse, error)

DepositZRC20 deposits ZRC4 tokens into to account; Callable only by the fungible module account returns directly CallEVM()

func (Keeper) DepositZRC20AndCallContract

func (k Keeper) DepositZRC20AndCallContract(ctx sdk.Context,
	context systemcontract.ZContext,
	zrc20Addr common.Address,
	targetContract common.Address,
	amount *big.Int,
	message []byte,
) (*evmtypes.MsgEthereumTxResponse, error)

DepositZRC20AndCallContract deposits into ZRC4 and call contract function in a single tx callable from fungible module Returns directly results from CallEVM

func (Keeper) EVMHooks

func (k Keeper) EVMHooks() EVMHooks

func (Keeper) EnsureGasStabilityPoolAccountCreated

func (k Keeper) EnsureGasStabilityPoolAccountCreated(ctx sdk.Context)

EnsureGasStabilityPoolAccountCreated ensures the gas stability pool account exists

func (Keeper) FundGasStabilityPool

func (k Keeper) FundGasStabilityPool(
	ctx sdk.Context,
	chainID int64,
	amount *big.Int,
) error

FundGasStabilityPool mints the ZRC20 into a special address called gas stability pool for the chain

func (Keeper) GetAllForeignCoinMap

func (k Keeper) GetAllForeignCoinMap(ctx sdk.Context) map[int64]map[string]types.ForeignCoins

GetAllForeignCoinMap returns all foreign ERC20 coins in a map of chainID -> asset -> coin Note: DO NOT use this method outside of gRPC queries

func (Keeper) GetAllForeignCoins

func (k Keeper) GetAllForeignCoins(ctx sdk.Context) (list []types.ForeignCoins)

GetAllForeignCoins returns all foreignCoins

func (Keeper) GetAllForeignCoinsForChain

func (k Keeper) GetAllForeignCoinsForChain(ctx sdk.Context, foreignChainID int64) (list []types.ForeignCoins)

GetAllForeignCoinsForChain returns all foreignCoins on a given chain

func (Keeper) GetAuthKeeper

func (k Keeper) GetAuthKeeper() types.AccountKeeper

func (Keeper) GetAuthorityKeeper

func (k Keeper) GetAuthorityKeeper() types.AuthorityKeeper

func (Keeper) GetBankKeeper

func (k Keeper) GetBankKeeper() types.BankKeeper

func (Keeper) GetEVMKeeper

func (k Keeper) GetEVMKeeper() types.EVMKeeper

func (Keeper) GetForeignCoinFromAsset

func (k Keeper) GetForeignCoinFromAsset(ctx sdk.Context, asset string, chainID int64) (types.ForeignCoins, bool)

GetForeignCoinFromAsset returns the foreign coin for a given asset for a given chain

func (Keeper) GetForeignCoins

func (k Keeper) GetForeignCoins(
	ctx sdk.Context,
	zrc20Addr string,
) (val types.ForeignCoins, found bool)

GetForeignCoins returns a foreignCoins from its index

func (Keeper) GetGasCoinForForeignCoin

func (k Keeper) GetGasCoinForForeignCoin(ctx sdk.Context, chainID int64) (types.ForeignCoins, bool)

GetGasCoinForForeignCoin returns the gas coin for a given chain

func (Keeper) GetGasStabilityPoolBalance

func (k Keeper) GetGasStabilityPoolBalance(
	ctx sdk.Context,
	chainID int64,
) (*big.Int, error)

GetGasStabilityPoolBalance returns the balance of the gas stability pool

func (Keeper) GetObserverKeeper

func (k Keeper) GetObserverKeeper() types.ObserverKeeper

func (Keeper) GetSystemContract

func (k Keeper) GetSystemContract(ctx sdk.Context) (val types.SystemContract, found bool)

GetSystemContract returns system contract from the store

func (*Keeper) GetSystemContractAddress

func (k *Keeper) GetSystemContractAddress(ctx sdk.Context) (ethcommon.Address, error)

GetSystemContractAddress returns the system contract address TODO : wzetaContractAddress and other constant strings , can be declared as a constant string in types TODO Remove repetitive code

func (*Keeper) GetUniswapV2FactoryAddress

func (k *Keeper) GetUniswapV2FactoryAddress(ctx sdk.Context) (ethcommon.Address, error)

GetUniswapV2FactoryAddress returns the uniswapv2 factory contract address on ZetaChain

func (*Keeper) GetUniswapV2Router02Address

func (k *Keeper) GetUniswapV2Router02Address(ctx sdk.Context) (ethcommon.Address, error)

GetUniswapV2Router02Address returns the uniswapv2 router02 address on ZetaChain

func (*Keeper) GetWZetaContractAddress

func (k *Keeper) GetWZetaContractAddress(ctx sdk.Context) (ethcommon.Address, error)

GetWZetaContractAddress returns the wzeta contract address on ZetaChain

func (Keeper) Logger

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

func (*Keeper) MintZetaToEVMAccount

func (k *Keeper) MintZetaToEVMAccount(ctx sdk.Context, to sdk.AccAddress, amount *big.Int) error

MintZetaToEVMAccount mints ZETA (gas token) to the given address NOTE: this method should be used with a temporary context, and it should not be committed if the method returns an error

func (*Keeper) MintZetaToFungibleModule

func (k *Keeper) MintZetaToFungibleModule(ctx sdk.Context, amount *big.Int) error

func (Keeper) QueryChainIDFromContract

func (k Keeper) QueryChainIDFromContract(
	ctx sdk.Context,
	contract common.Address,
) (*big.Int, error)

QueryChainIDFromContract returns the chain id of the chain

func (Keeper) QueryGasLimit

func (k Keeper) QueryGasLimit(ctx sdk.Context, contract common.Address) (*big.Int, error)

QueryGasLimit returns the gas limit for a withdrawal transaction associated with a given zrc20

func (Keeper) QueryProtocolFlatFee

func (k Keeper) QueryProtocolFlatFee(ctx sdk.Context, contract common.Address) (*big.Int, error)

QueryProtocolFlatFee returns the protocol flat fee associated with a given zrc20

func (*Keeper) QuerySystemContractGasCoinZRC20

func (k *Keeper) QuerySystemContractGasCoinZRC20(ctx sdk.Context, chainid *big.Int) (ethcommon.Address, error)

QuerySystemContractGasCoinZRC20 returns the gas coin zrc20 address for the given chain id

func (*Keeper) QueryUniswapV2RouterGetZRC4AmountsIn

func (k *Keeper) QueryUniswapV2RouterGetZRC4AmountsIn(
	ctx sdk.Context,
	amountOut *big.Int,
	inZRC4 ethcommon.Address,
) (*big.Int, error)

QueryUniswapV2RouterGetZRC4AmountsIn returns the amount of ZRC4 tokens needed to buy the given amount of zeta

func (*Keeper) QueryUniswapV2RouterGetZRC4ToZRC4AmountsIn

func (k *Keeper) QueryUniswapV2RouterGetZRC4ToZRC4AmountsIn(
	ctx sdk.Context,
	amountOut *big.Int,
	inZRC4, outZRC4 ethcommon.Address,
) (*big.Int, error)

QueryUniswapV2RouterGetZRC4ToZRC4AmountsIn returns the amount of ZRC4 tokens needed to buy another ZRC4 token, it uses the WZeta contract as a bridge

func (*Keeper) QueryUniswapV2RouterGetZetaAmountsIn

func (k *Keeper) QueryUniswapV2RouterGetZetaAmountsIn(
	ctx sdk.Context,
	amountOut *big.Int,
	outZRC4 ethcommon.Address,
) (*big.Int, error)

QueryUniswapV2RouterGetZetaAmountsIn returns the amount of zeta needed to buy the given amount of ZRC4 tokens

func (*Keeper) QueryWZetaBalanceOf

func (k *Keeper) QueryWZetaBalanceOf(ctx sdk.Context, addr ethcommon.Address) (*big.Int, error)

QueryWZetaBalanceOf returns the balance of the given address in the wzeta contract

func (Keeper) QueryZRC20Data

func (k Keeper) QueryZRC20Data(
	ctx sdk.Context,
	contract common.Address,
) (types.ZRC20Data, error)

QueryZRC20Data returns the data of a deployed ZRC20 contract

func (Keeper) RemoveForeignCoins

func (k Keeper) RemoveForeignCoins(
	ctx sdk.Context,
	zrc20Addr string,
)

RemoveForeignCoins removes a foreignCoins from the store

func (Keeper) RemoveSystemContract

func (k Keeper) RemoveSystemContract(ctx sdk.Context)

RemoveSystemContract removes system contract from the store

func (Keeper) SetForeignCoins

func (k Keeper) SetForeignCoins(ctx sdk.Context, foreignCoins types.ForeignCoins)

SetForeignCoins set a specific foreignCoins in the store from its index

func (Keeper) SetGasCoin

func (k Keeper) SetGasCoin(ctx sdk.Context, chainid *big.Int, address ethcommon.Address) error

func (Keeper) SetGasPrice

func (k Keeper) SetGasPrice(ctx sdk.Context, chainid *big.Int, gasPrice *big.Int) (uint64, error)

SetGasPrice sets gas price on the system contract in zEVM; return the gasUsed and error code

func (Keeper) SetGasZetaPool

func (k Keeper) SetGasZetaPool(ctx sdk.Context, chainid *big.Int, pool ethcommon.Address) error

func (Keeper) SetSystemContract

func (k Keeper) SetSystemContract(ctx sdk.Context, sytemContract types.SystemContract)

SetSystemContract set system contract in the store

func (Keeper) SetupChainGasCoinAndPool

func (k Keeper) SetupChainGasCoinAndPool(
	ctx sdk.Context,
	chainID int64,
	gasAssetName string,
	symbol string,
	decimals uint8,
	gasLimit *big.Int,
) (ethcommon.Address, error)

SetupChainGasCoinAndPool setup gas ZRC20, and ZETA/gas pool for a chain add 0.1gas/0.1wzeta to the pool FIXME: add cointype and use proper gas limit based on cointype/chain

func (Keeper) TotalSupplyZRC4

func (k Keeper) TotalSupplyZRC4(
	ctx sdk.Context,
	contract common.Address,
) (*big.Int, error)

TotalSupplyZRC4 queries the total supply of a given ZRC4 contract

func (Keeper) UpdateZRC20GasLimit

func (k Keeper) UpdateZRC20GasLimit(
	ctx sdk.Context,
	zrc20Addr common.Address,
	newGasLimit *big.Int,
) (*evmtypes.MsgEthereumTxResponse, error)

UpdateZRC20GasLimit updates the gas limit for a given ZRC20 contract

func (Keeper) UpdateZRC20ProtocolFlatFee

func (k Keeper) UpdateZRC20ProtocolFlatFee(
	ctx sdk.Context,
	zrc20Addr common.Address,
	newFee *big.Int,
) (*evmtypes.MsgEthereumTxResponse, error)

UpdateZRC20ProtocolFlatFee updates the protocol flat fee for a given ZRC20 contract

func (Keeper) WithdrawFromGasStabilityPool

func (k Keeper) WithdrawFromGasStabilityPool(
	ctx sdk.Context,
	chainID int64,
	amount *big.Int,
) error

WithdrawFromGasStabilityPool burns the ZRC20 from the gas stability pool

func (Keeper) ZETADepositAndCallContract

func (k Keeper) ZETADepositAndCallContract(ctx sdk.Context,
	sender ethcommon.Address,
	to ethcommon.Address,
	inboundSenderChainID int64,
	inboundAmount *big.Int,
	data []byte,
	indexBytes [32]byte) (*evmtypes.MsgEthereumTxResponse, error)

ZETADepositAndCallContract deposits native ZETA to the to address if its an account or if the account does not exist yet If it's not an account it calls onReceive function of the connector contract and provides the address as the destinationAddress .The amount of tokens is minted to the fungible module account, wrapped and sent to the contract

func (Keeper) ZETARevertAndCallContract

func (k Keeper) ZETARevertAndCallContract(ctx sdk.Context,
	sender ethcommon.Address,
	to ethcommon.Address,
	inboundSenderChainID int64,
	destinationChainID int64,
	remainingAmount *big.Int,
	data []byte,
	indexBytes [32]byte) (*evmtypes.MsgEthereumTxResponse, error)

ZETARevertAndCallContract deposits native ZETA to the sender address if its account or if the account does not exist yet If it's not an account it calls onRevert function of the connector contract and provides the sender address as the zetaTxSenderAddress.The amount of tokens is minted to the fungible module account, wrapped and sent to the contract

func (Keeper) ZRC20DepositAndCallContract

func (k Keeper) ZRC20DepositAndCallContract(
	ctx sdk.Context,
	from []byte,
	to eth.Address,
	amount *big.Int,
	senderChainID int64,
	data []byte,
	coinType coin.CoinType,
	asset string,
) (*evmtypes.MsgEthereumTxResponse, bool, error)

ZRC20DepositAndCallContract deposits ZRC20 to the EVM account and calls the contract returns [txResponse, isContractCall, error] isContractCall is true if the receiver is a contract and a contract call was made

Jump to

Keyboard shortcuts

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