diff --git a/CHANGELOG.md b/CHANGELOG.md index a883a72f31..5a6321ab8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,21 +46,22 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] -### Bug Fixes - -- [2148](https://github.com/umee-network/umee/pull/2148) Fix MsgBeginUnbonding counting existing unbondings against max unbond twice. -- [2148](https://github.com/umee-network/umee/pull/2148) Fix MsgLeverageLiquidate CLI not actually allowing wildcard denoms. - ### Features - [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. +- [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. ### Improvements - [2134](https://github.com/umee-network/umee/pull/2134) Bump CometBFT to 34.29. +### Bug Fixes + +- [2148](https://github.com/umee-network/umee/pull/2148) Fix MsgBeginUnbonding counting existing unbondings against max unbond twice. +- [2148](https://github.com/umee-network/umee/pull/2148) Fix MsgLeverageLiquidate CLI not actually allowing wildcard denoms. + ### API Breaking - [2140](https://github.com/umee-network/umee/pull/2140) diff --git a/app/app.go b/app/app.go index 4a99441541..a087dde662 100644 --- a/app/app.go +++ b/app/app.go @@ -120,6 +120,7 @@ import ( wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" customante "github.com/umee-network/umee/v5/ante" + "github.com/umee-network/umee/v5/app/inflation" appparams "github.com/umee-network/umee/v5/app/params" "github.com/umee-network/umee/v5/swagger" "github.com/umee-network/umee/v5/util/genmap" @@ -672,6 +673,11 @@ func New( // we prefer to be more strict in what arguments the modules expect. skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) + inflationClaculator := inflation.Calculator{ + UgovKeeperB: app.UGovKeeperB, + MintKeeper: &app.MintKeeper, + } + // NOTE: Any module instantiated in the module manager that is later modified // must be passed by reference here. appModules := []module.AppModule{ @@ -694,7 +700,7 @@ func New( app.interfaceRegistry, ), gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), - mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil), + mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, inflationClaculator.InflationRate), // need to dereference StakingKeeper because x/distribution uses interface casting :( // TODO: in the next SDK version we can remove the dereference slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), diff --git a/app/inflation/expected_keepers.go b/app/inflation/expected_keepers.go new file mode 100644 index 0000000000..4f9d97c84d --- /dev/null +++ b/app/inflation/expected_keepers.go @@ -0,0 +1,10 @@ +package inflation + +import ( + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type MintKeeper interface { + StakingTokenSupply(ctx sdk.Context) math.Int +} diff --git a/app/inflation/inflatin.go b/app/inflation/inflatin.go new file mode 100644 index 0000000000..efd8dc50c1 --- /dev/null +++ b/app/inflation/inflatin.go @@ -0,0 +1,51 @@ +package inflation + +import ( + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + + 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, p minttypes.Params, bondedRatio sdk.Dec) sdk.Dec { + + maxSupply, _ := sdk.NewIntFromString("21_000_000_000_000_000000") + + totalSupply := c.MintKeeper.StakingTokenSupply(ctx) + if totalSupply.GTE(maxSupply) { + // supply is already reached the maximum amount, so inflation should be zero + return sdk.ZeroDec() + } + + // TODO: here we need to use a new inflation function and check if we need to go to the + // next inflation cycle + minter.Inflation = c.calculateInflation(ctx, minter, p, bondedRatio) + return readjustSupply(totalSupply, maxSupply, minter, p) +} + +func (c Calculator) calculateInflation( + ctx sdk.Context, minter minttypes.Minter, p minttypes.Params, bondedRatio sdk.Dec) sdk.Dec { + return minttypes.DefaultInflationCalculationFn(ctx, minter, p, bondedRatio) +} + +// TODO: add unit tests to this function +func readjustSupply(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) { + overdraft := newTotalSupply.Sub(maxSupply) + maxNewSupply := newSupply.Sub(overdraft) + factor := sdk.NewDecFromInt(maxNewSupply).QuoInt(newSupply) + minter.Inflation = minter.Inflation.Mul(factor) + } + + return minter.Inflation +}