Skip to content

Commit

Permalink
feat(inflation)!: make inflation follow a polynomial distribution (#1670
Browse files Browse the repository at this point in the history
)

* feat: make inflation follow a polynomial distribution

* chore: changelog

* fix: fix inflation test

* fix: fix epoch/period confusion
  • Loading branch information
matthiasmatt authored and k-yang committed Nov 21, 2023
1 parent c55185f commit e2011cd
Show file tree
Hide file tree
Showing 32 changed files with 6,074 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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
* [#1658](https://github.com/NibiruChain/nibiru/pull/1658) - feat(oracle): add `EditOracleParams` message
* [#1670](https://github.com/NibiruChain/nibiru/pull/1670) - feat(inflation): Make inflation polynomial

### State Machine Breaking

Expand Down
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import (
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"

"github.com/NibiruChain/nibiru/wasmbinding"
wasmbinding "github.com/NibiruChain/nibiru/wasmbinding"
)

const (
Expand Down Expand Up @@ -118,10 +118,10 @@ func GetWasmOpts(nibiru NibiruApp, appOpts servertypes.AppOptions) []wasmkeeper.
// Add the bindings to the app's set of []wasmkeeper.Option.
wasmOpts = append(wasmOpts, wasmbinding.NibiruWasmOptions(
nibiru.GRPCQueryRouter(),
nibiru.AppCodec(),
nibiru.appCodec,
nibiru.SudoKeeper,
)...)
// Add the bindings to the app's set of []wasm.Option.

return wasmOpts
}

Expand Down
2 changes: 2 additions & 0 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/NibiruChain/nibiru/app/codec"
)

// EncodingConfig specifies the concrete encoding types to use for a given app.
// This is provided for compatibility between protobuf and amino implementations.
type EncodingConfig = codec.EncodingConfig

// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
Expand Down
34 changes: 26 additions & 8 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,16 @@ import (
epochskeeper "github.com/NibiruChain/nibiru/x/epochs/keeper"
epochstypes "github.com/NibiruChain/nibiru/x/epochs/types"
"github.com/NibiruChain/nibiru/x/genmsg"
"github.com/NibiruChain/nibiru/x/inflation"
inflationkeeper "github.com/NibiruChain/nibiru/x/inflation/keeper"
inflationtypes "github.com/NibiruChain/nibiru/x/inflation/types"
oracle "github.com/NibiruChain/nibiru/x/oracle"
oraclekeeper "github.com/NibiruChain/nibiru/x/oracle/keeper"
oracletypes "github.com/NibiruChain/nibiru/x/oracle/types"
"github.com/NibiruChain/nibiru/x/sudo"
"github.com/NibiruChain/nibiru/x/sudo/keeper"
sudotypes "github.com/NibiruChain/nibiru/x/sudo/types"

tokenfactory "github.com/NibiruChain/nibiru/x/tokenfactory"
tokenfactorykeeper "github.com/NibiruChain/nibiru/x/tokenfactory/keeper"
tokenfactorytypes "github.com/NibiruChain/nibiru/x/tokenfactory/types"
Expand Down Expand Up @@ -161,6 +165,7 @@ type AppKeepers struct {
// ---------------
EpochsKeeper epochskeeper.Keeper
OracleKeeper oraclekeeper.Keeper
InflationKeeper inflationkeeper.Keeper
SudoKeeper keeper.Keeper
DevGasKeeper devgaskeeper.Keeper
TokenFactoryKeeper tokenfactorykeeper.Keeper
Expand Down Expand Up @@ -199,6 +204,7 @@ func initStoreKeys() (
// nibiru x/ keys
oracletypes.StoreKey,
epochstypes.StoreKey,
inflationtypes.StoreKey,
sudotypes.StoreKey,
wasmtypes.StoreKey,
devgastypes.StoreKey,
Expand Down Expand Up @@ -345,8 +351,14 @@ func (app *NibiruApp) InitKeepers(
appCodec, keys[sudotypes.StoreKey],
)

app.InflationKeeper = inflationkeeper.NewKeeper(
appCodec, keys[inflationtypes.StoreKey], app.GetSubspace(inflationtypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.stakingKeeper, app.SudoKeeper, authtypes.FeeCollectorName,
)

app.EpochsKeeper.SetHooks(
epochstypes.NewMultiEpochHooks(
app.InflationKeeper.Hooks(),
app.OracleKeeper.Hooks(),
),
)
Expand Down Expand Up @@ -556,6 +568,7 @@ func (app *NibiruApp) initAppModules(
// Nibiru modules
oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper, app.SudoKeeper),
epochs.NewAppModule(appCodec, app.EpochsKeeper),
inflation.NewAppModule(app.InflationKeeper, app.AccountKeeper, *app.stakingKeeper),
sudo.NewAppModule(appCodec, app.SudoKeeper),
genmsg.NewAppModule(app.MsgServiceRouter()),

Expand Down Expand Up @@ -622,6 +635,7 @@ func orderedModuleNames() []string {
// Native x/ Modules
epochstypes.ModuleName,
oracletypes.ModuleName,
inflationtypes.ModuleName,
sudotypes.ModuleName,

// --------------------------------------------------------------------
Expand Down Expand Up @@ -735,6 +749,7 @@ func ModuleBasicManager() module.BasicManager {
// native x/
oracle.AppModuleBasic{},
epochs.AppModuleBasic{},
inflation.AppModuleBasic{},
sudo.AppModuleBasic{},
wasm.AppModuleBasic{},
devgas.AppModuleBasic{},
Expand All @@ -746,14 +761,16 @@ func ModuleBasicManager() module.BasicManager {

func ModuleAccPerms() map[string][]string {
return map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
oracletypes.ModuleName: {},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcfeetypes.ModuleName: {},
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
inflationtypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
oracletypes.ModuleName: {},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcfeetypes.ModuleName: {},

epochstypes.ModuleName: {},
sudotypes.ModuleName: {},
common.TreasuryPoolModuleAccount: {},
Expand All @@ -778,6 +795,7 @@ func initParamsKeeper(
paramsKeeper.Subspace(crisistypes.ModuleName)
// Nibiru core params keepers | x/
paramsKeeper.Subspace(epochstypes.ModuleName)
paramsKeeper.Subspace(inflationtypes.ModuleName)
// ibc params keepers
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibcexported.ModuleName)
Expand Down
45 changes: 45 additions & 0 deletions proto/nibiru/inflation/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
syntax = "proto3";

package nibiru.inflation.v1;

import "gogoproto/gogo.proto";
import "nibiru/inflation/v1/inflation.proto";

option go_package = "github.com/NibiruChain/nibiru/x/inflation/types";

// GenesisState defines the inflation module's genesis state.
message GenesisState {
// params defines all the parameters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];
// period is the amount of past periods, based on the epochs per period param
uint64 period = 2;
// skipped_epochs is the number of epochs that have passed while inflation is
// disabled
uint64 skipped_epochs = 3;
}

// Params holds parameters for the inflation module.
message Params {
// inflation_enabled is the parameter that enables inflation and halts
// increasing the skipped_epochs
bool inflation_enabled = 1;
// polynomial_factors takes in the variables to calculate polynomial
// inflation
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;
}
30 changes: 30 additions & 0 deletions proto/nibiru/inflation/v1/inflation.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
syntax = "proto3";
package nibiru.inflation.v1;

import "gogoproto/gogo.proto";

option go_package = "github.com/NibiruChain/nibiru/x/inflation/types";

// InflationDistribution defines the distribution in which inflation is
// allocated through minting on each epoch (staking, community, strategic). It
// excludes the team vesting distribution.
message InflationDistribution {
// staking_rewards defines the proportion of the minted_denom that is
// to be allocated as staking rewards
string staking_rewards = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// community_pool defines the proportion of the minted_denom that is to
// be allocated to the community pool
string community_pool = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// strategic_reserves defines the proportion of the minted_denom that
// is to be allocated to the strategic reserves module address
string strategic_reserves = 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.

Loading

0 comments on commit e2011cd

Please sign in to comment.