Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mint): add mint module #794

Merged
merged 8 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ import (
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/mint"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
Expand Down Expand Up @@ -125,6 +122,10 @@ import (
participationmodulekeeper "github.com/tendermint/spn/x/participation/keeper"
participationmoduletypes "github.com/tendermint/spn/x/participation/types"

"github.com/tendermint/spn/x/mint"
mintkeeper "github.com/tendermint/spn/x/mint/keeper"
minttypes "github.com/tendermint/spn/x/mint/types"

// this line is used by starport scaffolding # stargate/app/moduleImport

"github.com/ignite-hq/cli/ignite/pkg/cosmoscmd"
Expand Down Expand Up @@ -368,14 +369,14 @@ func New(
stakingKeeper := stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AuthKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName),
)
app.MintKeeper = mintkeeper.NewKeeper(
appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper,
app.AuthKeeper, app.BankKeeper, authtypes.FeeCollectorName,
)
app.DistrKeeper = distrkeeper.NewKeeper(
appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AuthKeeper, app.BankKeeper,
&stakingKeeper, authtypes.FeeCollectorName, app.ModuleAccountAddrs(),
)
app.MintKeeper = mintkeeper.NewKeeper(
appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper,
app.AuthKeeper, app.BankKeeper, app.DistrKeeper, authtypes.FeeCollectorName,
)
app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName),
)
Expand Down
4 changes: 4 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ genesis:
mint:
params:
mint_denom: "uspn"
distribution_proportions:
staking: "0.400000000000000000"
incentives: "0.400000000000000000"
community_pool: "0.200000000000000000"
launch:
params:
revertDelay: "5"
Expand Down
7 changes: 6 additions & 1 deletion localnet/genesis_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,12 @@
"inflation_max": "0.200000000000000000",
"inflation_min": "0.070000000000000000",
"inflation_rate_change": "0.130000000000000000",
"mint_denom": "uspn"
"mint_denom": "uspn",
"distribution_proportions": {
"staking": "0.400000000000000000",
"incentives": "0.400000000000000000",
"community_pool": "0.200000000000000000",
}
}
},
"monitoringc": {
Expand Down
16 changes: 16 additions & 0 deletions proto/mint/genesis.proto
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];
}
72 changes: 72 additions & 0 deletions proto/mint/mint.proto
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 ];
}
57 changes: 57 additions & 0 deletions proto/mint/query.proto
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];
}
2 changes: 1 addition & 1 deletion testutil/keeper/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
Expand All @@ -30,6 +29,7 @@ import (
campaigntypes "github.com/tendermint/spn/x/campaign/types"
launchkeeper "github.com/tendermint/spn/x/launch/keeper"
launchtypes "github.com/tendermint/spn/x/launch/types"
minttypes "github.com/tendermint/spn/x/mint/types"
monitoringcmodulekeeper "github.com/tendermint/spn/x/monitoringc/keeper"
monitoringcmoduletypes "github.com/tendermint/spn/x/monitoringc/types"
monitoringpmodulekeeper "github.com/tendermint/spn/x/monitoringp/keeper"
Expand Down
56 changes: 56 additions & 0 deletions x/mint/abci.go
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()),
),
)
}
Loading