Skip to content

Commit fe70928

Browse files
authored
Upgrade v0.11.3: NOMX token munic. infl. & creation if required (#336)
1 parent 9dd34ea commit fe70928

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed

app/app.go

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,15 +719,90 @@ func (app *App) GetSubspace(moduleName string) paramstypes.Subspace {
719719
}
720720

721721
func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) {
722+
const municipalInflationTargetAddress = "fetch1n8d5466h8he33uedc0vsgtahal0mrz55glre03"
723+
724+
// NOTE(pb): The `fetchd-v0.10.7` upgrade handler *MUST* be present due to the mainnent, where this is the *LAST*
725+
// executed upgrade. Presence of this handler is enforced by the `x/upgrade/abci.go#L31-L40` (see the
726+
// https://github.com/fetchai/cosmos-sdk/blob/09cf7baf4297a30acd8d09d9db7dd97d79ffe008/x/upgrade/abci.go#L31-L40).
727+
app.UpgradeKeeper.SetUpgradeHandler("fetchd-v0.10.7", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
728+
return app.mm.RunMigrations(ctx, cfg, fromVM)
729+
})
730+
731+
// NOTE(pb): The `v0.11.2` upgrade handler *MUST* be present due to Dorado-1 testnet, where this is the *LAST*
732+
// executed upgrade. Please see the details in the NOTE above.
722733
app.UpgradeKeeper.SetUpgradeHandler("v0.11.2", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
723734
mobixInfl, err := sdk.NewDecFromStr("0.03")
724735
if err != nil {
725736
return module.VersionMap{}, err
726737
}
727738
minter := app.MintKeeper.GetMinter(ctx)
728739
minter.MunicipalInflation = []*minttypes.MunicipalInflationPair{
729-
{Denom: "nanomobx", Inflation: minttypes.NewMunicipalInflation("fetch1n8d5466h8he33uedc0vsgtahal0mrz55glre03", mobixInfl)},
740+
{Denom: "nanomobx", Inflation: minttypes.NewMunicipalInflation(municipalInflationTargetAddress, mobixInfl)},
741+
}
742+
743+
app.MintKeeper.SetMinter(ctx, minter)
744+
745+
return app.mm.RunMigrations(ctx, cfg, fromVM)
746+
})
747+
748+
app.UpgradeKeeper.SetUpgradeHandler("v0.11.3", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
749+
// Introducing the NOMX token **IF** it does not exist yet:
750+
const nomxDenom = "nanonomx"
751+
const nomxName = "NOMX"
752+
const nomxSupply = 1000000000000000000 // = 10^18 < 2^63 (max(int64))
753+
if !app.BankKeeper.HasSupply(ctx, nomxDenom) {
754+
coinsToMint := sdk.NewCoins(sdk.NewInt64Coin(nomxDenom, nomxSupply))
755+
app.MintKeeper.MintCoins(ctx, coinsToMint)
756+
757+
acc, err := sdk.AccAddressFromBech32(municipalInflationTargetAddress)
758+
if err != nil {
759+
panic(err)
760+
}
761+
762+
err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, acc, coinsToMint)
763+
if err != nil {
764+
panic(err)
765+
}
766+
767+
ctx.EventManager().EmitEvent(
768+
sdk.NewEvent(
769+
minttypes.EventTypeMunicipalMint,
770+
sdk.NewAttribute(minttypes.AttributeKeyDenom, nomxDenom),
771+
sdk.NewAttribute(minttypes.AttributeKeyTargetAddr, municipalInflationTargetAddress),
772+
sdk.NewAttribute(sdk.AttributeKeyAmount, coinsToMint.String()),
773+
),
774+
)
775+
776+
nomxMetadata := banktypes.Metadata{
777+
Base: nomxDenom,
778+
Name: nomxName,
779+
Symbol: nomxName,
780+
Display: nomxName,
781+
Description: nomxName + " token",
782+
DenomUnits: []*banktypes.DenomUnit{
783+
{Denom: nomxName, Exponent: 9, Aliases: nil},
784+
{Denom: "mnomx", Exponent: 6, Aliases: nil},
785+
{Denom: "unomx", Exponent: 3, Aliases: nil},
786+
{Denom: nomxDenom, Exponent: 0, Aliases: nil},
787+
},
788+
}
789+
790+
app.BankKeeper.SetDenomMetaData(ctx, nomxMetadata)
791+
}
792+
793+
// Municipal Inflation for MOBX & NOMX tokens:
794+
inflation, err := sdk.NewDecFromStr("0.03")
795+
if err != nil {
796+
return module.VersionMap{}, err
797+
}
798+
799+
minter := app.MintKeeper.GetMinter(ctx)
800+
municipalInflation := minttypes.NewMunicipalInflation(municipalInflationTargetAddress, inflation)
801+
minter.MunicipalInflation = []*minttypes.MunicipalInflationPair{
802+
{Denom: "nanomobx", Inflation: municipalInflation},
803+
{Denom: nomxDenom, Inflation: municipalInflation},
730804
}
805+
731806
app.MintKeeper.SetMinter(ctx, minter)
732807

733808
return app.mm.RunMigrations(ctx, cfg, fromVM)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ replace google.golang.org/grpc => google.golang.org/grpc v1.33.2
133133

134134
replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
135135

136-
replace github.com/cosmos/cosmos-sdk => github.com/fetchai/cosmos-sdk v0.19.3-0.20231027022256-09cf7baf4297
136+
replace github.com/cosmos/cosmos-sdk => github.com/fetchai/cosmos-sdk v0.19.3
137137

138138
// This is to add support for Ledger Nano S-Plus on linux + new macOS
139139
// usb bus device enumeration (it needs to be reiterated here, even though

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
228228
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
229229
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
230230
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
231-
github.com/fetchai/cosmos-sdk v0.19.3-0.20231027022256-09cf7baf4297 h1:aifpDotvRF/5/Zn/nvMeDlTPh0pa3qRMUwGY6cGqHgU=
232-
github.com/fetchai/cosmos-sdk v0.19.3-0.20231027022256-09cf7baf4297/go.mod h1:xLNanYMukOhNMWoGJyy6mIZQR+Sf2sIi2Mlq0BY5rCg=
231+
github.com/fetchai/cosmos-sdk v0.19.3 h1:9cTSRmLRl8g7AbEf3CBT/bT/NhC1VbKcgRu8e0CxU5o=
232+
github.com/fetchai/cosmos-sdk v0.19.3/go.mod h1:xLNanYMukOhNMWoGJyy6mIZQR+Sf2sIi2Mlq0BY5rCg=
233233
github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
234234
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
235235
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=

0 commit comments

Comments
 (0)