From 7eb293f5cf61101ef78c18b954b246eee99a8fde Mon Sep 17 00:00:00 2001 From: Giuseppe Natale <12249307+giunatale@users.noreply.github.com> Date: Fri, 13 May 2022 05:09:20 +0200 Subject: [PATCH 1/5] add `mint` module --- app/app.go | 15 +- proto/mint/genesis.proto | 16 + proto/mint/mint.proto | 72 ++ proto/mint/query.proto | 57 ++ testutil/keeper/initializer.go | 2 +- x/mint/abci.go | 56 ++ x/mint/client/cli/query.go | 120 +++ x/mint/client/rest/grpc_query_test.go | 111 +++ x/mint/client/rest/query.go | 86 ++ x/mint/client/rest/rest.go | 13 + x/mint/genesis.go | 22 + x/mint/keeper/grpc.go | 35 + x/mint/keeper/grpc_test.go | 56 ++ x/mint/keeper/integration_test.go | 71 ++ x/mint/keeper/keeper.go | 151 ++++ x/mint/keeper/querier.go | 63 ++ x/mint/keeper/querier_test.go | 84 ++ x/mint/module.go | 186 ++++ x/mint/module_test.go | 28 + x/mint/simulation/decoder.go | 27 + x/mint/simulation/decoder_test.go | 47 + x/mint/simulation/genesis.go | 117 +++ x/mint/simulation/genesis_test.go | 90 ++ x/mint/simulation/params.go | 47 + x/mint/simulation/params_test.go | 38 + x/mint/types/codec.go | 15 + x/mint/types/events.go | 10 + x/mint/types/expected_keepers.go | 31 + x/mint/types/genesis.go | 27 + x/mint/types/genesis.pb.go | 376 ++++++++ x/mint/types/keys.go | 20 + x/mint/types/mint.pb.go | 1102 +++++++++++++++++++++++ x/mint/types/minter.go | 80 ++ x/mint/types/minter_test.go | 134 +++ x/mint/types/params.go | 234 +++++ x/mint/types/query.pb.go | 1200 +++++++++++++++++++++++++ x/mint/types/query.pb.gw.go | 283 ++++++ 37 files changed, 5114 insertions(+), 8 deletions(-) create mode 100644 proto/mint/genesis.proto create mode 100644 proto/mint/mint.proto create mode 100644 proto/mint/query.proto create mode 100644 x/mint/abci.go create mode 100644 x/mint/client/cli/query.go create mode 100644 x/mint/client/rest/grpc_query_test.go create mode 100644 x/mint/client/rest/query.go create mode 100644 x/mint/client/rest/rest.go create mode 100644 x/mint/genesis.go create mode 100644 x/mint/keeper/grpc.go create mode 100644 x/mint/keeper/grpc_test.go create mode 100644 x/mint/keeper/integration_test.go create mode 100644 x/mint/keeper/keeper.go create mode 100644 x/mint/keeper/querier.go create mode 100644 x/mint/keeper/querier_test.go create mode 100644 x/mint/module.go create mode 100644 x/mint/module_test.go create mode 100644 x/mint/simulation/decoder.go create mode 100644 x/mint/simulation/decoder_test.go create mode 100644 x/mint/simulation/genesis.go create mode 100644 x/mint/simulation/genesis_test.go create mode 100644 x/mint/simulation/params.go create mode 100644 x/mint/simulation/params_test.go create mode 100644 x/mint/types/codec.go create mode 100644 x/mint/types/events.go create mode 100644 x/mint/types/expected_keepers.go create mode 100644 x/mint/types/genesis.go create mode 100644 x/mint/types/genesis.pb.go create mode 100644 x/mint/types/keys.go create mode 100644 x/mint/types/mint.pb.go create mode 100644 x/mint/types/minter.go create mode 100644 x/mint/types/minter_test.go create mode 100644 x/mint/types/params.go create mode 100644 x/mint/types/query.pb.go create mode 100644 x/mint/types/query.pb.gw.go diff --git a/app/app.go b/app/app.go index 7cfde75d7..f73fbd50c 100644 --- a/app/app.go +++ b/app/app.go @@ -56,9 +56,6 @@ import ( govclient "github.com/cosmos/cosmos-sdk/x/gov/client" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/mint" - mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/cosmos/cosmos-sdk/x/params" paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" @@ -125,6 +122,10 @@ import ( participationmodulekeeper "github.com/tendermint/spn/x/participation/keeper" participationmoduletypes "github.com/tendermint/spn/x/participation/types" + "github.com/tendermint/spn/x/mint" + mintkeeper "github.com/tendermint/spn/x/mint/keeper" + minttypes "github.com/tendermint/spn/x/mint/types" + // this line is used by starport scaffolding # stargate/app/moduleImport "github.com/ignite-hq/cli/ignite/pkg/cosmoscmd" @@ -368,14 +369,14 @@ func New( stakingKeeper := stakingkeeper.NewKeeper( appCodec, keys[stakingtypes.StoreKey], app.AuthKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), ) - app.MintKeeper = mintkeeper.NewKeeper( - appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper, - app.AuthKeeper, app.BankKeeper, authtypes.FeeCollectorName, - ) app.DistrKeeper = distrkeeper.NewKeeper( appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AuthKeeper, app.BankKeeper, &stakingKeeper, authtypes.FeeCollectorName, app.ModuleAccountAddrs(), ) + app.MintKeeper = mintkeeper.NewKeeper( + appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper, + app.AuthKeeper, app.BankKeeper, app.DistrKeeper, authtypes.FeeCollectorName, + ) app.SlashingKeeper = slashingkeeper.NewKeeper( appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName), ) diff --git a/proto/mint/genesis.proto b/proto/mint/genesis.proto new file mode 100644 index 000000000..8e66c0c98 --- /dev/null +++ b/proto/mint/genesis.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; +package tendermint.spn.mint; + +import "gogoproto/gogo.proto"; +import "mint/mint.proto"; + +option go_package = "github.com/tendermint/spn/x/mint/types"; + +// GenesisState defines the mint module's genesis state. +message GenesisState { + // minter is a space for holding current inflation information. + Minter minter = 1 [(gogoproto.nullable) = false]; + + // params defines all the paramaters of the module. + Params params = 2 [(gogoproto.nullable) = false]; +} diff --git a/proto/mint/mint.proto b/proto/mint/mint.proto new file mode 100644 index 000000000..ad81c0cd4 --- /dev/null +++ b/proto/mint/mint.proto @@ -0,0 +1,72 @@ +syntax = "proto3"; +package tendermint.spn.mint; + +option go_package = "github.com/tendermint/spn/x/mint/types"; + +import "gogoproto/gogo.proto"; + +// Minter represents the minting state. +message Minter { + // current annual inflation rate + string inflation = 1 + [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + // current annual expected provisions + string annual_provisions = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; +} + +message DistributionProportions { + // staking defines the proportion of the minted minted_denom that is to be + // allocated as staking rewards. + string staking = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // incentives defines the proportion of the minted minted_denom that is + // to be allocated as incentives. + string incentives = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // community_pool defines the proportion of the minted minted_denom that is + // to be allocated to the community pool. + string community_pool = 3 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; +} + +// Params holds parameters for the mint module. +message Params { + option (gogoproto.goproto_stringer) = false; + + // type of coin to mint + string mint_denom = 1; + // maximum annual change in inflation rate + string inflation_rate_change = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // maximum inflation rate + string inflation_max = 3 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // minimum inflation rate + string inflation_min = 4 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // goal of percent bonded atoms + string goal_bonded = 5 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // expected blocks per year + uint64 blocks_per_year = 6; + // distribution_proportions defines the proportion of the minted denom + DistributionProportions distribution_proportions = 7 + [ (gogoproto.nullable) = false ]; +} diff --git a/proto/mint/query.proto b/proto/mint/query.proto new file mode 100644 index 000000000..09f44ed2c --- /dev/null +++ b/proto/mint/query.proto @@ -0,0 +1,57 @@ +syntax = "proto3"; +package tendermint.spn.mint; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "mint/mint.proto"; + +option go_package = "github.com/tendermint/spn/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 = "/cosmos/mint/v1beta1/params"; + } + + // Inflation returns the current minting inflation value. + rpc Inflation(QueryInflationRequest) returns (QueryInflationResponse) { + option (google.api.http).get = "/cosmos/mint/v1beta1/inflation"; + } + + // AnnualProvisions current minting annual provisions value. + rpc AnnualProvisions(QueryAnnualProvisionsRequest) returns (QueryAnnualProvisionsResponse) { + option (google.api.http).get = "/cosmos/mint/v1beta1/annual_provisions"; + } +} + +// 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]; +} + +// QueryInflationRequest is the request type for the Query/Inflation RPC method. +message QueryInflationRequest {} + +// QueryInflationResponse is the response type for the Query/Inflation RPC +// method. +message QueryInflationResponse { + // inflation is the current minting inflation value. + bytes inflation = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; +} + +// QueryAnnualProvisionsRequest is the request type for the +// Query/AnnualProvisions RPC method. +message QueryAnnualProvisionsRequest {} + +// QueryAnnualProvisionsResponse is the response type for the +// Query/AnnualProvisions RPC method. +message QueryAnnualProvisionsResponse { + // annual_provisions is the current minting annual provisions value. + bytes annual_provisions = 1 + [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; +} diff --git a/testutil/keeper/initializer.go b/testutil/keeper/initializer.go index 51555aa66..e50ec9ab8 100644 --- a/testutil/keeper/initializer.go +++ b/testutil/keeper/initializer.go @@ -13,7 +13,6 @@ import ( capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" @@ -30,6 +29,7 @@ import ( campaigntypes "github.com/tendermint/spn/x/campaign/types" launchkeeper "github.com/tendermint/spn/x/launch/keeper" launchtypes "github.com/tendermint/spn/x/launch/types" + minttypes "github.com/tendermint/spn/x/mint/types" monitoringcmodulekeeper "github.com/tendermint/spn/x/monitoringc/keeper" monitoringcmoduletypes "github.com/tendermint/spn/x/monitoringc/types" monitoringpmodulekeeper "github.com/tendermint/spn/x/monitoringp/keeper" diff --git a/x/mint/abci.go b/x/mint/abci.go new file mode 100644 index 000000000..2f07e1355 --- /dev/null +++ b/x/mint/abci.go @@ -0,0 +1,56 @@ +package mint + +import ( + "time" + + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/tendermint/spn/x/mint/keeper" + "github.com/tendermint/spn/x/mint/types" +) + +// BeginBlocker mints new tokens for the previous block. +func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + + // fetch stored minter & params + minter := k.GetMinter(ctx) + params := k.GetParams(ctx) + + // recalculate inflation rate + totalStakingSupply := k.StakingTokenSupply(ctx) + bondedRatio := k.BondedRatio(ctx) + minter.Inflation = minter.NextInflationRate(params, bondedRatio) + minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalStakingSupply) + k.SetMinter(ctx, minter) + + // mint coins, update supply + mintedCoin := minter.BlockProvision(params) + mintedCoins := sdk.NewCoins(mintedCoin) + + err := k.MintCoins(ctx, mintedCoins) + if err != nil { + panic(err) + } + + // distribute minted coins according to the defined proportions + err = k.DistributeMintedCoins(ctx, mintedCoin) + if err != nil { + panic(err) + } + + if mintedCoin.Amount.IsInt64() { + defer telemetry.ModuleSetGauge(types.ModuleName, float32(mintedCoin.Amount.Int64()), "minted_tokens") + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeMint, + sdk.NewAttribute(types.AttributeKeyBondedRatio, bondedRatio.String()), + sdk.NewAttribute(types.AttributeKeyInflation, minter.Inflation.String()), + sdk.NewAttribute(types.AttributeKeyAnnualProvisions, minter.AnnualProvisions.String()), + sdk.NewAttribute(sdk.AttributeKeyAmount, mintedCoin.Amount.String()), + ), + ) +} diff --git a/x/mint/client/cli/query.go b/x/mint/client/cli/query.go new file mode 100644 index 000000000..dfc89b77d --- /dev/null +++ b/x/mint/client/cli/query.go @@ -0,0 +1,120 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/tendermint/spn/x/mint/types" +) + +// GetQueryCmd returns the cli query commands for the minting module. +func GetQueryCmd() *cobra.Command { + mintingQueryCmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Querying commands for the minting module", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + mintingQueryCmd.AddCommand( + GetCmdQueryParams(), + GetCmdQueryInflation(), + GetCmdQueryAnnualProvisions(), + ) + + return mintingQueryCmd +} + +// GetCmdQueryParams implements a command to return the current minting +// parameters. +func GetCmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "Query the current minting parameters", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryParamsRequest{} + res, err := queryClient.Params(cmd.Context(), params) + + if err != nil { + return err + } + + return clientCtx.PrintProto(&res.Params) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// GetCmdQueryInflation implements a command to return the current minting +// inflation value. +func GetCmdQueryInflation() *cobra.Command { + cmd := &cobra.Command{ + Use: "inflation", + Short: "Query the current minting inflation value", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryInflationRequest{} + res, err := queryClient.Inflation(cmd.Context(), params) + + if err != nil { + return err + } + + return clientCtx.PrintString(fmt.Sprintf("%s\n", res.Inflation)) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// GetCmdQueryAnnualProvisions implements a command to return the current minting +// annual provisions value. +func GetCmdQueryAnnualProvisions() *cobra.Command { + cmd := &cobra.Command{ + Use: "annual-provisions", + Short: "Query the current minting annual provisions value", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryAnnualProvisionsRequest{} + res, err := queryClient.AnnualProvisions(cmd.Context(), params) + + if err != nil { + return err + } + + return clientCtx.PrintString(fmt.Sprintf("%s\n", res.AnnualProvisions)) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/mint/client/rest/grpc_query_test.go b/x/mint/client/rest/grpc_query_test.go new file mode 100644 index 000000000..a995ff230 --- /dev/null +++ b/x/mint/client/rest/grpc_query_test.go @@ -0,0 +1,111 @@ +package rest_test + +import ( + "fmt" + "testing" + + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" + "github.com/gogo/protobuf/proto" + "github.com/stretchr/testify/suite" + + "github.com/tendermint/spn/testutil/network" + minttypes "github.com/tendermint/spn/x/mint/types" +) + +type IntegrationTestSuite struct { + suite.Suite + cfg network.Config + network *network.Network +} + +func (s *IntegrationTestSuite) SetupSuite() { + s.T().Log("setting up integration test suite") + + cfg := network.DefaultConfig() + + genesisState := cfg.GenesisState + cfg.NumValidators = 1 + + var mintData minttypes.GenesisState + s.Require().NoError(cfg.Codec.UnmarshalJSON(genesisState[minttypes.ModuleName], &mintData)) + + mintData.Params.InflationMin = sdk.OneDec() + mintData.Params.InflationMax = sdk.OneDec() + mintData.Minter.Inflation = sdk.OneDec() + + mintDataBz, err := cfg.Codec.MarshalJSON(&mintData) + s.Require().NoError(err) + genesisState[minttypes.ModuleName] = mintDataBz + cfg.GenesisState = genesisState + + s.cfg = cfg + s.network = network.New(s.T(), s.cfg) + + _, err = s.network.WaitForHeight(1) + s.Require().NoError(err) +} + +func (s *IntegrationTestSuite) TearDownSuite() { + s.T().Log("tearing down integration test suite") +} + +func (s *IntegrationTestSuite) TestQueryGRPC() { + val := s.network.Validators[0] + baseURL := val.APIAddress + + expectedParams := minttypes.DefaultParams() + expectedParams.InflationMin = sdk.OneDec() + expectedParams.InflationMax = sdk.OneDec() + + testCases := []struct { + name string + url string + headers map[string]string + respType proto.Message + expected proto.Message + }{ + { + "gRPC request params", + fmt.Sprintf("%s/cosmos/mint/v1beta1/params", baseURL), + map[string]string{}, + &minttypes.QueryParamsResponse{}, + &minttypes.QueryParamsResponse{ + Params: expectedParams, + }, + }, + { + "gRPC request inflation", + fmt.Sprintf("%s/cosmos/mint/v1beta1/inflation", baseURL), + map[string]string{}, + &minttypes.QueryInflationResponse{}, + &minttypes.QueryInflationResponse{ + Inflation: sdk.OneDec(), + }, + }, + { + "gRPC request annual provisions", + fmt.Sprintf("%s/cosmos/mint/v1beta1/annual_provisions", baseURL), + map[string]string{ + grpctypes.GRPCBlockHeightHeader: "1", + }, + &minttypes.QueryAnnualProvisionsResponse{}, + &minttypes.QueryAnnualProvisionsResponse{ + AnnualProvisions: sdk.NewDec(500000000), + }, + }, + } + for _, tc := range testCases { + resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) + s.Run(tc.name, func() { + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType)) + s.Require().Equal(tc.expected.String(), tc.respType.String()) + }) + } +} + +func TestIntegrationTestSuite(t *testing.T) { + suite.Run(t, new(IntegrationTestSuite)) +} diff --git a/x/mint/client/rest/query.go b/x/mint/client/rest/query.go new file mode 100644 index 000000000..b10382eb2 --- /dev/null +++ b/x/mint/client/rest/query.go @@ -0,0 +1,86 @@ +package rest + +import ( + "fmt" + "net/http" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/types/rest" + "github.com/gorilla/mux" + + "github.com/tendermint/spn/x/mint/types" +) + +func registerQueryRoutes(clientCtx client.Context, r *mux.Router) { + r.HandleFunc( + "/minting/parameters", + queryParamsHandlerFn(clientCtx), + ).Methods("GET") + + r.HandleFunc( + "/minting/inflation", + queryInflationHandlerFn(clientCtx), + ).Methods("GET") + + r.HandleFunc( + "/minting/annual-provisions", + queryAnnualProvisionsHandlerFn(clientCtx), + ).Methods("GET") +} + +func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParameters) + + clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) + if !ok { + return + } + + res, height, err := clientCtx.QueryWithData(route, nil) + if rest.CheckInternalServerError(w, err) { + return + } + + clientCtx = clientCtx.WithHeight(height) + rest.PostProcessResponse(w, clientCtx, res) + } +} + +func queryInflationHandlerFn(clientCtx client.Context) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryInflation) + + clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) + if !ok { + return + } + + res, height, err := clientCtx.QueryWithData(route, nil) + if rest.CheckInternalServerError(w, err) { + return + } + + clientCtx = clientCtx.WithHeight(height) + rest.PostProcessResponse(w, clientCtx, res) + } +} + +func queryAnnualProvisionsHandlerFn(clientCtx client.Context) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAnnualProvisions) + + clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) + if !ok { + return + } + + res, height, err := clientCtx.QueryWithData(route, nil) + if rest.CheckInternalServerError(w, err) { + return + } + + clientCtx = clientCtx.WithHeight(height) + rest.PostProcessResponse(w, clientCtx, res) + } +} diff --git a/x/mint/client/rest/rest.go b/x/mint/client/rest/rest.go new file mode 100644 index 000000000..b31805e0c --- /dev/null +++ b/x/mint/client/rest/rest.go @@ -0,0 +1,13 @@ +package rest + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/rest" + "github.com/gorilla/mux" +) + +// RegisterRoutes registers minting module REST handlers on the provided router. +func RegisterRoutes(clientCtx client.Context, rtr *mux.Router) { + r := rest.WithHTTPDeprecationHeaders(rtr) + registerQueryRoutes(clientCtx, r) +} diff --git a/x/mint/genesis.go b/x/mint/genesis.go new file mode 100644 index 000000000..f19a27e83 --- /dev/null +++ b/x/mint/genesis.go @@ -0,0 +1,22 @@ +package mint + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/tendermint/spn/x/mint/keeper" + "github.com/tendermint/spn/x/mint/types" +) + +// InitGenesis new mint genesis +func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, ak types.AccountKeeper, data *types.GenesisState) { + keeper.SetMinter(ctx, data.Minter) + keeper.SetParams(ctx, data.Params) + ak.GetModuleAccount(ctx, types.ModuleName) +} + +// ExportGenesis returns a GenesisState for a given context and keeper. +func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState { + minter := keeper.GetMinter(ctx) + params := keeper.GetParams(ctx) + return types.NewGenesisState(minter, params) +} diff --git a/x/mint/keeper/grpc.go b/x/mint/keeper/grpc.go new file mode 100644 index 000000000..0f89f6030 --- /dev/null +++ b/x/mint/keeper/grpc.go @@ -0,0 +1,35 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/tendermint/spn/x/mint/types" +) + +var _ types.QueryServer = Keeper{} + +// Params returns params of the mint module. +func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + params := k.GetParams(ctx) + + return &types.QueryParamsResponse{Params: params}, nil +} + +// Inflation returns minter.Inflation of the mint module. +func (k Keeper) Inflation(c context.Context, _ *types.QueryInflationRequest) (*types.QueryInflationResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + minter := k.GetMinter(ctx) + + return &types.QueryInflationResponse{Inflation: minter.Inflation}, nil +} + +// AnnualProvisions returns minter.AnnualProvisions of the mint module. +func (k Keeper) AnnualProvisions(c context.Context, _ *types.QueryAnnualProvisionsRequest) (*types.QueryAnnualProvisionsResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + minter := k.GetMinter(ctx) + + return &types.QueryAnnualProvisionsResponse{AnnualProvisions: minter.AnnualProvisions}, nil +} diff --git a/x/mint/keeper/grpc_test.go b/x/mint/keeper/grpc_test.go new file mode 100644 index 000000000..da1fc2f29 --- /dev/null +++ b/x/mint/keeper/grpc_test.go @@ -0,0 +1,56 @@ +package keeper_test + +import ( + gocontext "context" + "testing" + + "github.com/cosmos/cosmos-sdk/baseapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/suite" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + spnapp "github.com/tendermint/spn/app" + "github.com/tendermint/spn/x/mint/types" +) + +type MintTestSuite struct { + suite.Suite + + app *spnapp.App + ctx sdk.Context + queryClient types.QueryClient +} + +func (suite *MintTestSuite) SetupTest() { + app := setup(false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + + queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) + types.RegisterQueryServer(queryHelper, app.MintKeeper) + queryClient := types.NewQueryClient(queryHelper) + + suite.app = app + suite.ctx = ctx + + suite.queryClient = queryClient +} + +func (suite *MintTestSuite) TestGRPCParams() { + app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient + + params, err := queryClient.Params(gocontext.Background(), &types.QueryParamsRequest{}) + suite.Require().NoError(err) + suite.Require().Equal(params.Params, app.MintKeeper.GetParams(ctx)) + + inflation, err := queryClient.Inflation(gocontext.Background(), &types.QueryInflationRequest{}) + suite.Require().NoError(err) + suite.Require().Equal(inflation.Inflation, app.MintKeeper.GetMinter(ctx).Inflation) + + annualProvisions, err := queryClient.AnnualProvisions(gocontext.Background(), &types.QueryAnnualProvisionsRequest{}) + suite.Require().NoError(err) + suite.Require().Equal(annualProvisions.AnnualProvisions, app.MintKeeper.GetMinter(ctx).AnnualProvisions) +} + +func TestMintTestSuite(t *testing.T) { + suite.Run(t, new(MintTestSuite)) +} diff --git a/x/mint/keeper/integration_test.go b/x/mint/keeper/integration_test.go new file mode 100644 index 000000000..2192dec05 --- /dev/null +++ b/x/mint/keeper/integration_test.go @@ -0,0 +1,71 @@ +package keeper_test + +import ( + "encoding/json" + + "github.com/cosmos/cosmos-sdk/simapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ignite-hq/cli/ignite/pkg/cosmoscmd" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/log" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + dbm "github.com/tendermint/tm-db" + + spnapp "github.com/tendermint/spn/app" + "github.com/tendermint/spn/x/mint/types" +) + +// returns context and an app with updated mint keeper +func createTestApp(isCheckTx bool) (*spnapp.App, sdk.Context) { + app := setup(isCheckTx) + + ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) + app.MintKeeper.SetParams(ctx, types.DefaultParams()) + app.MintKeeper.SetMinter(ctx, types.DefaultInitialMinter()) + + return app, ctx +} + +func setup(isCheckTx bool) *spnapp.App { + app, genesisState := genApp(!isCheckTx, 5) + if !isCheckTx { + // init chain must be called to stop deliverState from being nil + stateBytes, err := json.MarshalIndent(genesisState, "", " ") + if err != nil { + panic(err) + } + + // Initialize the chain + app.InitChain( + abci.RequestInitChain{ + Validators: []abci.ValidatorUpdate{}, + ConsensusParams: simapp.DefaultConsensusParams, + AppStateBytes: stateBytes, + }, + ) + } + + return app +} + +func genApp(withGenesis bool, invCheckPeriod uint) (*spnapp.App, spnapp.GenesisState) { + db := dbm.NewMemDB() + encCdc := cosmoscmd.MakeEncodingConfig(spnapp.ModuleBasics) + app := spnapp.New( + log.NewNopLogger(), + db, + nil, + true, + map[int64]bool{}, + simapp.DefaultNodeHome, + invCheckPeriod, + encCdc, + simapp.EmptyAppOptions{}) + + originalApp := app.(*spnapp.App) + if withGenesis { + return originalApp, spnapp.NewDefaultGenesisState(encCdc.Marshaler) + } + + return originalApp, spnapp.GenesisState{} +} diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go new file mode 100644 index 000000000..73a97affd --- /dev/null +++ b/x/mint/keeper/keeper.go @@ -0,0 +1,151 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/tendermint/tendermint/libs/log" + + "github.com/tendermint/spn/x/mint/types" +) + +// Keeper of the mint store +type Keeper struct { + cdc codec.BinaryCodec + storeKey sdk.StoreKey + paramSpace paramtypes.Subspace + stakingKeeper types.StakingKeeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + distrKeeper types.DistrKeeper + feeCollectorName string +} + +// NewKeeper creates a new mint Keeper instance +func NewKeeper( + cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, + sk types.StakingKeeper, ak types.AccountKeeper, bk types.BankKeeper, dk types.DistrKeeper, + feeCollectorName string, +) Keeper { + // ensure mint module account is set + if addr := ak.GetModuleAddress(types.ModuleName); addr == nil { + panic("the mint module account has not been set") + } + + // set KeyTable if it has not already been set + if !paramSpace.HasKeyTable() { + paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) + } + + return Keeper{ + cdc: cdc, + storeKey: key, + paramSpace: paramSpace, + stakingKeeper: sk, + accountKeeper: ak, + bankKeeper: bk, + distrKeeper: dk, + feeCollectorName: feeCollectorName, + } +} + +// Logger returns a module-specific logger. +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", "x/"+types.ModuleName) +} + +// get the minter +func (k Keeper) GetMinter(ctx sdk.Context) (minter types.Minter) { + store := ctx.KVStore(k.storeKey) + b := store.Get(types.MinterKey) + if b == nil { + panic("stored minter should not have been nil") + } + + k.cdc.MustUnmarshal(b, &minter) + return +} + +// set the minter +func (k Keeper) SetMinter(ctx sdk.Context, minter types.Minter) { + store := ctx.KVStore(k.storeKey) + b := k.cdc.MustMarshal(&minter) + store.Set(types.MinterKey, b) +} + +// GetParams returns the total set of minting parameters. +func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { + k.paramSpace.GetParamSet(ctx, ¶ms) + return params +} + +// SetParams sets the total set of minting parameters. +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + k.paramSpace.SetParamSet(ctx, ¶ms) +} + +// StakingTokenSupply implements an alias call to the underlying staking keeper's +// StakingTokenSupply to be used in BeginBlocker. +func (k Keeper) StakingTokenSupply(ctx sdk.Context) sdk.Int { + 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 sdk.Context) sdk.Dec { + 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 sdk.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 sdk.Context, fees sdk.Coins) error { + return k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, k.feeCollectorName, fees) +} + +// GetProportions gets the balance of the `MintedDenom` from minted coins and returns coins according to the `AllocationRatio`. +func (k Keeper) GetProportions(ctx sdk.Context, mintedCoin sdk.Coin, ratio sdk.Dec) sdk.Coin { + return sdk.NewCoin(mintedCoin.Denom, mintedCoin.Amount.ToDec().Mul(ratio).TruncateInt()) +} + +// DistributeMintedCoins implements distribution of minted coins from mint +// DistributeMintedCoins to be used in BeginBlocker. +func (k Keeper) DistributeMintedCoins(ctx sdk.Context, mintedCoin sdk.Coin) error { + params := k.GetParams(ctx) + proportions := params.DistributionProportions + + // allocate staking rewards into fee collector account to be moved to on next begin blocker by staking module + stakingRewardsCoins := sdk.NewCoins(k.GetProportions(ctx, mintedCoin, proportions.Staking)) + err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, k.feeCollectorName, stakingRewardsCoins) + if err != nil { + return err + } + + // allocate pool allocation ratio to incentives module account + incentivesCoins := sdk.NewCoins() + //TODO: uncomment once incentives module is in place + // incentivesCoins := sdk.NewCoins(k.GetProportions(ctx, mintedCoin, proportions.Incentives)) + // err = k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, incentivestypes.ModuleName, incentivesCoins) + // if err != nil { + // return err + // } + + // subtract from original provision to ensure no coins left over after the allocations + communityPoolCoins := sdk.NewCoins(mintedCoin).Sub(stakingRewardsCoins).Sub(incentivesCoins) + err = k.distrKeeper.FundCommunityPool(ctx, communityPoolCoins, k.accountKeeper.GetModuleAddress(types.ModuleName)) + if err != nil { + return err + } + + return err +} diff --git a/x/mint/keeper/querier.go b/x/mint/keeper/querier.go new file mode 100644 index 000000000..e0f973f29 --- /dev/null +++ b/x/mint/keeper/querier.go @@ -0,0 +1,63 @@ +package keeper + +import ( + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/tendermint/spn/x/mint/types" +) + +// NewQuerier returns a minting Querier handler. +func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { + return func(ctx sdk.Context, path []string, _ abci.RequestQuery) ([]byte, error) { + switch path[0] { + case types.QueryParameters: + return queryParams(ctx, k, legacyQuerierCdc) + + case types.QueryInflation: + return queryInflation(ctx, k, legacyQuerierCdc) + + case types.QueryAnnualProvisions: + return queryAnnualProvisions(ctx, k, legacyQuerierCdc) + + default: + return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path: %s", path[0]) + } + } +} + +func queryParams(ctx sdk.Context, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { + params := k.GetParams(ctx) + + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, params) + if err != nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) + } + + return res, nil +} + +func queryInflation(ctx sdk.Context, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { + minter := k.GetMinter(ctx) + + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, minter.Inflation) + if err != nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) + } + + return res, nil +} + +func queryAnnualProvisions(ctx sdk.Context, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { + minter := k.GetMinter(ctx) + + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, minter.AnnualProvisions) + if err != nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) + } + + return res, nil +} diff --git a/x/mint/keeper/querier_test.go b/x/mint/keeper/querier_test.go new file mode 100644 index 000000000..507f47fa7 --- /dev/null +++ b/x/mint/keeper/querier_test.go @@ -0,0 +1,84 @@ +package keeper_test + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/tendermint/spn/x/mint/keeper" + "github.com/tendermint/spn/x/mint/types" +) + +func TestNewQuerier(t *testing.T) { + app, ctx := createTestApp(true) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) + querier := keeper.NewQuerier(app.MintKeeper, legacyQuerierCdc.LegacyAmino) + + query := abci.RequestQuery{ + Path: "", + Data: []byte{}, + } + + _, err := querier(ctx, []string{types.QueryParameters}, query) + require.NoError(t, err) + + _, err = querier(ctx, []string{types.QueryInflation}, query) + require.NoError(t, err) + + _, err = querier(ctx, []string{types.QueryAnnualProvisions}, query) + require.NoError(t, err) + + _, err = querier(ctx, []string{"foo"}, query) + require.Error(t, err) +} + +func TestQueryParams(t *testing.T) { + app, ctx := createTestApp(true) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) + querier := keeper.NewQuerier(app.MintKeeper, legacyQuerierCdc.LegacyAmino) + + var params types.Params + + res, sdkErr := querier(ctx, []string{types.QueryParameters}, abci.RequestQuery{}) + require.NoError(t, sdkErr) + + err := app.LegacyAmino().UnmarshalJSON(res, ¶ms) + require.NoError(t, err) + + require.Equal(t, app.MintKeeper.GetParams(ctx), params) +} + +func TestQueryInflation(t *testing.T) { + app, ctx := createTestApp(true) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) + querier := keeper.NewQuerier(app.MintKeeper, legacyQuerierCdc.LegacyAmino) + + var inflation sdk.Dec + + res, sdkErr := querier(ctx, []string{types.QueryInflation}, abci.RequestQuery{}) + require.NoError(t, sdkErr) + + err := app.LegacyAmino().UnmarshalJSON(res, &inflation) + require.NoError(t, err) + + require.Equal(t, app.MintKeeper.GetMinter(ctx).Inflation, inflation) +} + +func TestQueryAnnualProvisions(t *testing.T) { + app, ctx := createTestApp(true) + legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) + querier := keeper.NewQuerier(app.MintKeeper, legacyQuerierCdc.LegacyAmino) + + var annualProvisions sdk.Dec + + res, sdkErr := querier(ctx, []string{types.QueryAnnualProvisions}, abci.RequestQuery{}) + require.NoError(t, sdkErr) + + err := app.LegacyAmino().UnmarshalJSON(res, &annualProvisions) + require.NoError(t, err) + + require.Equal(t, app.MintKeeper.GetMinter(ctx).AnnualProvisions, annualProvisions) +} diff --git a/x/mint/module.go b/x/mint/module.go new file mode 100644 index 000000000..91bbbc00a --- /dev/null +++ b/x/mint/module.go @@ -0,0 +1,186 @@ +package mint + +import ( + "context" + "encoding/json" + "fmt" + "math/rand" + + "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" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/tendermint/spn/x/mint/client/cli" + "github.com/tendermint/spn/x/mint/client/rest" + "github.com/tendermint/spn/x/mint/keeper" + "github.com/tendermint/spn/x/mint/simulation" + "github.com/tendermint/spn/x/mint/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleSimulation = AppModule{} +) + +// AppModuleBasic defines the basic application module used by the mint module. +type AppModuleBasic struct { + cdc codec.Codec +} + +var _ module.AppModuleBasic = AppModuleBasic{} + +// 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) {} + +// RegisterInterfaces registers the module's interface types +func (b AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {} + +// 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, config client.TxEncodingConfig, bz json.RawMessage) error { + var data types.GenesisState + if err := cdc.UnmarshalJSON(bz, &data); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + + return types.ValidateGenesis(data) +} + +// RegisterRESTRoutes registers the REST routes for the mint module. +func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { + rest.RegisterRoutes(clientCtx, rtr) +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the mint module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + +} + +// GetTxCmd returns no root tx command for the mint module. +func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil } + +// GetQueryCmd returns the root query command for the mint module. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// AppModule implements an application module for the mint module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper + authKeeper types.AccountKeeper +} + +// NewAppModule creates a new AppModule object +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper) AppModule { + return AppModule{ + AppModuleBasic: AppModuleBasic{cdc: cdc}, + keeper: keeper, + authKeeper: ak, + } +} + +// Name returns the mint module's name. +func (AppModule) Name() string { + return types.ModuleName +} + +// RegisterInvariants registers the mint module invariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// Route returns the message routing key for the mint module. +func (AppModule) Route() sdk.Route { return sdk.Route{} } + +// QuerierRoute returns the mint module's querier route name. +func (AppModule) QuerierRoute() string { + return types.QuerierRoute +} + +// LegacyQuerierHandler returns the mint module sdk.Querier. +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { + return keeper.NewQuerier(am.keeper, legacyQuerierCdc) +} + +// 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(), 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) []abci.ValidatorUpdate { + var genesisState types.GenesisState + cdc.MustUnmarshalJSON(data, &genesisState) + + InitGenesis(ctx, am.keeper, am.authKeeper, &genesisState) + return []abci.ValidatorUpdate{} +} + +// 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 := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(gs) +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock returns the begin blocker for the mint module. +func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { + BeginBlocker(ctx, am.keeper) +} + +// EndBlock returns the end blocker for the mint module. It returns no validator +// updates. +func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} + +// AppModuleSimulation functions + +// GenerateGenesisState creates a randomized GenState of the mint module. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// ProposalContents doesn't return any content functions for governance proposals. +func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { + return nil +} + +// RandomizedParams creates randomized mint param changes for the simulator. +func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { + return simulation.ParamChanges(r) +} + +// RegisterStoreDecoder registers a decoder for mint module's types. +func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { + sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) +} + +// WeightedOperations doesn't return any mint module operation. +func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { + return nil +} diff --git a/x/mint/module_test.go b/x/mint/module_test.go new file mode 100644 index 000000000..a6a70dce6 --- /dev/null +++ b/x/mint/module_test.go @@ -0,0 +1,28 @@ +package mint_test + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/simapp" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/stretchr/testify/require" + abcitypes "github.com/tendermint/tendermint/abci/types" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/tendermint/spn/x/mint/types" +) + +func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + + app.InitChain( + abcitypes.RequestInitChain{ + AppStateBytes: []byte("{}"), + ChainId: "test-chain-id", + }, + ) + + acc := app.AccountKeeper.GetAccount(ctx, authtypes.NewModuleAddress(types.ModuleName)) + require.NotNil(t, acc) +} diff --git a/x/mint/simulation/decoder.go b/x/mint/simulation/decoder.go new file mode 100644 index 000000000..9c0dc8914 --- /dev/null +++ b/x/mint/simulation/decoder.go @@ -0,0 +1,27 @@ +package simulation + +import ( + "bytes" + "fmt" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/types/kv" + + "github.com/tendermint/spn/x/mint/types" +) + +// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's +// Value to the corresponding mint type. +func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { + return func(kvA, kvB kv.Pair) string { + switch { + case bytes.Equal(kvA.Key, types.MinterKey): + var minterA, minterB types.Minter + cdc.MustUnmarshal(kvA.Value, &minterA) + cdc.MustUnmarshal(kvB.Value, &minterB) + return fmt.Sprintf("%v\n%v", minterA, minterB) + default: + panic(fmt.Sprintf("invalid mint key %X", kvA.Key)) + } + } +} diff --git a/x/mint/simulation/decoder_test.go b/x/mint/simulation/decoder_test.go new file mode 100644 index 000000000..2cbc0a8a9 --- /dev/null +++ b/x/mint/simulation/decoder_test.go @@ -0,0 +1,47 @@ +package simulation_test + +import ( + "fmt" + "testing" + + "github.com/cosmos/cosmos-sdk/simapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/stretchr/testify/require" + + "github.com/tendermint/spn/x/mint/simulation" + "github.com/tendermint/spn/x/mint/types" +) + +func TestDecodeStore(t *testing.T) { + cdc := simapp.MakeTestEncodingConfig().Marshaler + dec := simulation.NewDecodeStore(cdc) + + minter := types.NewMinter(sdk.OneDec(), sdk.NewDec(15)) + + kvPairs := kv.Pairs{ + Pairs: []kv.Pair{ + {Key: types.MinterKey, Value: cdc.MustMarshal(&minter)}, + {Key: []byte{0x99}, Value: []byte{0x99}}, + }, + } + tests := []struct { + name string + expectedLog string + }{ + {"Minter", fmt.Sprintf("%v\n%v", minter, minter)}, + {"other", ""}, + } + + for i, tt := range tests { + i, tt := i, tt + t.Run(tt.name, func(t *testing.T) { + switch i { + case len(tests) - 1: + require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name) + default: + require.Equal(t, tt.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name) + } + }) + } +} diff --git a/x/mint/simulation/genesis.go b/x/mint/simulation/genesis.go new file mode 100644 index 000000000..2cf9f887a --- /dev/null +++ b/x/mint/simulation/genesis.go @@ -0,0 +1,117 @@ +package simulation + +// DONTCOVER + +import ( + "encoding/json" + "fmt" + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/tendermint/spn/x/mint/types" +) + +// Simulation parameter constants +const ( + Inflation = "inflation" + InflationRateChange = "inflation_rate_change" + InflationMax = "inflation_max" + InflationMin = "inflation_min" + GoalBonded = "goal_bonded" + DistributionProportions = "distribution_proportions" +) + +// GenInflation randomized Inflation +func GenInflation(r *rand.Rand) sdk.Dec { + return sdk.NewDecWithPrec(int64(r.Intn(99)), 2) +} + +// GenInflationRateChange randomized InflationRateChange +func GenInflationRateChange(r *rand.Rand) sdk.Dec { + return sdk.NewDecWithPrec(int64(r.Intn(99)), 2) +} + +// GenInflationMax randomized InflationMax +func GenInflationMax(r *rand.Rand) sdk.Dec { + return sdk.NewDecWithPrec(20, 2) +} + +// GenInflationMin randomized InflationMin +func GenInflationMin(r *rand.Rand) sdk.Dec { + return sdk.NewDecWithPrec(7, 2) +} + +// GenGoalBonded randomized GoalBonded +func GenGoalBonded(r *rand.Rand) sdk.Dec { + return sdk.NewDecWithPrec(67, 2) +} + +// GenDistributionProportions randomized DistributionProportions +func GenDistributionProportions(r *rand.Rand) types.DistributionProportions { + staking := r.Int63n(99) + left := int64(100) - staking + incentives := r.Int63n(left) + communityPool := left - incentives + + return types.DistributionProportions{ + Staking: sdk.NewDecWithPrec(staking, 2), + Incentives: sdk.NewDecWithPrec(incentives, 2), + CommunityPool: sdk.NewDecWithPrec(communityPool, 2), + } +} + +// RandomizedGenState generates a random GenesisState for mint +func RandomizedGenState(simState *module.SimulationState) { + // minter + var inflation sdk.Dec + simState.AppParams.GetOrGenerate( + simState.Cdc, Inflation, &inflation, simState.Rand, + func(r *rand.Rand) { inflation = GenInflation(r) }, + ) + + // params + var inflationRateChange sdk.Dec + simState.AppParams.GetOrGenerate( + simState.Cdc, InflationRateChange, &inflationRateChange, simState.Rand, + func(r *rand.Rand) { inflationRateChange = GenInflationRateChange(r) }, + ) + + var inflationMax sdk.Dec + simState.AppParams.GetOrGenerate( + simState.Cdc, InflationMax, &inflationMax, simState.Rand, + func(r *rand.Rand) { inflationMax = GenInflationMax(r) }, + ) + + var inflationMin sdk.Dec + simState.AppParams.GetOrGenerate( + simState.Cdc, InflationMin, &inflationMin, simState.Rand, + func(r *rand.Rand) { inflationMin = GenInflationMin(r) }, + ) + + var goalBonded sdk.Dec + simState.AppParams.GetOrGenerate( + simState.Cdc, GoalBonded, &goalBonded, simState.Rand, + func(r *rand.Rand) { goalBonded = GenGoalBonded(r) }, + ) + + var distributionProportions types.DistributionProportions + simState.AppParams.GetOrGenerate( + simState.Cdc, DistributionProportions, &distributionProportions, simState.Rand, + func(r *rand.Rand) { distributionProportions = GenDistributionProportions(r) }, + ) + + mintDenom := sdk.DefaultBondDenom + blocksPerYear := uint64(60 * 60 * 8766 / 5) + params := types.NewParams(mintDenom, inflationRateChange, inflationMax, inflationMin, goalBonded, blocksPerYear, distributionProportions) + + mintGenesis := types.NewGenesisState(types.InitialMinter(inflation), params) + + bz, err := json.MarshalIndent(&mintGenesis, "", " ") + if err != nil { + panic(err) + } + fmt.Printf("Selected randomly generated minting parameters:\n%s\n", bz) + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(mintGenesis) +} diff --git a/x/mint/simulation/genesis_test.go b/x/mint/simulation/genesis_test.go new file mode 100644 index 000000000..a28567578 --- /dev/null +++ b/x/mint/simulation/genesis_test.go @@ -0,0 +1,90 @@ +package simulation_test + +import ( + "encoding/json" + "math/rand" + "testing" + + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/stretchr/testify/require" + + "github.com/tendermint/spn/x/mint/simulation" + "github.com/tendermint/spn/x/mint/types" +) + +// TestRandomizedGenState tests the normal scenario of applying RandomizedGenState. +// Abonormal scenarios are not tested here. +func TestRandomizedGenState(t *testing.T) { + interfaceRegistry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(interfaceRegistry) + + s := rand.NewSource(1) + r := rand.New(s) + + simState := module.SimulationState{ + AppParams: make(simtypes.AppParams), + Cdc: cdc, + Rand: r, + NumBonded: 3, + Accounts: simtypes.RandomAccounts(r, 3), + InitialStake: 1000, + GenState: make(map[string]json.RawMessage), + } + + simulation.RandomizedGenState(&simState) + + var mintGenesis types.GenesisState + simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &mintGenesis) + + dec1, _ := sdk.NewDecFromStr("0.670000000000000000") + dec2, _ := sdk.NewDecFromStr("0.200000000000000000") + dec3, _ := sdk.NewDecFromStr("0.070000000000000000") + dec4, _ := sdk.NewDecFromStr("0.170000000000000000") + dec5, _ := sdk.NewDecFromStr("0.700000000000000000") + dec6, _ := sdk.NewDecFromStr("0.130000000000000000") + + require.Equal(t, uint64(6311520), mintGenesis.Params.BlocksPerYear) + require.Equal(t, dec1, mintGenesis.Params.GoalBonded) + require.Equal(t, dec2, mintGenesis.Params.InflationMax) + require.Equal(t, dec3, mintGenesis.Params.InflationMin) + require.Equal(t, "stake", mintGenesis.Params.MintDenom) + require.Equal(t, dec4, mintGenesis.Params.DistributionProportions.Staking) + require.Equal(t, dec5, mintGenesis.Params.DistributionProportions.Incentives) + require.Equal(t, dec6, mintGenesis.Params.DistributionProportions.CommunityPool) + require.Equal(t, "0stake", mintGenesis.Minter.BlockProvision(mintGenesis.Params).String()) + require.Equal(t, "0.170000000000000000", mintGenesis.Minter.NextAnnualProvisions(mintGenesis.Params, sdk.OneInt()).String()) + require.Equal(t, "0.169999926644441493", mintGenesis.Minter.NextInflationRate(mintGenesis.Params, sdk.OneDec()).String()) + require.Equal(t, "0.170000000000000000", mintGenesis.Minter.Inflation.String()) + require.Equal(t, "0.000000000000000000", mintGenesis.Minter.AnnualProvisions.String()) +} + +// TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState. +func TestRandomizedGenState1(t *testing.T) { + interfaceRegistry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(interfaceRegistry) + + s := rand.NewSource(1) + r := rand.New(s) + // all these tests will panic + tests := []struct { + simState module.SimulationState + panicMsg string + }{ + { // panic => reason: incomplete initialization of the simState + module.SimulationState{}, "invalid memory address or nil pointer dereference"}, + { // panic => reason: incomplete initialization of the simState + module.SimulationState{ + AppParams: make(simtypes.AppParams), + Cdc: cdc, + Rand: r, + }, "assignment to entry in nil map"}, + } + + for _, tt := range tests { + require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) + } +} diff --git a/x/mint/simulation/params.go b/x/mint/simulation/params.go new file mode 100644 index 000000000..b75b0fc70 --- /dev/null +++ b/x/mint/simulation/params.go @@ -0,0 +1,47 @@ +package simulation + +// DONTCOVER + +import ( + "fmt" + "math/rand" + + "github.com/cosmos/cosmos-sdk/x/simulation" + + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/mint/types" +) + +const ( + keyInflationRateChange = "InflationRateChange" + keyInflationMax = "InflationMax" + keyInflationMin = "InflationMin" + keyGoalBonded = "GoalBonded" +) + +// ParamChanges defines the parameters that can be modified by param change proposals +// on the simulation +func ParamChanges(r *rand.Rand) []simtypes.ParamChange { + return []simtypes.ParamChange{ + simulation.NewSimParamChange(types.ModuleName, keyInflationRateChange, + func(r *rand.Rand) string { + return fmt.Sprintf("\"%s\"", GenInflationRateChange(r)) + }, + ), + simulation.NewSimParamChange(types.ModuleName, keyInflationMax, + func(r *rand.Rand) string { + return fmt.Sprintf("\"%s\"", GenInflationMax(r)) + }, + ), + simulation.NewSimParamChange(types.ModuleName, keyInflationMin, + func(r *rand.Rand) string { + return fmt.Sprintf("\"%s\"", GenInflationMin(r)) + }, + ), + simulation.NewSimParamChange(types.ModuleName, keyGoalBonded, + func(r *rand.Rand) string { + return fmt.Sprintf("\"%s\"", GenGoalBonded(r)) + }, + ), + } +} diff --git a/x/mint/simulation/params_test.go b/x/mint/simulation/params_test.go new file mode 100644 index 000000000..2d7d97235 --- /dev/null +++ b/x/mint/simulation/params_test.go @@ -0,0 +1,38 @@ +package simulation_test + +import ( + "math/rand" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/tendermint/spn/x/mint/simulation" +) + +func TestParamChangest(t *testing.T) { + s := rand.NewSource(1) + r := rand.New(s) + + expected := []struct { + composedKey string + key string + simValue string + subspace string + }{ + {"mint/InflationRateChange", "InflationRateChange", "\"0.230000000000000000\"", "mint"}, + {"mint/InflationMax", "InflationMax", "\"0.200000000000000000\"", "mint"}, + {"mint/InflationMin", "InflationMin", "\"0.070000000000000000\"", "mint"}, + {"mint/GoalBonded", "GoalBonded", "\"0.670000000000000000\"", "mint"}, + } + + paramChanges := simulation.ParamChanges(r) + require.Len(t, paramChanges, 4) + + for i, p := range paramChanges { + require.Equal(t, expected[i].composedKey, p.ComposedKey()) + require.Equal(t, expected[i].key, p.Key()) + require.Equal(t, expected[i].simValue, p.SimValue()(r)) + require.Equal(t, expected[i].subspace, p.Subspace()) + } + +} diff --git a/x/mint/types/codec.go b/x/mint/types/codec.go new file mode 100644 index 000000000..b436c1029 --- /dev/null +++ b/x/mint/types/codec.go @@ -0,0 +1,15 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" +) + +var ( + amino = codec.NewLegacyAmino() +) + +func init() { + cryptocodec.RegisterCrypto(amino) + amino.Seal() +} diff --git a/x/mint/types/events.go b/x/mint/types/events.go new file mode 100644 index 000000000..dce85bdb7 --- /dev/null +++ b/x/mint/types/events.go @@ -0,0 +1,10 @@ +package types + +// Minting module event types +const ( + EventTypeMint = ModuleName + + AttributeKeyBondedRatio = "bonded_ratio" + AttributeKeyInflation = "inflation" + AttributeKeyAnnualProvisions = "annual_provisions" +) diff --git a/x/mint/types/expected_keepers.go b/x/mint/types/expected_keepers.go new file mode 100644 index 000000000..929aa777d --- /dev/null +++ b/x/mint/types/expected_keepers.go @@ -0,0 +1,31 @@ +package types // noalias + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +// StakingKeeper defines the expected staking keeper +type StakingKeeper interface { + StakingTokenSupply(ctx sdk.Context) sdk.Int + BondedRatio(ctx sdk.Context) sdk.Dec +} + +// AccountKeeper defines the contract required for account APIs. +type AccountKeeper interface { + GetModuleAddress(name string) sdk.AccAddress + GetModuleAccount(ctx sdk.Context, moduleName string) types.ModuleAccountI +} + +// DistrKeeper defines the contract needed to be fulfilled for distribution keeper. +type DistrKeeper interface { + FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error +} + +// BankKeeper defines the contract needed to be fulfilled for banking and supply +// dependencies. +type BankKeeper interface { + SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error + MintCoins(ctx sdk.Context, name string, amt sdk.Coins) error +} diff --git a/x/mint/types/genesis.go b/x/mint/types/genesis.go new file mode 100644 index 000000000..3d2f761b4 --- /dev/null +++ b/x/mint/types/genesis.go @@ -0,0 +1,27 @@ +package types + +// NewGenesisState creates a new GenesisState object +func NewGenesisState(minter Minter, params Params) *GenesisState { + return &GenesisState{ + Minter: minter, + Params: params, + } +} + +// DefaultGenesisState creates a default GenesisState object +func DefaultGenesisState() *GenesisState { + return &GenesisState{ + Minter: DefaultInitialMinter(), + Params: DefaultParams(), + } +} + +// ValidateGenesis validates the provided genesis state to ensure the +// expected invariants holds. +func ValidateGenesis(data GenesisState) error { + if err := data.Params.Validate(); err != nil { + return err + } + + return ValidateMinter(data.Minter) +} diff --git a/x/mint/types/genesis.pb.go b/x/mint/types/genesis.pb.go new file mode 100644 index 000000000..88e49b9d7 --- /dev/null +++ b/x/mint/types/genesis.pb.go @@ -0,0 +1,376 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: mint/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/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 { + // minter is a space for holding current inflation information. + Minter Minter `protobuf:"bytes,1,opt,name=minter,proto3" json:"minter"` + // params defines all the paramaters of the module. + Params Params `protobuf:"bytes,2,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_50813f2cd53c1776, []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) GetMinter() Minter { + if m != nil { + return m.Minter + } + return Minter{} +} + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "tendermint.spn.mint.GenesisState") +} + +func init() { proto.RegisterFile("mint/genesis.proto", fileDescriptor_50813f2cd53c1776) } + +var fileDescriptor_50813f2cd53c1776 = []byte{ + // 208 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xca, 0xcd, 0xcc, 0x2b, + 0xd1, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, + 0x2e, 0x49, 0xcd, 0x4b, 0x49, 0x2d, 0x02, 0xc9, 0xe8, 0x15, 0x17, 0xe4, 0xe9, 0x81, 0x18, 0x52, + 0x22, 0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0x79, 0x7d, 0x10, 0x0b, 0xa2, 0x54, 0x8a, 0x1f, 0xac, 0x1d, + 0xac, 0x12, 0x2c, 0xa0, 0xd4, 0xc2, 0xc8, 0xc5, 0xe3, 0x0e, 0x31, 0x2d, 0xb8, 0x24, 0xb1, 0x24, + 0x55, 0xc8, 0x92, 0x8b, 0x0d, 0x24, 0x9d, 0x5a, 0x24, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x6d, 0x24, + 0xad, 0x87, 0xc5, 0x74, 0x3d, 0x5f, 0xb0, 0x12, 0x27, 0x96, 0x13, 0xf7, 0xe4, 0x19, 0x82, 0xa0, + 0x1a, 0x40, 0x5a, 0x0b, 0x12, 0x8b, 0x12, 0x73, 0x8b, 0x25, 0x98, 0xf0, 0x68, 0x0d, 0x00, 0x2b, + 0x81, 0x69, 0x85, 0x68, 0x70, 0x72, 0x38, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, + 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, + 0x28, 0xb5, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0x84, 0x71, 0xfa, + 0xc5, 0x05, 0x79, 0xfa, 0x15, 0x60, 0x8f, 0xe8, 0x97, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, + 0xfd, 0x63, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x23, 0xca, 0x6d, 0x2e, 0x21, 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] = 0x12 + { + size, err := m.Minter.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.Minter.Size() + n += 1 + l + sovGenesis(uint64(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 Minter", 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.Minter.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + 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/x/mint/types/keys.go b/x/mint/types/keys.go new file mode 100644 index 000000000..e1c778744 --- /dev/null +++ b/x/mint/types/keys.go @@ -0,0 +1,20 @@ +package types + +// MinterKey is the key to use for the keeper store. +var MinterKey = []byte{0x00} + +const ( + // module name + ModuleName = "mint" + + // StoreKey is the default store key for mint + StoreKey = ModuleName + + // QuerierRoute is the querier route for the minting store. + QuerierRoute = StoreKey + + // Query endpoints supported by the minting querier + QueryParameters = "parameters" + QueryInflation = "inflation" + QueryAnnualProvisions = "annual_provisions" +) diff --git a/x/mint/types/mint.pb.go b/x/mint/types/mint.pb.go new file mode 100644 index 000000000..f81b5a192 --- /dev/null +++ b/x/mint/types/mint.pb.go @@ -0,0 +1,1102 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: mint/mint.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/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 + +// Minter represents the minting state. +type Minter struct { + // current annual inflation rate + Inflation github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=inflation,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflation"` + // current annual expected provisions + AnnualProvisions github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=annual_provisions,json=annualProvisions,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"annual_provisions"` +} + +func (m *Minter) Reset() { *m = Minter{} } +func (m *Minter) String() string { return proto.CompactTextString(m) } +func (*Minter) ProtoMessage() {} +func (*Minter) Descriptor() ([]byte, []int) { + return fileDescriptor_e1b9fbb701b2a577, []int{0} +} +func (m *Minter) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Minter) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Minter.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 *Minter) XXX_Merge(src proto.Message) { + xxx_messageInfo_Minter.Merge(m, src) +} +func (m *Minter) XXX_Size() int { + return m.Size() +} +func (m *Minter) XXX_DiscardUnknown() { + xxx_messageInfo_Minter.DiscardUnknown(m) +} + +var xxx_messageInfo_Minter proto.InternalMessageInfo + +type DistributionProportions struct { + // staking defines the proportion of the minted minted_denom that is to be + // allocated as staking rewards. + Staking github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=staking,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"staking"` + // incentives defines the proportion of the minted minted_denom that is + // to be allocated as incentives. + Incentives github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=incentives,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"incentives"` + // community_pool defines the proportion of the minted minted_denom that is + // to be allocated to the community pool. + CommunityPool github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=community_pool,json=communityPool,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"community_pool"` +} + +func (m *DistributionProportions) Reset() { *m = DistributionProportions{} } +func (m *DistributionProportions) String() string { return proto.CompactTextString(m) } +func (*DistributionProportions) ProtoMessage() {} +func (*DistributionProportions) Descriptor() ([]byte, []int) { + return fileDescriptor_e1b9fbb701b2a577, []int{1} +} +func (m *DistributionProportions) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DistributionProportions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DistributionProportions.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 *DistributionProportions) XXX_Merge(src proto.Message) { + xxx_messageInfo_DistributionProportions.Merge(m, src) +} +func (m *DistributionProportions) XXX_Size() int { + return m.Size() +} +func (m *DistributionProportions) XXX_DiscardUnknown() { + xxx_messageInfo_DistributionProportions.DiscardUnknown(m) +} + +var xxx_messageInfo_DistributionProportions proto.InternalMessageInfo + +// Params holds parameters for the 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"` + // maximum annual change in inflation rate + InflationRateChange github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=inflation_rate_change,json=inflationRateChange,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflation_rate_change"` + // maximum inflation rate + InflationMax github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=inflation_max,json=inflationMax,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflation_max"` + // minimum inflation rate + InflationMin github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=inflation_min,json=inflationMin,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflation_min"` + // goal of percent bonded atoms + GoalBonded github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=goal_bonded,json=goalBonded,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"goal_bonded"` + // expected blocks per year + BlocksPerYear uint64 `protobuf:"varint,6,opt,name=blocks_per_year,json=blocksPerYear,proto3" json:"blocks_per_year,omitempty"` + // distribution_proportions defines the proportion of the minted denom + DistributionProportions DistributionProportions `protobuf:"bytes,7,opt,name=distribution_proportions,json=distributionProportions,proto3" json:"distribution_proportions"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_e1b9fbb701b2a577, []int{2} +} +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) GetBlocksPerYear() uint64 { + if m != nil { + return m.BlocksPerYear + } + return 0 +} + +func (m *Params) GetDistributionProportions() DistributionProportions { + if m != nil { + return m.DistributionProportions + } + return DistributionProportions{} +} + +func init() { + proto.RegisterType((*Minter)(nil), "tendermint.spn.mint.Minter") + proto.RegisterType((*DistributionProportions)(nil), "tendermint.spn.mint.DistributionProportions") + proto.RegisterType((*Params)(nil), "tendermint.spn.mint.Params") +} + +func init() { proto.RegisterFile("mint/mint.proto", fileDescriptor_e1b9fbb701b2a577) } + +var fileDescriptor_e1b9fbb701b2a577 = []byte{ + // 482 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x3f, 0x6f, 0xd3, 0x40, + 0x18, 0xc6, 0xe3, 0x62, 0x52, 0xe5, 0x4a, 0x28, 0x5c, 0x41, 0xb5, 0x90, 0x70, 0xa2, 0x0c, 0x55, + 0x06, 0xb0, 0x25, 0xd8, 0x98, 0x50, 0xc8, 0xc0, 0x40, 0xc1, 0x32, 0x62, 0x00, 0x06, 0xeb, 0x6c, + 0x1f, 0xee, 0x29, 0xf6, 0xfb, 0x5a, 0x77, 0x97, 0x2a, 0xf9, 0x0a, 0x4c, 0x8c, 0x8c, 0x48, 0x7c, + 0x04, 0xbe, 0x44, 0xc7, 0x8e, 0x88, 0xa1, 0x42, 0xc9, 0x17, 0x41, 0x67, 0x53, 0x27, 0x42, 0x65, + 0x71, 0x17, 0xfb, 0xd5, 0x73, 0xf6, 0xef, 0xbd, 0x47, 0xef, 0x1f, 0xb2, 0x5f, 0x08, 0xd0, 0xbe, + 0x79, 0x78, 0xa5, 0x44, 0x8d, 0xf4, 0x40, 0x73, 0x48, 0xb9, 0xac, 0x14, 0x55, 0x82, 0x67, 0x82, + 0x07, 0xf7, 0x32, 0xcc, 0xb0, 0x3a, 0xf7, 0x4d, 0x54, 0x7f, 0x3a, 0xfa, 0x61, 0x91, 0xee, 0xb1, + 0x00, 0xcd, 0x25, 0x7d, 0x45, 0x7a, 0x02, 0x3e, 0xe5, 0x4c, 0x0b, 0x04, 0xc7, 0x1a, 0x5a, 0xe3, + 0xde, 0xc4, 0x3b, 0xbb, 0x18, 0x74, 0x7e, 0x5d, 0x0c, 0x8e, 0x32, 0xa1, 0x4f, 0xe6, 0xb1, 0x97, + 0x60, 0xe1, 0x27, 0xa8, 0x0a, 0x54, 0x7f, 0x5f, 0x8f, 0x55, 0x3a, 0xf3, 0xf5, 0xb2, 0xe4, 0xca, + 0x9b, 0xf2, 0x24, 0xdc, 0x00, 0xe8, 0x47, 0x72, 0x97, 0x01, 0xcc, 0x59, 0x1e, 0x95, 0x12, 0x4f, + 0x85, 0x12, 0x08, 0xca, 0xd9, 0x69, 0x45, 0xbd, 0x53, 0x83, 0x82, 0x86, 0x33, 0xfa, 0xbc, 0x43, + 0x0e, 0xa7, 0x42, 0x69, 0x29, 0xe2, 0xb9, 0xc9, 0x16, 0x48, 0x2c, 0x51, 0x9a, 0x48, 0xd1, 0x97, + 0x64, 0x57, 0x69, 0x36, 0x13, 0x90, 0xb5, 0x34, 0x71, 0xf9, 0x3b, 0x7d, 0x4d, 0x88, 0x80, 0x84, + 0x83, 0x16, 0xa7, 0xbc, 0xed, 0xdd, 0xb7, 0x08, 0xf4, 0x1d, 0xb9, 0x9d, 0x60, 0x51, 0xcc, 0x41, + 0xe8, 0x65, 0x54, 0x22, 0xe6, 0xce, 0x8d, 0x56, 0xcc, 0x7e, 0x43, 0x09, 0x10, 0xf3, 0xd1, 0x77, + 0x9b, 0x74, 0x03, 0x26, 0x59, 0xa1, 0xe8, 0x43, 0x42, 0x4c, 0xad, 0xa3, 0x94, 0x03, 0x16, 0xb5, + 0xfd, 0xb0, 0x67, 0x94, 0xa9, 0x11, 0x68, 0x4c, 0xee, 0x37, 0x05, 0x8a, 0x24, 0xd3, 0x3c, 0x4a, + 0x4e, 0x18, 0x64, 0xbc, 0xa5, 0xb7, 0x83, 0x06, 0x16, 0x32, 0xcd, 0x5f, 0x54, 0x28, 0xfa, 0x96, + 0xf4, 0x37, 0x39, 0x0a, 0xb6, 0x68, 0xe9, 0xf1, 0x56, 0x03, 0x39, 0x66, 0x8b, 0x7f, 0xa0, 0x02, + 0x1c, 0xfb, 0xba, 0x50, 0x01, 0xf4, 0x0d, 0xd9, 0xcb, 0x90, 0xe5, 0x51, 0x8c, 0x90, 0xf2, 0xd4, + 0xb9, 0xd9, 0xae, 0xbe, 0x06, 0x31, 0xa9, 0x08, 0xf4, 0x88, 0xec, 0xc7, 0x39, 0x26, 0x33, 0x15, + 0x95, 0x5c, 0x46, 0x4b, 0xce, 0xa4, 0xd3, 0x1d, 0x5a, 0x63, 0x3b, 0xec, 0xd7, 0x72, 0xc0, 0xe5, + 0x7b, 0xce, 0x24, 0x2d, 0x88, 0x93, 0x6e, 0x35, 0xaf, 0x19, 0x90, 0xcb, 0xee, 0x75, 0x76, 0x87, + 0xd6, 0x78, 0xef, 0xc9, 0x23, 0xef, 0x8a, 0x09, 0xf6, 0xfe, 0xd3, 0xf1, 0x13, 0xdb, 0xdc, 0x39, + 0x3c, 0x4c, 0xaf, 0x3e, 0x7e, 0x66, 0x7f, 0xfd, 0x36, 0xe8, 0x4c, 0x9e, 0x9f, 0xad, 0x5c, 0xeb, + 0x7c, 0xe5, 0x5a, 0xbf, 0x57, 0xae, 0xf5, 0x65, 0xed, 0x76, 0xce, 0xd7, 0x6e, 0xe7, 0xe7, 0xda, + 0xed, 0x7c, 0xd8, 0xb6, 0xba, 0x49, 0xeb, 0xab, 0x12, 0xfc, 0x45, 0xb5, 0x55, 0x6a, 0xbb, 0x71, + 0xb7, 0xda, 0x18, 0x4f, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0xc9, 0x3f, 0xba, 0x9e, 0x6f, 0x04, + 0x00, 0x00, +} + +func (m *Minter) 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 *Minter) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Minter) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.AnnualProvisions.Size() + i -= size + if _, err := m.AnnualProvisions.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintMint(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size := m.Inflation.Size() + i -= size + if _, err := m.Inflation.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintMint(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *DistributionProportions) 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 *DistributionProportions) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DistributionProportions) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.CommunityPool.Size() + i -= size + if _, err := m.CommunityPool.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintMint(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size := m.Incentives.Size() + i -= size + if _, err := m.Incentives.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintMint(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size := m.Staking.Size() + i -= size + if _, err := m.Staking.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintMint(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +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 + { + size, err := m.DistributionProportions.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintMint(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + if m.BlocksPerYear != 0 { + i = encodeVarintMint(dAtA, i, uint64(m.BlocksPerYear)) + i-- + dAtA[i] = 0x30 + } + { + size := m.GoalBonded.Size() + i -= size + if _, err := m.GoalBonded.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintMint(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + { + size := m.InflationMin.Size() + i -= size + if _, err := m.InflationMin.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintMint(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + { + size := m.InflationMax.Size() + i -= size + if _, err := m.InflationMax.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintMint(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size := m.InflationRateChange.Size() + i -= size + if _, err := m.InflationRateChange.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintMint(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + 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 *Minter) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Inflation.Size() + n += 1 + l + sovMint(uint64(l)) + l = m.AnnualProvisions.Size() + n += 1 + l + sovMint(uint64(l)) + return n +} + +func (m *DistributionProportions) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Staking.Size() + n += 1 + l + sovMint(uint64(l)) + l = m.Incentives.Size() + n += 1 + l + sovMint(uint64(l)) + l = m.CommunityPool.Size() + n += 1 + l + sovMint(uint64(l)) + return n +} + +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)) + } + l = m.InflationRateChange.Size() + n += 1 + l + sovMint(uint64(l)) + l = m.InflationMax.Size() + n += 1 + l + sovMint(uint64(l)) + l = m.InflationMin.Size() + n += 1 + l + sovMint(uint64(l)) + l = m.GoalBonded.Size() + n += 1 + l + sovMint(uint64(l)) + if m.BlocksPerYear != 0 { + n += 1 + sovMint(uint64(m.BlocksPerYear)) + } + l = m.DistributionProportions.Size() + n += 1 + l + sovMint(uint64(l)) + 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 *Minter) 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: Minter: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Minter: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Inflation", 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 + } + if err := m.Inflation.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AnnualProvisions", 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 + } + if err := m.AnnualProvisions.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + 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 (m *DistributionProportions) 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: DistributionProportions: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DistributionProportions: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Staking", 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 + } + if err := m.Staking.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Incentives", 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 + } + if err := m.Incentives.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CommunityPool", 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 + } + if err := m.CommunityPool.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + 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 (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 != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InflationRateChange", 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 + } + if err := m.InflationRateChange.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InflationMax", 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 + } + if err := m.InflationMax.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InflationMin", 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 + } + if err := m.InflationMin.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GoalBonded", 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 + } + if err := m.GoalBonded.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + 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 + } + } + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DistributionProportions", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMint + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthMint + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthMint + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.DistributionProportions.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + 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/x/mint/types/minter.go b/x/mint/types/minter.go new file mode 100644 index 000000000..3285d6ddf --- /dev/null +++ b/x/mint/types/minter.go @@ -0,0 +1,80 @@ +package types + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// NewMinter returns a new Minter object with the given inflation and annual +// provisions values. +func NewMinter(inflation, annualProvisions sdk.Dec) Minter { + return Minter{ + Inflation: inflation, + AnnualProvisions: annualProvisions, + } +} + +// InitialMinter returns an initial Minter object with a given inflation value. +func InitialMinter(inflation sdk.Dec) Minter { + return NewMinter( + inflation, + sdk.NewDec(0), + ) +} + +// DefaultInitialMinter returns a default initial Minter object for a new chain +// which uses an inflation rate of 13%. +func DefaultInitialMinter() Minter { + return InitialMinter( + sdk.NewDecWithPrec(13, 2), + ) +} + +// validate minter +func ValidateMinter(minter Minter) error { + if minter.Inflation.IsNegative() { + return fmt.Errorf("mint parameter Inflation should be positive, is %s", + minter.Inflation.String()) + } + return nil +} + +// NextInflationRate returns the new inflation rate for the next hour. +func (m Minter) NextInflationRate(params Params, bondedRatio sdk.Dec) sdk.Dec { + // The target annual inflation rate is recalculated for each previsions cycle. The + // inflation is also subject to a rate change (positive or negative) depending on + // the distance from the desired ratio (67%). The maximum rate change possible is + // defined to be 13% per year, however the annual inflation is capped as between + // 7% and 20%. + + // (1 - bondedRatio/GoalBonded) * InflationRateChange + inflationRateChangePerYear := sdk.OneDec(). + Sub(bondedRatio.Quo(params.GoalBonded)). + Mul(params.InflationRateChange) + inflationRateChange := inflationRateChangePerYear.Quo(sdk.NewDec(int64(params.BlocksPerYear))) + + // adjust the new annual inflation for this next cycle + inflation := m.Inflation.Add(inflationRateChange) // note inflationRateChange may be negative + if inflation.GT(params.InflationMax) { + inflation = params.InflationMax + } + if inflation.LT(params.InflationMin) { + inflation = params.InflationMin + } + + return inflation +} + +// NextAnnualProvisions returns the annual provisions based on current total +// supply and inflation rate. +func (m Minter) NextAnnualProvisions(_ Params, totalSupply sdk.Int) sdk.Dec { + return m.Inflation.MulInt(totalSupply) +} + +// BlockProvision returns the provisions for a block based on the annual +// provisions rate. +func (m Minter) BlockProvision(params Params) sdk.Coin { + provisionAmt := m.AnnualProvisions.QuoInt(sdk.NewInt(int64(params.BlocksPerYear))) + return sdk.NewCoin(params.MintDenom, provisionAmt.TruncateInt()) +} diff --git a/x/mint/types/minter_test.go b/x/mint/types/minter_test.go new file mode 100644 index 000000000..4abedb51c --- /dev/null +++ b/x/mint/types/minter_test.go @@ -0,0 +1,134 @@ +package types + +import ( + "math/rand" + "testing" + + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func TestNextInflation(t *testing.T) { + minter := DefaultInitialMinter() + params := DefaultParams() + blocksPerYr := sdk.NewDec(int64(params.BlocksPerYear)) + + // Governing Mechanism: + // inflationRateChangePerYear = (1- BondedRatio/ GoalBonded) * MaxInflationRateChange + + tests := []struct { + bondedRatio, setInflation, expChange sdk.Dec + }{ + // with 0% bonded atom supply the inflation should increase by InflationRateChange + {sdk.ZeroDec(), sdk.NewDecWithPrec(7, 2), params.InflationRateChange.Quo(blocksPerYr)}, + + // 100% bonded, starting at 20% inflation and being reduced + // (1 - (1/0.67))*(0.13/8667) + {sdk.OneDec(), sdk.NewDecWithPrec(20, 2), + sdk.OneDec().Sub(sdk.OneDec().Quo(params.GoalBonded)).Mul(params.InflationRateChange).Quo(blocksPerYr)}, + + // 50% bonded, starting at 10% inflation and being increased + {sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(10, 2), + sdk.OneDec().Sub(sdk.NewDecWithPrec(5, 1).Quo(params.GoalBonded)).Mul(params.InflationRateChange).Quo(blocksPerYr)}, + + // test 7% minimum stop (testing with 100% bonded) + {sdk.OneDec(), sdk.NewDecWithPrec(7, 2), sdk.ZeroDec()}, + {sdk.OneDec(), sdk.NewDecWithPrec(700000001, 10), sdk.NewDecWithPrec(-1, 10)}, + + // test 20% maximum stop (testing with 0% bonded) + {sdk.ZeroDec(), sdk.NewDecWithPrec(20, 2), sdk.ZeroDec()}, + {sdk.ZeroDec(), sdk.NewDecWithPrec(1999999999, 10), sdk.NewDecWithPrec(1, 10)}, + + // perfect balance shouldn't change inflation + {sdk.NewDecWithPrec(67, 2), sdk.NewDecWithPrec(15, 2), sdk.ZeroDec()}, + } + for i, tc := range tests { + minter.Inflation = tc.setInflation + + inflation := minter.NextInflationRate(params, tc.bondedRatio) + diffInflation := inflation.Sub(tc.setInflation) + + require.True(t, diffInflation.Equal(tc.expChange), + "Test Index: %v\nDiff: %v\nExpected: %v\n", i, diffInflation, tc.expChange) + } +} + +func TestBlockProvision(t *testing.T) { + minter := InitialMinter(sdk.NewDecWithPrec(1, 1)) + params := DefaultParams() + + secondsPerYear := int64(60 * 60 * 8766) + + tests := []struct { + annualProvisions int64 + expProvisions int64 + }{ + {secondsPerYear / 5, 1}, + {secondsPerYear/5 + 1, 1}, + {(secondsPerYear / 5) * 2, 2}, + {(secondsPerYear / 5) / 2, 0}, + } + for i, tc := range tests { + minter.AnnualProvisions = sdk.NewDec(tc.annualProvisions) + provisions := minter.BlockProvision(params) + + expProvisions := sdk.NewCoin(params.MintDenom, + sdk.NewInt(tc.expProvisions)) + + require.True(t, expProvisions.IsEqual(provisions), + "test: %v\n\tExp: %v\n\tGot: %v\n", + i, tc.expProvisions, provisions) + } +} + +// Benchmarking :) +// previously using sdk.Int operations: +// BenchmarkBlockProvision-4 5000000 220 ns/op +// +// using sdk.Dec operations: (current implementation) +// BenchmarkBlockProvision-4 3000000 429 ns/op +func BenchmarkBlockProvision(b *testing.B) { + b.ReportAllocs() + minter := InitialMinter(sdk.NewDecWithPrec(1, 1)) + params := DefaultParams() + + s1 := rand.NewSource(100) + r1 := rand.New(s1) + minter.AnnualProvisions = sdk.NewDec(r1.Int63n(1000000)) + + // run the BlockProvision function b.N times + for n := 0; n < b.N; n++ { + minter.BlockProvision(params) + } +} + +// Next inflation benchmarking +// BenchmarkNextInflation-4 1000000 1828 ns/op +func BenchmarkNextInflation(b *testing.B) { + b.ReportAllocs() + minter := InitialMinter(sdk.NewDecWithPrec(1, 1)) + params := DefaultParams() + bondedRatio := sdk.NewDecWithPrec(1, 1) + + // run the NextInflationRate function b.N times + for n := 0; n < b.N; n++ { + minter.NextInflationRate(params, bondedRatio) + } + +} + +// Next annual provisions benchmarking +// BenchmarkNextAnnualProvisions-4 5000000 251 ns/op +func BenchmarkNextAnnualProvisions(b *testing.B) { + b.ReportAllocs() + minter := InitialMinter(sdk.NewDecWithPrec(1, 1)) + params := DefaultParams() + totalSupply := sdk.NewInt(100000000000000) + + // run the NextAnnualProvisions function b.N times + for n := 0; n < b.N; n++ { + minter.NextAnnualProvisions(params, totalSupply) + } + +} diff --git a/x/mint/types/params.go b/x/mint/types/params.go new file mode 100644 index 000000000..a546feae8 --- /dev/null +++ b/x/mint/types/params.go @@ -0,0 +1,234 @@ +package types + +import ( + "errors" + "fmt" + "strings" + + yaml "gopkg.in/yaml.v2" + + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +// Parameter store keys +var ( + KeyMintDenom = []byte("MintDenom") + KeyInflationRateChange = []byte("InflationRateChange") + KeyInflationMax = []byte("InflationMax") + KeyInflationMin = []byte("InflationMin") + KeyGoalBonded = []byte("GoalBonded") + KeyBlocksPerYear = []byte("BlocksPerYear") + KeyDistributionProportions = []byte("DistributionProportions") +) + +// ParamTable for minting module. +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +func NewParams( + mintDenom string, + inflationRateChange, + inflationMax, + inflationMin, + goalBonded sdk.Dec, + blocksPerYear uint64, + proportions DistributionProportions, +) Params { + + return Params{ + MintDenom: mintDenom, + InflationRateChange: inflationRateChange, + InflationMax: inflationMax, + InflationMin: inflationMin, + GoalBonded: goalBonded, + BlocksPerYear: blocksPerYear, + DistributionProportions: proportions, + } +} + +// default minting module parameters +func DefaultParams() Params { + return Params{ + MintDenom: sdk.DefaultBondDenom, + InflationRateChange: sdk.NewDecWithPrec(13, 2), + InflationMax: sdk.NewDecWithPrec(20, 2), + InflationMin: sdk.NewDecWithPrec(7, 2), + GoalBonded: sdk.NewDecWithPrec(67, 2), + BlocksPerYear: uint64(60 * 60 * 8766 / 5), // assuming 5 second block times + DistributionProportions: DistributionProportions{ + Staking: sdk.NewDecWithPrec(4, 1), // 0.4 + Incentives: sdk.NewDecWithPrec(4, 1), // 0.4 + CommunityPool: sdk.NewDecWithPrec(2, 1), // 0.2 + }, + } +} + +// validate params +func (p Params) Validate() error { + if err := validateMintDenom(p.MintDenom); err != nil { + return err + } + if err := validateInflationRateChange(p.InflationRateChange); err != nil { + return err + } + if err := validateInflationMax(p.InflationMax); err != nil { + return err + } + if err := validateInflationMin(p.InflationMin); err != nil { + return err + } + if err := validateGoalBonded(p.GoalBonded); err != nil { + return err + } + if err := validateBlocksPerYear(p.BlocksPerYear); err != nil { + return err + } + if p.InflationMax.LT(p.InflationMin) { + return fmt.Errorf( + "max inflation (%s) must be greater than or equal to min inflation (%s)", + p.InflationMax, p.InflationMin, + ) + } + return validateDistributionProportions(p.DistributionProportions) +} + +// String implements the Stringer interface. +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} + +// Implements params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyMintDenom, &p.MintDenom, validateMintDenom), + paramtypes.NewParamSetPair(KeyInflationRateChange, &p.InflationRateChange, validateInflationRateChange), + paramtypes.NewParamSetPair(KeyInflationMax, &p.InflationMax, validateInflationMax), + paramtypes.NewParamSetPair(KeyInflationMin, &p.InflationMin, validateInflationMin), + paramtypes.NewParamSetPair(KeyGoalBonded, &p.GoalBonded, validateGoalBonded), + paramtypes.NewParamSetPair(KeyBlocksPerYear, &p.BlocksPerYear, validateBlocksPerYear), + paramtypes.NewParamSetPair(KeyDistributionProportions, &p.DistributionProportions, validateDistributionProportions), + } +} + +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 err + } + + return nil +} + +func validateInflationRateChange(i interface{}) error { + v, ok := i.(sdk.Dec) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v.IsNegative() { + return fmt.Errorf("inflation rate change cannot be negative: %s", v) + } + if v.GT(sdk.OneDec()) { + return fmt.Errorf("inflation rate change too large: %s", v) + } + + return nil +} + +func validateInflationMax(i interface{}) error { + v, ok := i.(sdk.Dec) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v.IsNegative() { + return fmt.Errorf("max inflation cannot be negative: %s", v) + } + if v.GT(sdk.OneDec()) { + return fmt.Errorf("max inflation too large: %s", v) + } + + return nil +} + +func validateInflationMin(i interface{}) error { + v, ok := i.(sdk.Dec) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v.IsNegative() { + return fmt.Errorf("min inflation cannot be negative: %s", v) + } + if v.GT(sdk.OneDec()) { + return fmt.Errorf("min inflation too large: %s", v) + } + + return nil +} + +func validateGoalBonded(i interface{}) error { + v, ok := i.(sdk.Dec) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v.IsNegative() { + return fmt.Errorf("goal bonded cannot be negative: %s", v) + } + if v.GT(sdk.OneDec()) { + return fmt.Errorf("goal bonded too large: %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 +} + +func validateDistributionProportions(i interface{}) error { + v, ok := i.(DistributionProportions) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v.Staking.IsNegative() { + return errors.New("staking distribution ratio should not be negative") + } + + if v.Incentives.IsNegative() { + return errors.New("pool incentives distribution ratio should not be negative") + } + + if v.CommunityPool.IsNegative() { + return errors.New("community pool distribution ratio should not be negative") + } + + totalProportions := v.Staking.Add(v.Incentives).Add(v.CommunityPool) + + if !totalProportions.Equal(sdk.NewDec(1)) { + return errors.New("total distributions ratio should be 1") + } + + return nil +} diff --git a/x/mint/types/query.pb.go b/x/mint/types/query.pb.go new file mode 100644 index 000000000..1c9ef0a8e --- /dev/null +++ b/x/mint/types/query.pb.go @@ -0,0 +1,1200 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: mint/query.proto + +package types + +import ( + context "context" + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/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_3082aecef156f565, []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_3082aecef156f565, []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{} +} + +// QueryInflationRequest is the request type for the Query/Inflation RPC method. +type QueryInflationRequest struct { +} + +func (m *QueryInflationRequest) Reset() { *m = QueryInflationRequest{} } +func (m *QueryInflationRequest) String() string { return proto.CompactTextString(m) } +func (*QueryInflationRequest) ProtoMessage() {} +func (*QueryInflationRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_3082aecef156f565, []int{2} +} +func (m *QueryInflationRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryInflationRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryInflationRequest.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 *QueryInflationRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryInflationRequest.Merge(m, src) +} +func (m *QueryInflationRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryInflationRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryInflationRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryInflationRequest proto.InternalMessageInfo + +// QueryInflationResponse is the response type for the Query/Inflation RPC +// method. +type QueryInflationResponse struct { + // inflation is the current minting inflation value. + Inflation github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=inflation,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflation"` +} + +func (m *QueryInflationResponse) Reset() { *m = QueryInflationResponse{} } +func (m *QueryInflationResponse) String() string { return proto.CompactTextString(m) } +func (*QueryInflationResponse) ProtoMessage() {} +func (*QueryInflationResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_3082aecef156f565, []int{3} +} +func (m *QueryInflationResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryInflationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryInflationResponse.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 *QueryInflationResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryInflationResponse.Merge(m, src) +} +func (m *QueryInflationResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryInflationResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryInflationResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryInflationResponse proto.InternalMessageInfo + +// QueryAnnualProvisionsRequest is the request type for the +// Query/AnnualProvisions RPC method. +type QueryAnnualProvisionsRequest struct { +} + +func (m *QueryAnnualProvisionsRequest) Reset() { *m = QueryAnnualProvisionsRequest{} } +func (m *QueryAnnualProvisionsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAnnualProvisionsRequest) ProtoMessage() {} +func (*QueryAnnualProvisionsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_3082aecef156f565, []int{4} +} +func (m *QueryAnnualProvisionsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAnnualProvisionsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAnnualProvisionsRequest.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 *QueryAnnualProvisionsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAnnualProvisionsRequest.Merge(m, src) +} +func (m *QueryAnnualProvisionsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAnnualProvisionsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAnnualProvisionsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAnnualProvisionsRequest proto.InternalMessageInfo + +// QueryAnnualProvisionsResponse is the response type for the +// Query/AnnualProvisions RPC method. +type QueryAnnualProvisionsResponse struct { + // annual_provisions is the current minting annual provisions value. + AnnualProvisions github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=annual_provisions,json=annualProvisions,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"annual_provisions"` +} + +func (m *QueryAnnualProvisionsResponse) Reset() { *m = QueryAnnualProvisionsResponse{} } +func (m *QueryAnnualProvisionsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAnnualProvisionsResponse) ProtoMessage() {} +func (*QueryAnnualProvisionsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_3082aecef156f565, []int{5} +} +func (m *QueryAnnualProvisionsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAnnualProvisionsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAnnualProvisionsResponse.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 *QueryAnnualProvisionsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAnnualProvisionsResponse.Merge(m, src) +} +func (m *QueryAnnualProvisionsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAnnualProvisionsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAnnualProvisionsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAnnualProvisionsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "tendermint.spn.mint.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "tendermint.spn.mint.QueryParamsResponse") + proto.RegisterType((*QueryInflationRequest)(nil), "tendermint.spn.mint.QueryInflationRequest") + proto.RegisterType((*QueryInflationResponse)(nil), "tendermint.spn.mint.QueryInflationResponse") + proto.RegisterType((*QueryAnnualProvisionsRequest)(nil), "tendermint.spn.mint.QueryAnnualProvisionsRequest") + proto.RegisterType((*QueryAnnualProvisionsResponse)(nil), "tendermint.spn.mint.QueryAnnualProvisionsResponse") +} + +func init() { proto.RegisterFile("mint/query.proto", fileDescriptor_3082aecef156f565) } + +var fileDescriptor_3082aecef156f565 = []byte{ + // 456 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0x4f, 0x6b, 0x13, 0x41, + 0x18, 0xc6, 0x77, 0xfc, 0x13, 0xe8, 0x28, 0x18, 0xa7, 0xf5, 0x0f, 0xdb, 0x76, 0x5a, 0x56, 0x88, + 0x41, 0x71, 0x86, 0xc4, 0x93, 0x37, 0x0d, 0x5e, 0x04, 0x0f, 0x31, 0x47, 0x3d, 0xc8, 0x24, 0x9d, + 0xae, 0x8b, 0xd9, 0x99, 0xe9, 0xce, 0x6c, 0xb1, 0xe0, 0x41, 0x3c, 0x7b, 0x10, 0xfc, 0x14, 0x7e, + 0x10, 0xa1, 0xc7, 0x82, 0x17, 0xf1, 0x50, 0x24, 0xf1, 0x83, 0xc8, 0xbe, 0xbb, 0x9b, 0xe8, 0x66, + 0x17, 0xb5, 0xa7, 0x0c, 0xef, 0x3b, 0xf3, 0x3c, 0xbf, 0xbc, 0xcf, 0xbb, 0xb8, 0x1d, 0x47, 0xca, + 0xf1, 0x83, 0x54, 0x26, 0x47, 0xcc, 0x24, 0xda, 0x69, 0xb2, 0xee, 0xa4, 0xda, 0x93, 0x49, 0x56, + 0x67, 0xd6, 0x28, 0x96, 0x1d, 0xfc, 0x8d, 0x50, 0x87, 0x1a, 0xfa, 0x3c, 0x3b, 0xe5, 0x57, 0xfd, + 0xad, 0x50, 0xeb, 0x70, 0x2a, 0xb9, 0x30, 0x11, 0x17, 0x4a, 0x69, 0x27, 0x5c, 0xa4, 0x95, 0x2d, + 0xba, 0x57, 0x40, 0x1a, 0x74, 0xa0, 0x10, 0x6c, 0x60, 0xf2, 0x2c, 0x33, 0x1a, 0x8a, 0x44, 0xc4, + 0x76, 0x24, 0x0f, 0x52, 0x69, 0x5d, 0x30, 0xc4, 0xeb, 0x7f, 0x54, 0xad, 0xd1, 0xca, 0x4a, 0xf2, + 0x00, 0xb7, 0x0c, 0x54, 0x6e, 0xa2, 0x5d, 0xd4, 0xbd, 0xd4, 0xdf, 0x64, 0x35, 0x5c, 0x2c, 0x7f, + 0x34, 0xb8, 0x70, 0x7c, 0xba, 0xe3, 0x8d, 0x8a, 0x07, 0xc1, 0x0d, 0x7c, 0x0d, 0x14, 0x9f, 0xa8, + 0xfd, 0x29, 0x10, 0x95, 0x56, 0xfb, 0xf8, 0x7a, 0xb5, 0x51, 0xb8, 0x3d, 0xc5, 0x6b, 0x51, 0x59, + 0x04, 0xc3, 0xcb, 0x03, 0x96, 0x69, 0x7e, 0x3f, 0xdd, 0xe9, 0x84, 0x91, 0x7b, 0x95, 0x8e, 0xd9, + 0x44, 0xc7, 0x7c, 0xa2, 0x6d, 0xac, 0x6d, 0xf1, 0x73, 0xcf, 0xee, 0xbd, 0xe6, 0xee, 0xc8, 0x48, + 0xcb, 0x1e, 0xcb, 0xc9, 0x68, 0x29, 0x10, 0x50, 0xbc, 0x05, 0x3e, 0x8f, 0x94, 0x4a, 0xc5, 0x74, + 0x98, 0xe8, 0xc3, 0xc8, 0x66, 0x83, 0x29, 0x39, 0xde, 0xe2, 0xed, 0x86, 0x7e, 0x81, 0xf3, 0x02, + 0x5f, 0x15, 0xd0, 0x7b, 0x69, 0x16, 0xcd, 0x33, 0x62, 0xb5, 0x45, 0xc5, 0xa4, 0xff, 0xe5, 0x3c, + 0xbe, 0x08, 0xf6, 0xe4, 0x1d, 0xc2, 0xad, 0x7c, 0x82, 0xe4, 0x76, 0xed, 0x78, 0x57, 0xe3, 0xf2, + 0xbb, 0x7f, 0xbf, 0x98, 0xff, 0x89, 0xe0, 0xd6, 0xfb, 0xaf, 0x3f, 0x3f, 0x9d, 0xdb, 0x26, 0x9b, + 0x25, 0x1f, 0xec, 0xc3, 0x61, 0x6f, 0x2c, 0x9d, 0xe8, 0xf1, 0x3c, 0x2b, 0xf2, 0x01, 0xe1, 0xb5, + 0x45, 0x1c, 0xe4, 0x4e, 0xb3, 0x78, 0x35, 0x4c, 0xff, 0xee, 0x3f, 0xdd, 0x2d, 0x58, 0x3a, 0xc0, + 0xb2, 0x4b, 0x68, 0x2d, 0xcb, 0x22, 0x39, 0xf2, 0x19, 0xe1, 0x76, 0x35, 0x15, 0xd2, 0x6b, 0x76, + 0x6a, 0x48, 0xd8, 0xef, 0xff, 0xcf, 0x93, 0x82, 0x91, 0x01, 0x63, 0x97, 0x74, 0x6a, 0x19, 0x57, + 0xf6, 0x61, 0xf0, 0xf0, 0x78, 0x46, 0xd1, 0xc9, 0x8c, 0xa2, 0x1f, 0x33, 0x8a, 0x3e, 0xce, 0xa9, + 0x77, 0x32, 0xa7, 0xde, 0xb7, 0x39, 0xf5, 0x9e, 0xff, 0xbe, 0x1b, 0x4b, 0x0e, 0x6e, 0x8d, 0xe2, + 0x6f, 0x72, 0x55, 0xd8, 0x8f, 0x71, 0x0b, 0xbe, 0xcb, 0xfb, 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, + 0xa6, 0x41, 0x13, 0x99, 0x05, 0x04, 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) + // Inflation returns the current minting inflation value. + Inflation(ctx context.Context, in *QueryInflationRequest, opts ...grpc.CallOption) (*QueryInflationResponse, error) + // AnnualProvisions current minting annual provisions value. + AnnualProvisions(ctx context.Context, in *QueryAnnualProvisionsRequest, opts ...grpc.CallOption) (*QueryAnnualProvisionsResponse, 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, "/tendermint.spn.mint.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Inflation(ctx context.Context, in *QueryInflationRequest, opts ...grpc.CallOption) (*QueryInflationResponse, error) { + out := new(QueryInflationResponse) + err := c.cc.Invoke(ctx, "/tendermint.spn.mint.Query/Inflation", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) AnnualProvisions(ctx context.Context, in *QueryAnnualProvisionsRequest, opts ...grpc.CallOption) (*QueryAnnualProvisionsResponse, error) { + out := new(QueryAnnualProvisionsResponse) + err := c.cc.Invoke(ctx, "/tendermint.spn.mint.Query/AnnualProvisions", 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) + // Inflation returns the current minting inflation value. + Inflation(context.Context, *QueryInflationRequest) (*QueryInflationResponse, error) + // AnnualProvisions current minting annual provisions value. + AnnualProvisions(context.Context, *QueryAnnualProvisionsRequest) (*QueryAnnualProvisionsResponse, 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 (*UnimplementedQueryServer) Inflation(ctx context.Context, req *QueryInflationRequest) (*QueryInflationResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Inflation not implemented") +} +func (*UnimplementedQueryServer) AnnualProvisions(ctx context.Context, req *QueryAnnualProvisionsRequest) (*QueryAnnualProvisionsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AnnualProvisions 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: "/tendermint.spn.mint.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Inflation_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryInflationRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Inflation(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/tendermint.spn.mint.Query/Inflation", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Inflation(ctx, req.(*QueryInflationRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_AnnualProvisions_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAnnualProvisionsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AnnualProvisions(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/tendermint.spn.mint.Query/AnnualProvisions", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AnnualProvisions(ctx, req.(*QueryAnnualProvisionsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "tendermint.spn.mint.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "Inflation", + Handler: _Query_Inflation_Handler, + }, + { + MethodName: "AnnualProvisions", + Handler: _Query_AnnualProvisions_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "mint/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 (m *QueryInflationRequest) 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 *QueryInflationRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryInflationRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryInflationResponse) 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 *QueryInflationResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryInflationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Inflation.Size() + i -= size + if _, err := m.Inflation.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryAnnualProvisionsRequest) 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 *QueryAnnualProvisionsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAnnualProvisionsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryAnnualProvisionsResponse) 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 *QueryAnnualProvisionsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAnnualProvisionsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.AnnualProvisions.Size() + i -= size + if _, err := m.AnnualProvisions.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + 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 (m *QueryInflationRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryInflationResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Inflation.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryAnnualProvisionsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryAnnualProvisionsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.AnnualProvisions.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 (m *QueryInflationRequest) 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: QueryInflationRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryInflationRequest: 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 *QueryInflationResponse) 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: QueryInflationResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryInflationResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Inflation", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Inflation.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 (m *QueryAnnualProvisionsRequest) 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: QueryAnnualProvisionsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAnnualProvisionsRequest: 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 *QueryAnnualProvisionsResponse) 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: QueryAnnualProvisionsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAnnualProvisionsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AnnualProvisions", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.AnnualProvisions.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/x/mint/types/query.pb.gw.go b/x/mint/types/query.pb.gw.go new file mode 100644 index 000000000..c13ea6278 --- /dev/null +++ b/x/mint/types/query.pb.gw.go @@ -0,0 +1,283 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: mint/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_Inflation_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryInflationRequest + var metadata runtime.ServerMetadata + + msg, err := client.Inflation(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Inflation_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryInflationRequest + var metadata runtime.ServerMetadata + + msg, err := server.Inflation(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_AnnualProvisions_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAnnualProvisionsRequest + var metadata runtime.ServerMetadata + + msg, err := client.AnnualProvisions(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_AnnualProvisions_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAnnualProvisionsRequest + var metadata runtime.ServerMetadata + + msg, err := server.AnnualProvisions(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Inflation_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Inflation_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Inflation_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AnnualProvisions_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_AnnualProvisions_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AnnualProvisions_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Inflation_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Inflation_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Inflation_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AnnualProvisions_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_AnnualProvisions_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AnnualProvisions_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "mint", "v1beta1", "params"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_Inflation_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "mint", "v1beta1", "inflation"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_AnnualProvisions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "mint", "v1beta1", "annual_provisions"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_Inflation_0 = runtime.ForwardResponseMessage + + forward_Query_AnnualProvisions_0 = runtime.ForwardResponseMessage +) From ba0880782572d9723d33eb79fa57ef29cd4c269c Mon Sep 17 00:00:00 2001 From: Giuseppe Natale <12249307+giunatale@users.noreply.github.com> Date: Fri, 13 May 2022 05:38:32 +0200 Subject: [PATCH 2/5] sim --- x/mint/simulation/params.go | 16 ++++++++++++---- x/mint/simulation/params_test.go | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/x/mint/simulation/params.go b/x/mint/simulation/params.go index b75b0fc70..62ed293e5 100644 --- a/x/mint/simulation/params.go +++ b/x/mint/simulation/params.go @@ -13,10 +13,11 @@ import ( ) const ( - keyInflationRateChange = "InflationRateChange" - keyInflationMax = "InflationMax" - keyInflationMin = "InflationMin" - keyGoalBonded = "GoalBonded" + keyInflationRateChange = "InflationRateChange" + keyInflationMax = "InflationMax" + keyInflationMin = "InflationMin" + keyGoalBonded = "GoalBonded" + keyDistributionProportions = "DistributionProportions" ) // ParamChanges defines the parameters that can be modified by param change proposals @@ -43,5 +44,12 @@ func ParamChanges(r *rand.Rand) []simtypes.ParamChange { return fmt.Sprintf("\"%s\"", GenGoalBonded(r)) }, ), + simulation.NewSimParamChange(types.ModuleName, keyDistributionProportions, + func(r *rand.Rand) string { + proportions := GenDistributionProportions(r) + return fmt.Sprintf("\"distribution_proportions\":{\"staking\":\"%s\",\"incentives\":\"%s\",\"community_pool\":\"%s\"}", + proportions.Staking.String(), proportions.Incentives.String(), proportions.CommunityPool.String()) + }, + ), } } diff --git a/x/mint/simulation/params_test.go b/x/mint/simulation/params_test.go index 2d7d97235..14b4a4dfe 100644 --- a/x/mint/simulation/params_test.go +++ b/x/mint/simulation/params_test.go @@ -23,10 +23,11 @@ func TestParamChangest(t *testing.T) { {"mint/InflationMax", "InflationMax", "\"0.200000000000000000\"", "mint"}, {"mint/InflationMin", "InflationMin", "\"0.070000000000000000\"", "mint"}, {"mint/GoalBonded", "GoalBonded", "\"0.670000000000000000\"", "mint"}, + {"mint/DistributionProportions", "DistributionProportions", "\"distribution_proportions\":{\"staking\":\"0.250000000000000000\",\"incentives\":\"0.210000000000000000\",\"community_pool\":\"0.540000000000000000\"}", "mint"}, } paramChanges := simulation.ParamChanges(r) - require.Len(t, paramChanges, 4) + require.Len(t, paramChanges, 5) for i, p := range paramChanges { require.Equal(t, expected[i].composedKey, p.ComposedKey()) From 4b0bb09663a06cd410e2b1d95787facdcfbdd171 Mon Sep 17 00:00:00 2001 From: Giuseppe Natale <12249307+giunatale@users.noreply.github.com> Date: Fri, 13 May 2022 12:21:16 +0200 Subject: [PATCH 3/5] add default values --- config.yml | 4 ++++ localnet/genesis_template.json | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config.yml b/config.yml index fea971169..de60891cd 100644 --- a/config.yml +++ b/config.yml @@ -43,6 +43,10 @@ genesis: mint: params: mint_denom: "uspn" + distribution_proportions: + staking: "0.400000000000000000" + incentives: "0.400000000000000000" + community_pool: "0.200000000000000000" launch: params: revertDelay: "5" diff --git a/localnet/genesis_template.json b/localnet/genesis_template.json index df82d189f..6b8a35365 100644 --- a/localnet/genesis_template.json +++ b/localnet/genesis_template.json @@ -309,7 +309,12 @@ "inflation_max": "0.200000000000000000", "inflation_min": "0.070000000000000000", "inflation_rate_change": "0.130000000000000000", - "mint_denom": "uspn" + "mint_denom": "uspn", + "distribution_proportions": { + "staking": "0.400000000000000000", + "incentives": "0.400000000000000000", + "community_pool": "0.200000000000000000", + } } }, "monitoringc": { From 6943448868125042470e76642c853f30b6fe38f1 Mon Sep 17 00:00:00 2001 From: Giuseppe Natale <12249307+giunatale@users.noreply.github.com> Date: Fri, 13 May 2022 12:21:25 +0200 Subject: [PATCH 4/5] fix sim param change --- x/mint/simulation/params.go | 2 +- x/mint/simulation/params_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x/mint/simulation/params.go b/x/mint/simulation/params.go index 62ed293e5..717a1fb80 100644 --- a/x/mint/simulation/params.go +++ b/x/mint/simulation/params.go @@ -47,7 +47,7 @@ func ParamChanges(r *rand.Rand) []simtypes.ParamChange { simulation.NewSimParamChange(types.ModuleName, keyDistributionProportions, func(r *rand.Rand) string { proportions := GenDistributionProportions(r) - return fmt.Sprintf("\"distribution_proportions\":{\"staking\":\"%s\",\"incentives\":\"%s\",\"community_pool\":\"%s\"}", + return fmt.Sprintf("{\"staking\":\"%s\",\"incentives\":\"%s\",\"community_pool\":\"%s\"}", proportions.Staking.String(), proportions.Incentives.String(), proportions.CommunityPool.String()) }, ), diff --git a/x/mint/simulation/params_test.go b/x/mint/simulation/params_test.go index 14b4a4dfe..ab18e9a67 100644 --- a/x/mint/simulation/params_test.go +++ b/x/mint/simulation/params_test.go @@ -23,7 +23,7 @@ func TestParamChangest(t *testing.T) { {"mint/InflationMax", "InflationMax", "\"0.200000000000000000\"", "mint"}, {"mint/InflationMin", "InflationMin", "\"0.070000000000000000\"", "mint"}, {"mint/GoalBonded", "GoalBonded", "\"0.670000000000000000\"", "mint"}, - {"mint/DistributionProportions", "DistributionProportions", "\"distribution_proportions\":{\"staking\":\"0.250000000000000000\",\"incentives\":\"0.210000000000000000\",\"community_pool\":\"0.540000000000000000\"}", "mint"}, + {"mint/DistributionProportions", "DistributionProportions", "{\"staking\":\"0.250000000000000000\",\"incentives\":\"0.210000000000000000\",\"community_pool\":\"0.540000000000000000\"}", "mint"}, } paramChanges := simulation.ParamChanges(r) From 381e6b300772799998272febe419c414decc8853 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 16 May 2022 08:45:40 -0400 Subject: [PATCH 5/5] format and lint fix --- x/campaign/module_simulation.go | 3 ++- x/campaign/types/shares_test.go | 3 ++- x/mint/keeper/querier.go | 2 +- x/mint/module.go | 5 +---- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/x/campaign/module_simulation.go b/x/campaign/module_simulation.go index e5a1146b9..90ab5cd35 100644 --- a/x/campaign/module_simulation.go +++ b/x/campaign/module_simulation.go @@ -171,10 +171,11 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp weightMsgUnredeemVouchers, campaignsim.SimulateMsgUnredeemVouchers(am.accountKeeper, am.bankKeeper, am.keeper), ), + // disabled: https://github.com/tendermint/spn/issues/774 // simulation.NewWeightedOperation( // weightMsgAddVestingOptions, // campaignsim.SimulateMsgAddVestingOptions(am.accountKeeper, am.bankKeeper, am.profileKeeper, am.keeper), - //), + // ), } } diff --git a/x/campaign/types/shares_test.go b/x/campaign/types/shares_test.go index dd61b3e99..f792ad26d 100644 --- a/x/campaign/types/shares_test.go +++ b/x/campaign/types/shares_test.go @@ -2,9 +2,10 @@ package types_test import ( "fmt" - "github.com/tendermint/spn/testutil/sample" "testing" + "github.com/tendermint/spn/testutil/sample" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" diff --git a/x/mint/keeper/querier.go b/x/mint/keeper/querier.go index e0f973f29..1248829d9 100644 --- a/x/mint/keeper/querier.go +++ b/x/mint/keeper/querier.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - + "github.com/tendermint/spn/x/mint/types" ) diff --git a/x/mint/module.go b/x/mint/module.go index 91bbbc00a..41770eba5 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -35,8 +35,6 @@ type AppModuleBasic struct { cdc codec.Codec } -var _ module.AppModuleBasic = AppModuleBasic{} - // Name returns the mint module's name. func (AppModuleBasic) Name() string { return types.ModuleName @@ -71,8 +69,7 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the mint module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) - + types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) // nolint } // GetTxCmd returns no root tx command for the mint module.