diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eda47a87..9a43e8c9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1620](https://github.com/NibiruChain/nibiru/pull/1620) - Token factory transaction messages for Mint and Burn * [#1573](https://github.com/NibiruChain/nibiru/pull/1573) - feat(perp): Close markets and compute settlement price * [#1632](https://github.com/NibiruChain/nibiru/pull/1632) - feat(perp): Add settle position transaction +* [#1670](https://github.com/NibiruChain/nibiru/pull/1670) - feat(inflation): Make inflation polynomial ### State Machine Breaking diff --git a/proto/nibiru/inflation/v1/genesis.proto b/proto/nibiru/inflation/v1/genesis.proto index 6eacf44c4..e72fff223 100644 --- a/proto/nibiru/inflation/v1/genesis.proto +++ b/proto/nibiru/inflation/v1/genesis.proto @@ -23,14 +23,23 @@ 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[ + (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; + + // periods_per_year is the number of periods that occur in a year + uint64 periods_per_year = 5; + + // max_period is the maximum number of periods that have inflation being + // paid off. After this period, inflation will be disabled. + uint64 max_period = 6; } diff --git a/proto/nibiru/inflation/v1/inflation.proto b/proto/nibiru/inflation/v1/inflation.proto index ca900bb9e..cad921ede 100644 --- a/proto/nibiru/inflation/v1/inflation.proto +++ b/proto/nibiru/inflation/v1/inflation.proto @@ -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 - ]; -} diff --git a/x/epochs/types/query.pb.go b/x/epochs/types/query.pb.go index e486ff116..bab7018fb 100644 --- a/x/epochs/types/query.pb.go +++ b/x/epochs/types/query.pb.go @@ -208,33 +208,33 @@ func init() { func init() { proto.RegisterFile("nibiru/epochs/v1/query.proto", fileDescriptor_2d273c3d69b40555) } var fileDescriptor_2d273c3d69b40555 = []byte{ - // 413 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x4f, 0x8b, 0xd3, 0x40, - 0x14, 0xcf, 0xd4, 0x5a, 0x70, 0xac, 0x20, 0x83, 0x68, 0x8c, 0x35, 0x2d, 0xf1, 0x0f, 0xb5, 0x96, - 0x0c, 0xa9, 0x27, 0x3d, 0x49, 0x8b, 0x82, 0x17, 0xc1, 0xe0, 0xc9, 0x8b, 0x4c, 0xe2, 0x34, 0x1d, - 0xb0, 0x33, 0x69, 0x66, 0x52, 0xec, 0xd5, 0xd3, 0x1e, 0x17, 0x96, 0xfd, 0x12, 0xfb, 0x49, 0x7a, - 0x2c, 0xec, 0x65, 0x4f, 0xcb, 0xd2, 0xee, 0x07, 0x59, 0x3a, 0x93, 0x2e, 0xdd, 0xfe, 0x81, 0xde, - 0x92, 0xf7, 0xfb, 0xf3, 0x7e, 0xef, 0xbd, 0x81, 0x35, 0xce, 0x22,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 0xf5, 0xe5, 0xb0, 0x1a, 0xaf, 0x91, 0x3b, 0x67, 0x25, 0x78, 0x5f, 0x5b, 0xa0, 0x23, 0x00, - 0xe1, 0x6d, 0x46, 0x89, 0x9a, 0xdb, 0x13, 0xec, 0x5e, 0x8b, 0xf3, 0xee, 0x00, 0xa6, 0x89, 0xe4, - 0xbd, 0xf9, 0x7f, 0x7e, 0x7d, 0x52, 0xaa, 0xa3, 0x97, 0x78, 0xf3, 0x04, 0xe6, 0x54, 0xe6, 0x17, - 0x9d, 0x02, 0x58, 0x5d, 0x1f, 0x09, 0xb5, 0xf6, 0xb4, 0xd8, 0xb1, 0x33, 0xe7, 0xfd, 0x41, 0xdc, - 0x22, 0x50, 0x5b, 0x07, 0x7a, 0x8b, 0x5e, 0xef, 0x09, 0x74, 0x67, 0x81, 0xdd, 0xaf, 0xd3, 0xb9, - 0x0b, 0x66, 0x73, 0x17, 0x5c, 0xcd, 0x5d, 0x70, 0xbc, 0x70, 0xad, 0xd9, 0xc2, 0xb5, 0x2e, 0x16, - 0xae, 0xf5, 0xab, 0x9d, 0x30, 0x35, 0xc8, 0x23, 0x3f, 0x16, 0x43, 0xfc, 0x5d, 0x3b, 0xf5, 0x06, - 0x84, 0xf1, 0x95, 0xeb, 0xbf, 0x95, 0xaf, 0x9a, 0xa4, 0x54, 0x46, 0x15, 0xfd, 0xd2, 0x3e, 0xdc, - 0x04, 0x00, 0x00, 0xff, 0xff, 0x57, 0x11, 0x22, 0x69, 0x19, 0x03, 0x00, 0x00, + // 412 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x4d, 0x8b, 0xd3, 0x40, + 0x18, 0xce, 0xd4, 0x5a, 0x70, 0xac, 0x20, 0x83, 0x68, 0x8c, 0x35, 0x2d, 0xf1, 0x83, 0x5a, 0x4b, + 0x86, 0xd4, 0x93, 0x9e, 0xa4, 0x45, 0xc1, 0x8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ff, 0xff, 0xe7, 0x96, 0x70, 0xa3, 0x19, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/inflation/keeper/hooks_test.go b/x/inflation/keeper/hooks_test.go index 97ccd310f..0db86f9bc 100644 --- a/x/inflation/keeper/hooks_test.go +++ b/x/inflation/keeper/hooks_test.go @@ -74,13 +74,13 @@ func TestPeriodChangesSkippedEpochsAfterEpochEnd(t *testing.T) { false, }, { - "[Period 0] period changes once enough epochs have passed", - 0, - currentEpochPeriod + 1, - epochstypes.DayEpochID, - 0, - true, - true, + name: "[Period 0] period changes once enough epochs have passed", + currentPeriod: 0, + height: currentEpochPeriod + 1, + epochIdentifier: epochstypes.DayEpochID, + skippedEpochs: 0, + InflationEnabled: true, + periodChanges: true, }, { "[Period 1] period stays the same under the epoch per period", @@ -161,6 +161,7 @@ func TestPeriodChangesSkippedEpochsAfterEpochEnd(t *testing.T) { // Perform Epoch Hooks futureCtx := ctx.WithBlockTime(time.Now().Add(time.Minute)) + fmt.Println("tc.height", tc.height) nibiruApp.EpochsKeeper.BeforeEpochStart(futureCtx, tc.epochIdentifier, tc.height) nibiruApp.EpochsKeeper.AfterEpochEnd(futureCtx, tc.epochIdentifier, tc.height) @@ -168,14 +169,22 @@ func TestPeriodChangesSkippedEpochsAfterEpochEnd(t *testing.T) { period := nibiruApp.InflationKeeper.CurrentPeriod.Peek(ctx) if tc.periodChanges { + fmt.Println("periodChanges", tc.periodChanges) newProvision := nibiruApp.InflationKeeper.GetEpochMintProvision(ctx) + expectedProvision := types.CalculateEpochMintProvision( nibiruApp.InflationKeeper.GetParams(ctx), period, ) + + fmt.Println("periodChanges", tc.periodChanges) + fmt.Println("newProvision", newProvision) + fmt.Println("expectedProvision", expectedProvision) + fmt.Println("originalProvision", originalProvision) + require.Equal(t, expectedProvision, newProvision) // mint provisions will change - require.NotEqual(t, newProvision.BigInt().Uint64(), originalProvision.BigInt().Uint64()) + require.NotEqual(t, newProvision, originalProvision) require.Equal(t, currentSkippedEpochs, skippedEpochs) require.Equal(t, currentPeriod+1, period) } else { diff --git a/x/inflation/keeper/inflation.go b/x/inflation/keeper/inflation.go index ab9355b67..a03987427 100644 --- a/x/inflation/keeper/inflation.go +++ b/x/inflation/keeper/inflation.go @@ -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 @@ -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, @@ -125,7 +125,11 @@ func (k Keeper) GetInflationRate(ctx sdk.Context, mintDenom string) sdk.Dec { // EpochMintProvision * 365 / circulatingSupply * 100 circulatingSupplyToDec := sdk.NewDecFromInt(circulatingSupply) - return epochMintProvision.MulInt64(int64(k.EpochsPerPeriod(ctx))).Quo(circulatingSupplyToDec).Mul(sdk.NewDec(100)) + return epochMintProvision. + MulInt64(int64(k.EpochsPerPeriod(ctx))). + MulInt64(int64(k.PeriodsPerYear(ctx))). + Quo(circulatingSupplyToDec). + Mul(sdk.NewDec(100)) } // GetEpochMintProvision retrieves necessary params KV storage diff --git a/x/inflation/keeper/inflation_test.go b/x/inflation/keeper/inflation_test.go index 103e6d721..0394dfc5e 100644 --- a/x/inflation/keeper/inflation_test.go +++ b/x/inflation/keeper/inflation_test.go @@ -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(), @@ -141,13 +141,13 @@ func TestGetCirculatingSupplyAndInflationRate(t *testing.T) { "high supply", sdk.TokensFromConsensusPower(800_000_000, sdk.DefaultPowerReduction), func(nibiruApp *app.NibiruApp, ctx sdk.Context) {}, - sdk.MustNewDecFromStr("50.674438476562500000"), + sdk.MustNewDecFromStr("27.095518287362700000"), }, { "low supply", sdk.TokensFromConsensusPower(400_000_000, sdk.DefaultPowerReduction), func(nibiruApp *app.NibiruApp, ctx sdk.Context) {}, - sdk.MustNewDecFromStr("101.348876953125000000"), + sdk.MustNewDecFromStr("54.191036574725400000"), }, } for _, tc := range testCases { @@ -177,7 +177,8 @@ func TestGetters(t *testing.T) { nibiruApp, ctx := testapp.NewNibiruTestAppAndContext() k := nibiruApp.InflationKeeper require.NotPanics(t, func() { - _ = k.ExponentialCalculation(ctx) + _ = k.PolynomialFactors(ctx) + _ = k.PeriodsPerYear(ctx) _ = k.InflationDistribution(ctx) _ = k.InflationEnabled(ctx) _ = k.EpochsPerPeriod(ctx) diff --git a/x/inflation/keeper/params.go b/x/inflation/keeper/params.go index 7b8b2ce0b..c741ff304 100644 --- a/x/inflation/keeper/params.go +++ b/x/inflation/keeper/params.go @@ -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 } @@ -39,3 +39,8 @@ func (k Keeper) EpochsPerPeriod(ctx sdk.Context) (res uint64) { k.paramSpace.Get(ctx, types.KeyEpochsPerPeriod, &res) return } + +func (k Keeper) PeriodsPerYear(ctx sdk.Context) (res uint64) { + k.paramSpace.Get(ctx, types.KeyPeriodsPerYear, &res) + return +} diff --git a/x/inflation/types/genesis.pb.go b/x/inflation/types/genesis.pb.go index c008f5889..61e7d72ce 100644 --- a/x/inflation/types/genesis.pb.go +++ b/x/inflation/types/genesis.pb.go @@ -5,6 +5,7 @@ package types import ( fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" io "io" @@ -93,14 +94,19 @@ type Params struct { // inflation_enabled is the parameter that enables inflation and halts // increasing the skipped_epochs InflationEnabled bool `protobuf:"varint,1,opt,name=inflation_enabled,json=inflationEnabled,proto3" json:"inflation_enabled,omitempty"` - // exponential_calculation takes in the variables to calculate exponential + // polynomial_factors takes in the variables to calculate polynomial // inflation - ExponentialCalculation ExponentialCalculation `protobuf:"bytes,2,opt,name=exponential_calculation,json=exponentialCalculation,proto3" json:"exponential_calculation"` + PolynomialFactors []github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,rep,name=polynomial_factors,json=polynomialFactors,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"polynomial_factors"` // inflation_distribution of the minted denom InflationDistribution InflationDistribution `protobuf:"bytes,3,opt,name=inflation_distribution,json=inflationDistribution,proto3" json:"inflation_distribution"` // epochs_per_period is the number of epochs that must pass before a new // period is created EpochsPerPeriod uint64 `protobuf:"varint,4,opt,name=epochs_per_period,json=epochsPerPeriod,proto3" json:"epochs_per_period,omitempty"` + // periods_per_year is the number of periods that occur in a year + PeriodsPerYear uint64 `protobuf:"varint,5,opt,name=periods_per_year,json=periodsPerYear,proto3" json:"periods_per_year,omitempty"` + // max_period is the maximum number of periods that have inflation being + // paid off. After this period, inflation will be disabled. + MaxPeriod uint64 `protobuf:"varint,6,opt,name=max_period,json=maxPeriod,proto3" json:"max_period,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -143,13 +149,6 @@ func (m *Params) GetInflationEnabled() bool { return false } -func (m *Params) GetExponentialCalculation() ExponentialCalculation { - if m != nil { - return m.ExponentialCalculation - } - return ExponentialCalculation{} -} - func (m *Params) GetInflationDistribution() InflationDistribution { if m != nil { return m.InflationDistribution @@ -164,6 +163,20 @@ func (m *Params) GetEpochsPerPeriod() uint64 { return 0 } +func (m *Params) GetPeriodsPerYear() uint64 { + if m != nil { + return m.PeriodsPerYear + } + return 0 +} + +func (m *Params) GetMaxPeriod() uint64 { + if m != nil { + return m.MaxPeriod + } + return 0 +} + func init() { proto.RegisterType((*GenesisState)(nil), "nibiru.inflation.v1.GenesisState") proto.RegisterType((*Params)(nil), "nibiru.inflation.v1.Params") @@ -172,31 +185,35 @@ func init() { func init() { proto.RegisterFile("nibiru/inflation/v1/genesis.proto", fileDescriptor_2d00e2bb98c08f74) } var fileDescriptor_2d00e2bb98c08f74 = []byte{ - // 375 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x52, 0x4d, 0x4f, 0xfa, 0x30, - 0x1c, 0xde, 0x80, 0x2c, 0xff, 0x94, 0xbf, 0x2f, 0x54, 0x45, 0x82, 0xc9, 0x44, 0x8c, 0x09, 0x81, - 0x64, 0x0b, 0x78, 0xf2, 0x0a, 0x12, 0xc3, 0xc5, 0x10, 0xbc, 0x79, 0x59, 0xba, 0xad, 0x8e, 0xea, - 0x68, 0x9b, 0xad, 0x23, 0xf8, 0x0d, 0x3c, 0xfa, 0x69, 0xfc, 0x0c, 0x1c, 0x39, 0x7a, 0x32, 0x06, - 0xbe, 0x88, 0xb1, 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86, 0x99, 0x67, 0x90, 0x59, 0xd2, - 0x2f, 0x55, 0x71, 0x2e, 0x0b, 0x03, 0x50, 0xcd, 0x8a, 0xf9, 0x24, 0x16, 0x11, 0x71, 0x13, 0x19, - 0x55, 0x94, 0x51, 0xed, 0xdc, 0xa8, 0xd1, 0xdf, 0xe5, 0x76, 0xc7, 0x91, 0x26, 0x9d, 0x90, 0x3c, - 0x12, 0xb6, 0x41, 0x45, 0xcd, 0xca, 0xe1, 0x38, 0x72, 0xd2, 0xb1, 0x96, 0xe4, 0xd8, 0x0e, 0x14, - 0x31, 0xc6, 0xd1, 0x58, 0xc2, 0xfd, 0xd1, 0x72, 0x6d, 0xea, 0xab, 0xb5, 0xa9, 0x7f, 0xaf, 0x4d, - 0xfd, 0x7d, 0x63, 0x6a, 0xab, 0x8d, 0xa9, 0x7d, 0x6e, 0x4c, 0xed, 0xd1, 0x0e, 0x88, 0x98, 0x26, - 0xae, 0xe5, 0xb1, 0x99, 0x7d, 0x2f, 0x8b, 0x0d, 0xa6, 0x88, 0x50, 0x3b, 0xdd, 0x8c, 0xc5, 0xce, - 0x6e, 0x88, 0x57, 0x8e, 0x63, 0xd7, 0x90, 0x5b, 0x71, 0xfd, 0x13, 0x00, 0x00, 0xff, 0xff, 0xb4, - 0xdb, 0xd9, 0x20, 0x8a, 0x02, 0x00, 0x00, + // 438 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x92, 0xcf, 0x6e, 0xd4, 0x30, + 0x10, 0xc6, 0x37, 0xdb, 0x25, 0xa2, 0x2e, 0x94, 0xae, 0x81, 0x2a, 0x2a, 0x22, 0x5d, 0x8a, 0x40, + 0x51, 0x11, 0xb6, 0x5a, 0x4e, 0x5c, 0x97, 0x16, 0xd4, 0x0b, 0x8a, 0xc2, 0x09, 0x24, 0x14, 0x39, + 0x89, 0x9b, 0xb5, 0x9a, 0xc4, 0x96, 0xed, 0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x97, 0xf9, 0xe6, 0xa2, 0x3e, 0xdc, 0x07, 0x00, 0x00, 0xff, 0xff, 0x1c, 0x56, + 0x6e, 0x63, 0xc6, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -262,6 +279,16 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.MaxPeriod != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.MaxPeriod)) + i-- + dAtA[i] = 0x30 + } + if m.PeriodsPerYear != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.PeriodsPerYear)) + i-- + dAtA[i] = 0x28 + } if m.EpochsPerPeriod != 0 { i = encodeVarintGenesis(dAtA, i, uint64(m.EpochsPerPeriod)) i-- @@ -277,16 +304,20 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { } i-- dAtA[i] = 0x1a - { - size, err := m.ExponentialCalculation.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if len(m.PolynomialFactors) > 0 { + for iNdEx := len(m.PolynomialFactors) - 1; iNdEx >= 0; iNdEx-- { + { + size := m.PolynomialFactors[iNdEx].Size() + i -= size + if _, err := m.PolynomialFactors[iNdEx].MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) } - i-- - dAtA[i] = 0x12 if m.InflationEnabled { i-- if m.InflationEnabled { @@ -337,13 +368,23 @@ func (m *Params) Size() (n int) { if m.InflationEnabled { n += 2 } - l = m.ExponentialCalculation.Size() - n += 1 + l + sovGenesis(uint64(l)) + if len(m.PolynomialFactors) > 0 { + for _, e := range m.PolynomialFactors { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } l = m.InflationDistribution.Size() n += 1 + l + sovGenesis(uint64(l)) if m.EpochsPerPeriod != 0 { n += 1 + sovGenesis(uint64(m.EpochsPerPeriod)) } + if m.PeriodsPerYear != 0 { + n += 1 + sovGenesis(uint64(m.PeriodsPerYear)) + } + if m.MaxPeriod != 0 { + n += 1 + sovGenesis(uint64(m.MaxPeriod)) + } return n } @@ -525,9 +566,9 @@ func (m *Params) Unmarshal(dAtA []byte) error { m.InflationEnabled = bool(v != 0) case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ExponentialCalculation", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field PolynomialFactors", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowGenesis @@ -537,22 +578,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthGenesis } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthGenesis } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.ExponentialCalculation.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + var v github_com_cosmos_cosmos_sdk_types.Dec + m.PolynomialFactors = append(m.PolynomialFactors, v) + if err := m.PolynomialFactors[len(m.PolynomialFactors)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -608,6 +652,44 @@ func (m *Params) Unmarshal(dAtA []byte) error { break } } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PeriodsPerYear", wireType) + } + m.PeriodsPerYear = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PeriodsPerYear |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxPeriod", wireType) + } + m.MaxPeriod = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxPeriod |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/inflation/types/inflation.pb.go b/x/inflation/types/inflation.pb.go index ecc0666b3..632c86ebf 100644 --- a/x/inflation/types/inflation.pb.go +++ b/x/inflation/types/inflation.pb.go @@ -72,55 +72,8 @@ func (m *InflationDistribution) XXX_DiscardUnknown() { var xxx_messageInfo_InflationDistribution proto.InternalMessageInfo -// ExponentialCalculation holds factors to calculate exponential inflation on -// each period. Calculation reference: -// periodProvision = exponentialDecay -// f(x) = a * (1 - r) ^ x + c -type ExponentialCalculation struct { - // a defines the initial value - A github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=a,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"a"` - // r defines the reduction factor - R github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=r,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"r"` - // c defines the parameter for long term inflation - C github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=c,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"c"` -} - -func (m *ExponentialCalculation) Reset() { *m = ExponentialCalculation{} } -func (m *ExponentialCalculation) String() string { return proto.CompactTextString(m) } -func (*ExponentialCalculation) ProtoMessage() {} -func (*ExponentialCalculation) Descriptor() ([]byte, []int) { - return fileDescriptor_37da805e9a324a97, []int{1} -} -func (m *ExponentialCalculation) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ExponentialCalculation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ExponentialCalculation.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ExponentialCalculation) XXX_Merge(src proto.Message) { - xxx_messageInfo_ExponentialCalculation.Merge(m, src) -} -func (m *ExponentialCalculation) XXX_Size() int { - return m.Size() -} -func (m *ExponentialCalculation) XXX_DiscardUnknown() { - xxx_messageInfo_ExponentialCalculation.DiscardUnknown(m) -} - -var xxx_messageInfo_ExponentialCalculation proto.InternalMessageInfo - func init() { proto.RegisterType((*InflationDistribution)(nil), "nibiru.inflation.v1.InflationDistribution") - proto.RegisterType((*ExponentialCalculation)(nil), "nibiru.inflation.v1.ExponentialCalculation") } func init() { @@ -128,28 +81,25 @@ func init() { } var fileDescriptor_37da805e9a324a97 = []byte{ - // 329 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0xcd, 0x4a, 0x3b, 0x31, - 0x14, 0xc5, 0x27, 0xfd, 0xc3, 0x1f, 0x0c, 0x58, 0x71, 0xfc, 0xa0, 0xb8, 0x48, 0xa5, 0x82, 0xb8, - 0x71, 0x42, 0x71, 0xeb, 0xaa, 0xad, 0x8b, 0x6e, 0x44, 0x0a, 0x22, 0x08, 0x52, 0x32, 0x69, 0x9c, - 0x86, 0xce, 0xe4, 0x0e, 0x49, 0xa6, 0xb6, 0x6f, 0xe1, 0x53, 0xf8, 0x2c, 0x5d, 0x16, 0x57, 0xe2, - 0xa2, 0x48, 0xe7, 0x45, 0x64, 0x3e, 0x6c, 0xbb, 0x9e, 0x55, 0x6e, 0x92, 0x73, 0x7e, 0x70, 0x0f, - 0x07, 0x5f, 0x28, 0xe9, 0x4b, 0x9d, 0x50, 0xa9, 0x5e, 0x43, 0x66, 0x25, 0x28, 0x3a, 0x6d, 0x6f, - 0x2f, 0x5e, 0xac, 0xc1, 0x82, 0x7b,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ef, 0x29, 0x71, 0x96, 0x29, - 0x71, 0xbe, 0x52, 0xe2, 0x3c, 0xd3, 0x1d, 0xc8, 0x7d, 0xde, 0xa6, 0xee, 0x98, 0x49, 0x45, 0xcb, - 0xfa, 0xcd, 0x76, 0x0a, 0x98, 0x13, 0xfd, 0xff, 0x79, 0x9f, 0x6e, 0x7e, 0x03, 0x00, 0x00, 0xff, - 0xff, 0xe0, 0x01, 0x1c, 0xb7, 0xa1, 0x02, 0x00, 0x00, + // 284 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xce, 0xcb, 0x4c, 0xca, + 0x2c, 0x2a, 0xd5, 0xcf, 0xcc, 0x4b, 0xcb, 0x49, 0x2c, 0xc9, 0xcc, 0xcf, 0xd3, 0x2f, 0x33, 0x44, + 0x70, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x84, 0x21, 0x8a, 0xf4, 0x10, 0xe2, 0x65, 0x86, + 0x52, 0x22, 0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0x79, 0x7d, 0x10, 0x0b, 0xa2, 0x54, 0x69, 0x19, 0x13, + 0x97, 0xa8, 0x27, 0x4c, 0x99, 0x4b, 0x66, 0x71, 0x49, 0x51, 0x66, 0x52, 0x29, 0x88, 0x2d, 0x14, + 0xce, 0xc5, 0x5f, 0x5c, 0x92, 0x98, 0x9d, 0x99, 0x97, 0x1e, 0x5f, 0x94, 0x5a, 0x9e, 0x58, 0x94, + 0x52, 0x2c, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0xe9, 0xa4, 0x77, 0xe2, 0x9e, 0x3c, 0xc3, 0xad, 0x7b, + 0xf2, 0x6a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xc9, 0xf9, 0xc5, + 0xb9, 0xf9, 0xc5, 0x50, 0x4a, 0xb7, 0x38, 0x25, 0x5b, 0xbf, 0xa4, 0xb2, 0x20, 0xb5, 0x58, 0xcf, + 0x25, 0x35, 0x39, 0x88, 0x0f, 0x6a, 0x4c, 0x10, 0xc4, 0x14, 0xa1, 0x50, 0x2e, 0xbe, 0xe4, 0xfc, + 0xdc, 0xdc, 0xd2, 0xbc, 0xcc, 0x92, 0xca, 0xf8, 0x82, 0xfc, 0xfc, 0x1c, 0x09, 0x26, 0xb2, 0xcc, + 0xe5, 0x85, 0x9b, 0x12, 0x90, 0x9f, 0x9f, 0x23, 0x14, 0xcb, 0x25, 0x54, 0x5c, 0x52, 0x94, 0x58, + 0x92, 0x9a, 0x9e, 0x99, 0x1c, 0x5f, 0x94, 0x5a, 0x9c, 0x5a, 0x54, 0x96, 0x5a, 0x2c, 0xc1, 0x4c, + 0x96, 0xd1, 0x82, 0x70, 0x93, 0x82, 0xa0, 0x06, 0x39, 0x79, 0x9e, 0x78, 0x24, 0xc7, 0x78, 0xe1, + 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, + 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x3e, 0x92, 0xa1, 0x7e, 0xe0, 0x80, 0x77, 0xce, 0x48, 0xcc, 0xcc, + 0xd3, 0x87, 0xc6, 0x54, 0x05, 0x52, 0x5c, 0x81, 0x6d, 0x48, 0x62, 0x03, 0x07, 0xbd, 0x31, 0x20, + 0x00, 0x00, 0xff, 0xff, 0x75, 0xbf, 0x6b, 0xae, 0xcc, 0x01, 0x00, 0x00, } func (m *InflationDistribution) Marshal() (dAtA []byte, err error) { @@ -205,59 +155,6 @@ func (m *InflationDistribution) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *ExponentialCalculation) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ExponentialCalculation) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ExponentialCalculation) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.C.Size() - i -= size - if _, err := m.C.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintInflation(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - { - size := m.R.Size() - i -= size - if _, err := m.R.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintInflation(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - { - size := m.A.Size() - i -= size - if _, err := m.A.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintInflation(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - func encodeVarintInflation(dAtA []byte, offset int, v uint64) int { offset -= sovInflation(v) base := offset @@ -284,21 +181,6 @@ func (m *InflationDistribution) Size() (n int) { return n } -func (m *ExponentialCalculation) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.A.Size() - n += 1 + l + sovInflation(uint64(l)) - l = m.R.Size() - n += 1 + l + sovInflation(uint64(l)) - l = m.C.Size() - n += 1 + l + sovInflation(uint64(l)) - return n -} - func sovInflation(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -457,158 +339,6 @@ func (m *InflationDistribution) Unmarshal(dAtA []byte) error { } return nil } -func (m *ExponentialCalculation) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowInflation - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ExponentialCalculation: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ExponentialCalculation: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field A", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowInflation - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthInflation - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthInflation - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.A.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field R", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowInflation - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthInflation - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthInflation - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.R.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field C", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowInflation - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthInflation - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthInflation - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.C.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipInflation(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthInflation - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipInflation(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/inflation/types/inflation_calculation.go b/x/inflation/types/inflation_calculation.go index 9fa5e542f..e1c6d2c38 100644 --- a/x/inflation/types/inflation_calculation.go +++ b/x/inflation/types/inflation_calculation.go @@ -9,25 +9,31 @@ func CalculateEpochMintProvision( params Params, period uint64, ) sdk.Dec { - if params.EpochsPerPeriod == 0 { + if params.EpochsPerPeriod == 0 || !params.InflationEnabled || period >= params.MaxPeriod { return sdk.ZeroDec() } - x := period // period - a := params.ExponentialCalculation.A // initial value - r := params.ExponentialCalculation.R // reduction factor - c := params.ExponentialCalculation.C // long term inflation + // truncating to the nearest integer + x := period - // exponentialDecay := a * (1 - r) ^ x + c - decay := sdk.OneDec().Sub(r) - periodProvision := a.Mul(decay.Power(x)).Add(c) + // Calculate the value of the polynomial at x + polynomialValue := polynomial(params.PolynomialFactors, sdk.NewDec(int64(x))) - // epochProvision = periodProvision / epochsPerPeriod - epochProvision := periodProvision.QuoInt64(int64(params.EpochsPerPeriod)) + if polynomialValue.IsNegative() { + // Just to make sure nothing weird occur + return sdk.ZeroDec() + } + + return polynomialValue.Quo(sdk.NewDec(int64(params.EpochsPerPeriod))) +} + +// Compute the value of x given the polynomial factors +func polynomial(factors []sdk.Dec, x sdk.Dec) sdk.Dec { + result := sdk.ZeroDec() + for i, factor := range factors { + result = result.Add(factor.Mul(x.Power(uint64(len(factors) - i - 1)))) + } - // Multiply epochMintProvision with power reduction (10^6 for unibi) as the - // calculation is based on `NIBI` and the issued tokens need to be given in - // `uNIBI` - epochProvision = epochProvision.MulInt(sdk.DefaultPowerReduction) - return epochProvision + // Multiply by 1 million to get the value in unibi + return result.Mul(sdk.NewDec(1_000_000)) } diff --git a/x/inflation/types/inflation_calculation_test.go b/x/inflation/types/inflation_calculation_test.go index 1b9b21ba8..a63701e87 100644 --- a/x/inflation/types/inflation_calculation_test.go +++ b/x/inflation/types/inflation_calculation_test.go @@ -8,63 +8,45 @@ import ( "github.com/stretchr/testify/require" ) +// These numbers are for year n month 1 +var ExpectedYearlyInflation = []sdk.Dec{ + sdk.NewDec(195_895_391_000_000), + sdk.NewDec(156_348_637_000_000), + sdk.NewDec(124_785_459_000_000), + sdk.NewDec(99_594_157_000_000), + sdk.NewDec(79_488_398_000_000), + sdk.NewDec(63_441_527_000_000), + sdk.NewDec(50_634_148_000_000), + sdk.NewDec(40_412_283_000_000), +} + +var ExpectedTotalInflation = sdk.NewDec(810_600_000_000_000) + func TestCalculateEpochMintProvision(t *testing.T) { - testCases := []struct { - name string - period uint64 - expEpochProvision sdk.Dec - }{ - { - "pass - initial period", - 0, - sdk.MustNewDecFromStr("1110672624143.835616438356000000"), - }, - { - "pass - period 1", - 1, - sdk.MustNewDecFromStr("555878103595.890410958904000000"), - }, - { - "pass - period 2", - 2, - sdk.MustNewDecFromStr("278480843321.917808219178000000"), - }, - { - "pass - period 3", - 3, - sdk.MustNewDecFromStr("139782213184.931506849315000000"), - }, - { - "pass - period 4", - 4, - sdk.MustNewDecFromStr("70432898116.438356164383000000"), - }, - { - "pass - period 5", - 5, - sdk.MustNewDecFromStr("35758240582.191780821917000000"), - }, - { - "pass - period 6", - 6, - sdk.MustNewDecFromStr("18420911815.068493150684000000"), - }, - { - "pass - period 7", - 7, - sdk.MustNewDecFromStr("9752247431.506849315068000000"), - }, - } - for _, tc := range testCases { - t.Run(fmt.Sprintf("Case %s", tc.name), func(t *testing.T) { - epochMintProvisions := CalculateEpochMintProvision( - DefaultParams(), - tc.period, - ) + params := DefaultParams() - require.Equal(t, tc.expEpochProvision, epochMintProvisions) - }) + epochId := uint64(0) + totalInflation := sdk.ZeroDec() + + // Only the first 8 years have inflation with default params + for year := uint64(0); year < 10; year++ { + yearlyInflation := sdk.ZeroDec() + for month := uint64(0); month < 12; month++ { + for day := uint64(0); day < 30; day++ { + epochMintProvisions := CalculateEpochMintProvision(params, epochId) + yearlyInflation = yearlyInflation.Add(epochMintProvisions) + } + epochId++ + } + // Should be within 0.0098% + if year < uint64(len(ExpectedYearlyInflation)) { + require.NoError(t, withingRange(yearlyInflation, ExpectedYearlyInflation[year])) + } else { + require.Equal(t, yearlyInflation, sdk.ZeroDec()) + } + totalInflation = totalInflation.Add(yearlyInflation) } + require.NoError(t, withingRange(totalInflation, ExpectedTotalInflation)) } func TestCalculateEpochMintProvision_ZeroEpochs(t *testing.T) { @@ -74,3 +56,15 @@ func TestCalculateEpochMintProvision_ZeroEpochs(t *testing.T) { epochMintProvisions := CalculateEpochMintProvision(params, 1) require.Equal(t, epochMintProvisions, sdk.ZeroDec()) } + +// withingRange returns an error if the actual value is not within the expected value +/- tolerance +// tolerance is a percentage set to 0.01% by default +func withingRange(expected, actual sdk.Dec) error { + tolerance := sdk.NewDecWithPrec(1, 4) + is_within := expected.Sub(actual).Abs().Quo(expected).LTE(tolerance) + if !is_within { + tolerancePercent := tolerance.Mul(sdk.NewDec(100)) + return fmt.Errorf("expected %s to be within %s%% of %s", actual.String(), tolerancePercent.String(), expected.String()) + } + return nil +} diff --git a/x/inflation/types/params.go b/x/inflation/types/params.go index f043f1eb1..9d0be967a 100644 --- a/x/inflation/types/params.go +++ b/x/inflation/types/params.go @@ -9,48 +9,61 @@ import ( ) var ( - KeyInflationEnabled = []byte("InflationEnabled") - KeyExponentialCalculation = []byte("ExponentialCalculation") - KeyInflationDistribution = []byte("InflationDistribution") - KeyEpochsPerPeriod = []byte("EpochsPerPeriod") + KeyInflationEnabled = []byte("InflationEnabled") + KeyPolynomialFactors = []byte("PolynomialFactors") + KeyInflationDistribution = []byte("InflationDistribution") + KeyEpochsPerPeriod = []byte("EpochsPerPeriod") + KeyPeriodsPerYear = []byte("PeriodsPerYear") + KeyMaxPeriod = []byte("MaxPeriod") ) var ( - DefaultInflation = true - DefaultExponentialCalculation = ExponentialCalculation{ - A: sdk.NewDec(int64(405_000_000)), - R: sdk.NewDecWithPrec(50, 2), // 50% - C: sdk.NewDecWithPrec(395_507_8125, 4), + DefaultInflation = true + DefaultPolynomialFactors = []sdk.Dec{ + sdk.MustNewDecFromStr("-0.00014903"), + sdk.MustNewDecFromStr("0.07527647"), + sdk.MustNewDecFromStr("-19.11742154"), + sdk.MustNewDecFromStr("3170.0969905"), + sdk.MustNewDecFromStr("-339271.31060432"), + sdk.MustNewDecFromStr("18063678.8582418"), } DefaultInflationDistribution = InflationDistribution{ StakingRewards: sdk.NewDecWithPrec(27_8, 3), // 27.8% CommunityPool: sdk.NewDecWithPrec(62_20, 4), // 62.20% StrategicReserves: sdk.NewDecWithPrec(10, 2), // 10% } - DefaultEpochsPerPeriod = uint64(365) + DefaultEpochsPerPeriod = uint64(30) + DefaultPeriodsPerYear = uint64(12) + DefaultMaxPeriod = uint64(8 * 12) // 8 years with 360 days per year ) func NewParams( - exponentialCalculation ExponentialCalculation, + polynomialCalculation []sdk.Dec, inflationDistribution InflationDistribution, inflationEnabled bool, - epochsPerPeriod uint64, + epochsPerPeriod, + periodsPerYear, + maxPeriod uint64, ) Params { return Params{ - ExponentialCalculation: exponentialCalculation, - InflationDistribution: inflationDistribution, - InflationEnabled: inflationEnabled, - EpochsPerPeriod: epochsPerPeriod, + PolynomialFactors: polynomialCalculation, + InflationDistribution: inflationDistribution, + InflationEnabled: inflationEnabled, + EpochsPerPeriod: epochsPerPeriod, + PeriodsPerYear: periodsPerYear, + MaxPeriod: maxPeriod, } } // default minting module parameters func DefaultParams() Params { return Params{ - ExponentialCalculation: DefaultExponentialCalculation, - InflationDistribution: DefaultInflationDistribution, - InflationEnabled: DefaultInflation, - EpochsPerPeriod: DefaultEpochsPerPeriod, + PolynomialFactors: DefaultPolynomialFactors, + InflationDistribution: DefaultInflationDistribution, + InflationEnabled: DefaultInflation, + EpochsPerPeriod: DefaultEpochsPerPeriod, + PeriodsPerYear: DefaultPeriodsPerYear, + MaxPeriod: DefaultMaxPeriod, } } @@ -66,37 +79,23 @@ var _ paramstypes.ParamSet = (*Params)(nil) func (p *Params) ParamSetPairs() paramstypes.ParamSetPairs { return paramstypes.ParamSetPairs{ paramstypes.NewParamSetPair(KeyInflationEnabled, &p.InflationEnabled, validateBool), - paramstypes.NewParamSetPair(KeyExponentialCalculation, &p.ExponentialCalculation, validateExponentialCalculation), + paramstypes.NewParamSetPair(KeyPolynomialFactors, &p.PolynomialFactors, validatePolynomialFactors), paramstypes.NewParamSetPair(KeyInflationDistribution, &p.InflationDistribution, validateInflationDistribution), paramstypes.NewParamSetPair(KeyEpochsPerPeriod, &p.EpochsPerPeriod, validateUint64), + paramstypes.NewParamSetPair(KeyPeriodsPerYear, &p.PeriodsPerYear, validateUint64), + paramstypes.NewParamSetPair(KeyMaxPeriod, &p.MaxPeriod, validateUint64), } } -func validateExponentialCalculation(i interface{}) error { - v, ok := i.(ExponentialCalculation) +func validatePolynomialFactors(i interface{}) error { + v, ok := i.([]sdk.Dec) if !ok { return fmt.Errorf("invalid parameter type: %T", i) } - // validate initial value - if v.A.IsNegative() { - return fmt.Errorf("initial value cannot be negative") + if len(v) == 0 { + return errors.New("polynomial factors cannot be empty") } - - // validate reduction factor - if v.R.GT(sdk.OneDec()) { - return fmt.Errorf("reduction factor cannot be greater than 1") - } - - if v.R.IsNegative() { - return fmt.Errorf("reduction factor cannot be negative") - } - - // validate long term inflation - if v.C.IsNegative() { - return fmt.Errorf("long term inflation cannot be negative") - } - return nil } @@ -156,16 +155,35 @@ func validateEpochsPerPeriod(i interface{}) error { return nil } +func validatePeriodsPerYear(i interface{}) error { + val, ok := i.(uint64) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if val <= 0 { + return fmt.Errorf("periods per year must be positive: %d", val) + } + + return nil +} + func (p Params) Validate() error { if err := validateEpochsPerPeriod(p.EpochsPerPeriod); err != nil { return err } - if err := validateExponentialCalculation(p.ExponentialCalculation); err != nil { + if err := validatePeriodsPerYear(p.PeriodsPerYear); err != nil { + return err + } + if err := validatePolynomialFactors(p.PolynomialFactors); err != nil { return err } if err := validateInflationDistribution(p.InflationDistribution); err != nil { return err } + if err := validateUint64(p.MaxPeriod); err != nil { + return err + } return validateBool(p.InflationEnabled) } diff --git a/x/inflation/types/params_test.go b/x/inflation/types/params_test.go index 1dbadcef1..805855c36 100644 --- a/x/inflation/types/params_test.go +++ b/x/inflation/types/params_test.go @@ -29,83 +29,41 @@ func TestParamsValidate(t *testing.T) { { "valid", inflationtypes.NewParams( - inflationtypes.DefaultExponentialCalculation, + inflationtypes.DefaultPolynomialFactors, inflationtypes.DefaultInflationDistribution, true, inflationtypes.DefaultEpochsPerPeriod, + inflationtypes.DefaultPeriodsPerYear, + inflationtypes.DefaultMaxPeriod, ), false, }, { "valid param literal", inflationtypes.Params{ - ExponentialCalculation: inflationtypes.DefaultExponentialCalculation, - InflationDistribution: inflationtypes.DefaultInflationDistribution, - InflationEnabled: true, - EpochsPerPeriod: inflationtypes.DefaultEpochsPerPeriod, - }, - false, - }, - { - "invalid - exponential calculation - negative A", - inflationtypes.Params{ - ExponentialCalculation: inflationtypes.ExponentialCalculation{ - A: sdk.NewDec(int64(-1)), - R: sdk.NewDecWithPrec(5, 1), - C: sdk.NewDec(int64(9_375_000)), - }, + PolynomialFactors: inflationtypes.DefaultPolynomialFactors, InflationDistribution: inflationtypes.DefaultInflationDistribution, InflationEnabled: true, EpochsPerPeriod: inflationtypes.DefaultEpochsPerPeriod, + PeriodsPerYear: inflationtypes.DefaultPeriodsPerYear, }, - true, - }, - { - "invalid - exponential calculation - R greater than 1", - inflationtypes.Params{ - ExponentialCalculation: inflationtypes.ExponentialCalculation{ - A: sdk.NewDec(int64(300_000_000)), - R: sdk.NewDecWithPrec(5, 0), - C: sdk.NewDec(int64(9_375_000)), - }, - InflationDistribution: inflationtypes.DefaultInflationDistribution, - InflationEnabled: true, - EpochsPerPeriod: inflationtypes.DefaultEpochsPerPeriod, - }, - true, - }, - { - "invalid - exponential calculation - negative R", - inflationtypes.Params{ - ExponentialCalculation: inflationtypes.ExponentialCalculation{ - A: sdk.NewDec(int64(300_000_000)), - R: sdk.NewDecWithPrec(-5, 1), - C: sdk.NewDec(int64(9_375_000)), - }, - InflationDistribution: inflationtypes.DefaultInflationDistribution, - InflationEnabled: true, - EpochsPerPeriod: inflationtypes.DefaultEpochsPerPeriod, - }, - true, + false, }, { - "invalid - exponential calculation - negative C", + "invalid - polynomial calculation - no coefficient", inflationtypes.Params{ - ExponentialCalculation: inflationtypes.ExponentialCalculation{ - A: sdk.NewDec(int64(300_000_000)), - R: sdk.NewDecWithPrec(5, 1), - C: sdk.NewDec(int64(-9_375_000)), - }, + PolynomialFactors: []sdk.Dec{}, InflationDistribution: inflationtypes.DefaultInflationDistribution, InflationEnabled: true, EpochsPerPeriod: inflationtypes.DefaultEpochsPerPeriod, + PeriodsPerYear: inflationtypes.DefaultPeriodsPerYear, }, true, }, { "invalid - inflation distribution - negative staking rewards", inflationtypes.Params{ - ExponentialCalculation: inflationtypes.DefaultExponentialCalculation, + PolynomialFactors: inflationtypes.DefaultPolynomialFactors, InflationDistribution: inflationtypes.InflationDistribution{ StakingRewards: sdk.OneDec().Neg(), CommunityPool: sdk.NewDecWithPrec(133333, 6), @@ -113,13 +71,14 @@ func TestParamsValidate(t *testing.T) { }, InflationEnabled: true, EpochsPerPeriod: inflationtypes.DefaultEpochsPerPeriod, + PeriodsPerYear: inflationtypes.DefaultPeriodsPerYear, }, true, }, { "invalid - inflation distribution - negative usage incentives", inflationtypes.Params{ - ExponentialCalculation: inflationtypes.DefaultExponentialCalculation, + PolynomialFactors: inflationtypes.DefaultPolynomialFactors, InflationDistribution: inflationtypes.InflationDistribution{ StakingRewards: sdk.NewDecWithPrec(533334, 6), CommunityPool: sdk.NewDecWithPrec(133333, 6), @@ -127,13 +86,14 @@ func TestParamsValidate(t *testing.T) { }, InflationEnabled: true, EpochsPerPeriod: inflationtypes.DefaultEpochsPerPeriod, + PeriodsPerYear: inflationtypes.DefaultPeriodsPerYear, }, true, }, { "invalid - inflation distribution - negative community pool rewards", inflationtypes.Params{ - ExponentialCalculation: inflationtypes.DefaultExponentialCalculation, + PolynomialFactors: inflationtypes.DefaultPolynomialFactors, InflationDistribution: inflationtypes.InflationDistribution{ StakingRewards: sdk.NewDecWithPrec(533334, 6), CommunityPool: sdk.OneDec().Neg(), @@ -141,13 +101,14 @@ func TestParamsValidate(t *testing.T) { }, InflationEnabled: true, EpochsPerPeriod: inflationtypes.DefaultEpochsPerPeriod, + PeriodsPerYear: inflationtypes.DefaultPeriodsPerYear, }, true, }, { "invalid - inflation distribution - total distribution ratio unequal 1", inflationtypes.Params{ - ExponentialCalculation: inflationtypes.DefaultExponentialCalculation, + PolynomialFactors: inflationtypes.DefaultPolynomialFactors, InflationDistribution: inflationtypes.InflationDistribution{ StakingRewards: sdk.NewDecWithPrec(533333, 6), CommunityPool: sdk.NewDecWithPrec(133333, 6), @@ -155,6 +116,7 @@ func TestParamsValidate(t *testing.T) { }, InflationEnabled: true, EpochsPerPeriod: inflationtypes.DefaultEpochsPerPeriod, + PeriodsPerYear: inflationtypes.DefaultPeriodsPerYear, }, true, },