diff --git a/src/lib/getAPYCalculation.ts b/src/lib/getAPYCalculation.ts index 593180dc..7bd34216 100644 --- a/src/lib/getAPYCalculation.ts +++ b/src/lib/getAPYCalculation.ts @@ -2,23 +2,21 @@ import { OneMonth, StakeDurationMultipliers, MULTIPLIER_BASIS } from "@/constant import { parseUnits } from "viem"; export const getAPYCalculation = ( - rewardRate: number, + rewardRatePerSec: number, totalWeightedStake: number, stakeDurationIndex: number, ) => { - // -------- APR and APY Formula ----------- // - const OneToken = Number(parseUnits("1", 18)); const OneYear = 12 * OneMonth; - if (totalWeightedStake == 0) { - totalWeightedStake = OneToken; - } - const rewardRatePerSecPerToken = (rewardRate * OneToken) / totalWeightedStake; - const rewardRatePerYearPerToken = rewardRatePerSecPerToken * OneYear; + const rewardRatePerYear = rewardRatePerSec * OneYear; const multiplier = StakeDurationMultipliers[stakeDurationIndex]; const myStakeAmount = (OneToken * multiplier) / MULTIPLIER_BASIS; + if (totalWeightedStake == 0) { + totalWeightedStake = myStakeAmount; + } const myPortion = myStakeAmount / totalWeightedStake; - const APY = rewardRatePerYearPerToken * myPortion * 100; + const rewardsAmountPerYear = rewardRatePerYear * myPortion; + const APY = (rewardsAmountPerYear / OneToken) * 100; return APY.toFixed(2); };