feature: show pools apr

This commit is contained in:
Claudio Ramos
2021-08-15 02:21:39 -03:00
parent c1129b9953
commit 9e96a3664b
17 changed files with 996 additions and 145 deletions

View File

@@ -0,0 +1,22 @@
import BigNumber from "bignumber.js";
import { BLOCKS_PER_YEAR } from "../constants";
export const getApr = (
stakingTokenPrice: number,
rewardTokenPrice: number,
totalStaked: number,
tokenPerBlock: number
) => {
const totalRewardPricePerYear = new BigNumber(rewardTokenPrice)
.times(tokenPerBlock)
.times(BLOCKS_PER_YEAR);
const totalStakingTokenInPool = new BigNumber(stakingTokenPrice).times(
totalStaked
);
const apr = totalRewardPricePerYear.div(totalStakingTokenInPool).times(100);
return apr.isNaN() || !apr.isFinite() ? null : apr.toNumber();
};