Skip to content

Commit

Permalink
Merge pull request #384 from terra-project/feature/mint-module
Browse files Browse the repository at this point in the history
feat(mint): use uluna as default mint denom
  • Loading branch information
hanjukim authored Aug 21, 2020
2 parents d76e776 + be67e9a commit 4cc75e5
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 8 deletions.
24 changes: 17 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/terra-project/core/x/genutil"
"github.com/terra-project/core/x/gov"
"github.com/terra-project/core/x/market"
"github.com/terra-project/core/x/mint"
"github.com/terra-project/core/x/msgauth"
"github.com/terra-project/core/x/oracle"
"github.com/terra-project/core/x/params"
Expand Down Expand Up @@ -65,6 +66,7 @@ var (
auth.AppModuleBasic{},
bank.AppModuleBasic{},
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
paramsclient.ProposalHandler,
Expand All @@ -90,6 +92,7 @@ var (
maccPerms = map[string][]string{
auth.FeeCollectorName: nil, // just added to enable align fee
bank.BurnModuleName: {supply.Burner},
mint.ModuleName: {supply.Minter},
market.ModuleName: {supply.Minter, supply.Burner},
oracle.ModuleName: nil,
distr.ModuleName: nil,
Expand Down Expand Up @@ -148,6 +151,7 @@ type TerraApp struct {
evidenceKeeper evidence.Keeper
oracleKeeper oracle.Keeper
marketKeeper market.Keeper
mintKeeper mint.Keeper
treasuryKeeper treasury.Keeper
wasmKeeper wasm.Keeper
msgauthKeeper msgauth.Keeper
Expand All @@ -174,8 +178,9 @@ func NewTerraApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
bam.MainStoreKey, auth.StoreKey, staking.StoreKey,
supply.StoreKey, distr.StoreKey, slashing.StoreKey,
gov.StoreKey, params.StoreKey, oracle.StoreKey,
market.StoreKey, treasury.StoreKey, upgrade.StoreKey,
evidence.StoreKey, wasm.StoreKey, msgauth.StoreKey,
market.StoreKey, mint.StoreKey, treasury.StoreKey,
upgrade.StoreKey, evidence.StoreKey, wasm.StoreKey,
msgauth.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(params.TStoreKey)

Expand All @@ -200,8 +205,9 @@ func NewTerraApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
app.subspaces[evidence.ModuleName] = app.paramsKeeper.Subspace(evidence.DefaultParamspace)
app.subspaces[oracle.ModuleName] = app.paramsKeeper.Subspace(oracle.DefaultParamspace)
app.subspaces[market.ModuleName] = app.paramsKeeper.Subspace(market.DefaultParamspace)
app.subspaces[treasury.ModuleName] = app.paramsKeeper.Subspace(treasury.DefaultParamspace)
app.subspaces[mint.ModuleName] = app.paramsKeeper.Subspace(mint.DefaultParamspace)
app.subspaces[wasm.ModuleName] = app.paramsKeeper.Subspace(wasm.DefaultParamspace)
app.subspaces[treasury.ModuleName] = app.paramsKeeper.Subspace(treasury.DefaultParamspace)

// add keepers
app.accountKeeper = auth.NewAccountKeeper(app.cdc, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount)
Expand All @@ -218,6 +224,7 @@ func NewTerraApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
&stakingKeeper, app.supplyKeeper, distr.ModuleName)
app.marketKeeper = market.NewKeeper(app.cdc, keys[market.StoreKey], app.subspaces[market.ModuleName],
app.oracleKeeper, app.supplyKeeper)
app.mintKeeper = mint.NewKeeper(app.cdc, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper, app.supplyKeeper, auth.FeeCollectorName)
app.treasuryKeeper = treasury.NewKeeper(app.cdc, keys[treasury.StoreKey], app.subspaces[treasury.ModuleName],
app.supplyKeeper, app.marketKeeper, &stakingKeeper, app.distrKeeper,
oracle.ModuleName, distr.ModuleName)
Expand Down Expand Up @@ -273,6 +280,7 @@ func NewTerraApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
supply.NewAppModule(app.supplyKeeper, app.accountKeeper),
distr.NewAppModule(app.distrKeeper, app.accountKeeper, app.supplyKeeper, app.stakingKeeper),
gov.NewAppModule(app.govKeeper, app.accountKeeper, app.supplyKeeper),
mint.NewAppModule(app.mintKeeper),
slashing.NewAppModule(app.slashingKeeper, app.accountKeeper, app.stakingKeeper),
staking.NewAppModule(app.stakingKeeper, app.accountKeeper, app.supplyKeeper),
upgrade.NewAppModule(app.upgradeKeeper),
Expand All @@ -287,7 +295,7 @@ func NewTerraApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
// CanWithdrawInvariant invariant.
app.mm.SetOrderBeginBlockers(upgrade.ModuleName, distr.ModuleName, slashing.ModuleName, evidence.ModuleName)
app.mm.SetOrderBeginBlockers(upgrade.ModuleName, mint.ModuleName, distr.ModuleName, slashing.ModuleName, evidence.ModuleName)
app.mm.SetOrderEndBlockers(crisis.ModuleName, oracle.ModuleName, gov.ModuleName, market.ModuleName,
treasury.ModuleName, msgauth.ModuleName, staking.ModuleName)

Expand All @@ -296,9 +304,10 @@ func NewTerraApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
// initialized with tokens from genesis accounts.
app.mm.SetOrderInitGenesis(auth.ModuleName, distr.ModuleName,
staking.ModuleName, bank.ModuleName, slashing.ModuleName,
gov.ModuleName, supply.ModuleName, oracle.ModuleName, treasury.ModuleName,
market.ModuleName, wasm.ModuleName, msgauth.ModuleName,
crisis.ModuleName, genutil.ModuleName, evidence.ModuleName)
gov.ModuleName, mint.ModuleName, supply.ModuleName,
oracle.ModuleName, treasury.ModuleName, market.ModuleName,
wasm.ModuleName, msgauth.ModuleName, crisis.ModuleName,
genutil.ModuleName, evidence.ModuleName)

app.mm.RegisterInvariants(&app.crisisKeeper)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter())
Expand All @@ -309,6 +318,7 @@ func NewTerraApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
bank.NewAppModule(app.bankKeeper, app.accountKeeper, app.supplyKeeper),
supply.NewAppModule(app.supplyKeeper, app.accountKeeper),
gov.NewAppModule(app.govKeeper, app.accountKeeper, app.supplyKeeper),
mint.NewAppModule(app.mintKeeper),
staking.NewAppModule(app.stakingKeeper, app.accountKeeper, app.supplyKeeper),
distr.NewAppModule(app.distrKeeper, app.accountKeeper, app.supplyKeeper, app.stakingKeeper),
slashing.NewAppModule(app.slashingKeeper, app.accountKeeper, app.stakingKeeper),
Expand Down
2 changes: 2 additions & 0 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/cosmos/cosmos-sdk/x/slashing"
Expand Down Expand Up @@ -167,6 +168,7 @@ func TestAppImportExport(t *testing.T) {
{app.keys[gov.StoreKey], newApp.keys[gov.StoreKey], [][]byte{}},
{app.keys[oracle.StoreKey], newApp.keys[oracle.StoreKey], [][]byte{}},
{app.keys[market.StoreKey], newApp.keys[market.StoreKey], [][]byte{}},
{app.keys[mint.StoreKey], newApp.keys[mint.StoreKey], [][]byte{}},
{app.keys[treasury.StoreKey], newApp.keys[treasury.StoreKey], [][]byte{}},
{app.keys[wasm.StoreKey], newApp.keys[wasm.StoreKey], [][]byte{}},
}
Expand Down
1 change: 1 addition & 0 deletions cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ func TestTerraCLIQuerySupply(t *testing.T) {
totalSupply := f.QueryTotalSupply()
totalSupplyOf := f.QueryTotalSupplyOf(fooDenom)

fmt.Println(totalCoins, totalSupply)
require.Equal(t, totalCoins, totalSupply)
require.True(sdk.IntEq(t, totalCoins.AmountOf(fooDenom), totalSupplyOf))

Expand Down
2 changes: 1 addition & 1 deletion cli_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var (
sdk.NewCoin(fee2Denom, sdk.TokensFromConsensusPower(2000000)),
sdk.NewCoin(feeDenom, sdk.TokensFromConsensusPower(2000000)),
sdk.NewCoin(fooDenom, sdk.TokensFromConsensusPower(2000)),
sdk.NewCoin(denom, sdk.TokensFromConsensusPower(300)),
sdk.NewCoin(denom, sdk.TokensFromConsensusPower(300).Add(sdk.NewInt(12))),
)

startCoins = sdk.NewCoins(
Expand Down
37 changes: 37 additions & 0 deletions x/mint/cosmos_alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// nolint
package mint

import (
"github.com/cosmos/cosmos-sdk/x/mint"
)

const (
ModuleName = mint.ModuleName
StoreKey = mint.StoreKey
QuerierRoute = mint.QuerierRoute
QueryParameters = mint.QueryParameters
DefaultParamspace = mint.DefaultParamspace
)

var (
// functions aliases
NewGenesisState = mint.NewGenesisState
DefaultGenesisState = mint.DefaultGenesisState
ValidateGenesis = mint.ValidateGenesis
ParamKeyTable = mint.ParamKeyTable
NewParams = mint.NewParams
DefaultParams = mint.DefaultParams
NewCosmosAppModule = mint.NewAppModule
NewKeeper = mint.NewKeeper

// variable aliases
CosmosModuleCdc = mint.ModuleCdc
)

type (
GenesisState = mint.GenesisState
Params = mint.Params
Keeper = mint.Keeper
CosmosAppModule = mint.AppModule
CosmosAppModuleBasic = mint.AppModuleBasic
)
160 changes: 160 additions & 0 deletions x/mint/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package mint

import (
"encoding/json"
"math/rand"

"github.com/gorilla/mux"
"github.com/spf13/cobra"

abci "github.com/tendermint/tendermint/abci/types"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
sim "github.com/cosmos/cosmos-sdk/x/simulation"

core "github.com/terra-project/core/types"
)

var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModuleSimulation = AppModule{}
)

// AppModuleBasic defines the basic application module used by the slashing module.
type AppModuleBasic struct{}

// Name returns the slashing module's name
func (AppModuleBasic) Name() string {
return CosmosAppModuleBasic{}.Name()
}

// RegisterCodec registers the slashing module's types for the given codec.
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
CosmosAppModuleBasic{}.RegisterCodec(cdc)
}

// DefaultGenesis returns default genesis state as raw bytes for the slashing
// module.
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
// customize to set default genesis state bond denom to uluna
defaultGenesisState := DefaultGenesisState()
defaultGenesisState.Params.MintDenom = core.MicroLunaDenom

return CosmosModuleCdc.MustMarshalJSON(defaultGenesisState)
}

// ValidateGenesis performs genesis state validation for the slashing module.
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
return CosmosAppModuleBasic{}.ValidateGenesis(bz)
}

// RegisterRESTRoutes registers the REST routes for the slashing module.
func (AppModuleBasic) RegisterRESTRoutes(cliCtx context.CLIContext, route *mux.Router) {
CosmosAppModuleBasic{}.RegisterRESTRoutes(cliCtx, route)
}

// GetTxCmd returns the root tx command for the slashing module.
func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
return CosmosAppModuleBasic{}.GetTxCmd(cdc)
}

// GetQueryCmd returns the root query command for the slashing module.
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return CosmosAppModuleBasic{}.GetQueryCmd(cdc)
}

//___________________________

// AppModule implements an application module for the slashing module.
type AppModule struct {
AppModuleBasic
cosmosAppModule CosmosAppModule
}

// NewAppModule creates a new AppModule object
func NewAppModule(keeper Keeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
cosmosAppModule: NewCosmosAppModule(keeper),
}
}

// Name returns the slashing module's name.
func (am AppModule) Name() string {
return am.cosmosAppModule.Name()
}

// RegisterInvariants registers the slashing module invariants.
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
am.cosmosAppModule.RegisterInvariants(ir)
}

// Route returns the message routing key for the slashing module.
func (am AppModule) Route() string {
return am.cosmosAppModule.Route()
}

// NewHandler returns an sdk.Handler for the slashing module.
func (am AppModule) NewHandler() sdk.Handler {
return am.cosmosAppModule.NewHandler()
}

// QuerierRoute returns the slashing module's querier route name.
func (am AppModule) QuerierRoute() string { return am.cosmosAppModule.QuerierRoute() }

// NewQuerierHandler returns the slashing module sdk.Querier.
func (am AppModule) NewQuerierHandler() sdk.Querier { return am.cosmosAppModule.NewQuerierHandler() }

// InitGenesis performs genesis initialization for the slashing module.
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
return am.cosmosAppModule.InitGenesis(ctx, data)
}

// ExportGenesis returns the exported genesis state as raw bytes for the slashing
// module.
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
return am.cosmosAppModule.ExportGenesis(ctx)
}

// BeginBlock returns the begin blocker for the slashing module.
func (am AppModule) BeginBlock(ctx sdk.Context, rbb abci.RequestBeginBlock) {
am.cosmosAppModule.BeginBlock(ctx, rbb)
}

// EndBlock returns the end blocker for the slashing module.
func (am AppModule) EndBlock(ctx sdk.Context, rbb abci.RequestEndBlock) []abci.ValidatorUpdate {
return am.cosmosAppModule.EndBlock(ctx, rbb)
}

//____________________________________________________________________________

// AppModuleSimulation functions

// GenerateGenesisState creates a randomized GenState of the auth module
func (am AppModule) GenerateGenesisState(simState *module.SimulationState) {
am.cosmosAppModule.GenerateGenesisState(simState)
}

// ProposalContents doesn't return any content functions for governance proposals.
func (am AppModule) ProposalContents(simState module.SimulationState) []sim.WeightedProposalContent {
return am.cosmosAppModule.ProposalContents(simState)
}

// RandomizedParams creates randomized auth param changes for the simulator.
func (am AppModule) RandomizedParams(r *rand.Rand) []sim.ParamChange {
return am.cosmosAppModule.RandomizedParams(r)
}

// RegisterStoreDecoder registers a decoder for auth module's types
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
am.cosmosAppModule.RegisterStoreDecoder(sdr)
}

// WeightedOperations doesn't return any auth module operation.
func (am AppModule) WeightedOperations(simState module.SimulationState) []sim.WeightedOperation {
return am.cosmosAppModule.WeightedOperations(simState)
}

0 comments on commit 4cc75e5

Please sign in to comment.