Skip to content

Commit

Permalink
Link inflation calculations source (polkadot-js#8182)
Browse files Browse the repository at this point in the history
* Link inflation calculations

* Update packages/react-hooks/src/useInflation.ts
  • Loading branch information
jacogr authored Sep 29, 2022
1 parent 0701ece commit f2e6578
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/apps-config/src/api/params/inflation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ 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
};

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 },
Expand Down
4 changes: 4 additions & 0 deletions packages/react-hooks/src/useInflation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit f2e6578

Please sign in to comment.