Skip to content

Commit

Permalink
feat: integrate florin (noble-assets#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnletey authored Aug 30, 2024
1 parent 2c3866f commit 59619a1
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 31 deletions.
36 changes: 28 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/noble-assets/noble/v7/app/upgrades/xenon"
"github.com/noble-assets/noble/v7/app/upgrades/numus"
"github.com/noble-assets/noble/v7/cmd"
"github.com/noble-assets/noble/v7/docs"
"github.com/noble-assets/noble/v7/x/globalfee"
Expand All @@ -120,6 +120,10 @@ import (
"github.com/noble-assets/halo/x/halo"
halokeeper "github.com/noble-assets/halo/x/halo/keeper"
halotypes "github.com/noble-assets/halo/x/halo/types"

"github.com/noble-assets/florin/x/florin"
florinkeeper "github.com/noble-assets/florin/x/florin/keeper"
florintypes "github.com/noble-assets/florin/x/florin/types"
)

const (
Expand Down Expand Up @@ -165,6 +169,7 @@ var (
forwarding.AppModuleBasic{},
aura.AppModuleBasic{},
halo.AppModuleBasic{},
florin.AppModuleBasic{},
)

// module account permissions
Expand All @@ -180,6 +185,7 @@ var (
cctptypes.ModuleName: nil,
auratypes.ModuleName: {authtypes.Burner, authtypes.Minter},
halotypes.ModuleName: {authtypes.Burner, authtypes.Minter},
florintypes.ModuleName: {authtypes.Burner, authtypes.Minter},
}
)

Expand Down Expand Up @@ -246,6 +252,7 @@ type App struct {
ForwardingKeeper *forwardingkeeper.Keeper
AuraKeeper *aurakeeper.Keeper
HaloKeeper *halokeeper.Keeper
FlorinKeeper *florinkeeper.Keeper

// this line is used by starport scaffolding # stargate/app/keeperDeclaration

Expand Down Expand Up @@ -284,7 +291,7 @@ func New(
paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey,
ibctransfertypes.StoreKey, icahosttypes.StoreKey, capabilitytypes.StoreKey,
tokenfactorymoduletypes.StoreKey, fiattokenfactorymoduletypes.StoreKey, packetforwardtypes.StoreKey, stakingtypes.StoreKey,
cctptypes.StoreKey, forwardingtypes.StoreKey, auratypes.ModuleName, halotypes.ModuleName,
cctptypes.StoreKey, forwardingtypes.StoreKey, auratypes.ModuleName, halotypes.ModuleName, florintypes.ModuleName,
)
tkeys := sdk.NewTransientStoreKeys(
paramstypes.TStoreKey,
Expand Down Expand Up @@ -359,6 +366,12 @@ func New(
interfaceRegistry,
)

app.FlorinKeeper = florinkeeper.NewKeeper(
keys[florintypes.ModuleName],
app.AccountKeeper,
nil,
)

app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec,
keys[banktypes.StoreKey],
Expand All @@ -367,9 +380,11 @@ func New(
app.BlockedModuleAccountAddrs(),
).
WithSendCoinsRestriction(app.AuraKeeper.SendRestrictionFn).
WithSendCoinsRestriction(app.HaloKeeper.SendRestrictionFn)
WithSendCoinsRestriction(app.HaloKeeper.SendRestrictionFn).
WithSendCoinsRestriction(app.FlorinKeeper.SendRestrictionFn)
app.AuraKeeper.SetBankKeeper(app.BankKeeper)
app.HaloKeeper.SetBankKeeper(app.BankKeeper)
app.FlorinKeeper.SetBankKeeper(app.BankKeeper)

app.StakingKeeper = stakingkeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -588,6 +603,7 @@ func New(
forwarding.NewAppModule(app.ForwardingKeeper),
aura.NewAppModule(app.AuraKeeper),
halo.NewAppModule(app.HaloKeeper),
florin.NewAppModule(app.FlorinKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -622,6 +638,7 @@ func New(
forwardingtypes.ModuleName,
auratypes.ModuleName,
halotypes.ModuleName,
florintypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand Down Expand Up @@ -651,6 +668,7 @@ func New(
forwardingtypes.ModuleName,
auratypes.ModuleName,
halotypes.ModuleName,
florintypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -685,6 +703,7 @@ func New(
forwardingtypes.ModuleName,
auratypes.ModuleName,
halotypes.ModuleName,
florintypes.ModuleName,

// this line is used by starport scaffolding # stargate/app/initGenesis
)
Expand Down Expand Up @@ -923,12 +942,13 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino

func (app *App) setupUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(
xenon.UpgradeName,
xenon.CreateUpgradeHandler(
numus.UpgradeName,
numus.CreateUpgradeHandler(
app.mm,
app.configurator,
app.HaloKeeper,
app.BankKeeper,
app.FlorinKeeper,
app.ParamsKeeper,
),
)

Expand All @@ -943,8 +963,8 @@ func (app *App) setupUpgradeHandlers() {
var storeLoader baseapp.StoreLoader

switch upgradeInfo.Name {
case xenon.UpgradeName:
storeLoader = xenon.CreateStoreLoader(upgradeInfo.Height)
case numus.UpgradeName:
storeLoader = numus.CreateStoreLoader(upgradeInfo.Height)
}

if storeLoader != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package xenon
package numus

// UpgradeName is the name of this specific software upgrade used on-chain.
const UpgradeName = "xenon"
const UpgradeName = "numus"

// MainnetChainID is the Chain ID of the Noble mainnet.
const MainnetChainID = "noble-1"
Expand Down
6 changes: 3 additions & 3 deletions app/upgrades/xenon/store.go → app/upgrades/numus/store.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package xenon
package numus

import (
"github.com/cosmos/cosmos-sdk/baseapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
halotypes "github.com/noble-assets/halo/x/halo/types"
florintypes "github.com/noble-assets/florin/x/florin/types"
)

func CreateStoreLoader(upgradeHeight int64) baseapp.StoreLoader {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{halotypes.ModuleName},
Added: []string{florintypes.ModuleName},
}

return upgradetypes.UpgradeStoreLoader(upgradeHeight, &storeUpgrades)
Expand Down
38 changes: 20 additions & 18 deletions app/upgrades/xenon/upgrade.go → app/upgrades/numus/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,58 +1,60 @@
package xenon
package numus

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
halokeeper "github.com/noble-assets/halo/x/halo/keeper"
florinkeeper "github.com/noble-assets/florin/x/florin/keeper"
paramskeeper "github.com/strangelove-ventures/paramauthority/x/params/keeper"
)

func CreateUpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
haloKeeper *halokeeper.Keeper,
bankKeeper bankkeeper.Keeper,
florinKeeper *florinkeeper.Keeper,
paramsKeeper paramskeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
vm, err := mm.RunMigrations(ctx, cfg, vm)
if err != nil {
return vm, err
}

authority := paramsKeeper.GetAuthority(ctx)
florinKeeper.SetAuthority(ctx, authority)

switch ctx.ChainID() {
case TestnetChainID:
haloKeeper.SetOwner(ctx, "noble1u0nahk4wltsp89tpce4cyayd63a69dhpkfq9wq")
haloKeeper.SetAggregatorOwner(ctx, "noble1u0nahk4wltsp89tpce4cyayd63a69dhpkfq9wq")
haloKeeper.SetEntitlementsOwner(ctx, "noble1u0nahk4wltsp89tpce4cyayd63a69dhpkfq9wq")
florinKeeper.SetOwner(ctx, "ueure", "noble1tv9u97jln0k3anpzhahkeahh66u74dug302pyn")
florinKeeper.SetBlacklistOwner(ctx, "noble1tv9u97jln0k3anpzhahkeahh66u74dug302pyn")
case MainnetChainID:
haloKeeper.SetOwner(ctx, "noble184afdqq8x575e4m4khm0e52p4duxe6lxaxju3f")
haloKeeper.SetAggregatorOwner(ctx, "noble184afdqq8x575e4m4khm0e52p4duxe6lxaxju3f")
haloKeeper.SetEntitlementsOwner(ctx, "noble184afdqq8x575e4m4khm0e52p4duxe6lxaxju3f")
florinKeeper.SetOwner(ctx, "ueure", "") // TODO
florinKeeper.SetBlacklistOwner(ctx, "") // TODO
default:
return vm, fmt.Errorf("%s upgrade not allowed to execute on %s chain", UpgradeName, ctx.ChainID())
}

bankKeeper.SetDenomMetaData(ctx, banktypes.Metadata{
Description: "Hashnote US Yield Coin",
Description: "Monerium EUR emoney",
DenomUnits: []*banktypes.DenomUnit{
{
Denom: "uusyc",
Denom: "ueure",
Exponent: 0,
Aliases: []string{"microusyc"},
Aliases: []string{"microeure"},
},
{
Denom: "usyc",
Denom: "eure",
Exponent: 6,
},
},
Base: "uusyc",
Display: "usyc",
Name: "Hashnote US Yield Coin",
Symbol: "USYC",
Base: "ueure",
Display: "eure",
Name: "Monerium EUR emoney",
Symbol: "EURe",
})

return vm, nil
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/noble-assets/florin v1.0.0-rc.1
github.com/noble-assets/forwarding v1.1.0
github.com/noble-assets/halo v1.0.0
github.com/ondoprotocol/usdy-noble v1.0.0
Expand All @@ -31,6 +32,7 @@ require (
)

require (
adr36.dev v0.0.0-20240829163820-17879c0e838f // indirect
cosmossdk.io/api v0.2.6 // indirect
cosmossdk.io/core v0.5.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.3 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
4d63.com/gocheckcompilerdirectives v1.2.1/go.mod h1:yjDJSxmDTtIHHCqX0ufRYZDL6vQtMG7tJdKVeWwsqvs=
4d63.com/gochecknoglobals v0.2.1 h1:1eiorGsgHOFOuoOiJDy2psSrQbRdIHrlge0IJIkUgDc=
4d63.com/gochecknoglobals v0.2.1/go.mod h1:KRE8wtJB3CXCsb1xy421JfTHIIbmT3U5ruxw2Qu8fSU=
adr36.dev v0.0.0-20240829163820-17879c0e838f h1:GM7s+hh4g6VmxtduPyAj/hkXpkwt9N/aZ0WC5OreuOw=
adr36.dev v0.0.0-20240829163820-17879c0e838f/go.mod h1:E6HaE8hVk+ss7kpa9wlj8Iue/G9sSKOca4eG95WHZDw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
cloud.google.com/go v0.43.0/go.mod h1:BOSR3VbTLkk6FDC/TcffxP4NF/FFBGA5ku+jvKOP7pg=
Expand Down Expand Up @@ -963,6 +965,8 @@ github.com/nishanths/predeclared v0.2.2 h1:V2EPdZPliZymNAn79T8RkNApBjMmVKh5XRpLm
github.com/nishanths/predeclared v0.2.2/go.mod h1:RROzoN6TnGQupbC+lqggsOlcgysk3LMK/HI84Mp280c=
github.com/noble-assets/cosmos-sdk v0.45.16-send-restrictions h1:oQwbCoejkXp2/ozQSwc//A6UW9wJl71YgP7o04MsYq0=
github.com/noble-assets/cosmos-sdk v0.45.16-send-restrictions/go.mod h1:bScuNwWAP0TZJpUf+SHXRU3xGoUPp+X9nAzfeIXts40=
github.com/noble-assets/florin v1.0.0-rc.1 h1:0O8Xr0Jqos7lvyvdtQE8Y0WcNH5PvfIJsocPeYLufh8=
github.com/noble-assets/florin v1.0.0-rc.1/go.mod h1:W+6DjaZdSRQe2oqv8eCHQtbyp36LUNImGRCLdPNSA2o=
github.com/noble-assets/forwarding v1.1.0 h1:2TXBs2Y9vWqgHyDKtdcHht6i7OT+pLaVHE3bPvfpmJY=
github.com/noble-assets/forwarding v1.1.0/go.mod h1:o64ZfzCHteRDhOlkpi7GeKAcjlcbWUihC7Y34Er2/3U=
github.com/noble-assets/halo v1.0.0 h1:JG5TAZZcuLArYgl/9dgwJJ9KAOIo2f03/S010WRVNV8=
Expand Down
5 changes: 5 additions & 0 deletions interchaintest/upgrade_grand-1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ func TestGrand1ChainUpgrade(t *testing.T) {
upgradeName: "xenon",
image: ghcrImage("v6.0.0-rc.0"),
},
{
// numus is a major release that introduced the florin module.
upgradeName: "numus",
image: nobleImageInfo[0],
},
}

testNobleChainUpgrade(t, "grand-1", genesis, denomMetadataUsdc, numValidators, numFullNodes, upgrades)
Expand Down
5 changes: 5 additions & 0 deletions interchaintest/upgrade_noble-1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ func TestNoble1ChainUpgrade(t *testing.T) {
upgradeName: "xenon",
image: ghcrImage("v6.0.0"),
},
{
// numus is a major release that introduced the florin module.
upgradeName: "numus",
image: nobleImageInfo[0],
},
}

testNobleChainUpgrade(t, "noble-1", genesis, denomMetadataFrienzies, numValidators, numFullNodes, upgrades)
Expand Down

0 comments on commit 59619a1

Please sign in to comment.