mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-20 15:05:21 +00:00
fix
This commit is contained in:
parent
4917eb5976
commit
8d761147a2
@ -398,12 +398,16 @@ func NewApp(
|
|||||||
app.loadBlockedMaccAddrs(),
|
app.loadBlockedMaccAddrs(),
|
||||||
govAuthAddrStr,
|
govAuthAddrStr,
|
||||||
)
|
)
|
||||||
|
app.vestingKeeper = vestingkeeper.NewVestingKeeper(app.accountKeeper, app.bankKeeper, keys[vestingtypes.StoreKey])
|
||||||
|
|
||||||
app.stakingKeeper = stakingkeeper.NewKeeper(
|
app.stakingKeeper = stakingkeeper.NewKeeper(
|
||||||
appCodec,
|
appCodec,
|
||||||
keys[stakingtypes.StoreKey],
|
keys[stakingtypes.StoreKey],
|
||||||
app.accountKeeper,
|
app.accountKeeper,
|
||||||
app.bankKeeper,
|
app.bankKeeper,
|
||||||
govAuthAddrStr,
|
govAuthAddrStr,
|
||||||
|
app.vestingKeeper,
|
||||||
|
stakingSubspace,
|
||||||
)
|
)
|
||||||
app.authzKeeper = authzkeeper.NewKeeper(
|
app.authzKeeper = authzkeeper.NewKeeper(
|
||||||
keys[authzkeeper.StoreKey],
|
keys[authzkeeper.StoreKey],
|
||||||
@ -737,8 +741,6 @@ func NewApp(
|
|||||||
keys[counciltypes.StoreKey], appCodec, app.stakingKeeper,
|
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
|
// create the module manager (Note: Any module instantiated in the module manager that is later modified
|
||||||
// must be passed by reference here.)
|
// must be passed by reference here.)
|
||||||
app.mm = module.NewManager(
|
app.mm = module.NewManager(
|
||||||
|
@ -1,36 +1,73 @@
|
|||||||
package chaincfg
|
package chaincfg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/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 {
|
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
|
X := bondedRatio.Quo(circulatingRatio)
|
||||||
// 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
|
var apy sdk.Dec
|
||||||
inflationRateChangePerYear := sdk.OneDec().
|
if X.LT(Xmin) {
|
||||||
Sub(bondedRatio.Quo(params.GoalBonded)).
|
apy = Ymax
|
||||||
Mul(params.InflationRateChange)
|
} else {
|
||||||
inflationRateChange := inflationRateChangePerYear.Quo(sdk.NewDec(int64(params.BlocksPerYear)))
|
exp := decayRate.Neg().Mul(Xmax.Sub(Xmin))
|
||||||
|
c := decExp(exp)
|
||||||
// adjust the new annual inflation for this next cycle
|
d := Ymin.Sub(Ymax.Mul(c)).Quo(sdk.OneDec().Sub(c))
|
||||||
inflation := minter.Inflation.Add(inflationRateChange) // note inflationRateChange may be negative
|
expBonded := decayRate.Neg().Mul(X.Sub(Xmin))
|
||||||
if inflation.GT(params.InflationMax) {
|
cBonded := decExp(expBonded)
|
||||||
inflation = params.InflationMax
|
e := Ymax.Sub(d).Mul(cBonded)
|
||||||
}
|
apy = d.Add(e)
|
||||||
if inflation.LT(params.InflationMin) {
|
|
||||||
inflation = params.InflationMin
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Logger().Debug(
|
inflation := apy.Mul(bondedRatio)
|
||||||
"calculated new annual inflation",
|
|
||||||
|
// // 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,
|
"bondedRatio", bondedRatio,
|
||||||
"circulatingRatio", circulatingRatio,
|
"circulatingRatio", circulatingRatio,
|
||||||
|
"apy", apy,
|
||||||
"inflation", inflation,
|
"inflation", inflation,
|
||||||
"params", params,
|
"params", params,
|
||||||
"minter", minter,
|
"minter", minter,
|
||||||
|
8
go.sum
8
go.sum
@ -219,10 +219,10 @@ filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
|
|||||||
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
|
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
|
||||||
git.sr.ht/~sircmpwn/getopt v0.0.0-20191230200459-23622cc906b3/go.mod h1:wMEGFFFNuPos7vHmWXfszqImLppbc0wEhh6JBfJIUgw=
|
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=
|
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.5 h1:/7zqU8Az6n3UpKnypKQ92Yw8AgrE1v1AfatrL8elajs=
|
||||||
github.com/0glabs/cosmos-sdk v0.46.11-0glabs.4/go.mod h1:jwgWoeAWxqMF5pZUZ4N+G4rD3q6oOLulq3/dGCFLEX4=
|
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.1 h1:loFnZAEZ8tboo3JO3+AE+1gJcUm6hkYuwcn+ZHBhjxE=
|
github.com/0glabs/ethermint v0.21.0-0g.v2.0.2 h1:mFVOMra9lmeNk+CgL0UsBxqiXHx5JWVeiURJFgQmHzY=
|
||||||
github.com/0glabs/ethermint v0.21.0-0g.v2.0.1/go.mod h1:peUmQT71k9BOBgoWoIRWRrM/O01mffVjIH0RLnoaFuI=
|
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 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
|
||||||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
|
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=
|
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=
|
||||||
|
Loading…
Reference in New Issue
Block a user