diff --git a/frontend/src/lib/liquidityMining.ts b/frontend/src/lib/liquidityMining.ts index 8cc45379..e726db16 100644 --- a/frontend/src/lib/liquidityMining.ts +++ b/frontend/src/lib/liquidityMining.ts @@ -24,7 +24,7 @@ type ObligationClaim = { export type RewardSummary = { stats: { id: string; - active: boolean; + isActive: boolean; rewardIndex: number; reserveCoinType: string; rewardCoinType: string; @@ -69,6 +69,10 @@ export function formatRewards( const rewardReserve = parsedReserveMap[poolReward.coinType]; const rewardCoinMetadata = coinMetadataMap[poolReward.coinType]; + const isActive = + currentTime >= poolReward.startTimeMs && + currentTime < poolReward.endTimeMs; + const aprPercent = rewardReserve ? poolReward.totalRewards .times(rewardReserve.price) @@ -94,9 +98,7 @@ export function formatRewards( return { stats: { id: poolReward.id, - active: - currentTime >= poolReward.startTimeMs && - currentTime < poolReward.endTimeMs, + isActive, rewardIndex: poolReward.rewardIndex, reserveCoinType: reserve.coinType, rewardCoinType: poolReward.coinType, @@ -173,7 +175,7 @@ function getObligationClaims( } export const getFilteredRewards = (rewards: RewardSummary[]): RewardSummary[] => - rewards.filter((r) => r.stats.active); + rewards.filter((r) => r.stats.isActive); export const getDedupedAprRewards = ( filteredRewards: RewardSummary[], diff --git a/frontend/src/lib/points.ts b/frontend/src/lib/points.ts index 1ba22571..36922e73 100644 --- a/frontend/src/lib/points.ts +++ b/frontend/src/lib/points.ts @@ -3,7 +3,7 @@ import BigNumber from "bignumber.js"; import { ParsedObligation } from "@suilend/sdk/parsers/obligation"; import { isSuilendPoints } from "@/lib/coinType"; -import { RewardMap, getFilteredRewards } from "@/lib/liquidityMining"; +import { RewardMap } from "@/lib/liquidityMining"; export const roundPoints = (value: BigNumber) => value.decimalPlaces(0, BigNumber.ROUND_HALF_UP); @@ -26,15 +26,11 @@ export const getPointsStats = ( return { totalPoints, pointsPerDay }; const pointsRewards = { - deposit: getFilteredRewards( - Object.values(rewardMap).flatMap((rewards) => - rewards.deposit.filter((r) => isSuilendPoints(r.stats.rewardCoinType)), - ), + deposit: Object.values(rewardMap).flatMap((rewards) => + rewards.deposit.filter((r) => isSuilendPoints(r.stats.rewardCoinType)), ), - borrow: getFilteredRewards( - Object.values(rewardMap).flatMap((rewards) => - rewards.borrow.filter((r) => isSuilendPoints(r.stats.rewardCoinType)), - ), + borrow: Object.values(rewardMap).flatMap((rewards) => + rewards.borrow.filter((r) => isSuilendPoints(r.stats.rewardCoinType)), ), }; @@ -45,12 +41,14 @@ export const getPointsStats = ( new BigNumber(0), ); - pointsPerDay.deposit = pointsPerDay.deposit.plus( - obligation.deposits - .find((d) => d.coinType === reward.stats.reserveCoinType) - ?.depositedAmount.times(reward.stats.perDay ?? new BigNumber(0)) ?? - new BigNumber(0), - ); + if (reward.stats.isActive) { + pointsPerDay.deposit = pointsPerDay.deposit.plus( + obligation.deposits + .find((d) => d.coinType === reward.stats.reserveCoinType) + ?.depositedAmount.times(reward.stats.perDay ?? new BigNumber(0)) ?? + new BigNumber(0), + ); + } }); pointsRewards.borrow.forEach((reward) => { @@ -59,12 +57,14 @@ export const getPointsStats = ( new BigNumber(0), ); - pointsPerDay.borrow = pointsPerDay.borrow.plus( - obligation.borrows - .find((d) => d.coinType === reward.stats.reserveCoinType) - ?.borrowedAmount.times(reward.stats.perDay ?? new BigNumber(0)) ?? - new BigNumber(0), - ); + if (reward.stats.isActive) { + pointsPerDay.borrow = pointsPerDay.borrow.plus( + obligation.borrows + .find((d) => d.coinType === reward.stats.reserveCoinType) + ?.borrowedAmount.times(reward.stats.perDay ?? new BigNumber(0)) ?? + new BigNumber(0), + ); + } }); });