-
Notifications
You must be signed in to change notification settings - Fork 610
/
Copy pathupgrades.go
117 lines (100 loc) · 3.76 KB
/
upgrades.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package v15
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/osmosis-labs/osmosis/v14/wasmbinding"
icqkeeper "github.com/strangelove-ventures/async-icq/v4/keeper"
icqtypes "github.com/strangelove-ventures/async-icq/v4/types"
packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/osmosis-labs/osmosis/v14/app/keepers"
appParams "github.com/osmosis-labs/osmosis/v14/app/params"
"github.com/osmosis-labs/osmosis/v14/app/upgrades"
gammkeeper "github.com/osmosis-labs/osmosis/v14/x/gamm/keeper"
"github.com/osmosis-labs/osmosis/v14/x/poolmanager"
poolmanagertypes "github.com/osmosis-labs/osmosis/v14/x/poolmanager/types"
)
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
bpm upgrades.BaseAppParamManager,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
poolmanagerParams := poolmanagertypes.NewParams(keepers.GAMMKeeper.GetParams(ctx).PoolCreationFee)
keepers.PoolManagerKeeper.SetParams(ctx, poolmanagerParams)
keepers.PacketForwardKeeper.SetParams(ctx, packetforwardtypes.DefaultParams())
setICQParams(ctx, keepers.ICQKeeper)
// N.B: pool id in gamm is to be deprecated in the future
// Instead,it is moved to poolmanager.
migrateNextPoolId(ctx, keepers.GAMMKeeper, keepers.PoolManagerKeeper)
// N.B.: this is done to avoid initializing genesis for poolmanager module.
// Otherwise, it would overwrite migrations with InitGenesis().
// See RunMigrations() for details.
fromVM[poolmanagertypes.ModuleName] = 0
// Metadata for uosmo and uion were missing prior to this upgrade.
// They are added in this upgrade.
registerOsmoIonMetadata(ctx, keepers.BankKeeper)
return mm.RunMigrations(ctx, configurator, fromVM)
}
}
func setICQParams(ctx sdk.Context, icqKeeper *icqkeeper.Keeper) {
icqparams := icqtypes.DefaultParams()
icqparams.AllowQueries = wasmbinding.GetStargateWhitelistedPaths()
// Adding SmartContractState query to allowlist
icqparams.AllowQueries = append(icqparams.AllowQueries, "/cosmwasm.wasm.v1.Query/SmartContractState")
icqKeeper.SetParams(ctx, icqparams)
}
func migrateNextPoolId(ctx sdk.Context, gammKeeper *gammkeeper.Keeper, poolmanagerKeeper *poolmanager.Keeper) {
// N.B: pool id in gamm is to be deprecated in the future
// Instead,it is moved to poolmanager.
// nolint: staticcheck
nextPoolId := gammKeeper.GetNextPoolId(ctx)
poolmanagerKeeper.SetNextPoolId(ctx, nextPoolId)
for poolId := uint64(1); poolId < nextPoolId; poolId++ {
poolType, err := gammKeeper.GetPoolType(ctx, poolId)
if err != nil {
panic(err)
}
poolmanagerKeeper.SetPoolRoute(ctx, poolId, poolType)
}
}
func registerOsmoIonMetadata(ctx sdk.Context, bankKeeper bankkeeper.Keeper) {
uosmoMetadata := banktypes.Metadata{
Description: "The native token of Osmosis",
DenomUnits: []*banktypes.DenomUnit{
{
Denom: appParams.BaseCoinUnit,
Exponent: 0,
Aliases: nil,
},
{
Denom: appParams.HumanCoinUnit,
Exponent: appParams.OsmoExponent,
Aliases: nil,
},
},
Base: appParams.BaseCoinUnit,
Display: appParams.HumanCoinUnit,
}
uionMetadata := banktypes.Metadata{
DenomUnits: []*banktypes.DenomUnit{
{
Denom: "uion",
Exponent: 0,
Aliases: nil,
},
{
Denom: "ion",
Exponent: 6,
Aliases: nil,
},
},
Base: "uion",
Display: "ion",
}
bankKeeper.SetDenomMetaData(ctx, uosmoMetadata)
bankKeeper.SetDenomMetaData(ctx, uionMetadata)
}