From f2e65785df94e69ce49d5170e397d80e79741804 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 29 Sep 2022 14:17:14 +0300 Subject: [PATCH] Link inflation calculations source (#8182) * Link inflation calculations * Update packages/react-hooks/src/useInflation.ts --- packages/apps-config/src/api/params/inflation.ts | 8 ++++++++ packages/react-hooks/src/useInflation.ts | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/packages/apps-config/src/api/params/inflation.ts b/packages/apps-config/src/api/params/inflation.ts index a329b39069..835a25ba1c 100644 --- a/packages/apps-config/src/api/params/inflation.ts +++ b/packages/apps-config/src/api/params/inflation.ts @@ -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 = { [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 }, diff --git a/packages/react-hooks/src/useInflation.ts b/packages/react-hooks/src/useInflation.ts index d8c1fd7182..8bc9ec2869 100644 --- a/packages/react-hooks/src/useInflation.ts +++ b/packages/react-hooks/src/useInflation.ts @@ -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)))