-
Notifications
You must be signed in to change notification settings - Fork 872
Add x/mint module from cosmos-sdk #113
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f81622
Add custom mint module
philipsu522 b41dad2
Refactor mint module to use custom in sei
philipsu522 0f5ef5c
fix unit tests
philipsu522 cbfe810
rm file
philipsu522 faba3a8
rm empty
philipsu522 07bc899
gofumpt
philipsu522 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 seiprotocol.seichain.mint; | ||
|
|
||
| import "gogoproto/gogo.proto"; | ||
| import "mint/v1beta1/mint.proto"; | ||
|
|
||
| option go_package = "github.com/sei-protocol/sei-chain/x/mint/types"; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for protos we want to make sure this is sei-protocol not cosmos-sdk as well |
||
|
|
||
| // 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 hidden or 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,64 @@ | ||
| syntax = "proto3"; | ||
| package seiprotocol.seichain.mint; | ||
|
|
||
| option go_package = "github.com/sei-protocol/sei-chain/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.moretags) = "yaml:\"annual_provisions\"", | ||
| (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.moretags) = "yaml:\"inflation_rate_change\"", | ||
| (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", | ||
| (gogoproto.nullable) = false | ||
| ]; | ||
| // maximum inflation rate | ||
| string inflation_max = 3 [ | ||
| (gogoproto.moretags) = "yaml:\"inflation_max\"", | ||
| (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", | ||
| (gogoproto.nullable) = false | ||
| ]; | ||
| // minimum inflation rate | ||
| string inflation_min = 4 [ | ||
| (gogoproto.moretags) = "yaml:\"inflation_min\"", | ||
| (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", | ||
| (gogoproto.nullable) = false | ||
| ]; | ||
| // goal of percent bonded atoms | ||
| string goal_bonded = 5 [ | ||
| (gogoproto.moretags) = "yaml:\"goal_bonded\"", | ||
| (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", | ||
| (gogoproto.nullable) = false | ||
| ]; | ||
| // expected blocks per year | ||
| uint64 blocks_per_year = 6 [(gogoproto.moretags) = "yaml:\"blocks_per_year\""]; | ||
| // mint epoch identifier | ||
| // string epoch_identifier = 7 [(gogoproto.moretags) = "yaml:\"epoch_identifier\""]; | ||
| // number of epochs to take to reduce rewards | ||
| // int64 reduction_period_in_epochs = 8 [(gogoproto.moretags) = "yaml:\"reduction_period_in_epochs\""]; | ||
| // reduction multiplier to execute on each period | ||
| // string reduction_factor = 9 [ | ||
| // (gogoproto.moretags) = "yaml:\"reduction-factor\"", | ||
| // (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", | ||
| // (gogoproto.nullable) = false | ||
| // ]; | ||
|
|
||
| } |
This file contains hidden or 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 seiprotocol.seichain.mint; | ||
|
|
||
| import "gogoproto/gogo.proto"; | ||
| import "google/api/annotations.proto"; | ||
| import "mint/v1beta1/mint.proto"; | ||
|
|
||
| option go_package = "github.com/sei-protocol/sei-chain/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 = "/seichain/mint/v1beta1/params"; | ||
| } | ||
|
|
||
| // Inflation returns the current minting inflation value. | ||
| rpc Inflation(QueryInflationRequest) returns (QueryInflationResponse) { | ||
| option (google.api.http).get = "/seichain/mint/v1beta1/inflation"; | ||
| } | ||
|
|
||
| // AnnualProvisions current minting annual provisions value. | ||
| rpc AnnualProvisions(QueryAnnualProvisionsRequest) returns (QueryAnnualProvisionsResponse) { | ||
| option (google.api.http).get = "/seichain/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 hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
| package mint | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/cosmos/cosmos-sdk/telemetry" | ||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| "github.com/sei-protocol/sei-chain/x/mint/keeper" | ||
| "github.com/sei-protocol/sei-chain/x/mint/types" | ||
|
Comment on lines
+8
to
+9
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. example of ensuring imports are correct |
||
| ) | ||
|
|
||
| // 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) | ||
| } | ||
|
|
||
| // send the minted coins to the fee collector account | ||
| err = k.AddCollectedFees(ctx, mintedCoins) | ||
| 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()), | ||
| ), | ||
| ) | ||
| } | ||
This file contains hidden or 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,117 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/cosmos/cosmos-sdk/client" | ||
| "github.com/cosmos/cosmos-sdk/client/flags" | ||
| "github.com/sei-protocol/sei-chain/x/mint/types" | ||
| ) | ||
|
|
||
| // GetQueryCmd returns the cli query commands for the minting module. | ||
| func GetQueryCmd() *cobra.Command { | ||
| mintingQueryCmd := &cobra.Command{ | ||
| Use: types.ModuleName, | ||
| Short: "Querying commands for the minting module", | ||
| DisableFlagParsing: true, | ||
| SuggestionsMinimumDistance: 2, | ||
| RunE: client.ValidateCmd, | ||
| } | ||
|
|
||
| mintingQueryCmd.AddCommand( | ||
| GetCmdQueryParams(), | ||
| GetCmdQueryInflation(), | ||
| GetCmdQueryAnnualProvisions(), | ||
| ) | ||
|
|
||
| return mintingQueryCmd | ||
| } | ||
|
|
||
| // GetCmdQueryParams implements a command to return the current minting | ||
| // parameters. | ||
| func GetCmdQueryParams() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "params", | ||
| Short: "Query the current minting parameters", | ||
| Args: cobra.NoArgs, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| clientCtx, err := client.GetClientQueryContext(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| queryClient := types.NewQueryClient(clientCtx) | ||
|
|
||
| params := &types.QueryParamsRequest{} | ||
| res, err := queryClient.Params(cmd.Context(), params) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return clientCtx.PrintProto(&res.Params) | ||
| }, | ||
| } | ||
|
|
||
| flags.AddQueryFlagsToCmd(cmd) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| // GetCmdQueryInflation implements a command to return the current minting | ||
| // inflation value. | ||
| func GetCmdQueryInflation() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "inflation", | ||
| Short: "Query the current minting inflation value", | ||
| Args: cobra.NoArgs, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| clientCtx, err := client.GetClientQueryContext(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| queryClient := types.NewQueryClient(clientCtx) | ||
|
|
||
| params := &types.QueryInflationRequest{} | ||
| res, err := queryClient.Inflation(cmd.Context(), params) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return clientCtx.PrintString(fmt.Sprintf("%s\n", res.Inflation)) | ||
| }, | ||
| } | ||
|
|
||
| flags.AddQueryFlagsToCmd(cmd) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| // GetCmdQueryAnnualProvisions implements a command to return the current minting | ||
| // annual provisions value. | ||
| func GetCmdQueryAnnualProvisions() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "annual-provisions", | ||
| Short: "Query the current minting annual provisions value", | ||
| Args: cobra.NoArgs, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| clientCtx, err := client.GetClientQueryContext(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| queryClient := types.NewQueryClient(clientCtx) | ||
|
|
||
| params := &types.QueryAnnualProvisionsRequest{} | ||
| res, err := queryClient.AnnualProvisions(cmd.Context(), params) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return clientCtx.PrintString(fmt.Sprintf("%s\n", res.AnnualProvisions)) | ||
| }, | ||
| } | ||
|
|
||
| flags.AddQueryFlagsToCmd(cmd) | ||
|
|
||
| return cmd | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically we want to make sure all imports are migrated from
"github.com/cosmos/cosmos-sdk/x/mint" -> "github.com/sei-protocol/sei-chain/x/mint"
A lot of these within the x/mint module, but mostly just imports