Skip to content

Commit 96790da

Browse files
committed
fix: improve error handling for insufficient funds in ERC20 transfer
1 parent b52f3c3 commit 96790da

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

precompiles/erc20/tx.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import (
77
"github.com/ethereum/go-ethereum/common"
88
"github.com/ethereum/go-ethereum/core/vm"
99

10+
errorsmod "cosmossdk.io/errors"
1011
"cosmossdk.io/math"
1112

1213
cmn "github.com/cosmos/evm/precompiles/common"
1314

1415
sdk "github.com/cosmos/cosmos-sdk/types"
16+
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
1517
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
1618
)
1719

@@ -108,9 +110,9 @@ func (p *Precompile) transfer(
108110

109111
msgSrv := NewMsgServerImpl(p.BankKeeper)
110112
if err = msgSrv.Send(ctx, msg); err != nil {
111-
spendable := p.BankKeeper.SpendableCoin(ctx, from.Bytes(), p.tokenPair.Denom)
112-
bal := spendable.Amount.BigInt()
113-
if amount.Cmp(bal) > 0 {
113+
if errorsmod.IsOf(err, sdkerrors.ErrInsufficientFunds) {
114+
spendable := p.BankKeeper.SpendableCoin(ctx, from.Bytes(), p.tokenPair.Denom)
115+
bal := spendable.Amount.BigInt()
114116
return nil, cmn.NewRevertWithSolidityError(p.ABI, SolidityErrERC20InsufficientBalance, from, bal, amount)
115117
}
116118
return nil, cmn.NewRevertWithSolidityError(p.ABI, cmn.SolidityErrMsgServerFailed, method.Name, err.Error())

0 commit comments

Comments
 (0)