From 8b0604651f82914b57610387870ae13d5a592764 Mon Sep 17 00:00:00 2001 From: 0xsatoshi Date: Sun, 16 Jun 2024 23:18:18 +0800 Subject: [PATCH] fix --- app/app.go | 5 ++-- chaincfg/mint.go | 77 +++++++++++++++++++++++++++++++++++------------- go.mod | 5 ++-- go.sum | 8 ++--- 4 files changed, 66 insertions(+), 29 deletions(-) diff --git a/app/app.go b/app/app.go index 5af95ced..83b1836c 100644 --- a/app/app.go +++ b/app/app.go @@ -367,11 +367,14 @@ func NewApp( bankSubspace, app.loadBlockedMaccAddrs(), ) + app.vestingKeeper = vestingkeeper.NewVestingKeeper(app.accountKeeper, app.bankKeeper, keys[vestingtypes.StoreKey]) + app.stakingKeeper = stakingkeeper.NewKeeper( appCodec, keys[stakingtypes.StoreKey], app.accountKeeper, app.bankKeeper, + app.vestingKeeper, stakingSubspace, ) app.authzKeeper = authzkeeper.NewKeeper( @@ -574,8 +577,6 @@ func NewApp( keys[counciltypes.StoreKey], appCodec, app.stakingKeeper, ) - app.vestingKeeper = vestingkeeper.NewVestingKeeper(app.accountKeeper, app.bankKeeper, keys[vestingtypes.StoreKey]) - // create the module manager (Note: Any module instantiated in the module manager that is later modified // must be passed by reference here.) app.mm = module.NewManager( diff --git a/chaincfg/mint.go b/chaincfg/mint.go index 9293e10e..754dd86b 100644 --- a/chaincfg/mint.go +++ b/chaincfg/mint.go @@ -1,36 +1,73 @@ package chaincfg import ( + "github.com/shopspring/decimal" + sdk "github.com/cosmos/cosmos-sdk/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" ) +var ( + Xmax, _ = sdk.NewDecFromStr("1.0") // upper limit on staked supply (as % of circ supply) + Ymin, _ = sdk.NewDecFromStr("0.05") // target APY at upper limit + + Xmin, _ = sdk.NewDecFromStr("0.2") // lower limit on staked supply (as % of circ supply) + Ymax, _ = sdk.NewDecFromStr("0.15") // target APY at lower limit + + decayRate, _ = sdk.NewDecFromStr("10") +) + +func decExp(x sdk.Dec) sdk.Dec { + xDec := decimal.NewFromBigInt(x.BigInt(), -18) + expDec, _ := xDec.ExpTaylor(18) + expInt := expDec.Shift(18).BigInt() + return sdk.NewDecFromBigIntWithPrec(expInt, 18) +} + func NextInflationRate(ctx sdk.Context, minter minttypes.Minter, params minttypes.Params, bondedRatio sdk.Dec, circulatingRatio sdk.Dec) sdk.Dec { - // The target annual inflation rate is recalculated for each previsions cycle. The - // inflation is also subject to a rate change (positive or negative) depending on - // the distance from the desired ratio (67%). The maximum rate change possible is - // defined to be 13% per year, however the annual inflation is capped as between - // 7% and 20%. + X := bondedRatio.Quo(circulatingRatio) - // (1 - bondedRatio/GoalBonded) * InflationRateChange - inflationRateChangePerYear := sdk.OneDec(). - Sub(bondedRatio.Quo(params.GoalBonded)). - Mul(params.InflationRateChange) - inflationRateChange := inflationRateChangePerYear.Quo(sdk.NewDec(int64(params.BlocksPerYear))) - - // adjust the new annual inflation for this next cycle - inflation := minter.Inflation.Add(inflationRateChange) // note inflationRateChange may be negative - if inflation.GT(params.InflationMax) { - inflation = params.InflationMax - } - if inflation.LT(params.InflationMin) { - inflation = params.InflationMin + var apy sdk.Dec + if X.LT(Xmin) { + apy = Ymax + } else { + exp := decayRate.Neg().Mul(Xmax.Sub(Xmin)) + c := decExp(exp) + d := Ymin.Sub(Ymax.Mul(c)).Quo(sdk.OneDec().Sub(c)) + expBonded := decayRate.Neg().Mul(X.Sub(Xmin)) + cBonded := decExp(expBonded) + e := Ymax.Sub(d).Mul(cBonded) + apy = d.Add(e) } - ctx.Logger().Debug( - "calculated new annual inflation", + inflation := apy.Mul(bondedRatio) + + // // The target annual inflation rate is recalculated for each previsions cycle. The + // // inflation is also subject to a rate change (positive or negative) depending on + // // the distance from the desired ratio (67%). The maximum rate change possible is + // // defined to be 13% per year, however the annual inflation is capped as between + // // 7% and 20%. + + // // (1 - bondedRatio/GoalBonded) * InflationRateChange + // inflationRateChangePerYear := sdk.OneDec(). + // Sub(bondedRatio.Quo(params.GoalBonded)). + // Mul(params.InflationRateChange) + // inflationRateChange := inflationRateChangePerYear.Quo(sdk.NewDec(int64(params.BlocksPerYear))) + + // // adjust the new annual inflation for this next cycle + // inflation := minter.Inflation.Add(inflationRateChange) // note inflationRateChange may be negative + // if inflation.GT(params.InflationMax) { + // inflation = params.InflationMax + // } + // if inflation.LT(params.InflationMin) { + // inflation = params.InflationMin + // } + + ctx.Logger().Info( + "nextInflationRate", "bondedRatio", bondedRatio, "circulatingRatio", circulatingRatio, + "apy", apy, "inflation", inflation, "params", params, "minter", minter, diff --git a/go.mod b/go.mod index 9d6dca0b..d6c38257 100644 --- a/go.mod +++ b/go.mod @@ -212,14 +212,13 @@ replace ( // Use rocksdb 7.9.2 github.com/cometbft/cometbft-db => github.com/kava-labs/cometbft-db v0.7.0-rocksdb-v7.9.2-kava.1 // Use cosmos-sdk fork with backported fix for unsafe-reset-all, staking transfer events, and custom tally handler support - // github.com/cosmos/cosmos-sdk => github.com/0glabs/cosmos-sdk v0.46.11-kava.3 - github.com/cosmos/cosmos-sdk => /home/dongz/projects/cosmos-sdk + github.com/cosmos/cosmos-sdk => github.com/0glabs/cosmos-sdk v0.46.11-0glabs.5 // See https://github.com/cosmos/cosmos-sdk/pull/13093 github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2 // Use go-ethereum fork with precompiles github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26-evmos-rc2 // Use ethermint fork that respects min-gas-price with NoBaseFee true and london enabled, and includes eip712 support - github.com/evmos/ethermint => /home/dongz/projects/ethermint + github.com/evmos/ethermint => github.com/0glabs/ethermint v0.21.0-0g.v2.0.2 // See https://github.com/cosmos/cosmos-sdk/pull/10401, https://github.com/cosmos/cosmos-sdk/commit/0592ba6158cd0bf49d894be1cef4faeec59e8320 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0 // Use the cosmos modified protobufs diff --git a/go.sum b/go.sum index 96dfdfd0..4329d648 100644 --- a/go.sum +++ b/go.sum @@ -202,10 +202,10 @@ filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmG filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= git.sr.ht/~sircmpwn/getopt v0.0.0-20191230200459-23622cc906b3/go.mod h1:wMEGFFFNuPos7vHmWXfszqImLppbc0wEhh6JBfJIUgw= git.sr.ht/~sircmpwn/go-bare v0.0.0-20210406120253-ab86bc2846d9/go.mod h1:BVJwbDfVjCjoFiKrhkei6NdGcZYpkDkdyCdg1ukytRA= -github.com/0glabs/cosmos-sdk v0.46.11-0glabs.4 h1:NYKYgJIilexHR8VE1EAl7Tv2wMQGPwdzKiLV2DnIAwg= -github.com/0glabs/cosmos-sdk v0.46.11-0glabs.4/go.mod h1:jwgWoeAWxqMF5pZUZ4N+G4rD3q6oOLulq3/dGCFLEX4= -github.com/0glabs/ethermint v0.21.0-0g.v2.0.1 h1:loFnZAEZ8tboo3JO3+AE+1gJcUm6hkYuwcn+ZHBhjxE= -github.com/0glabs/ethermint v0.21.0-0g.v2.0.1/go.mod h1:peUmQT71k9BOBgoWoIRWRrM/O01mffVjIH0RLnoaFuI= +github.com/0glabs/cosmos-sdk v0.46.11-0glabs.5 h1:/7zqU8Az6n3UpKnypKQ92Yw8AgrE1v1AfatrL8elajs= +github.com/0glabs/cosmos-sdk v0.46.11-0glabs.5/go.mod h1:jwgWoeAWxqMF5pZUZ4N+G4rD3q6oOLulq3/dGCFLEX4= +github.com/0glabs/ethermint v0.21.0-0g.v2.0.2 h1:mFVOMra9lmeNk+CgL0UsBxqiXHx5JWVeiURJFgQmHzY= +github.com/0glabs/ethermint v0.21.0-0g.v2.0.2/go.mod h1:KPLRino6lVDPV/cZCbQf7dZdR1nsVgptr0Htf6ZxZe8= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4= github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=