Skip to content

Commit

Permalink
fix calc (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
EugenWay authored Jan 10, 2024
1 parent b1abc2f commit 49e694a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/calculators/staking-roi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 49e694a

Please sign in to comment.