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: new token emission #2145

Merged
merged 33 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0d519e7
WIP: add liquidation params for inflation rate changes
gsk967 Jul 13, 2023
50880a8
add new token emission implementation
gsk967 Jul 14, 2023
48e0f4c
Merge branch 'main' into sai/token_emission
gsk967 Jul 15, 2023
59f23d2
inflation rate change condition updated
gsk967 Jul 17, 2023
7a53ed4
Merge branch 'main' into sai/token_emission
gsk967 Jul 18, 2023
8f8b68b
rename the LiquidationParams to InflationParams
gsk967 Jul 18, 2023
5df26bb
fix the lint
gsk967 Jul 18, 2023
f810e05
update the MaxSupply
gsk967 Jul 18, 2023
55f28b1
Merge branch 'main' into sai/token_emission
gsk967 Jul 18, 2023
1b4fd0b
Merge branch 'main' into sai/token_emission
gsk967 Jul 19, 2023
f26a104
Merge branch 'main' into sai/token_emission
gsk967 Jul 19, 2023
171eeca
rename inflation_cycle_start_time to inflation_cycle_start in params
gsk967 Jul 19, 2023
835df3f
Merge branch 'main' into sai/token_emission
gsk967 Jul 19, 2023
5ed49ac
Merge branch 'main' into sai/token_emission
gsk967 Jul 20, 2023
69cd3fa
change inflation reduction rate to bpmath.FixedBP (uint32)
gsk967 Jul 20, 2023
939414c
Merge branch 'main' into sai/token_emission
gsk967 Jul 20, 2023
4dbc879
Merge branch 'main' into sai/token_emission
gsk967 Jul 21, 2023
5260d9a
rename mint to umint
gsk967 Jul 21, 2023
5dfc76d
update the changelog
gsk967 Jul 21, 2023
bc40309
Merge branch 'main' into sai/token_emission
gsk967 Jul 21, 2023
5824dde
Merge branch 'main' into sai/token_emission
gsk967 Jul 21, 2023
a4f1a02
Merge remote-tracking branch 'origin/sai/token_emission' into sai/tok…
gsk967 Jul 21, 2023
852320b
Merge branch 'main' into sai/token_emission
gsk967 Jul 21, 2023
b7c6659
Merge branch 'main' into sai/token_emission
gsk967 Jul 23, 2023
2566e80
remove the umint and using umee inflaiton calculator for mint BeginBlock
gsk967 Jul 23, 2023
a5b87da
Merge branch 'main' into sai/token_emission
gsk967 Jul 24, 2023
eb79c89
Merge branch 'main' into sai/token_emission
gsk967 Jul 25, 2023
b7f6f2c
move cycle start time to cycle end
gsk967 Jul 25, 2023
41d5ce3
rename inflationReductionRate to factor
gsk967 Jul 25, 2023
abf283d
using bpmath.FixedBP for inflation rate change
gsk967 Jul 25, 2023
d75dfae
address the review comments
gsk967 Jul 25, 2023
ac4c881
fix the buf lint
gsk967 Jul 25, 2023
3cbf87e
fix genesis
robert-zaremba Jul 26, 2023
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [2129](https://github.com/umee-network/umee/pull/2129) Emergency Group x/ugov proto.
- [2146](https://github.com/umee-network/umee/pull/2146) Add store `GetTimeMs` and `SetTimeMs`.
- [2157](https://github.com/umee-network/umee/pull/2157) Add `x/metoken` module.
- [2145](https://github.com/umee-network/umee/pull/2145) Add hard market cap for token emission.
- [2145](https://github.com/umee-network/umee/pull/2145) Add New `Inflation Parms` to x/ugov proto and added `inflation rate` change logic to umint
- [2159](https://github.com/umee-network/umee/pull/2159) Add hard market cap for token emission.

### Improvements

Expand Down
2 changes: 2 additions & 0 deletions app/inflation/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package inflation
import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
)

type MintKeeper interface {
StakingTokenSupply(ctx sdk.Context) math.Int
SetParams(ctx sdk.Context, params minttypes.Params)
}
51 changes: 0 additions & 51 deletions app/inflation/inflatin.go

This file was deleted.

77 changes: 77 additions & 0 deletions app/inflation/inflation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package inflation

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"

"github.com/umee-network/umee/v5/util"
ugovkeeper "github.com/umee-network/umee/v5/x/ugov/keeper"
)

type Calculator struct {
UgovKeeperB ugovkeeper.Builder
MintKeeper MintKeeper
}

func (c Calculator) InflationRate(ctx sdk.Context, minter minttypes.Minter, mintParams minttypes.Params,
bondedRatio sdk.Dec) sdk.Dec {

ugovKeeper := c.UgovKeeperB.Keeper(&ctx)
inflationParams := ugovKeeper.InflationParams()
maxSupplyAmount := inflationParams.MaxSupply.Amount

totalSupply := c.MintKeeper.StakingTokenSupply(ctx)
if totalSupply.GTE(maxSupplyAmount) {
// supply is already reached the maximum amount, so inflation should be zero
return sdk.ZeroDec()
}

icst, err := ugovKeeper.GetInflationCycleStart()
util.Panic(err)

// Initially inflation_cycle start time is zero
// Once chain start inflation cycle start time will be inflation rate change executed block time
if ctx.BlockTime().After(icst.Add(inflationParams.InflationCycle)) {
// inflation cycle is completed , so we need to update the inflation max and min rate
// inflationReductionRate = 25 / 100 = 0.25
inflationReductionRate := inflationParams.InflationReductionRate.ToDec().Quo(sdk.NewDec(100))
// InflationMax = PrevInflationMax * ( 1 - 0.25)
mintParams.InflationMax = mintParams.InflationMax.Mul(sdk.OneDec().Sub(inflationReductionRate))
// InflationMin = PrevInflationMin * ( 1 - 0.25)
mintParams.InflationMin = mintParams.InflationMin.Mul(sdk.OneDec().Sub(inflationReductionRate))

// update the changed inflation min and max rates
c.MintKeeper.SetParams(ctx, mintParams)

// update the executed time of inflation cycle
err := ugovKeeper.SetInflationCycleStart(ctx.BlockTime())
util.Panic(err)
ctx.Logger().Info("inflation min and max rates are updated",
"inflation_max", mintParams.InflationMax, "inflation_min", mintParams.InflationMin,
"inflation_cycle_start", ctx.BlockTime().String(),
)
}

minter.Inflation = minttypes.DefaultInflationCalculationFn(ctx, minter, mintParams, bondedRatio)
return c.adjustInflation(totalSupply, inflationParams.MaxSupply.Amount, minter, mintParams)
}

// adjustInflation check if newly minting coins will execeed the MaxSupply then it will adjust the inflation with
// respect to MaxSupply
func (c Calculator) adjustInflation(totalSupply, maxSupply math.Int, minter minttypes.Minter,
params minttypes.Params) sdk.Dec {
minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalSupply)
newSupply := minter.BlockProvision(params).Amount
newTotalSupply := totalSupply.Add(newSupply)
if newTotalSupply.GT(maxSupply) {
newTotalSupply = maxSupply.Sub(totalSupply)
newAnnualProvision := newTotalSupply.Mul(sdk.NewInt(int64(params.BlocksPerYear)))
// AnnualProvisions = Inflation * TotalSupply
// Mint Coins = AnnualProvisions / BlocksPerYear
// so get the new Inflation
// Inflation = (New Mint Coins * BlocksPerYear ) / TotalSupply
return sdk.NewDec(newAnnualProvision.Quo(totalSupply).Int64())
}
return minter.Inflation
}
6 changes: 6 additions & 0 deletions proto/umee/ugov/v1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package umee.ugov.v1;
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "umee/ugov/v1/ugov.proto";

option go_package = "github.com/umee-network/umee/v5/x/ugov";
option (gogoproto.goproto_getters_all) = false;
Expand All @@ -17,3 +18,8 @@ message EventMinGasPrice {
message EventEmergencyGroup {
string emergency_group = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// EventInflationParams is emitted when GovUpdateInflationParams is correctly executed.
message EventInflationParams {
InflationParams params = 1 [(gogoproto.nullable) = false];
}
8 changes: 8 additions & 0 deletions proto/umee/ugov/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package umee.ugov.v1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "google/protobuf/timestamp.proto";
import "cosmos_proto/cosmos.proto";
import "umee/ugov/v1/ugov.proto";

option go_package = "github.com/umee-network/umee/v5/x/ugov";
option (gogoproto.goproto_getters_all) = false;
Expand All @@ -14,4 +16,10 @@ message GenesisState {

// Emergency Group address
string emergency_group = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// InflationParams is params for inflation rate changes
InflationParams inflation_params = 3 [(gogoproto.nullable) = false];

// Time when the last inflation cycle started
google.protobuf.Timestamp inflation_cycle_start = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
}
29 changes: 29 additions & 0 deletions proto/umee/ugov/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";

import "umee/ugov/v1/ugov.proto";

option go_package = "github.com/umee-network/umee/v5/x/ugov";

Expand All @@ -21,6 +24,16 @@ service Query {
rpc EmergencyGroup(QueryEmergencyGroup) returns (QueryEmergencyGroupResponse) {
option (google.api.http).get = "/umee/ugov/v1/emergency_group";
}

// InflationParams returns params of inflation reduction rates
rpc InflationParams(QueryInflationParams) returns (QueryInflationParamsResponse) {
option (google.api.http).get = "/umee/ugov/v1/inflation-params";
}

// InflationCycleStart returns inflation cycle start time
rpc InflationCycleStart(QueryInflationCycleStart) returns (QueryInflationCycleStartResponse) {
option (google.api.http).get = "/umee/ugov/v1/inflation-cycle-start";
}
}

// QueryMinGasPrice is a request type.
Expand All @@ -38,3 +51,19 @@ message QueryEmergencyGroup {}
message QueryEmergencyGroupResponse {
string emergency_group = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// QueryInflationParams request type.
message QueryInflationParams {}

// QueryInflationParamsResponse response type.
message QueryInflationParamsResponse {
InflationParams inflation_params = 1 [(gogoproto.nullable) = false];
}

// QueryInflationCycleStart request type.
message QueryInflationCycleStart {}

// QueryInflationCycleStartResponse response type.
message QueryInflationCycleStartResponse {
google.protobuf.Timestamp start = 1 [(gogoproto.nullable) = true, (gogoproto.stdtime) = true];
}
16 changes: 16 additions & 0 deletions proto/umee/ugov/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "cosmos/base/v1beta1/coin.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "umee/ugov/v1/ugov.proto";

option go_package = "github.com/umee-network/umee/v5/x/ugov";

Expand All @@ -17,6 +18,9 @@ service Msg {

// GovSetEmergencyGroup sets emergency group address.
rpc GovSetEmergencyGroup(MsgGovSetEmergencyGroup) returns (MsgGovSetEmergencyGroupResponse);

// GovUpdateInflationParams sets new params for inflation rate change.
rpc GovUpdateInflationParams(MsgGovUpdateInflationParams) returns (GovUpdateInflationParamsResponse);
}

// MsgGovUpdateMinGasPrice request type.
Expand All @@ -43,3 +47,15 @@ message MsgGovSetEmergencyGroup {

// MsgGovSetEmergencyGroupResponse response type.
message MsgGovSetEmergencyGroupResponse {};

// MsgGovUpdateInflationParams request type.
message MsgGovUpdateInflationParams {
option (cosmos.msg.v1.signer) = "authority";

// authority must be the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
InflationParams inflation_params = 2 [(gogoproto.nullable) = false];
}

// GovUpdateInflationParamsResponse response type.
message GovUpdateInflationParamsResponse {}
28 changes: 28 additions & 0 deletions proto/umee/ugov/v1/ugov.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
syntax = "proto3";
package umee.ugov.v1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "google/protobuf/duration.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/umee-network/umee/v5/x/ugov";
option (gogoproto.goproto_getters_all) = false;

// InflationParams params for changing the inflation min rate and max rate of mint module params.
message InflationParams {
// max_supply is the maximum supply for liquidation.
cosmos.base.v1beta1.Coin max_supply = 1 [(gogoproto.nullable) = false];
// inflation_cycle duration after which inflation rates are changed.
google.protobuf.Duration inflation_cycle = 2 [
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true,
(gogoproto.jsontag) = "inflation_cycle,omitempty",
(gogoproto.moretags) = "yaml:\"inflation_cycle\""
];
// inflation_reduction_rate for every inflation cycle.
uint32 inflation_reduction_rate = 3 [
(gogoproto.customtype) = "github.com/umee-network/umee/v5/util/bpmath.FixedBP",
(gogoproto.nullable) = false
];
}
48 changes: 48 additions & 0 deletions x/ugov/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func GetQueryCmd() *cobra.Command {

cmd.AddCommand(
QueryMinGasPrice(),
QueryLiquidationParams(),
QueryInflationCyleStartedTime(),
)

return cmd
Expand Down Expand Up @@ -49,3 +51,49 @@ func QueryMinGasPrice() *cobra.Command {

return cmd
}

// QueryLiquidationParams create the Msg/QueryLiquidationParams CLI.
func QueryLiquidationParams() *cobra.Command {
cmd := &cobra.Command{
Use: "liquidation-params",
Args: cobra.NoArgs,
Short: "Query the liquidation params",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := ugov.NewQueryClient(clientCtx)
resp, err := queryClient.InflationParams(cmd.Context(), &ugov.QueryInflationParams{})
return cli.PrintOrErr(resp, err, clientCtx)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// QueryInflationCyleStartedTime create the Msg/QueryInflationCyleStartedTime CLI.
func QueryInflationCyleStartedTime() *cobra.Command {
cmd := &cobra.Command{
Use: "inflation-cycle-start-time",
Args: cobra.NoArgs,
Short: "Query the When the Inflation Cycle is Started",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := ugov.NewQueryClient(clientCtx)
resp, err := queryClient.InflationCycleStart(cmd.Context(), &ugov.QueryInflationCycleStart{})
return cli.PrintOrErr(resp, err, clientCtx)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
2 changes: 2 additions & 0 deletions x/ugov/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ func init() {
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgGovUpdateMinGasPrice{}, proto.MessageName(&MsgGovUpdateMinGasPrice{}), nil)
cdc.RegisterConcrete(&MsgGovSetEmergencyGroup{}, "umee/ugov/MsgGovSetEmergencyGroup", nil)
cdc.RegisterConcrete(&MsgGovUpdateInflationParams{}, "umee/ugov/MsgGovUpdateInflationParams", nil)
}

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgGovUpdateMinGasPrice{},
&MsgGovSetEmergencyGroup{},
&MsgGovUpdateInflationParams{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
Expand Down
Loading