Link inflation calculations source (#8182)
* Link inflation calculations * Update packages/react-hooks/src/useInflation.ts
This commit is contained in:
parent
0701ece72f
commit
f2e65785df
@ -17,7 +17,11 @@ interface InflationParams {
|
||||
const DEFAULT_PARAMS: InflationParams = {
|
||||
auctionAdjust: 0,
|
||||
auctionMax: 0,
|
||||
// 5% for falloff, as per the defaults, see
|
||||
// https://github.com/paritytech/polkadot/blob/816cb64ea16102c6c79f6be2a917d832d98df757/runtime/kusama/src/lib.rs#L534
|
||||
falloff: 0.05,
|
||||
// 10% max, 0.25% min, see
|
||||
// https://github.com/paritytech/polkadot/blob/816cb64ea16102c6c79f6be2a917d832d98df757/runtime/kusama/src/lib.rs#L523
|
||||
maxInflation: 0.1,
|
||||
minInflation: 0.025,
|
||||
stakeTarget: 0.5
|
||||
@ -25,6 +29,10 @@ const DEFAULT_PARAMS: InflationParams = {
|
||||
|
||||
const KNOWN_PARAMS: Record<string, InflationParams> = {
|
||||
[DOCK_POS_TESTNET_GENESIS]: { ...DEFAULT_PARAMS, stakeTarget: 0.75 },
|
||||
// 30% for up to 60 slots, see
|
||||
// https://github.com/paritytech/polkadot/blob/816cb64ea16102c6c79f6be2a917d832d98df757/runtime/kusama/src/lib.rs#L526-L527
|
||||
// 75% ideal target, see
|
||||
// https://github.com/paritytech/polkadot/blob/816cb64ea16102c6c79f6be2a917d832d98df757/runtime/kusama/src/lib.rs#L529-L531
|
||||
[KUSAMA_GENESIS]: { ...DEFAULT_PARAMS, auctionAdjust: (0.3 / 60), auctionMax: 60, stakeTarget: 0.75 },
|
||||
[NEATCOIN_GENESIS]: { ...DEFAULT_PARAMS, stakeTarget: 0.75 },
|
||||
[NFTMART_GENESIS]: { ...DEFAULT_PARAMS, falloff: 0.04, stakeTarget: 0.60 },
|
||||
|
||||
@ -21,8 +21,12 @@ function calcInflation (api: ApiPromise, totalStaked: BN, totalIssuance: BN, num
|
||||
const stakedFraction = totalStaked.isZero() || totalIssuance.isZero()
|
||||
? 0
|
||||
: totalStaked.mul(BN_MILLION).div(totalIssuance).toNumber() / BN_MILLION.toNumber();
|
||||
// Ideal is less based on the actual auctions, see
|
||||
// https://github.com/paritytech/polkadot/blob/816cb64ea16102c6c79f6be2a917d832d98df757/runtime/kusama/src/lib.rs#L531
|
||||
const idealStake = stakeTarget - (Math.min(auctionMax, numAuctions.toNumber()) * auctionAdjust);
|
||||
const idealInterest = maxInflation / idealStake;
|
||||
// inflation calculations, see
|
||||
// https://github.com/paritytech/substrate/blob/0ba251c9388452c879bfcca425ada66f1f9bc802/frame/staking/reward-fn/src/lib.rs#L28-L54
|
||||
const inflation = 100 * (minInflation + (
|
||||
stakedFraction <= idealStake
|
||||
? (stakedFraction * (idealInterest - (minInflation / idealStake)))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user