diff --git a/x/stakeibc/keeper/icacallbacks_undelegate.go b/x/stakeibc/keeper/icacallbacks_undelegate.go index ecb8300fa..3ab97162a 100644 --- a/x/stakeibc/keeper/icacallbacks_undelegate.go +++ b/x/stakeibc/keeper/icacallbacks_undelegate.go @@ -120,7 +120,13 @@ func (k Keeper) UpdateDelegationBalances(ctx sdk.Context, zone types.HostZone, u if !success { return sdkerrors.Wrapf(types.ErrValidatorDelegationChg, "Failed to remove delegation to validator") } - zone.StakedBal -= undelegation.Amount + if undelegation.Amount > zone.StakedBal { + // handle incoming underflow + // Once we add a killswitch, we should also stop liquid staking on the zone here + return sdkerrors.Wrapf(types.ErrUndelegationAmount, "undelegation.Amount > zone.StakedBal, undelegation.Amount: %d, zone.StakedBal %d", undelegation.Amount, zone.StakedBal) + } else { + zone.StakedBal -= undelegation.Amount + } } k.SetHostZone(ctx, zone) return nil diff --git a/x/stakeibc/types/errors.go b/x/stakeibc/types/errors.go index 062151529..d2de73ee6 100644 --- a/x/stakeibc/types/errors.go +++ b/x/stakeibc/types/errors.go @@ -47,4 +47,5 @@ var ( ErrHostZoneICAAccountNotFound = sdkerrors.Register(ModuleName, 1537, "host zone's ICA account not found") ErrNoValidatorAmts = sdkerrors.Register(ModuleName, 1538, "could not fetch validator amts") ErrMaxNumValidators = sdkerrors.Register(ModuleName, 1539, "max number of validators reached") + ErrUndelegationAmount = sdkerrors.Register(ModuleName, 1540, "Undelegation amount is greater than stakedBal") )