From 49e694ab0f7a730f8dac271b9d7f505bdb1368a7 Mon Sep 17 00:00:00 2001 From: Eugene Way Date: Wed, 10 Jan 2024 13:56:22 +0100 Subject: [PATCH] fix calc (#9) --- src/calculators/staking-roi.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/calculators/staking-roi.js b/src/calculators/staking-roi.js index db658bc..b9222b7 100644 --- a/src/calculators/staking-roi.js +++ b/src/calculators/staking-roi.js @@ -6,11 +6,13 @@ import { DECIMALS } from '../consts.js'; // era_payout = total_issuance * inflation_per_era export async function stakingRoi() { - const lastEra = (await api.query.staking.currentEra()).toHuman() - 1; + const lastEra = (await api.query.staking.currentEra()).toHuman(); - const inflationPerEra = (await api.query.staking.erasValidatorReward(lastEra)).toJSON(); - const totalStaked = await api.query.staking.erasTotalStake(lastEra); + const inflationPerEra = (await api.query.staking.erasValidatorReward(lastEra - 2)).toJSON(); + const totalStaked = await api.query.staking.erasTotalStake(lastEra - 2); const totalIssuance = await totalSupply(); - return (totalIssuance * (inflationPerEra / 10 ** DECIMALS)) / (totalStaked / 10 ** DECIMALS) * 730; + const roi = (totalIssuance * (inflationPerEra / 10 ** DECIMALS)) / (totalStaked / 10 ** DECIMALS) * 730; + + return (roi / 10 ** 8) }