Documentation ¶
Overview ¶
Copyright (c) 2023-2024 Nibi, Inc.
Copyright (c) 2023-2024 Nibi, Inc.
Copyright (c) 2023-2024 Nibi, Inc.
Copyright (c) 2023-2024 Nibi, Inc.
Copyright (c) 2023-2024 Nibi, Inc.
Copyright (c) 2023-2024 Nibi, Inc.
Copyright (c) 2023-2024 Nibi, Inc.
Copyright (c) 2023-2024 Nibi, Inc.
Copyright (c) 2023-2024 Nibi, Inc.
Copyright (c) 2023-2024 Nibi, Inc.
Copyright (c) 2023-2024 Nibi, Inc.
Copyright (c) 2023-2024 Nibi, Inc.
Copyright (c) 2023-2024 Nibi, Inc.
Index ¶
- Constants
- func CheckSenderBalance(balanceWei *big.Int, txData evm.TxData) error
- func GasToRefund(availableRefund, gasConsumed, refundQuotient uint64) uint64
- func HandleOutOfGasPanic(err *error, format string) func()
- func ParseProposerAddr(ctx sdk.Context, proposerAddress sdk.ConsAddress) sdk.ConsAddress
- func ParseWeiAsMultipleOfMicronibi(weiInt *big.Int) (newWeiInt *big.Int, err error)
- func VerifyFee(txData evm.TxData, denom string, baseFeeMicronibi *big.Int, isCheckTx bool) (sdk.Coins, error)
- type AccStatePrimaryKey
- type CodeHash
- type ERC20BigInt
- type ERC20Bool
- type ERC20Metadata
- type ERC20String
- type ERC20Uint8
- type EvmState
- func (state EvmState) CalcBloomFromLogs(ctx sdk.Context, newLogs []*gethcore.Log) (bloom gethcore.Bloom)
- func (state EvmState) GetBlockBloomTransient(ctx sdk.Context) *big.Int
- func (state EvmState) GetContractBytecode(ctx sdk.Context, codeHash []byte) (code []byte)
- func (state EvmState) SetAccCode(ctx sdk.Context, codeHash, code []byte)
- func (state EvmState) SetAccState(ctx sdk.Context, addr gethcommon.Address, stateKey gethcommon.Hash, ...)
- type FunTokenState
- type IndexesFunToken
- type Keeper
- func (k *Keeper) AddPrecompiles(precompileMap map[gethcommon.Address]vm.PrecompiledContract)
- func (k *Keeper) AddToBlockGasUsed(ctx sdk.Context, gasUsed uint64) (blockGasUsed uint64, err error)
- func (k *Keeper) ApplyEvmMsg(ctx sdk.Context, msg core.Message, tracer vm.EVMLogger, commit bool, ...) (resp *evm.MsgEthereumTxResponse, evmObj *vm.EVM, err error)
- func (k Keeper) Balance(goCtx context.Context, req *evm.QueryBalanceRequest) (*evm.QueryBalanceResponse, error)
- func (k Keeper) BaseFee(goCtx context.Context, _ *evm.QueryBaseFeeRequest) (*evm.QueryBaseFeeResponse, error)
- func (k Keeper) BaseFeeMicronibiPerGas(_ sdk.Context) *big.Int
- func (k Keeper) BaseFeeWeiPerGas(_ sdk.Context) *big.Int
- func (k *Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock)
- func (k Keeper) CallContract(ctx sdk.Context, abi *gethabi.ABI, fromAcc gethcommon.Address, ...) (evmResp *evm.MsgEthereumTxResponse, err error)
- func (k Keeper) CallContractWithInput(ctx sdk.Context, fromAcc gethcommon.Address, contract *gethcommon.Address, ...) (evmResp *evm.MsgEthereumTxResponse, evmObj *vm.EVM, err error)
- func (k Keeper) Code(goCtx context.Context, req *evm.QueryCodeRequest) (*evm.QueryCodeResponse, error)
- func (k *Keeper) ConvertCoinToEvm(goCtx context.Context, msg *evm.MsgConvertCoinToEvm) (resp *evm.MsgConvertCoinToEvmResponse, err error)
- func (k *Keeper) CreateFunToken(goCtx context.Context, msg *evm.MsgCreateFunToken) (resp *evm.MsgCreateFunTokenResponse, err error)
- func (k *Keeper) DeductTxCostsFromUserBalance(ctx sdk.Context, fees sdk.Coins, from gethcommon.Address) error
- func (k *Keeper) DeleteAccount(ctx sdk.Context, addr gethcommon.Address) error
- func (k Keeper) ERC20() erc20Calls
- func (k *Keeper) EVMState() EvmState
- func (k *Keeper) EmitEthereumTxEvents(ctx sdk.Context, recipient *gethcommon.Address, txType uint8, ...) error
- func (k *Keeper) EmitLogEvents(ctx sdk.Context, evmResp *evm.MsgEthereumTxResponse) error
- func (k *Keeper) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate
- func (k Keeper) EstimateGas(goCtx context.Context, req *evm.EthCallRequest) (*evm.EstimateGasResponse, error)
- func (k Keeper) EstimateGasForEvmCallType(goCtx context.Context, req *evm.EthCallRequest, fromType evm.CallType) (*evm.EstimateGasResponse, error)
- func (k Keeper) EthAccount(goCtx context.Context, req *evm.QueryEthAccountRequest) (*evm.QueryEthAccountResponse, error)
- func (k *Keeper) EthCall(goCtx context.Context, req *evm.EthCallRequest) (*evm.MsgEthereumTxResponse, error)
- func (k Keeper) EthChainID(ctx sdk.Context) *big.Int
- func (k *Keeper) EthereumTx(goCtx context.Context, txMsg *evm.MsgEthereumTx) (evmResp *evm.MsgEthereumTxResponse, err error)
- func (k Keeper) FeeForCreateFunToken(ctx sdk.Context) sdk.Coins
- func (k Keeper) FindERC20Metadata(ctx sdk.Context, contract gethcommon.Address) (info *ERC20Metadata, err error)
- func (k *Keeper) ForEachStorage(ctx sdk.Context, addr gethcommon.Address, ...)
- func (k Keeper) FunTokenMapping(goCtx context.Context, req *evm.QueryFunTokenMappingRequest) (*evm.QueryFunTokenMappingResponse, error)
- func (k Keeper) GetAccNonce(ctx sdk.Context, addr gethcommon.Address) uint64
- func (k *Keeper) GetAccount(ctx sdk.Context, addr gethcommon.Address) *statedb.Account
- func (k *Keeper) GetAccountOrEmpty(ctx sdk.Context, addr gethcommon.Address) statedb.Account
- func (k *Keeper) GetAccountWithoutBalance(ctx sdk.Context, addr gethcommon.Address) *statedb.Account
- func (k *Keeper) GetCode(ctx sdk.Context, codeHash gethcommon.Hash) []byte
- func (k Keeper) GetCoinbaseAddress(ctx sdk.Context, proposerAddress sdk.ConsAddress) (common.Address, error)
- func (k *Keeper) GetEVMConfig(ctx sdk.Context, proposerAddress sdk.ConsAddress, chainID *big.Int) (*statedb.EVMConfig, error)
- func (k *Keeper) GetEthIntrinsicGas(ctx sdk.Context, msg core.Message, cfg *params.ChainConfig, ...) (uint64, error)
- func (k *Keeper) GetEvmGasBalance(ctx sdk.Context, addr gethcommon.Address) (balance *big.Int)
- func (k Keeper) GetHashFn(ctx sdk.Context) vm.GetHashFunc
- func (k Keeper) GetParams(ctx sdk.Context) (params evm.Params)
- func (k *Keeper) GetState(ctx sdk.Context, addr gethcommon.Address, stateKey gethcommon.Hash) gethcommon.Hash
- func (k *Keeper) IsPrecompile(addr gethcommon.Address) bool
- func (k Keeper) LoadERC20BigInt(ctx sdk.Context, abi *gethabi.ABI, contract gethcommon.Address, ...) (out *big.Int, err error)
- func (k Keeper) LoadERC20Decimals(ctx sdk.Context, abi *gethabi.ABI, erc20 gethcommon.Address) (out uint8, err error)
- func (k Keeper) LoadERC20Name(ctx sdk.Context, abi *gethabi.ABI, erc20 gethcommon.Address) (out string, err error)
- func (k Keeper) LoadERC20String(ctx sdk.Context, erc20Abi *gethabi.ABI, erc20Contract gethcommon.Address, ...) (out string, err error)
- func (k Keeper) LoadERC20Symbol(ctx sdk.Context, abi *gethabi.ABI, erc20 gethcommon.Address) (out string, err error)
- func (k Keeper) Logger(ctx sdk.Context) log.Logger
- func (k *Keeper) NewEVM(ctx sdk.Context, msg core.Message, evmConfig *statedb.EVMConfig, ...) *vm.EVM
- func (evmKeeper *Keeper) NewStateDB(ctx sdk.Context, txConfig statedb.TxConfig) *statedb.StateDB
- func (k Keeper) Params(goCtx context.Context, _ *evm.QueryParamsRequest) (*evm.QueryParamsResponse, error)
- func (k *Keeper) RefundGas(ctx sdk.Context, msgFrom gethcommon.Address, leftoverGas uint64, ...) error
- func (k *Keeper) ResetGasMeterAndConsumeGas(ctx sdk.Context, gasUsed uint64)
- func (k *Keeper) ResetTransientGasUsed(ctx sdk.Context)
- func (k *Keeper) SetAccBalance(ctx sdk.Context, addr gethcommon.Address, amountEvmDenom *big.Int) error
- func (k *Keeper) SetAccount(ctx sdk.Context, addr gethcommon.Address, account statedb.Account) error
- func (k *Keeper) SetCode(ctx sdk.Context, codeHash, code []byte)
- func (k Keeper) SetParams(ctx sdk.Context, params evm.Params) (err error)
- func (k *Keeper) SetState(ctx sdk.Context, addr gethcommon.Address, stateKey gethcommon.Hash, ...)
- func (k Keeper) Storage(goCtx context.Context, req *evm.QueryStorageRequest) (*evm.QueryStorageResponse, error)
- func (k Keeper) TraceBlock(goCtx context.Context, req *evm.QueryTraceBlockRequest) (*evm.QueryTraceBlockResponse, error)
- func (k Keeper) TraceCall(goCtx context.Context, req *evm.QueryTraceTxRequest) (*evm.QueryTraceTxResponse, error)
- func (k *Keeper) TraceEthTxMsg(ctx sdk.Context, cfg *statedb.EVMConfig, txConfig statedb.TxConfig, ...) (*any, uint, error)
- func (k Keeper) TraceTx(goCtx context.Context, req *evm.QueryTraceTxRequest) (*evm.QueryTraceTxResponse, error)
- func (k Keeper) Tracer(ctx sdk.Context, msg core.Message, ethCfg *gethparams.ChainConfig) vm.EVMLogger
- func (k *Keeper) TxConfig(ctx sdk.Context, txHash common.Hash) statedb.TxConfig
- func (k *Keeper) UpdateParams(goCtx context.Context, req *evm.MsgUpdateParams) (resp *evm.MsgUpdateParamsResponse, err error)
- func (k Keeper) VMConfig(ctx sdk.Context, _ core.Message, cfg *statedb.EVMConfig, tracer vm.EVMLogger) vm.Config
- func (k Keeper) ValidatorAccount(goCtx context.Context, req *evm.QueryValidatorAccountRequest) (*evm.QueryValidatorAccountResponse, error)
- type NibiruBankKeeper
- func (bk NibiruBankKeeper) BurnCoins(ctx sdk.Context, moduleName string, coins sdk.Coins) error
- func (bk NibiruBankKeeper) MintCoins(ctx sdk.Context, moduleName string, coins sdk.Coins) error
- func (bk NibiruBankKeeper) SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, ...) error
- func (bk NibiruBankKeeper) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, ...) error
- func (bk NibiruBankKeeper) SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, ...) error
- func (bk NibiruBankKeeper) SendCoinsFromModuleToModule(ctx sdk.Context, senderModule string, recipientModule string, coins sdk.Coins) error
- func (bk *NibiruBankKeeper) SyncStateDBWithAccount(ctx sdk.Context, acc sdk.AccAddress)
Constants ¶
const ( // Erc20GasLimitDeploy only used internally when deploying ERC20Minter. // Deployment requires ~1_600_000 gas Erc20GasLimitDeploy uint64 = 2_000_000 // Erc20GasLimitQuery used only for querying name, symbol and decimals // Cannot be heavy. Only if the contract is malicious. Erc20GasLimitQuery uint64 = 100_000 // Erc20GasLimitExecute used for transfer, mint and burn. // All must not exceed 200_000 Erc20GasLimitExecute uint64 = 200_000 )
const DefaultGethTraceTimeout = 5 * time.Second
Re-export of the default tracer timeout from go-ethereum. See "geth/eth/tracers/api.go".
Variables ¶
This section is empty.
Functions ¶
func CheckSenderBalance ¶
CheckSenderBalance validates that the tx cost value is positive and that the sender has enough funds to pay for the fees and value of the transaction.
func GasToRefund ¶
GasToRefund calculates the amount of gas the state machine should refund to the sender. It is capped by the refund quotient value. Note that passing a jrefundQuotient of 0 will cause problems.
func HandleOutOfGasPanic ¶
HandleOutOfGasPanic gracefully captures "out of gas" panic and just sets the value to err
func ParseProposerAddr ¶
func ParseProposerAddr( ctx sdk.Context, proposerAddress sdk.ConsAddress, ) sdk.ConsAddress
ParseProposerAddr returns current block proposer's address when provided proposer address is empty.
func VerifyFee ¶
func VerifyFee( txData evm.TxData, denom string, baseFeeMicronibi *big.Int, isCheckTx bool, ) (sdk.Coins, error)
VerifyFee is used to return the fee for the given transaction data in sdk.Coins. It checks that the gas limit is not reached, the gas limit is higher than the intrinsic gas and that the base fee is lower than the gas fee cap.
Types ¶
type AccStatePrimaryKey ¶
type AccStatePrimaryKey = collections.Pair[gethcommon.Address, gethcommon.Hash]
type ERC20BigInt ¶
ERC20BigInt: Unpacking type for "uint256" from Solidity.
type ERC20Metadata ¶
ERC20Metadata: Optional metadata fields parsed from an ERC20 contract. The Wrapped Ether contract is a good example for reference.
```solidity constract WETH9 { string public name = "Wrapped Ether"; string public symbol = "WETH" uint8 public decimals = 18; } ```
Note that the name and symbol fields may be empty, according to the ERC20 specification.
func (ERC20Metadata) ToBankMetadata ¶
func (erc20Info ERC20Metadata) ToBankMetadata( bankDenom string, erc20 gethcommon.Address, ) bank.Metadata
ToBankMetadata produces the "bank.Metadata" corresponding to a FunToken mapping created from an ERC20 token.
The first argument of DenomUnits is required and the official base unit onchain, meaning the denom must be equivalent to bank.Metadata.Base.
Decimals for an ERC20 are synonymous to "bank.DenomUnit.Exponent" in what they mean for external clients like wallets.
type ERC20String ¶
type ERC20String struct{ Value string }
type ERC20Uint8 ¶
type ERC20Uint8 struct{ Value uint8 }
ERC20Uint8: Unpacking type for "uint8" from Solidity. This is only used in the "ERC20.decimals" function.
type EvmState ¶
type EvmState struct { ModuleParams collections.Item[evm.Params] // ContractBytecode: Map from (byte)code hash -> contract bytecode ContractBytecode collections.Map[CodeHash, []byte] // AccState: Map from eth address (account) and hash of a state key -> smart // contract state. Each contract essentially has its own key-value store. // // - primary key (PK): (EthAddr+EthHash). The contract is the primary key // because there's exactly one deployer and withdrawer. // - value (V): State value bytes. AccState collections.Map[ AccStatePrimaryKey, []byte, ] // BlockGasUsed: Gas used by Ethereum txs in the block (transient). BlockGasUsed collections.ItemTransient[uint64] // BlockLogSize: EVM tx log size for the block (transient). BlockLogSize collections.ItemTransient[uint64] // BlockTxIndex: EVM tx index for the block (transient). BlockTxIndex collections.ItemTransient[uint64] // BlockBloom: Bloom filters. BlockBloom collections.ItemTransient[[]byte] }
EvmState isolates the key-value stores (collections) for the x/evm module.
func NewEvmState ¶
func (EvmState) CalcBloomFromLogs ¶
func (EvmState) GetBlockBloomTransient ¶
GetBlockBloomTransient returns bloom bytes for the current block height
func (EvmState) GetContractBytecode ¶
func (EvmState) SetAccCode ¶
func (EvmState) SetAccState ¶
func (state EvmState) SetAccState( ctx sdk.Context, addr gethcommon.Address, stateKey gethcommon.Hash, stateValue []byte, )
SetState updates contract storage and deletes if the value is empty.
type FunTokenState ¶
type FunTokenState struct { collections.IndexedMap[[]byte, evm.FunToken, IndexesFunToken] }
FunTokenState isolates the key-value stores (collections) for fungible token mappings. This struct is written as an extension of the default indexed map to add utility functions.
func NewFunTokenState ¶
func NewFunTokenState( cdc sdkcodec.BinaryCodec, storeKey storetypes.StoreKey, ) FunTokenState
func (FunTokenState) SafeInsert ¶
func (fun FunTokenState) SafeInsert( ctx sdk.Context, erc20 gethcommon.Address, bankDenom string, isMadeFromCoin bool, ) error
Insert adds an evm.FunToken to state with defensive validation. Errors if the given inputs would result in a corrupted evm.FunToken.
type IndexesFunToken ¶
type IndexesFunToken struct { // ERC20Addr (MultiIndex): Index FunToken by ERC-20 contract address. // - indexing key (IK): ERC-20 addr // - primary key (PK): FunToken ID // - value (V): FunToken value ERC20Addr collections.MultiIndex[gethcommon.Address, []byte, evm.FunToken] // BankDenom (MultiIndex): Index FunToken by coin denomination // - indexing key (IK): Coin denom // - primary key (PK): FunToken ID // - value (V): FunToken value BankDenom collections.MultiIndex[string, []byte, evm.FunToken] }
IndexesFunToken: Abstraction for indexing over the FunToken store.
func (IndexesFunToken) IndexerList ¶
func (idxs IndexesFunToken) IndexerList() []collections.Indexer[[]byte, evm.FunToken]
type Keeper ¶
type Keeper struct { // EvmState isolates the key-value stores (collections) for the x/evm module. EvmState EvmState // FunTokens isolates the key-value stores (collections) for fungible token // mappings. FunTokens FunTokenState Bank *NibiruBankKeeper // contains filtered or unexported fields }
func NewKeeper ¶
func NewKeeper( cdc codec.BinaryCodec, storeKey, transientKey storetypes.StoreKey, authority sdk.AccAddress, accKeeper evm.AccountKeeper, bankKeeper *NibiruBankKeeper, stakingKeeper evm.StakingKeeper, tracer string, ) Keeper
NewKeeper is a constructor for an x/evm Keeper. This function is necessary because the Keeper struct has private fields.
func (*Keeper) AddPrecompiles ¶
func (k *Keeper) AddPrecompiles( precompileMap map[gethcommon.Address]vm.PrecompiledContract, )
func (*Keeper) AddToBlockGasUsed ¶
func (k *Keeper) AddToBlockGasUsed( ctx sdk.Context, gasUsed uint64, ) (blockGasUsed uint64, err error)
AddToBlockGasUsed accumulate gas used by each eth msgs included in current block tx.
func (*Keeper) ApplyEvmMsg ¶
func (k *Keeper) ApplyEvmMsg(ctx sdk.Context, msg core.Message, tracer vm.EVMLogger, commit bool, evmConfig *statedb.EVMConfig, txConfig statedb.TxConfig, fullRefundLeftoverGas bool, ) (resp *evm.MsgEthereumTxResponse, evmObj *vm.EVM, err error)
ApplyEvmMsg computes the new state by applying the given message against the existing state. If the message fails, the VM execution error with the reason will be returned to the client and the transaction won't be committed to the store.
Reverted state ¶
The snapshot and rollback are supported by the `statedb.StateDB`.
Different Callers ¶
It's called in three scenarios: 1. `ApplyTransaction`, in the transaction processing flow. 2. `EthCall/EthEstimateGas` grpc query handler. 3. Called by other native modules directly.
Prechecks and Preprocessing ¶
All relevant state transition prechecks for the MsgEthereumTx are performed on the AnteHandler, prior to running the transaction against the state. The prechecks run are the following:
1. the nonce of the message caller is correct 2. caller has enough balance to cover transaction fee(gaslimit * gasprice) 3. the amount of gas required is available in the block 4. the purchased gas is enough to cover intrinsic usage 5. there is no overflow when calculating intrinsic gas 6. caller has enough balance to cover asset transfer for **topmost** call
The preprocessing steps performed by the AnteHandler are:
1. set up the initial access list
# Tracer parameter It should be a `vm.Tracer` object or nil, if pass `nil`, it'll create a default one based on keeper options.
# Commit parameter If commit is true, the `StateDB` will be committed, otherwise discarded.
# fullRefundLeftoverGas parameter For internal calls like funtokens, user does not specify gas limit explicitly. In this case we don't apply any caps for refund and refund 100%
func (Keeper) Balance ¶
func (k Keeper) Balance(goCtx context.Context, req *evm.QueryBalanceRequest) (*evm.QueryBalanceResponse, error)
Balance: Implements the gRPC query for "/eth.evm.v1.Query/Balance". Balance retrieves the balance of an Ethereum address in "wei", the smallest unit of "Ether". Ether refers to NIBI tokens on Nibiru EVM.
Parameters:
- goCtx: The context.Context object representing the request context.
- req: The QueryBalanceRequest object containing the Ethereum address.
Returns:
- A pointer to the QueryBalanceResponse object containing the balance.
- An error if the balance retrieval process encounters any issues.
func (Keeper) BaseFee ¶
func (k Keeper) BaseFee( goCtx context.Context, _ *evm.QueryBaseFeeRequest, ) (*evm.QueryBaseFeeResponse, error)
BaseFee implements the Query/BaseFee gRPC method
func (Keeper) BaseFeeMicronibiPerGas ¶
BaseFeeMicronibiPerGas returns the gas base fee in units of the EVM denom. Note that this function is currently constant/stateless.
func (Keeper) BaseFeeWeiPerGas ¶
BaseFeeWeiPerGas is the same as BaseFeeMicronibiPerGas, except its in units of wei per gas.
func (*Keeper) BeginBlock ¶
func (k *Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock)
BeginBlock hook for the EVM module.
func (Keeper) CallContract ¶
func (k Keeper) CallContract( ctx sdk.Context, abi *gethabi.ABI, fromAcc gethcommon.Address, contract *gethcommon.Address, commit bool, gasLimit uint64, methodName string, args ...any, ) (evmResp *evm.MsgEthereumTxResponse, err error)
CallContract invokes a smart contract on the method specified by [methodName] using the given [args].
Parameters:
- ctx: The SDK context for the transaction.
- abi: The ABI (Application Binary Interface) of the smart contract.
- fromAcc: The Ethereum address of the account initiating the contract call.
- contract: Pointer to the Ethereum address of the contract to be called.
- commit: Boolean flag indicating whether to commit the transaction (true) or simulate it (false).
- methodName: The name of the contract method to be called.
- args: Variadic parameter for the arguments to be passed to the contract method.
Note: This function handles both contract method calls and simulations, depending on the 'commit' parameter.
func (Keeper) CallContractWithInput ¶
func (k Keeper) CallContractWithInput( ctx sdk.Context, fromAcc gethcommon.Address, contract *gethcommon.Address, commit bool, contractInput []byte, gasLimit uint64, ) (evmResp *evm.MsgEthereumTxResponse, evmObj *vm.EVM, err error)
CallContractWithInput invokes a smart contract with the given [contractInput] or deploys a new contract.
Parameters:
- ctx: The SDK context for the transaction.
- fromAcc: The Ethereum address of the account initiating the contract call.
- contract: Pointer to the Ethereum address of the contract. Nil if new contract is deployed.
- commit: Boolean flag indicating whether to commit the transaction (true) or simulate it (false).
- contractInput: Hexadecimal-encoded bytes use as input data to the call.
Note: This function handles both contract method calls and simulations, depending on the 'commit' parameter. It uses a default gas limit.
func (Keeper) Code ¶
func (k Keeper) Code( goCtx context.Context, req *evm.QueryCodeRequest, ) (*evm.QueryCodeResponse, error)
Code: Implements the gRPC query for "/eth.evm.v1.Query/Code". Code retrieves the smart contract bytecode associated with a given Ethereum address.
Parameters:
- goCtx: The context.Context object representing the request context.
- req: Request with the Ethereum address of the smart contract bytecode.
Returns:
- Response containing the smart contract bytecode.
- An error if the code retrieval process encounters any issues.
func (*Keeper) ConvertCoinToEvm ¶
func (k *Keeper) ConvertCoinToEvm( goCtx context.Context, msg *evm.MsgConvertCoinToEvm, ) (resp *evm.MsgConvertCoinToEvmResponse, err error)
ConvertCoinToEvm Sends a coin with a valid "FunToken" mapping to the given recipient address ("to_eth_addr") in the corresponding ERC20 representation.
func (*Keeper) CreateFunToken ¶
func (k *Keeper) CreateFunToken( goCtx context.Context, msg *evm.MsgCreateFunToken, ) (resp *evm.MsgCreateFunTokenResponse, err error)
CreateFunToken is a gRPC transaction message for creating fungible token ("FunToken") a mapping between a bank coin and ERC20 token.
If the mapping is generated from an ERC20, this tx creates a bank coin to go with it, and if the mapping's generated from a coin, the EVM module deploys an ERC20 contract that for which it will be the owner.
func (*Keeper) DeductTxCostsFromUserBalance ¶
func (k *Keeper) DeductTxCostsFromUserBalance( ctx sdk.Context, fees sdk.Coins, from gethcommon.Address, ) error
DeductTxCostsFromUserBalance deducts the fees from the user balance. Returns an error if the specified sender address does not exist or the account balance is not sufficient.
func (*Keeper) DeleteAccount ¶
DeleteAccount handles contract's suicide call, clearing the balance, contract bytecode, contract state, and its native account. Implements the `statedb.Keeper` interface. Only called by `StateDB.Commit()`.
func (Keeper) ERC20 ¶
func (k Keeper) ERC20() erc20Calls
ERC20 returns a mutable reference to the keeper with an ERC20 contract ABI and Go functions corresponding to contract calls in the ERC20 standard like "mint" and "transfer" in the ERC20 standard.
func (*Keeper) EmitEthereumTxEvents ¶
func (k *Keeper) EmitEthereumTxEvents( ctx sdk.Context, recipient *gethcommon.Address, txType uint8, msg gethcore.Message, evmResp *evm.MsgEthereumTxResponse, ) error
EmitEthereumTxEvents emits all types of EVM events applicable to a particular execution case
func (*Keeper) EmitLogEvents ¶
EmitLogEvents emits all types of EVM events applicable to a particular execution case
func (*Keeper) EndBlock ¶
func (k *Keeper) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate
EndBlock also retrieves the bloom filter value from the transient store and commits it to the
func (Keeper) EstimateGas ¶
func (k Keeper) EstimateGas( goCtx context.Context, req *evm.EthCallRequest, ) (*evm.EstimateGasResponse, error)
EstimateGas: Implements the gRPC query for "/eth.evm.v1.Query/EstimateGas". EstimateGas implements eth_estimateGas rpc api.
func (Keeper) EstimateGasForEvmCallType ¶
func (k Keeper) EstimateGasForEvmCallType( goCtx context.Context, req *evm.EthCallRequest, fromType evm.CallType, ) (*evm.EstimateGasResponse, error)
EstimateGasForEvmCallType estimates the gas cost of a transaction. This can be called with the "eth_estimateGas" JSON-RPC method or smart contract query.
When [EstimateGas] is called from the JSON-RPC client, we need to reset the gas meter before simulating the transaction (tx) to have an accurate gas estimate txs using EVM extensions.
Parameters:
- goCtx: The context.Context object representing the request context.
- req: The EthCallRequest object containing the transaction parameters.
Returns:
- A response containing the estimated gas cost.
- An error if the gas estimation process encounters any issues.
func (Keeper) EthAccount ¶
func (k Keeper) EthAccount( goCtx context.Context, req *evm.QueryEthAccountRequest, ) (*evm.QueryEthAccountResponse, error)
EthAccount: Implements the gRPC query for "/eth.evm.v1.Query/EthAccount". EthAccount retrieves the account and balance details for an account with the given address.
Parameters:
- goCtx: The context.Context object representing the request context.
- req: Request containing the address in either Ethereum hexadecimal or Bech32 format.
func (*Keeper) EthCall ¶
func (k *Keeper) EthCall( goCtx context.Context, req *evm.EthCallRequest, ) (*evm.MsgEthereumTxResponse, error)
EthCall: Implements the gRPC query for "/eth.evm.v1.Query/EthCall". EthCall performs a smart contract call using the eth_call JSON-RPC method.
An "eth_call" is a method from the Ethereum JSON-RPC specification that allows one to call a smart contract function without execution a transaction on the blockchain. This is useful for simulating transactions and for reading data from the chain using responses from smart contract calls.
Parameters:
- goCtx: Request context with information about the current block that serves as the main access point to the blockchain state.
- req: "eth_call" parameters to interact with a smart contract.
Returns:
- A pointer to the MsgEthereumTxResponse object containing the result of the eth_call.
- An error if the eth_call process encounters any issues.
func (*Keeper) EthereumTx ¶
func (k *Keeper) EthereumTx( goCtx context.Context, txMsg *evm.MsgEthereumTx, ) (evmResp *evm.MsgEthereumTxResponse, err error)
func (Keeper) FeeForCreateFunToken ¶
func (Keeper) FindERC20Metadata ¶
func (k Keeper) FindERC20Metadata( ctx sdk.Context, contract gethcommon.Address, ) (info *ERC20Metadata, err error)
FindERC20Metadata retrieves the metadata of an ERC20 token.
Parameters:
- ctx: The SDK context for the transaction.
- contract: The Ethereum address of the ERC20 contract.
Returns:
- info: ERC20Metadata containing name, symbol, and decimals.
- err: An error if metadata retrieval fails.
func (*Keeper) ForEachStorage ¶
func (k *Keeper) ForEachStorage( ctx sdk.Context, addr gethcommon.Address, stopIter func(key, value gethcommon.Hash) bool, )
ForEachStorage: Iterator over contract storage. Implements the `statedb.Keeper` interface.
func (Keeper) FunTokenMapping ¶
func (k Keeper) FunTokenMapping( goCtx context.Context, req *evm.QueryFunTokenMappingRequest, ) (*evm.QueryFunTokenMappingResponse, error)
func (Keeper) GetAccNonce ¶
GetAccNonce returns the sequence number of an account, returns 0 if not exists.
func (*Keeper) GetAccount ¶
GetAccount: Ethereum account getter for a statedb.Account. Implements the `statedb.Keeper` interface. Returns nil if the account does not exist or has the wrong type.
func (*Keeper) GetAccountOrEmpty ¶
GetAccountOrEmpty returns empty account if not exist, returns error if it's not `EthAccount`
func (*Keeper) GetAccountWithoutBalance ¶
func (k *Keeper) GetAccountWithoutBalance(ctx sdk.Context, addr gethcommon.Address) *statedb.Account
GetAccountWithoutBalance load nonce and codehash without balance, more efficient in cases where balance is not needed.
func (*Keeper) GetCode ¶
GetCode: Loads smart contract bytecode. Implements the `statedb.Keeper` interface.
func (Keeper) GetCoinbaseAddress ¶
func (k Keeper) GetCoinbaseAddress(ctx sdk.Context, proposerAddress sdk.ConsAddress) (common.Address, error)
GetCoinbaseAddress returns the block proposer's validator operator address. In Ethereum, the coinbase (or "benficiary") is the address that proposed the current block. It corresponds to the COINBASE op code.
func (*Keeper) GetEVMConfig ¶
func (*Keeper) GetEthIntrinsicGas ¶
func (k *Keeper) GetEthIntrinsicGas( ctx sdk.Context, msg core.Message, cfg *params.ChainConfig, isContractCreation bool, ) (uint64, error)
GetEthIntrinsicGas returns the intrinsic gas cost for the transaction
func (*Keeper) GetEvmGasBalance ¶
GetEvmGasBalance: Used in the EVM Ante Handler, "github.com/NibiruChain/nibiru/v2/app/evmante": Load account's balance of gas tokens for EVM execution in EVM denom units.
func (Keeper) GetHashFn ¶
func (k Keeper) GetHashFn(ctx sdk.Context) vm.GetHashFunc
GetHashFn implements vm.GetHashFunc for Ethermint. It handles 3 cases:
- The requested height matches the current height from context (and thus same epoch number)
- The requested height is from a previous height from the same chain epoch
- The requested height is from a height greater than the latest one
func (*Keeper) GetState ¶
func (k *Keeper) GetState(ctx sdk.Context, addr gethcommon.Address, stateKey gethcommon.Hash) gethcommon.Hash
GetState: Implements `statedb.Keeper` interface: Loads smart contract state.
func (*Keeper) IsPrecompile ¶
func (k *Keeper) IsPrecompile(addr gethcommon.Address) bool
func (Keeper) LoadERC20BigInt ¶
func (Keeper) LoadERC20Decimals ¶
func (Keeper) LoadERC20Name ¶
func (Keeper) LoadERC20String ¶
func (Keeper) LoadERC20Symbol ¶
func (*Keeper) NewEVM ¶
func (k *Keeper) NewEVM( ctx sdk.Context, msg core.Message, evmConfig *statedb.EVMConfig, tracer vm.EVMLogger, stateDB vm.StateDB, ) *vm.EVM
NewEVM generates a go-ethereum VM.
Args:
- ctx: Consensus and KV store info for the current block.
- msg: Ethereum message sent to a contract
- cfg: Encapsulates params required to construct an EVM.
- tracer: Collects execution traces for EVM transaction logging.
- stateDB: Holds the EVM state.
func (*Keeper) NewStateDB ¶
func (Keeper) Params ¶
func (k Keeper) Params( goCtx context.Context, _ *evm.QueryParamsRequest, ) (*evm.QueryParamsResponse, error)
Params: Implements the gRPC query for "/eth.evm.v1.Query/Params". Params retrieves the EVM module parameters.
Parameters:
- goCtx: The context.Context object representing the request context.
- req: The QueryParamsRequest object (unused).
Returns:
- A pointer to the QueryParamsResponse object containing the EVM module parameters.
- An error if the parameter retrieval process encounters any issues.
func (*Keeper) RefundGas ¶
func (k *Keeper) RefundGas( ctx sdk.Context, msgFrom gethcommon.Address, leftoverGas uint64, weiPerGas *big.Int, ) error
RefundGas transfers the leftover gas to the sender of the message.
func (*Keeper) ResetGasMeterAndConsumeGas ¶
ResetGasMeterAndConsumeGas reset first the gas meter consumed value to zero and set it back to the new value 'gasUsed'.
func (*Keeper) ResetTransientGasUsed ¶
ResetTransientGasUsed resets gas to prepare for the next block of execution. Called in an ante handler.
func (*Keeper) SetAccBalance ¶
func (k *Keeper) SetAccBalance( ctx sdk.Context, addr gethcommon.Address, amountEvmDenom *big.Int, ) error
SetAccBalance update account's balance, compare with current balance first, then decide to mint or burn. Implements the `statedb.Keeper` interface. Only called by `StateDB.Commit()`.
func (*Keeper) SetAccount ¶
func (k *Keeper) SetAccount( ctx sdk.Context, addr gethcommon.Address, account statedb.Account, ) error
SetAccount: Updates nonce, balance, and codeHash. Implements the `statedb.Keeper` interface. Only called by `StateDB.Commit()`.
func (*Keeper) SetCode ¶
SetCode: Setter for smart contract bytecode. Delete if code is empty. Implements the `statedb.Keeper` interface. Only called by `StateDB.Commit()`.
func (*Keeper) SetState ¶
func (k *Keeper) SetState( ctx sdk.Context, addr gethcommon.Address, stateKey gethcommon.Hash, stateValue []byte, )
SetState: Update contract storage, delete if value is empty. Implements the `statedb.Keeper` interface. Only called by `StateDB.Commit()`.
func (Keeper) Storage ¶
func (k Keeper) Storage( goCtx context.Context, req *evm.QueryStorageRequest, ) (*evm.QueryStorageResponse, error)
Storage: Implements the gRPC query for "/eth.evm.v1.Query/Storage". Storage retrieves the storage value for a given Ethereum address and key.
Parameters:
- goCtx: The context.Context object representing the request context.
- req: The QueryStorageRequest object containing the Ethereum address and key.
Returns:
- A pointer to the QueryStorageResponse object containing the storage value.
- An error if the storage retrieval process encounters any issues.
func (Keeper) TraceBlock ¶
func (k Keeper) TraceBlock( goCtx context.Context, req *evm.QueryTraceBlockRequest, ) (*evm.QueryTraceBlockResponse, error)
TraceBlock: Implements the gRPC query for "/eth.evm.v1.Query/TraceBlock". Configures a Nibiru EVM tracer that is used to "trace" and analyze the execution of transactions within a given block. Block information is read from the context (goCtx). [TraceBlock] is responsible iterates over each Eth transacion message and calls [TraceEthTxMsg] on it.
func (Keeper) TraceCall ¶
func (k Keeper) TraceCall( goCtx context.Context, req *evm.QueryTraceTxRequest, ) (*evm.QueryTraceTxResponse, error)
TraceCall configures a new tracer according to the provided configuration, and executes the given message in the provided environment. The return value will be tracer dependent.
func (*Keeper) TraceEthTxMsg ¶
func (k *Keeper) TraceEthTxMsg( ctx sdk.Context, cfg *statedb.EVMConfig, txConfig statedb.TxConfig, msg gethcore.Message, traceConfig *evm.TraceConfig, commitMessage bool, tracerJSONConfig json.RawMessage, ) (*any, uint, error)
TraceEthTxMsg do trace on one transaction, it returns a tuple: (traceResult, nextLogIndex, error).
func (Keeper) TraceTx ¶
func (k Keeper) TraceTx( goCtx context.Context, req *evm.QueryTraceTxRequest, ) (*evm.QueryTraceTxResponse, error)
TraceTx configures a new tracer according to the provided configuration, and executes the given message in the provided environment. The return value will be tracer dependent.
func (Keeper) Tracer ¶
func (k Keeper) Tracer( ctx sdk.Context, msg core.Message, ethCfg *gethparams.ChainConfig, ) vm.EVMLogger
Tracer return a default vm.Tracer based on current keeper state
func (*Keeper) UpdateParams ¶
func (k *Keeper) UpdateParams( goCtx context.Context, req *evm.MsgUpdateParams, ) (resp *evm.MsgUpdateParamsResponse, err error)
func (Keeper) VMConfig ¶
func (k Keeper) VMConfig( ctx sdk.Context, _ core.Message, cfg *statedb.EVMConfig, tracer vm.EVMLogger, ) vm.Config
VMConfig creates an EVM configuration from the debug setting and the extra EIPs enabled on the module parameters. The config generated uses the default JumpTable from the EVM.
func (Keeper) ValidatorAccount ¶
func (k Keeper) ValidatorAccount( goCtx context.Context, req *evm.QueryValidatorAccountRequest, ) (*evm.QueryValidatorAccountResponse, error)
ValidatorAccount: Implements the gRPC query for "/eth.evm.v1.Query/ValidatorAccount". ValidatorAccount retrieves the account details for a given validator consensus address.
Parameters:
- goCtx: The context.Context object representing the request context.
- req: Request containing the validator consensus address.
Returns:
- Response containing the account details.
- An error if the account retrieval process encounters any issues.
type NibiruBankKeeper ¶
type NibiruBankKeeper struct { bankkeeper.BaseKeeper StateDB *statedb.StateDB }
func (NibiruBankKeeper) SendCoins ¶
func (bk NibiruBankKeeper) SendCoins( ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, coins sdk.Coins, ) error
func (NibiruBankKeeper) SendCoinsFromAccountToModule ¶
func (bk NibiruBankKeeper) SendCoinsFromAccountToModule( ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, coins sdk.Coins, ) error
func (NibiruBankKeeper) SendCoinsFromModuleToAccount ¶
func (bk NibiruBankKeeper) SendCoinsFromModuleToAccount( ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, coins sdk.Coins, ) error
func (NibiruBankKeeper) SendCoinsFromModuleToModule ¶
func (*NibiruBankKeeper) SyncStateDBWithAccount ¶
func (bk *NibiruBankKeeper) SyncStateDBWithAccount( ctx sdk.Context, acc sdk.AccAddress, )