From 0693707b0a86d239e0b5b0a4d6a9d6f1fc96f110 Mon Sep 17 00:00:00 2001 From: SidharthK2 Date: Tue, 29 Oct 2024 21:39:26 +0530 Subject: [PATCH] Refactor yield calculations and update token details --- src/components/lock/LockOverview.tsx | 5 ++++- src/components/lock/RewardCalculator.tsx | 7 +------ src/data/LockConstants.tsx | 2 +- src/utils/LockOverviewUtils.ts | 15 --------------- 4 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/components/lock/LockOverview.tsx b/src/components/lock/LockOverview.tsx index 6d051247..7cf07165 100644 --- a/src/components/lock/LockOverview.tsx +++ b/src/components/lock/LockOverview.tsx @@ -11,9 +11,12 @@ import StakeCard from '../cards/StakeCard' import StakeOverviewWrapper from '../elements/stakeCommon/StakeOverviewWrapper' import { calculateEstimatedYieldPerWeek } from '@/data/LockConstants' import { useGetIqPriceQuery } from '@/services/iqPrice' +import config from '@/config' const LockOverview = () => { - const { totalHiiqSupply, userTotalIQLocked } = useLockOverview() + const { totalHiiqSupply, userTotalIQLocked } = useLockOverview( + config.treasuryHiIQAddress, + ) const { tvl } = useErc20() const [holders, setHolders] = useState(0) const [averageLockTime, setAverageLockTime] = useState(0) diff --git a/src/components/lock/RewardCalculator.tsx b/src/components/lock/RewardCalculator.tsx index 9067c858..61c2c4c4 100644 --- a/src/components/lock/RewardCalculator.tsx +++ b/src/components/lock/RewardCalculator.tsx @@ -62,12 +62,7 @@ const RewardCalculator = ({ useEffect(() => { if (years && inputIQ) { // TODO: review calculation APR needs to be calculated w generated HiIQ not w inputIQ - const userReward = calculateStakeReward( - totalHiiqSupply, - inputIQ, - years, - years, - ) + const userReward = calculateStakeReward(totalHiiqSupply, inputIQ, years) setExpectedReward(userReward) } else { setExpectedReward(0) diff --git a/src/data/LockConstants.tsx b/src/data/LockConstants.tsx index a3bf4995..0fcbb9c4 100644 --- a/src/data/LockConstants.tsx +++ b/src/data/LockConstants.tsx @@ -24,7 +24,7 @@ export const YEARLY_EMISSION = DAILY_EMISSION * 365 export const WEEKLY_EMISSION = DAILY_EMISSION * 7 export const calculateEstimatedYieldPerWeek = () => { - return WEEKLY_EMISSION // 21M IQ per week (3M * 7) + return WEEKLY_EMISSION } export const calculateUserPoolRewardOverTheYear = ( diff --git a/src/utils/LockOverviewUtils.ts b/src/utils/LockOverviewUtils.ts index 4a16d5f6..1e1b9be5 100644 --- a/src/utils/LockOverviewUtils.ts +++ b/src/utils/LockOverviewUtils.ts @@ -15,16 +15,9 @@ export const calculateStakeReward = ( years: number, ) => { const yearsLocked = years || YEARS_LOCK - - // Calculate base HiIQ (including lock multiplier) const baseHiIQ = amountLocked + amountLocked * 3 * (yearsLocked / 4) - - // Calculate pool share const userPoolShare = baseHiIQ / (totalHiiq + baseHiIQ) - - // Calculate total rewards over the period const totalPoolReward = YEARLY_EMISSION * userPoolShare * yearsLocked - return baseHiIQ + totalPoolReward } @@ -36,17 +29,9 @@ export const calculateAPR = ( if (!totalLockedIq || !totalHiiq) return 0 const amountLocked = totalLockedIq > 0 ? totalLockedIq : 1000000 - - // Calculate base HiIQ with lock multiplier const baseHiIQ = amountLocked + amountLocked * 3 * (years / 4) - - // Calculate share of the pool const poolShare = baseHiIQ / (totalHiiq + baseHiIQ) - - // Calculate yearly rewards const yearlyRewards = YEARLY_EMISSION * poolShare - - // Calculate APR return (yearlyRewards / amountLocked) * 100 }