From fe70928ac767f7bc416a38df058e047e2f777779 Mon Sep 17 00:00:00 2001 From: void* Date: Thu, 2 Nov 2023 11:11:55 +0000 Subject: [PATCH] Upgrade v0.11.3: NOMX token munic. infl. & creation if required (#336) --- app/app.go | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++- go.mod | 2 +- go.sum | 4 +-- 3 files changed, 79 insertions(+), 4 deletions(-) diff --git a/app/app.go b/app/app.go index baad74c9..1a73a094 100644 --- a/app/app.go +++ b/app/app.go @@ -719,6 +719,17 @@ func (app *App) GetSubspace(moduleName string) paramstypes.Subspace { } func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) { + const municipalInflationTargetAddress = "fetch1n8d5466h8he33uedc0vsgtahal0mrz55glre03" + + // NOTE(pb): The `fetchd-v0.10.7` upgrade handler *MUST* be present due to the mainnent, where this is the *LAST* + // executed upgrade. Presence of this handler is enforced by the `x/upgrade/abci.go#L31-L40` (see the + // https://github.com/fetchai/cosmos-sdk/blob/09cf7baf4297a30acd8d09d9db7dd97d79ffe008/x/upgrade/abci.go#L31-L40). + app.UpgradeKeeper.SetUpgradeHandler("fetchd-v0.10.7", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + return app.mm.RunMigrations(ctx, cfg, fromVM) + }) + + // NOTE(pb): The `v0.11.2` upgrade handler *MUST* be present due to Dorado-1 testnet, where this is the *LAST* + // executed upgrade. Please see the details in the NOTE above. app.UpgradeKeeper.SetUpgradeHandler("v0.11.2", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { mobixInfl, err := sdk.NewDecFromStr("0.03") if err != nil { @@ -726,8 +737,72 @@ func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) { } minter := app.MintKeeper.GetMinter(ctx) minter.MunicipalInflation = []*minttypes.MunicipalInflationPair{ - {Denom: "nanomobx", Inflation: minttypes.NewMunicipalInflation("fetch1n8d5466h8he33uedc0vsgtahal0mrz55glre03", mobixInfl)}, + {Denom: "nanomobx", Inflation: minttypes.NewMunicipalInflation(municipalInflationTargetAddress, mobixInfl)}, + } + + app.MintKeeper.SetMinter(ctx, minter) + + return app.mm.RunMigrations(ctx, cfg, fromVM) + }) + + app.UpgradeKeeper.SetUpgradeHandler("v0.11.3", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + // Introducing the NOMX token **IF** it does not exist yet: + const nomxDenom = "nanonomx" + const nomxName = "NOMX" + const nomxSupply = 1000000000000000000 // = 10^18 < 2^63 (max(int64)) + if !app.BankKeeper.HasSupply(ctx, nomxDenom) { + coinsToMint := sdk.NewCoins(sdk.NewInt64Coin(nomxDenom, nomxSupply)) + app.MintKeeper.MintCoins(ctx, coinsToMint) + + acc, err := sdk.AccAddressFromBech32(municipalInflationTargetAddress) + if err != nil { + panic(err) + } + + err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, acc, coinsToMint) + if err != nil { + panic(err) + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + minttypes.EventTypeMunicipalMint, + sdk.NewAttribute(minttypes.AttributeKeyDenom, nomxDenom), + sdk.NewAttribute(minttypes.AttributeKeyTargetAddr, municipalInflationTargetAddress), + sdk.NewAttribute(sdk.AttributeKeyAmount, coinsToMint.String()), + ), + ) + + nomxMetadata := banktypes.Metadata{ + Base: nomxDenom, + Name: nomxName, + Symbol: nomxName, + Display: nomxName, + Description: nomxName + " token", + DenomUnits: []*banktypes.DenomUnit{ + {Denom: nomxName, Exponent: 9, Aliases: nil}, + {Denom: "mnomx", Exponent: 6, Aliases: nil}, + {Denom: "unomx", Exponent: 3, Aliases: nil}, + {Denom: nomxDenom, Exponent: 0, Aliases: nil}, + }, + } + + app.BankKeeper.SetDenomMetaData(ctx, nomxMetadata) + } + + // Municipal Inflation for MOBX & NOMX tokens: + inflation, err := sdk.NewDecFromStr("0.03") + if err != nil { + return module.VersionMap{}, err + } + + minter := app.MintKeeper.GetMinter(ctx) + municipalInflation := minttypes.NewMunicipalInflation(municipalInflationTargetAddress, inflation) + minter.MunicipalInflation = []*minttypes.MunicipalInflationPair{ + {Denom: "nanomobx", Inflation: municipalInflation}, + {Denom: nomxDenom, Inflation: municipalInflation}, } + app.MintKeeper.SetMinter(ctx, minter) return app.mm.RunMigrations(ctx, cfg, fromVM) diff --git a/go.mod b/go.mod index 32d3950a..49769611 100644 --- a/go.mod +++ b/go.mod @@ -133,7 +133,7 @@ replace google.golang.org/grpc => google.golang.org/grpc v1.33.2 replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 -replace github.com/cosmos/cosmos-sdk => github.com/fetchai/cosmos-sdk v0.19.3-0.20231027022256-09cf7baf4297 +replace github.com/cosmos/cosmos-sdk => github.com/fetchai/cosmos-sdk v0.19.3 // This is to add support for Ledger Nano S-Plus on linux + new macOS // usb bus device enumeration (it needs to be reiterated here, even though diff --git a/go.sum b/go.sum index a83afb2d..ecf9d03f 100644 --- a/go.sum +++ b/go.sum @@ -228,8 +228,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ= github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/fetchai/cosmos-sdk v0.19.3-0.20231027022256-09cf7baf4297 h1:aifpDotvRF/5/Zn/nvMeDlTPh0pa3qRMUwGY6cGqHgU= -github.com/fetchai/cosmos-sdk v0.19.3-0.20231027022256-09cf7baf4297/go.mod h1:xLNanYMukOhNMWoGJyy6mIZQR+Sf2sIi2Mlq0BY5rCg= +github.com/fetchai/cosmos-sdk v0.19.3 h1:9cTSRmLRl8g7AbEf3CBT/bT/NhC1VbKcgRu8e0CxU5o= +github.com/fetchai/cosmos-sdk v0.19.3/go.mod h1:xLNanYMukOhNMWoGJyy6mIZQR+Sf2sIi2Mlq0BY5rCg= github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=