diff --git a/Makefile b/Makefile
index d2f75138b79..3fb9b2438fb 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,5 @@
#!/usr/bin/make -f
-PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md
index 142e1312290..e01fb48042b 100644
--- a/docs/core/proto-docs.md
+++ b/docs/core/proto-docs.md
@@ -2533,15 +2533,17 @@ Msg defines the Msg service.
### DistributionProportions
-
+DistributionProportions defines the distribution proportions of the minted
+denom. In other words, defines which stakeholders will receive the minted
+denoms and how much.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
-| `staking` | [string](#string) | | staking defines the proportion of the minted minted_denom that is to be allocated as staking rewards. |
-| `pool_incentives` | [string](#string) | | pool_incentives defines the proportion of the minted minted_denom that is to be allocated as pool incentives. |
-| `developer_rewards` | [string](#string) | | developer_rewards defines the proportion of the minted minted_denom that is to be allocated to developer rewards address. |
-| `community_pool` | [string](#string) | | community_pool defines the proportion of the minted minted_denom that is to be allocated to the community pool. |
+| `staking` | [string](#string) | | staking defines the proportion of the minted mint_denom that is to be allocated as staking rewards. |
+| `pool_incentives` | [string](#string) | | pool_incentives defines the proportion of the minted mint_denom that is to be allocated as pool incentives. |
+| `developer_rewards` | [string](#string) | | developer_rewards defines the proportion of the minted mint_denom that is to be allocated to developer rewards address. |
+| `community_pool` | [string](#string) | | community_pool defines the proportion of the minted mint_denom that is to be allocated to the community pool. |
@@ -2556,7 +2558,7 @@ Minter represents the minting state.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
-| `epoch_provisions` | [string](#string) | | current epoch provisions |
+| `epoch_provisions` | [string](#string) | | epoch_provisions represent rewards for the current epoch. |
@@ -2566,19 +2568,19 @@ Minter represents the minting state.
### Params
-Params holds parameters for the mint module.
+Params holds parameters for the x/mint module.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
-| `mint_denom` | [string](#string) | | type of coin to mint |
-| `genesis_epoch_provisions` | [string](#string) | | epoch provisions from the first epoch |
-| `epoch_identifier` | [string](#string) | | mint epoch identifier |
-| `reduction_period_in_epochs` | [int64](#int64) | | number of epochs take to reduce rewards |
-| `reduction_factor` | [string](#string) | | reduction multiplier to execute on each period |
-| `distribution_proportions` | [DistributionProportions](#osmosis.mint.v1beta1.DistributionProportions) | | distribution_proportions defines the proportion of the minted denom |
-| `weighted_developer_rewards_receivers` | [WeightedAddress](#osmosis.mint.v1beta1.WeightedAddress) | repeated | address to receive developer rewards |
-| `minting_rewards_distribution_start_epoch` | [int64](#int64) | | start epoch to distribute minting rewards |
+| `mint_denom` | [string](#string) | | mint_denom is the denom of the coin to mint. |
+| `genesis_epoch_provisions` | [string](#string) | | genesis_epoch_provisions epoch provisions from the first epoch. |
+| `epoch_identifier` | [string](#string) | | epoch_identifier mint epoch identifier e.g. (day, week). |
+| `reduction_period_in_epochs` | [int64](#int64) | | reduction_period_in_epochs the number of epochs it takes to reduce the rewards. |
+| `reduction_factor` | [string](#string) | | reduction_factor is the reduction multiplier to execute at the end of each period set by reduction_period_in_epochs. |
+| `distribution_proportions` | [DistributionProportions](#osmosis.mint.v1beta1.DistributionProportions) | | distribution_proportions defines the distribution proportions of the minted denom. In other words, defines which stakeholders will receive the minted denoms and how much. |
+| `weighted_developer_rewards_receivers` | [WeightedAddress](#osmosis.mint.v1beta1.WeightedAddress) | repeated | weighted_developer_rewards_receivers is the address to receive developer rewards with weights assignedt to each address. The final amount that each address receives is: epoch_provisions * distribution_proportions.developer_rewards * Address's Weight. |
+| `minting_rewards_distribution_start_epoch` | [int64](#int64) | | minting_rewards_distribution_start_epoch start epoch to distribute minting rewards |
@@ -2588,7 +2590,9 @@ Params holds parameters for the mint module.
### WeightedAddress
-
+WeightedAddress represents an address with a weight assigned to it.
+The weight is used to determine the proportion of the total minted
+tokens to be minted to the address.
| Field | Type | Label | Description |
@@ -2625,9 +2629,9 @@ GenesisState defines the mint module's genesis state.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
-| `minter` | [Minter](#osmosis.mint.v1beta1.Minter) | | minter is a space for holding current rewards information. |
-| `params` | [Params](#osmosis.mint.v1beta1.Params) | | params defines all the paramaters of the module. |
-| `halven_started_epoch` | [int64](#int64) | | current halven period start epoch |
+| `minter` | [Minter](#osmosis.mint.v1beta1.Minter) | | minter is an abstraction for holding current rewards information. |
+| `params` | [Params](#osmosis.mint.v1beta1.Params) | | params defines all the paramaters of the mint module. |
+| `reduction_started_epoch` | [int64](#int64) | | reduction_started_epoch is the first epoch in which the reduction of mint begins. |
@@ -2716,7 +2720,7 @@ Query provides defines the gRPC querier service.
| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `Params` | [QueryParamsRequest](#osmosis.mint.v1beta1.QueryParamsRequest) | [QueryParamsResponse](#osmosis.mint.v1beta1.QueryParamsResponse) | Params returns the total set of minting parameters. | GET|/osmosis/mint/v1beta1/params|
-| `EpochProvisions` | [QueryEpochProvisionsRequest](#osmosis.mint.v1beta1.QueryEpochProvisionsRequest) | [QueryEpochProvisionsResponse](#osmosis.mint.v1beta1.QueryEpochProvisionsResponse) | EpochProvisions current minting epoch provisions value. | GET|/osmosis/mint/v1beta1/epoch_provisions|
+| `EpochProvisions` | [QueryEpochProvisionsRequest](#osmosis.mint.v1beta1.QueryEpochProvisionsRequest) | [QueryEpochProvisionsResponse](#osmosis.mint.v1beta1.QueryEpochProvisionsResponse) | EpochProvisions returns the current minting epoch provisions value. | GET|/osmosis/mint/v1beta1/epoch_provisions|
diff --git a/proto/osmosis/mint/v1beta1/genesis.proto b/proto/osmosis/mint/v1beta1/genesis.proto
index 8a4dd8fe286..ef215f37e68 100644
--- a/proto/osmosis/mint/v1beta1/genesis.proto
+++ b/proto/osmosis/mint/v1beta1/genesis.proto
@@ -8,13 +8,14 @@ option go_package = "github.com/osmosis-labs/osmosis/v10/x/mint/types";
// GenesisState defines the mint module's genesis state.
message GenesisState {
- // minter is a space for holding current rewards information.
+ // minter is an abstraction for holding current rewards information.
Minter minter = 1 [ (gogoproto.nullable) = false ];
- // params defines all the paramaters of the module.
+ // params defines all the paramaters of the mint module.
Params params = 2 [ (gogoproto.nullable) = false ];
- // current halven period start epoch
- int64 halven_started_epoch = 3
- [ (gogoproto.moretags) = "yaml:\"halven_started_epoch\"" ];
+ // reduction_started_epoch is the first epoch in which the reduction of mint
+ // begins.
+ int64 reduction_started_epoch = 3
+ [ (gogoproto.moretags) = "yaml:\"reduction_started_epoch\"" ];
}
diff --git a/proto/osmosis/mint/v1beta1/mint.proto b/proto/osmosis/mint/v1beta1/mint.proto
index 2f33028b0a3..f8502f6f6bf 100644
--- a/proto/osmosis/mint/v1beta1/mint.proto
+++ b/proto/osmosis/mint/v1beta1/mint.proto
@@ -10,7 +10,7 @@ import "google/protobuf/duration.proto";
// Minter represents the minting state.
message Minter {
- // current epoch provisions
+ // epoch_provisions represent rewards for the current epoch.
string epoch_provisions = 1 [
(gogoproto.moretags) = "yaml:\"epoch_provisions\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
@@ -18,6 +18,9 @@ message Minter {
];
}
+// WeightedAddress represents an address with a weight assigned to it.
+// The weight is used to determine the proportion of the total minted
+// tokens to be minted to the address.
message WeightedAddress {
string address = 1 [ (gogoproto.moretags) = "yaml:\"address\"" ];
string weight = 2 [
@@ -27,29 +30,32 @@ message WeightedAddress {
];
}
+// DistributionProportions defines the distribution proportions of the minted
+// denom. In other words, defines which stakeholders will receive the minted
+// denoms and how much.
message DistributionProportions {
- // staking defines the proportion of the minted minted_denom that is to be
+ // staking defines the proportion of the minted mint_denom that is to be
// allocated as staking rewards.
string staking = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"staking\"",
(gogoproto.nullable) = false
];
- // pool_incentives defines the proportion of the minted minted_denom that is
+ // pool_incentives defines the proportion of the minted mint_denom that is
// to be allocated as pool incentives.
string pool_incentives = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"pool_incentives\"",
(gogoproto.nullable) = false
];
- // developer_rewards defines the proportion of the minted minted_denom that is
+ // developer_rewards defines the proportion of the minted mint_denom that is
// to be allocated to developer rewards address.
string developer_rewards = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"developer_rewards\"",
(gogoproto.nullable) = false
];
- // community_pool defines the proportion of the minted minted_denom that is
+ // community_pool defines the proportion of the minted mint_denom that is
// to be allocated to the community pool.
string community_pool = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
@@ -58,39 +64,47 @@ message DistributionProportions {
];
}
-// Params holds parameters for the mint module.
+// Params holds parameters for the x/mint module.
message Params {
option (gogoproto.goproto_stringer) = false;
- // type of coin to mint
+ // mint_denom is the denom of the coin to mint.
string mint_denom = 1;
- // epoch provisions from the first epoch
+ // genesis_epoch_provisions epoch provisions from the first epoch.
string genesis_epoch_provisions = 2 [
(gogoproto.moretags) = "yaml:\"genesis_epoch_provisions\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
- // mint epoch identifier
+ // epoch_identifier mint epoch identifier e.g. (day, week).
string epoch_identifier = 3
[ (gogoproto.moretags) = "yaml:\"epoch_identifier\"" ];
- // number of epochs take to reduce rewards
+ // reduction_period_in_epochs the number of epochs it takes
+ // to reduce the rewards.
int64 reduction_period_in_epochs = 4
[ (gogoproto.moretags) = "yaml:\"reduction_period_in_epochs\"" ];
- // reduction multiplier to execute on each period
+ // reduction_factor is the reduction multiplier to execute
+ // at the end of each period set by reduction_period_in_epochs.
string reduction_factor = 5 [
(gogoproto.moretags) = "yaml:\"reduction_factor\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
- // distribution_proportions defines the proportion of the minted denom
+ // distribution_proportions defines the distribution proportions of the minted
+ // denom. In other words, defines which stakeholders will receive the minted
+ // denoms and how much.
DistributionProportions distribution_proportions = 6
[ (gogoproto.nullable) = false ];
- // address to receive developer rewards
+ // weighted_developer_rewards_receivers is the address to receive developer
+ // rewards with weights assignedt to each address. The final amount that each
+ // address receives is: epoch_provisions *
+ // distribution_proportions.developer_rewards * Address's Weight.
repeated WeightedAddress weighted_developer_rewards_receivers = 7 [
(gogoproto.moretags) = "yaml:\"developer_rewards_receiver\"",
(gogoproto.nullable) = false
];
- // start epoch to distribute minting rewards
+ // minting_rewards_distribution_start_epoch start epoch to distribute minting
+ // rewards
int64 minting_rewards_distribution_start_epoch = 8
[ (gogoproto.moretags) =
"yaml:\"minting_rewards_distribution_start_epoch\"" ];
diff --git a/proto/osmosis/mint/v1beta1/query.proto b/proto/osmosis/mint/v1beta1/query.proto
index 6812437ccf8..8cd9aecfc46 100644
--- a/proto/osmosis/mint/v1beta1/query.proto
+++ b/proto/osmosis/mint/v1beta1/query.proto
@@ -14,7 +14,7 @@ service Query {
option (google.api.http).get = "/osmosis/mint/v1beta1/params";
}
- // EpochProvisions current minting epoch provisions value.
+ // EpochProvisions returns the current minting epoch provisions value.
rpc EpochProvisions(QueryEpochProvisionsRequest)
returns (QueryEpochProvisionsResponse) {
option (google.api.http).get = "/osmosis/mint/v1beta1/epoch_provisions";
diff --git a/proto/osmosis/superfluid/query.proto b/proto/osmosis/superfluid/query.proto
index bffe9a0cd07..b8a3da4e761 100644
--- a/proto/osmosis/superfluid/query.proto
+++ b/proto/osmosis/superfluid/query.proto
@@ -256,4 +256,4 @@ message EstimateSuperfluidDelegatedAmountByValidatorDenomResponse {
// (gogoproto.nullable) = false,
// (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
// ];
-// }
\ No newline at end of file
+// }
diff --git a/x/mint/spec/README.md b/x/mint/README.md
similarity index 79%
rename from x/mint/spec/README.md
rename to x/mint/README.md
index c4b30dca5c1..2ba6a0bdd66 100644
--- a/x/mint/spec/README.md
+++ b/x/mint/README.md
@@ -1,11 +1,13 @@
# Mint
-The ```mint``` module is responsible for creating tokens in a flexible way to reward
-validators, incentivize providing pool liquidity, provide funds for Osmosis governance, and pay developers to maintain and improve Osmosis.
+The `mint` module is responsible for creating tokens in a flexible way to reward
+validators, incentivize providing pool liquidity, provide funds for Osmosis governance,
+and pay developers to maintain and improve Osmosis.
-The module is also responsible for reducing the token creation and distribution by a set amount and a set period of time until it reaches its maximum supply (see ```reduction_factor``` and ```reduction_period_in_epochs```)
+The module is also responsible for reducing the token creation and distribution by a set period
+until it reaches its maximum supply (see `reduction_factor` and `reduction_period_in_epochs`)
-Module uses time basis epochs supported by ```epochs``` module.
+The module uses time basis epochs supported by the `epochs` module.
## Contents
@@ -23,19 +25,19 @@ The `x/mint` module is designed to handle the regular printing of new
tokens within a chain. The design taken within Osmosis is to
- Mint new tokens once per epoch (default one week)
-- To have a "Reductioning factor" every period, which reduces the
- amount of rewards per epoch. (default: period is 3 years, where a
+- To have a "Reductioning factor" every period, which reduces the number of
+ rewards per epoch. (default: period is 3 years, where a
year is 52 epochs. The next period's rewards are 2/3 of the prior
period's rewards)
-### Reductioning factor
+### Reduction factor
-This is a generalization over the Bitcoin style halvenings. Every year,
-the amount of rewards issued per week will reduce by a governance
-specified factor, instead of a fixed `1/2`. So
+This is a generalization over the Bitcoin-style halvenings. Every year, the number
+ of rewards issued per week will reduce by a governance-specified
+factor, instead of a fixed `1/2`. So
`RewardsPerEpochNextPeriod = ReductionFactor * CurrentRewardsPerEpoch)`.
When `ReductionFactor = 1/2`, the Bitcoin halvenings are recreated. We
-default to having a reduction factor of `2/3`, and thus reduce rewards
+default to having a reduction factor of `2/3` and thus reduce rewards
at the end of every year by `33%`.
The implication of this is that the total supply is finite, according to
@@ -47,7 +49,7 @@ the following formula:
### Minter
-The minter is a space for holding current rewards information.
+The [`Minter`](https://github.com/osmosis-labs/osmosis/blob/cbb683e8395655042b4421355cd54a8c96bfa507/x/mint/types/mint.pb.go#L30) is an abstraction for holding current rewards information.
```go
type Minter struct {
@@ -57,65 +59,33 @@ type Minter struct {
### Params
-Minting params are held in the global params store.
+Minting [`Params`](https://github.com/osmosis-labs/osmosis/blob/cbb683e8395655042b4421355cd54a8c96bfa507/x/mint/types/mint.pb.go#L168) are held in the global params store.
-```go
-type Params struct {
- MintDenom string // type of coin to mint
- GenesisEpochProvisions sdk.Dec // initial epoch provisions at genesis
- EpochIdentifier string // identifier of epoch
- ReductionPeriodInEpochs int64 // number of epochs between reward reductions
- ReductionFactor sdk.Dec // reduction multiplier to execute on each period
- DistributionProportions DistributionProportions // distribution_proportions defines the proportion of the minted denom
- WeightedDeveloperRewardsReceivers []WeightedAddress // address to receive developer rewards
- MintingRewardsDistributionStartEpoch int64 // start epoch to distribute minting rewards
-}
-```
+### LastReductionEpoch
-### LastHalvenEpoch
-
-Last halven epoch stores the epoch number when the last reduction of
+Last reduction epoch stores the epoch number when the last reduction of
coin mint amount per epoch has happened.
-**TODO:**
-
-- Update the name to LastReductionEpoch as the reduction amount could
- be set by governance.
-
## Begin-Epoch
-Minting parameters are recalculated and inflation paid at the beginning
-of each epoch. An epoch is signalled by x/epochs
+Minting parameters are recalculated and inflation is paid at the beginning
+of each epoch. An epoch is signaled by x/epochs
### NextEpochProvisions
The target epoch provision is recalculated on each reduction period
-(default 3 years). At the time of reduction, the current provision is
-multiplied by reduction factor (default `2/3`), to calculate the
+(default 3 years). At the time of the reduction, the current provision is
+multiplied by the reduction factor (default `2/3`), to calculate the
provisions for the next epoch. Consequently, the rewards of the next
-period will be lowered by `1 - reduction factor`.
-
-``` go
-func (m Minter) NextEpochProvisions(params Params) sdk.Dec {
- return m.EpochProvisions.Mul(params.ReductionFactor)
-}
-```
+period will be lowered by a `1` - reduction factor.
### EpochProvision
Calculate the provisions generated for each epoch based on current epoch
provisions. The provisions are then minted by the `mint` module's
`ModuleMinterAccount`. These rewards are transferred to a
-`FeeCollector`, which handles distributing the rewards per the chains
-needs. (See TODO.md for details) This fee collector is specified as the
-`auth` module's `FeeCollector` `ModuleAccount`.
-
-``` go
-func (m Minter) EpochProvision(params Params) sdk.Coin {
- provisionAmt := m.EpochProvisions.QuoInt(sdk.NewInt(int64(params.EpochsPerYear)))
- return sdk.NewCoin(params.MintDenom, provisionAmt.TruncateInt())
-}
-```
+`FeeCollector`, which handles distributing the rewards per the chain's needs.
+This fee collector is specified as the `auth` module's `FeeCollector` `ModuleAccount`.
## Network Parameters
@@ -139,10 +109,10 @@ The minting module contains the following parameters:
Below are all the network parameters for the ```mint``` module:
- **```mint_denom```** - Token type being minted
-- **```genesis_epoch_provisions```** - Amount of tokens generated at epoch to the distribution categories (see distribution_proportions)
+- **```genesis_epoch_provisions```** - Amount of tokens generated at the epoch to the distribution categories (see distribution_proportions)
- **```epoch_identifier```** - Type of epoch that triggers token issuance (day, week, etc.)
- **```reduction_period_in_epochs```** - How many epochs must occur before implementing the reduction factor
-- **```reduction_factor```** - What the total token issuance factor will reduce by after reduction period passes (if set to 66.66%, token issuance will reduce by 1/3)
+- **```reduction_factor```** - What the total token issuance factor will reduce by after the reduction period passes (if set to 66.66%, token issuance will reduce by 1/3)
- **```distribution_proportions```** - Categories in which the specified proportion of newly released tokens are distributed to
- **```staking```** - Proportion of minted funds to incentivize staking OSMO
- **```pool_incentives```** - Proportion of minted funds to incentivize pools on Osmosis
@@ -154,21 +124,16 @@ Below are all the network parameters for the ```mint``` module:
**Notes**
1. `mint_denom` defines denom for minting token - uosmo
-2. `genesis_epoch_provisions` provides minting tokens per epoch at
- genesis.
-3. `epoch_identifier` defines the epoch identifier to be used for mint
- module e.g. "weekly"
-4. `reduction_period_in_epochs` defines the number of epochs to pass to
- reduce mint amount
-5. `reduction_factor` defines the reduction factor of tokens at every
- `reduction_period_in_epochs`
-6. `distribution_proportions` defines distribution rules for minted
- tokens, when developer rewards address is empty, it distribute
- tokens to community pool.
-7. `weighted_developer_rewards_receivers` provides the addresses that
- receives developer rewards by weight
-8. `minting_rewards_distribution_start_epoch` defines the start epoch
- of minting to make sure minting start after initial pools are set
+2. `genesis_epoch_provisions` provides minting tokens per epoch at genesis.
+3. `epoch_identifier` defines the epoch identifier to be used for the mint module e.g. "weekly"
+4. `reduction_period_in_epochs` defines the number of epochs to pass to reduce the mint amount
+5. `reduction_factor` defines the reduction factor of tokens at every `reduction_period_in_epochs`
+6. `distribution_proportions` defines distribution rules for minted tokens, when the developer
+ rewards address is empty, it distributes tokens to the community pool.
+7. `weighted_developer_rewards_receivers` provides the addresses that receive developer
+ rewards by weight
+8. `minting_rewards_distribution_start_epoch` defines the start epoch of minting to make sure
+ minting start after initial pools are set
## Events
diff --git a/x/mint/client/cli/cli_test.go b/x/mint/client/cli/cli_test.go
index 44b01915669..d9703eb8933 100644
--- a/x/mint/client/cli/cli_test.go
+++ b/x/mint/client/cli/cli_test.go
@@ -1,5 +1,4 @@
//go:build norace
-// +build norace
package cli_test
diff --git a/x/mint/client/rest/grpc_query_test.go b/x/mint/client/rest/grpc_query_test.go
index 8b7034c7d9d..9f8470cafe7 100644
--- a/x/mint/client/rest/grpc_query_test.go
+++ b/x/mint/client/rest/grpc_query_test.go
@@ -1,5 +1,4 @@
//go:build norace
-// +build norace
package rest_test
diff --git a/x/mint/genesis_test.go b/x/mint/genesis_test.go
index 5066c6b572b..d0431b5f4c6 100644
--- a/x/mint/genesis_test.go
+++ b/x/mint/genesis_test.go
@@ -25,5 +25,5 @@ func TestMintInitGenesis(t *testing.T) {
expectedVestingCoins, ok := sdk.NewIntFromString("225000000000000")
require.True(t, ok)
require.Equal(t, expectedVestingCoins, initialVestingCoins.Amount)
- require.Equal(t, int64(0), app.MintKeeper.GetLastHalvenEpochNum(ctx))
+ require.Equal(t, int64(0), app.MintKeeper.GetLastReductionEpochNum(ctx))
}
diff --git a/x/mint/keeper/genesis.go b/x/mint/keeper/genesis.go
new file mode 100644
index 00000000000..a1adb13f8a8
--- /dev/null
+++ b/x/mint/keeper/genesis.go
@@ -0,0 +1,31 @@
+package keeper
+
+import (
+ sdk "github.com/cosmos/cosmos-sdk/types"
+
+ "github.com/osmosis-labs/osmosis/v10/x/mint/types"
+)
+
+// InitGenesis new mint genesis.
+func (k Keeper) InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, data *types.GenesisState) {
+ data.Minter.EpochProvisions = data.Params.GenesisEpochProvisions
+ k.SetMinter(ctx, data.Minter)
+ k.SetParams(ctx, data.Params)
+
+ if !ak.HasAccount(ctx, ak.GetModuleAddress(types.ModuleName)) {
+ ak.GetModuleAccount(ctx, types.ModuleName)
+ totalDeveloperVestingCoins := sdk.NewCoin(data.Params.MintDenom, sdk.NewInt(225_000_000_000_000))
+ k.CreateDeveloperVestingModuleAccount(ctx, totalDeveloperVestingCoins)
+ bk.AddSupplyOffset(ctx, data.Params.MintDenom, sdk.NewInt(225_000_000_000_000).Neg())
+ }
+
+ k.SetLastReductionEpochNum(ctx, data.ReductionStartedEpoch)
+}
+
+// ExportGenesis returns a GenesisState for a given context and keeper.
+func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
+ minter := k.GetMinter(ctx)
+ params := k.GetParams(ctx)
+ lastReductionEpoch := k.GetLastReductionEpochNum(ctx)
+ return types.NewGenesisState(minter, params, lastReductionEpoch)
+}
diff --git a/x/mint/keeper/hooks.go b/x/mint/keeper/hooks.go
index 42b50e2202d..6fb37f37692 100644
--- a/x/mint/keeper/hooks.go
+++ b/x/mint/keeper/hooks.go
@@ -21,20 +21,22 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumb
if epochNumber < params.MintingRewardsDistributionStartEpoch {
return
} else if epochNumber == params.MintingRewardsDistributionStartEpoch {
- k.SetLastHalvenEpochNum(ctx, epochNumber)
+ k.SetLastReductionEpochNum(ctx, epochNumber)
}
// fetch stored minter & params
minter := k.GetMinter(ctx)
params := k.GetParams(ctx)
// Check if we have hit an epoch where we update the inflation parameter.
- // Since epochs only update based on BFT time data, it is safe to store the "halvening period time"
- // in terms of the number of epochs that have transpired.
- if epochNumber >= k.GetParams(ctx).ReductionPeriodInEpochs+k.GetLastHalvenEpochNum(ctx) {
- // Halven the reward per halven period
+ // We measure time between reductions in number of epochs.
+ // This avoids issues with measuring in block numbers, as epochs have fixed intervals, with very
+ // low variance at the relevant sizes. As a result, it is safe to store the epoch number
+ // of the last reduction to be later retrieved for comparison.
+ if epochNumber >= k.GetParams(ctx).ReductionPeriodInEpochs+k.GetLastReductionEpochNum(ctx) {
+ // Reduce the reward per reduction period
minter.EpochProvisions = minter.NextEpochProvisions(params)
k.SetMinter(ctx, minter)
- k.SetLastHalvenEpochNum(ctx, epochNumber)
+ k.SetLastReductionEpochNum(ctx, epochNumber)
}
// mint coins, update supply
@@ -59,7 +61,7 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumb
ctx.EventManager().EmitEvent(
sdk.NewEvent(
- types.EventTypeMint,
+ types.ModuleName,
sdk.NewAttribute(types.AttributeEpochNumber, fmt.Sprintf("%d", epochNumber)),
sdk.NewAttribute(types.AttributeKeyEpochProvisions, minter.EpochProvisions.String()),
sdk.NewAttribute(sdk.AttributeKeyAmount, mintedCoin.Amount.String()),
diff --git a/x/mint/keeper/hooks_test.go b/x/mint/keeper/hooks_test.go
index 2f1fc3b631a..3ba04e3b2da 100644
--- a/x/mint/keeper/hooks_test.go
+++ b/x/mint/keeper/hooks_test.go
@@ -43,9 +43,9 @@ func TestEndOfEpochMintedCoinDistribution(t *testing.T) {
ctx, sdk.NewCoin("stake", sdk.NewInt(156*500000*2)))
height := int64(1)
- lastHalvenPeriod := app.MintKeeper.GetLastHalvenEpochNum(ctx)
+ lastReductionPeriod := app.MintKeeper.GetLastReductionEpochNum(ctx)
// correct rewards
- for ; height < lastHalvenPeriod+app.MintKeeper.GetParams(ctx).ReductionPeriodInEpochs; height++ {
+ for ; height < lastReductionPeriod+app.MintKeeper.GetParams(ctx).ReductionPeriodInEpochs; height++ {
devRewardsModuleAcc := app.AccountKeeper.GetModuleAccount(ctx, types.DeveloperVestingModuleAcctName)
devRewardsModuleOrigin := app.BankKeeper.GetAllBalances(ctx, devRewardsModuleAcc.GetAddress())
feePoolOrigin := app.DistrKeeper.GetFeePool(ctx)
@@ -82,10 +82,10 @@ func TestEndOfEpochMintedCoinDistribution(t *testing.T) {
app.EpochsKeeper.BeforeEpochStart(futureCtx, params.DistrEpochIdentifier, height)
app.EpochsKeeper.AfterEpochEnd(futureCtx, params.DistrEpochIdentifier, height)
- lastHalvenPeriod = app.MintKeeper.GetLastHalvenEpochNum(ctx)
- require.Equal(t, lastHalvenPeriod, app.MintKeeper.GetParams(ctx).ReductionPeriodInEpochs)
+ lastReductionPeriod = app.MintKeeper.GetLastReductionEpochNum(ctx)
+ require.Equal(t, lastReductionPeriod, app.MintKeeper.GetParams(ctx).ReductionPeriodInEpochs)
- for ; height < lastHalvenPeriod+app.MintKeeper.GetParams(ctx).ReductionPeriodInEpochs; height++ {
+ for ; height < lastReductionPeriod+app.MintKeeper.GetParams(ctx).ReductionPeriodInEpochs; height++ {
devRewardsModuleAcc := app.AccountKeeper.GetModuleAccount(ctx, types.DeveloperVestingModuleAcctName)
devRewardsModuleOrigin := app.BankKeeper.GetAllBalances(ctx, devRewardsModuleAcc.GetAddress())
feePoolOrigin := app.DistrKeeper.GetFeePool(ctx)
@@ -126,9 +126,9 @@ func TestMintedCoinDistributionWhenDevRewardsAddressEmpty(t *testing.T) {
ctx, sdk.NewCoin("stake", sdk.NewInt(156*500000*2)))
height := int64(1)
- lastHalvenPeriod := app.MintKeeper.GetLastHalvenEpochNum(ctx)
+ lastReductionPeriod := app.MintKeeper.GetLastReductionEpochNum(ctx)
// correct rewards
- for ; height < lastHalvenPeriod+app.MintKeeper.GetParams(ctx).ReductionPeriodInEpochs; height++ {
+ for ; height < lastReductionPeriod+app.MintKeeper.GetParams(ctx).ReductionPeriodInEpochs; height++ {
devRewardsModuleAcc := app.AccountKeeper.GetModuleAccount(ctx, types.DeveloperVestingModuleAcctName)
devRewardsModuleOrigin := app.BankKeeper.GetAllBalances(ctx, devRewardsModuleAcc.GetAddress())
feePoolOrigin := app.DistrKeeper.GetFeePool(ctx)
@@ -153,10 +153,10 @@ func TestMintedCoinDistributionWhenDevRewardsAddressEmpty(t *testing.T) {
app.EpochsKeeper.BeforeEpochStart(futureCtx, params.DistrEpochIdentifier, height)
app.EpochsKeeper.AfterEpochEnd(futureCtx, params.DistrEpochIdentifier, height)
- lastHalvenPeriod = app.MintKeeper.GetLastHalvenEpochNum(ctx)
- require.Equal(t, lastHalvenPeriod, app.MintKeeper.GetParams(ctx).ReductionPeriodInEpochs)
+ lastReductionPeriod = app.MintKeeper.GetLastReductionEpochNum(ctx)
+ require.Equal(t, lastReductionPeriod, app.MintKeeper.GetParams(ctx).ReductionPeriodInEpochs)
- for ; height < lastHalvenPeriod+app.MintKeeper.GetParams(ctx).ReductionPeriodInEpochs; height++ {
+ for ; height < lastReductionPeriod+app.MintKeeper.GetParams(ctx).ReductionPeriodInEpochs; height++ {
devRewardsModuleAcc := app.AccountKeeper.GetModuleAccount(ctx, types.DeveloperVestingModuleAcctName)
devRewardsModuleOrigin := app.BankKeeper.GetAllBalances(ctx, devRewardsModuleAcc.GetAddress())
feePoolOrigin := app.DistrKeeper.GetFeePool(ctx)
@@ -215,9 +215,9 @@ func TestEndOfEpochNoDistributionWhenIsNotYetStartTime(t *testing.T) {
require.NotEqual(t, sdk.DecCoins{}, app.DistrKeeper.GetFeePool(ctx).CommunityPool,
"Tokens to community pool at start distribution epoch")
- // halven period should be set to mintParams.MintingRewardsDistributionStartEpoch
- lastHalvenPeriod := app.MintKeeper.GetLastHalvenEpochNum(ctx)
- require.Equal(t, lastHalvenPeriod, mintParams.MintingRewardsDistributionStartEpoch)
+ // reduction period should be set to mintParams.MintingRewardsDistributionStartEpoch
+ lastReductionPeriod := app.MintKeeper.GetLastReductionEpochNum(ctx)
+ require.Equal(t, lastReductionPeriod, mintParams.MintingRewardsDistributionStartEpoch)
}
func setupGaugeForLPIncentives(t *testing.T, app *osmoapp.OsmosisApp, ctx sdk.Context) {
diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go
index b02f7c0212c..5075d5be8b9 100644
--- a/x/mint/keeper/keeper.go
+++ b/x/mint/keeper/keeper.go
@@ -93,10 +93,10 @@ func (k *Keeper) SetHooks(h types.MintHooks) *Keeper {
return k
}
-// GetLastHalvenEpochNum returns last halven epoch number.
-func (k Keeper) GetLastHalvenEpochNum(ctx sdk.Context) int64 {
+// GetLastReductionEpochNum returns last reduction epoch number.
+func (k Keeper) GetLastReductionEpochNum(ctx sdk.Context) int64 {
store := ctx.KVStore(k.storeKey)
- b := store.Get(types.LastHalvenEpochKey)
+ b := store.Get(types.LastReductionEpochKey)
if b == nil {
return 0
}
@@ -104,10 +104,10 @@ func (k Keeper) GetLastHalvenEpochNum(ctx sdk.Context) int64 {
return int64(sdk.BigEndianToUint64(b))
}
-// SetLastHalvenEpochNum set last halven epoch number.
-func (k Keeper) SetLastHalvenEpochNum(ctx sdk.Context, epochNum int64) {
+// SetLastReductionEpochNum set last reduction epoch number.
+func (k Keeper) SetLastReductionEpochNum(ctx sdk.Context, epochNum int64) {
store := ctx.KVStore(k.storeKey)
- store.Set(types.LastHalvenEpochKey, sdk.Uint64ToBigEndian(uint64(epochNum)))
+ store.Set(types.LastReductionEpochKey, sdk.Uint64ToBigEndian(uint64(epochNum)))
}
// get the minter.
diff --git a/x/mint/module.go b/x/mint/module.go
index 2fbd428c591..017836999ad 100644
--- a/x/mint/module.go
+++ b/x/mint/module.go
@@ -162,6 +162,9 @@ func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.Validato
return []abci.ValidatorUpdate{}
}
+// ConsensusVersion implements AppModule/ConsensusVersion.
+func (AppModule) ConsensusVersion() uint64 { return 1 }
+
// ___________________________________________________________________________
// AppModuleSimulation functions
@@ -190,6 +193,3 @@ func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
return nil
}
-
-// ConsensusVersion implements AppModule/ConsensusVersion.
-func (AppModule) ConsensusVersion() uint64 { return 1 }
diff --git a/x/mint/simulation/export_test.go b/x/mint/simulation/export_test.go
new file mode 100644
index 00000000000..4e7719ebdaf
--- /dev/null
+++ b/x/mint/simulation/export_test.go
@@ -0,0 +1,10 @@
+package simulation
+
+const (
+ ExpectedEpochIdentifier = epochIdentifier
+)
+
+var (
+ ExpectedDistributionProportions = distributionProportions
+ ExpectedDevRewardReceivers = weightedDevRewardReceivers
+)
diff --git a/x/mint/simulation/genesis.go b/x/mint/simulation/genesis.go
index 6dcd1ee89c7..cc6531e906e 100644
--- a/x/mint/simulation/genesis.go
+++ b/x/mint/simulation/genesis.go
@@ -5,6 +5,7 @@ package simulation
import (
"encoding/json"
"fmt"
+ "math/rand"
"github.com/osmosis-labs/osmosis/v10/x/mint/types"
@@ -12,39 +13,163 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
)
+// Simulation parameter constants.
+const (
+ epochProvisionsKey = "genesis_epoch_provisions"
+ epochIdentifierKey = "epoch_identifier"
+ reductionFactorKey = "reduction_factor"
+ reductionPeriodInEpochsKey = "reduction_period_in_epochs"
+
+ stakingDistributionProportionKey = "staking_distribution_proportion"
+ poolIncentivesDistributionProportionKey = "pool_incentives_distribution_proportion"
+ developerRewardsDistributionProportionKey = "developer_rewards_distribution_proportion"
+ communityPoolDistributionProportionKey = "community_pool_distribution_proportion"
+ weightedDevRewardReceiversKey = "weighted_developer_rewards_receivers"
+ mintingRewardsDistributionStartEpochKey = "minting_rewards_distribution_start_epoch"
+
+ epochIdentifier = "day"
+ maxInt64 = int(^uint(0) >> 1)
+)
+
+var (
+ // Taken from: // https://github.com/osmosis-labs/networks/raw/main/osmosis-1/genesis.json
+ distributionProportions = types.DistributionProportions{
+ Staking: sdk.NewDecWithPrec(25, 2),
+ PoolIncentives: sdk.NewDecWithPrec(45, 2),
+ DeveloperRewards: sdk.NewDecWithPrec(25, 2),
+ CommunityPool: sdk.NewDecWithPrec(05, 2),
+ }
+ weightedDevRewardReceivers = []types.WeightedAddress{
+ {
+ Address: "osmo14kjcwdwcqsujkdt8n5qwpd8x8ty2rys5rjrdjj",
+ Weight: sdk.NewDecWithPrec(2887, 4),
+ },
+ {
+ Address: "osmo1gw445ta0aqn26suz2rg3tkqfpxnq2hs224d7gq",
+ Weight: sdk.NewDecWithPrec(229, 3),
+ },
+ {
+ Address: "osmo13lt0hzc6u3htsk7z5rs6vuurmgg4hh2ecgxqkf",
+ Weight: sdk.NewDecWithPrec(1625, 4),
+ },
+ {
+ Address: "osmo1kvc3he93ygc0us3ycslwlv2gdqry4ta73vk9hu",
+ Weight: sdk.NewDecWithPrec(109, 3),
+ },
+ {
+ Address: "osmo19qgldlsk7hdv3ddtwwpvzff30pxqe9phq9evxf",
+ Weight: sdk.NewDecWithPrec(995, 3).Quo(sdk.NewDec(10)), // 0.0995
+ },
+ {
+ Address: "osmo19fs55cx4594een7qr8tglrjtt5h9jrxg458htd",
+ Weight: sdk.NewDecWithPrec(6, 1).Quo(sdk.NewDec(10)), // 0.06
+ },
+ {
+ Address: "osmo1ssp6px3fs3kwreles3ft6c07mfvj89a544yj9k",
+ Weight: sdk.NewDecWithPrec(15, 2).Quo(sdk.NewDec(10)), // 0.015
+ },
+ {
+ Address: "osmo1c5yu8498yzqte9cmfv5zcgtl07lhpjrj0skqdx",
+ Weight: sdk.NewDecWithPrec(1, 1).Quo(sdk.NewDec(10)), // 0.01
+ },
+ {
+ Address: "osmo1yhj3r9t9vw7qgeg22cehfzj7enwgklw5k5v7lj",
+ Weight: sdk.NewDecWithPrec(75, 2).Quo(sdk.NewDec(100)), // 0.0075
+ },
+ {
+ Address: "osmo18nzmtyn5vy5y45dmcdnta8askldyvehx66lqgm",
+ Weight: sdk.NewDecWithPrec(7, 1).Quo(sdk.NewDec(100)), // 0.007
+ },
+ {
+ Address: "osmo1z2x9z58cg96ujvhvu6ga07yv9edq2mvkxpgwmc",
+ Weight: sdk.NewDecWithPrec(5, 1).Quo(sdk.NewDec(100)), // 0.005
+ },
+ {
+ Address: "osmo1tvf3373skua8e6480eyy38avv8mw3hnt8jcxg9",
+ Weight: sdk.NewDecWithPrec(25, 2).Quo(sdk.NewDec(100)), // 0.0025
+ },
+ {
+ Address: "osmo1zs0txy03pv5crj2rvty8wemd3zhrka2ne8u05n",
+ Weight: sdk.NewDecWithPrec(25, 2).Quo(sdk.NewDec(100)), // 0.0025
+ },
+ {
+ Address: "osmo1djgf9p53n7m5a55hcn6gg0cm5mue4r5g3fadee",
+ Weight: sdk.NewDecWithPrec(1, 1).Quo(sdk.NewDec(100)), // 0.001
+ },
+ {
+ Address: "osmo1488zldkrn8xcjh3z40v2mexq7d088qkna8ceze",
+ Weight: sdk.NewDecWithPrec(8, 1).Quo(sdk.NewDec(1000)), // 0.0008
+ },
+ }
+)
+
// RandomizedGenState generates a random GenesisState for mint.
func RandomizedGenState(simState *module.SimulationState) {
- // minter
+ var epochProvisions sdk.Dec
+ simState.AppParams.GetOrGenerate(
+ simState.Cdc, epochProvisionsKey, &epochProvisions, simState.Rand,
+ func(r *rand.Rand) { epochProvisions = genEpochProvisions(r) },
+ )
+
+ var reductionFactor sdk.Dec
+ simState.AppParams.GetOrGenerate(
+ simState.Cdc, reductionFactorKey, &reductionFactor, simState.Rand,
+ func(r *rand.Rand) { reductionFactor = genReductionFactor(r) },
+ )
- // var maxRewardPerEpoch sdk.Dec
- // simState.AppParams.GetOrGenerate(
- // simState.Cdc, MaxRewardPerEpoch, &maxRewardPerEpoch, simState.Rand,
- // func(r *rand.Rand) { maxRewardPerEpoch = GenMaxRewardPerEpoch(r) },
- // )
+ var reductionPeriodInEpochs int64
+ simState.AppParams.GetOrGenerate(
+ simState.Cdc, reductionPeriodInEpochsKey, &reductionPeriodInEpochs, simState.Rand,
+ func(r *rand.Rand) { reductionPeriodInEpochs = genReductionPeriodInEpochs(r) },
+ )
- // var minRewardPerEpoch sdk.Dec
- // simState.AppParams.GetOrGenerate(
- // simState.Cdc, MinRewardPerEpoch, &minRewardPerEpoch, simState.Rand,
- // func(r *rand.Rand) { minRewardPerEpoch = GenMinRewardPerEpoch(r) },
- // )
- // Leaving as sample code
+ var mintintRewardsDistributionStartEpoch int64
+ simState.AppParams.GetOrGenerate(
+ simState.Cdc, mintingRewardsDistributionStartEpochKey, &mintintRewardsDistributionStartEpoch, simState.Rand,
+ func(r *rand.Rand) { mintintRewardsDistributionStartEpoch = genMintintRewardsDistributionStartEpoch(r) },
+ )
+
+ reductionStartedEpoch := genReductionStartedEpoch(simState.Rand)
mintDenom := sdk.DefaultBondDenom
- epochProvisions := sdk.NewDec(500000) // TODO: Randomize this
- params := types.NewParams(mintDenom, epochProvisions, "week", sdk.NewDecWithPrec(5, 1), 156, types.DistributionProportions{
- Staking: sdk.NewDecWithPrec(4, 1), // 0.4
- PoolIncentives: sdk.NewDecWithPrec(3, 1), // 0.3
- DeveloperRewards: sdk.NewDecWithPrec(2, 1), // 0.2
- CommunityPool: sdk.NewDecWithPrec(1, 1), // 0.1
- }, []types.WeightedAddress{}, 0)
+ params := types.NewParams(
+ mintDenom,
+ epochProvisions,
+ epochIdentifier,
+ reductionFactor,
+ reductionPeriodInEpochs,
+ distributionProportions,
+ weightedDevRewardReceivers,
+ mintintRewardsDistributionStartEpoch)
+
+ minter := types.NewMinter(epochProvisions)
- mintGenesis := types.NewGenesisState(types.InitialMinter(), params, 0)
+ mintGenesis := types.NewGenesisState(minter, params, reductionStartedEpoch)
bz, err := json.MarshalIndent(&mintGenesis, "", " ")
if err != nil {
panic(err)
}
- // TODO: Do some randomization later
- fmt.Printf("Selected deterministically generated minting parameters:\n%s\n", bz)
+ fmt.Printf("Selected pseudo-randomly generated minting parameters:\n%s\n", bz)
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(mintGenesis)
}
+
+func genEpochProvisions(r *rand.Rand) sdk.Dec {
+ return sdk.NewDec(int64(r.Intn(maxInt64)))
+}
+
+func genReductionFactor(r *rand.Rand) sdk.Dec {
+ return sdk.NewDecWithPrec(int64(r.Intn(10)), 1)
+}
+
+func genReductionPeriodInEpochs(r *rand.Rand) int64 {
+ return int64(r.Intn(maxInt64))
+}
+
+func genMintintRewardsDistributionStartEpoch(r *rand.Rand) int64 {
+ return int64(r.Intn(maxInt64))
+}
+
+func genReductionStartedEpoch(r *rand.Rand) int64 {
+ return int64(r.Intn(maxInt64))
+}
diff --git a/x/mint/simulation/genesis_test.go b/x/mint/simulation/genesis_test.go
index 544003aabc3..41c9bf358a8 100644
--- a/x/mint/simulation/genesis_test.go
+++ b/x/mint/simulation/genesis_test.go
@@ -2,6 +2,7 @@ package simulation_test
import (
"encoding/json"
+ "fmt"
"math/rand"
"testing"
@@ -12,17 +13,18 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
+ sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
)
// TestRandomizedGenState tests the normal scenario of applying RandomizedGenState.
-// Abonormal scenarios are not tested here.
+// Abnormal scenarios are not tested here.
func TestRandomizedGenState(t *testing.T) {
interfaceRegistry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(interfaceRegistry)
- s := rand.NewSource(1)
+ s := rand.NewSource(5)
r := rand.New(s)
simState := module.SimulationState{
@@ -40,14 +42,59 @@ func TestRandomizedGenState(t *testing.T) {
var mintGenesis types.GenesisState
simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &mintGenesis)
- require.Equal(t, "stake", mintGenesis.Params.MintDenom)
- require.Equal(t, "0stake", mintGenesis.Minter.EpochProvision(mintGenesis.Params).String())
- require.Equal(t, "0.000000000000000000", mintGenesis.Minter.NextEpochProvisions(mintGenesis.Params).String())
- require.Equal(t, "0.000000000000000000", mintGenesis.Minter.EpochProvisions.String())
+ const (
+ expectedEpochProvisionsStr = "7913048388940673156"
+ expectedReductionFactorStr = "0.6"
+ expectedReductionPeriodInEpochs = int64(9171281239991390334)
+
+ expectedMintintRewardsDistributionStartEpoch = int64(14997548954463330)
+
+ expectedReductionStartedEpoch = int64(6009281777831789783)
+
+ expectedNextEpochProvisionsStr = "3956524194470336578"
+ expectedDenom = sdk.DefaultBondDenom
+ )
+
+ // Epoch provisions from Minter.
+ epochProvisionsDec, err := sdk.NewDecFromStr(expectedEpochProvisionsStr)
+ require.NoError(t, err)
+ require.Equal(t, epochProvisionsDec, mintGenesis.Minter.EpochProvisions)
+
+ // Epoch identifier.
+ require.Equal(t, simulation.ExpectedEpochIdentifier, mintGenesis.Params.EpochIdentifier)
+
+ // Reduction factor.
+ reductionFactorDec, err := sdk.NewDecFromStr(expectedReductionFactorStr)
+ require.NoError(t, err)
+ require.Equal(t, reductionFactorDec, mintGenesis.Params.ReductionFactor)
+
+ // Reduction perion in epochs.
+ require.Equal(t, expectedReductionPeriodInEpochs, mintGenesis.Params.ReductionPeriodInEpochs)
+
+ // Distribution proportions.
+ require.Equal(t, simulation.ExpectedDistributionProportions, mintGenesis.Params.DistributionProportions)
+
+ // Weighted developer rewards receivers.
+ require.Equal(t, simulation.ExpectedDevRewardReceivers, mintGenesis.Params.WeightedDeveloperRewardsReceivers)
+
+ // Minting rewards distribution start epoch
+ require.Equal(t, expectedMintintRewardsDistributionStartEpoch, mintGenesis.Params.MintingRewardsDistributionStartEpoch)
+
+ // Reduction started epoch.
+ require.Equal(t, expectedReductionStartedEpoch, mintGenesis.ReductionStartedEpoch)
+
+ // Next epoch provisions.
+ nextEpochProvisionsDec := epochProvisionsDec.Mul(reductionFactorDec)
+ require.NoError(t, err)
+ require.Equal(t, nextEpochProvisionsDec, mintGenesis.Minter.NextEpochProvisions(mintGenesis.Params))
+
+ // Denom and Epoch provisions from Params.
+ require.Equal(t, expectedDenom, mintGenesis.Params.MintDenom)
+ require.Equal(t, fmt.Sprintf("%s%s", expectedEpochProvisionsStr, expectedDenom), mintGenesis.Minter.EpochProvision(mintGenesis.Params).String())
}
-// TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState.
-func TestRandomizedGenState1(t *testing.T) {
+// TestRandomizedGenState_Invalid tests abnormal scenarios of applying RandomizedGenState.
+func TestRandomizedGenState_Invalid(t *testing.T) {
interfaceRegistry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(interfaceRegistry)
diff --git a/x/mint/types/events.go b/x/mint/types/events.go
index 6ad8f851868..4f1ca5464b6 100644
--- a/x/mint/types/events.go
+++ b/x/mint/types/events.go
@@ -1,9 +1,11 @@
package types
-// Minting module event types.
+// Minting module event constants.
const (
- EventTypeMint = ModuleName
-
+ // AttributeKeyEpochProvisions is the string representation of the
+ // epoch provisions event attribute.
AttributeKeyEpochProvisions = "epoch_provisions"
- AttributeEpochNumber = "epoch_number"
+ // AttributeEpochNumber is the string representation of the
+ // epoch number event attribute.
+ AttributeEpochNumber = "epoch_number"
)
diff --git a/x/mint/types/expected_keepers.go b/x/mint/types/expected_keepers.go
index c2eb08ffb6e..4db66e45456 100644
--- a/x/mint/types/expected_keepers.go
+++ b/x/mint/types/expected_keepers.go
@@ -12,7 +12,6 @@ type AccountKeeper interface {
GetModuleAddress(name string) sdk.AccAddress
HasAccount(ctx sdk.Context, addr sdk.AccAddress) bool
- // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862
SetModuleAccount(sdk.Context, types.ModuleAccountI)
GetModuleAccount(ctx sdk.Context, moduleName string) types.ModuleAccountI
}
diff --git a/x/mint/types/export_test.go b/x/mint/types/export_test.go
new file mode 100644
index 00000000000..103197e146c
--- /dev/null
+++ b/x/mint/types/export_test.go
@@ -0,0 +1,6 @@
+package types
+
+var (
+ ErrNilEpochProvisions = errNilEpochProvisions
+ ErrNegativeEpochProvisions = errNegativeEpochProvisions
+)
diff --git a/x/mint/types/genesis.go b/x/mint/types/genesis.go
index eae6321d589..17756127b7e 100644
--- a/x/mint/types/genesis.go
+++ b/x/mint/types/genesis.go
@@ -1,20 +1,20 @@
package types
// NewGenesisState creates a new GenesisState object.
-func NewGenesisState(minter Minter, params Params, halvenStartedEpoch int64) *GenesisState {
+func NewGenesisState(minter Minter, params Params, reductionStartedEpoch int64) *GenesisState {
return &GenesisState{
- Minter: minter,
- Params: params,
- HalvenStartedEpoch: halvenStartedEpoch,
+ Minter: minter,
+ Params: params,
+ ReductionStartedEpoch: reductionStartedEpoch,
}
}
// DefaultGenesisState creates a default GenesisState object.
func DefaultGenesisState() *GenesisState {
return &GenesisState{
- Minter: DefaultInitialMinter(),
- Params: DefaultParams(),
- HalvenStartedEpoch: 0,
+ Minter: DefaultInitialMinter(),
+ Params: DefaultParams(),
+ ReductionStartedEpoch: 0,
}
}
@@ -25,5 +25,5 @@ func ValidateGenesis(data GenesisState) error {
return err
}
- return ValidateMinter(data.Minter)
+ return data.Minter.Validate()
}
diff --git a/x/mint/types/genesis.pb.go b/x/mint/types/genesis.pb.go
index 5815950ec9a..260ff0b4280 100644
--- a/x/mint/types/genesis.pb.go
+++ b/x/mint/types/genesis.pb.go
@@ -25,12 +25,13 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
// GenesisState defines the mint module's genesis state.
type GenesisState struct {
- // minter is a space for holding current rewards information.
+ // minter is an abstraction for holding current rewards information.
Minter Minter `protobuf:"bytes,1,opt,name=minter,proto3" json:"minter"`
- // params defines all the paramaters of the module.
+ // params defines all the paramaters of the mint module.
Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"`
- // current halven period start epoch
- HalvenStartedEpoch int64 `protobuf:"varint,3,opt,name=halven_started_epoch,json=halvenStartedEpoch,proto3" json:"halven_started_epoch,omitempty" yaml:"halven_started_epoch"`
+ // reduction_started_epoch is the first epoch in which the reduction of mint
+ // begins.
+ ReductionStartedEpoch int64 `protobuf:"varint,3,opt,name=reduction_started_epoch,json=reductionStartedEpoch,proto3" json:"reduction_started_epoch,omitempty" yaml:"reduction_started_epoch"`
}
func (m *GenesisState) Reset() { *m = GenesisState{} }
@@ -80,9 +81,9 @@ func (m *GenesisState) GetParams() Params {
return Params{}
}
-func (m *GenesisState) GetHalvenStartedEpoch() int64 {
+func (m *GenesisState) GetReductionStartedEpoch() int64 {
if m != nil {
- return m.HalvenStartedEpoch
+ return m.ReductionStartedEpoch
}
return 0
}
@@ -96,25 +97,25 @@ func init() {
}
var fileDescriptor_12e6a5511ad3feeb = []byte{
- // 280 bytes of a gzipped FileDescriptorProto
+ // 283 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xca, 0x2f, 0xce, 0xcd,
0x2f, 0xce, 0x2c, 0xd6, 0xcf, 0xcd, 0xcc, 0x2b, 0xd1, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34,
0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12,
0x81, 0xaa, 0xd1, 0x03, 0xa9, 0xd1, 0x83, 0xaa, 0x91, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x2b,
- 0xd0, 0x07, 0xb1, 0x20, 0x6a, 0xa5, 0xe4, 0xb1, 0x9a, 0x07, 0xd6, 0x08, 0x56, 0xa0, 0x74, 0x93,
+ 0xd0, 0x07, 0xb1, 0x20, 0x6a, 0xa5, 0xe4, 0xb1, 0x9a, 0x07, 0xd6, 0x08, 0x56, 0xa0, 0xf4, 0x88,
0x91, 0x8b, 0xc7, 0x1d, 0x62, 0x7c, 0x70, 0x49, 0x62, 0x49, 0xaa, 0x90, 0x15, 0x17, 0x1b, 0x48,
0x3a, 0xb5, 0x48, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, 0x48, 0x46, 0x0f, 0x9b, 0x75, 0x7a, 0xbe,
0x60, 0x35, 0x4e, 0x2c, 0x27, 0xee, 0xc9, 0x33, 0x04, 0x41, 0x75, 0x80, 0xf4, 0x16, 0x24, 0x16,
0x25, 0xe6, 0x16, 0x4b, 0x30, 0xe1, 0xd3, 0x1b, 0x00, 0x56, 0x03, 0xd3, 0x0b, 0xd1, 0x21, 0x14,
- 0xc8, 0x25, 0x92, 0x91, 0x98, 0x53, 0x96, 0x9a, 0x17, 0x5f, 0x5c, 0x92, 0x58, 0x54, 0x92, 0x9a,
- 0x12, 0x9f, 0x5a, 0x90, 0x9f, 0x9c, 0x21, 0xc1, 0xac, 0xc0, 0xa8, 0xc1, 0xec, 0x24, 0xff, 0xe9,
- 0x9e, 0xbc, 0x74, 0x65, 0x62, 0x6e, 0x8e, 0x95, 0x12, 0x36, 0x55, 0x4a, 0x41, 0x42, 0x10, 0xe1,
- 0x60, 0x88, 0xa8, 0x2b, 0x48, 0xd0, 0xc9, 0xeb, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18,
- 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5,
- 0x18, 0xa2, 0x0c, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0xa1, 0x4e,
- 0xd4, 0xcd, 0x49, 0x4c, 0x2a, 0x86, 0x71, 0xf4, 0xcb, 0x0c, 0x0d, 0xf4, 0x2b, 0x20, 0x81, 0x56,
- 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0x0e, 0x2e, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff,
- 0xa6, 0x32, 0x10, 0xc2, 0xa1, 0x01, 0x00, 0x00,
+ 0xc5, 0x25, 0x5e, 0x94, 0x9a, 0x52, 0x9a, 0x5c, 0x92, 0x99, 0x9f, 0x17, 0x5f, 0x5c, 0x92, 0x58,
+ 0x54, 0x92, 0x9a, 0x12, 0x9f, 0x5a, 0x90, 0x9f, 0x9c, 0x21, 0xc1, 0xac, 0xc0, 0xa8, 0xc1, 0xec,
+ 0xa4, 0xf4, 0xe9, 0x9e, 0xbc, 0x5c, 0x65, 0x62, 0x6e, 0x8e, 0x95, 0x12, 0x0e, 0x85, 0x4a, 0x41,
+ 0xa2, 0x70, 0x99, 0x60, 0x88, 0x84, 0x2b, 0x48, 0xdc, 0xc9, 0xeb, 0xc4, 0x23, 0x39, 0xc6, 0x0b,
+ 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86,
+ 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x0c, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73,
+ 0xf5, 0xa1, 0x6e, 0xd5, 0xcd, 0x49, 0x4c, 0x2a, 0x86, 0x71, 0xf4, 0xcb, 0x0c, 0x0d, 0xf4, 0x2b,
+ 0x20, 0xa1, 0x57, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0x0e, 0x37, 0x63, 0x40, 0x00, 0x00,
+ 0x00, 0xff, 0xff, 0x4c, 0xe3, 0x63, 0xd9, 0xaa, 0x01, 0x00, 0x00,
}
func (m *GenesisState) Marshal() (dAtA []byte, err error) {
@@ -137,8 +138,8 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
- if m.HalvenStartedEpoch != 0 {
- i = encodeVarintGenesis(dAtA, i, uint64(m.HalvenStartedEpoch))
+ if m.ReductionStartedEpoch != 0 {
+ i = encodeVarintGenesis(dAtA, i, uint64(m.ReductionStartedEpoch))
i--
dAtA[i] = 0x18
}
@@ -186,8 +187,8 @@ func (m *GenesisState) Size() (n int) {
n += 1 + l + sovGenesis(uint64(l))
l = m.Params.Size()
n += 1 + l + sovGenesis(uint64(l))
- if m.HalvenStartedEpoch != 0 {
- n += 1 + sovGenesis(uint64(m.HalvenStartedEpoch))
+ if m.ReductionStartedEpoch != 0 {
+ n += 1 + sovGenesis(uint64(m.ReductionStartedEpoch))
}
return n
}
@@ -295,9 +296,9 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error {
iNdEx = postIndex
case 3:
if wireType != 0 {
- return fmt.Errorf("proto: wrong wireType = %d for field HalvenStartedEpoch", wireType)
+ return fmt.Errorf("proto: wrong wireType = %d for field ReductionStartedEpoch", wireType)
}
- m.HalvenStartedEpoch = 0
+ m.ReductionStartedEpoch = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowGenesis
@@ -307,7 +308,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error {
}
b := dAtA[iNdEx]
iNdEx++
- m.HalvenStartedEpoch |= int64(b&0x7F) << shift
+ m.ReductionStartedEpoch |= int64(b&0x7F) << shift
if b < 0x80 {
break
}
diff --git a/x/mint/types/hooks.go b/x/mint/types/hooks.go
index ff2b3c3d4d1..1cffa07ccd4 100644
--- a/x/mint/types/hooks.go
+++ b/x/mint/types/hooks.go
@@ -4,19 +4,24 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
+// MintHooks defines an interface for mint module's hooks.
type MintHooks interface {
AfterDistributeMintedCoin(ctx sdk.Context, mintedCoin sdk.Coin)
}
var _ MintHooks = MultiMintHooks{}
-// combine multiple mint hooks, all hook functions are run in array sequence.
+// MultiMintHooks is a container for mint hooks.
+// All hooks are run in sequence.
type MultiMintHooks []MintHooks
+// NewMultiMintHooks returns new MultiMintHooks given hooks.
func NewMultiMintHooks(hooks ...MintHooks) MultiMintHooks {
return hooks
}
+// AfterDistributeMintedCoin is a hook that runs after minter mints and distributes coins
+// at the beginning of each epoch.
func (h MultiMintHooks) AfterDistributeMintedCoin(ctx sdk.Context, mintedCoin sdk.Coin) {
for i := range h {
h[i].AfterDistributeMintedCoin(ctx, mintedCoin)
diff --git a/x/mint/types/keys.go b/x/mint/types/keys.go
index 6812a631889..f2c40c0871d 100644
--- a/x/mint/types/keys.go
+++ b/x/mint/types/keys.go
@@ -1,15 +1,17 @@
package types
-// MinterKey is the key to use for the keeper store.
+// MinterKey is the key to use for the keeper store at which
+// the Minter and its EpochProvisions are stored.
var MinterKey = []byte{0x00}
-// LastHalvenEpochKey is the key to use for the keeper store.
-var LastHalvenEpochKey = []byte{0x03}
+// LastReductionEpochKey is the key to use for the keeper store
+// for storing the last epoch at which reduction occurred.
+var LastReductionEpochKey = []byte{0x03}
const (
- // module name.
+ // ModuleName is the module name.
ModuleName = "mint"
- // module acct name for developer vesting.
+ // DeveloperVestingModuleAcctName is the module acct name for developer vesting.
DeveloperVestingModuleAcctName = "developer_vesting_unvested"
// StoreKey is the default store key for mint.
@@ -18,7 +20,9 @@ const (
// QuerierRoute is the querier route for the minting store.
QuerierRoute = StoreKey
- // Query endpoints supported by the minting querier.
- QueryParameters = "parameters"
+ // QueryParameters is an endpoint path for querying mint parameters.
+ QueryParameters = "parameters"
+
+ // QueryEpochProvisions is an endpoint path for querying mint epoch provisions.
QueryEpochProvisions = "epoch_provisions"
)
diff --git a/x/mint/types/mint.pb.go b/x/mint/types/mint.pb.go
index 6839982f304..b24984ad784 100644
--- a/x/mint/types/mint.pb.go
+++ b/x/mint/types/mint.pb.go
@@ -29,7 +29,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
// Minter represents the minting state.
type Minter struct {
- // current epoch provisions
+ // epoch_provisions represent rewards for the current epoch.
EpochProvisions github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=epoch_provisions,json=epochProvisions,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"epoch_provisions" yaml:"epoch_provisions"`
}
@@ -66,6 +66,9 @@ func (m *Minter) XXX_DiscardUnknown() {
var xxx_messageInfo_Minter proto.InternalMessageInfo
+// WeightedAddress represents an address with a weight assigned to it.
+// The weight is used to determine the proportion of the total minted
+// tokens to be minted to the address.
type WeightedAddress struct {
Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty" yaml:"address"`
Weight github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=weight,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"weight" yaml:"weight"`
@@ -111,17 +114,20 @@ func (m *WeightedAddress) GetAddress() string {
return ""
}
+// DistributionProportions defines the distribution proportions of the minted
+// denom. In other words, defines which stakeholders will receive the minted
+// denoms and how much.
type DistributionProportions struct {
- // staking defines the proportion of the minted minted_denom that is to be
+ // staking defines the proportion of the minted mint_denom that is to be
// allocated as staking rewards.
Staking github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=staking,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"staking" yaml:"staking"`
- // pool_incentives defines the proportion of the minted minted_denom that is
+ // pool_incentives defines the proportion of the minted mint_denom that is
// to be allocated as pool incentives.
PoolIncentives github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=pool_incentives,json=poolIncentives,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"pool_incentives" yaml:"pool_incentives"`
- // developer_rewards defines the proportion of the minted minted_denom that is
+ // developer_rewards defines the proportion of the minted mint_denom that is
// to be allocated to developer rewards address.
DeveloperRewards github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=developer_rewards,json=developerRewards,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"developer_rewards" yaml:"developer_rewards"`
- // community_pool defines the proportion of the minted minted_denom that is
+ // community_pool defines the proportion of the minted mint_denom that is
// to be allocated to the community pool.
CommunityPool github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=community_pool,json=communityPool,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"community_pool" yaml:"community_pool"`
}
@@ -159,23 +165,31 @@ func (m *DistributionProportions) XXX_DiscardUnknown() {
var xxx_messageInfo_DistributionProportions proto.InternalMessageInfo
-// Params holds parameters for the mint module.
+// Params holds parameters for the x/mint module.
type Params struct {
- // type of coin to mint
+ // mint_denom is the denom of the coin to mint.
MintDenom string `protobuf:"bytes,1,opt,name=mint_denom,json=mintDenom,proto3" json:"mint_denom,omitempty"`
- // epoch provisions from the first epoch
+ // genesis_epoch_provisions epoch provisions from the first epoch.
GenesisEpochProvisions github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=genesis_epoch_provisions,json=genesisEpochProvisions,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"genesis_epoch_provisions" yaml:"genesis_epoch_provisions"`
- // mint epoch identifier
+ // epoch_identifier mint epoch identifier e.g. (day, week).
EpochIdentifier string `protobuf:"bytes,3,opt,name=epoch_identifier,json=epochIdentifier,proto3" json:"epoch_identifier,omitempty" yaml:"epoch_identifier"`
- // number of epochs take to reduce rewards
+ // reduction_period_in_epochs the number of epochs it takes
+ // to reduce the rewards.
ReductionPeriodInEpochs int64 `protobuf:"varint,4,opt,name=reduction_period_in_epochs,json=reductionPeriodInEpochs,proto3" json:"reduction_period_in_epochs,omitempty" yaml:"reduction_period_in_epochs"`
- // reduction multiplier to execute on each period
+ // reduction_factor is the reduction multiplier to execute
+ // at the end of each period set by reduction_period_in_epochs.
ReductionFactor github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=reduction_factor,json=reductionFactor,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"reduction_factor" yaml:"reduction_factor"`
- // distribution_proportions defines the proportion of the minted denom
+ // distribution_proportions defines the distribution proportions of the minted
+ // denom. In other words, defines which stakeholders will receive the minted
+ // denoms and how much.
DistributionProportions DistributionProportions `protobuf:"bytes,6,opt,name=distribution_proportions,json=distributionProportions,proto3" json:"distribution_proportions"`
- // address to receive developer rewards
+ // weighted_developer_rewards_receivers is the address to receive developer
+ // rewards with weights assignedt to each address. The final amount that each
+ // address receives is: epoch_provisions *
+ // distribution_proportions.developer_rewards * Address's Weight.
WeightedDeveloperRewardsReceivers []WeightedAddress `protobuf:"bytes,7,rep,name=weighted_developer_rewards_receivers,json=weightedDeveloperRewardsReceivers,proto3" json:"weighted_developer_rewards_receivers" yaml:"developer_rewards_receiver"`
- // start epoch to distribute minting rewards
+ // minting_rewards_distribution_start_epoch start epoch to distribute minting
+ // rewards
MintingRewardsDistributionStartEpoch int64 `protobuf:"varint,8,opt,name=minting_rewards_distribution_start_epoch,json=mintingRewardsDistributionStartEpoch,proto3" json:"minting_rewards_distribution_start_epoch,omitempty" yaml:"minting_rewards_distribution_start_epoch"`
}
diff --git a/x/mint/types/minter.go b/x/mint/types/minter.go
index e9ba2b5d5f3..c4037c71aaa 100644
--- a/x/mint/types/minter.go
+++ b/x/mint/types/minter.go
@@ -1,9 +1,16 @@
package types
import (
+ "errors"
+
sdk "github.com/cosmos/cosmos-sdk/types"
)
+var (
+ errNilEpochProvisions = errors.New("epoch provisions was nil in genesis")
+ errNegativeEpochProvisions = errors.New("epoch provisions should be non-negative")
+)
+
// NewMinter returns a new Minter object with the given epoch
// provisions values.
func NewMinter(epochProvisions sdk.Dec) Minter {
@@ -22,8 +29,15 @@ func DefaultInitialMinter() Minter {
return InitialMinter()
}
-// validate minter.
-func ValidateMinter(minter Minter) error {
+// Validate validates minter. Returns nil on success, error otherewise.
+func (m Minter) Validate() error {
+ if m.EpochProvisions.IsNil() {
+ return errNilEpochProvisions
+ }
+
+ if m.EpochProvisions.IsNegative() {
+ return errNegativeEpochProvisions
+ }
return nil
}
diff --git a/x/mint/types/minter_test.go b/x/mint/types/minter_test.go
index 1865228a274..5ac0f67c74d 100644
--- a/x/mint/types/minter_test.go
+++ b/x/mint/types/minter_test.go
@@ -1,10 +1,13 @@
-package types
+package types_test
import (
"math/rand"
"testing"
+ "github.com/osmosis-labs/osmosis/v10/x/mint/types"
+
sdk "github.com/cosmos/cosmos-sdk/types"
+ "github.com/stretchr/testify/require"
)
// Benchmarking :)
@@ -15,8 +18,8 @@ import (
// BenchmarkEpochProvision-4 3000000 429 ns/op
func BenchmarkEpochProvision(b *testing.B) {
b.ReportAllocs()
- minter := InitialMinter()
- params := DefaultParams()
+ minter := types.InitialMinter()
+ params := types.DefaultParams()
s1 := rand.NewSource(100)
r1 := rand.New(s1)
@@ -32,11 +35,50 @@ func BenchmarkEpochProvision(b *testing.B) {
// BenchmarkNextEpochProvisions-4 5000000 251 ns/op
func BenchmarkNextEpochProvisions(b *testing.B) {
b.ReportAllocs()
- minter := InitialMinter()
- params := DefaultParams()
+ minter := types.InitialMinter()
+ params := types.DefaultParams()
// run the NextEpochProvisions function b.N times
for n := 0; n < b.N; n++ {
minter.NextEpochProvisions(params)
}
}
+
+func TestMinterValidate(t *testing.T) {
+
+ testcases := []struct {
+ name string
+ minter types.Minter
+ expected error
+ }{
+ {
+ "valid - success",
+ types.InitialMinter(),
+ nil,
+ },
+ {
+ "negative -errir",
+ types.Minter{
+ EpochProvisions: sdk.NewDec(-1),
+ },
+ types.ErrNegativeEpochProvisions,
+ },
+ {
+ "nil -error",
+ types.Minter{},
+ types.ErrNilEpochProvisions,
+ },
+ }
+
+ for _, tc := range testcases {
+ t.Run(tc.name, func(t *testing.T) {
+ actual := tc.minter.Validate()
+ if tc.expected != nil {
+ require.Error(t, actual)
+ require.Equal(t, actual, tc.expected)
+ } else {
+ require.NoError(t, actual)
+ }
+ })
+ }
+}
diff --git a/x/mint/types/params.go b/x/mint/types/params.go
index 3a03aed3641..6631b9927eb 100644
--- a/x/mint/types/params.go
+++ b/x/mint/types/params.go
@@ -30,6 +30,7 @@ func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
}
+// NewParams returns new mint module parameters initialized to the given values.
func NewParams(
mintDenom string, genesisEpochProvisions sdk.Dec, epochIdentifier string,
ReductionFactor sdk.Dec, reductionPeriodInEpochs int64, distrProportions DistributionProportions,
@@ -47,7 +48,7 @@ func NewParams(
}
}
-// default minting module parameters.
+// DefaultParams returns the default minting module parameters.
func DefaultParams() Params {
return Params{
MintDenom: sdk.DefaultBondDenom,
@@ -66,7 +67,8 @@ func DefaultParams() Params {
}
}
-// validate params.
+// Validate validates mint module parameters. Returns nil if valid,
+// error otherwise
func (p Params) Validate() error {
if err := validateMintDenom(p.MintDenom); err != nil {
return err
@@ -193,8 +195,6 @@ func validateDistributionProportions(i interface{}) error {
return errors.New("developer rewards distribution ratio should not be negative")
}
- // TODO: Maybe we should allow this :joy:, lets you burn osmo from community pool
- // for new chains
if v.CommunityPool.IsNegative() {
return errors.New("community pool distribution ratio should not be negative")
}
diff --git a/x/mint/types/query.pb.go b/x/mint/types/query.pb.go
index ea134825f67..ad109b6d370 100644
--- a/x/mint/types/query.pb.go
+++ b/x/mint/types/query.pb.go
@@ -243,7 +243,7 @@ const _ = grpc.SupportPackageIsVersion4
type QueryClient interface {
// Params returns the total set of minting parameters.
Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error)
- // EpochProvisions current minting epoch provisions value.
+ // EpochProvisions returns the current minting epoch provisions value.
EpochProvisions(ctx context.Context, in *QueryEpochProvisionsRequest, opts ...grpc.CallOption) (*QueryEpochProvisionsResponse, error)
}
@@ -277,7 +277,7 @@ func (c *queryClient) EpochProvisions(ctx context.Context, in *QueryEpochProvisi
type QueryServer interface {
// Params returns the total set of minting parameters.
Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error)
- // EpochProvisions current minting epoch provisions value.
+ // EpochProvisions returns the current minting epoch provisions value.
EpochProvisions(context.Context, *QueryEpochProvisionsRequest) (*QueryEpochProvisionsResponse, error)
}
diff --git a/x/pool-incentives/keeper/hooks.go b/x/pool-incentives/keeper/hooks.go
index a2a858d217c..b5261778419 100644
--- a/x/pool-incentives/keeper/hooks.go
+++ b/x/pool-incentives/keeper/hooks.go
@@ -4,6 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
gammtypes "github.com/osmosis-labs/osmosis/v10/x/gamm/types"
+ minttypes "github.com/osmosis-labs/osmosis/v10/x/mint/types"
)
type Hooks struct {
@@ -11,6 +12,7 @@ type Hooks struct {
}
var _ gammtypes.GammHooks = Hooks{}
+var _ minttypes.MintHooks = Hooks{}
// Create new pool incentives hooks.
func (k Keeper) Hooks() Hooks { return Hooks{k} }