Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Jan 11, 2024
1 parent ea64988 commit 7c073c8
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
24 changes: 24 additions & 0 deletions app/upgrades/v19/mainnet_account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package v19

import (
"encoding/json"

vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
)

// junod q auth account juno190g5j8aszqhvtg7cprmev8xcxs6csra7xnk3n3 --output=json
func CreateMainnetVestingAccount() *vestingtypes.PeriodicVestingAccount {

Check failure on line 11 in app/upgrades/v19/mainnet_account.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
// manually convert the account_number, sequence, start_time, end_time to a non string
// regex: "length":"([0-9]+)" -> "length":$1

str := `{"@type":"/cosmos.vesting.v1beta1.PeriodicVestingAccount","base_vesting_account":{"base_account":{"address":"juno190g5j8aszqhvtg7cprmev8xcxs6csra7xnk3n3","pub_key":{"@type":"/cosmos.crypto.multisig.LegacyAminoPubKey","threshold":3,"public_keys":[{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A+hZFIZ3i+5jD83trhShTmD/bAAXpIyb6tHJDJtiOAn6"},{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"ApcEus7fRKwSRNNs4nlOy62fFH9Ep7lg9DQRsnx9Ht0H"},{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A1SgSrlikj83agLUJPYDuWTjPkw4rPzkWgMMy/5RxANy"},{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A5fjV581bOBJSuHpBkY7ve3uZJFAv4JI14+K+RiHgr30"},{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Akr1IlYcH7p08W8pdYNkmAEvDRoPOXdOefg56cm3paKm"}]},"account_number":46159,"sequence":33},"original_vesting":[{"denom":"ujuno","amount":"12457737000000"}],"delegated_free":[{"denom":"ujuno","amount":"398745473523"}],"delegated_vesting":[{"denom":"ujuno","amount":"6404764327386"}],"end_time":2006348400},"start_time":1633100400,"vesting_periods":[{"length":0,"amount":[{"denom":"ujuno","amount":"2373341000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"294128000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"294128000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"294128000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"294128000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"294128000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"294128000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"294128000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"294128000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"294128000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"294128000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"294128000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"294128000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"147064000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"147064000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"147064000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"147064000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"147064000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"147064000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"147064000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"147064000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"147064000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"147064000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"147064000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"147064000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"73952000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"73952000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"73952000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"73952000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"73952000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"73952000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"73952000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"73952000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"73952000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"73952000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"73952000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"73952000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"66388000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"66388000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"66388000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"66388000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"66388000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"66388000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"66388000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"66388000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"66388000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"66388000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"66388000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"66388000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"58825000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"58825000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"58825000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"58825000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"58825000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"58825000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"58825000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"58825000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"58825000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"58825000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"58825000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"58825000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"51262000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"51262000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"51262000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"51262000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"51262000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"51262000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"51262000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"51262000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"51262000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"51262000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"51262000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"51262000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"43867000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"43867000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"43867000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"43867000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"43867000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"43867000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"43867000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"43867000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"43867000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"43867000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"43867000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"43867000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"36556000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"36556000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"36556000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"36556000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"36556000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"36556000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"36556000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"36556000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"36556000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"36556000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"36556000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"36556000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"29245000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"29245000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"29245000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"29245000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"29245000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"29245000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"29245000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"29245000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"29245000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"29245000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"29245000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"29245000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"21934000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"21934000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"21934000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"21934000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"21934000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"21934000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"21934000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"21934000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"21934000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"21934000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"21934000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"21934000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"14623000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"14623000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"14623000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"14623000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"14623000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"14623000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"14623000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"14623000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"14623000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"14623000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"14623000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"14623000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"2522000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"2522000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"2522000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"2522000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"2522000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"2522000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"2522000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"2522000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"2522000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"2522000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"2522000000"}]},{"length":2592000,"amount":[{"denom":"ujuno","amount":"2526000000"}]}]}`

var accStruct vestingtypes.PeriodicVestingAccount

if err := json.Unmarshal([]byte(str), &accStruct); err != nil {
panic(err)
}

return &accStruct
}
27 changes: 25 additions & 2 deletions app/upgrades/v19/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/CosmosContracts/juno/v19/app/apptesting"
decorators "github.com/CosmosContracts/juno/v19/app/decorators"
v19 "github.com/CosmosContracts/juno/v19/app/upgrades/v19"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
)

type UpgradeTestSuite struct {
Expand All @@ -27,16 +28,37 @@ func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

func (s *UpgradeTestSuite) setupMockCore1MultisigAccount() *vestingtypes.PeriodicVestingAccount {
core1Multisig := v19.CreateMainnetVestingAccount()
s.App.AppKeepers.AccountKeeper.SetAccount(s.Ctx, core1Multisig)
return core1Multisig
}

// Ensures the test does not error out.
func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup()

preUpgradeChecks(s)

// Core-1 account mock up
va := s.setupMockCore1MultisigAccount()
fmt.Println(va)

// delegate to a validator
valAddr1 := s.SetupValidator(stakingtypes.Bonded)
valAddr2 := s.SetupValidator(stakingtypes.Bonded)

Check failure on line 48 in app/upgrades/v19/upgrade_test.go

View workflow job for this annotation

GitHub Actions / test

valAddr2 declared and not used

Check failure on line 48 in app/upgrades/v19/upgrade_test.go

View workflow job for this annotation

GitHub Actions / lint

valAddr2 declared and not used
valAddr3 := s.SetupValidator(stakingtypes.Bonded)

Check failure on line 49 in app/upgrades/v19/upgrade_test.go

View workflow job for this annotation

GitHub Actions / test

valAddr3 declared and not used

Check failure on line 49 in app/upgrades/v19/upgrade_test.go

View workflow job for this annotation

GitHub Actions / lint

valAddr3 declared and not used

// delegate to a validator
s.DelegateToValidator(valAddr1, 1000000000)

Check failure on line 52 in app/upgrades/v19/upgrade_test.go

View workflow job for this annotation

GitHub Actions / test

s.DelegateToValidator undefined (type *UpgradeTestSuite has no field or method DelegateToValidator)

Check failure on line 52 in app/upgrades/v19/upgrade_test.go

View workflow job for this annotation

GitHub Actions / lint

s.DelegateToValidator undefined (type *UpgradeTestSuite has no field or method DelegateToValidator) (typecheck)

// upgrade
upgradeHeight := int64(5)
s.ConfirmUpgradeSucceeded(v19.UpgradeName, upgradeHeight)

postUpgradeChecks(s)

// TODO: check it was modified
updatedAcc := s.App.AppKeepers.AccountKeeper.GetAccount(s.Ctx, va.GetAddress())
fmt.Println(updatedAcc)
}

func preUpgradeChecks(s *UpgradeTestSuite) {
Expand Down Expand Up @@ -74,4 +96,5 @@ func postUpgradeChecks(s *UpgradeTestSuite) {
for _, validator := range validators {
s.Require().True(validator.Commission.MaxChangeRate.LTE(sdk.MustNewDecFromStr(decorators.MaxChangeRate)))
}

}
42 changes: 42 additions & 0 deletions app/upgrades/v19/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v19

import (
"fmt"
"time"

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

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/CosmosContracts/juno) --custom-order (gci)
wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"

Expand All @@ -12,6 +13,13 @@ import (
decorators "github.com/CosmosContracts/juno/v19/app/decorators"
"github.com/CosmosContracts/juno/v19/app/keepers"
"github.com/CosmosContracts/juno/v19/app/upgrades"
"github.com/cometbft/cometbft/libs/log"

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

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/CosmosContracts/juno) --custom-order (gci)
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
)

const (
Core1MultisigVestingAccount = "juno190g5j8aszqhvtg7cprmev8xcxs6csra7xnk3n3"
CharterCouncil = "juno1nmezpepv3lx45mndyctz2lzqxa6d9xzd2xumkxf7a6r4nxt0y95qypm6c0"
)

func CreateV19UpgradeHandler(
Expand Down Expand Up @@ -45,6 +53,9 @@ func CreateV19UpgradeHandler(
}
}

// TODO: ONLY DO THIS WITH MAINNET
migrateCore1Vesting(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)
params.AllowedClients = append(params.AllowedClients, wasmlctypes.Wasm)
Expand All @@ -53,3 +64,34 @@ func CreateV19UpgradeHandler(
return versionMap, err
}
}

func migrateCore1Vesting(ctx sdk.Context, logger log.Logger, k *keepers.AppKeepers) {

Check warning on line 68 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)
core1Acc := k.AccountKeeper.GetAccount(ctx, sdk.MustAccAddressFromBech32(Core1MultisigVestingAccount))

vestingAcc, ok := core1Acc.(*vestingtypes.PeriodicVestingAccount)
if !ok {
panic(fmt.Errorf("core1Acc.(*vestingtypes.PeriodicVestingAccount): %+v", core1Acc))
}
fmt.Println(vestingAcc)

// remove 1 hour from the current block time to ensure it is set
currTime := ctx.BlockTime().Sub(time.Time{}.Add(time.Hour))
totalTokens := uint64(0)

vestingAcc.EndTime = int64(currTime.Seconds())

// TODO: remove all delegations instantly from prop16 code

// sum all tokens
for _, period := range vestingAcc.VestingPeriods {
for _, coin := range period.Amount {
if coin.Denom == "ujuno" {
totalTokens += coin.Amount.Uint64()
}
}
}

totalTokens += vestingAcc.DelegatedVesting[0].Amount.Uint64()

fmt.Println(totalTokens)
}

0 comments on commit 7c073c8

Please sign in to comment.