|
| 1 | +package v23 |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types" |
| 7 | + |
| 8 | + sdk "github.com/cosmos/cosmos-sdk/types" |
| 9 | + "github.com/cosmos/cosmos-sdk/types/module" |
| 10 | + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" |
| 11 | + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" |
| 12 | + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" |
| 13 | + |
| 14 | + "github.com/CosmosContracts/juno/v23/app/keepers" |
| 15 | + "github.com/CosmosContracts/juno/v23/app/upgrades" |
| 16 | +) |
| 17 | + |
| 18 | +type IndividualAccount struct { |
| 19 | + Owner string |
| 20 | + Address string |
| 21 | +} |
| 22 | + |
| 23 | +// Core1VestingAccounts https://daodao.zone/dao/juno1j6glql3xmrcnga0gytecsucq3kd88jexxamxg3yn2xnqhunyvflqr7lxx3/members |
| 24 | +// we are including only lobo, dimi and jake because the other ones do not agree on giving up their vesting |
| 25 | +var Core1VestingAccounts = []IndividualAccount{ |
| 26 | + { |
| 27 | + Owner: "dimi", |
| 28 | + Address: "juno1s33zct2zhhaf60x4a90cpe9yquw99jj0zen8pt", |
| 29 | + }, |
| 30 | + { |
| 31 | + Owner: "jake", |
| 32 | + Address: "juno18qw9ydpewh405w4lvmuhlg9gtaep79vy2gmtr2", |
| 33 | + }, |
| 34 | + { |
| 35 | + Owner: "wolf", |
| 36 | + Address: "juno1a8u47ggy964tv9trjxfjcldutau5ls705djqyu", |
| 37 | + }, |
| 38 | +} |
| 39 | + |
| 40 | +func CreateV23UpgradeHandler( |
| 41 | + mm *module.Manager, |
| 42 | + cfg module.Configurator, |
| 43 | + keepers *keepers.AppKeepers, |
| 44 | +) upgradetypes.UpgradeHandler { |
| 45 | + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { |
| 46 | + logger := ctx.Logger().With("upgrade", UpgradeName) |
| 47 | + |
| 48 | + nativeDenom := upgrades.GetChainsDenomToken(ctx.ChainID()) |
| 49 | + logger.Info(fmt.Sprintf("With native denom %s", nativeDenom)) |
| 50 | + |
| 51 | + // migrate ICQ params |
| 52 | + for _, subspace := range keepers.ParamsKeeper.GetSubspaces() { |
| 53 | + subspace := subspace |
| 54 | + |
| 55 | + var keyTable paramstypes.KeyTable |
| 56 | + if subspace.Name() == icqtypes.ModuleName { |
| 57 | + keyTable = icqtypes.ParamKeyTable() |
| 58 | + } else { |
| 59 | + continue |
| 60 | + } |
| 61 | + |
| 62 | + if !subspace.HasKeyTable() { |
| 63 | + subspace.WithKeyTable(keyTable) |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + // Run migrations |
| 68 | + logger.Info(fmt.Sprintf("pre migrate version map: %v", vm)) |
| 69 | + versionMap, err := mm.RunMigrations(ctx, cfg, vm) |
| 70 | + if err != nil { |
| 71 | + return nil, err |
| 72 | + } |
| 73 | + |
| 74 | + logger.Info(fmt.Sprintf("post migrate version map: %v", versionMap)) |
| 75 | + |
| 76 | + // convert pob builder account to an actual module account |
| 77 | + // during upgrade from v15 to v16 it wasn't correctly created, and since it received tokens on mainnet is now a base account |
| 78 | + // it's like this on both mainnet and uni |
| 79 | + if ctx.ChainID() == "juno-1" || ctx.ChainID() == "uni-6" { |
| 80 | + logger.Info("converting x/pob builder module account") |
| 81 | + |
| 82 | + address := sdk.MustAccAddressFromBech32("juno1ma4sw9m2nvtucny6lsjhh4qywvh86zdh5dlkd4") |
| 83 | + |
| 84 | + acc := keepers.AccountKeeper.NewAccount( |
| 85 | + ctx, |
| 86 | + authtypes.NewModuleAccount( |
| 87 | + authtypes.NewBaseAccountWithAddress(address), |
| 88 | + "builder", |
| 89 | + ), |
| 90 | + ) |
| 91 | + keepers.AccountKeeper.SetAccount(ctx, acc) |
| 92 | + |
| 93 | + logger.Info("x/pob builder module address is now a module account") |
| 94 | + } |
| 95 | + |
| 96 | + // only on mainnet and uni, migrate core1 vesting accounts |
| 97 | + if ctx.ChainID() == "juno-1" || ctx.ChainID() == "uni-6" { |
| 98 | + if err := migrateCore1VestingAccounts(ctx, keepers, nativeDenom); err != nil { |
| 99 | + return nil, err |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + return versionMap, err |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +// Migrate balances from the Core-1 vesting accounts to the Council SubDAO. |
| 108 | +func migrateCore1VestingAccounts(ctx sdk.Context, keepers *keepers.AppKeepers, bondDenom string) error { |
| 109 | + for _, account := range Core1VestingAccounts { |
| 110 | + if err := MoveVestingCoinFromVestingAccount(ctx, |
| 111 | + keepers, |
| 112 | + bondDenom, |
| 113 | + account.Owner, |
| 114 | + sdk.MustAccAddressFromBech32(account.Address), |
| 115 | + ); err != nil { |
| 116 | + return err |
| 117 | + } |
| 118 | + } |
| 119 | + return nil |
| 120 | +} |
0 commit comments