Skip to content

Commit

Permalink
Refactor yield calculations and update token details
Browse files Browse the repository at this point in the history
  • Loading branch information
SidharthK2 committed Oct 29, 2024
1 parent 000b828 commit 0693707
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 23 deletions.
5 changes: 4 additions & 1 deletion src/components/lock/LockOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions src/components/lock/RewardCalculator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/data/LockConstants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
15 changes: 0 additions & 15 deletions src/utils/LockOverviewUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 0693707

Please sign in to comment.