Skip to content

Commit

Permalink
points fix
Browse files Browse the repository at this point in the history
  • Loading branch information
0xshiba1 committed Jul 18, 2024
1 parent 8c0faa1 commit dde0c25
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
12 changes: 7 additions & 5 deletions frontend/src/lib/liquidityMining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type ObligationClaim = {
export type RewardSummary = {
stats: {
id: string;
active: boolean;
isActive: boolean;
rewardIndex: number;
reserveCoinType: string;
rewardCoinType: string;
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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[],
Expand Down
42 changes: 21 additions & 21 deletions frontend/src/lib/points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)),
),
};

Expand All @@ -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) => {
Expand All @@ -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),
);
}
});
});

Expand Down

0 comments on commit dde0c25

Please sign in to comment.