Additional calcInflation check (#4900)

This commit is contained in:
Jaco Greeff 2021-03-22 10:44:49 +01:00 committed by GitHub
parent 32dadfa02d
commit 2e68dc3cc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,9 @@ const EMPTY: Inflation = { inflation: 0, stakedReturn: 0 };
export function calcInflation (api: ApiPromise, totalStaked: BN, totalIssuance: BN): Inflation {
const { falloff, idealStake, maxInflation, minInflation } = getInflationParams(api);
const stakedFraction = totalStaked.mul(BN_MILLION).div(totalIssuance).toNumber() / BN_MILLION.toNumber();
const stakedFraction = totalStaked.isZero() || totalIssuance.isZero()
? 0
: totalStaked.mul(BN_MILLION).div(totalIssuance).toNumber() / BN_MILLION.toNumber();
const idealInterest = maxInflation / idealStake;
const inflation = 100 * (minInflation + (
stakedFraction <= idealStake