Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Jan 12, 2024
1 parent 6b6b82d commit 4e21099
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 32 deletions.
4 changes: 0 additions & 4 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ func (s *KeeperTestHelper) SetupValidator(bondStatus stakingtypes.BondStatus) sd
)
s.App.AppKeepers.SlashingKeeper.SetValidatorSigningInfo(s.Ctx, consAddr, signingInfo)

// set some rewards (else you get a reference error)
// s.AllocateRewardsToValidator(val.GetOperator(), sdk.NewInt(1_000_000))

return valAddr
}

Expand Down Expand Up @@ -238,7 +235,6 @@ func (s *KeeperTestHelper) AllocateRewardsToValidator(valAddr sdk.ValAddress, re
// allocate rewards to validator
s.Ctx = s.Ctx.WithBlockHeight(s.Ctx.BlockHeight() + 1)
decTokens := sdk.DecCoins{{Denom: appparams.BondDenom, Amount: sdk.NewDec(rewardAmt.Int64() * 2)}}
// s.App.AppKeepers.DistrKeeper.AllocateTokensToValidator(s.Ctx, validator, decTokens)

s.App.AppKeepers.DistrKeeper.GetValidatorHistoricalRewards(s.Ctx, validator.GetOperator(), 0)
s.App.AppKeepers.DistrKeeper.SetValidatorHistoricalRewards(s.Ctx, validator.GetOperator(), 1, distrtypes.NewValidatorHistoricalRewards(decTokens, 2))
Expand Down
12 changes: 5 additions & 7 deletions app/upgrades/v19/mainnet_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
)

const (
// based off some mintscan data, this is JUST for testing.
AvaliableCoins = "2176229.301554"
DelegatedCoins = "6803271.425657"
StakingRewardCoins = "909613.203388"
// based off some mintscan data, this is JUST for testing. (ujuno)
AvaliableCoins = 2176229301554
DelegatedCoins = 6803271425657
StakingRewardCoins = 909613203388
)

// junod q auth account juno190g5j8aszqhvtg7cprmev8xcxs6csra7xnk3n3 --output=json
Expand All @@ -32,11 +32,9 @@ func CreateMainnetVestingAccount(ctx sdk.Context, k keepers.AppKeepers) (*vestin
panic(err)
}

// sum unvested token periods. We need to know this to mint to the charter (since we are removing the multisig vesting)

unvested := SumPeriodVestingAccountsUnvestedTokensAmount(&acc)

err := banktestutil.FundAccount(k.BankKeeper, ctx, acc.BaseAccount.GetAddress(), sdk.NewCoins(sdk.NewCoin("ujuno", unvested)))
err := banktestutil.FundAccount(k.BankKeeper, ctx, acc.BaseAccount.GetAddress(), sdk.NewCoins(sdk.NewCoin("ujuno", math.NewInt(AvaliableCoins+DelegatedCoins+StakingRewardCoins))))
if err != nil {
panic(err)
}
Expand Down
17 changes: 6 additions & 11 deletions app/upgrades/v19/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,21 @@ func (s *UpgradeTestSuite) TestUpgrade() {
// Core-1 Multisig mock
c1m, unvested := v19.CreateMainnetVestingAccount(s.Ctx, s.App.AppKeepers)
c1mAddr := c1m.GetAddress()
// TODO: mint this to the council since we are 'burning' it from the multisig (by setting to a base account)
fmt.Printf("c1mAddr unvested: %+v\n", unvested)

bal := s.App.AppKeepers.BankKeeper.GetAllBalances(s.Ctx, c1mAddr)
fmt.Printf("bal: %s\n", bal)
core1Prebal := s.App.AppKeepers.BankKeeper.GetAllBalances(s.Ctx, c1mAddr)
fmt.Printf("Core1 bal: %s\n", core1Prebal)

// create many validators to confirm the unbonding code works
newVal1 := s.SetupValidator(stakingtypes.Bonded)
newVal2 := s.SetupValidator(stakingtypes.Bonded)
newVal3 := s.SetupValidator(stakingtypes.Bonded)

// Delegate 6 tokens of the core1 multisig account
// Delegate tokens of the core1 multisig account
s.StakingHelper.Delegate(c1mAddr, newVal1, sdk.NewInt(1))
s.StakingHelper.Delegate(c1mAddr, newVal2, sdk.NewInt(2))
s.StakingHelper.Delegate(c1mAddr, newVal3, sdk.NewInt(3))

// Verify delegations
dels := s.App.AppKeepers.StakingKeeper.GetAllDelegatorDelegations(s.Ctx, c1mAddr)
s.Require().Equal(3, len(dels))
s.Require().Equal(3, len(s.App.AppKeepers.StakingKeeper.GetAllDelegatorDelegations(s.Ctx, c1mAddr)))

// == UPGRADE ==
upgradeHeight := int64(5)
Expand All @@ -77,10 +73,9 @@ func (s *UpgradeTestSuite) TestUpgrade() {
s.Require().Equal(0, len(s.App.AppKeepers.BankKeeper.GetAllBalances(s.Ctx, c1mAddr)))
s.Require().Equal(0, len(s.App.AppKeepers.StakingKeeper.GetAllDelegatorDelegations(s.Ctx, c1mAddr)))

// query balance of CharterCouncil
charterBal := s.App.AppKeepers.BankKeeper.GetAllBalances(s.Ctx, sdk.MustAccAddressFromBech32(v19.CharterCouncil))
fmt.Printf("charterBal: %s\n", charterBal) // this should == the vesting

fmt.Printf("Council Post Upgrade Balance: %s\n", charterBal) // this should be >= unvested + balance before the upgrade
s.Require().True(charterBal.AmountOf("ujuno").GTE(unvested.Add(core1Prebal.AmountOf("ujuno"))))
}

func preUpgradeChecks(s *UpgradeTestSuite) {
Expand Down
22 changes: 12 additions & 10 deletions app/upgrades/v19/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ func CreateV19UpgradeHandler(
}
}

// TODO: ONLY DO THIS WITH MAINNET
migrateCore1MultisigVesting(ctx, logger, k)
if nativeDenom == "ujuno" {
// Mainnet Only
migrateCore1MultisigVesting(ctx, logger, k)
}

// https://github.com/cosmos/ibc-go/blob/main/docs/docs/03-light-clients/04-wasm/03-integration.md
params := k.IBCKeeper.ClientKeeper.GetParams(ctx)
Expand All @@ -61,9 +63,11 @@ func CreateV19UpgradeHandler(
}
}

// migrateCore1Vesting moves the funds and delegations from the PeriodicVestingAccount -> the Council.
// All redelegations and unbonds are completed, and returned to the multisigs balance.
// Finally, the remaining vested tokens are minted, sent to the council, and the vesting account is removed.
// migrateCore1Vesting moves the funds and delegations from the PeriodicVestingAccount -> the new Council (contract address).
// - Get the Core-1 multisig vesting account
// - Instantly finish all redelegations, then unbond all tokens.
// - Send all tokens to the new council (including the previously held balance)
// - Sum all future vesting periods, then mint and send those tokens to the new council.
func migrateCore1MultisigVesting(ctx sdk.Context, logger log.Logger, k *keepers.AppKeepers) {

Check warning on line 71 in app/upgrades/v19/upgrades.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'logger' seems to be unused, consider removing or renaming it as _ (revive)
Core1Addr := sdk.MustAccAddressFromBech32(Core1MultisigVestingAccount)
CouncilAddr := sdk.MustAccAddressFromBech32(CharterCouncil)
Expand All @@ -81,7 +85,7 @@ func migrateCore1MultisigVesting(ctx sdk.Context, logger log.Logger, k *keepers.
// MINT UNVESTED TOKENS TO THE CHARTER
mintUnvestedToCharter(ctx, k, CouncilAddr, vestingAcc)

// REMOVE VESTING FROM THE CORE1 MULTISIG (set it to the base account)
// REMOVE VESTING FROM THE CORE1 MULTISIG (set it to the base account, no vesting terms)
k.AccountKeeper.SetAccount(ctx, vestingAcc.BaseAccount)
}

Expand All @@ -101,9 +105,6 @@ func mintUnvestedToCharter(ctx sdk.Context, k *keepers.AppKeepers, CouncilAddr s
}

func prop16Core1Multisig(ctx sdk.Context, k *keepers.AppKeepers, Core1Addr, CouncilAddr sdk.AccAddress) {

Check failure on line 107 in app/upgrades/v19/upgrades.go

View workflow job for this annotation

GitHub Actions / lint

captLocal: `Core1Addr' should not be capitalized (gocritic)
// undelegate all tokens from the core1 multisig
// - complete pending redelegations
// - unbond all tokens -> balance
redelegated, err := completeAllRedelegations(ctx, ctx.BlockTime(), k, Core1Addr)
if err != nil {
panic(err)
Expand All @@ -119,7 +120,7 @@ func prop16Core1Multisig(ctx sdk.Context, k *keepers.AppKeepers, Core1Addr, Coun
fmt.Printf("Core1Addr Instant Redelegations: %s\n", redelegated)
fmt.Printf("Core1Addr Instant Unbonding: %s\n", unbonded)

// now send these to the charter council
// now send these to the council
err = k.BankKeeper.SendCoins(ctx, Core1Addr, CouncilAddr, sdk.NewCoins(k.BankKeeper.GetBalance(ctx, Core1Addr, "ujuno")))
if err != nil {
panic(err)
Expand Down Expand Up @@ -150,6 +151,7 @@ func completeAllRedelegations(ctx sdk.Context, now time.Time, keepers *keepers.A
return redelegatedAmt, nil
}

// From Prop16
func unbondAllAndFinish(ctx sdk.Context, now time.Time, keepers *keepers.AppKeepers, accAddr sdk.AccAddress) (math.Int, error) {
unbondedAmt := math.ZeroInt()

Expand Down

0 comments on commit 4e21099

Please sign in to comment.