Skip to content

Commit

Permalink
update logic for UpdateDelegationBalances function (#547)
Browse files Browse the repository at this point in the history
Co-authored-by: sampocs <sam.pochyly@gmail.com>
  • Loading branch information
ThanhNhann and sampocs authored Feb 24, 2023
1 parent 7414ce9 commit c3df52d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions x/stakeibc/keeper/icacallbacks_undelegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,18 @@ func UndelegateCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, a
func (k Keeper) UpdateDelegationBalances(ctx sdk.Context, zone types.HostZone, undelegateCallback types.UndelegateCallback) error {
// Undelegate from each validator and update host zone staked balance, if successful
for _, undelegation := range undelegateCallback.SplitDelegations {
success := k.AddDelegationToValidator(ctx, zone, undelegation.Validator, undelegation.Amount.Neg(), ICACallbackID_Undelegate)
if !success {
return errorsmod.Wrapf(types.ErrValidatorDelegationChg, "Failed to remove delegation to validator")
}

if undelegation.Amount.GT(zone.StakedBal) {
// handle incoming underflow
// Once we add a killswitch, we should also stop liquid staking on the zone here
return errorsmod.Wrapf(types.ErrUndelegationAmount, "undelegation.Amount > zone.StakedBal, undelegation.Amount: %v, zone.StakedBal %v", undelegation.Amount, zone.StakedBal)
} else {
zone.StakedBal = zone.StakedBal.Sub(undelegation.Amount)
}

success := k.AddDelegationToValidator(ctx, zone, undelegation.Validator, undelegation.Amount.Neg(), ICACallbackID_Undelegate)
if !success {
return errorsmod.Wrapf(types.ErrValidatorDelegationChg, "Failed to remove delegation to validator")
}
}
k.SetHostZone(ctx, zone)
return nil
Expand Down

0 comments on commit c3df52d

Please sign in to comment.