Skip to content

Commit

Permalink
feat: make inflation follow a polynomial distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasmatt committed Nov 8, 2023
1 parent 7503a33 commit 7420dfd
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 567 deletions.
12 changes: 9 additions & 3 deletions proto/nibiru/inflation/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ message Params {
// inflation_enabled is the parameter that enables inflation and halts
// increasing the skipped_epochs
bool inflation_enabled = 1;
// exponential_calculation takes in the variables to calculate exponential
// polynomial_factors takes in the variables to calculate polynomial
// inflation
ExponentialCalculation exponential_calculation = 2
[ (gogoproto.nullable) = false ];
repeated string polynomial_factors = 2[

Check failure on line 28 in proto/nibiru/inflation/v1/genesis.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "2" with name "polynomial_factors" on message "Params" changed option "json_name" from "exponentialCalculation" to "polynomialFactors".

Check failure on line 28 in proto/nibiru/inflation/v1/genesis.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "2" on message "Params" changed label from "optional" to "repeated".

Check failure on line 28 in proto/nibiru/inflation/v1/genesis.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "2" on message "Params" changed type from "message" to "string".

Check failure on line 28 in proto/nibiru/inflation/v1/genesis.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "2" on message "Params" changed name from "exponential_calculation" to "polynomial_factors".
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// inflation_distribution of the minted denom
InflationDistribution inflation_distribution = 3
[ (gogoproto.nullable) = false ];
// epochs_per_period is the number of epochs that must pass before a new
// period is created
uint64 epochs_per_period = 4;

// max_period is the maximum number of periods that have inflation being
// paid off. After this period, inflation will be disabled.
uint64 max_period = 5;
}
22 changes: 0 additions & 22 deletions proto/nibiru/inflation/v1/inflation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,3 @@ message InflationDistribution {
(gogoproto.nullable) = false
];
}

// ExponentialCalculation holds factors to calculate exponential inflation on
// each period. Calculation reference:
// periodProvision = exponentialDecay
// f(x) = a * (1 - r) ^ x + c
message ExponentialCalculation {
// a defines the initial value
string a = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// r defines the reduction factor
string r = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// c defines the parameter for long term inflation
string c = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
54 changes: 27 additions & 27 deletions x/epochs/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions x/inflation/keeper/inflation.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (k Keeper) MintAndAllocateInflation(
}

// Allocate minted coins according to allocation proportions (staking, strategic, community pool)
return k.AllocateExponentialInflation(ctx, coins, params)
return k.AllocatePolynomialInflation(ctx, coins, params)
}

// MintCoins implements an alias call to the underlying supply keeper's
Expand All @@ -38,12 +38,12 @@ func (k Keeper) MintCoins(ctx sdk.Context, coin sdk.Coin) error {
return k.bankKeeper.MintCoins(ctx, types.ModuleName, coins)
}

// AllocateExponentialInflation allocates coins from the inflation to external
// AllocatePolynomialInflation allocates coins from the inflation to external
// modules according to allocation proportions:
// - staking rewards -> sdk `auth` module fee collector
// - strategic reserves -> root account of x/sudo module
// - community pool -> `sdk `distr` module community pool
func (k Keeper) AllocateExponentialInflation(
func (k Keeper) AllocatePolynomialInflation(
ctx sdk.Context,
mintedCoin sdk.Coin,
params types.Params,
Expand Down
10 changes: 5 additions & 5 deletions x/inflation/keeper/inflation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ func TestGetCirculatingSupplyAndInflationRate(t *testing.T) {
sdk.TokensFromConsensusPower(400_000_000, sdk.DefaultPowerReduction),
func(nibiruApp *app.NibiruApp, ctx sdk.Context) {
nibiruApp.InflationKeeper.SetParams(ctx, types.Params{
EpochsPerPeriod: 0,
InflationEnabled: true,
ExponentialCalculation: types.DefaultExponentialCalculation,
InflationDistribution: types.DefaultInflationDistribution,
EpochsPerPeriod: 0,
InflationEnabled: true,
PolynomialFactors: types.DefaultPolynomialFactors,
InflationDistribution: types.DefaultInflationDistribution,
})
},
sdk.ZeroDec(),
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestGetters(t *testing.T) {
nibiruApp, ctx := testapp.NewNibiruTestAppAndContext()
k := nibiruApp.InflationKeeper
require.NotPanics(t, func() {
_ = k.ExponentialCalculation(ctx)
_ = k.PolynomialFactors(ctx)
_ = k.InflationDistribution(ctx)
_ = k.InflationEnabled(ctx)
_ = k.EpochsPerPeriod(ctx)
Expand Down
4 changes: 2 additions & 2 deletions x/inflation/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
}

// VotePeriod returns the number of blocks during which voting takes place.
func (k Keeper) ExponentialCalculation(ctx sdk.Context) (res types.ExponentialCalculation) {
k.paramSpace.Get(ctx, types.KeyExponentialCalculation, &res)
func (k Keeper) PolynomialFactors(ctx sdk.Context) (res []sdk.Dec) {
k.paramSpace.Get(ctx, types.KeyPolynomialFactors, &res)
return
}

Expand Down
Loading

0 comments on commit 7420dfd

Please sign in to comment.