diff --git a/app/app.go b/app/app.go index d0b2b293..6dd7a511 100644 --- a/app/app.go +++ b/app/app.go @@ -49,6 +49,9 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov" 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" @@ -128,9 +131,6 @@ import ( kavadistclient "github.com/kava-labs/kava/x/kavadist/client" kavadistkeeper "github.com/kava-labs/kava/x/kavadist/keeper" kavadisttypes "github.com/kava-labs/kava/x/kavadist/types" - "github.com/kava-labs/kava/x/kavamint" - kavamintkeeper "github.com/kava-labs/kava/x/kavamint/keeper" - kavaminttypes "github.com/kava-labs/kava/x/kavamint/types" "github.com/kava-labs/kava/x/liquid" liquidkeeper "github.com/kava-labs/kava/x/liquid/keeper" liquidtypes "github.com/kava-labs/kava/x/liquid/types" @@ -208,7 +208,7 @@ var ( liquid.AppModuleBasic{}, earn.AppModuleBasic{}, router.AppModuleBasic{}, - kavamint.AppModuleBasic{}, + mint.AppModuleBasic{}, community.AppModuleBasic{}, ) @@ -236,7 +236,7 @@ var ( liquidtypes.ModuleAccountName: {authtypes.Minter, authtypes.Burner}, earntypes.ModuleAccountName: nil, kavadisttypes.FundModuleAccount: nil, - kavaminttypes.ModuleAccountName: {authtypes.Minter}, + minttypes.ModuleName: {authtypes.Minter}, communitytypes.ModuleName: nil, } ) @@ -308,7 +308,7 @@ type App struct { liquidKeeper liquidkeeper.Keeper earnKeeper earnkeeper.Keeper routerKeeper routerkeeper.Keeper - kavamintKeeper kavamintkeeper.Keeper + mintKeeper mintkeeper.Keeper communityKeeper communitykeeper.Keeper // make scoped keepers public for test purposes @@ -363,7 +363,7 @@ func NewApp( issuancetypes.StoreKey, bep3types.StoreKey, pricefeedtypes.StoreKey, swaptypes.StoreKey, cdptypes.StoreKey, hardtypes.StoreKey, committeetypes.StoreKey, incentivetypes.StoreKey, evmutiltypes.StoreKey, - savingstypes.StoreKey, earntypes.StoreKey, kavaminttypes.StoreKey, + savingstypes.StoreKey, earntypes.StoreKey, minttypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -408,7 +408,7 @@ func NewApp( evmSubspace := app.paramsKeeper.Subspace(evmtypes.ModuleName) evmutilSubspace := app.paramsKeeper.Subspace(evmutiltypes.ModuleName) earnSubspace := app.paramsKeeper.Subspace(earntypes.ModuleName) - kavamintSubspace := app.paramsKeeper.Subspace(kavaminttypes.ModuleName) + mintSubspace := app.paramsKeeper.Subspace(minttypes.ModuleName) bApp.SetParamStore( app.paramsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable()), @@ -628,15 +628,14 @@ func NewApp( app.loadBlockedMaccAddrs(), ) - app.kavamintKeeper = kavamintkeeper.NewKeeper( + app.mintKeeper = mintkeeper.NewKeeper( appCodec, - keys[kavaminttypes.StoreKey], - kavamintSubspace, + keys[minttypes.StoreKey], + mintSubspace, app.stakingKeeper, app.accountKeeper, app.bankKeeper, - authtypes.FeeCollectorName, // same fee collector as vanilla sdk - communitytypes.ModuleAccountName, + authtypes.FeeCollectorName, ) app.incentiveKeeper = incentivekeeper.NewKeeper( @@ -652,7 +651,7 @@ func NewApp( &savingsKeeper, &app.liquidKeeper, &earnKeeper, - app.kavamintKeeper, + app.mintKeeper, app.distrKeeper, app.pricefeedKeeper, ) @@ -758,7 +757,7 @@ func NewApp( liquid.NewAppModule(app.liquidKeeper), earn.NewAppModule(app.earnKeeper, app.accountKeeper, app.bankKeeper), router.NewAppModule(app.routerKeeper), - kavamint.NewAppModule(appCodec, app.kavamintKeeper, app.accountKeeper), + mint.NewAppModule(appCodec, app.mintKeeper, app.accountKeeper), community.NewAppModule(app.communityKeeper, app.accountKeeper), ) @@ -771,8 +770,7 @@ func NewApp( // Committee begin blocker changes module params by enacting proposals. // Run before to ensure params are updated together before state changes. committeetypes.ModuleName, - // Kavamint must be registered before distribution module in order to generate block staking rewards. - kavaminttypes.ModuleName, + minttypes.ModuleName, distrtypes.ModuleName, // During begin block slashing happens after distr.BeginBlocker so that // there is nothing left over in the validator fee pool, so as to keep the @@ -851,7 +849,7 @@ func NewApp( liquidtypes.ModuleName, earntypes.ModuleName, routertypes.ModuleName, - kavaminttypes.ModuleName, + minttypes.ModuleName, communitytypes.ModuleName, ) @@ -864,7 +862,7 @@ func NewApp( stakingtypes.ModuleName, slashingtypes.ModuleName, // iterates over validators, run after staking govtypes.ModuleName, - kavaminttypes.ModuleName, + minttypes.ModuleName, ibchost.ModuleName, evidencetypes.ModuleName, authz.ModuleName, diff --git a/app/test_common.go b/app/test_common.go index e4d7de40..932301e4 100644 --- a/app/test_common.go +++ b/app/test_common.go @@ -18,6 +18,8 @@ import ( crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper" distkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" + mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" @@ -41,8 +43,6 @@ import ( incentivekeeper "github.com/kava-labs/kava/x/incentive/keeper" issuancekeeper "github.com/kava-labs/kava/x/issuance/keeper" kavadistkeeper "github.com/kava-labs/kava/x/kavadist/keeper" - kavamintkeeper "github.com/kava-labs/kava/x/kavamint/keeper" - kavaminttypes "github.com/kava-labs/kava/x/kavamint/types" liquidkeeper "github.com/kava-labs/kava/x/liquid/keeper" pricefeedkeeper "github.com/kava-labs/kava/x/pricefeed/keeper" routerkeeper "github.com/kava-labs/kava/x/router/keeper" @@ -92,6 +92,7 @@ func NewTestAppFromSealed() TestApp { // nolint func (tApp TestApp) GetAccountKeeper() authkeeper.AccountKeeper { return tApp.accountKeeper } func (tApp TestApp) GetBankKeeper() bankkeeper.Keeper { return tApp.bankKeeper } +func (tApp TestApp) GetMintKeeper() mintkeeper.Keeper { return tApp.mintKeeper } func (tApp TestApp) GetStakingKeeper() stakingkeeper.Keeper { return tApp.stakingKeeper } func (tApp TestApp) GetSlashingKeeper() slashingkeeper.Keeper { return tApp.slashingKeeper } func (tApp TestApp) GetDistrKeeper() distkeeper.Keeper { return tApp.distrKeeper } @@ -116,7 +117,6 @@ func (tApp TestApp) GetFeeMarketKeeper() feemarketkeeper.Keeper { return tApp.fe func (tApp TestApp) GetLiquidKeeper() liquidkeeper.Keeper { return tApp.liquidKeeper } func (tApp TestApp) GetEarnKeeper() earnkeeper.Keeper { return tApp.earnKeeper } func (tApp TestApp) GetRouterKeeper() routerkeeper.Keeper { return tApp.routerKeeper } -func (tApp TestApp) GetKavamintKeeper() kavamintkeeper.Keeper { return tApp.kavamintKeeper } func (tApp TestApp) GetCommunityKeeper() communitykeeper.Keeper { return tApp.communityKeeper } // LegacyAmino returns the app's amino codec. @@ -203,11 +203,11 @@ func (tApp TestApp) GetModuleAccountBalance(ctx sdk.Context, moduleName string, // FundAccount is a utility function that funds an account by minting and sending the coins to the address. func (tApp TestApp) FundAccount(ctx sdk.Context, addr sdk.AccAddress, amounts sdk.Coins) error { - if err := tApp.bankKeeper.MintCoins(ctx, kavaminttypes.ModuleAccountName, amounts); err != nil { + if err := tApp.bankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil { return err } - return tApp.bankKeeper.SendCoinsFromModuleToAccount(ctx, kavaminttypes.ModuleAccountName, addr, amounts) + return tApp.bankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, amounts) } // NewQueryServerTestHelper creates a new QueryServiceTestHelper that wraps the provided sdk.Context. @@ -217,11 +217,11 @@ func (tApp TestApp) NewQueryServerTestHelper(ctx sdk.Context) *baseapp.QueryServ // FundModuleAccount is a utility function that funds a module account by minting and sending the coins to the address. func (tApp TestApp) FundModuleAccount(ctx sdk.Context, recipientMod string, amounts sdk.Coins) error { - if err := tApp.bankKeeper.MintCoins(ctx, kavaminttypes.ModuleAccountName, amounts); err != nil { + if err := tApp.bankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil { return err } - return tApp.bankKeeper.SendCoinsFromModuleToModule(ctx, kavaminttypes.ModuleAccountName, recipientMod, amounts) + return tApp.bankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, recipientMod, amounts) } // CreateNewUnbondedValidator creates a new validator in the staking module. diff --git a/ci/env/kava-internal-testnet/genesis.json b/ci/env/kava-internal-testnet/genesis.json index cd495815..f88e25a1 100644 --- a/ci/env/kava-internal-testnet/genesis.json +++ b/ci/env/kava-internal-testnet/genesis.json @@ -2465,14 +2465,21 @@ }, "previous_block_time": "1970-01-01T00:00:01Z" }, - "kavamint": { - "params": { - "community_pool_inflation": "0.200000000000000000", - "staking_rewards_apy": "0.150000000000000000" - }, - "previous_block_time": "2022-05-25T17:00:00Z" - }, "liquid": {}, + "mint": { + "minter": { + "inflation": "0.130000000000000000", + "annual_provisions": "0.000000000000000000" + }, + "params": { + "mint_denom": "ukava", + "inflation_rate_change": "0.130000000000000000", + "inflation_max": "0.750000000000000000", + "inflation_min": "0.750000000000000000", + "goal_bonded": "0.670000000000000000", + "blocks_per_year": "6311520" + } + }, "params": null, "pricefeed": { "params": { diff --git a/client/docs/config.json b/client/docs/config.json index 0e692c8a..6319e6f6 100644 --- a/client/docs/config.json +++ b/client/docs/config.json @@ -216,23 +216,6 @@ ] } }, - { - "url": "./out/swagger/kava/kavamint/v1beta1/query.swagger.json", - "tags": { - "rename": { - "Query": "Kavamint" - } - }, - "operationIds": { - "rename": [ - { - "type": "regex", - "from": "(.*)", - "to": "Kavamint$1" - } - ] - } - }, { "url": "./client/docs/cosmos-swagger.yml", "dereference": { diff --git a/client/docs/swagger-ui/swagger.yaml b/client/docs/swagger-ui/swagger.yaml index 52c8a009..0b6c9e8d 100644 --- a/client/docs/swagger-ui/swagger.yaml +++ b/client/docs/swagger-ui/swagger.yaml @@ -12033,101 +12033,6 @@ paths: format: byte tags: - Savings - /kava/kavamint/v1beta1/inflation: - get: - summary: >- - Inflation queries x/kavamint for the overall cumulative inflation rate - of KAVA. - operationId: KavamintInflation - responses: - '200': - description: A successful response. - schema: - type: object - properties: - inflation: - type: string - title: |- - inflation is the current minting inflation value. - example "0.990000000000000000" - 99% inflation - description: >- - QueryInflationResponse is the response type for the - Query/Inflation RPC method. - default: - description: An unexpected error response. - schema: - type: object - properties: - error: - type: string - code: - type: integer - format: int32 - message: - type: string - details: - type: array - items: - type: object - properties: - type_url: - type: string - value: - type: string - format: byte - tags: - - Kavamint - /kava/kavamint/v1beta1/params: - get: - summary: Params queries the parameters of x/kavamint module. - operationId: KavamintParams - responses: - '200': - description: A successful response. - schema: - type: object - properties: - params: - type: object - properties: - community_pool_inflation: - type: string - description: >- - yearly inflation of total token supply minted to the - community pool. - staking_rewards_apy: - type: string - description: >- - yearly inflation of bonded tokens minted for staking - rewards to validators. - title: Params wraps the governance parameters for the kavamint module - description: >- - QueryParamsResponse defines the response type for querying - x/kavamint parameters. - default: - description: An unexpected error response. - schema: - type: object - properties: - error: - type: string - code: - type: integer - format: int32 - message: - type: string - details: - type: array - items: - type: object - properties: - type_url: - type: string - value: - type: string - format: byte - tags: - - Kavamint /node_info: get: description: Information about the connected node @@ -57766,49 +57671,6 @@ definitions: description: >- TotalSupplyResponse defines the response type for the Query/TotalSupply method. - kava.kavamint.v1beta1.Params: - type: object - properties: - community_pool_inflation: - type: string - description: yearly inflation of total token supply minted to the community pool. - staking_rewards_apy: - type: string - description: >- - yearly inflation of bonded tokens minted for staking rewards to - validators. - title: Params wraps the governance parameters for the kavamint module - kava.kavamint.v1beta1.QueryInflationResponse: - type: object - properties: - inflation: - type: string - title: |- - inflation is the current minting inflation value. - example "0.990000000000000000" - 99% inflation - description: >- - QueryInflationResponse is the response type for the Query/Inflation RPC - method. - kava.kavamint.v1beta1.QueryParamsResponse: - type: object - properties: - params: - type: object - properties: - community_pool_inflation: - type: string - description: >- - yearly inflation of total token supply minted to the community - pool. - staking_rewards_apy: - type: string - description: >- - yearly inflation of bonded tokens minted for staking rewards to - validators. - title: Params wraps the governance parameters for the kavamint module - description: >- - QueryParamsResponse defines the response type for querying x/kavamint - parameters. CheckTxResult: type: object properties: diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 0b11e3d6..9432d092 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -417,20 +417,6 @@ - [Query](#kava.kavadist.v1beta1.Query) -- [kava/kavamint/v1beta1/kavamint.proto](#kava/kavamint/v1beta1/kavamint.proto) - - [Params](#kava.kavamint.v1beta1.Params) - -- [kava/kavamint/v1beta1/genesis.proto](#kava/kavamint/v1beta1/genesis.proto) - - [GenesisState](#kava.kavamint.v1beta1.GenesisState) - -- [kava/kavamint/v1beta1/query.proto](#kava/kavamint/v1beta1/query.proto) - - [QueryInflationRequest](#kava.kavamint.v1beta1.QueryInflationRequest) - - [QueryInflationResponse](#kava.kavamint.v1beta1.QueryInflationResponse) - - [QueryParamsRequest](#kava.kavamint.v1beta1.QueryParamsRequest) - - [QueryParamsResponse](#kava.kavamint.v1beta1.QueryParamsResponse) - - - [Query](#kava.kavamint.v1beta1.Query) - - [kava/liquid/v1beta1/query.proto](#kava/liquid/v1beta1/query.proto) - [QueryDelegatedBalanceRequest](#kava.liquid.v1beta1.QueryDelegatedBalanceRequest) - [QueryDelegatedBalanceResponse](#kava.liquid.v1beta1.QueryDelegatedBalanceResponse) @@ -5850,147 +5836,6 @@ Query defines the gRPC querier service. - -

Top

- -## kava/kavamint/v1beta1/kavamint.proto - - - - - -### Params -Params wraps the governance parameters for the kavamint module - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `community_pool_inflation` | [string](#string) | | yearly inflation of total token supply minted to the community pool. | -| `staking_rewards_apy` | [string](#string) | | yearly inflation of bonded tokens minted for staking rewards to validators. | - - - - - - - - - - - - - - - - -

Top

- -## kava/kavamint/v1beta1/genesis.proto - - - - - -### GenesisState -GenesisState defines the kavamint module's genesis state. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `params` | [Params](#kava.kavamint.v1beta1.Params) | | Params defines all the parameters of the module. | -| `previous_block_time` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | PreviousBlockTime holds the last last time tokens were minted. On first block, tokens will be minted for total number of seconds passed since this time. | - - - - - - - - - - - - - - - - -

Top

- -## kava/kavamint/v1beta1/query.proto - - - - - -### QueryInflationRequest -QueryInflationRequest is the request type for the Query/Inflation RPC method. - - - - - - - - -### QueryInflationResponse -QueryInflationResponse is the response type for the Query/Inflation RPC method. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `inflation` | [string](#string) | | inflation is the current minting inflation value. example "0.990000000000000000" - 99% inflation | - - - - - - - - -### QueryParamsRequest -QueryParamsRequest defines the request type for querying x/kavamint parameters. - - - - - - - - -### QueryParamsResponse -QueryParamsResponse defines the response type for querying x/kavamint parameters. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `params` | [Params](#kava.kavamint.v1beta1.Params) | | | - - - - - - - - - - - - - - -### Query -Query defines the gRPC querier service for kavamint. - -| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | -| ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `Params` | [QueryParamsRequest](#kava.kavamint.v1beta1.QueryParamsRequest) | [QueryParamsResponse](#kava.kavamint.v1beta1.QueryParamsResponse) | Params queries the parameters of x/kavamint module. | GET|/kava/kavamint/v1beta1/params| -| `Inflation` | [QueryInflationRequest](#kava.kavamint.v1beta1.QueryInflationRequest) | [QueryInflationResponse](#kava.kavamint.v1beta1.QueryInflationResponse) | Inflation queries x/kavamint for the overall cumulative inflation rate of KAVA. | GET|/kava/kavamint/v1beta1/inflation| - - - - -

Top

diff --git a/proto/kava/kavamint/v1beta1/genesis.proto b/proto/kava/kavamint/v1beta1/genesis.proto deleted file mode 100644 index f7bba2eb..00000000 --- a/proto/kava/kavamint/v1beta1/genesis.proto +++ /dev/null @@ -1,23 +0,0 @@ -syntax = "proto3"; -package kava.kavamint.v1beta1; - -import "gogoproto/gogo.proto"; -import "google/protobuf/timestamp.proto"; -import "kava/kavamint/v1beta1/kavamint.proto"; - -option go_package = "github.com/kava-labs/kava/x/kavamint/types"; - -// GenesisState defines the kavamint module's genesis state. -message GenesisState { - option (gogoproto.goproto_getters) = false; - - // Params defines all the parameters of the module. - Params params = 1 [(gogoproto.nullable) = false]; - - // PreviousBlockTime holds the last last time tokens were minted. - // On first block, tokens will be minted for total number of seconds passed since this time. - google.protobuf.Timestamp previous_block_time = 2 [ - (gogoproto.stdtime) = true, - (gogoproto.nullable) = false - ]; -} diff --git a/proto/kava/kavamint/v1beta1/kavamint.proto b/proto/kava/kavamint/v1beta1/kavamint.proto deleted file mode 100644 index 98fb10a6..00000000 --- a/proto/kava/kavamint/v1beta1/kavamint.proto +++ /dev/null @@ -1,26 +0,0 @@ -syntax = "proto3"; -package kava.kavamint.v1beta1; - -import "cosmos_proto/cosmos.proto"; -import "gogoproto/gogo.proto"; - -option go_package = "github.com/kava-labs/kava/x/kavamint/types"; - -// Params wraps the governance parameters for the kavamint module -message Params { - option (gogoproto.goproto_stringer) = false; - option (gogoproto.goproto_getters) = false; - - // yearly inflation of total token supply minted to the community pool. - string community_pool_inflation = 1 [ - (cosmos_proto.scalar) = "cosmos.Dec", - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", - (gogoproto.nullable) = false - ]; - // yearly inflation of bonded tokens minted for staking rewards to validators. - string staking_rewards_apy = 2 [ - (cosmos_proto.scalar) = "cosmos.Dec", - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", - (gogoproto.nullable) = false - ]; -} diff --git a/proto/kava/kavamint/v1beta1/query.proto b/proto/kava/kavamint/v1beta1/query.proto deleted file mode 100644 index 36aaa0fe..00000000 --- a/proto/kava/kavamint/v1beta1/query.proto +++ /dev/null @@ -1,44 +0,0 @@ -syntax = "proto3"; -package kava.kavamint.v1beta1; - -import "cosmos_proto/cosmos.proto"; -import "gogoproto/gogo.proto"; -import "google/api/annotations.proto"; -import "kava/kavamint/v1beta1/kavamint.proto"; - -option go_package = "github.com/kava-labs/kava/x/kavamint/types"; - -// Query defines the gRPC querier service for kavamint. -service Query { - // Params queries the parameters of x/kavamint module. - rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { - option (google.api.http).get = "/kava/kavamint/v1beta1/params"; - } - - // Inflation queries x/kavamint for the overall cumulative inflation rate of KAVA. - rpc Inflation(QueryInflationRequest) returns (QueryInflationResponse) { - option (google.api.http).get = "/kava/kavamint/v1beta1/inflation"; - } -} - -// QueryParamsRequest defines the request type for querying x/kavamint parameters. -message QueryParamsRequest {} - -// QueryParamsResponse defines the response type for querying x/kavamint parameters. -message QueryParamsResponse { - 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. - // example "0.990000000000000000" - 99% inflation - string inflation = 1 [ - (cosmos_proto.scalar) = "cosmos.Dec", - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", - (gogoproto.nullable) = false - ]; -} diff --git a/x/evmutil/testutil/suite.go b/x/evmutil/testutil/suite.go index 79fad593..3c1857e4 100644 --- a/x/evmutil/testutil/suite.go +++ b/x/evmutil/testutil/suite.go @@ -38,7 +38,6 @@ import ( "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/evmutil/keeper" "github.com/kava-labs/kava/x/evmutil/types" - kavaminttypes "github.com/kava-labs/kava/x/kavamint/types" ) type Suite struct { @@ -348,14 +347,7 @@ func (suite *Suite) SendTx( } func (suite *Suite) MintFeeCollector(coins sdk.Coins) { - err := suite.App.GetBankKeeper().MintCoins(suite.Ctx, kavaminttypes.ModuleAccountName, coins) - suite.Require().NoError(err) - err = suite.App.GetBankKeeper().SendCoinsFromModuleToModule( - suite.Ctx, - kavaminttypes.ModuleAccountName, - authtypes.FeeCollectorName, - coins, - ) + err := suite.App.FundModuleAccount(suite.Ctx, authtypes.FeeCollectorName, coins) suite.Require().NoError(err) } diff --git a/x/incentive/keeper/keeper.go b/x/incentive/keeper/keeper.go index 53f98332..dd9e9e06 100644 --- a/x/incentive/keeper/keeper.go +++ b/x/incentive/keeper/keeper.go @@ -26,7 +26,7 @@ type Keeper struct { earnKeeper types.EarnKeeper // Keepers used for APY queries - kavamintKeeper types.KavamintKeeper + mintKeeper types.MintKeeper distrKeeper types.DistrKeeper pricefeedKeeper types.PricefeedKeeper } @@ -36,7 +36,7 @@ func NewKeeper( cdc codec.Codec, key sdk.StoreKey, paramstore types.ParamSubspace, bk types.BankKeeper, cdpk types.CdpKeeper, hk types.HardKeeper, ak types.AccountKeeper, stk types.StakingKeeper, swpk types.SwapKeeper, svk types.SavingsKeeper, lqk types.LiquidKeeper, ek types.EarnKeeper, - kmk types.KavamintKeeper, dk types.DistrKeeper, pfk types.PricefeedKeeper, + mk types.MintKeeper, dk types.DistrKeeper, pfk types.PricefeedKeeper, ) Keeper { if !paramstore.HasKeyTable() { paramstore = paramstore.WithKeyTable(types.ParamKeyTable()) @@ -56,7 +56,7 @@ func NewKeeper( liquidKeeper: lqk, earnKeeper: ek, - kavamintKeeper: kmk, + mintKeeper: mk, distrKeeper: dk, pricefeedKeeper: pfk, } diff --git a/x/incentive/keeper/msg_server_earn_test.go b/x/incentive/keeper/msg_server_earn_test.go index 94827422..aab483f5 100644 --- a/x/incentive/keeper/msg_server_earn_test.go +++ b/x/incentive/keeper/msg_server_earn_test.go @@ -8,11 +8,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/distribution" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/mint" earntypes "github.com/kava-labs/kava/x/earn/types" "github.com/kava-labs/kava/x/incentive" "github.com/kava-labs/kava/x/incentive/testutil" "github.com/kava-labs/kava/x/incentive/types" - "github.com/kava-labs/kava/x/kavamint" liquidtypes "github.com/kava-labs/kava/x/liquid/types" ) @@ -53,7 +53,7 @@ func (suite *HandlerTestSuite) TestEarnLiquidClaim() { // bk := suite.App.GetBankKeeper() sk := suite.App.GetStakingKeeper() lq := suite.App.GetLiquidKeeper() - mk := suite.App.GetKavamintKeeper() + mk := suite.App.GetMintKeeper() dk := suite.App.GetDistrKeeper() ik := suite.App.GetIncentiveKeeper() @@ -62,9 +62,9 @@ func (suite *HandlerTestSuite) TestEarnLiquidClaim() { suite.Require().True(found) suite.Require().Equal("bkava", period.CollateralType) - // Ensure nonzero staking APY + // Use ukava for mint denom mParams := mk.GetParams(suite.Ctx) - mParams.StakingRewardsApy = sdk.NewDecWithPrec(20, 2) + mParams.MintDenom = "ukava" mk.SetParams(suite.Ctx, mParams) bkavaDenom1 := lq.GetLiquidStakingTokenDenom(valAddr1) @@ -138,7 +138,10 @@ func (suite *HandlerTestSuite) TestEarnLiquidClaim() { WithBlockTime(suite.Ctx.BlockTime().Add(7 * time.Second)) // Mint tokens - kavamint.BeginBlocker(suite.Ctx, suite.App.GetKavamintKeeper()) + mint.BeginBlocker( + suite.Ctx, + suite.App.GetMintKeeper(), + ) // Distribute to validators, block needs votes distribution.BeginBlocker( suite.Ctx, @@ -163,10 +166,10 @@ func (suite *HandlerTestSuite) TestEarnLiquidClaim() { // Zero rewards since this block is the same as the block it was last claimed // This needs to run **after** staking rewards are minted/distributed in - // x/kavamint + x/distribution but **before** the x/incentive BeginBlocker. + // x/mint + x/distribution but **before** the x/incentive BeginBlocker. // Order of operations: - // 1. x/kavamint + x/distribution BeginBlocker + // 1. x/mint + x/distribution BeginBlocker // 2. CalculateDelegationRewards // 3. x/incentive BeginBlocker to claim staking rewards delegationRewards := dk.CalculateDelegationRewards(suite.Ctx, validator1, delegation, endingPeriod) diff --git a/x/incentive/keeper/querier.go b/x/incentive/keeper/querier.go index d5dbae1a..f94352ee 100644 --- a/x/incentive/keeper/querier.go +++ b/x/incentive/keeper/querier.go @@ -422,8 +422,18 @@ func queryGetAPYs(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerie // GetStakingAPR returns the total APR for staking and incentive rewards func GetStakingAPR(ctx sdk.Context, k Keeper, params types.Params) (sdk.Dec, error) { - // Get staking APR - stakingAPR := k.kavamintKeeper.GetStakingApy(ctx) + // Get staking APR + incentive APR + inflationRate := k.mintKeeper.GetMinter(ctx).Inflation + communityTax := k.distrKeeper.GetCommunityTax(ctx) + + bondedTokens := k.stakingKeeper.TotalBondedTokens(ctx) + circulatingSupply := k.bankKeeper.GetSupply(ctx, types.BondDenom) + + // Staking APR = (Inflation Rate * (1 - Community Tax)) / (Bonded Tokens / Circulating Supply) + stakingAPR := inflationRate. + Mul(sdk.OneDec().Sub(communityTax)). + Quo(bondedTokens.ToDec(). + Quo(circulatingSupply.Amount.ToDec())) // Get incentive APR bkavaRewardPeriod, found := params.EarnRewardPeriods.GetMultiRewardPeriod(liquidtypes.DefaultDerivativeDenom) diff --git a/x/incentive/keeper/querier_test.go b/x/incentive/keeper/querier_test.go index cfe88d91..2076fbff 100644 --- a/x/incentive/keeper/querier_test.go +++ b/x/incentive/keeper/querier_test.go @@ -5,6 +5,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" pricefeedtypes "github.com/kava-labs/kava/x/pricefeed/types" earntypes "github.com/kava-labs/kava/x/earn/types" @@ -29,18 +30,6 @@ func (suite *QuerierTestSuite) TestGetStakingAPR() { liquidStakedTokens := int64(60_000_000_000000) totalSupply := int64(289_138_414_286684) - // inflation values below are used to regression test the switch from x/mint to x/kavamint - // rather than define the total inflation w/ a community tax, we now directly define - // inflation for staking rewards & inflation for the community pool. - // derive these values from the above values in order to verify no change to output - bondedRatio := sdk.NewDec(bondedTokens).Quo(sdk.NewDec(totalSupply)) - communityInflation := inflation. - Mul(communityTax). - Quo(bondedRatio) - stakingRewardsApy := inflation. - Mul(sdk.OneDec().Sub(communityTax)). - Quo(bondedRatio) - usdcDenom := "erc20/multichain/usdc" usdcSupply := int64(2_500_000_000000) @@ -49,10 +38,12 @@ func (suite *QuerierTestSuite) TestGetStakingAPR() { addVault(usdcDenom, earntypes.NewVaultShare(usdcDenom, sdk.NewDec(usdcSupply))) suite.keeper = suite.NewTestKeeper(&fakeParamSubspace{}). - WithKavamintKeeper( - newFakeKavamintKeeper(). - setCommunityInflation(communityInflation). - setStakingApy(stakingRewardsApy), + WithDistrKeeper( + newFakeDistrKeeper().setCommunityTax(communityTax), + ). + WithMintKeeper( + newFakeMintKeeper(). + setMinter(minttypes.NewMinter(inflation, sdk.OneDec())), ). WithStakingKeeper( newFakeStakingKeeper().addBondedTokens(bondedTokens), diff --git a/x/incentive/keeper/rewards_earn_accum_integration_test.go b/x/incentive/keeper/rewards_earn_accum_integration_test.go index 05079573..51e3dfa0 100644 --- a/x/incentive/keeper/rewards_earn_accum_integration_test.go +++ b/x/incentive/keeper/rewards_earn_accum_integration_test.go @@ -64,9 +64,11 @@ func (suite *AccumulateEarnRewardsIntegrationTests) SetupTest() { stakingBuilder := testutil.NewStakingGenesisBuilder() - kavamintBuilder := testutil.NewKavamintGenesisBuilder(). - WithStakingRewardsApy(sdk.MustNewDecFromStr("0.2")). - WithPreviousBlockTime(suite.GenesisTime) + mintBuilder := testutil.NewMintGenesisBuilder(). + WithInflationMax(sdk.OneDec()). + WithInflationMin(sdk.OneDec()). + WithMinter(sdk.OneDec(), sdk.ZeroDec()). + WithMintDenom("ukava") suite.StartChainWithBuilders( authBuilder, @@ -74,7 +76,7 @@ func (suite *AccumulateEarnRewardsIntegrationTests) SetupTest() { savingsBuilder, earnBuilder, stakingBuilder, - kavamintBuilder, + mintBuilder, ) } @@ -311,7 +313,7 @@ func (suite *AccumulateEarnRewardsIntegrationTests) TestStateUpdatedWhenBlockTim }, { CollateralType: "ukava", - RewardFactor: d("4.154285714285714286").Add(stakingRewardIndexes0), + RewardFactor: d("4.154285714285714285").Add(stakingRewardIndexes0), }, }) diff --git a/x/incentive/keeper/rewards_earn_staking_integration_test.go b/x/incentive/keeper/rewards_earn_staking_integration_test.go index 52af6780..f909bc42 100644 --- a/x/incentive/keeper/rewards_earn_staking_integration_test.go +++ b/x/incentive/keeper/rewards_earn_staking_integration_test.go @@ -63,9 +63,11 @@ func (suite *EarnStakingRewardsIntegrationTestSuite) SetupTest() { stakingBuilder := testutil.NewStakingGenesisBuilder() - kavamintBuilder := testutil.NewKavamintGenesisBuilder(). - WithStakingRewardsApy(sdk.MustNewDecFromStr("0.2")). - WithPreviousBlockTime(suite.GenesisTime) + mintBuilder := testutil.NewMintGenesisBuilder(). + WithInflationMax(sdk.OneDec()). + WithInflationMin(sdk.OneDec()). + WithMinter(sdk.OneDec(), sdk.ZeroDec()). + WithMintDenom("ukava") suite.StartChainWithBuilders( authBuilder, @@ -73,7 +75,7 @@ func (suite *EarnStakingRewardsIntegrationTestSuite) SetupTest() { savingsBuilder, earnBuilder, stakingBuilder, - kavamintBuilder, + mintBuilder, ) } @@ -134,7 +136,6 @@ func (suite *EarnStakingRewardsIntegrationTestSuite) TestStakingRewardsDistribut suite.keeper.SetEarnRewardAccrualTime(suite.Ctx, vaultDenom1, suite.Ctx.BlockTime()) suite.keeper.SetEarnRewardAccrualTime(suite.Ctx, vaultDenom2, suite.Ctx.BlockTime()) - suite.App.GetKavamintKeeper().SetPreviousBlockTime(suite.Ctx, suite.Ctx.BlockTime()) val := suite.GetAbciValidator(suite.valAddrs[0]) diff --git a/x/incentive/keeper/unit_test.go b/x/incentive/keeper/unit_test.go index 23a2f9e2..a7db3b47 100644 --- a/x/incentive/keeper/unit_test.go +++ b/x/incentive/keeper/unit_test.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" pricefeedtypes "github.com/kava-labs/kava/x/pricefeed/types" @@ -153,7 +154,7 @@ type TestKeeperBuilder struct { earnKeeper types.EarnKeeper // Keepers used for APY queries - kavamintKeeper types.KavamintKeeper + mintKeeper types.MintKeeper distrKeeper types.DistrKeeper pricefeedKeeper types.PricefeedKeeper } @@ -178,6 +179,7 @@ func (suite *unitTester) NewTestKeeper( savingsKeeper: nil, liquidKeeper: nil, earnKeeper: nil, + mintKeeper: nil, distrKeeper: nil, pricefeedKeeper: nil, } @@ -203,8 +205,8 @@ func (tk *TestKeeperBuilder) WithStakingKeeper(k types.StakingKeeper) *TestKeepe return tk } -func (tk *TestKeeperBuilder) WithKavamintKeeper(k types.KavamintKeeper) *TestKeeperBuilder { - tk.kavamintKeeper = k +func (tk *TestKeeperBuilder) WithMintKeeper(k types.MintKeeper) *TestKeeperBuilder { + tk.mintKeeper = k return tk } @@ -223,7 +225,7 @@ func (tk *TestKeeperBuilder) Build() keeper.Keeper { tk.cdc, tk.key, tk.paramSubspace, tk.bankKeeper, tk.cdpKeeper, tk.hardKeeper, tk.accountKeeper, tk.stakingKeeper, tk.swapKeeper, tk.savingsKeeper, tk.liquidKeeper, - tk.earnKeeper, tk.kavamintKeeper, tk.distrKeeper, tk.pricefeedKeeper, + tk.earnKeeper, tk.mintKeeper, tk.distrKeeper, tk.pricefeedKeeper, ) } @@ -641,29 +643,23 @@ func (k *fakeDistrKeeper) GetCommunityTax(ctx sdk.Context) (percent sdk.Dec) { return k.communityTax } -type fakeKavamintKeeper struct { - stakingApy sdk.Dec - communityInflation sdk.Dec +type fakeMintKeeper struct { + minter minttypes.Minter } -var _ types.KavamintKeeper = newFakeKavamintKeeper() +var _ types.MintKeeper = newFakeMintKeeper() -func newFakeKavamintKeeper() *fakeKavamintKeeper { - return &fakeKavamintKeeper{} +func newFakeMintKeeper() *fakeMintKeeper { + return &fakeMintKeeper{} } -func (k *fakeKavamintKeeper) setStakingApy(apy sdk.Dec) *fakeKavamintKeeper { - k.stakingApy = apy +func (k *fakeMintKeeper) setMinter(minter minttypes.Minter) *fakeMintKeeper { + k.minter = minter return k } -func (k *fakeKavamintKeeper) setCommunityInflation(inflation sdk.Dec) *fakeKavamintKeeper { - k.communityInflation = inflation - return k -} - -func (k *fakeKavamintKeeper) GetStakingApy(ctx sdk.Context) (apy sdk.Dec) { - return k.stakingApy +func (k *fakeMintKeeper) GetMinter(ctx sdk.Context) (minter minttypes.Minter) { + return k.minter } type fakePricefeedKeeper struct { diff --git a/x/incentive/testutil/kavamint_builder.go b/x/incentive/testutil/kavamint_builder.go deleted file mode 100644 index 14d50567..00000000 --- a/x/incentive/testutil/kavamint_builder.go +++ /dev/null @@ -1,59 +0,0 @@ -package testutil - -import ( - "time" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/app" - - kavaminttypes "github.com/kava-labs/kava/x/kavamint/types" -) - -// KavamintGenesisBuilder is a tool for creating a mint genesis state. -// Helper methods add values onto a default genesis state. -// All methods are immutable and return updated copies of the builder. -type KavamintGenesisBuilder struct { - kavaminttypes.GenesisState -} - -var _ GenesisBuilder = (*KavamintGenesisBuilder)(nil) - -func NewKavamintGenesisBuilder() KavamintGenesisBuilder { - gen := kavaminttypes.DefaultGenesisState() - gen.Params.CommunityPoolInflation = sdk.ZeroDec() - gen.Params.StakingRewardsApy = sdk.ZeroDec() - - return KavamintGenesisBuilder{ - GenesisState: *gen, - } -} - -func (builder KavamintGenesisBuilder) Build() kavaminttypes.GenesisState { - return builder.GenesisState -} - -func (builder KavamintGenesisBuilder) BuildMarshalled(cdc codec.JSONCodec) app.GenesisState { - built := builder.Build() - - return app.GenesisState{ - kavaminttypes.ModuleName: cdc.MustMarshalJSON(&built), - } -} - -func (builder KavamintGenesisBuilder) WithPreviousBlockTime(t time.Time) KavamintGenesisBuilder { - builder.PreviousBlockTime = t - return builder -} - -func (builder KavamintGenesisBuilder) WithStakingRewardsApy(apy sdk.Dec) KavamintGenesisBuilder { - builder.Params.StakingRewardsApy = apy - return builder -} - -func (builder KavamintGenesisBuilder) WithCommunityPoolInflation( - inflation sdk.Dec, -) KavamintGenesisBuilder { - builder.Params.CommunityPoolInflation = inflation - return builder -} diff --git a/x/incentive/testutil/mint_builder.go b/x/incentive/testutil/mint_builder.go new file mode 100644 index 00000000..9c7bde74 --- /dev/null +++ b/x/incentive/testutil/mint_builder.go @@ -0,0 +1,68 @@ +package testutil + +import ( + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/app" + + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" +) + +// MintGenesisBuilder is a tool for creating a mint genesis state. +// Helper methods add values onto a default genesis state. +// All methods are immutable and return updated copies of the builder. +type MintGenesisBuilder struct { + minttypes.GenesisState +} + +var _ GenesisBuilder = (*MintGenesisBuilder)(nil) + +func NewMintGenesisBuilder() MintGenesisBuilder { + gen := minttypes.DefaultGenesisState() + gen.Params.MintDenom = "ukava" + + return MintGenesisBuilder{ + GenesisState: *gen, + } +} + +func (builder MintGenesisBuilder) Build() minttypes.GenesisState { + return builder.GenesisState +} + +func (builder MintGenesisBuilder) BuildMarshalled(cdc codec.JSONCodec) app.GenesisState { + built := builder.Build() + + return app.GenesisState{ + minttypes.ModuleName: cdc.MustMarshalJSON(&built), + } +} + +func (builder MintGenesisBuilder) WithMinter( + inflation sdk.Dec, + annualProvisions sdk.Dec, +) MintGenesisBuilder { + builder.Minter = minttypes.NewMinter(inflation, annualProvisions) + return builder +} + +func (builder MintGenesisBuilder) WithInflationMax( + inflationMax sdk.Dec, +) MintGenesisBuilder { + builder.Params.InflationMax = inflationMax + return builder +} + +func (builder MintGenesisBuilder) WithInflationMin( + inflationMin sdk.Dec, +) MintGenesisBuilder { + builder.Params.InflationMin = inflationMin + return builder +} + +func (builder MintGenesisBuilder) WithMintDenom( + mintDenom string, +) MintGenesisBuilder { + builder.Params.MintDenom = mintDenom + return builder +} diff --git a/x/incentive/types/expected_keepers.go b/x/incentive/types/expected_keepers.go index eeca9446..d24538b7 100644 --- a/x/incentive/types/expected_keepers.go +++ b/x/incentive/types/expected_keepers.go @@ -3,6 +3,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" cdptypes "github.com/kava-labs/kava/x/cdp/types" @@ -93,9 +94,9 @@ type AccountKeeper interface { GetModuleAccount(ctx sdk.Context, name string) authtypes.ModuleAccountI } -// KavamintKeeper defines the required methods needed by this modules keeper -type KavamintKeeper interface { - GetStakingApy(ctx sdk.Context) sdk.Dec +// MintKeeper defines the required methods needed by this modules keeper +type MintKeeper interface { + GetMinter(ctx sdk.Context) (minter minttypes.Minter) } // DistrKeeper defines the required methods needed by this modules keeper diff --git a/x/kavamint/abci.go b/x/kavamint/abci.go deleted file mode 100644 index 5e25fa17..00000000 --- a/x/kavamint/abci.go +++ /dev/null @@ -1,13 +0,0 @@ -package kavamint - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/x/kavamint/keeper" -) - -// BeginBlocker mints & distributes new tokens for the previous block. -func BeginBlocker(ctx sdk.Context, k keeper.KeeperI) { - if err := k.AccumulateAndMintInflation(ctx); err != nil { - panic(err) - } -} diff --git a/x/kavamint/abci_test.go b/x/kavamint/abci_test.go deleted file mode 100644 index 3911670b..00000000 --- a/x/kavamint/abci_test.go +++ /dev/null @@ -1,216 +0,0 @@ -package kavamint_test - -import ( - "testing" - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/staking" - "github.com/stretchr/testify/suite" - - communitytypes "github.com/kava-labs/kava/x/community/types" - "github.com/kava-labs/kava/x/kavamint" - "github.com/kava-labs/kava/x/kavamint/keeper" - "github.com/kava-labs/kava/x/kavamint/testutil" - "github.com/kava-labs/kava/x/kavamint/types" -) - -type abciTestSuite struct { - testutil.KavamintTestSuite -} - -func (suite *abciTestSuite) SetupTest() { - suite.KavamintTestSuite.SetupTest() -} - -func (suite abciTestSuite) CheckModuleBalance(ctx sdk.Context, moduleName string, expectedAmount sdk.Int) { - denom := suite.StakingKeeper.BondDenom(ctx) - amount := suite.App.GetModuleAccountBalance(ctx, moduleName, denom) - suite.Require().Equal(expectedAmount, amount) -} - -func (suite *abciTestSuite) CheckFeeCollectorBalance(ctx sdk.Context, expectedAmount sdk.Int) { - suite.CheckModuleBalance(ctx, authtypes.FeeCollectorName, expectedAmount) -} - -func (suite *abciTestSuite) CheckKavamintBalance(ctx sdk.Context, expectedAmount sdk.Int) { - suite.CheckModuleBalance(ctx, types.ModuleName, expectedAmount) -} - -func (suite *abciTestSuite) CheckCommunityPoolBalance(ctx sdk.Context, expectedAmount sdk.Int) { - suite.CheckModuleBalance(ctx, communitytypes.ModuleAccountName, expectedAmount) -} - -func TestABCITestSuite(t *testing.T) { - suite.Run(t, new(abciTestSuite)) -} - -func (suite *abciTestSuite) Test_BeginBlocker_MintsExpectedTokens() { - testCases := []struct { - name string - blockTime uint64 - communityPoolInflation sdk.Dec - stakingRewardsApy sdk.Dec - bondedRatio sdk.Dec - setup func() - expCommunityPoolBalance sdk.Int - expFeeCollectorBalance sdk.Int - }{ - { - name: "sanity check: a year of seconds mints total yearly inflation", - blockTime: keeper.SecondsPerYear, - communityPoolInflation: sdk.NewDecWithPrec(20, 2), - stakingRewardsApy: sdk.NewDecWithPrec(20, 2), - bondedRatio: sdk.NewDecWithPrec(50, 2), - // 20% inflation on 1e10 tokens -> 2e9 minted - expCommunityPoolBalance: sdk.NewInt(2e9), - // 20% APY, 50% bonded (5e9) -> 1e9 minted - expFeeCollectorBalance: sdk.NewInt(1e9), - }, - { - name: "mints staking rewards, handles 0 community pool inflation", - blockTime: 6, - communityPoolInflation: sdk.ZeroDec(), - stakingRewardsApy: sdk.NewDecWithPrec(20, 2), - bondedRatio: sdk.NewDecWithPrec(40, 2), - expCommunityPoolBalance: sdk.ZeroInt(), - // 20% APY for 6 seconds - // bond ratio is 40%, so total supply * ratio = 1e10 * .4 - // https://www.wolframalpha.com/input?i2d=true&i=%5C%2840%29Power%5B%5C%2840%29Surd%5B1.20%2C31536000%5D%5C%2841%29%2C6%5D-1%5C%2841%29*1e10*.4 - // => 138.75 => truncated to 138 tokens. - expFeeCollectorBalance: sdk.NewInt(138), - }, - { - name: "mints community pool inflation, handles 0 staking rewards", - blockTime: 6, - communityPoolInflation: sdk.NewDecWithPrec(80, 2), - stakingRewardsApy: sdk.ZeroDec(), - bondedRatio: sdk.NewDecWithPrec(40, 2), - // 80% APY for 6 seconds - // total supply = 1e10 - // https://www.wolframalpha.com/input?i2d=true&i=%5C%2840%29Power%5B%5C%2840%29Surd%5B1.80%2C31536000%5D%5C%2841%29%2C6%5D-1%5C%2841%29*1e10 - // => 1118.32 => truncated to 1118 tokens. - expCommunityPoolBalance: sdk.NewInt(1118), - expFeeCollectorBalance: sdk.ZeroInt(), - }, - { - name: "mints no tokens if all inflation is zero", - blockTime: 6, - communityPoolInflation: sdk.ZeroDec(), - stakingRewardsApy: sdk.ZeroDec(), - bondedRatio: sdk.NewDecWithPrec(40, 2), - expCommunityPoolBalance: sdk.ZeroInt(), - expFeeCollectorBalance: sdk.ZeroInt(), - }, - { - name: "mints no tokens if zero seconds passed", - blockTime: 0, - communityPoolInflation: sdk.NewDecWithPrec(50, 2), - stakingRewardsApy: sdk.NewDecWithPrec(20, 2), - bondedRatio: sdk.NewDecWithPrec(35, 2), - expCommunityPoolBalance: sdk.ZeroInt(), - expFeeCollectorBalance: sdk.ZeroInt(), - }, - { - name: "mints community pool inflation and staking rewards", - blockTime: 6, - communityPoolInflation: sdk.NewDecWithPrec(50, 2), - stakingRewardsApy: sdk.NewDecWithPrec(20, 2), - bondedRatio: sdk.NewDecWithPrec(35, 2), - // 50% APY for 6 seconds - // total supply = 1e10 - // https://www.wolframalpha.com/input?i2d=true&i=%5C%2840%29Power%5B%5C%2840%29Surd%5B1.5%2C31536000%5D%5C%2841%29%2C6%5D-1%5C%2841%29*1e10 - // => 771.43 => truncated to 771 tokens. - expCommunityPoolBalance: sdk.NewInt(771), - // 20% APY for 6 seconds - // total bonded = 1e10 * 35% - // https://www.wolframalpha.com/input?i2d=true&i=%5C%2840%29Power%5B%5C%2840%29Surd%5B1.20%2C31536000%5D%5C%2841%29%2C6%5D-1%5C%2841%29*1e10*.35 - // => 121.41 => truncated to 121 tokens. - expFeeCollectorBalance: sdk.NewInt(121), - }, - { - name: "handles long block time", - blockTime: 60, // a minute - communityPoolInflation: sdk.NewDecWithPrec(50, 2), - stakingRewardsApy: sdk.NewDecWithPrec(20, 2), - bondedRatio: sdk.NewDecWithPrec(35, 2), - // https://www.wolframalpha.com/input?i2d=true&i=%5C%2840%29Power%5B%5C%2840%29Surd%5B1.5%2C31536000%5D%5C%2841%29%2C60%5D-1%5C%2841%29*1e10 - expCommunityPoolBalance: sdk.NewInt(7714), - // https://www.wolframalpha.com/input?i2d=true&i=%5C%2840%29Power%5B%5C%2840%29Surd%5B1.20%2C31536000%5D%5C%2841%29%2C60%5D-1%5C%2841%29*1e10*.35 - expFeeCollectorBalance: sdk.NewInt(1214), - }, - { - name: "handles extra long block time", - blockTime: 3 * 3600, // three hours - communityPoolInflation: sdk.NewDecWithPrec(50, 2), - stakingRewardsApy: sdk.NewDecWithPrec(20, 2), - bondedRatio: sdk.NewDecWithPrec(35, 2), - // https://www.wolframalpha.com/input?i2d=true&i=%5C%2840%29Power%5B%5C%2840%29Surd%5B1.5%2C31536000%5D%5C%2841%29%2C3*3600%5D-1%5C%2841%29*1e10 - expCommunityPoolBalance: sdk.NewInt(1388675), - // https://www.wolframalpha.com/input?i2d=true&i=%5C%2840%29Power%5B%5C%2840%29Surd%5B1.20%2C31536000%5D%5C%2841%29%2C3*3600%5D-1%5C%2841%29*1e10*.35 - expFeeCollectorBalance: sdk.NewInt(218542), - }, - } - - for _, tc := range testCases { - suite.Run(tc.name, func() { - suite.SetupTest() - - // set store and params - suite.Keeper.SetPreviousBlockTime(suite.Ctx, suite.Ctx.BlockTime()) - suite.Keeper.SetParams( - suite.Ctx, - types.NewParams(tc.communityPoolInflation, tc.stakingRewardsApy), - ) - - // set bonded token ratio - suite.SetBondedTokenRatio(tc.bondedRatio) - staking.EndBlocker(suite.Ctx, suite.StakingKeeper) - - // run begin blocker - kavamint.BeginBlocker(suite.Ctx, suite.Keeper) - - // expect everything empty to start - suite.CheckFeeCollectorBalance(suite.Ctx, sdk.ZeroInt()) - suite.CheckKavamintBalance(suite.Ctx, sdk.ZeroInt()) - suite.CheckCommunityPoolBalance(suite.Ctx, sdk.ZeroInt()) - - // expect initial block time set - startBlockTime := suite.Keeper.GetPreviousBlockTime(suite.Ctx) - suite.Require().False(startBlockTime.IsZero()) - suite.Require().Equal(suite.Ctx.BlockTime(), startBlockTime) - - // run begin blocker again to mint inflation - ctx2 := suite.Ctx.WithBlockTime(suite.Ctx.BlockTime().Add(time.Second * time.Duration(tc.blockTime))) - kavamint.BeginBlocker(ctx2, suite.Keeper) - - // check expected balances - suite.CheckCommunityPoolBalance(ctx2, tc.expCommunityPoolBalance) - suite.CheckFeeCollectorBalance(ctx2, tc.expFeeCollectorBalance) - - // x/kavamint balance should always be 0 because 100% should be transferred out every block - suite.CheckKavamintBalance(ctx2, sdk.ZeroInt()) - - // expect time to be updated - endBlockTime := suite.Keeper.GetPreviousBlockTime(ctx2) - suite.Require().False(endBlockTime.IsZero()) - suite.Require().Equal(ctx2.BlockTime(), endBlockTime) - }) - } -} - -func (suite *abciTestSuite) Test_BeginBlocker_DefaultsToBlockTime() { - suite.SetupTest() - - // unset previous block time - suite.Keeper.SetPreviousBlockTime(suite.Ctx, time.Time{}) - - // run begin blocker - kavamint.BeginBlocker(suite.Ctx, suite.Keeper) - - // ensure block time gets set - blockTime := suite.Keeper.GetPreviousBlockTime(suite.Ctx) - suite.False(blockTime.IsZero()) - suite.Equal(suite.Ctx.BlockTime(), blockTime) -} diff --git a/x/kavamint/client/cli/query.go b/x/kavamint/client/cli/query.go deleted file mode 100644 index 62a085e8..00000000 --- a/x/kavamint/client/cli/query.go +++ /dev/null @@ -1,89 +0,0 @@ -package cli - -import ( - "fmt" - - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/kava-labs/kava/x/kavamint/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(), - ) - - 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 cumulative 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 -} diff --git a/x/kavamint/genesis.go b/x/kavamint/genesis.go deleted file mode 100644 index 8b29f9a2..00000000 --- a/x/kavamint/genesis.go +++ /dev/null @@ -1,38 +0,0 @@ -package kavamint - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/kava-labs/kava/x/kavamint/keeper" - "github.com/kava-labs/kava/x/kavamint/types" -) - -// InitGenesis new mint genesis -func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, ak types.AccountKeeper, gs *types.GenesisState) { - // guard against invalid genesis - if err := gs.Validate(); err != nil { - panic(fmt.Sprintf("failed to validate %s genesis state: %s", types.ModuleName, err)) - } - - // get module account -- creates one with allowed permissions if it does not exist - macc := ak.GetModuleAccount(ctx, types.ModuleName) - if macc == nil { - panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) - } - - // check module account has minter permissions - if !macc.HasPermission(authtypes.Minter) { - panic(fmt.Sprintf("%s module account does not have %s permissions", types.ModuleName, authtypes.Minter)) - } - - // set store state from genesis - keeper.SetParams(ctx, gs.Params) - keeper.SetPreviousBlockTime(ctx, gs.PreviousBlockTime) -} - -// ExportGenesis returns a GenesisState for a given context and keeper. -func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState { - return types.NewGenesisState(keeper.GetParams(ctx), keeper.GetPreviousBlockTime(ctx)) -} diff --git a/x/kavamint/genesis_test.go b/x/kavamint/genesis_test.go deleted file mode 100644 index 1a6ef1ed..00000000 --- a/x/kavamint/genesis_test.go +++ /dev/null @@ -1,117 +0,0 @@ -package kavamint_test - -import ( - "testing" - "time" - - "github.com/kava-labs/kava/x/kavamint" - "github.com/kava-labs/kava/x/kavamint/testutil" - "github.com/kava-labs/kava/x/kavamint/types" - "github.com/stretchr/testify/suite" - - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" -) - -type genesisTestSuite struct { - testutil.KavamintTestSuite -} - -func (suite *genesisTestSuite) Test_InitGenesis_ValidationPanic() { - invalidState := types.NewGenesisState( - types.NewParams(sdk.OneDec(), types.MaxMintingRate.Add(sdk.OneDec())), // rate over max - time.Time{}, - ) - - suite.Panics(func() { - kavamint.InitGenesis(suite.Ctx, suite.Keeper, suite.App.GetAccountKeeper(), invalidState) - }, "expected init genesis to panic with invalid state") -} - -func (suite *genesisTestSuite) Test_InitGenesis_ModuleAccountDoesNotHaveMinterPerms() { - gs := types.DefaultGenesisState() - - ak := suite.App.GetAccountKeeper() - macc := ak.GetModuleAccount(suite.Ctx, types.ModuleName) - suite.Require().NotNil(macc) - - m, ok := macc.(*authtypes.ModuleAccount) - suite.Require().True(ok) - - m.Permissions = []string{} - ak.SetAccount(suite.Ctx, m) - - suite.PanicsWithValue("kavamint module account does not have minter permissions", func() { - kavamint.InitGenesis(suite.Ctx, suite.Keeper, suite.App.GetAccountKeeper(), gs) - }) -} - -func (suite *genesisTestSuite) Test_InitGenesis_CreatesModuleAccountWithPermissions() { - gs := types.DefaultGenesisState() - ak := suite.App.GetAccountKeeper() - - kavamint.InitGenesis(suite.Ctx, suite.Keeper, ak, gs) - - // by pass auto creation of module accounts - addr, _ := ak.GetModuleAddressAndPermissions(types.ModuleName) - acc := suite.App.GetAccountKeeper().GetAccount(suite.Ctx, addr) - suite.Require().NotNil(acc) - - macc, ok := acc.(authtypes.ModuleAccountI) - suite.Require().True(ok) - - suite.True(macc.HasPermission(authtypes.Minter)) -} - -func (suite *genesisTestSuite) Test_InitAndExportGenesis_DefaultValues() { - state := types.DefaultGenesisState() - - kavamint.InitGenesis(suite.Ctx, suite.Keeper, suite.App.GetAccountKeeper(), state) - - suite.Equal(types.DefaultParams(), suite.Keeper.GetParams(suite.Ctx), "expected default params to bet set in store") - - storeTime := suite.Keeper.GetPreviousBlockTime(suite.Ctx) - suite.Equal(types.DefaultPreviousBlockTime, storeTime, "expected default previous block time to be set in store") - - exportedState := kavamint.ExportGenesis(suite.Ctx, suite.Keeper) - suite.Equal(state, exportedState, "expected exported state to match imported state") -} - -func (suite *genesisTestSuite) Test_InitAndExportGenesis_SetValues() { - prevBlockTime := time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC) - state := types.NewGenesisState( - types.NewParams(sdk.MustNewDecFromStr("0.000000000000000001"), sdk.MustNewDecFromStr("0.000000000000000002")), - prevBlockTime, - ) - - kavamint.InitGenesis(suite.Ctx, suite.Keeper, suite.App.GetAccountKeeper(), state) - - suite.Equal(state.Params, suite.Keeper.GetParams(suite.Ctx), "expected params to bet set in store") - - storeTime := suite.Keeper.GetPreviousBlockTime(suite.Ctx) - suite.Equal(state.PreviousBlockTime, storeTime, "expected previous block time to be set in store") - - exportedState := kavamint.ExportGenesis(suite.Ctx, suite.Keeper) - suite.Equal(state, exportedState, "expected exported state to match imported state") -} - -func (suite *genesisTestSuite) Test_InitAndExportGenesis_ZeroValues() { - state := types.NewGenesisState( - types.NewParams(sdk.ZeroDec(), sdk.ZeroDec()), - time.Time{}, - ) - - kavamint.InitGenesis(suite.Ctx, suite.Keeper, suite.App.GetAccountKeeper(), state) - - suite.Equal(state.Params, suite.Keeper.GetParams(suite.Ctx), "expected params to bet set in store") - - storeTime := suite.Keeper.GetPreviousBlockTime(suite.Ctx) - suite.Equal(state.PreviousBlockTime, storeTime, "expected previous block time to be set in store") - - exportedState := kavamint.ExportGenesis(suite.Ctx, suite.Keeper) - suite.Equal(state, exportedState, "expected exported state to match imported state") -} - -func TestGenesisTestSuite(t *testing.T) { - suite.Run(t, new(genesisTestSuite)) -} diff --git a/x/kavamint/keeper/grpc_query.go b/x/kavamint/keeper/grpc_query.go deleted file mode 100644 index 75230688..00000000 --- a/x/kavamint/keeper/grpc_query.go +++ /dev/null @@ -1,85 +0,0 @@ -package keeper - -import ( - "context" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - - sdk "github.com/cosmos/cosmos-sdk/types" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - - "github.com/kava-labs/kava/x/kavamint/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) - inflation := k.CumulativeInflation(ctx) - - return &types.QueryInflationResponse{Inflation: inflation}, nil -} - -// MintQueryServer implements cosmos sdk's x/mint querier. -// x/mint was removed from kava, but the standard inflation endpoint is still registered -// for easier third party integration and backwards compatibility. -type MintQueryServer struct { - keeper Keeper -} - -// NewMintQueryServer returns a service that implements x/mint's QueryServer -func NewMintQueryServer(kavamintKeeper Keeper) MintQueryServer { - return MintQueryServer{kavamintKeeper} -} - -var _ minttypes.QueryServer = MintQueryServer{} - -// Params is not implemented. There is no mint module. -func (MintQueryServer) Params( - _ context.Context, _ *minttypes.QueryParamsRequest, -) (*minttypes.QueryParamsResponse, error) { - return nil, status.Error(codes.Unimplemented, "x/mint has been replaced by x/kavamint") -} - -// Inflation returns an adjusted inflation rate. -// The `/cosmos/mint/v1beta1/inflation` endpoint is used by third parties to calculate staking APY. -// The usual staking APY calculation takes the inflation and determines the portion of it devoted -// to staking rewards after adjusting for the bonded ratio and x/distribution community_tax. -// staking_apy = (inflation - community_tax) * total_supply / total_bonded -// Staking APY is not set directly via the x/kavamint staking_rewards_apy param. -// This endpoint returns the inflation that makes the above calculation equal to the param: -// inflation = staking_apy * total_bonded / total_supply -// NOTE: assumes x/distribution community_tax = 0 -func (mq MintQueryServer) Inflation( - c context.Context, _ *minttypes.QueryInflationRequest, -) (*minttypes.QueryInflationResponse, error) { - ctx := sdk.UnwrapSDKContext(c) - - stakingApy := mq.keeper.GetParams(ctx).StakingRewardsApy - totalBonded := mq.keeper.totalBondedTokens(ctx) - totalSupply := mq.keeper.totalSupply(ctx) - - // inflation = staking_apy * total_bonded / total_supply - inflation := stakingApy.MulInt(totalBonded).QuoInt(totalSupply) - - return &minttypes.QueryInflationResponse{ - Inflation: inflation, - }, nil -} - -// AnnualProvisions is not implemented. -func (MintQueryServer) AnnualProvisions( - _ context.Context, _ *minttypes.QueryAnnualProvisionsRequest, -) (*minttypes.QueryAnnualProvisionsResponse, error) { - return nil, status.Error(codes.Unimplemented, "x/mint has been replaced by x/kavamint") -} diff --git a/x/kavamint/keeper/grpc_query_test.go b/x/kavamint/keeper/grpc_query_test.go deleted file mode 100644 index b88864e2..00000000 --- a/x/kavamint/keeper/grpc_query_test.go +++ /dev/null @@ -1,159 +0,0 @@ -package keeper_test - -import ( - "context" - "testing" - - "github.com/stretchr/testify/suite" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - - "github.com/cosmos/cosmos-sdk/baseapp" - sdk "github.com/cosmos/cosmos-sdk/types" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - "github.com/cosmos/cosmos-sdk/x/staking" - - "github.com/kava-labs/kava/x/kavamint/keeper" - "github.com/kava-labs/kava/x/kavamint/testutil" - "github.com/kava-labs/kava/x/kavamint/types" -) - -type grpcQueryTestSuite struct { - testutil.KavamintTestSuite - - queryClient types.QueryClient - mintQueryClient minttypes.QueryClient -} - -func (suite *grpcQueryTestSuite) SetupTest() { - suite.KavamintTestSuite.SetupTest() - - queryHelper := baseapp.NewQueryServerTestHelper(suite.Ctx, suite.App.InterfaceRegistry()) - types.RegisterQueryServer(queryHelper, suite.Keeper) - suite.queryClient = types.NewQueryClient(queryHelper) - - mintQueryServer := keeper.NewMintQueryServer(suite.Keeper) - minttypes.RegisterQueryServer(queryHelper, mintQueryServer) - suite.mintQueryClient = minttypes.NewQueryClient(queryHelper) -} - -func TestGRPCQueryTestSuite(t *testing.T) { - suite.Run(t, new(grpcQueryTestSuite)) -} - -func (suite *grpcQueryTestSuite) TestGRPCQueryParams() { - app, ctx, queryClient := suite.App, suite.Ctx, suite.queryClient - - kavamintKeeper := app.GetKavamintKeeper() - - params, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) - suite.Require().NoError(err) - suite.Require().Equal(params.Params, kavamintKeeper.GetParams(ctx)) -} - -func (suite *grpcQueryTestSuite) TestGRPCInflationQuery() { - testCases := []struct { - name string - communityInflation sdk.Dec - stakingApy sdk.Dec - bondedRatio sdk.Dec - expectedInflation sdk.Dec - }{ - { - name: "no community inflation, no staking apy = no inflation", - communityInflation: sdk.NewDec(0), - stakingApy: sdk.NewDec(0), - bondedRatio: sdk.NewDecWithPrec(40, 2), - expectedInflation: sdk.NewDec(0), - }, - { - name: "no community inflation means only staking contributes", - communityInflation: sdk.NewDec(0), - stakingApy: sdk.NewDec(1), - bondedRatio: sdk.NewDecWithPrec(34, 2), - expectedInflation: sdk.NewDecWithPrec(34, 2), - }, - { - name: "no staking apy means only inflation contributes", - communityInflation: sdk.NewDecWithPrec(75, 2), - stakingApy: sdk.NewDec(0), - bondedRatio: sdk.NewDecWithPrec(40, 2), - expectedInflation: sdk.NewDecWithPrec(75, 2), - }, - { - name: "staking and community inflation combines (100 percent bonded)", - communityInflation: sdk.NewDec(1), - stakingApy: sdk.NewDecWithPrec(50, 2), - bondedRatio: sdk.NewDec(1), - expectedInflation: sdk.NewDecWithPrec(150, 2), - }, - { - name: "staking and community inflation combines (40 percent bonded)", - communityInflation: sdk.NewDecWithPrec(90, 2), - stakingApy: sdk.NewDecWithPrec(25, 2), - bondedRatio: sdk.NewDecWithPrec(40, 2), - // 90 + .4*25 = 100 - expectedInflation: sdk.NewDec(1), - }, - { - name: "staking and community inflation combines (25 percent bonded)", - communityInflation: sdk.NewDecWithPrec(90, 2), - stakingApy: sdk.NewDecWithPrec(20, 2), - bondedRatio: sdk.NewDecWithPrec(25, 2), - // 90 + .25*20 = 95 - expectedInflation: sdk.NewDecWithPrec(95, 2), - }, - } - - for _, tc := range testCases { - suite.Run(tc.name, func() { - suite.SetupTest() - - app, ctx, queryClient := suite.App, suite.Ctx, suite.queryClient - - kavamintKeeper := app.GetKavamintKeeper() - - // set desired params - kavamintKeeper.SetParams(ctx, types.NewParams(tc.communityInflation, tc.stakingApy)) - - // set bonded token ratio - suite.SetBondedTokenRatio(tc.bondedRatio) - staking.EndBlocker(ctx, suite.StakingKeeper) - - // query inflation & check for expected results - inflation, err := queryClient.Inflation(context.Background(), &types.QueryInflationRequest{}) - suite.Require().NoError(err) - suite.Require().Equal(inflation.Inflation, kavamintKeeper.CumulativeInflation(ctx)) - suite.Require().Equal(inflation.Inflation, tc.expectedInflation) - - // ensure overridden x/mint query for inflation returns the adjusted inflation - // the adjusted inflation is the inflation that returns the correct staking apy for the - // standard staking apy calculation used by third parties: - // staking_apy = (inflation - community_tax) * total_supply / total_bonded - // => inflation = staking_apy * total_bonded / total_supply - expectedAdjustedInflation := tc.stakingApy.Mul(tc.bondedRatio) - mintQ, err := suite.mintQueryClient.Inflation( - context.Background(), - &minttypes.QueryInflationRequest{}, - ) - suite.NoError(err) - suite.Equal(expectedAdjustedInflation, mintQ.Inflation) - }) - } -} - -func (suite *grpcQueryTestSuite) TestUnimplementedMintQueries() { - suite.SetupTest() - - suite.Run("Params is unimplemented", func() { - _, err := suite.mintQueryClient.Params(context.Background(), nil) - suite.Error(err) - suite.Equal(codes.Unimplemented, status.Code(err)) - }) - - suite.Run("AnnualProvisions is unimplemented", func() { - _, err := suite.mintQueryClient.AnnualProvisions(context.Background(), nil) - suite.Error(err) - suite.Equal(codes.Unimplemented, status.Code(err)) - }) -} diff --git a/x/kavamint/keeper/inflation.go b/x/kavamint/keeper/inflation.go deleted file mode 100644 index 6540c098..00000000 --- a/x/kavamint/keeper/inflation.go +++ /dev/null @@ -1,146 +0,0 @@ -package keeper - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/kava-labs/kava/x/kavamint/types" -) - -// this is the same value used in the x/hard -const ( - SecondsPerYear = uint64(31536000) -) - -// Minter wraps the logic of a single source of inflation. It calculates the amount of coins to be -// minted to match a yearly `rate` of inflating the `basis`. -type Minter struct { - name string // name of the minting. used as event attribute to report how much is minted - rate sdk.Dec // the yearly apy of the mint. ex. 20% => 0.2 - basis sdk.Int // the base amount of coins that is inflated - destMaccName string // the destination module account name to mint coins to - mintDenom string // denom of coin this minter is responsible for minting -} - -// NewMinter returns creates a new source of minting inflation -func NewMinter( - name string, rate sdk.Dec, basis sdk.Int, mintDenom string, destMaccName string, -) Minter { - return Minter{ - name: name, - rate: rate, - basis: basis, - destMaccName: destMaccName, - mintDenom: mintDenom, - } -} - -// AccumulateInflation calculates the number of coins that should be minted to match a yearly `rate` -// for interest compounded each second of the year over `secondsPassed` seconds. -// `basis` is the base amount of coins that is inflated. -func (m Minter) AccumulateInflation(secondsPassed uint64) (sdk.Coin, error) { - // calculate the rate factor based on apy & seconds passed since last block - inflationRate, err := m.CalculateInflationRate(secondsPassed) - if err != nil { - return sdk.Coin{}, err - } - amount := inflationRate.MulInt(m.basis).TruncateInt() - return sdk.NewCoin(m.mintDenom, amount), nil -} - -// CalculateInflationRate converts an APY into the factor corresponding with that APY's accumulation -// over a period of secondsPassed seconds. -func (m Minter) CalculateInflationRate(secondsPassed uint64) (sdk.Dec, error) { - perSecondInterestRate, err := apyToSpy(m.rate.Add(sdk.OneDec())) - if err != nil { - return sdk.ZeroDec(), err - } - rate := perSecondInterestRate.Power(secondsPassed) - return rate.Sub(sdk.OneDec()), nil -} - -// AccumulateAndMintInflation defines the sources of inflation, determines the seconds passed since -// the last mint, and then mints each source of inflation to the defined destination. -func (k Keeper) AccumulateAndMintInflation(ctx sdk.Context) error { - params := k.GetParams(ctx) - // determine seconds since last mint - previousBlockTime := k.GetPreviousBlockTime(ctx) - if previousBlockTime.IsZero() { - previousBlockTime = ctx.BlockTime() - } - secondsPassed := ctx.BlockTime().Sub(previousBlockTime).Seconds() - - // calculate totals before any minting is done to prevent new mints affecting the values - totalSupply := k.totalSupply(ctx) - totalBonded := k.totalBondedTokens(ctx) - - bondDenom := k.bondDenom(ctx) - - // define minters for each contributing piece of inflation - minters := []Minter{ - // staking rewards - NewMinter( - types.AttributeKeyStakingRewardMint, - params.StakingRewardsApy, - totalBonded, - bondDenom, - k.stakingRewardsFeeCollectorName, - ), - // community pool inflation - NewMinter( - types.AttributeKeyCommunityPoolMint, - params.CommunityPoolInflation, - totalSupply, - bondDenom, - k.communityPoolModuleAccountName, - ), - } - - mintEventAttrs := make([]sdk.Attribute, 0, len(minters)) - for _, minter := range minters { - // calculate amount for time passed - amount, err := minter.AccumulateInflation(uint64(secondsPassed)) - if err != nil { - return err - } - - // mint & transfer coins - inflation := sdk.NewCoins(amount) - if err := k.mintCoinsToModule(ctx, inflation, minter.destMaccName); err != nil { - return err - } - - // add attribute to event - mintEventAttrs = append(mintEventAttrs, sdk.NewAttribute( - minter.name, - inflation.String(), - )) - } - - // ------------- Bookkeeping ------------- - // bookkeep the previous block time - k.SetPreviousBlockTime(ctx, ctx.BlockTime()) - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeMint, - sdk.NewAttribute(types.AttributeKeyTotalSupply, totalSupply.String()), - sdk.NewAttribute(types.AttributeKeyTotalBonded, totalBonded.String()), - sdk.NewAttribute(types.AttributeSecondsPassed, fmt.Sprintf("%f", secondsPassed)), - ).AppendAttributes(mintEventAttrs...), - ) - - return nil -} - -// apyToSpy converts the input annual interest rate. For example, 10% apy would be passed as 1.10. -// SPY = Per second compounded interest rate is how cosmos mathematically represents APY. -func apyToSpy(apy sdk.Dec) (sdk.Dec, error) { - // Note: any APY greater than 176.5 will cause an out-of-bounds error - root, err := apy.ApproxRoot(SecondsPerYear) - if err != nil { - return sdk.ZeroDec(), err - } - return root, nil -} diff --git a/x/kavamint/keeper/inflation_test.go b/x/kavamint/keeper/inflation_test.go deleted file mode 100644 index d19ef867..00000000 --- a/x/kavamint/keeper/inflation_test.go +++ /dev/null @@ -1,167 +0,0 @@ -package keeper_test - -import ( - "fmt" - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/x/kavamint/keeper" - "github.com/kava-labs/kava/x/kavamint/types" - "github.com/stretchr/testify/suite" -) - -type InflationTestSuite struct { - suite.Suite -} - -func TestInflationTestSuite(t *testing.T) { - suite.Run(t, new(InflationTestSuite)) -} - -func (suite *InflationTestSuite) TestCalculateInflationFactor() { - testCases := []struct { - name string - apy sdk.Dec - secondsPassed uint64 - expectedRate sdk.Dec - // preciseToDecimal is the decimal place after which error is present. if >=18, number is exact. - // ex. precise to 3 decimals means accurate to +/-0.0005 - preciseToDecimal int - }{ - { - name: "any apy over 0 seconds is 0", - apy: sdk.OneDec(), - secondsPassed: 0, - expectedRate: sdk.ZeroDec(), - preciseToDecimal: 19, - }, - { - name: "zero apy for any number of seconds is 0", - apy: sdk.ZeroDec(), - secondsPassed: 100, - expectedRate: sdk.ZeroDec(), - preciseToDecimal: 19, - }, - { - name: "an apy over a year's worth of seconds should be the apy", - apy: sdk.NewDecWithPrec(10, 2), - secondsPassed: keeper.SecondsPerYear, - expectedRate: sdk.NewDecWithPrec(10, 2), - preciseToDecimal: 10, - }, - { - name: "example: 22 percent for 6 seconds, precise to 17 decimals", - apy: sdk.NewDecWithPrec(22, 2), - secondsPassed: 6, - expectedRate: sdk.MustNewDecFromStr("0.000000037833116915"), - preciseToDecimal: 17, - }, - { - name: "example: 3 percent for 10 seconds, precise to 17 decimals", - apy: sdk.NewDecWithPrec(3, 2), - secondsPassed: 10, - expectedRate: sdk.MustNewDecFromStr("0.000000009373034748"), - preciseToDecimal: 17, - }, - { - name: "example: 150 percent for 10 seconds, precise to 17 decimals", - apy: sdk.NewDecWithPrec(150, 2), - secondsPassed: 10, - expectedRate: sdk.MustNewDecFromStr("0.000000290553927255"), - preciseToDecimal: 17, - }, - { - name: "example: 10 percent for 10 seconds, precise to 16 decimals", - apy: sdk.NewDecWithPrec(10, 2), - secondsPassed: 10, - expectedRate: sdk.MustNewDecFromStr("0.000000030222660212"), - preciseToDecimal: 16, - }, - { - name: "example: 1,000 percent for 10 seconds, precise to 16 decimals", - apy: sdk.NewDecWithPrec(1000, 2), - secondsPassed: 10, - expectedRate: sdk.MustNewDecFromStr("0.000000760367892072"), - preciseToDecimal: 16, - }, - { - name: "example: 10 percent for 30 seconds, precise to 16 decimals", - apy: sdk.NewDecWithPrec(10, 2), - secondsPassed: 30, - expectedRate: sdk.MustNewDecFromStr("0.00000009066798338"), - preciseToDecimal: 16, - }, - { - name: "example: 95 percent for 15 seconds, precise to 16 decimals", - apy: sdk.NewDecWithPrec(95, 2), - secondsPassed: 15, - expectedRate: sdk.MustNewDecFromStr("0.000000317651007726"), - preciseToDecimal: 16, - }, - { - name: "example: 10,000 percent for 10 seconds, precise to 13 decimals", - apy: sdk.NewDecWithPrec(10000, 2), - secondsPassed: 10, - expectedRate: sdk.MustNewDecFromStr("0.000001463446186527"), - preciseToDecimal: 13, - }, - { - name: "can handle upper bound of APY (but w/ large error)", - apy: types.MaxMintingRate, - secondsPassed: 10, - expectedRate: sdk.MustNewDecFromStr("0.000001642242155465"), - preciseToDecimal: 4, // NOTE: error is really large here - }, - } - - for _, tc := range testCases { - suite.Run(tc.name, func() { - minter := keeper.NewMinter(tc.name, tc.apy, sdk.ZeroInt(), "ukava", "ignored") - actualRate, err := minter.CalculateInflationRate(tc.secondsPassed) - suite.Require().NoError(err) - - marginOfError := sdk.ZeroDec() - if tc.preciseToDecimal < 18 { - marginOfError = sdk.NewDecWithPrec(5, int64(tc.preciseToDecimal+1)) - } - suite.requireWithinError(tc.expectedRate, actualRate, marginOfError) - }) - } - - suite.Run("errors with out-of-bounds when rate is too high", func() { - // Dec.ApproxRoot will error w/ out-of-bounds when rate is >176.5 - oob := sdk.NewDec(177) - minter := keeper.NewMinter( - "out-of-bounds-minter", - oob, - sdk.OneInt(), - "uakva", - "ignored", - ) - _, err := minter.CalculateInflationRate(100) - suite.Error(err) - - // ensure max mint rate is less than out-of-bounds value - suite.True(types.MaxMintingRate.LT(oob)) - }) -} - -func (suite *InflationTestSuite) Test_AccumulateInflation_FailsWithInvalidRate() { - oob := sdk.NewDec(177) - minter := keeper.NewMinter( - "out-of-bounds-minter", - oob, - sdk.OneInt(), - "uakva", - "ignored", - ) - _, err := minter.AccumulateInflation(1) - suite.ErrorContains(err, "out of bounds") -} - -func (suite *InflationTestSuite) requireWithinError(expected, actual, margin sdk.Dec) { - suite.Require().Truef( - actual.Sub(expected).Abs().LTE(margin), - fmt.Sprintf("precision is outside desired margin of error %s\nexpected: %s\nactual : %s", margin, expected, actual), - ) -} diff --git a/x/kavamint/keeper/keeper.go b/x/kavamint/keeper/keeper.go deleted file mode 100644 index 086ab087..00000000 --- a/x/kavamint/keeper/keeper.go +++ /dev/null @@ -1,161 +0,0 @@ -package keeper - -import ( - "time" - - "github.com/tendermint/tendermint/libs/log" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/kava-labs/kava/x/kavamint/types" -) - -// KeeperI is the required keeper interface for x/kavamint's begin blocker -type KeeperI interface { - AccumulateAndMintInflation(ctx sdk.Context) error -} - -// Keeper of the kavamint store -type Keeper struct { - cdc codec.BinaryCodec - storeKey sdk.StoreKey - paramSpace paramtypes.Subspace - stakingKeeper types.StakingKeeper - bankKeeper types.BankKeeper - stakingRewardsFeeCollectorName string - communityPoolModuleAccountName string -} - -var _ KeeperI = Keeper{} - -// NewKeeper creates a new kavamint Keeper instance -func NewKeeper( - cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, - sk types.StakingKeeper, ak types.AccountKeeper, bk types.BankKeeper, - stakingRewardsFeeCollectorName string, communityPoolModuleAccountName string, -) Keeper { - // 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, - bankKeeper: bk, - stakingRewardsFeeCollectorName: stakingRewardsFeeCollectorName, - communityPoolModuleAccountName: communityPoolModuleAccountName, - } -} - -// Logger returns a module-specific logger. -func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", "x/"+types.ModuleName) -} - -// 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) -} - -// GetStakingApy returns the APY minted for staking rewards -func (k Keeper) GetStakingApy(ctx sdk.Context) sdk.Dec { - params := k.GetParams(ctx) - return params.StakingRewardsApy -} - -// bondDenom implements an alias call to the underlying staking keeper's BondDenom. -func (k Keeper) bondDenom(ctx sdk.Context) string { - return k.stakingKeeper.BondDenom(ctx) -} - -// totalBondedTokens implements an alias call to the underlying staking keeper's -// TotalBondedTokens to be used in BeginBlocker. -func (k Keeper) totalBondedTokens(ctx sdk.Context) sdk.Int { - return k.stakingKeeper.TotalBondedTokens(ctx) -} - -// mintCoinsToModule mints teh desired coins to the x/kavamint module account and then -// transfers them to the designated module account. -// if `newCoins` is empty or zero, this method is a noop. -func (k Keeper) mintCoinsToModule(ctx sdk.Context, newCoins sdk.Coins, destMaccName string) error { - if newCoins.IsZero() { - // skip as no coins need to be minted - return nil - } - - // mint the coins - err := k.bankKeeper.MintCoins(ctx, types.ModuleAccountName, newCoins) - if err != nil { - return nil - } - - // transfer them to the desired destination module account - return k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleAccountName, destMaccName, newCoins) -} - -// totalSupply implements an alias call to the underlying supply keeper's -// GetSupply for the mint denom to be used in calculating cumulative inflation. -func (k Keeper) totalSupply(ctx sdk.Context) sdk.Int { - return k.bankKeeper.GetSupply(ctx, k.bondDenom(ctx)).Amount -} - -func (k Keeper) CumulativeInflation(ctx sdk.Context) sdk.Dec { - params := k.GetParams(ctx) - totalInflation := sdk.NewDec(0) - - // community pool contribution is simply the inflation param - totalInflation = totalInflation.Add(params.CommunityPoolInflation) - - // staking rewards contribution is the apy * bonded_ratio - bondedSupply := k.totalBondedTokens(ctx) - totalSupply := k.totalSupply(ctx) - bondedRatio := sdk.NewDecFromInt(bondedSupply).QuoInt(totalSupply) - inflationFromStakingRewards := params.StakingRewardsApy.Mul(bondedRatio) - - totalInflation = totalInflation.Add(inflationFromStakingRewards) - - return totalInflation -} - -// GetPreviousBlockTime get the blocktime for the previous block -func (k Keeper) GetPreviousBlockTime(ctx sdk.Context) (blockTime time.Time) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PreviousBlockTimeKey) - - b := store.Get(types.PreviousBlockTimeKey) - if b == nil { - return blockTime - } - - if err := blockTime.UnmarshalBinary(b); err != nil { - panic(err) - } - - return -} - -// SetPreviousBlockTime set the time of the previous block -func (k Keeper) SetPreviousBlockTime(ctx sdk.Context, blockTime time.Time) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PreviousBlockTimeKey) - - if blockTime.IsZero() { - store.Delete(types.PreviousBlockTimeKey) - return - } - - b, err := blockTime.MarshalBinary() - if err != nil { - panic(err) - } - store.Set(types.PreviousBlockTimeKey, b) -} diff --git a/x/kavamint/keeper/keeper_test.go b/x/kavamint/keeper/keeper_test.go deleted file mode 100644 index d4780395..00000000 --- a/x/kavamint/keeper/keeper_test.go +++ /dev/null @@ -1,71 +0,0 @@ -package keeper_test - -import ( - "testing" - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/x/kavamint/testutil" - "github.com/kava-labs/kava/x/kavamint/types" - "github.com/stretchr/testify/suite" -) - -type keeperTestSuite struct { - testutil.KavamintTestSuite -} - -func TestKeeperTestSuite(t *testing.T) { - suite.Run(t, new(keeperTestSuite)) -} - -func (suite keeperTestSuite) TestParams_Persistance() { - keeper := suite.Keeper - - params := types.NewParams( - sdk.MustNewDecFromStr("0.000000000000000001"), - sdk.MustNewDecFromStr("0.000000000000000002"), - ) - keeper.SetParams(suite.Ctx, params) - suite.Equal(keeper.GetParams(suite.Ctx), params) - - oldParams := params - params = types.NewParams( - sdk.MustNewDecFromStr("0.000000000000000011"), - sdk.MustNewDecFromStr("0.000000000000000022"), - ) - keeper.SetParams(suite.Ctx, params) - suite.NotEqual(keeper.GetParams(suite.Ctx), oldParams) - suite.Equal(keeper.GetParams(suite.Ctx), params) -} - -func (suite keeperTestSuite) TestPreviousBlockTime_Persistance() { - keeper := suite.Keeper - zeroTime := time.Time{} - - keeper.SetPreviousBlockTime(suite.Ctx, zeroTime) - suite.Equal(keeper.GetPreviousBlockTime(suite.Ctx), zeroTime) - - newTime := suite.Ctx.BlockTime() - suite.Require().False(newTime.IsZero()) - - keeper.SetPreviousBlockTime(suite.Ctx, newTime) - suite.Equal(keeper.GetPreviousBlockTime(suite.Ctx), newTime) -} - -func (suite keeperTestSuite) Test_GetStakingApy() { - suite.SetupTest() - - testCases := []sdk.Dec{ - sdk.ZeroDec(), - sdk.MustNewDecFromStr("0.000005"), - sdk.MustNewDecFromStr("0.15"), - sdk.OneDec(), - types.MaxMintingRate, - } - - for _, tc := range testCases { - params := types.NewParams(sdk.ZeroDec(), tc) - suite.Keeper.SetParams(suite.Ctx, params) - suite.Equal(tc, suite.Keeper.GetStakingApy(suite.Ctx)) - } -} diff --git a/x/kavamint/module.go b/x/kavamint/module.go deleted file mode 100644 index 9d8f9667..00000000 --- a/x/kavamint/module.go +++ /dev/null @@ -1,161 +0,0 @@ -package kavamint - -import ( - "context" - "encoding/json" - "fmt" - - "github.com/gorilla/mux" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - abci "github.com/tendermint/tendermint/abci/types" - - "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" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - - "github.com/kava-labs/kava/x/kavamint/client/cli" - "github.com/kava-labs/kava/x/kavamint/keeper" - "github.com/kava-labs/kava/x/kavamint/types" -) - -var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} -) - -// AppModuleBasic defines the basic application module used by the kavamint 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 kavamint 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 kavamint module. -func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { - var gs types.GenesisState - if err := cdc.UnmarshalJSON(bz, &gs); err != nil { - return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) - } - - return gs.Validate() -} - -// RegisterRESTRoutes registers the REST routes for the kavamint module. -func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {} - -// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the kavamint module. -func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) - - // add x/mint query handler for better 3rd party compatibility - minttypes.RegisterQueryHandlerClient(context.Background(), mux, minttypes.NewQueryClient(clientCtx)) -} - -// GetTxCmd returns no root tx command for the kavamint module. -func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil } - -// GetQueryCmd returns the root query command for the kavamint module. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd() -} - -// AppModule implements an application module for the kavamint 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 kavamint module's name. -func (AppModule) Name() string { - return types.ModuleName -} - -// RegisterInvariants registers the kavamint module invariants. -func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} - -// Route returns the message routing key for the kavamint module. -func (AppModule) Route() sdk.Route { return sdk.Route{} } - -// QuerierRoute returns the kavamint module's querier route name. -func (AppModule) QuerierRoute() string { - return types.QuerierRoute -} - -// LegacyQuerierHandler returns the kavamint module sdk.Querier. -func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { - return nil -} - -// 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) - - // register x/mint query server. - // x/mint was replaced by this module but we still want 3rd parties to be able to - // request the original sdk endpoints. - minttypes.RegisterQueryServer(cfg.QueryServer(), keeper.NewMintQueryServer(am.keeper)) -} - -// InitGenesis performs genesis initialization for the kavamint 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 kavamint module. -func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { - BeginBlocker(ctx, am.keeper) -} - -// EndBlock returns the end blocker for the kavamint module. It returns no validator -// updates. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} diff --git a/x/kavamint/module_test.go b/x/kavamint/module_test.go deleted file mode 100644 index f7a070e7..00000000 --- a/x/kavamint/module_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package kavamint_test - -import ( - "testing" - - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/stretchr/testify/require" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - - "github.com/kava-labs/kava/app" - "github.com/kava-labs/kava/x/kavamint/types" -) - -func TestKavaMintModuleAccountWithPermissionsOnAppInit(t *testing.T) { - tApp := app.NewTestApp() - ctx := tApp.NewContext(true, tmproto.Header{Height: 1}) - tApp.InitializeFromGenesisStates() - - ak := tApp.GetAccountKeeper() - - // by pass auto creation of module accounts - addr, _ := ak.GetModuleAddressAndPermissions(types.ModuleName) - acc := ak.GetAccount(ctx, addr) - - require.NotNil(t, acc, "expected module account to exist") - - macc, ok := acc.(authtypes.ModuleAccountI) - require.True(t, ok) - - require.True(t, macc.HasPermission(authtypes.Minter), "expected module account to have mint permissions") -} diff --git a/x/kavamint/spec/01_concepts.md b/x/kavamint/spec/01_concepts.md deleted file mode 100644 index 1314053f..00000000 --- a/x/kavamint/spec/01_concepts.md +++ /dev/null @@ -1,45 +0,0 @@ - - -# Concepts - -## Singular Source of Inflation - -The kavamint module mints new tokens each block. How many tokens are minted is determined by rates set in kavamint's parameters. Where the newly minted tokens are transferred to is dictated by which parameter. The kavamint module supports minting for the following purposes: - -| Purpose | Parameter | Rate Based On | Transferred To | -| --------------- | ------------------------ | ----------------------- | --------------- | -| Community Pool | `CommunityPoolInflation` | TotalSupply | x/community | -| Staking Rewards | `StakingRewardsApy` | TotalSupply*BondedRatio | x/auth fee pool | - -`TotalSupply` is the total number of tokens. `BondedRatio` is the percentage of those tokens that are delegated to a bonded validator. - -### How Amount is Calculated - -The number of seconds since the previous block is determined: `secondsSinceLastBlock`. - -For each yearly rate set in the parameters, an equivalent rate for the number of seconds passed is determined assuming the rate compounds every second and, for simplicity, there are a fixed number of seconds per year (`365 x 24 x 60 x 60 = 31,536,000`). The rate compounded over `secondsSinceLastBlock` seconds is the `31,536,000`th root of `rate + 1` to the `secondsSinceLastBlock` power (minus 100% to determine number of new tokens). This number is truncated to an `sdk.Int`. - -**example**: -Assume `CommunityPoolInflation` is 20%, the `TotalSupply` is 1e10 tokens and `secondsSinceLastBlock` is 5 seconds. The number of tokens minted is determined to be 289 tokens. - -```math -({\sqrt[secondsPerYear]{1 + CommunityPoolInflation}}^{secondsSinceLastBlock} - 1)*TotalSupply -= ({\sqrt[31,536,000]{1.2}}^{5} - 1)*1e10 -\approx 289 -``` - -## Staking Reward Distribution - -It helps to understand how newly minted tokens are created and distributed as validator rewards by default in a Cosmos SDK blockchain. In the standard Cosmos SDK mint module, tokens are minted each block based on a variable inflation rate determined by the parameters and the desired bonded token ratio. The tokens are then transferred to the auth module's fee pool to be distributed as staking rewards after a portion of the total fee pool is transferred to the community pool (determined by the CommunityTax parameter of the distribution module). - -The kavamint module separates the default community pool inflation from staking rewards. For staking rewards, it uses an APY determined by StakingRewardsApy. The basis is the total bonded tokens. The tokens are distributed to the same fee pool as above so they can be distributed as rewards to delegators with the default distribution module. - -## Community Pool Inflation - -Every block, tokens are distributed to KAVA's community pool, the module account of x/community. The number of tokens distributed is determined by the total supply. - -## Disabling Default Inflation - -The intention of this module is to replace the default minting of the x/mint module. To make that the case, the minimum and maximum inflation parameters of the mint module should be set to 0. Additionally, it's recommended that the community tax parameter of the distribution module should be set to 0 as the logic for funding the community pool is controlled by kavamint. diff --git a/x/kavamint/spec/02_state.md b/x/kavamint/spec/02_state.md deleted file mode 100644 index 91a8e1df..00000000 --- a/x/kavamint/spec/02_state.md +++ /dev/null @@ -1,36 +0,0 @@ - - -# State - -## Parameters and Genesis State - -`Parameters` define the governance parameters that control inflation of KAVA. -Each parameter is an APY/inflation used in conjunction with the block time to -calculate how much KAVA to mint for what purposes. See [params](./05_params.md) for a description of each param. - -```go -// Params wraps the governance parameters for the kavamint module -type Params struct { - // yearly inflation of total token supply minted to the community pool. - CommunityPoolInflation sdk.Dec `json:"community_pool_inflation" yaml:"community_pool_inflation"` - // yearly inflation of bonded tokens minted for staking rewards to validators. - StakingRewardsApy sdk.Dec `json:"staking_rewards_apy" yaml:"staking_rewards_apy"` -} -``` - -`GenesisState` defines the state that must be persisted when the blockchain stops/restarts in order for normal function of the kavamint module to resume. - -```go - -// GenesisState defines the kavamint module's genesis state. -type GenesisState struct { - // params defines all the parameters of the module. - Params Params `json:"params" yaml:"params"` -} -``` - -## Previous Block Time - -The `PreviousBlockTime` is stored in the keeper and updated each block. In the BeginBlocker, the number of seconds between the current and previous block is determined and used to calculate how much KAVA should be minted for each diff --git a/x/kavamint/spec/03_messages.md b/x/kavamint/spec/03_messages.md deleted file mode 100644 index 6b466303..00000000 --- a/x/kavamint/spec/03_messages.md +++ /dev/null @@ -1,7 +0,0 @@ - - -# Messages - -The kavadist module contains no messages. All state transitions are controlled by parameters, which can be updated via parameter change governance proposals. diff --git a/x/kavamint/spec/04_events.md b/x/kavamint/spec/04_events.md deleted file mode 100644 index 45502156..00000000 --- a/x/kavamint/spec/04_events.md +++ /dev/null @@ -1,17 +0,0 @@ - - -# Events - -The kavamint module emits the following events: - -## BeginBlocker - -| Type | Attribute Key | Attribute Value | -| -------- | ------------------------------- | ------------------------ | -| kavamint | total_supply | {totalSupply} | -| kavamint | bonded_ratio | {bondedRatio} | -| kavamint | seconds_since_last_mint | {secondsPassed} | -| kavamint | minted_community_pool_inflation | {communityPoolInflation} | -| kavamint | minted_staking_rewards | {stakingRewardCoins} | diff --git a/x/kavamint/spec/05_params.md b/x/kavamint/spec/05_params.md deleted file mode 100644 index 33d1f490..00000000 --- a/x/kavamint/spec/05_params.md +++ /dev/null @@ -1,12 +0,0 @@ - - -# Parameters - -Example parameters for the kavamint module: - -| Key | Type | Example | Description | -| ---------------------- | ------- | ---------------------- | ------------------------------------------------------------------------ | -| CommunityPoolInflation | sdk.Dec | "0.250000000000000000" | Yearly inflation rate of total token supply minted to the community pool | -| StakingRewardsAPY | sdk.Dec | "0.200000000000000000" | APY of bonded tokens minted for staking reward distribution | diff --git a/x/kavamint/spec/06_begin_block.md b/x/kavamint/spec/06_begin_block.md deleted file mode 100644 index 0542c795..00000000 --- a/x/kavamint/spec/06_begin_block.md +++ /dev/null @@ -1,21 +0,0 @@ - - -# Begin Block - -At the start of each block, new KAVA tokens are minted and distributed - -```go -// BeginBlocker mints & distributes new tokens for the previous block. -func BeginBlocker(ctx sdk.Context, k Keeper) { - if err := k.AccumulateAndMintInflation(ctx); err != nil { - panic(err) - } -} -``` - -`AccumulateAndMintInflation` defines all sources of inflation from yearly APYs set via the parameters. -Those rates are converted to the effective rate of the yearly interest rate assuming it is -compounded once per second, for the number of seconds since the previous mint. See concepts for -more details on calculations & the defined sources of inflation. diff --git a/x/kavamint/spec/README.md b/x/kavamint/spec/README.md deleted file mode 100644 index e6e1e731..00000000 --- a/x/kavamint/spec/README.md +++ /dev/null @@ -1,21 +0,0 @@ - - -# `kavamint` - - - -1. **[Concepts](01_concepts.md)** -2. **[State](02_state.md)** -3. **[Messages](03_messages.md)** -4. **[Events](04_events.md)** -5. **[Params](05_params.md)** -6. **[BeginBlock](06_begin_block.md)** - -## Abstract - -`x/kavamint` is an implementation of a Cosmos SDK Module that provides for functionality and governance of overall inflation of the KAVA staking token. diff --git a/x/kavamint/testutil/suite.go b/x/kavamint/testutil/suite.go deleted file mode 100644 index 66c04ea7..00000000 --- a/x/kavamint/testutil/suite.go +++ /dev/null @@ -1,61 +0,0 @@ -package testutil - -import ( - "github.com/stretchr/testify/suite" - - sdk "github.com/cosmos/cosmos-sdk/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" - - "github.com/kava-labs/kava/app" - "github.com/kava-labs/kava/x/kavamint/keeper" -) - -type KavamintTestSuite struct { - suite.Suite - - App app.TestApp - Ctx sdk.Context - Keeper keeper.Keeper - StakingKeeper stakingkeeper.Keeper - - BondDenom string -} - -func (suite *KavamintTestSuite) SetupTest() { - app.SetSDKConfig() - suite.App = app.NewTestApp() - suite.App.InitializeFromGenesisStates() - suite.Ctx = suite.App.BaseApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()}) - suite.Keeper = suite.App.GetKavamintKeeper() - suite.StakingKeeper = suite.App.GetStakingKeeper() - - suite.BondDenom = suite.StakingKeeper.BondDenom(suite.Ctx) -} - -// SetBondedTokenRatio mints the total supply to an account and creates a validator with a self -// delegation that makes the total staked token ratio set as desired. -// EndBlocker must be run in order for tokens to become bonded. -// returns total supply coins -func (suite *KavamintTestSuite) SetBondedTokenRatio(ratio sdk.Dec) sdk.Coins { - address := app.RandomAddress() - - supplyAmount := sdk.NewInt(1e10) - totalSupply := sdk.NewCoins(sdk.NewCoin(suite.BondDenom, supplyAmount)) - amountToBond := ratio.MulInt(supplyAmount).TruncateInt() - - // fund account that will create validator with total supply - err := suite.App.FundAccount(suite.Ctx, address, totalSupply) - suite.Require().NoError(err) - - if ratio.IsZero() { - return totalSupply - } - - // create a validator with self delegation such that ratio is achieved - err = suite.App.CreateNewUnbondedValidator(suite.Ctx, sdk.ValAddress(address), amountToBond) - suite.Require().NoError(err) - - return totalSupply -} diff --git a/x/kavamint/types/events.go b/x/kavamint/types/events.go deleted file mode 100644 index 33a1bf60..00000000 --- a/x/kavamint/types/events.go +++ /dev/null @@ -1,12 +0,0 @@ -package types - -// Minting module event types -const ( - EventTypeMint = ModuleName - - AttributeKeyTotalSupply = "total_supply" - AttributeKeyTotalBonded = "total_bonded" - AttributeSecondsPassed = "seconds_since_last_mint" - AttributeKeyCommunityPoolMint = "minted_community_pool_inflation" - AttributeKeyStakingRewardMint = "minted_staking_rewards" -) diff --git a/x/kavamint/types/expected_keepers.go b/x/kavamint/types/expected_keepers.go deleted file mode 100644 index db7941ee..00000000 --- a/x/kavamint/types/expected_keepers.go +++ /dev/null @@ -1,26 +0,0 @@ -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 { - BondDenom(sdk.Context) string - TotalBondedTokens(sdk.Context) sdk.Int -} - -// AccountKeeper defines the contract required for account APIs. -type AccountKeeper interface { - GetModuleAddress(name string) sdk.AccAddress - GetModuleAccount(ctx sdk.Context, moduleName string) types.ModuleAccountI -} - -// BankKeeper defines the contract needed to be fulfilled for banking and supply -// dependencies. -type BankKeeper interface { - GetSupply(ctx sdk.Context, denom string) sdk.Coin - 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/kavamint/types/genesis.go b/x/kavamint/types/genesis.go deleted file mode 100644 index e5ec4fb5..00000000 --- a/x/kavamint/types/genesis.go +++ /dev/null @@ -1,32 +0,0 @@ -package types - -import ( - time "time" -) - -var ( - // DefaultPreviousBlockTime represents a time that is unset -- no previous block has occured - DefaultPreviousBlockTime = time.Time{} -) - -// NewGenesisState creates a new GenesisState object -func NewGenesisState(params Params, previousBlockTime time.Time) *GenesisState { - return &GenesisState{ - Params: params, - PreviousBlockTime: previousBlockTime, - } -} - -// DefaultGenesisState creates a default GenesisState object -func DefaultGenesisState() *GenesisState { - return &GenesisState{ - Params: DefaultParams(), - PreviousBlockTime: DefaultPreviousBlockTime, - } -} - -// Validate validates the provided genesis state to ensure the -// expected invariants holds. -func (gs GenesisState) Validate() error { - return gs.Params.Validate() -} diff --git a/x/kavamint/types/genesis.pb.go b/x/kavamint/types/genesis.pb.go deleted file mode 100644 index 6750080f..00000000 --- a/x/kavamint/types/genesis.pb.go +++ /dev/null @@ -1,372 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: kava/kavamint/v1beta1/genesis.proto - -package types - -import ( - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" - _ "google.golang.org/protobuf/types/known/timestamppb" - io "io" - math "math" - math_bits "math/bits" - time "time" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf -var _ = time.Kitchen - -// 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 kavamint module's genesis state. -type GenesisState struct { - // Params defines all the parameters of the module. - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - // PreviousBlockTime holds the last last time tokens were minted. - // On first block, tokens will be minted for total number of seconds passed since this time. - PreviousBlockTime time.Time `protobuf:"bytes,2,opt,name=previous_block_time,json=previousBlockTime,proto3,stdtime" json:"previous_block_time"` -} - -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_179d81c8ae95ec37, []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 init() { - proto.RegisterType((*GenesisState)(nil), "kava.kavamint.v1beta1.GenesisState") -} - -func init() { - proto.RegisterFile("kava/kavamint/v1beta1/genesis.proto", fileDescriptor_179d81c8ae95ec37) -} - -var fileDescriptor_179d81c8ae95ec37 = []byte{ - // 286 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xce, 0x4e, 0x2c, 0x4b, - 0xd4, 0x07, 0x11, 0xb9, 0x99, 0x79, 0x25, 0xfa, 0x65, 0x86, 0x49, 0xa9, 0x25, 0x89, 0x86, 0xfa, - 0xe9, 0xa9, 0x79, 0xa9, 0xc5, 0x99, 0xc5, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xa2, 0x20, - 0x79, 0x3d, 0x98, 0x22, 0x3d, 0xa8, 0x22, 0x29, 0x91, 0xf4, 0xfc, 0xf4, 0x7c, 0xb0, 0x0a, 0x7d, - 0x10, 0x0b, 0xa2, 0x58, 0x4a, 0x3e, 0x3d, 0x3f, 0x3f, 0x3d, 0x27, 0x55, 0x1f, 0xcc, 0x4b, 0x2a, - 0x4d, 0xd3, 0x2f, 0xc9, 0xcc, 0x4d, 0x2d, 0x2e, 0x49, 0xcc, 0x2d, 0x80, 0x2a, 0x50, 0xc1, 0x6e, - 0x25, 0xdc, 0x78, 0xb0, 0x2a, 0xa5, 0xe5, 0x8c, 0x5c, 0x3c, 0xee, 0x10, 0x57, 0x04, 0x97, 0x24, - 0x96, 0xa4, 0x0a, 0x59, 0x73, 0xb1, 0x15, 0x24, 0x16, 0x25, 0xe6, 0x16, 0x4b, 0x30, 0x2a, 0x30, - 0x6a, 0x70, 0x1b, 0xc9, 0xea, 0x61, 0x75, 0x95, 0x5e, 0x00, 0x58, 0x91, 0x13, 0xcb, 0x89, 0x7b, - 0xf2, 0x0c, 0x41, 0x50, 0x2d, 0x42, 0x21, 0x5c, 0xc2, 0x05, 0x45, 0xa9, 0x65, 0x99, 0xf9, 0xa5, - 0xc5, 0xf1, 0x49, 0x39, 0xf9, 0xc9, 0xd9, 0xf1, 0x20, 0x57, 0x49, 0x30, 0x81, 0x4d, 0x92, 0xd2, - 0x83, 0x38, 0x59, 0x0f, 0xe6, 0x64, 0xbd, 0x10, 0x98, 0x93, 0x9d, 0x38, 0x40, 0xc6, 0x4c, 0xb8, - 0x2f, 0xcf, 0x18, 0x24, 0x08, 0x33, 0xc0, 0x09, 0xa4, 0x1f, 0xa4, 0xc2, 0x8a, 0xa5, 0x63, 0x81, - 0x3c, 0x83, 0x93, 0xcb, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, - 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x69, 0xa5, - 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0x82, 0xbd, 0xa7, 0x9b, 0x93, 0x98, 0x54, - 0x0c, 0x66, 0xe9, 0x57, 0x20, 0x02, 0xa0, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0x6c, 0xb9, - 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x2f, 0x48, 0xff, 0xce, 0x91, 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 - n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.PreviousBlockTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.PreviousBlockTime):]) - if err1 != nil { - return 0, err1 - } - i -= n1 - i = encodeVarintGenesis(dAtA, i, uint64(n1)) - i-- - dAtA[i] = 0x12 - { - size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { - offset -= sovGenesis(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *GenesisState) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.Params.Size() - n += 1 + l + sovGenesis(uint64(l)) - l = github_com_gogo_protobuf_types.SizeOfStdTime(m.PreviousBlockTime) - n += 1 + l + sovGenesis(uint64(l)) - return n -} - -func sovGenesis(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozGenesis(x uint64) (n int) { - return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *GenesisState) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PreviousBlockTime", 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 := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.PreviousBlockTime, 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/kavamint/types/genesis_test.go b/x/kavamint/types/genesis_test.go deleted file mode 100644 index e9c24915..00000000 --- a/x/kavamint/types/genesis_test.go +++ /dev/null @@ -1,149 +0,0 @@ -package types_test - -import ( - "encoding/json" - "testing" - - time "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "sigs.k8s.io/yaml" - - "github.com/kava-labs/kava/x/kavamint/types" -) - -func TestGenesis_Default(t *testing.T) { - defaultGenesis := types.DefaultGenesisState() - - require.NoError(t, defaultGenesis.Validate()) - - defaultParams := types.DefaultParams() - assert.Equal(t, defaultParams, defaultGenesis.Params) -} - -func TestGenesis_Validation(t *testing.T) { - testCases := []struct { - name string - gs *types.GenesisState - expectedErr string - }{ - { - "valid - default genesis is valid", - types.DefaultGenesisState(), - "", - }, - { - "valid - valid genesis", - types.NewGenesisState( - newValidParams(t), - time.Now(), - ), - "", - }, - { - "valid - no inflation", - types.NewGenesisState( - types.NewParams(sdk.ZeroDec(), sdk.ZeroDec()), - time.Now(), - ), - "", - }, - { - "valid - no time set", - types.NewGenesisState( - newValidParams(t), - time.Time{}, - ), - "", - }, - { - "invalid - community inflation param too big", - types.NewGenesisState( - types.NewParams(types.MaxMintingRate.Add(sdk.NewDecWithPrec(1, 18)), sdk.ZeroDec()), - time.Now(), - ), - "invalid rate: 100.000000000000000001", - }, - { - "invalid - staking reward inflation param too big", - types.NewGenesisState( - // inflation is larger than is allowed! - types.NewParams(sdk.ZeroDec(), types.MaxMintingRate.Add(sdk.NewDecWithPrec(1, 18))), - time.Now(), - ), - "invalid rate: 100.000000000000000001", - }, - { - "invalid - negative community inflation param", - types.NewGenesisState( - types.NewParams(sdk.OneDec().MulInt64(-1), sdk.ZeroDec()), - time.Now(), - ), - "invalid rate: -1.000000000000000000", - }, - { - "invalid - negative staking inflation param", - types.NewGenesisState( - types.NewParams(sdk.ZeroDec(), sdk.OneDec().MulInt64(-1)), - time.Now(), - ), - "invalid rate: -1.000000000000000000", - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - err := tc.gs.Validate() - - if tc.expectedErr == "" { - assert.Nil(t, err) - } else { - assert.EqualError(t, err, tc.expectedErr) - } - }) - } -} - -func TestGenesis_JSONEncoding(t *testing.T) { - raw := `{ - "params": { - "community_pool_inflation": "0.000000000000000001", - "staking_rewards_apy": "0.000000000000000002" - }, - "previous_block_time": "2022-12-01T11:30:55.000000001Z" - }` - - var state types.GenesisState - err := json.Unmarshal([]byte(raw), &state) - require.NoError(t, err) - - assert.Equal(t, sdk.MustNewDecFromStr("0.000000000000000001"), state.Params.CommunityPoolInflation) - assert.Equal(t, sdk.MustNewDecFromStr("0.000000000000000002"), state.Params.StakingRewardsApy) - - prevBlockTime, err := time.Parse(time.RFC3339, "2022-12-01T11:30:55.000000001Z") - require.NoError(t, err) - - assert.Equal(t, prevBlockTime, state.PreviousBlockTime) -} - -func TestGenesis_YAMLEncoding(t *testing.T) { - expected := `params: - community_pool_inflation: "0.000000000000000001" - staking_rewards_apy: "0.000000000000000002" -previous_block_time: "2022-12-01T11:30:55.000000001Z" -` - prevBlockTime, err := time.Parse(time.RFC3339, "2022-12-01T11:30:55.000000001Z") - require.NoError(t, err) - - state := types.NewGenesisState( - types.NewParams(sdk.MustNewDecFromStr("0.000000000000000001"), sdk.MustNewDecFromStr("0.000000000000000002")), - prevBlockTime, - ) - - data, err := yaml.Marshal(state) - require.NoError(t, err) - - assert.Equal(t, expected, string(data)) -} diff --git a/x/kavamint/types/kavamint.pb.go b/x/kavamint/types/kavamint.pb.go deleted file mode 100644 index b04237f5..00000000 --- a/x/kavamint/types/kavamint.pb.go +++ /dev/null @@ -1,373 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: kava/kavamint/v1beta1/kavamint.proto - -package types - -import ( - fmt "fmt" - _ "github.com/cosmos/cosmos-proto" - 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 - -// Params wraps the governance parameters for the kavamint module -type Params struct { - // yearly inflation of total token supply minted to the community pool. - CommunityPoolInflation github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=community_pool_inflation,json=communityPoolInflation,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"community_pool_inflation"` - // yearly inflation of bonded tokens minted for staking rewards to validators. - StakingRewardsApy github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=staking_rewards_apy,json=stakingRewardsApy,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"staking_rewards_apy"` -} - -func (m *Params) Reset() { *m = Params{} } -func (*Params) ProtoMessage() {} -func (*Params) Descriptor() ([]byte, []int) { - return fileDescriptor_bdfe36d50f127f04, []int{0} -} -func (m *Params) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Params.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Params) XXX_Merge(src proto.Message) { - xxx_messageInfo_Params.Merge(m, src) -} -func (m *Params) XXX_Size() int { - return m.Size() -} -func (m *Params) XXX_DiscardUnknown() { - xxx_messageInfo_Params.DiscardUnknown(m) -} - -var xxx_messageInfo_Params proto.InternalMessageInfo - -func init() { - proto.RegisterType((*Params)(nil), "kava.kavamint.v1beta1.Params") -} - -func init() { - proto.RegisterFile("kava/kavamint/v1beta1/kavamint.proto", fileDescriptor_bdfe36d50f127f04) -} - -var fileDescriptor_bdfe36d50f127f04 = []byte{ - // 293 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xc9, 0x4e, 0x2c, 0x4b, - 0xd4, 0x07, 0x11, 0xb9, 0x99, 0x79, 0x25, 0xfa, 0x65, 0x86, 0x49, 0xa9, 0x25, 0x89, 0x86, 0x70, - 0x01, 0xbd, 0x82, 0xa2, 0xfc, 0x92, 0x7c, 0x21, 0x51, 0x10, 0x5f, 0x0f, 0x2e, 0x08, 0x55, 0x25, - 0x25, 0x99, 0x9c, 0x5f, 0x9c, 0x9b, 0x5f, 0x1c, 0x0f, 0x56, 0xa4, 0x0f, 0xe1, 0x40, 0x74, 0x48, - 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x43, 0xc4, 0x41, 0x2c, 0x88, 0xa8, 0xd2, 0x0f, 0x46, 0x2e, 0xb6, - 0x80, 0xc4, 0xa2, 0xc4, 0xdc, 0x62, 0xa1, 0x32, 0x2e, 0x89, 0xe4, 0xfc, 0xdc, 0xdc, 0xd2, 0xbc, - 0xcc, 0x92, 0xca, 0xf8, 0x82, 0xfc, 0xfc, 0x9c, 0xf8, 0xcc, 0xbc, 0xb4, 0x9c, 0xc4, 0x92, 0xcc, - 0xfc, 0x3c, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x4e, 0x27, 0x9b, 0x13, 0xf7, 0xe4, 0x19, 0x6e, 0xdd, - 0x93, 0x57, 0x4b, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0x85, 0xda, 0x01, 0xa5, - 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0xf5, 0x5c, 0x52, 0x93, 0x2f, 0x6d, - 0xd1, 0xe5, 0x82, 0x3a, 0xc1, 0x25, 0x35, 0x39, 0x48, 0x0c, 0x6e, 0x7a, 0x40, 0x7e, 0x7e, 0x8e, - 0x27, 0xcc, 0x6c, 0xa1, 0x1c, 0x2e, 0xe1, 0xe2, 0x92, 0xc4, 0xec, 0xcc, 0xbc, 0xf4, 0xf8, 0xa2, - 0xd4, 0xf2, 0xc4, 0xa2, 0x94, 0xe2, 0xf8, 0xc4, 0x82, 0x4a, 0x09, 0x26, 0x2a, 0x58, 0x29, 0x08, - 0x35, 0x38, 0x08, 0x62, 0xae, 0x63, 0x41, 0xa5, 0x15, 0x47, 0xc7, 0x02, 0x79, 0x86, 0x19, 0x0b, - 0xe4, 0x19, 0x9c, 0x5c, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, - 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x0b, - 0xc9, 0x32, 0x50, 0x10, 0xeb, 0xe6, 0x24, 0x26, 0x15, 0x83, 0x59, 0xfa, 0x15, 0x88, 0x98, 0x01, - 0x5b, 0x9a, 0xc4, 0x06, 0x0e, 0x47, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x8a, 0xce, 0xb7, - 0xff, 0xb7, 0x01, 0x00, 0x00, -} - -func (m *Params) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Params) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.StakingRewardsApy.Size() - i -= size - if _, err := m.StakingRewardsApy.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintKavamint(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - { - size := m.CommunityPoolInflation.Size() - i -= size - if _, err := m.CommunityPoolInflation.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintKavamint(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func encodeVarintKavamint(dAtA []byte, offset int, v uint64) int { - offset -= sovKavamint(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Params) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.CommunityPoolInflation.Size() - n += 1 + l + sovKavamint(uint64(l)) - l = m.StakingRewardsApy.Size() - n += 1 + l + sovKavamint(uint64(l)) - return n -} - -func sovKavamint(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozKavamint(x uint64) (n int) { - return sovKavamint(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Params) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKavamint - } - 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 CommunityPoolInflation", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKavamint - } - 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 ErrInvalidLengthKavamint - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthKavamint - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.CommunityPoolInflation.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StakingRewardsApy", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKavamint - } - 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 ErrInvalidLengthKavamint - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthKavamint - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.StakingRewardsApy.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipKavamint(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthKavamint - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipKavamint(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, ErrIntOverflowKavamint - } - 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, ErrIntOverflowKavamint - } - 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, ErrIntOverflowKavamint - } - 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, ErrInvalidLengthKavamint - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupKavamint - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthKavamint - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthKavamint = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowKavamint = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupKavamint = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/kavamint/types/keys.go b/x/kavamint/types/keys.go deleted file mode 100644 index bc9a4517..00000000 --- a/x/kavamint/types/keys.go +++ /dev/null @@ -1,18 +0,0 @@ -package types - -const ( - // module name - ModuleName = "kavamint" - - // ModuleAccountName is the name of the module's account - ModuleAccountName = ModuleName - - // StoreKey is the default store key for mint - StoreKey = ModuleName - - // QuerierRoute is the querier route for the minting store. - QuerierRoute = StoreKey -) - -// PreviousBlockTimeKey is the store key for the previous block time -var PreviousBlockTimeKey = []byte{0x00} diff --git a/x/kavamint/types/params.go b/x/kavamint/types/params.go deleted file mode 100644 index b546c557..00000000 --- a/x/kavamint/types/params.go +++ /dev/null @@ -1,87 +0,0 @@ -package types - -import ( - fmt "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -) - -// Parameter keys and default values -var ( - KeyCommunityPoolInflation = []byte("CommunityPoolInflation") - KeyStakingRewardsApy = []byte("StakingRewardsApy") - - // default inflation values are zero - DefaultCommunityPoolInflation = sdk.ZeroDec() - DefaultStakingRewardsApy = sdk.ZeroDec() - - // MaxMintingRate returns the per second rate equivalent to 10,000% per year - MaxMintingRate = sdk.NewDec(100) -) - -// NewParams returns new Params with inflation rates set -func NewParams(communityPoolInflation sdk.Dec, stakingRewardsApy sdk.Dec) Params { - return Params{ - CommunityPoolInflation: communityPoolInflation, - StakingRewardsApy: stakingRewardsApy, - } -} - -// ParamKeyTable returns the key table for the kavamint module -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - -// ParamSetPairs implements the ParamSet interface and returns all the key/value pairs -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyCommunityPoolInflation, &p.CommunityPoolInflation, validateCommunityPoolInflation), - paramtypes.NewParamSetPair(KeyStakingRewardsApy, &p.StakingRewardsApy, validateStakingRewardsApy), - } -} - -// DefaultParams returns default valid parameters for the kavamint module -func DefaultParams() Params { - return NewParams(DefaultCommunityPoolInflation, DefaultStakingRewardsApy) -} - -// Validate checks that the parameters have valid values. -func (p *Params) Validate() error { - if err := validateCommunityPoolInflation(p.CommunityPoolInflation); err != nil { - return err - } - return validateStakingRewardsApy(p.StakingRewardsApy) -} - -// String implements fmt.Stringer -func (p Params) String() string { - return fmt.Sprintf(`Params: - CommunityPoolInflation: %s - StakingRewardsApy: %s`, - p.CommunityPoolInflation, p.StakingRewardsApy) -} - -func validateCommunityPoolInflation(i interface{}) error { - rate, ok := i.(sdk.Dec) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - return validateRate(rate) -} - -func validateStakingRewardsApy(i interface{}) error { - rate, ok := i.(sdk.Dec) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - return validateRate(rate) -} - -// validateRate ensures rate is properly initialized (non-nil), not negative, and not greater than the max rate -func validateRate(rate sdk.Dec) error { - if rate.IsNil() || rate.IsNegative() || rate.GT(MaxMintingRate) { - return fmt.Errorf(fmt.Sprintf("invalid rate: %s", rate)) - } - return nil -} diff --git a/x/kavamint/types/params_test.go b/x/kavamint/types/params_test.go deleted file mode 100644 index 808a4c9b..00000000 --- a/x/kavamint/types/params_test.go +++ /dev/null @@ -1,297 +0,0 @@ -package types_test - -import ( - "bytes" - "encoding/json" - fmt "fmt" - "reflect" - "testing" - - "github.com/kava-labs/kava/x/kavamint/types" - - sdk "github.com/cosmos/cosmos-sdk/types" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "sigs.k8s.io/yaml" -) - -const secondsPerYear = 31536000 - -func newValidParams(t *testing.T) types.Params { - // 50% - poolRate := sdk.MustNewDecFromStr("0.5") - - // 10% - stakingRate := sdk.MustNewDecFromStr("0.1") - - params := types.NewParams(poolRate, stakingRate) - require.NoError(t, params.Validate()) - - return params -} - -func TestParams_Default(t *testing.T) { - defaultParams := types.DefaultParams() - - require.NoError(t, defaultParams.Validate(), "default parameters must be valid") - - assert.Equal(t, types.DefaultCommunityPoolInflation, defaultParams.CommunityPoolInflation, "expected default pool inflation to match exported default value") - assert.Equal(t, defaultParams.CommunityPoolInflation, sdk.ZeroDec(), "expected default pool inflation to be zero") - - assert.Equal(t, types.DefaultStakingRewardsApy, defaultParams.StakingRewardsApy, "expected default staking inflation to match exported default value") - assert.Equal(t, defaultParams.CommunityPoolInflation, sdk.ZeroDec(), "expected default staking inflation to be zero") -} - -func TestParams_MaxInflationRate_ApproxRootDoesNotPanic(t *testing.T) { - require.Equal(t, sdk.NewDec(100), types.MaxMintingRate) // 10,000%, should never be a reason to exceed this value - maxYearlyRate := types.MaxMintingRate - - require.NotPanics(t, func() { - expectedMaxRate, err := maxYearlyRate.ApproxRoot(secondsPerYear) - require.NoError(t, err) - expectedMaxRate = expectedMaxRate.Sub(sdk.OneDec()) - }) -} - -func TestParams_MaxInflationRate_DoesNotOverflow(t *testing.T) { - maxRate := types.MaxMintingRate // use the max minting rate - totalSupply := sdk.NewDec(1e14) // 100 trillion starting supply - years := uint64(25) // calculate over 50 years - - perSecondMaxRate, err := maxRate.ApproxRoot(secondsPerYear) - require.NoError(t, err) - perSecondMaxRate = perSecondMaxRate.Sub(sdk.OneDec()) - - var finalSupply sdk.Int - - require.NotPanics(t, func() { - compoundedRate := perSecondMaxRate.Power(years * secondsPerYear) - finalSupply = totalSupply.Mul(compoundedRate).RoundInt() - - }) - - require.Less(t, finalSupply.BigInt().BitLen(), 256) -} - -func TestParams_ParamSetPairs_CommunityPoolInflation(t *testing.T) { - assert.Equal(t, []byte("CommunityPoolInflation"), types.KeyCommunityPoolInflation) - defaultParams := types.DefaultParams() - - var paramSetPair *paramstypes.ParamSetPair - for _, pair := range defaultParams.ParamSetPairs() { - if bytes.Equal(pair.Key, types.KeyCommunityPoolInflation) { - paramSetPair = &pair - break - } - } - require.NotNil(t, paramSetPair) - - pairs, ok := paramSetPair.Value.(*sdk.Dec) - require.True(t, ok) - assert.Equal(t, pairs, &defaultParams.CommunityPoolInflation) - - assert.Nil(t, paramSetPair.ValidatorFn(*pairs)) - assert.EqualError(t, paramSetPair.ValidatorFn(struct{}{}), "invalid parameter type: struct {}") -} - -func TestParams_ParamSetPairs_StakingRewardsApy(t *testing.T) { - assert.Equal(t, []byte("StakingRewardsApy"), types.KeyStakingRewardsApy) - defaultParams := types.DefaultParams() - - var paramSetPair *paramstypes.ParamSetPair - for _, pair := range defaultParams.ParamSetPairs() { - if bytes.Equal(pair.Key, types.KeyStakingRewardsApy) { - paramSetPair = &pair - break - } - } - require.NotNil(t, paramSetPair) - - pairs, ok := paramSetPair.Value.(*sdk.Dec) - require.True(t, ok) - assert.Equal(t, pairs, &defaultParams.StakingRewardsApy) - - assert.Nil(t, paramSetPair.ValidatorFn(*pairs)) - assert.EqualError(t, paramSetPair.ValidatorFn(struct{}{}), "invalid parameter type: struct {}") -} - -func TestParams_Validation(t *testing.T) { - testCases := []struct { - name string - key []byte - testFn func(params *types.Params) - expectedErr string - }{ - { - name: "nil community pool inflation", - key: types.KeyCommunityPoolInflation, - testFn: func(params *types.Params) { - params.CommunityPoolInflation = sdk.Dec{} - }, - expectedErr: "invalid rate: ", - }, - { - name: "negative community pool inflation", - key: types.KeyCommunityPoolInflation, - testFn: func(params *types.Params) { - params.CommunityPoolInflation = sdk.MustNewDecFromStr("-0.000000000011111111") - }, - expectedErr: "invalid rate: -0.000000000011111111", - }, - { - name: "0 community pool inflation", - key: types.KeyCommunityPoolInflation, - testFn: func(params *types.Params) { - params.CommunityPoolInflation = sdk.ZeroDec() - }, - expectedErr: "", // ok - }, - { - name: "community pool inflation 1e-18 less than max rate", - key: types.KeyCommunityPoolInflation, - testFn: func(params *types.Params) { - params.CommunityPoolInflation = types.MaxMintingRate.Sub(sdk.NewDecWithPrec(1, 18)) - }, - expectedErr: "", // ok - }, - { - name: "community pool inflation equal to max rate", - key: types.KeyCommunityPoolInflation, - testFn: func(params *types.Params) { - params.CommunityPoolInflation = types.MaxMintingRate - }, - expectedErr: "", // ok - }, - { - name: "community pool inflation 1e-18 greater than max rate", - key: types.KeyCommunityPoolInflation, - testFn: func(params *types.Params) { - params.CommunityPoolInflation = types.MaxMintingRate.Add(sdk.NewDecWithPrec(1, 18)) - }, - expectedErr: "invalid rate: 100.000000000000000001", - }, - { - name: "nil staking inflation", - key: types.KeyStakingRewardsApy, - testFn: func(params *types.Params) { - params.StakingRewardsApy = sdk.Dec{} - }, - expectedErr: "invalid rate: ", - }, - { - name: "negative staking inflation", - key: types.KeyStakingRewardsApy, - testFn: func(params *types.Params) { - params.StakingRewardsApy = sdk.MustNewDecFromStr("-0.000000002222222222") - }, - expectedErr: "invalid rate: -0.000000002222222222", - }, - { - name: "0 staking inflation", - key: types.KeyStakingRewardsApy, - testFn: func(params *types.Params) { - params.StakingRewardsApy = sdk.ZeroDec() - }, - expectedErr: "", // ok - }, - { - name: "staking inflation 1e-18 less than max rate", - key: types.KeyStakingRewardsApy, - testFn: func(params *types.Params) { - params.StakingRewardsApy = types.MaxMintingRate.Sub(sdk.NewDecWithPrec(1, 18)) - }, - expectedErr: "", // ok - }, - { - name: "staking inflation equal to max rate", - key: types.KeyStakingRewardsApy, - testFn: func(params *types.Params) { - params.StakingRewardsApy = types.MaxMintingRate - }, - expectedErr: "", // ok - }, - { - name: "staking inflation 1e-18 greater than max rate", - key: types.KeyStakingRewardsApy, - testFn: func(params *types.Params) { - params.StakingRewardsApy = types.MaxMintingRate.Add(sdk.NewDecWithPrec(1, 18)) - }, - expectedErr: "invalid rate: 100.000000000000000001", - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - params := types.DefaultParams() - tc.testFn(¶ms) - - err := params.Validate() - - if tc.expectedErr == "" { - assert.Nil(t, err) - } else { - assert.EqualError(t, err, tc.expectedErr) - } - - var paramSetPair *paramstypes.ParamSetPair - for _, pair := range params.ParamSetPairs() { - if bytes.Equal(pair.Key, tc.key) { - paramSetPair = &pair - break - } - } - require.NotNil(t, paramSetPair) - value := reflect.ValueOf(paramSetPair.Value).Elem().Interface() - - // assert validation error is same as param set validation - assert.Equal(t, err, paramSetPair.ValidatorFn(value)) - }) - } -} - -func TestParams_String(t *testing.T) { - params := newValidParams(t) - - output := params.String() - assert.Contains(t, output, fmt.Sprintf("CommunityPoolInflation: %s", params.CommunityPoolInflation.String())) - assert.Contains(t, output, fmt.Sprintf("StakingRewardsApy: %s", params.StakingRewardsApy.String())) -} - -func TestParams_UnmarshalJSON(t *testing.T) { - params := newValidParams(t) - - poolRateData, err := json.Marshal(params.CommunityPoolInflation) - require.NoError(t, err) - - stakingRateData, err := json.Marshal(params.StakingRewardsApy) - require.NoError(t, err) - - data := fmt.Sprintf(`{ - "community_pool_inflation": %s, - "staking_rewards_apy": %s -}`, string(poolRateData), string(stakingRateData)) - - var parsedParams types.Params - err = json.Unmarshal([]byte(data), &parsedParams) - require.NoError(t, err) - - assert.Equal(t, params.CommunityPoolInflation, parsedParams.CommunityPoolInflation) - assert.Equal(t, params.StakingRewardsApy, parsedParams.StakingRewardsApy) -} - -func TestParams_MarshalYAML(t *testing.T) { - p := newValidParams(t) - - data, err := yaml.Marshal(p) - require.NoError(t, err) - - var params map[string]interface{} - err = yaml.Unmarshal(data, ¶ms) - require.NoError(t, err) - - _, ok := params["community_pool_inflation"] - require.True(t, ok) - _, ok = params["staking_rewards_apy"] - require.True(t, ok) -} diff --git a/x/kavamint/types/query.pb.go b/x/kavamint/types/query.pb.go deleted file mode 100644 index 9427de8a..00000000 --- a/x/kavamint/types/query.pb.go +++ /dev/null @@ -1,870 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: kava/kavamint/v1beta1/query.proto - -package types - -import ( - context "context" - fmt "fmt" - _ "github.com/cosmos/cosmos-proto" - 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 defines the request type for querying x/kavamint parameters. -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_3a66171519c59de7, []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 defines the response type for querying x/kavamint parameters. -type QueryParamsResponse struct { - 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_3a66171519c59de7, []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_3a66171519c59de7, []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. - // example "0.990000000000000000" - 99% inflation - 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_3a66171519c59de7, []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 - -func init() { - proto.RegisterType((*QueryParamsRequest)(nil), "kava.kavamint.v1beta1.QueryParamsRequest") - proto.RegisterType((*QueryParamsResponse)(nil), "kava.kavamint.v1beta1.QueryParamsResponse") - proto.RegisterType((*QueryInflationRequest)(nil), "kava.kavamint.v1beta1.QueryInflationRequest") - proto.RegisterType((*QueryInflationResponse)(nil), "kava.kavamint.v1beta1.QueryInflationResponse") -} - -func init() { proto.RegisterFile("kava/kavamint/v1beta1/query.proto", fileDescriptor_3a66171519c59de7) } - -var fileDescriptor_3a66171519c59de7 = []byte{ - // 397 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcc, 0x4e, 0x2c, 0x4b, - 0xd4, 0x07, 0x11, 0xb9, 0x99, 0x79, 0x25, 0xfa, 0x65, 0x86, 0x49, 0xa9, 0x25, 0x89, 0x86, 0xfa, - 0x85, 0xa5, 0xa9, 0x45, 0x95, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xa2, 0x20, 0x59, 0x3d, - 0x98, 0x12, 0x3d, 0xa8, 0x12, 0x29, 0xc9, 0xe4, 0xfc, 0xe2, 0xdc, 0xfc, 0xe2, 0x78, 0xb0, 0x22, - 0x7d, 0x08, 0x07, 0xa2, 0x43, 0x4a, 0x24, 0x3d, 0x3f, 0x3d, 0x1f, 0x22, 0x0e, 0x62, 0x41, 0x45, - 0x65, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0x13, 0x0b, 0x32, 0xf5, 0x13, 0xf3, 0xf2, 0xf2, - 0x4b, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x60, 0x7a, 0x54, 0xb0, 0x3b, 0x04, 0x6e, 0x2d, 0x58, 0x95, - 0x92, 0x08, 0x97, 0x50, 0x20, 0xc8, 0x69, 0x01, 0x89, 0x45, 0x89, 0xb9, 0xc5, 0x41, 0xa9, 0x85, - 0xa5, 0xa9, 0xc5, 0x25, 0x4a, 0x41, 0x5c, 0xc2, 0x28, 0xa2, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, - 0x42, 0xd6, 0x5c, 0x6c, 0x05, 0x60, 0x11, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x59, 0x3d, - 0xac, 0x3e, 0xd1, 0x83, 0x68, 0x73, 0x62, 0x39, 0x71, 0x4f, 0x9e, 0x21, 0x08, 0xaa, 0x45, 0x49, - 0x9c, 0x4b, 0x14, 0x6c, 0xa6, 0x67, 0x5e, 0x5a, 0x0e, 0xd8, 0xa1, 0x30, 0xcb, 0x4a, 0xb8, 0xc4, - 0xd0, 0x25, 0xa0, 0xf6, 0x45, 0x71, 0x71, 0x66, 0xc2, 0x04, 0xc1, 0x56, 0x72, 0x3a, 0xd9, 0x80, - 0xcc, 0xbc, 0x75, 0x4f, 0x5e, 0x2d, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x17, - 0x1a, 0x54, 0x50, 0x4a, 0xb7, 0x38, 0x25, 0x5b, 0xbf, 0xa4, 0xb2, 0x20, 0xb5, 0x58, 0xcf, 0x25, - 0x35, 0xf9, 0xd2, 0x16, 0x5d, 0x2e, 0x68, 0x48, 0xba, 0xa4, 0x26, 0x07, 0x21, 0x8c, 0x33, 0x5a, - 0xca, 0xc4, 0xc5, 0x0a, 0xb6, 0x56, 0xa8, 0x8d, 0x91, 0x8b, 0x0d, 0xe2, 0x62, 0x21, 0x4d, 0x1c, - 0x1e, 0xc2, 0x0c, 0x22, 0x29, 0x2d, 0x62, 0x94, 0x42, 0xfc, 0xa1, 0xa4, 0xda, 0x74, 0xf9, 0xc9, - 0x64, 0x26, 0x79, 0x21, 0x59, 0x7d, 0xec, 0x71, 0x02, 0x09, 0x21, 0xa1, 0x49, 0x8c, 0x5c, 0x9c, - 0xf0, 0x40, 0x10, 0xd2, 0xc1, 0x67, 0x01, 0x7a, 0x20, 0x4a, 0xe9, 0x12, 0xa9, 0x1a, 0xea, 0x22, - 0x0d, 0xb0, 0x8b, 0x94, 0x84, 0x14, 0x70, 0xb8, 0x08, 0x1e, 0x4e, 0x4e, 0x2e, 0x27, 0x1e, 0xc9, - 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, - 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x85, 0x14, 0x05, 0x20, 0x03, 0x74, 0x73, 0x12, - 0x93, 0x8a, 0x21, 0xe6, 0x55, 0x20, 0x4c, 0x04, 0x47, 0x45, 0x12, 0x1b, 0x38, 0xb5, 0x19, 0x03, - 0x02, 0x00, 0x00, 0xff, 0xff, 0xfd, 0x9b, 0x02, 0x7d, 0x1e, 0x03, 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 queries the parameters of x/kavamint module. - Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) - // Inflation queries x/kavamint for the overall cumulative inflation rate of KAVA. - Inflation(ctx context.Context, in *QueryInflationRequest, opts ...grpc.CallOption) (*QueryInflationResponse, 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, "/kava.kavamint.v1beta1.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, "/kava.kavamint.v1beta1.Query/Inflation", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// QueryServer is the server API for Query service. -type QueryServer interface { - // Params queries the parameters of x/kavamint module. - Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) - // Inflation queries x/kavamint for the overall cumulative inflation rate of KAVA. - Inflation(context.Context, *QueryInflationRequest) (*QueryInflationResponse, 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 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: "/kava.kavamint.v1beta1.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: "/kava.kavamint.v1beta1.Query/Inflation", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Inflation(ctx, req.(*QueryInflationRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Query_serviceDesc = grpc.ServiceDesc{ - ServiceName: "kava.kavamint.v1beta1.Query", - HandlerType: (*QueryServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Params", - Handler: _Query_Params_Handler, - }, - { - MethodName: "Inflation", - Handler: _Query_Inflation_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "kava/kavamint/v1beta1/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 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 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 stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - 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 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/kavamint/types/query.pb.gw.go b/x/kavamint/types/query.pb.gw.go deleted file mode 100644 index 28e01ce0..00000000 --- a/x/kavamint/types/query.pb.gw.go +++ /dev/null @@ -1,218 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: kava/kavamint/v1beta1/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 - -} - -// 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()...) - - }) - - 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()...) - - }) - - return nil -} - -var ( - pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"kava", "kavamint", "v1beta1", "params"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_Inflation_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"kava", "kavamint", "v1beta1", "inflation"}, "", runtime.AssumeColonVerbOpt(false))) -) - -var ( - forward_Query_Params_0 = runtime.ForwardResponseMessage - - forward_Query_Inflation_0 = runtime.ForwardResponseMessage -)