@@ -7,11 +7,10 @@ import (
77 "cosmossdk.io/errors"
88 sdk "github.com/cosmos/cosmos-sdk/types"
99 sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
10- gethcommon "github.com/ethereum/go-ethereum/common"
1110 gethcore "github.com/ethereum/go-ethereum/core/types"
1211
12+ "github.com/NibiruChain/nibiru/v2/eth"
1313 "github.com/NibiruChain/nibiru/v2/x/evm"
14- "github.com/NibiruChain/nibiru/v2/x/evm/statedb"
1514)
1615
1716// CanTransferDecorator checks if the sender is allowed to transfer funds according to the EVM block
@@ -25,7 +24,6 @@ type CanTransferDecorator struct {
2524func (ctd CanTransferDecorator ) AnteHandle (
2625 ctx sdk.Context , tx sdk.Tx , simulate bool , next sdk.AnteHandler ,
2726) (sdk.Context , error ) {
28- params := ctd .GetParams (ctx )
2927 ethCfg := evm .EthereumConfig (ctd .EVMKeeper .EthChainID (ctx ))
3028 signer := gethcore .MakeSigner (ethCfg , big .NewInt (ctx .BlockHeight ()))
3129
@@ -40,7 +38,7 @@ func (ctd CanTransferDecorator) AnteHandle(
4038
4139 baseFeeWeiPerGas := evm .NativeToWei (ctd .EVMKeeper .BaseFeeMicronibiPerGas (ctx ))
4240
43- coreMsg , err := msgEthTx .AsMessage (signer , baseFeeWeiPerGas )
41+ evmMsg , err := msgEthTx .AsMessage (signer , baseFeeWeiPerGas )
4442 if err != nil {
4543 return ctx , errors .Wrapf (
4644 err ,
@@ -59,37 +57,27 @@ func (ctd CanTransferDecorator) AnteHandle(
5957 return ctx , errors .Wrapf (
6058 sdkerrors .ErrInsufficientFee ,
6159 "gas fee cap (wei) less than block base fee (wei); (%s < %s)" ,
62- coreMsg .GasFeeCap (), baseFeeWeiPerGas ,
60+ evmMsg .GasFeeCap (), baseFeeWeiPerGas ,
6361 )
6462 }
6563
66- cfg := & statedb.EVMConfig {
67- ChainConfig : ethCfg ,
68- Params : params ,
69- // Note that we use an empty coinbase here because the field is not
70- // used during this Ante Handler.
71- BlockCoinbase : gethcommon.Address {},
72- BaseFeeWei : baseFeeWeiPerGas ,
73- }
74-
75- stateDB := ctd .NewStateDB (
76- ctx ,
77- statedb .NewEmptyTxConfig (gethcommon .BytesToHash (ctx .HeaderHash ().Bytes ())),
78- )
79- evmInstance := ctd .EVMKeeper .NewEVM (ctx , coreMsg , cfg , evm .NewNoOpTracer (), stateDB )
80-
8164 // check that caller has enough balance to cover asset transfer for **topmost** call
8265 // NOTE: here the gas consumed is from the context with the infinite gas meter
83- if coreMsg .Value ().Sign () > 0 &&
84- ! evmInstance .Context .CanTransfer (stateDB , coreMsg .From (), coreMsg .Value ()) {
85- balanceWei := stateDB .GetBalance (coreMsg .From ())
86- return ctx , errors .Wrapf (
87- sdkerrors .ErrInsufficientFunds ,
88- "failed to transfer %s wei (balance=%s) from address %s using the EVM block context transfer function" ,
89- coreMsg .Value (),
90- balanceWei ,
91- coreMsg .From (),
92- )
66+
67+ if evmMsg .Value ().Sign () > 0 {
68+ nibiruAddr := eth .EthAddrToNibiruAddr (evmMsg .From ())
69+ balanceNative := ctd .Bank .GetBalance (ctx , nibiruAddr , evm .EVMBankDenom ).Amount .BigInt ()
70+ balanceWei := evm .NativeToWei (balanceNative )
71+
72+ if balanceWei .Cmp (evmMsg .Value ()) < 0 {
73+ return ctx , errors .Wrapf (
74+ sdkerrors .ErrInsufficientFunds ,
75+ "failed to transfer %s wei ( balance=%s )from address %s using the EVM block context transfer function" ,
76+ evmMsg .Value (),
77+ balanceWei ,
78+ evmMsg .From (),
79+ )
80+ }
9381 }
9482 }
9583
0 commit comments