mirror of
				https://github.com/0glabs/0g-chain.git
				synced 2025-11-03 23:47:27 +00:00 
			
		
		
		
	add new modules to app
This commit is contained in:
		
							parent
							
								
									57a1532db4
								
							
						
					
					
						commit
						fc2b7f9652
					
				
							
								
								
									
										69
									
								
								app/app.go
									
									
									
									
									
								
							
							
						
						
									
										69
									
								
								app/app.go
									
									
									
									
									
								
							@ -4,6 +4,10 @@ import (
 | 
				
			|||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/kava-labs/kava/x/auction"
 | 
				
			||||||
 | 
						"github.com/kava-labs/kava/x/cdp"
 | 
				
			||||||
 | 
						"github.com/kava-labs/kava/x/liquidator"
 | 
				
			||||||
 | 
						"github.com/kava-labs/kava/x/pricefeed"
 | 
				
			||||||
	validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
 | 
						validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	abci "github.com/tendermint/tendermint/abci/types"
 | 
						abci "github.com/tendermint/tendermint/abci/types"
 | 
				
			||||||
@ -55,6 +59,10 @@ var (
 | 
				
			|||||||
		crisis.AppModuleBasic{},
 | 
							crisis.AppModuleBasic{},
 | 
				
			||||||
		slashing.AppModuleBasic{},
 | 
							slashing.AppModuleBasic{},
 | 
				
			||||||
		supply.AppModuleBasic{},
 | 
							supply.AppModuleBasic{},
 | 
				
			||||||
 | 
							auction.AppModuleBasic{},
 | 
				
			||||||
 | 
							cdp.AppModuleBasic{},
 | 
				
			||||||
 | 
							liquidator.AppModuleBasic{},
 | 
				
			||||||
 | 
							pricefeed.AppModuleBasic{},
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// module account permissions
 | 
						// module account permissions
 | 
				
			||||||
@ -81,17 +89,21 @@ type App struct {
 | 
				
			|||||||
	tkeys map[string]*sdk.TransientStoreKey
 | 
						tkeys map[string]*sdk.TransientStoreKey
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// keepers from all the modules
 | 
						// keepers from all the modules
 | 
				
			||||||
	accountKeeper  auth.AccountKeeper
 | 
						accountKeeper    auth.AccountKeeper
 | 
				
			||||||
	bankKeeper     bank.Keeper
 | 
						bankKeeper       bank.Keeper
 | 
				
			||||||
	supplyKeeper   supply.Keeper
 | 
						supplyKeeper     supply.Keeper
 | 
				
			||||||
	stakingKeeper  staking.Keeper
 | 
						stakingKeeper    staking.Keeper
 | 
				
			||||||
	slashingKeeper slashing.Keeper
 | 
						slashingKeeper   slashing.Keeper
 | 
				
			||||||
	mintKeeper     mint.Keeper
 | 
						mintKeeper       mint.Keeper
 | 
				
			||||||
	distrKeeper    distr.Keeper
 | 
						distrKeeper      distr.Keeper
 | 
				
			||||||
	govKeeper      gov.Keeper
 | 
						govKeeper        gov.Keeper
 | 
				
			||||||
	crisisKeeper   crisis.Keeper
 | 
						crisisKeeper     crisis.Keeper
 | 
				
			||||||
	paramsKeeper   params.Keeper
 | 
						paramsKeeper     params.Keeper
 | 
				
			||||||
	vvKeeper       validatorvesting.Keeper
 | 
						vvKeeper         validatorvesting.Keeper
 | 
				
			||||||
 | 
						auctionKeeper    auction.Keeper
 | 
				
			||||||
 | 
						cdpKeeper        cdp.Keeper
 | 
				
			||||||
 | 
						liquidatorKeeper liquidator.Keeper
 | 
				
			||||||
 | 
						pricefeedKeeper  pricefeed.Keeper
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// the module manager
 | 
						// the module manager
 | 
				
			||||||
	mm *module.Manager
 | 
						mm *module.Manager
 | 
				
			||||||
@ -115,6 +127,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
 | 
				
			|||||||
		bam.MainStoreKey, auth.StoreKey, staking.StoreKey,
 | 
							bam.MainStoreKey, auth.StoreKey, staking.StoreKey,
 | 
				
			||||||
		supply.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey,
 | 
							supply.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey,
 | 
				
			||||||
		gov.StoreKey, params.StoreKey, validatorvesting.StoreKey,
 | 
							gov.StoreKey, params.StoreKey, validatorvesting.StoreKey,
 | 
				
			||||||
 | 
							auction.StoreKey, cdp.StoreKey, liquidator.StoreKey, pricefeed.StoreKey,
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	tkeys := sdk.NewTransientStoreKeys(params.TStoreKey)
 | 
						tkeys := sdk.NewTransientStoreKeys(params.TStoreKey)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -136,6 +149,10 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
 | 
				
			|||||||
	slashingSubspace := app.paramsKeeper.Subspace(slashing.DefaultParamspace)
 | 
						slashingSubspace := app.paramsKeeper.Subspace(slashing.DefaultParamspace)
 | 
				
			||||||
	govSubspace := app.paramsKeeper.Subspace(gov.DefaultParamspace).WithKeyTable(gov.ParamKeyTable())
 | 
						govSubspace := app.paramsKeeper.Subspace(gov.DefaultParamspace).WithKeyTable(gov.ParamKeyTable())
 | 
				
			||||||
	crisisSubspace := app.paramsKeeper.Subspace(crisis.DefaultParamspace)
 | 
						crisisSubspace := app.paramsKeeper.Subspace(crisis.DefaultParamspace)
 | 
				
			||||||
 | 
						auctionSubspace := app.paramsKeeper.Subspace(auction.DefaultParamspace)
 | 
				
			||||||
 | 
						cdpSubspace := app.paramsKeeper.Subspace(cdp.DefaultParamspace)
 | 
				
			||||||
 | 
						liquidatorSubspace := app.paramsKeeper.Subspace(liquidator.DefaultParamspace)
 | 
				
			||||||
 | 
						pricefeedSubspace := app.paramsKeeper.Subspace(pricefeed.DefaultParamspace).WithKeyTable(pricefeed.ParamKeyTable()) // TODO why do other modules not need this?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// add keepers
 | 
						// add keepers
 | 
				
			||||||
	app.accountKeeper = auth.NewAccountKeeper(
 | 
						app.accountKeeper = auth.NewAccountKeeper(
 | 
				
			||||||
@ -207,6 +224,29 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
 | 
				
			|||||||
		app.bankKeeper,
 | 
							app.bankKeeper,
 | 
				
			||||||
		app.supplyKeeper,
 | 
							app.supplyKeeper,
 | 
				
			||||||
		&stakingKeeper)
 | 
							&stakingKeeper)
 | 
				
			||||||
 | 
						app.pricefeedKeeper = pricefeed.NewKeeper(
 | 
				
			||||||
 | 
							app.cdc,
 | 
				
			||||||
 | 
							keys[pricefeed.StoreKey],
 | 
				
			||||||
 | 
							pricefeedSubspace,
 | 
				
			||||||
 | 
							pricefeed.DefaultCodespace)
 | 
				
			||||||
 | 
						app.cdpKeeper = cdp.NewKeeper(
 | 
				
			||||||
 | 
							app.cdc,
 | 
				
			||||||
 | 
							keys[cdp.StoreKey],
 | 
				
			||||||
 | 
							cdpSubspace,
 | 
				
			||||||
 | 
							app.pricefeedKeeper,
 | 
				
			||||||
 | 
							app.bankKeeper)
 | 
				
			||||||
 | 
						app.auctionKeeper = auction.NewKeeper(
 | 
				
			||||||
 | 
							app.cdc,
 | 
				
			||||||
 | 
							app.cdpKeeper, // CDP keeper standing in for bank
 | 
				
			||||||
 | 
							keys[auction.StoreKey],
 | 
				
			||||||
 | 
							auctionSubspace)
 | 
				
			||||||
 | 
						app.liquidatorKeeper = liquidator.NewKeeper(
 | 
				
			||||||
 | 
							app.cdc,
 | 
				
			||||||
 | 
							keys[liquidator.StoreKey],
 | 
				
			||||||
 | 
							liquidatorSubspace,
 | 
				
			||||||
 | 
							app.cdpKeeper,
 | 
				
			||||||
 | 
							app.auctionKeeper,
 | 
				
			||||||
 | 
							app.cdpKeeper) // CDP keeper standing in for bank
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// register the staking hooks
 | 
						// register the staking hooks
 | 
				
			||||||
	// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
 | 
						// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
 | 
				
			||||||
@ -227,6 +267,10 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
 | 
				
			|||||||
		slashing.NewAppModule(app.slashingKeeper, app.stakingKeeper),
 | 
							slashing.NewAppModule(app.slashingKeeper, app.stakingKeeper),
 | 
				
			||||||
		staking.NewAppModule(app.stakingKeeper, app.accountKeeper, app.supplyKeeper),
 | 
							staking.NewAppModule(app.stakingKeeper, app.accountKeeper, app.supplyKeeper),
 | 
				
			||||||
		validatorvesting.NewAppModule(app.vvKeeper, app.accountKeeper),
 | 
							validatorvesting.NewAppModule(app.vvKeeper, app.accountKeeper),
 | 
				
			||||||
 | 
							auction.NewAppModule(app.auctionKeeper),
 | 
				
			||||||
 | 
							cdp.NewAppModule(app.cdpKeeper, app.pricefeedKeeper),
 | 
				
			||||||
 | 
							liquidator.NewAppModule(app.liquidatorKeeper),
 | 
				
			||||||
 | 
							pricefeed.NewAppModule(app.pricefeedKeeper),
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// During begin block slashing happens after distr.BeginBlocker so that
 | 
						// During begin block slashing happens after distr.BeginBlocker so that
 | 
				
			||||||
@ -234,7 +278,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
 | 
				
			|||||||
	// CanWithdrawInvariant invariant.
 | 
						// CanWithdrawInvariant invariant.
 | 
				
			||||||
	app.mm.SetOrderBeginBlockers(mint.ModuleName, distr.ModuleName, slashing.ModuleName, validatorvesting.ModuleName)
 | 
						app.mm.SetOrderBeginBlockers(mint.ModuleName, distr.ModuleName, slashing.ModuleName, validatorvesting.ModuleName)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	app.mm.SetOrderEndBlockers(crisis.ModuleName, gov.ModuleName, staking.ModuleName)
 | 
						app.mm.SetOrderEndBlockers(crisis.ModuleName, gov.ModuleName, staking.ModuleName, pricefeed.ModuleName, auction.ModuleName) // TODO is this correct order?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Note: genutils must occur after staking so that pools are properly
 | 
						// Note: genutils must occur after staking so that pools are properly
 | 
				
			||||||
	// initialized with tokens from genesis accounts.
 | 
						// initialized with tokens from genesis accounts.
 | 
				
			||||||
@ -245,6 +289,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
 | 
				
			|||||||
		auth.ModuleName, validatorvesting.ModuleName, distr.ModuleName,
 | 
							auth.ModuleName, validatorvesting.ModuleName, distr.ModuleName,
 | 
				
			||||||
		staking.ModuleName, bank.ModuleName, slashing.ModuleName,
 | 
							staking.ModuleName, bank.ModuleName, slashing.ModuleName,
 | 
				
			||||||
		gov.ModuleName, mint.ModuleName, supply.ModuleName, crisis.ModuleName, genutil.ModuleName,
 | 
							gov.ModuleName, mint.ModuleName, supply.ModuleName, crisis.ModuleName, genutil.ModuleName,
 | 
				
			||||||
 | 
							pricefeed.ModuleName, cdp.ModuleName, auction.ModuleName, liquidator.ModuleName, // TODO is this order ok?
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	app.mm.RegisterInvariants(&app.crisisKeeper)
 | 
						app.mm.RegisterInvariants(&app.crisisKeeper)
 | 
				
			||||||
 | 
				
			|||||||
@ -4,13 +4,12 @@ import (
 | 
				
			|||||||
	sdk "github.com/cosmos/cosmos-sdk/types"
 | 
						sdk "github.com/cosmos/cosmos-sdk/types"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
// InitGenesis sets distribution information for genesis.
 | 
					// InitGenesis sets distribution information for genesis.
 | 
				
			||||||
func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState) {
 | 
					func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Set the assets and oracles from params
 | 
						// Set the assets and oracles from params
 | 
				
			||||||
	keeper.SetAssetParams(ctx, data.AssetParams)
 | 
						keeper.SetAssetParams(ctx, data.AssetParams)
 | 
				
			||||||
	keeper.SetOracleParams(ctx ,data.OracleParams)
 | 
						keeper.SetOracleParams(ctx, data.OracleParams)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Iterate through the posted prices and set them in the store
 | 
						// Iterate through the posted prices and set them in the store
 | 
				
			||||||
	for _, pp := range data.PostedPrices {
 | 
						for _, pp := range data.PostedPrices {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user