feature: show pools apr
This commit is contained in:
22
app/javascript/src/utils/apr.ts
Normal file
22
app/javascript/src/utils/apr.ts
Normal 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();
|
||||
};
|
||||
Reference in New Issue
Block a user