Skip to content

Commit

Permalink
Merge pull request #180 from DongLieu/dong/import-new-module
Browse files Browse the repository at this point in the history
init: import new module vaults, auction, psm and oracle mock
  • Loading branch information
vuong177 authored Oct 22, 2024
2 parents a0901db + 067fa57 commit 329ed22
Show file tree
Hide file tree
Showing 13 changed files with 511 additions and 145 deletions.
13 changes: 12 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import (
"github.com/onomyprotocol/onomy/app/upgrades"
v1_1_6 "github.com/onomyprotocol/onomy/app/upgrades/v1.1.6"
v2_0_0 "github.com/onomyprotocol/onomy/app/upgrades/v2.0.0"
v2_1_0 "github.com/onomyprotocol/onomy/app/upgrades/v2.1.0"
"github.com/onomyprotocol/onomy/docs"
)

Expand Down Expand Up @@ -233,9 +234,9 @@ func NewOnomyApp( // nolint:funlen // app new cosmos func
app.mm.SetOrderEndBlockers(orderEndBlockers()...)
app.mm.SetOrderInitGenesis(orderInitBlockers()...)

//
app.mm.RegisterInvariants(app.CrisisKeeper)
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())

err = app.mm.RegisterServices(app.configurator)
if err != nil {
panic(err)
Expand Down Expand Up @@ -460,6 +461,7 @@ func (app *OnomyApp) SimulationManager() *module.SimulationManager {
func (app *OnomyApp) setupUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(v1_1_6.Name, v1_1_6.UpgradeHandler)
app.UpgradeKeeper.SetUpgradeHandler(v2_0_0.Name, v2_0_0.CreateUpgradeHandler(app.mm, app.configurator, &app.AppKeepers))
app.UpgradeKeeper.SetUpgradeHandler(v2_1_0.Name, v2_1_0.CreateUpgradeHandler(app.mm, app.configurator, &app.AppKeepers))

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
Expand All @@ -478,6 +480,15 @@ func (app *OnomyApp) setupUpgradeHandlers() {
storeUpgrades = &storetypes.StoreUpgrades{
Deleted: []string{"provider"},
}
case v2_0_0.Name:
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{"consensus", "crisis", "dao"},
}

case v2_1_0.Name:
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{"vaults", "oracle", "auction", "psm"},
}
default:
// no store upgrades.
}
Expand Down
92 changes: 83 additions & 9 deletions app/keepers/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ import (
"github.com/onomyprotocol/onomy/x/dao"
daokeeper "github.com/onomyprotocol/onomy/x/dao/keeper"
daotypes "github.com/onomyprotocol/onomy/x/dao/types"

auctionKeeper "github.com/onomyprotocol/reserve/x/auction/keeper"
oracleKeeper "github.com/onomyprotocol/reserve/x/oracle/keeper"
psmKeeper "github.com/onomyprotocol/reserve/x/psm/keeper"
vaultsKeeper "github.com/onomyprotocol/reserve/x/vaults/keeper"
vaults "github.com/onomyprotocol/reserve/x/vaults/module"

auctiontypes "github.com/onomyprotocol/reserve/x/auction/types"
oracletypes "github.com/onomyprotocol/reserve/x/oracle/types"
psmtypes "github.com/onomyprotocol/reserve/x/psm/types"
vaultstypes "github.com/onomyprotocol/reserve/x/vaults/types"

oracle "github.com/onomyprotocol/reserve/x/oracle"
psm "github.com/onomyprotocol/reserve/x/psm/module"
)

type AppKeepers struct {
Expand Down Expand Up @@ -87,14 +101,18 @@ type AppKeepers struct {
TransferKeeper ibctransferkeeper.Keeper

// make scoped keepers public for test purposes.
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICSproviderkeeper capabilitykeeper.ScopedKeeper
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper

// Modules.
TransferModule transfer.AppModule

DaoKeeper daokeeper.Keeper

PSMKeeper psmKeeper.Keeper
AuctionKeeper auctionKeeper.Keeper
VaultsKeeper vaultsKeeper.Keeper
OracleMockKeeper oracleKeeper.Keeper
}

func NewAppKeeper(
Expand Down Expand Up @@ -291,12 +309,7 @@ func NewAppKeeper(
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
ibcmodule := transfer.NewIBCModule(appKeepers.TransferKeeper)

// Create static IBC router, add transfer route, then set and seal it.
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, ibcmodule)
appKeepers.IBCKeeper.SetRouter(ibcRouter)
// Register the proposal types
// Deprecated: Avoid adding new handlers, instead use the new proposal flow
// by granting the governance module the right to execute the message.
Expand All @@ -306,7 +319,10 @@ func NewAppKeeper(
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(appKeepers.ParamsKeeper)).
AddRoute(daotypes.RouterKey, dao.NewProposalHandler(appKeepers.DaoKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper))
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)).
AddRoute(psmtypes.RouterKey, psm.NewPSMProposalHandler(&appKeepers.PSMKeeper)).
AddRoute(oracletypes.RouterKey, oracle.NewOracleProposalHandler(appKeepers.OracleMockKeeper)).
AddRoute(vaultstypes.RouterKey, vaults.NewVaultsProposalHandler(&appKeepers.VaultsKeeper))

// Set legacy router for backwards compatibility with gov v1beta1.
appKeepers.GovKeeper.SetLegacyRouter(govRouter)
Expand Down Expand Up @@ -350,6 +366,52 @@ func NewAppKeeper(
appKeepers.StakingKeeper,
)

appKeepers.OracleMockKeeper = oracleKeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(appKeepers.keys[oracletypes.ModuleName]),
logger,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
// appKeepers.GetIBCKeeper,
// appKeepers.GetScopedIBCKeeper,
)

appKeepers.PSMKeeper = psmKeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(appKeepers.keys[psmtypes.ModuleName]),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
appKeepers.BankKeeper,
appKeepers.AccountKeeper,
appKeepers.OracleMockKeeper,
)

appKeepers.VaultsKeeper = *vaultsKeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(appKeepers.keys[vaultstypes.ModuleName]),
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.OracleMockKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.AuctionKeeper = auctionKeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(appKeepers.keys[auctiontypes.ModuleName]),
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
&appKeepers.VaultsKeeper,
appKeepers.OracleMockKeeper,
logger,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

ibcmodule := transfer.NewIBCModule(appKeepers.TransferKeeper)

// Create static IBC router, add transfer route, then set and seal it.
ibcRouter := porttypes.NewRouter().
AddRoute(ibctransfertypes.ModuleName, ibcmodule)

appKeepers.IBCKeeper.SetRouter(ibcRouter)

return appKeepers
}

Expand Down Expand Up @@ -380,6 +442,10 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable)
paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable())
paramsKeeper.Subspace(daotypes.ModuleName)
paramsKeeper.Subspace(psmtypes.ModuleName)
paramsKeeper.Subspace(auctiontypes.ModuleName)
paramsKeeper.Subspace(oracletypes.ModuleName)
paramsKeeper.Subspace(vaultstypes.ModuleName)

return paramsKeeper
}
Expand All @@ -397,3 +463,11 @@ func (r *DefaultFeemarketDenomResolver) ConvertToDenom(_ sdk.Context, coin sdk.D
func (r *DefaultFeemarketDenomResolver) ExtraDenoms(_ sdk.Context) ([]string, error) {
return []string{}, nil
}

func (a AppKeepers) GetIBCKeeper() *ibckeeper.Keeper {
return a.IBCKeeper
}

func (a AppKeepers) GetScopedIBCKeeper(string) capabilitykeeper.ScopedKeeper {
return a.ScopedIBCKeeper
}
9 changes: 9 additions & 0 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import (
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"

daotypes "github.com/onomyprotocol/onomy/x/dao/types"

auctiontypes "github.com/onomyprotocol/reserve/x/auction/types"
oracletypes "github.com/onomyprotocol/reserve/x/oracle/types"
psmtypes "github.com/onomyprotocol/reserve/x/psm/types"
vaultstypes "github.com/onomyprotocol/reserve/x/vaults/types"
)

func (appKeepers *AppKeepers) GenerateKeys() {
Expand All @@ -45,6 +50,10 @@ func (appKeepers *AppKeepers) GenerateKeys() {
authzkeeper.StoreKey,
daotypes.StoreKey,
consensusparamtypes.StoreKey,
auctiontypes.StoreKey,
oracletypes.StoreKey,
psmtypes.StoreKey,
vaultstypes.StoreKey,
)

// Define transient store keys.
Expand Down
35 changes: 35 additions & 0 deletions app/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,28 @@ import (

"github.com/onomyprotocol/onomy/x/dao"
daotypes "github.com/onomyprotocol/onomy/x/dao/types"

auctiontypes "github.com/onomyprotocol/reserve/x/auction/types"
oracletypes "github.com/onomyprotocol/reserve/x/oracle/types"
psmtypes "github.com/onomyprotocol/reserve/x/psm/types"
vaultstypes "github.com/onomyprotocol/reserve/x/vaults/types"

auction "github.com/onomyprotocol/reserve/x/auction/module"
oracle "github.com/onomyprotocol/reserve/x/oracle/module"
psm "github.com/onomyprotocol/reserve/x/psm/module"
vaults "github.com/onomyprotocol/reserve/x/vaults/module"
)

var (
// module account permissions.
maccPerms = map[string][]string{ //nolint:gochecknoglobals // cosmos-sdk application style
authtypes.FeeCollectorName: nil,
daotypes.ModuleName: {authtypes.Minter},
auctiontypes.ModuleName: {authtypes.Minter, authtypes.Burner},
vaultstypes.ModuleName: {authtypes.Minter, authtypes.Burner},
vaultstypes.ReserveModuleName: {authtypes.Burner},
psmtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
oracletypes.ModuleName: nil,
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
Expand Down Expand Up @@ -82,6 +97,10 @@ func appModules(
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
dao.NewAppModule(appCodec, app.DaoKeeper),
auction.NewAppModule(appCodec, app.AuctionKeeper, app.AccountKeeper, app.BankKeeper),
vaults.NewAppModule(appCodec, app.VaultsKeeper, app.AccountKeeper, app.BankKeeper),
oracle.NewAppModule(appCodec, app.OracleMockKeeper, app.AccountKeeper, app.BankKeeper),
psm.NewAppModule(appCodec, app.PSMKeeper, app.AccountKeeper, app.BankKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
Expand Down Expand Up @@ -142,6 +161,10 @@ func orderBeginBlockers() []string {
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
daotypes.ModuleName,
oracletypes.ModuleName,
vaultstypes.ModuleName,
auctiontypes.ModuleName,
psmtypes.ModuleName,
}
}

Expand All @@ -167,6 +190,10 @@ func orderEndBlockers() []string {
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
daotypes.ModuleName,
oracletypes.ModuleName,
vaultstypes.ModuleName,
auctiontypes.ModuleName,
psmtypes.ModuleName,
}
}

Expand All @@ -192,6 +219,10 @@ func orderInitBlockers() []string {
consensusparamtypes.ModuleName,
crisistypes.ModuleName,
daotypes.ModuleName,
oracletypes.ModuleName,
vaultstypes.ModuleName,
auctiontypes.ModuleName,
psmtypes.ModuleName,
}
}

Expand All @@ -204,6 +235,10 @@ func simulationModules(
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
dao.NewAppModule(appCodec, app.DaoKeeper),
// auction.NewAppModule(appCodec, app.AuctionKeeper, app.AccountKeeper, app.BankKeeper),
// vaults.NewAppModule(appCodec, app.VaultsKeeper, app.AccountKeeper, app.BankKeeper),
// oracle.NewAppModule(appCodec, app.OracleMockKeeper, app.AccountKeeper, app.BankKeeper),
psm.NewAppModule(appCodec, app.PSMKeeper, app.AccountKeeper, app.BankKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
Expand Down
3 changes: 3 additions & 0 deletions app/upgrades/v2.1.0/constant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package v2_1_0 //nolint:revive,stylecheck // app version

const Name = "v2.1.0"
29 changes: 29 additions & 0 deletions app/upgrades/v2.1.0/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package v2_1_0 //nolint:revive,stylecheck // app version

import (
"context"

upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/types/module"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/onomyprotocol/onomy/app/keepers"
)

// UpgradeHandler is an x/upgrade handler.
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {

return func(c context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx := sdk.UnwrapSDKContext(c)
collectionsConsensus(ctx, keepers)
return vm, nil
}
}

func collectionsConsensus(ctx sdk.Context, keepers *keepers.AppKeepers) {
keepers.ConsensusParamsKeeper.ParamsStore.Set(ctx, ctx.ConsensusParams())
}
Loading

0 comments on commit 329ed22

Please sign in to comment.