diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 90ec6038b4..1f00ef5814 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -326,7 +326,11 @@ func (k *Keeper) GetBalance(ctx sdk.Context, addr common.Address) *big.Int { if evmDenom == "" { return big.NewInt(-1) } - coin := k.bankKeeper.GetBalance(ctx, cosmosAddr, evmDenom) + + // Only spendable coin is considered as balance from EVM perspective. + // Locked coins are not shown in the balance to prevent misleading + // insufficient balance errors for users. + coin := k.bankKeeper.SpendableCoin(ctx, cosmosAddr, evmDenom) return coin.Amount.BigInt() } diff --git a/x/evm/keeper/statedb.go b/x/evm/keeper/statedb.go index c2cd893c5e..c78c059779 100644 --- a/x/evm/keeper/statedb.go +++ b/x/evm/keeper/statedb.go @@ -90,7 +90,11 @@ func (k *Keeper) SetBalance(ctx sdk.Context, addr common.Address, amount *big.In cosmosAddr := sdk.AccAddress(addr.Bytes()) params := k.GetParams(ctx) - coin := k.bankKeeper.GetBalance(ctx, cosmosAddr, params.EvmDenom) + + // Since spendable balances are fetched to get balances, when setting balances + // it should also compare with spendable coins as well to get the correct + // delta. + coin := k.bankKeeper.SpendableCoin(ctx, cosmosAddr, params.EvmDenom) balance := coin.Amount.BigInt() delta := new(big.Int).Sub(amount, balance) switch delta.Sign() { diff --git a/x/evm/types/interfaces.go b/x/evm/types/interfaces.go index caddeb78c9..98b25643d4 100644 --- a/x/evm/types/interfaces.go +++ b/x/evm/types/interfaces.go @@ -46,7 +46,7 @@ type AccountKeeper interface { // BankKeeper defines the expected interface needed to retrieve account balances. type BankKeeper interface { authtypes.BankKeeper - GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin + SpendableCoin(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error