-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
5,132 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
syntax = "proto3"; | ||
package tendermint.spn.mint; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "mint/mint.proto"; | ||
|
||
option go_package = "github.com/tendermint/spn/x/mint/types"; | ||
|
||
// GenesisState defines the mint module's genesis state. | ||
message GenesisState { | ||
// minter is a space for holding current inflation information. | ||
Minter minter = 1 [(gogoproto.nullable) = false]; | ||
|
||
// params defines all the paramaters of the module. | ||
Params params = 2 [(gogoproto.nullable) = false]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
syntax = "proto3"; | ||
package tendermint.spn.mint; | ||
|
||
option go_package = "github.com/tendermint/spn/x/mint/types"; | ||
|
||
import "gogoproto/gogo.proto"; | ||
|
||
// Minter represents the minting state. | ||
message Minter { | ||
// current annual inflation rate | ||
string inflation = 1 | ||
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; | ||
// current annual expected provisions | ||
string annual_provisions = 2 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", | ||
(gogoproto.nullable) = false | ||
]; | ||
} | ||
|
||
message DistributionProportions { | ||
// staking defines the proportion of the minted minted_denom that is to be | ||
// allocated as staking rewards. | ||
string staking = 1 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", | ||
(gogoproto.nullable) = false | ||
]; | ||
// incentives defines the proportion of the minted minted_denom that is | ||
// to be allocated as incentives. | ||
string incentives = 2 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", | ||
(gogoproto.nullable) = false | ||
]; | ||
// community_pool defines the proportion of the minted minted_denom that is | ||
// to be allocated to the community pool. | ||
string community_pool = 3 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", | ||
(gogoproto.nullable) = false | ||
]; | ||
} | ||
|
||
// Params holds parameters for the mint module. | ||
message Params { | ||
option (gogoproto.goproto_stringer) = false; | ||
|
||
// type of coin to mint | ||
string mint_denom = 1; | ||
// maximum annual change in inflation rate | ||
string inflation_rate_change = 2 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", | ||
(gogoproto.nullable) = false | ||
]; | ||
// maximum inflation rate | ||
string inflation_max = 3 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", | ||
(gogoproto.nullable) = false | ||
]; | ||
// minimum inflation rate | ||
string inflation_min = 4 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", | ||
(gogoproto.nullable) = false | ||
]; | ||
// goal of percent bonded atoms | ||
string goal_bonded = 5 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", | ||
(gogoproto.nullable) = false | ||
]; | ||
// expected blocks per year | ||
uint64 blocks_per_year = 6; | ||
// distribution_proportions defines the proportion of the minted denom | ||
DistributionProportions distribution_proportions = 7 | ||
[ (gogoproto.nullable) = false ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
syntax = "proto3"; | ||
package tendermint.spn.mint; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "google/api/annotations.proto"; | ||
import "mint/mint.proto"; | ||
|
||
option go_package = "github.com/tendermint/spn/x/mint/types"; | ||
|
||
// Query provides defines the gRPC querier service. | ||
service Query { | ||
// Params returns the total set of minting parameters. | ||
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { | ||
option (google.api.http).get = "/cosmos/mint/v1beta1/params"; | ||
} | ||
|
||
// Inflation returns the current minting inflation value. | ||
rpc Inflation(QueryInflationRequest) returns (QueryInflationResponse) { | ||
option (google.api.http).get = "/cosmos/mint/v1beta1/inflation"; | ||
} | ||
|
||
// AnnualProvisions current minting annual provisions value. | ||
rpc AnnualProvisions(QueryAnnualProvisionsRequest) returns (QueryAnnualProvisionsResponse) { | ||
option (google.api.http).get = "/cosmos/mint/v1beta1/annual_provisions"; | ||
} | ||
} | ||
|
||
// QueryParamsRequest is the request type for the Query/Params RPC method. | ||
message QueryParamsRequest {} | ||
|
||
// QueryParamsResponse is the response type for the Query/Params RPC method. | ||
message QueryParamsResponse { | ||
// params defines the parameters of the module. | ||
Params params = 1 [(gogoproto.nullable) = false]; | ||
} | ||
|
||
// QueryInflationRequest is the request type for the Query/Inflation RPC method. | ||
message QueryInflationRequest {} | ||
|
||
// QueryInflationResponse is the response type for the Query/Inflation RPC | ||
// method. | ||
message QueryInflationResponse { | ||
// inflation is the current minting inflation value. | ||
bytes inflation = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; | ||
} | ||
|
||
// QueryAnnualProvisionsRequest is the request type for the | ||
// Query/AnnualProvisions RPC method. | ||
message QueryAnnualProvisionsRequest {} | ||
|
||
// QueryAnnualProvisionsResponse is the response type for the | ||
// Query/AnnualProvisions RPC method. | ||
message QueryAnnualProvisionsResponse { | ||
// annual_provisions is the current minting annual provisions value. | ||
bytes annual_provisions = 1 | ||
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package mint | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/cosmos/cosmos-sdk/telemetry" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/tendermint/spn/x/mint/keeper" | ||
"github.com/tendermint/spn/x/mint/types" | ||
) | ||
|
||
// BeginBlocker mints new tokens for the previous block. | ||
func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { | ||
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) | ||
|
||
// fetch stored minter & params | ||
minter := k.GetMinter(ctx) | ||
params := k.GetParams(ctx) | ||
|
||
// recalculate inflation rate | ||
totalStakingSupply := k.StakingTokenSupply(ctx) | ||
bondedRatio := k.BondedRatio(ctx) | ||
minter.Inflation = minter.NextInflationRate(params, bondedRatio) | ||
minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalStakingSupply) | ||
k.SetMinter(ctx, minter) | ||
|
||
// mint coins, update supply | ||
mintedCoin := minter.BlockProvision(params) | ||
mintedCoins := sdk.NewCoins(mintedCoin) | ||
|
||
err := k.MintCoins(ctx, mintedCoins) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// distribute minted coins according to the defined proportions | ||
err = k.DistributeMintedCoins(ctx, mintedCoin) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if mintedCoin.Amount.IsInt64() { | ||
defer telemetry.ModuleSetGauge(types.ModuleName, float32(mintedCoin.Amount.Int64()), "minted_tokens") | ||
} | ||
|
||
ctx.EventManager().EmitEvent( | ||
sdk.NewEvent( | ||
types.EventTypeMint, | ||
sdk.NewAttribute(types.AttributeKeyBondedRatio, bondedRatio.String()), | ||
sdk.NewAttribute(types.AttributeKeyInflation, minter.Inflation.String()), | ||
sdk.NewAttribute(types.AttributeKeyAnnualProvisions, minter.AnnualProvisions.String()), | ||
sdk.NewAttribute(sdk.AttributeKeyAmount, mintedCoin.Amount.String()), | ||
), | ||
) | ||
} |
Oops, something went wrong.