Skip to content

Commit

Permalink
fix: upgrade handler balances minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpioborn committed Mar 19, 2024
1 parent ce2aca5 commit 2246096
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/upgrades/v7/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ func CreateUpgradeHandler(

for _, sa := range allSubAccounts {
subAccAddr := sdk.MustAccAddressFromBech32(sa.Address)
accSumm, found := k.SubaccountKeeper.GetAccountSummary(ctx, subAccAddr)
accSummary, found := k.SubaccountKeeper.GetAccountSummary(ctx, subAccAddr)
if !found {
panic(fmt.Errorf("account summary for the subaccount not found %s", subAccAddr))
}

_, totalBalances := k.SubaccountKeeper.GetBalances(ctx, subAccAddr, subaccounttypes.BalanceType_BALANCE_TYPE_UNSPECIFIED)
bankBalance := k.BankKeeper.GetBalance(ctx, subAccAddr, params.DefaultBondDenom).Amount

totalBalanceDiff := accSumm.DepositedAmount.Sub(totalBalances)
missingBalance := sdkmath.MinInt(bankBalance, totalBalanceDiff)
totalBalanceDiff := accSummary.DepositedAmount.
Sub(accSummary.SpentAmount).
Sub(accSummary.LostAmount).
Sub(accSummary.WithdrawnAmount)
missingBalance := sdkmath.MinInt(bankBalance, totalBalanceDiff).Sub(totalBalances)
if missingBalance.GT(sdkmath.ZeroInt()) {
k.SubaccountKeeper.SetLockedBalances(ctx, subAccAddr, []subaccounttypes.LockedBalance{
{
Expand Down

0 comments on commit 2246096

Please sign in to comment.