Skip to content

Commit

Permalink
[mint] Update mint distribution to be daily (#718)
Browse files Browse the repository at this point in the history
* update proto

* Fix test

* Mints

* Address unit test comments

* lint

* lint

* remove prints

* bweng-test handler

* refactor release amoujnt

* fix same day buy

* Remove

* Remove

* clean up

* Fix

* rename migrations

* Update upgrades.go
  • Loading branch information
BrandonWeng authored Apr 27, 2023
1 parent 7bad0ac commit 399f2eb
Show file tree
Hide file tree
Showing 24 changed files with 2,803 additions and 507 deletions.
2 changes: 0 additions & 2 deletions cmd/seid/cmd/iavl_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ func MintParser(key []byte) ([]string, error) {
switch {
case bytes.HasPrefix(key, minttypes.MinterKey):
keyItems = append(keyItems, "MinterKey")
case bytes.HasPrefix(key, minttypes.LastTokenReleaseDate):
keyItems = append(keyItems, "LastTokenReleaseDate")
default:
keyItems = append(keyItems, UNRECOGNIZED)
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ require (
github.com/firefart/nonamedreturns v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fzipp/gocyclo v0.5.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-critic/go-critic v0.6.3 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.0 // indirect
Expand Down Expand Up @@ -141,6 +142,7 @@ require (
github.com/gostaticanalysis/nilerr v0.1.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ github.com/fullstorydev/grpcurl v1.6.0/go.mod h1:ZQ+ayqbKMJNhzLmbpCiurTVlaK2M/3n
github.com/fzipp/gocyclo v0.5.1 h1:L66amyuYogbxl0j2U+vGqJXusPF2IkduvXLnYD5TFgw=
github.com/fzipp/gocyclo v0.5.1/go.mod h1:rXPyn8fnlpa0R2csP/31uerbiVBugk5whMdlyaLkLoA=
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
Expand Down Expand Up @@ -596,6 +597,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 h1:gDLXvp5S9izjldquuoAhDzccbskOL6tDC5jMSyx3zxE=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2/go.mod h1:7pdNwVWBBHGiCxa9lAszqCJMbfTISJ7oMftp8+UGV08=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
Expand Down
41 changes: 37 additions & 4 deletions proto/mint/v1beta1/mint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,40 @@ import "gogoproto/gogo.proto";

// Minter represents the most recent
message Minter {
string start_date = 1; // yyyy-mm-dd
string end_date = 2; // yyyy-mm-dd
string denom = 3;
uint64 total_mint_amount = 4;
uint64 remaining_mint_amount = 5;
uint64 last_mint_amount = 6;
string last_mint_date = 7;
uint64 last_mint_height = 8; // yyyy-mm-dd
}

message ScheduledTokenRelease {
string start_date = 1; // yyyy-mm-dd
string end_date = 2; // yyyy-mm-dd
uint64 token_release_amount = 3;
}

// Params holds parameters for the mint module.
message Params {
option (gogoproto.goproto_stringer) = false;

// type of coin to mint
string mint_denom = 1;
// List of token release schedules
repeated ScheduledTokenRelease token_release_schedule = 2 [
(gogoproto.moretags) = "yaml:\"token_release_schedule\"",
(gogoproto.nullable) = false
];
}


// Legacy Protobufs used for migration purposes

// Minter represents the most recent
message Version2Minter {
string last_mint_amount = 1 [
(gogoproto.moretags) = "yaml:\"last_mint_amount\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
Expand All @@ -23,21 +57,20 @@ message Minter {
];
}

message ScheduledTokenRelease {
message Version2ScheduledTokenRelease {
string date = 1; // yyyy-mm-dd
int64 token_release_amount = 2;
}

// Params holds parameters for the mint module.
message Params {
message Version2Params {
option (gogoproto.goproto_stringer) = false;

// type of coin to mint
string mint_denom = 1;
// List of token release schedules
repeated ScheduledTokenRelease token_release_schedule = 2 [
repeated Version2ScheduledTokenRelease token_release_schedule = 2 [
(gogoproto.moretags) = "yaml:\"token_release_schedule\"",
(gogoproto.nullable) = false
];
}

22 changes: 8 additions & 14 deletions proto/mint/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,12 @@ message QueryMinterRequest {}
// QueryMinterResponse is the response type for the
// Query/Minter RPC method.
message QueryMinterResponse {
string last_mint_amount = 1 [
(gogoproto.moretags) = "yaml:\"last_mint_amount\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string last_mint_date = 2 [
(gogoproto.moretags) = "yaml:\"last_mint_date\""
];
int64 last_mint_height = 3 [
(gogoproto.moretags) = "yaml:\"last_mint_height\""
];
string denom = 4 [
(gogoproto.moretags) = "yaml:\"denom\""
];
string start_date = 1 [(gogoproto.moretags) = "yaml:\"start_date\""];
string end_date = 2 [(gogoproto.moretags) = "yaml:\"end_date\""];
string denom = 3 [(gogoproto.moretags) = "yaml:\"denom\""];
uint64 total_mint_amount = 4 [(gogoproto.moretags) = "yaml:\"total_mint_amount\""];
uint64 remaining_mint_amount = 5 [(gogoproto.moretags) = "yaml:\"remaining_mint_amount\""];
uint64 last_mint_amount = 6 [(gogoproto.moretags) = "yaml:\"last_mint_amount\""];
string last_mint_date = 7 [(gogoproto.moretags) = "yaml:\"last_mint_date\""];
uint64 last_mint_height = 8 [(gogoproto.moretags) = "yaml:\"last_mint_height\""];
}
3 changes: 2 additions & 1 deletion scripts/initialize_local_chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ python3 loadtest/scripts/populate_genesis_accounts.py 10 loc
# update some params in genesis file for easier use of the chain localls (make gov props faster)
cat ~/.sei/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["max_deposit_period"]="300s"' > ~/.sei/config/tmp_genesis.json && mv ~/.sei/config/tmp_genesis.json ~/.sei/config/genesis.json
cat ~/.sei/config/genesis.json | jq '.app_state["gov"]["voting_params"]["voting_period"]="30s"' > ~/.sei/config/tmp_genesis.json && mv ~/.sei/config/tmp_genesis.json ~/.sei/config/genesis.json
cat ~/.sei/config/genesis.json | jq --arg release_date "$(date +"%Y-%m-%d")" '.app_state["mint"]["params"]["token_release_schedule"]=[{"date": $release_date, "token_release_amount": "999999999999"}]' > ~/.sei/config/tmp_genesis.json && mv ~/.sei/config/tmp_genesis.json ~/.sei/config/genesis.json
cat ~/.sei/config/genesis.json | jq --arg start_date "$(date +"%Y-%m-%d")" --arg end_date "$(date -v+3d +"%Y-%m-%d")" '.app_state["mint"]["params"]["token_release_schedule"]=[{"start_date": $start_date, "end_date": $end_date, "token_release_amount": "999999999999"}]' > ~/.sei/config/tmp_genesis.json && mv ~/.sei/config/tmp_genesis.json ~/.sei/config/genesis.json
cat ~/.sei/config/genesis.json | jq --arg start_date "$(date -v+3d +"%Y-%m-%d")" --arg end_date "$(date -v+5d +"%Y-%m-%d")" '.app_state["mint"]["params"]["token_release_schedule"] += [{"start_date": $start_date, "end_date": $end_date, "token_release_amount": "999999999999"}]' > ~/.sei/config/tmp_genesis.json && mv ~/.sei/config/tmp_genesis.json ~/.sei/config/genesis.json
cat ~/.sei/config/genesis.json | jq '.app_state["gov"]["voting_params"]["expedited_voting_period"]="10s"' > ~/.sei/config/tmp_genesis.json && mv ~/.sei/config/tmp_genesis.json ~/.sei/config/genesis.json
cat ~/.sei/config/genesis.json | jq '.app_state["oracle"]["params"]["vote_period"]="1"' > ~/.sei/config/tmp_genesis.json && mv ~/.sei/config/tmp_genesis.json ~/.sei/config/genesis.json
cat ~/.sei/config/genesis.json | jq '.app_state["distribution"]["params"]["community_tax"]="0.000000000000000000"' > ~/.sei/config/tmp_genesis.json && mv ~/.sei/config/tmp_genesis.json ~/.sei/config/genesis.json
Expand Down
12 changes: 12 additions & 0 deletions utils/metrics/metrics_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,15 @@ func IncrValidatorSlashed(proposer string) {
[]metrics.Label{telemetry.NewLabel("proposer", proposer)},
)
}

// Measures number of times a denom's price is updated
// Metric Name:
//
// sei_oracle_price_update_count
func SetCoinsMinted(amount uint64, denom string) {
telemetry.SetGaugeWithLabels(
[]string{"sei", "mint", "coins"},
float32(amount),
[]metrics.Label{telemetry.NewLabel("denom", denom)},
)
}
44 changes: 9 additions & 35 deletions x/mint/keeper/hooks.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
package keeper

import (
"fmt"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
epochTypes "github.com/sei-protocol/sei-chain/x/epoch/types"
"github.com/sei-protocol/sei-chain/x/mint/types"
)

func (k Keeper) BeforeEpochStart(ctx sdk.Context, epoch epochTypes.Epoch) {
}

func (k Keeper) AfterEpochEnd(ctx sdk.Context, epoch epochTypes.Epoch) {
params := k.GetParams(ctx)
minter := k.GetMinter(ctx)
latestMinter := k.GetOrUpdateLatestMinter(ctx, epoch)
coinsToMint := latestMinter.GetReleaseAmountToday(epoch.CurrentEpochStartTime.UTC())

// If the current yyyy-mm-dd of the epoch timestamp matches any of the scheduled token release then proceed to mint
lastRelaseDate := minter.GetLastMintDateTime()
scheduledTokenRelease := types.GetScheduledTokenRelease(epoch, lastRelaseDate, params.GetTokenReleaseSchedule())
if scheduledTokenRelease == nil {
ctx.Logger().Debug(fmt.Sprintf("No release at epoch time %s; last release %s", epoch.GetCurrentEpochStartTime().String(), lastRelaseDate.Format(types.TokenReleaseDateFormat)))
if coinsToMint.IsZero() || latestMinter.GetRemainingMintAmount() == 0 {
k.Logger(ctx).Debug("No coins to mint", "minter", latestMinter)
return
}

newMinter := types.NewMinter(
sdk.NewDec(scheduledTokenRelease.TokenReleaseAmount),
scheduledTokenRelease.GetDate(),
epoch.GetCurrentEpochHeight(),
params.GetMintDenom(),
)

// mint coins, update supply
coinsToMint := newMinter.GetCoins()
if err := k.MintCoins(ctx, coinsToMint); err != nil {
panic(err)
}
Expand All @@ -41,22 +26,11 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epoch epochTypes.Epoch) {
panic(err)
}

mintedCoin := newMinter.GetCoin()
if mintedCoin.Amount.IsInt64() {
mintedCoins := float32(mintedCoin.Amount.Int64())
ctx.Logger().Info(fmt.Sprintf("Minted %f at block time %s", mintedCoins, epoch.CurrentEpochStartTime.String()))
defer telemetry.ModuleSetGauge(types.ModuleName, mintedCoins, "minted_tokens")
}

k.SetMinter(ctx, newMinter)
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeMint,
sdk.NewAttribute(types.AttributeEpochNumber, fmt.Sprintf("%d", epoch.GetCurrentEpoch())),
sdk.NewAttribute(types.AttributeKeyEpochProvisions, minter.GetLastMintDate()),
sdk.NewAttribute(sdk.AttributeKeyAmount, mintedCoin.Amount.String()),
),
)
// Released Succssfully, decrement the remaining amount by the daily release amount and update minter
amountMinted := coinsToMint.AmountOf(latestMinter.GetDenom())
latestMinter.RecordSuccessfulMint(ctx, epoch, amountMinted.Uint64())
k.Logger(ctx).Info("Minted coins", "minter", latestMinter, "amount", coinsToMint.String())
k.SetMinter(ctx, latestMinter)
}

type Hooks struct {
Expand Down
Loading

0 comments on commit 399f2eb

Please sign in to comment.