diff --git a/client/app/app.go b/client/app/app.go index 094aafd6..6927b903 100644 --- a/client/app/app.go +++ b/client/app/app.go @@ -24,6 +24,7 @@ import ( "github.com/piplabs/story/client/app/keepers" "github.com/piplabs/story/client/comet" evmstakingkeeper "github.com/piplabs/story/client/x/evmstaking/keeper" + mintkeeper "github.com/piplabs/story/client/x/mint/keeper" "github.com/piplabs/story/lib/errors" "github.com/piplabs/story/lib/ethclient" @@ -36,7 +37,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/distribution" // import for side-effects _ "github.com/cosmos/cosmos-sdk/x/genutil" // import for side-effects _ "github.com/cosmos/cosmos-sdk/x/gov" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/mint" // import for side-effects _ "github.com/cosmos/cosmos-sdk/x/slashing" // import for side-effects _ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects ) @@ -95,6 +95,7 @@ func newApp( &app.Keepers.EpochsKeeper, &app.Keepers.EvmStakingKeeper, &app.Keepers.EVMEngKeeper, + &app.Keepers.MintKeeper, ); err != nil { return nil, errors.Wrap(err, "dep inject") } @@ -207,3 +208,7 @@ func (a App) GetDistrKeeper() distrkeeper.Keeper { func (a App) GetUpgradeKeeper() *upgradekeeper.Keeper { return a.Keepers.UpgradeKeeper } + +func (a App) GetMintKeeper() mintkeeper.Keeper { + return a.Keepers.MintKeeper +} diff --git a/client/app/app_config.go b/client/app/app_config.go index faee4920..3a5c5b98 100644 --- a/client/app/app_config.go +++ b/client/app/app_config.go @@ -9,7 +9,6 @@ import ( distrmodulev1 "cosmossdk.io/api/cosmos/distribution/module/v1" genutilmodulev1 "cosmossdk.io/api/cosmos/genutil/module/v1" govmodulev1 "cosmossdk.io/api/cosmos/gov/module/v1" - mintmodulev1 "cosmossdk.io/api/cosmos/mint/module/v1" slashingmodulev1 "cosmossdk.io/api/cosmos/slashing/module/v1" stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" @@ -26,7 +25,6 @@ import ( distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -36,6 +34,8 @@ import ( evmenginetypes "github.com/piplabs/story/client/x/evmengine/types" evmstakingmodule "github.com/piplabs/story/client/x/evmstaking/module" evmstakingtypes "github.com/piplabs/story/client/x/evmstaking/types" + mintmodule "github.com/piplabs/story/client/x/mint/module" + minttypes "github.com/piplabs/story/client/x/mint/types" ) // Bech32HRP is the human-readable-part of the Bech32 address format. @@ -215,7 +215,7 @@ var ( }, { Name: minttypes.ModuleName, - Config: appconfig.WrapAny(&mintmodulev1.Module{}), + Config: appconfig.WrapAny(&mintmodule.Module{}), }, }, }) diff --git a/client/app/keepers/types.go b/client/app/keepers/types.go index 7b21abdc..71e85a94 100644 --- a/client/app/keepers/types.go +++ b/client/app/keepers/types.go @@ -18,6 +18,7 @@ import ( epochskeeper "github.com/piplabs/story/client/x/epochs/keeper" evmengkeeper "github.com/piplabs/story/client/x/evmengine/keeper" evmstakingkeeper "github.com/piplabs/story/client/x/evmstaking/keeper" + mintkeeper "github.com/piplabs/story/client/x/mint/keeper" ) // Keepers includes all possible keepers. We separated it into a separate struct to make it easier to scaffold upgrades. @@ -36,4 +37,5 @@ type Keepers struct { EvmStakingKeeper *evmstakingkeeper.Keeper EVMEngKeeper *evmengkeeper.Keeper EpochsKeeper *epochskeeper.Keeper + MintKeeper mintkeeper.Keeper } diff --git a/client/server/mint.go b/client/server/mint.go new file mode 100644 index 00000000..76051229 --- /dev/null +++ b/client/server/mint.go @@ -0,0 +1,28 @@ +package server + +import ( + "net/http" + + "github.com/piplabs/story/client/server/utils" + "github.com/piplabs/story/client/x/mint/keeper" + minttypes "github.com/piplabs/story/client/x/mint/types" +) + +func (s *Server) initMintRoute() { + s.httpMux.HandleFunc("/mint/params", utils.SimpleWrap(s.aminoCodec, s.GetMintParams)) +} + +// GetMintParams queries params of the mint module. +func (s *Server) GetMintParams(r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := keeper.NewQuerier(s.store.GetMintKeeper()).Params(queryContext, &minttypes.QueryParamsRequest{}) + if err != nil { + return nil, err + } + + return queryResp, nil +} diff --git a/client/server/server.go b/client/server/server.go index ce31c476..d866c549 100644 --- a/client/server/server.go +++ b/client/server/server.go @@ -28,6 +28,7 @@ import ( "github.com/gorilla/mux" evmstakingkeeper "github.com/piplabs/story/client/x/evmstaking/keeper" + mintkeeper "github.com/piplabs/story/client/x/mint/keeper" ) type Store interface { @@ -39,6 +40,7 @@ type Store interface { GetBankKeeper() bankkeeper.Keeper GetDistrKeeper() distrkeeper.Keeper GetUpgradeKeeper() *upgradekeeper.Keeper + GetMintKeeper() mintkeeper.Keeper } type Server struct { @@ -121,6 +123,7 @@ func (s *Server) registerHandle() { s.initSlashingRoute() s.initStakingRoute() s.initUpgradeRoute() + s.initMintRoute() } func (s *Server) createQueryContextByHeader(r *http.Request) (sdk.Context, error) { diff --git a/client/x/evmengine/keeper/abci_internal_test.go b/client/x/evmengine/keeper/abci_internal_test.go index 0206a04c..eca2a1fc 100644 --- a/client/x/evmengine/keeper/abci_internal_test.go +++ b/client/x/evmengine/keeper/abci_internal_test.go @@ -221,6 +221,7 @@ func TestKeeper_PrepareProposal(t *testing.T) { ak := moduletestutil.NewMockAccountKeeper(ctrl) esk := moduletestutil.NewMockEvmStakingKeeper(ctrl) uk := moduletestutil.NewMockUpgradeKeeper(ctrl) + mk := moduletestutil.NewMockMintKeeper(ctrl) if tt.setupMocks != nil { tt.setupMocks(esk) @@ -230,7 +231,7 @@ func TestKeeper_PrepareProposal(t *testing.T) { tt.mockEngine.EngineClient, err = ethclient.NewEngineMock(storeKey) require.NoError(t, err) - k, err := NewKeeper(cdc, storeService, &tt.mockEngine, &tt.mockClient, txConfig, ak, esk, uk) + k, err := NewKeeper(cdc, storeService, &tt.mockEngine, &tt.mockClient, txConfig, ak, esk, uk, mk) require.NoError(t, err) k.SetValidatorAddress(common.BytesToAddress([]byte("test"))) populateGenesisHead(ctx, t, k) @@ -261,11 +262,11 @@ func TestKeeper_PrepareProposal(t *testing.T) { ak := moduletestutil.NewMockAccountKeeper(ctrl) esk := moduletestutil.NewMockEvmStakingKeeper(ctrl) uk := moduletestutil.NewMockUpgradeKeeper(ctrl) - + mk := moduletestutil.NewMockMintKeeper(ctrl) // Expected call for PeekEligibleWithdrawals esk.EXPECT().PeekEligibleWithdrawals(gomock.Any()).Return(nil, nil).AnyTimes() - keeper, err := NewKeeper(cdc, storeService, &mockEngine, mockClient, txConfig, ak, esk, uk) + keeper, err := NewKeeper(cdc, storeService, &mockEngine, mockClient, txConfig, ak, esk, uk, mk) require.NoError(t, err) keeper.SetValidatorAddress(common.BytesToAddress([]byte("test"))) populateGenesisHead(ctx, t, keeper) @@ -446,6 +447,7 @@ func TestKeeper_PostFinalize(t *testing.T) { ak := moduletestutil.NewMockAccountKeeper(ctrl) esk := moduletestutil.NewMockEvmStakingKeeper(ctrl) uk := moduletestutil.NewMockUpgradeKeeper(ctrl) + mk := moduletestutil.NewMockMintKeeper(ctrl) if tt.setupMocks != nil { tt.setupMocks(esk) @@ -464,7 +466,7 @@ func TestKeeper_PostFinalize(t *testing.T) { tt.mockEngine.EngineClient, err = ethclient.NewEngineMock(storeKey) require.NoError(t, err) - k, err := NewKeeper(cdc, storeService, &tt.mockEngine, &tt.mockClient, txConfig, ak, esk, uk) + k, err := NewKeeper(cdc, storeService, &tt.mockEngine, &tt.mockClient, txConfig, ak, esk, uk, mk) require.NoError(t, err) k.SetCometAPI(cmtAPI) k.SetValidatorAddress(nxtAddr) diff --git a/client/x/evmengine/keeper/keeper.go b/client/x/evmengine/keeper/keeper.go index 41e265a3..fe6a6ee7 100644 --- a/client/x/evmengine/keeper/keeper.go +++ b/client/x/evmengine/keeper/keeper.go @@ -41,6 +41,7 @@ type Keeper struct { accountKeeper types.AccountKeeper evmstakingKeeper types.EvmStakingKeeper upgradeKeeper types.UpgradeKeeper + mintKeeper types.MintKeeper upgradeContract *bindings.UpgradeEntrypoint @@ -64,6 +65,7 @@ func NewKeeper( ak types.AccountKeeper, esk types.EvmStakingKeeper, uk types.UpgradeKeeper, + mk types.MintKeeper, ) (*Keeper, error) { schema := &ormv1alpha1.ModuleSchemaDescriptor{SchemaFile: []*ormv1alpha1.ModuleSchemaDescriptor_FileEntry{ {Id: 1, ProtoFileName: File_client_x_evmengine_keeper_evmengine_proto.Path()}, @@ -94,6 +96,7 @@ func NewKeeper( evmstakingKeeper: esk, upgradeKeeper: uk, upgradeContract: upgradeContract, + mintKeeper: mk, }, nil } diff --git a/client/x/evmengine/keeper/keeper_internal_test.go b/client/x/evmengine/keeper/keeper_internal_test.go index 40fd34a9..d9ab3b58 100644 --- a/client/x/evmengine/keeper/keeper_internal_test.go +++ b/client/x/evmengine/keeper/keeper_internal_test.go @@ -49,12 +49,13 @@ func createTestKeeper(t *testing.T) (context.Context, *Keeper) { ak := moduletestutil.NewMockAccountKeeper(ctrl) esk := moduletestutil.NewMockEvmStakingKeeper(ctrl) uk := moduletestutil.NewMockUpgradeKeeper(ctrl) + mk := moduletestutil.NewMockMintKeeper(ctrl) ctx, storeKey, storeService := setupCtxStore(t, &header) mockEngine, err := newMockEngineAPI(storeKey, 0) require.NoError(t, err) - keeper, err := NewKeeper(cdc, storeService, &mockEngine, mockClient, txConfig, ak, esk, uk) + keeper, err := NewKeeper(cdc, storeService, &mockEngine, mockClient, txConfig, ak, esk, uk, mk) require.NoError(t, err) keeper.SetCometAPI(cmtAPI) @@ -78,11 +79,12 @@ func createKeeper(t *testing.T, args args) (sdk.Context, *mockCometAPI, *Keeper) ak := moduletestutil.NewMockAccountKeeper(ctrl) esk := moduletestutil.NewMockEvmStakingKeeper(ctrl) uk := moduletestutil.NewMockUpgradeKeeper(ctrl) + mk := moduletestutil.NewMockMintKeeper(ctrl) ctx, storeKey, storeService := setupCtxStore(t, &header) mockEngine, err := newMockEngineAPI(storeKey, 0) require.NoError(t, err) - keeper, err := NewKeeper(cdc, storeService, &mockEngine, mockClient, txConfig, ak, esk, uk) + keeper, err := NewKeeper(cdc, storeService, &mockEngine, mockClient, txConfig, ak, esk, uk, mk) require.NoError(t, err) keeper.SetCometAPI(cmtAPI) keeper.SetValidatorAddress(nxtAddr) diff --git a/client/x/evmengine/keeper/msg_server.go b/client/x/evmengine/keeper/msg_server.go index 01591507..fb77c4c4 100644 --- a/client/x/evmengine/keeper/msg_server.go +++ b/client/x/evmengine/keeper/msg_server.go @@ -115,6 +115,9 @@ func (s msgServer) ExecutionPayload(ctx context.Context, msg *types.MsgExecution if err := s.ProcessUpgradeEvents(ctx, payload.Number-1, msg.PrevPayloadEvents); err != nil { return nil, errors.Wrap(err, "deliver upgrade-related event logs") } + if err := s.mintKeeper.ProcessInflationEvents(ctx, payload.Number-1, msg.PrevPayloadEvents); err != nil { + return nil, errors.Wrap(err, "deliver inflation-related event logs") + } if err := s.updateExecutionHead(ctx, payload); err != nil { return nil, errors.Wrap(err, "update execution head") diff --git a/client/x/evmengine/keeper/msg_server_internal_test.go b/client/x/evmengine/keeper/msg_server_internal_test.go index e2378bca..b3f93cdc 100644 --- a/client/x/evmengine/keeper/msg_server_internal_test.go +++ b/client/x/evmengine/keeper/msg_server_internal_test.go @@ -40,6 +40,7 @@ func Test_msgServer_ExecutionPayload(t *testing.T) { ak := moduletestutil.NewMockAccountKeeper(ctrl) esk := moduletestutil.NewMockEvmStakingKeeper(ctrl) uk := moduletestutil.NewMockUpgradeKeeper(ctrl) + mk := moduletestutil.NewMockMintKeeper(ctrl) cmtAPI := newMockCometAPI(t, nil) // set the header and proposer so we have the correct next proposer @@ -53,7 +54,7 @@ func Test_msgServer_ExecutionPayload(t *testing.T) { evmLogProc := mockLogProvider{deliverErr: errors.New("test error")} mockEngine, err := newMockEngineAPI(storeKey, 2) require.NoError(t, err) - keeper, err := NewKeeper(cdc, storeService, &mockEngine, mockClient, txConfig, ak, esk, uk) + keeper, err := NewKeeper(cdc, storeService, &mockEngine, mockClient, txConfig, ak, esk, uk, mk) require.NoError(t, err) keeper.SetCometAPI(cmtAPI) keeper.SetValidatorAddress(nxtAddr) @@ -99,6 +100,7 @@ func Test_msgServer_ExecutionPayload(t *testing.T) { setup: func(c context.Context) sdk.Context { esk.EXPECT().DequeueEligibleWithdrawals(c).Return(nil, nil) esk.EXPECT().ProcessStakingEvents(c, gomock.Any(), gomock.Any()).Return(nil) + mk.EXPECT().ProcessInflationEvents(c, gomock.Any(), gomock.Any()).Return(nil) return sdk.UnwrapSDKContext(c) }, diff --git a/client/x/evmengine/keeper/proposal_server_internal_test.go b/client/x/evmengine/keeper/proposal_server_internal_test.go index 96c9d5ec..45e590a9 100644 --- a/client/x/evmengine/keeper/proposal_server_internal_test.go +++ b/client/x/evmengine/keeper/proposal_server_internal_test.go @@ -34,14 +34,14 @@ func Test_proposalServer_ExecutionPayload(t *testing.T) { ak := moduletestutil.NewMockAccountKeeper(ctrl) esk := moduletestutil.NewMockEvmStakingKeeper(ctrl) uk := moduletestutil.NewMockUpgradeKeeper(ctrl) - + mk := moduletestutil.NewMockMintKeeper(ctrl) esk.EXPECT().PeekEligibleWithdrawals(gomock.Any()).Return(nil, nil).AnyTimes() sdkCtx, storeKey, storeService := setupCtxStore(t, &cmtproto.Header{AppHash: tutil.RandomHash().Bytes()}) sdkCtx = sdkCtx.WithExecMode(sdk.ExecModeFinalize) mockEngine, err := newMockEngineAPI(storeKey, 0) require.NoError(t, err) - keeper, err := NewKeeper(cdc, storeService, &mockEngine, mockClient, txConfig, ak, esk, uk) + keeper, err := NewKeeper(cdc, storeService, &mockEngine, mockClient, txConfig, ak, esk, uk, mk) require.NoError(t, err) populateGenesisHead(sdkCtx, t, keeper) propSrv := NewProposalServer(keeper) diff --git a/client/x/evmengine/keeper/upgrades_internal_test.go b/client/x/evmengine/keeper/upgrades_internal_test.go index 722c69a1..8aea641f 100644 --- a/client/x/evmengine/keeper/upgrades_internal_test.go +++ b/client/x/evmengine/keeper/upgrades_internal_test.go @@ -262,12 +262,13 @@ func setupTestEnvironment(t *testing.T) (*Keeper, sdk.Context, *gomock.Controlle ak := moduletestutil.NewMockAccountKeeper(ctrl) esk := moduletestutil.NewMockEvmStakingKeeper(ctrl) uk := moduletestutil.NewMockUpgradeKeeper(ctrl) + mk := moduletestutil.NewMockMintKeeper(ctrl) ctx, storeKey, storeService := setupCtxStore(t, &header) mockEngine, err := newMockEngineAPI(storeKey, 0) require.NoError(t, err) - keeper, err := NewKeeper(cdc, storeService, &mockEngine, mockClient, txConfig, ak, esk, uk) + keeper, err := NewKeeper(cdc, storeService, &mockEngine, mockClient, txConfig, ak, esk, uk, mk) require.NoError(t, err) keeper.SetCometAPI(cmtAPI) nxtAddr, err := k1util.PubKeyToAddress(cmtAPI.validatorSet.Validators[1].PubKey) diff --git a/client/x/evmengine/module/depinject.go b/client/x/evmengine/module/depinject.go index 25b66a39..e35d3dd4 100644 --- a/client/x/evmengine/module/depinject.go +++ b/client/x/evmengine/module/depinject.go @@ -36,6 +36,7 @@ type ModuleInputs struct { AccountKeeper types.AccountKeeper EvmStakingKeeper types.EvmStakingKeeper UpgradeKeeper types.UpgradeKeeper + MintKeeper types.MintKeeper } type ModuleOutputs struct { @@ -56,6 +57,7 @@ func ProvideModule(in ModuleInputs) (ModuleOutputs, error) { in.AccountKeeper, in.EvmStakingKeeper, in.UpgradeKeeper, + in.MintKeeper, ) if err != nil { return ModuleOutputs{}, err diff --git a/client/x/evmengine/testutil/expected_keepers_mocks.go b/client/x/evmengine/testutil/expected_keepers_mocks.go index 3d40b6cc..cd96969d 100644 --- a/client/x/evmengine/testutil/expected_keepers_mocks.go +++ b/client/x/evmengine/testutil/expected_keepers_mocks.go @@ -219,3 +219,40 @@ func (mr *MockUpgradeKeeperMockRecorder) ScheduleUpgrade(ctx, plan any) *gomock. mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ScheduleUpgrade", reflect.TypeOf((*MockUpgradeKeeper)(nil).ScheduleUpgrade), ctx, plan) } + +// MockMintKeeper is a mock of MintKeeper interface. +type MockMintKeeper struct { + ctrl *gomock.Controller + recorder *MockMintKeeperMockRecorder +} + +// MockMintKeeperMockRecorder is the mock recorder for MockMintKeeper. +type MockMintKeeperMockRecorder struct { + mock *MockMintKeeper +} + +// NewMockMintKeeper creates a new mock instance. +func NewMockMintKeeper(ctrl *gomock.Controller) *MockMintKeeper { + mock := &MockMintKeeper{ctrl: ctrl} + mock.recorder = &MockMintKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockMintKeeper) EXPECT() *MockMintKeeperMockRecorder { + return m.recorder +} + +// ProcessInflationEvents mocks base method. +func (m *MockMintKeeper) ProcessInflationEvents(ctx context.Context, height uint64, logs []*types2.EVMEvent) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProcessInflationEvents", ctx, height, logs) + ret0, _ := ret[0].(error) + return ret0 +} + +// ProcessInflationEvents indicates an expected call of ProcessInflationEvents. +func (mr *MockMintKeeperMockRecorder) ProcessInflationEvents(ctx, height, logs any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProcessInflationEvents", reflect.TypeOf((*MockMintKeeper)(nil).ProcessInflationEvents), ctx, height, logs) +} diff --git a/client/x/evmengine/types/expected_keepers.go b/client/x/evmengine/types/expected_keepers.go index 59ca321f..401899f8 100644 --- a/client/x/evmengine/types/expected_keepers.go +++ b/client/x/evmengine/types/expected_keepers.go @@ -28,3 +28,7 @@ type EvmStakingKeeper interface { type UpgradeKeeper interface { ScheduleUpgrade(ctx context.Context, plan upgradetypes.Plan) error } + +type MintKeeper interface { + ProcessInflationEvents(ctx context.Context, height uint64, logs []*EVMEvent) error +} diff --git a/client/x/mint/README.md b/client/x/mint/README.md new file mode 100644 index 00000000..600267c3 --- /dev/null +++ b/client/x/mint/README.md @@ -0,0 +1,76 @@ +--- +sidebar_position: 1 +--- + +# `x/mint` + +## Contents + +- [`x/mint`](#xmint) + - [Contents](#contents) + - [State](#state) + - [Params](#params) + - [Begin-Block](#begin-block) + - [Inflation amount calculation](#inflation-amount-calculation) + - [Parameters](#parameters) + - [Events](#events) + - [BeginBlocker](#beginblocker) + +## State + +### Params + +The mint module stores its params in state with the prefix of `0x01`, +it can be updated by authority via specific smart contract. + +* Params: `mint/params -> legacy_amino(params)` + +```protobuf +message Params { + option (amino.name) = "client/x/mint/Params"; + + // type of coin to mint + string mint_denom = 1; + // inflation amount per year + uint64 inflations_per_year = 2; + // expected blocks per year + uint64 blocks_per_year = ; +} +``` + +## Begin-Block + +Minting parameters are calculated and inflation paid at the beginning of each block. + +### Inflation amount calculation + +Inflation amount is calculated using an "inflation calculation function" that's +passed to the `NewAppModule` function. If no function is passed, then the SDK's +default inflation function will be used (`DefaultInflationCalculationFn`). In case a custom +inflation calculation logic is needed, this can be achieved by defining and +passing a function that matches `InflationCalculationFn`'s signature. + +```go +type InflationCalculationFn func(ctx sdk.Context, minter Minter, params Params, bondedRatio math.LegacyDec) math.LegacyDec +``` + +## Parameters + +The minting module contains the following parameters: + +| Key | Type | Example | +|---------------------|-----------------|------------------------------| +| MintDenom | string | "stake" | +| InflationsPerYear | string (dec) | "24625000000000000" | +| BlocksPerYear | string (uint64) | "6311520" | + + +## Events + +The minting module emits the following events: + +### BeginBlocker + +| Type | Attribute Key | Attribute Value | +|------|-------------------|--------------------| +| mint | amount | {amount} | diff --git a/client/x/mint/keeper/abci.go b/client/x/mint/keeper/abci.go new file mode 100644 index 00000000..3fb8198e --- /dev/null +++ b/client/x/mint/keeper/abci.go @@ -0,0 +1,49 @@ +package keeper + +import ( + "context" + + "cosmossdk.io/math" + + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/piplabs/story/client/x/mint/types" +) + +// BeginBlocker mints new tokens for the previous block. +func (k Keeper) BeginBlocker(ctx context.Context, ic types.InflationCalculationFn) error { + defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) + + params, err := k.Params.Get(ctx) + if err != nil { + return err + } + + // mint coins, update supply + mintedCoinAmt := ic(ctx, params, math.LegacyNewDec(0)) // NOTE: bondedRatio is not used in current implementation. + mintedCoin := sdk.NewCoin(params.MintDenom, mintedCoinAmt.TruncateInt()) + mintedCoins := sdk.NewCoins(mintedCoin) + if err := k.MintCoins(ctx, mintedCoins); err != nil { + return err + } + + // send the minted coins to the fee collector account + if err := k.AddCollectedFees(ctx, mintedCoins); err != nil { + return err + } + + if mintedCoin.Amount.IsInt64() { + defer telemetry.ModuleSetGauge(types.ModuleName, float32(mintedCoin.Amount.Int64()), "minted_tokens") + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + sdkCtx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeMint, + sdk.NewAttribute(sdk.AttributeKeyAmount, mintedCoin.Amount.String()), + ), + ) + + return nil +} diff --git a/client/x/mint/keeper/genesis.go b/client/x/mint/keeper/genesis.go new file mode 100644 index 00000000..3b12a540 --- /dev/null +++ b/client/x/mint/keeper/genesis.go @@ -0,0 +1,26 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/piplabs/story/client/x/mint/types" +) + +// InitGenesis new mint genesis. +func (k Keeper) InitGenesis(ctx sdk.Context, ak types.AccountKeeper, data *types.GenesisState) { + if err := k.Params.Set(ctx, data.Params); err != nil { + panic(err) + } + + ak.GetModuleAccount(ctx, types.ModuleName) +} + +// ExportGenesis returns a GenesisState for a given context and keeper. +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + params, err := k.Params.Get(ctx) + if err != nil { + panic(err) + } + + return types.NewGenesisState(params) +} diff --git a/client/x/mint/keeper/genesis_test.go b/client/x/mint/keeper/genesis_test.go new file mode 100644 index 00000000..affa5818 --- /dev/null +++ b/client/x/mint/keeper/genesis_test.go @@ -0,0 +1,77 @@ +//nolint:paralleltest // just for testing +package keeper_test + +import ( + "testing" + + storetypes "cosmossdk.io/store/types" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/suite" + + "github.com/piplabs/story/client/x/mint/keeper" + mintmodule "github.com/piplabs/story/client/x/mint/module" + minttestutil "github.com/piplabs/story/client/x/mint/testutil" + "github.com/piplabs/story/client/x/mint/types" +) + +var minterAcc = authtypes.NewEmptyModuleAccount(types.ModuleName, authtypes.Minter) + +type GenesisTestSuite struct { + suite.Suite + + sdkCtx sdk.Context + keeper keeper.Keeper + cdc codec.BinaryCodec + accountKeeper types.AccountKeeper + key *storetypes.KVStoreKey +} + +func TestGenesisTestSuite(t *testing.T) { + suite.Run(t, new(GenesisTestSuite)) +} + +func (s *GenesisTestSuite) SetupTest() { + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(mintmodule.AppModuleBasic{}) + + // gomock initializations + ctrl := gomock.NewController(s.T()) + s.cdc = codec.NewProtoCodec(encCfg.InterfaceRegistry) + s.sdkCtx = testCtx.Ctx + s.key = key + + stakingKeeper := minttestutil.NewMockStakingKeeper(ctrl) + accountKeeper := minttestutil.NewMockAccountKeeper(ctrl) + bankKeeper := minttestutil.NewMockBankKeeper(ctrl) + s.accountKeeper = accountKeeper + accountKeeper.EXPECT().GetModuleAddress(minterAcc.Name).Return(minterAcc.GetAddress()) + accountKeeper.EXPECT().GetModuleAccount(s.sdkCtx, minterAcc.Name).Return(minterAcc) + + s.keeper = keeper.NewKeeper(s.cdc, runtime.NewKVStoreService(key), stakingKeeper, accountKeeper, bankKeeper, "") +} + +func (s *GenesisTestSuite) TestImportExportGenesis() { + genesisState := types.DefaultGenesisState() + genesisState.Params = types.NewParams( + "testDenom", + 24625000_000_000_000, + uint64(60*60*8766/5), + ) + + s.keeper.InitGenesis(s.sdkCtx, s.accountKeeper, genesisState) + + params, err := s.keeper.Params.Get(s.sdkCtx) + s.Require().Equal(genesisState.Params, params) + s.Require().NoError(err) + + genesisState2 := s.keeper.ExportGenesis(s.sdkCtx) + s.Require().Equal(genesisState, genesisState2) +} diff --git a/client/x/mint/keeper/grpc_query.go b/client/x/mint/keeper/grpc_query.go new file mode 100644 index 00000000..de614f23 --- /dev/null +++ b/client/x/mint/keeper/grpc_query.go @@ -0,0 +1,27 @@ +package keeper + +import ( + "context" + + "github.com/piplabs/story/client/x/mint/types" +) + +var _ types.QueryServer = Querier{} + +func NewQuerier(k Keeper) types.QueryServer { + return Querier{k} +} + +type Querier struct { + k Keeper +} + +// Params returns params of the mint module. +func (q Querier) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + params, err := q.k.Params.Get(ctx) + if err != nil { + return nil, err + } + + return &types.QueryParamsResponse{Params: params}, nil +} diff --git a/client/x/mint/keeper/grpc_query_test.go b/client/x/mint/keeper/grpc_query_test.go new file mode 100644 index 00000000..63b433d6 --- /dev/null +++ b/client/x/mint/keeper/grpc_query_test.go @@ -0,0 +1,76 @@ +//nolint:paralleltest // just for testing +package keeper_test + +import ( + gocontext "context" + "testing" + + storetypes "cosmossdk.io/store/types" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/suite" + + "github.com/piplabs/story/client/x/mint/keeper" + mintmodule "github.com/piplabs/story/client/x/mint/module" + minttestutil "github.com/piplabs/story/client/x/mint/testutil" + "github.com/piplabs/story/client/x/mint/types" +) + +type MintTestSuite struct { + suite.Suite + + ctx sdk.Context + queryClient types.QueryClient + mintKeeper keeper.Keeper +} + +func (suite *MintTestSuite) SetupTest() { + encCfg := moduletestutil.MakeTestEncodingConfig(mintmodule.AppModuleBasic{}) + key := storetypes.NewKVStoreKey(types.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) + suite.ctx = testCtx.Ctx + + // gomock initializations + ctrl := gomock.NewController(suite.T()) + accountKeeper := minttestutil.NewMockAccountKeeper(ctrl) + bankKeeper := minttestutil.NewMockBankKeeper(ctrl) + stakingKeeper := minttestutil.NewMockStakingKeeper(ctrl) + + accountKeeper.EXPECT().GetModuleAddress("mint").Return(sdk.AccAddress{}) + + suite.mintKeeper = keeper.NewKeeper( + encCfg.Codec, + storeService, + stakingKeeper, + accountKeeper, + bankKeeper, + authtypes.FeeCollectorName, + ) + + err := suite.mintKeeper.Params.Set(suite.ctx, types.DefaultParams()) + suite.Require().NoError(err) + + queryHelper := baseapp.NewQueryServerTestHelper(testCtx.Ctx, encCfg.InterfaceRegistry) + types.RegisterQueryServer(queryHelper, keeper.NewQuerier(suite.mintKeeper)) + + suite.queryClient = types.NewQueryClient(queryHelper) +} + +func (suite *MintTestSuite) TestGRPCParams() { + params, err := suite.queryClient.Params(gocontext.Background(), &types.QueryParamsRequest{}) + suite.Require().NoError(err) + kparams, err := suite.mintKeeper.Params.Get(suite.ctx) + suite.Require().NoError(err) + suite.Require().Equal(params.Params, kparams) +} + +func TestMintTestSuite(t *testing.T) { + suite.Run(t, new(MintTestSuite)) +} diff --git a/client/x/mint/keeper/keeper.go b/client/x/mint/keeper/keeper.go new file mode 100644 index 00000000..0f1d9394 --- /dev/null +++ b/client/x/mint/keeper/keeper.go @@ -0,0 +1,110 @@ +//nolint:revive // just use interface{} +package keeper + +import ( + "context" + "fmt" + + "cosmossdk.io/collections" + storetypes "cosmossdk.io/core/store" + "cosmossdk.io/log" + "cosmossdk.io/math" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + evmenginetypes "github.com/piplabs/story/client/x/evmengine/types" + "github.com/piplabs/story/client/x/mint/types" + "github.com/piplabs/story/contracts/bindings" + clog "github.com/piplabs/story/lib/log" +) + +// Keeper of the mint store. +type Keeper struct { + cdc codec.BinaryCodec + storeService storetypes.KVStoreService + stakingKeeper types.StakingKeeper + bankKeeper types.BankKeeper + feeCollectorName string + + inflationUpdateContract *bindings.IPTokenStaking // (rayden) TODO + + Schema collections.Schema + Params collections.Item[types.Params] +} + +// NewKeeper creates a new mint Keeper instance. +func NewKeeper( + cdc codec.BinaryCodec, + storeService storetypes.KVStoreService, + sk types.StakingKeeper, + ak types.AccountKeeper, + bk types.BankKeeper, + feeCollectorName string, +) Keeper { + // ensure mint module account is set + if addr := ak.GetModuleAddress(types.ModuleName); addr == nil { + panic(fmt.Sprintf("the x/%s module account has not been set", types.ModuleName)) + } + + sb := collections.NewSchemaBuilder(storeService) + k := Keeper{ + cdc: cdc, + storeService: storeService, + stakingKeeper: sk, + bankKeeper: bk, + feeCollectorName: feeCollectorName, + inflationUpdateContract: nil, + Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), + } + + schema, err := sb.Build() + if err != nil { + panic(err) + } + k.Schema = schema + + return k +} + +// Logger returns a module-specific logger. +func (k Keeper) Logger(ctx context.Context) log.Logger { + sdkCtx := sdk.UnwrapSDKContext(ctx) + return sdkCtx.Logger().With("module", "x/"+types.ModuleName) +} + +// StakingTokenSupply implements an alias call to the underlying staking keeper's +// StakingTokenSupply to be used in BeginBlocker. +func (k Keeper) StakingTokenSupply(ctx context.Context) (math.Int, error) { + return k.stakingKeeper.StakingTokenSupply(ctx) +} + +// BondedRatio implements an alias call to the underlying staking keeper's +// BondedRatio to be used in BeginBlocker. +func (k Keeper) BondedRatio(ctx context.Context) (math.LegacyDec, error) { + return k.stakingKeeper.BondedRatio(ctx) +} + +// MintCoins implements an alias call to the underlying supply keeper's +// MintCoins to be used in BeginBlocker. +func (k Keeper) MintCoins(ctx context.Context, newCoins sdk.Coins) error { + if newCoins.Empty() { + // skip as no coins need to be minted + return nil + } + + return k.bankKeeper.MintCoins(ctx, types.ModuleName, newCoins) +} + +// AddCollectedFees implements an alias call to the underlying supply keeper's +// AddCollectedFees to be used in BeginBlocker. +func (k Keeper) AddCollectedFees(ctx context.Context, fees sdk.Coins) error { + return k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, k.feeCollectorName, fees) +} + +func (k Keeper) ProcessInflationEvents(ctx context.Context, height uint64, logs []*evmenginetypes.EVMEvent) error { + // (rayden) TODO + clog.Debug(ctx, "Processed inflation events", "height", height, "count", len(logs)) + + return nil +} diff --git a/client/x/mint/keeper/keeper_test.go b/client/x/mint/keeper/keeper_test.go new file mode 100644 index 00000000..c22fa287 --- /dev/null +++ b/client/x/mint/keeper/keeper_test.go @@ -0,0 +1,91 @@ +//nolint:paralleltest // just for testing +package keeper_test + +import ( + "testing" + + "cosmossdk.io/math" + storetypes "cosmossdk.io/store/types" + + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/suite" + + "github.com/piplabs/story/client/x/mint/keeper" + mintmodule "github.com/piplabs/story/client/x/mint/module" + minttestutil "github.com/piplabs/story/client/x/mint/testutil" + "github.com/piplabs/story/client/x/mint/types" +) + +type IntegrationTestSuite struct { + suite.Suite + + mintKeeper keeper.Keeper + ctx sdk.Context + stakingKeeper *minttestutil.MockStakingKeeper + bankKeeper *minttestutil.MockBankKeeper +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(IntegrationTestSuite)) +} + +func (s *IntegrationTestSuite) SetupTest() { + encCfg := moduletestutil.MakeTestEncodingConfig(mintmodule.AppModuleBasic{}) + key := storetypes.NewKVStoreKey(types.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) + s.ctx = testCtx.Ctx + + // gomock initializations + ctrl := gomock.NewController(s.T()) + accountKeeper := minttestutil.NewMockAccountKeeper(ctrl) + bankKeeper := minttestutil.NewMockBankKeeper(ctrl) + stakingKeeper := minttestutil.NewMockStakingKeeper(ctrl) + + accountKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(sdk.AccAddress{}) + + s.mintKeeper = keeper.NewKeeper( + encCfg.Codec, + storeService, + stakingKeeper, + accountKeeper, + bankKeeper, + authtypes.FeeCollectorName, + ) + s.stakingKeeper = stakingKeeper + s.bankKeeper = bankKeeper + + s.Require().Equal(testCtx.Ctx.Logger().With("module", "x/"+types.ModuleName), + s.mintKeeper.Logger(testCtx.Ctx)) + + err := s.mintKeeper.Params.Set(s.ctx, types.DefaultParams()) + s.Require().NoError(err) +} + +func (s *IntegrationTestSuite) TestAliasFunctions() { + stakingTokenSupply := math.NewIntFromUint64(100000000000) + s.stakingKeeper.EXPECT().StakingTokenSupply(s.ctx).Return(stakingTokenSupply, nil) + tokenSupply, err := s.mintKeeper.StakingTokenSupply(s.ctx) + s.Require().NoError(err) + s.Require().Equal(tokenSupply, stakingTokenSupply) + + bondedRatio := math.LegacyNewDecWithPrec(15, 2) + s.stakingKeeper.EXPECT().BondedRatio(s.ctx).Return(bondedRatio, nil) + ratio, err := s.mintKeeper.BondedRatio(s.ctx) + s.Require().NoError(err) + s.Require().Equal(ratio, bondedRatio) + + coins := sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(1000000))) + s.bankKeeper.EXPECT().MintCoins(s.ctx, types.ModuleName, coins).Return(nil) + s.Require().NoError(s.mintKeeper.MintCoins(s.ctx, sdk.NewCoins())) + s.Require().NoError(s.mintKeeper.MintCoins(s.ctx, coins)) + + fees := sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(1000))) + s.bankKeeper.EXPECT().SendCoinsFromModuleToModule(s.ctx, types.ModuleName, authtypes.FeeCollectorName, fees).Return(nil) + s.Require().NoError(s.mintKeeper.AddCollectedFees(s.ctx, fees)) +} diff --git a/client/x/mint/keeper/params.go b/client/x/mint/keeper/params.go new file mode 100644 index 00000000..fa615d34 --- /dev/null +++ b/client/x/mint/keeper/params.go @@ -0,0 +1,19 @@ +package keeper + +import ( + "context" + + "github.com/piplabs/story/client/x/mint/types" +) + +func (k Keeper) GetParams(ctx context.Context) (types.Params, error) { + return k.Params.Get(ctx) +} + +func (k Keeper) SetParams(ctx context.Context, value types.Params) error { + if err := value.Validate(); err != nil { + return err + } + + return k.Params.Set(ctx, value) +} diff --git a/client/x/mint/keeper/set_inflation_parameters.go b/client/x/mint/keeper/set_inflation_parameters.go new file mode 100644 index 00000000..70de29cb --- /dev/null +++ b/client/x/mint/keeper/set_inflation_parameters.go @@ -0,0 +1,14 @@ +package keeper + +import ( + "context" + + "github.com/piplabs/story/contracts/bindings" +) + +//nolint:revive // (rayden) TODO +func (k Keeper) ProcessSetInflationParameters(ctx context.Context, ev *bindings.IPTokenStakingDeposit) error { + // (rayden) TODO + + return nil +} diff --git a/client/x/mint/module/depinject.go b/client/x/mint/module/depinject.go new file mode 100644 index 00000000..c1ef3699 --- /dev/null +++ b/client/x/mint/module/depinject.go @@ -0,0 +1,72 @@ +//nolint:revive // just use interface{} +package module + +import ( + "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/store" + "cosmossdk.io/depinject" + + "github.com/cosmos/cosmos-sdk/codec" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + + "github.com/piplabs/story/client/x/mint/keeper" + "github.com/piplabs/story/client/x/mint/types" +) + +var _ depinject.OnePerModuleType = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + +//nolint:gochecknoinits // depinject +func init() { + appmodule.Register( + &Module{}, + appmodule.Provide(ProvideModule), + ) +} + +type ModuleInputs struct { + depinject.In + + ModuleKey depinject.OwnModuleKey + Config *Module + StoreService store.KVStoreService + Cdc codec.Codec + InflationCalculationFn types.InflationCalculationFn `optional:"true"` + + AccountKeeper types.AccountKeeper + BankKeeper types.BankKeeper + StakingKeeper types.StakingKeeper +} + +type ModuleOutputs struct { + depinject.Out + + MintKeeper keeper.Keeper + Module appmodule.AppModule +} + +func ProvideModule(in ModuleInputs) ModuleOutputs { + feeCollectorName := in.Config.GetFeeCollectorName() + if feeCollectorName == "" { + feeCollectorName = authtypes.FeeCollectorName + } + + k := keeper.NewKeeper( + in.Cdc, + in.StoreService, + in.StakingKeeper, + in.AccountKeeper, + in.BankKeeper, + feeCollectorName, + ) + + // when no inflation calculation function is provided it will use the default types.DefaultInflationCalculationFn + m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.InflationCalculationFn) + + return ModuleOutputs{MintKeeper: k, Module: m} +} diff --git a/client/x/mint/module/module.go b/client/x/mint/module/module.go new file mode 100644 index 00000000..9b1cff08 --- /dev/null +++ b/client/x/mint/module/module.go @@ -0,0 +1,136 @@ +//nolint:revive // keep method receiver untouched +package module + +import ( + "context" + "encoding/json" + "fmt" + + "cosmossdk.io/core/appmodule" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" + + "github.com/piplabs/story/client/x/mint/keeper" + "github.com/piplabs/story/client/x/mint/types" + "github.com/piplabs/story/lib/errors" +) + +// ConsensusVersion defines the current x/mint module consensus version. +const ConsensusVersion = 1 + +var ( + _ module.AppModuleBasic = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} +) + +// AppModuleBasic defines the basic application module used by the mint module. +type AppModuleBasic struct { + cdc codec.Codec +} + +// Name returns the mint module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the mint module's types on the given LegacyAmino codec. +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types. +func (b AppModuleBasic) RegisterInterfaces(r cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(r) +} + +// DefaultGenesis returns default genesis state as raw bytes for the mint +// module. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesisState()) +} + +// ValidateGenesis performs genesis state validation for the mint module. +// + +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var data types.GenesisState + if err := cdc.UnmarshalJSON(bz, &data); err != nil { + return errors.Wrap(err, fmt.Sprintf("failed to unmarshal %s genesis state", types.ModuleName)) + } + + return types.ValidateGenesis(data) +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the mint module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {} + +// AppModule implements an application module for the mint module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper + authKeeper types.AccountKeeper + + // inflationCalculator is used to calculate the inflation amount during BeginBlock. + // If inflationCalculator is nil, the default inflation calculation logic is used. + inflationCalculator types.InflationCalculationFn +} + +// NewAppModule creates a new AppModule object. If the InflationCalculationFn +// argument is nil, then the SDK's default inflation function will be used. +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, + ak types.AccountKeeper, + ic types.InflationCalculationFn, +) AppModule { + if ic == nil { + ic = types.DefaultInflationCalculationFn + } + + return AppModule{ + AppModuleBasic: AppModuleBasic{cdc: cdc}, + keeper: keeper, + authKeeper: ak, + inflationCalculator: ic, + } +} + +// RegisterServices registers a gRPC query service to respond to the +// module-specific gRPC queries. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper)) +} + +// InitGenesis performs genesis initialization for the mint module. It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { + var genesisState types.GenesisState + cdc.MustUnmarshalJSON(data, &genesisState) + + am.keeper.InitGenesis(ctx, am.authKeeper, &genesisState) +} + +// ExportGenesis returns the exported genesis state as raw bytes for the mint +// module. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + gs := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(gs) +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } + +// BeginBlock returns the begin blocker for the mint module. +func (am AppModule) BeginBlock(ctx context.Context) error { + return am.keeper.BeginBlocker(ctx, am.inflationCalculator) +} diff --git a/client/x/mint/module/module.proto b/client/x/mint/module/module.proto new file mode 100644 index 00000000..de949a56 --- /dev/null +++ b/client/x/mint/module/module.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +package client.x.mint.module; + +import "cosmos/app/v1alpha1/module.proto"; + +option go_package = "client/x/mint/module"; + +// Module is the config object of the mint module. +message Module { + option (cosmos.app.v1alpha1.module) = { + go_import: "github.com/piplabs/story/client/x/mint" + }; + + string fee_collector_name = 1; +} \ No newline at end of file diff --git a/client/x/mint/module/module.pulsar.go b/client/x/mint/module/module.pulsar.go new file mode 100644 index 00000000..a8015ade --- /dev/null +++ b/client/x/mint/module/module.pulsar.go @@ -0,0 +1,576 @@ +// Code generated by protoc-gen-go-pulsar. DO NOT EDIT. +package module + +import ( + _ "cosmossdk.io/api/cosmos/app/v1alpha1" + fmt "fmt" + runtime "github.com/cosmos/cosmos-proto/runtime" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoiface "google.golang.org/protobuf/runtime/protoiface" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + reflect "reflect" + sync "sync" +) + +var ( + md_Module protoreflect.MessageDescriptor + fd_Module_fee_collector_name protoreflect.FieldDescriptor +) + +func init() { + file_client_x_mint_module_module_proto_init() + md_Module = File_client_x_mint_module_module_proto.Messages().ByName("Module") + fd_Module_fee_collector_name = md_Module.Fields().ByName("fee_collector_name") +} + +var _ protoreflect.Message = (*fastReflection_Module)(nil) + +type fastReflection_Module Module + +func (x *Module) ProtoReflect() protoreflect.Message { + return (*fastReflection_Module)(x) +} + +func (x *Module) slowProtoReflect() protoreflect.Message { + mi := &file_client_x_mint_module_module_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_Module_messageType fastReflection_Module_messageType +var _ protoreflect.MessageType = fastReflection_Module_messageType{} + +type fastReflection_Module_messageType struct{} + +func (x fastReflection_Module_messageType) Zero() protoreflect.Message { + return (*fastReflection_Module)(nil) +} +func (x fastReflection_Module_messageType) New() protoreflect.Message { + return new(fastReflection_Module) +} +func (x fastReflection_Module_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_Module +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_Module) Descriptor() protoreflect.MessageDescriptor { + return md_Module +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_Module) Type() protoreflect.MessageType { + return _fastReflection_Module_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_Module) New() protoreflect.Message { + return new(fastReflection_Module) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_Module) Interface() protoreflect.ProtoMessage { + return (*Module)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_Module) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.FeeCollectorName != "" { + value := protoreflect.ValueOfString(x.FeeCollectorName) + if !f(fd_Module_fee_collector_name, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_Module) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "client.x.mint.module.Module.fee_collector_name": + return x.FeeCollectorName != "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: client.x.mint.module.Module")) + } + panic(fmt.Errorf("message client.x.mint.module.Module does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Module) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "client.x.mint.module.Module.fee_collector_name": + x.FeeCollectorName = "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: client.x.mint.module.Module")) + } + panic(fmt.Errorf("message client.x.mint.module.Module does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_Module) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "client.x.mint.module.Module.fee_collector_name": + value := x.FeeCollectorName + return protoreflect.ValueOfString(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: client.x.mint.module.Module")) + } + panic(fmt.Errorf("message client.x.mint.module.Module does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Module) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "client.x.mint.module.Module.fee_collector_name": + x.FeeCollectorName = value.Interface().(string) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: client.x.mint.module.Module")) + } + panic(fmt.Errorf("message client.x.mint.module.Module does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Module) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "client.x.mint.module.Module.fee_collector_name": + panic(fmt.Errorf("field fee_collector_name of message client.x.mint.module.Module is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: client.x.mint.module.Module")) + } + panic(fmt.Errorf("message client.x.mint.module.Module does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_Module) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "client.x.mint.module.Module.fee_collector_name": + return protoreflect.ValueOfString("") + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: client.x.mint.module.Module")) + } + panic(fmt.Errorf("message client.x.mint.module.Module does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_Module) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in client.x.mint.module.Module", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_Module) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Module) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_Module) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*Module) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + l = len(x.FeeCollectorName) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*Module) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if len(x.FeeCollectorName) > 0 { + i -= len(x.FeeCollectorName) + copy(dAtA[i:], x.FeeCollectorName) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.FeeCollectorName))) + i-- + dAtA[i] = 0xa + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*Module) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: Module: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: Module: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field FeeCollectorName", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.FeeCollectorName = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.0 +// protoc (unknown) +// source: client/x/mint/module/module.proto + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// Module is the config object of the mint module. +type Module struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FeeCollectorName string `protobuf:"bytes,1,opt,name=fee_collector_name,json=feeCollectorName,proto3" json:"fee_collector_name,omitempty"` +} + +func (x *Module) Reset() { + *x = Module{} + if protoimpl.UnsafeEnabled { + mi := &file_client_x_mint_module_module_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Module) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Module) ProtoMessage() {} + +// Deprecated: Use Module.ProtoReflect.Descriptor instead. +func (*Module) Descriptor() ([]byte, []int) { + return file_client_x_mint_module_module_proto_rawDescGZIP(), []int{0} +} + +func (x *Module) GetFeeCollectorName() string { + if x != nil { + return x.FeeCollectorName + } + return "" +} + +var File_client_x_mint_module_module_proto protoreflect.FileDescriptor + +var file_client_x_mint_module_module_proto_rawDesc = []byte{ + 0x0a, 0x21, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2f, 0x78, 0x2f, 0x6d, 0x69, 0x6e, 0x74, 0x2f, + 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x14, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e, 0x78, 0x2e, 0x6d, 0x69, + 0x6e, 0x74, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x1a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x6d, + 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x66, 0x0a, 0x06, 0x4d, + 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x12, 0x2c, 0x0a, 0x12, 0x66, 0x65, 0x65, 0x5f, 0x63, 0x6f, 0x6c, + 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x10, 0x66, 0x65, 0x65, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x4e, + 0x61, 0x6d, 0x65, 0x3a, 0x2e, 0xba, 0xc0, 0x96, 0xda, 0x01, 0x28, 0x0a, 0x26, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x69, 0x70, 0x6c, 0x61, 0x62, 0x73, 0x2f, + 0x73, 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2f, 0x78, 0x2f, 0x6d, + 0x69, 0x6e, 0x74, 0x42, 0xc2, 0x01, 0x0a, 0x18, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6c, 0x69, 0x65, + 0x6e, 0x74, 0x2e, 0x78, 0x2e, 0x6d, 0x69, 0x6e, 0x74, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, + 0x42, 0x0b, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, + 0x25, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2f, 0x78, 0x2f, 0x6d, 0x69, 0x6e, 0x74, 0x2f, + 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0xa2, 0x02, 0x04, 0x43, 0x58, 0x4d, 0x4d, 0xaa, 0x02, 0x14, + 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e, 0x58, 0x2e, 0x4d, 0x69, 0x6e, 0x74, 0x2e, 0x4d, 0x6f, + 0x64, 0x75, 0x6c, 0x65, 0xca, 0x02, 0x14, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5c, 0x58, 0x5c, + 0x4d, 0x69, 0x6e, 0x74, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0xe2, 0x02, 0x20, 0x43, 0x6c, + 0x69, 0x65, 0x6e, 0x74, 0x5c, 0x58, 0x5c, 0x4d, 0x69, 0x6e, 0x74, 0x5c, 0x4d, 0x6f, 0x64, 0x75, + 0x6c, 0x65, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, + 0x17, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x3a, 0x3a, 0x58, 0x3a, 0x3a, 0x4d, 0x69, 0x6e, 0x74, + 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_client_x_mint_module_module_proto_rawDescOnce sync.Once + file_client_x_mint_module_module_proto_rawDescData = file_client_x_mint_module_module_proto_rawDesc +) + +func file_client_x_mint_module_module_proto_rawDescGZIP() []byte { + file_client_x_mint_module_module_proto_rawDescOnce.Do(func() { + file_client_x_mint_module_module_proto_rawDescData = protoimpl.X.CompressGZIP(file_client_x_mint_module_module_proto_rawDescData) + }) + return file_client_x_mint_module_module_proto_rawDescData +} + +var file_client_x_mint_module_module_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_client_x_mint_module_module_proto_goTypes = []interface{}{ + (*Module)(nil), // 0: client.x.mint.module.Module +} +var file_client_x_mint_module_module_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_client_x_mint_module_module_proto_init() } +func file_client_x_mint_module_module_proto_init() { + if File_client_x_mint_module_module_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_client_x_mint_module_module_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Module); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_client_x_mint_module_module_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_client_x_mint_module_module_proto_goTypes, + DependencyIndexes: file_client_x_mint_module_module_proto_depIdxs, + MessageInfos: file_client_x_mint_module_module_proto_msgTypes, + }.Build() + File_client_x_mint_module_module_proto = out.File + file_client_x_mint_module_module_proto_rawDesc = nil + file_client_x_mint_module_module_proto_goTypes = nil + file_client_x_mint_module_module_proto_depIdxs = nil +} diff --git a/client/x/mint/testutil/expected_keepers_mocks.go b/client/x/mint/testutil/expected_keepers_mocks.go new file mode 100644 index 00000000..26be50dd --- /dev/null +++ b/client/x/mint/testutil/expected_keepers_mocks.go @@ -0,0 +1,195 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: x/mint/types/expected_keepers.go + +// Package testutil is a generated GoMock package. +package testutil + +import ( + context "context" + reflect "reflect" + + math "cosmossdk.io/math" + types "github.com/cosmos/cosmos-sdk/types" + gomock "github.com/golang/mock/gomock" +) + +// MockStakingKeeper is a mock of StakingKeeper interface. +type MockStakingKeeper struct { + ctrl *gomock.Controller + recorder *MockStakingKeeperMockRecorder +} + +// MockStakingKeeperMockRecorder is the mock recorder for MockStakingKeeper. +type MockStakingKeeperMockRecorder struct { + mock *MockStakingKeeper +} + +// NewMockStakingKeeper creates a new mock instance. +func NewMockStakingKeeper(ctrl *gomock.Controller) *MockStakingKeeper { + mock := &MockStakingKeeper{ctrl: ctrl} + mock.recorder = &MockStakingKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockStakingKeeper) EXPECT() *MockStakingKeeperMockRecorder { + return m.recorder +} + +// BondedRatio mocks base method. +func (m *MockStakingKeeper) BondedRatio(ctx context.Context) (math.LegacyDec, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BondedRatio", ctx) + ret0, _ := ret[0].(math.LegacyDec) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BondedRatio indicates an expected call of BondedRatio. +func (mr *MockStakingKeeperMockRecorder) BondedRatio(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BondedRatio", reflect.TypeOf((*MockStakingKeeper)(nil).BondedRatio), ctx) +} + +// StakingTokenSupply mocks base method. +func (m *MockStakingKeeper) StakingTokenSupply(ctx context.Context) (math.Int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StakingTokenSupply", ctx) + ret0, _ := ret[0].(math.Int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StakingTokenSupply indicates an expected call of StakingTokenSupply. +func (mr *MockStakingKeeperMockRecorder) StakingTokenSupply(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StakingTokenSupply", reflect.TypeOf((*MockStakingKeeper)(nil).StakingTokenSupply), ctx) +} + +// MockAccountKeeper is a mock of AccountKeeper interface. +type MockAccountKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountKeeperMockRecorder +} + +// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. +type MockAccountKeeperMockRecorder struct { + mock *MockAccountKeeper +} + +// NewMockAccountKeeper creates a new mock instance. +func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper { + mock := &MockAccountKeeper{ctrl: ctrl} + mock.recorder = &MockAccountKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { + return m.recorder +} + +// GetModuleAccount mocks base method. +func (m *MockAccountKeeper) GetModuleAccount(ctx context.Context, moduleName string) types.ModuleAccountI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetModuleAccount", ctx, moduleName) + ret0, _ := ret[0].(types.ModuleAccountI) + return ret0 +} + +// GetModuleAccount indicates an expected call of GetModuleAccount. +func (mr *MockAccountKeeperMockRecorder) GetModuleAccount(ctx, moduleName interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAccount), ctx, moduleName) +} + +// GetModuleAddress mocks base method. +func (m *MockAccountKeeper) GetModuleAddress(name string) types.AccAddress { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetModuleAddress", name) + ret0, _ := ret[0].(types.AccAddress) + return ret0 +} + +// GetModuleAddress indicates an expected call of GetModuleAddress. +func (mr *MockAccountKeeperMockRecorder) GetModuleAddress(name interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAddress", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAddress), name) +} + +// SetModuleAccount mocks base method. +func (m *MockAccountKeeper) SetModuleAccount(arg0 context.Context, arg1 types.ModuleAccountI) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetModuleAccount", arg0, arg1) +} + +// SetModuleAccount indicates an expected call of SetModuleAccount. +func (mr *MockAccountKeeperMockRecorder) SetModuleAccount(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetModuleAccount", reflect.TypeOf((*MockAccountKeeper)(nil).SetModuleAccount), arg0, arg1) +} + +// MockBankKeeper is a mock of BankKeeper interface. +type MockBankKeeper struct { + ctrl *gomock.Controller + recorder *MockBankKeeperMockRecorder +} + +// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. +type MockBankKeeperMockRecorder struct { + mock *MockBankKeeper +} + +// NewMockBankKeeper creates a new mock instance. +func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper { + mock := &MockBankKeeper{ctrl: ctrl} + mock.recorder = &MockBankKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { + return m.recorder +} + +// MintCoins mocks base method. +func (m *MockBankKeeper) MintCoins(ctx context.Context, name string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MintCoins", ctx, name, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// MintCoins indicates an expected call of MintCoins. +func (mr *MockBankKeeperMockRecorder) MintCoins(ctx, name, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MintCoins", reflect.TypeOf((*MockBankKeeper)(nil).MintCoins), ctx, name, amt) +} + +// SendCoinsFromModuleToAccount mocks base method. +func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromModuleToAccount indicates an expected call of SendCoinsFromModuleToAccount. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromModuleToAccount", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromModuleToAccount), ctx, senderModule, recipientAddr, amt) +} + +// SendCoinsFromModuleToModule mocks base method. +func (m *MockBankKeeper) SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromModuleToModule", ctx, senderModule, recipientModule, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromModuleToModule indicates an expected call of SendCoinsFromModuleToModule. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToModule(ctx, senderModule, recipientModule, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromModuleToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromModuleToModule), ctx, senderModule, recipientModule, amt) +} diff --git a/client/x/mint/types/codec.go b/client/x/mint/types/codec.go new file mode 100644 index 00000000..a3fdb433 --- /dev/null +++ b/client/x/mint/types/codec.go @@ -0,0 +1,19 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// RegisterLegacyAminoCodec registers concrete types on the LegacyAmino codec. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(Params{}, "client/x/mint/Params", nil) +} + +// RegisterInterfaces registers the interfaces types with the interface registry. +func RegisterInterfaces(registry types.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + ) +} diff --git a/client/x/mint/types/events.go b/client/x/mint/types/events.go new file mode 100644 index 00000000..053d12a3 --- /dev/null +++ b/client/x/mint/types/events.go @@ -0,0 +1,6 @@ +package types + +// Minting module event types. +const ( + EventTypeMint = ModuleName +) diff --git a/client/x/mint/types/expected_keepers.go b/client/x/mint/types/expected_keepers.go new file mode 100644 index 00000000..dcdfda77 --- /dev/null +++ b/client/x/mint/types/expected_keepers.go @@ -0,0 +1,32 @@ +package types // noalias + +import ( + "context" + + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// StakingKeeper defines the expected staking keeper. +type StakingKeeper interface { + StakingTokenSupply(ctx context.Context) (math.Int, error) + BondedRatio(ctx context.Context) (math.LegacyDec, error) +} + +// AccountKeeper defines the contract required for account APIs. +type AccountKeeper interface { + GetModuleAddress(name string) sdk.AccAddress + + // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862 + SetModuleAccount(ctx context.Context, moduleAccount sdk.ModuleAccountI) + GetModuleAccount(ctx context.Context, moduleName string) sdk.ModuleAccountI +} + +// BankKeeper defines the contract needed to be fulfilled for banking and supply +// dependencies. +type BankKeeper interface { + SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt sdk.Coins) error + MintCoins(ctx context.Context, name string, amt sdk.Coins) error +} diff --git a/client/x/mint/types/genesis.go b/client/x/mint/types/genesis.go new file mode 100644 index 00000000..ff80226e --- /dev/null +++ b/client/x/mint/types/genesis.go @@ -0,0 +1,39 @@ +package types + +import ( + "context" + + "cosmossdk.io/math" +) + +// InflationCalculationFn defines the function required to calculate inflation amount during +// BeginBlock. It receives the params stored in the keeper, along with the current +// bondedRatio and returns the newly calculated inflation amount. +// It can be used to specify a custom inflation calculation logic, instead of relying on the +// default logic provided by the sdk. +type InflationCalculationFn func(ctx context.Context, params Params, bondedRatio math.LegacyDec) math.LegacyDec + +// DefaultInflationCalculationFn is the default function used to calculate inflation. +func DefaultInflationCalculationFn(_ context.Context, params Params, _ math.LegacyDec) math.LegacyDec { + return math.LegacyNewDec(int64(params.InflationsPerYear)).Quo(math.LegacyNewDec(int64(params.BlocksPerYear))) +} + +// NewGenesisState creates a new GenesisState object. +func NewGenesisState(params Params) *GenesisState { + return &GenesisState{ + Params: params, + } +} + +// DefaultGenesisState creates a default GenesisState object. +func DefaultGenesisState() *GenesisState { + return &GenesisState{ + Params: DefaultParams(), + } +} + +// ValidateGenesis validates the provided genesis state to ensure the +// expected invariants holds. +func ValidateGenesis(data GenesisState) error { + return data.Params.Validate() +} diff --git a/client/x/mint/types/genesis.pb.go b/client/x/mint/types/genesis.pb.go new file mode 100644 index 00000000..9f7e83c8 --- /dev/null +++ b/client/x/mint/types/genesis.pb.go @@ -0,0 +1,322 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: client/x/mint/types/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the mint module's genesis state. +type GenesisState struct { + // params defines all the parameters of the module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_f5cd7edb2fa50db9, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "client.x.mint.types.GenesisState") +} + +func init() { proto.RegisterFile("client/x/mint/types/genesis.proto", fileDescriptor_f5cd7edb2fa50db9) } + +var fileDescriptor_f5cd7edb2fa50db9 = []byte{ + // 192 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4c, 0xce, 0xc9, 0x4c, + 0xcd, 0x2b, 0xd1, 0xaf, 0xd0, 0xcf, 0xcd, 0xcc, 0x2b, 0xd1, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, + 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, + 0x28, 0xd1, 0xab, 0xd0, 0x03, 0x29, 0xd1, 0x03, 0x2b, 0x91, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, + 0xcb, 0xeb, 0x83, 0x58, 0x10, 0xa5, 0x52, 0x72, 0xd8, 0x4c, 0x03, 0xeb, 0x82, 0xc8, 0x0b, 0x26, + 0xe6, 0x66, 0xe6, 0xe5, 0xeb, 0x83, 0x49, 0x88, 0x90, 0x92, 0x1f, 0x17, 0x8f, 0x3b, 0xc4, 0xba, + 0xe0, 0x92, 0xc4, 0x92, 0x54, 0x21, 0x3b, 0x2e, 0xb6, 0x82, 0xc4, 0xa2, 0xc4, 0xdc, 0x62, 0x09, + 0x46, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x69, 0x3d, 0x2c, 0xd6, 0xeb, 0x05, 0x80, 0x95, 0x38, 0x71, + 0x9e, 0xb8, 0x27, 0xcf, 0xb0, 0xe2, 0xf9, 0x06, 0x2d, 0xc6, 0x20, 0xa8, 0x2e, 0x27, 0xdd, 0x13, + 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, + 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x12, 0xc6, 0xe2, 0xb8, 0x24, 0x36, 0xb0, + 0x2b, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xfb, 0xaf, 0x59, 0x3b, 0x08, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/client/x/mint/types/genesis.proto b/client/x/mint/types/genesis.proto new file mode 100644 index 00000000..e9d0af6e --- /dev/null +++ b/client/x/mint/types/genesis.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package client.x.mint.types; + +import "gogoproto/gogo.proto"; +import "client/x/mint/types/mint.proto"; +import "amino/amino.proto"; + +option go_package = "client/x/mint/types"; + +// GenesisState defines the mint module's genesis state. +message GenesisState { + // params defines all the parameters of the module. + Params params = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; +} diff --git a/client/x/mint/types/inflation_contract.go b/client/x/mint/types/inflation_contract.go new file mode 100644 index 00000000..113232c3 --- /dev/null +++ b/client/x/mint/types/inflation_contract.go @@ -0,0 +1,36 @@ +package types + +import ( + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + + "github.com/piplabs/story/contracts/bindings" +) + +// (rayden) TODO. +var ( + inflationUpdateABI = mustGetABI(bindings.IPTokenStakingMetaData) + SetInflationParameters = mustGetEvent(inflationUpdateABI, "Deposit") +) + +// mustGetABI returns the metadata's ABI as an abi.ABI type. +// It panics on error. +func mustGetABI(metadata *bind.MetaData) *abi.ABI { + abi, err := metadata.GetAbi() + if err != nil { + panic(err) + } + + return abi +} + +// mustGetEvent returns the event with the given name from the ABI. +// It panics if the event is not found. +func mustGetEvent(abi *abi.ABI, name string) abi.Event { + event, ok := abi.Events[name] + if !ok { + panic("event not found") + } + + return event +} diff --git a/client/x/mint/types/keys.go b/client/x/mint/types/keys.go new file mode 100644 index 00000000..cfa4cfd5 --- /dev/null +++ b/client/x/mint/types/keys.go @@ -0,0 +1,17 @@ +package types + +import "cosmossdk.io/collections" + +var ( + // MinterKey is the key to use for the keeper store. + MinterKey = collections.NewPrefix(0) + ParamsKey = collections.NewPrefix(1) +) + +const ( + // module name. + ModuleName = "mint" + + // StoreKey is the default store key for mint. + StoreKey = ModuleName +) diff --git a/client/x/mint/types/mint.pb.go b/client/x/mint/types/mint.pb.go new file mode 100644 index 00000000..59f0e424 --- /dev/null +++ b/client/x/mint/types/mint.pb.go @@ -0,0 +1,393 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: client/x/mint/types/mint.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Params defines the parameters for the x/mint module. +type Params struct { + // type of coin to mint + MintDenom string `protobuf:"bytes,1,opt,name=mint_denom,json=mintDenom,proto3" json:"mint_denom,omitempty"` + // inflation amount per year + InflationsPerYear uint64 `protobuf:"varint,2,opt,name=inflations_per_year,json=inflationsPerYear,proto3" json:"inflations_per_year,omitempty"` + // expected blocks per year + BlocksPerYear uint64 `protobuf:"varint,3,opt,name=blocks_per_year,json=blocksPerYear,proto3" json:"blocks_per_year,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_9c6e60aec58f52af, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetMintDenom() string { + if m != nil { + return m.MintDenom + } + return "" +} + +func (m *Params) GetInflationsPerYear() uint64 { + if m != nil { + return m.InflationsPerYear + } + return 0 +} + +func (m *Params) GetBlocksPerYear() uint64 { + if m != nil { + return m.BlocksPerYear + } + return 0 +} + +func init() { + proto.RegisterType((*Params)(nil), "client.x.mint.types.Params") +} + +func init() { proto.RegisterFile("client/x/mint/types/mint.proto", fileDescriptor_9c6e60aec58f52af) } + +var fileDescriptor_9c6e60aec58f52af = []byte{ + // 219 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4b, 0xce, 0xc9, 0x4c, + 0xcd, 0x2b, 0xd1, 0xaf, 0xd0, 0xcf, 0xcd, 0xcc, 0x2b, 0xd1, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x06, + 0x33, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x84, 0x21, 0xf2, 0x7a, 0x15, 0x7a, 0x60, 0x41, + 0xb0, 0xbc, 0x94, 0x60, 0x62, 0x6e, 0x66, 0x5e, 0xbe, 0x3e, 0x98, 0x84, 0xa8, 0x53, 0x9a, 0xc5, + 0xc8, 0xc5, 0x16, 0x90, 0x58, 0x94, 0x98, 0x5b, 0x2c, 0x24, 0xcb, 0xc5, 0x05, 0x52, 0x1b, 0x9f, + 0x92, 0x9a, 0x97, 0x9f, 0x2b, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x19, 0xc4, 0x09, 0x12, 0x71, 0x01, + 0x09, 0x08, 0xe9, 0x71, 0x09, 0x67, 0xe6, 0xa5, 0xe5, 0x24, 0x96, 0x64, 0xe6, 0xe7, 0x15, 0xc7, + 0x17, 0xa4, 0x16, 0xc5, 0x57, 0xa6, 0x26, 0x16, 0x49, 0x30, 0x29, 0x30, 0x6a, 0xb0, 0x04, 0x09, + 0x22, 0xa4, 0x02, 0x52, 0x8b, 0x22, 0x53, 0x13, 0x8b, 0x84, 0xd4, 0xb8, 0xf8, 0x93, 0x72, 0xf2, + 0x93, 0xb3, 0x91, 0xd4, 0x32, 0x83, 0xd5, 0xf2, 0x42, 0x84, 0xa1, 0xea, 0xac, 0x24, 0xbb, 0x9e, + 0x6f, 0xd0, 0x12, 0x41, 0xf5, 0x0e, 0xc4, 0x45, 0x4e, 0xba, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, + 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, + 0x78, 0x2c, 0xc7, 0x10, 0x25, 0x8c, 0xc5, 0xfb, 0x49, 0x6c, 0x60, 0x2f, 0x19, 0x03, 0x02, 0x00, + 0x00, 0xff, 0xff, 0xd9, 0x4d, 0x19, 0x4f, 0x1c, 0x01, 0x00, 0x00, +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BlocksPerYear != 0 { + i = encodeVarintMint(dAtA, i, uint64(m.BlocksPerYear)) + i-- + dAtA[i] = 0x18 + } + if m.InflationsPerYear != 0 { + i = encodeVarintMint(dAtA, i, uint64(m.InflationsPerYear)) + i-- + dAtA[i] = 0x10 + } + if len(m.MintDenom) > 0 { + i -= len(m.MintDenom) + copy(dAtA[i:], m.MintDenom) + i = encodeVarintMint(dAtA, i, uint64(len(m.MintDenom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintMint(dAtA []byte, offset int, v uint64) int { + offset -= sovMint(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.MintDenom) + if l > 0 { + n += 1 + l + sovMint(uint64(l)) + } + if m.InflationsPerYear != 0 { + n += 1 + sovMint(uint64(m.InflationsPerYear)) + } + if m.BlocksPerYear != 0 { + n += 1 + sovMint(uint64(m.BlocksPerYear)) + } + return n +} + +func sovMint(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozMint(x uint64) (n int) { + return sovMint(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMint + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MintDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMint + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthMint + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthMint + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MintDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field InflationsPerYear", wireType) + } + m.InflationsPerYear = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMint + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.InflationsPerYear |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BlocksPerYear", wireType) + } + m.BlocksPerYear = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMint + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlocksPerYear |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipMint(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthMint + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipMint(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMint + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMint + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMint + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthMint + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupMint + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthMint + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthMint = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowMint = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupMint = fmt.Errorf("proto: unexpected end of group") +) diff --git a/client/x/mint/types/mint.proto b/client/x/mint/types/mint.proto new file mode 100644 index 00000000..509ccd8f --- /dev/null +++ b/client/x/mint/types/mint.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; +package client.x.mint.types; + +option go_package = "client/x/mint/types"; + +import "amino/amino.proto"; + +// Params defines the parameters for the x/mint module. +message Params { + option (amino.name) = "client/x/mint/Params"; + + // type of coin to mint + string mint_denom = 1; + // inflation amount per year + uint64 inflations_per_year = 2; + // expected blocks per year + uint64 blocks_per_year = 3; +} diff --git a/client/x/mint/types/params.go b/client/x/mint/types/params.go new file mode 100644 index 00000000..cc5197a3 --- /dev/null +++ b/client/x/mint/types/params.go @@ -0,0 +1,92 @@ +//nolint:revive // just use interface{} +package types + +import ( + "fmt" + "strings" + + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/piplabs/story/lib/errors" +) + +// NewParams returns Params instance with the given values. +func NewParams(mintDenom string, inflationsPerYear uint64, blocksPerYear uint64) Params { + return Params{ + MintDenom: mintDenom, + InflationsPerYear: inflationsPerYear, + BlocksPerYear: blocksPerYear, + } +} + +// DefaultParams returns default x/mint module parameters. +func DefaultParams() Params { + return Params{ + MintDenom: sdk.DefaultBondDenom, + InflationsPerYear: 24625000_000_000_000, + BlocksPerYear: uint64(60 * 60 * 8766 / 5), // assuming 5 second block times + } +} + +// Validate does the sanity check on the params. +func (p Params) Validate() error { + if err := validateMintDenom(p.MintDenom); err != nil { + return err + } + if err := validateInflationsPerYear(p.InflationsPerYear); err != nil { + return err + } + if err := validateBlocksPerYear(p.BlocksPerYear); err != nil { + return err + } + + return nil +} + +func validateMintDenom(i interface{}) error { + v, ok := i.(string) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if strings.TrimSpace(v) == "" { + return errors.New("mint denom cannot be blank") + } + + if err := sdk.ValidateDenom(v); err != nil { + return errors.Wrap(err, "mint denom is invalid") + } + + return nil +} + +func validateInflationsPerYear(i interface{}) error { + v, ok := i.(math.LegacyDec) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v.IsNil() { + return fmt.Errorf("inflations per year cannot be nil: %s", v) + } + if v.IsNegative() { + return fmt.Errorf("inflations per year cannot be negative: %s", v) + } + + return nil +} + +func validateBlocksPerYear(i interface{}) error { + v, ok := i.(uint64) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v == 0 { + return fmt.Errorf("blocks per year must be positive: %d", v) + } + + return nil +} diff --git a/client/x/mint/types/query.pb.go b/client/x/mint/types/query.pb.go new file mode 100644 index 00000000..89738614 --- /dev/null +++ b/client/x/mint/types/query.pb.go @@ -0,0 +1,536 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: client/x/mint/types/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryParamsRequest is the request type for the Query/Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_a6d4efab0120ffa4, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is the response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params defines the parameters of the module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_a6d4efab0120ffa4, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "client.x.mint.types.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "client.x.mint.types.QueryParamsResponse") +} + +func init() { proto.RegisterFile("client/x/mint/types/query.proto", fileDescriptor_a6d4efab0120ffa4) } + +var fileDescriptor_a6d4efab0120ffa4 = []byte{ + // 279 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4f, 0xce, 0xc9, 0x4c, + 0xcd, 0x2b, 0xd1, 0xaf, 0xd0, 0xcf, 0xcd, 0xcc, 0x2b, 0xd1, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, + 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0x28, 0xd0, + 0xab, 0xd0, 0x03, 0x29, 0xd0, 0x03, 0x2b, 0x90, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xcb, 0xeb, + 0x83, 0x58, 0x10, 0xa5, 0x52, 0x32, 0xe9, 0xf9, 0xf9, 0xe9, 0x39, 0xa9, 0xfa, 0x89, 0x05, 0x99, + 0xfa, 0x89, 0x79, 0x79, 0xf9, 0x25, 0x89, 0x25, 0x99, 0xf9, 0x79, 0xc5, 0x50, 0x59, 0x39, 0x6c, + 0x36, 0x81, 0xcd, 0x84, 0xc8, 0x0b, 0x26, 0xe6, 0x66, 0xe6, 0xe5, 0xeb, 0x83, 0x49, 0x88, 0x90, + 0x92, 0x08, 0x97, 0x50, 0x20, 0xc8, 0x29, 0x01, 0x89, 0x45, 0x89, 0xb9, 0xc5, 0x41, 0xa9, 0x85, + 0xa5, 0xa9, 0xc5, 0x25, 0x4a, 0xa1, 0x5c, 0xc2, 0x28, 0xa2, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, + 0x42, 0x76, 0x5c, 0x6c, 0x05, 0x60, 0x11, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x69, 0x3d, + 0x2c, 0x2e, 0xd7, 0x83, 0x68, 0x72, 0xe2, 0x3c, 0x71, 0x4f, 0x9e, 0x61, 0xc5, 0xf3, 0x0d, 0x5a, + 0x8c, 0x41, 0x50, 0x5d, 0x46, 0x2d, 0x8c, 0x5c, 0xac, 0x60, 0x73, 0x85, 0xaa, 0xb9, 0xd8, 0x20, + 0xca, 0x84, 0xd4, 0xb1, 0x9a, 0x81, 0xe9, 0x26, 0x29, 0x0d, 0xc2, 0x0a, 0x21, 0xce, 0x54, 0x92, + 0x6b, 0xba, 0xfc, 0x64, 0x32, 0x93, 0x84, 0x90, 0x98, 0x3e, 0x34, 0x3c, 0xc0, 0xa1, 0x51, 0x66, + 0xa8, 0x0f, 0x71, 0x86, 0x93, 0xee, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, + 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, + 0x09, 0x63, 0x09, 0xc0, 0x24, 0x36, 0x70, 0x48, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x33, + 0x4d, 0xc0, 0x75, 0xc8, 0x01, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Params returns the total set of minting parameters. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/client.x.mint.types.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Params returns the total set of minting parameters. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/client.x.mint.types.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "client.x.mint.types.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "client/x/mint/types/query.proto", +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/client/x/mint/types/query.proto b/client/x/mint/types/query.proto new file mode 100644 index 00000000..c71b49f3 --- /dev/null +++ b/client/x/mint/types/query.proto @@ -0,0 +1,26 @@ +syntax = "proto3"; +package client.x.mint.types; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "client/x/mint/types/mint.proto"; +import "amino/amino.proto"; + +option go_package = "client/x/mint/types"; + +// Query provides defines the gRPC querier service. +service Query { + // Params returns the total set of minting parameters. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/client/mint/v1/params"; + } +} + +// QueryParamsRequest is the request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is the response type for the Query/Params RPC method. +message QueryParamsResponse { + // params defines the parameters of the module. + Params params = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; +} diff --git a/go.mod b/go.mod index 3c36fe7a..6cc516df 100644 --- a/go.mod +++ b/go.mod @@ -129,7 +129,7 @@ require ( github.com/gogo/googleapis v1.4.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/glog v1.2.0 // indirect - github.com/golang/mock v1.6.0 // indirect + github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect github.com/google/btree v1.1.2 // indirect