Skip to content

Commit

Permalink
fix: calculate balanceDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 committed Feb 6, 2024
1 parent d2e5b51 commit 2b2911c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions app/upgrades/v4_1_0/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,17 @@ func processMigrateMultisig(ctx sdk.Context, stakingKeeper stakingKeeper.Keeper,

fmt.Printf("currentAddr Instant Redelegations: %s\n", redelegated)
fmt.Printf("currentAddr Instant Unbonding: %s\n", unbonded)
// get vested + reward balance
totalBalance := bankKeeper.GetBalance(ctx, currentAddr, params.BaseDenom)

// delegate vesting coin to validator
err = delegateToValidator(ctx, stakingKeeper, currentAddr, oldAcc.GetVestingCoins(ctx.BlockTime())[0].Amount)
if err != nil {
panic(err)
}

// get vested + reward balance
totalBalance := bankKeeper.GetBalance(ctx, currentAddr, params.BaseDenom)
fmt.Println("total balance before migration ", totalBalance)
balanceCanSend := totalBalance.Amount.Sub(oldAcc.GetVestingCoins(ctx.BlockTime())[0].Amount)

fmt.Printf("total balance send to new multisig addr: %s\n", balanceCanSend)
// send vested + reward balance no newAddr
err = bankKeeper.SendCoins(ctx, currentAddr, newAddr, sdk.NewCoins(sdk.NewCoin(params.BaseDenom, balanceCanSend)))
Expand Down Expand Up @@ -203,7 +202,8 @@ func delegateToValidator(ctx sdk.Context,
) error {
listValidator := stakingKeeper.GetBondedValidatorsByPower(ctx)
totalValidatorDelegate := math.Min(10, len(listValidator))
balanceDelegate := totalVestingBalance.Quo(totalVestingBalance)
balanceDelegate := totalVestingBalance.Quo(math.NewInt(int64(totalValidatorDelegate)))
fmt.Printf("balanceDelegate each validator %v, total validator %d\n", balanceDelegate, totalValidatorDelegate)

for i, validator := range listValidator {
if i >= totalValidatorDelegate {
Expand Down
6 changes: 4 additions & 2 deletions app/upgrades/v4_1_0/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ func (s *UpgradeTestSuite) TestUpgrade() {
// check old multisign address balance
oldMultisigBalance := s.App.BankKeeper.GetAllBalances(s.Ctx, sdk.MustAccAddressFromBech32(v4.NotionalMultisigVestingAccount))
fmt.Printf("Old multisign address Upgrade Balance: %s\n", oldMultisigBalance)
s.Require().True(oldMultisigBalance.AmountOf(params.BaseDenom).GTE(unvested))
totalDelegateBalance := s.App.StakingKeeper.GetDelegatorBonded(s.Ctx, sdk.MustAccAddressFromBech32(v4.NotionalMultisigVestingAccount))
fmt.Printf("old multisign address totalDelegateBalance %v\n", totalDelegateBalance)
s.Require().True(totalDelegateBalance.Add(oldMultisigBalance[0].Amount).GTE(unvested))

// check new multisign address balance
newBalance := s.App.BankKeeper.GetAllBalances(s.Ctx, sdk.MustAccAddressFromBech32(v4.NewNotionalMultisigAccount))
vestedBalance := cVesting.GetVestedCoins(s.Ctx.BlockTime())
fmt.Printf("New multisign Upgrade Balance: %s, vestedBalance %s\n", newBalance, vestedBalance)
s.Require().True(newBalance.AmountOf(params.BaseDenom).LTE(vestedBalance.AmountOf(params.BaseDenom)))
s.Require().True(vestedBalance.AmountOf(params.BaseDenom).GTE(newBalance.AmountOf(params.BaseDenom)))
}

func (s *UpgradeTestSuite) TestMath() {
Expand Down

0 comments on commit 2b2911c

Please sign in to comment.