From fc4b195e6521e2442e97503a1667cc4d693df15c Mon Sep 17 00:00:00 2001 From: "nature.xie" Date: Mon, 1 Jan 2024 12:02:23 +0800 Subject: [PATCH] fix your apy issue --- hooks/useExtraAPY.ts | 12 ++++++++---- redux/selectors/getAccountRewards.ts | 12 ++++++++++-- screens/Market/APYCell.tsx | 2 -- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/hooks/useExtraAPY.ts b/hooks/useExtraAPY.ts index 324c628f..855e0bcc 100644 --- a/hooks/useExtraAPY.ts +++ b/hooks/useExtraAPY.ts @@ -9,6 +9,7 @@ import { useAppSelector } from "../redux/hooks"; import { shrinkToken } from "../store/helper"; import { getNetTvlAPY, getTotalNetTvlAPY } from "../redux/selectors/getNetAPY"; import { useNonFarmedAssets } from "./hooks"; +import { lpTokenPrefix, DEFAULT_POSITION } from "../utils/config"; export function useExtraAPY({ tokenId: assetId, @@ -40,13 +41,17 @@ export function useExtraAPY({ const assetDecimals = asset.metadata.decimals + asset.config.extra_decimals; const assetPrice = assets.data[assetId].price?.usd || 0; - + const position = assetId.indexOf(lpTokenPrefix) > -1 ? assetId : DEFAULT_POSITION; const totalBorrowAssetUSD = - Number(shrinkToken(portfolio.borrowed?.[assetId]?.balance || 0, assetDecimals)) * assetPrice; + Number( + shrinkToken(portfolio.positions[position].borrowed?.[assetId]?.balance || 0, assetDecimals), + ) * assetPrice; const totalSupplyAssetUSD = Number(shrinkToken(portfolio.supplied[assetId]?.balance || 0, assetDecimals)) * assetPrice; const totalCollateralAssetUSD = - Number(shrinkToken(portfolio.collateral?.[assetId]?.balance || 0, assetDecimals)) * assetPrice; + Number( + shrinkToken(portfolio.positions[position].collateral?.[assetId]?.balance || 0, assetDecimals), + ) * assetPrice; const totalUserAssetUSD = isBorrow ? totalBorrowAssetUSD @@ -87,7 +92,6 @@ export function useExtraAPY({ ((totalDailyRewards * price * 365 * multiplier) / ((totalUserAssetUSD * totalBoostedShares) / shares)) * 100; - return apy || 0; }; diff --git a/redux/selectors/getAccountRewards.ts b/redux/selectors/getAccountRewards.ts index 7ffa18ac..e557443d 100644 --- a/redux/selectors/getAccountRewards.ts +++ b/redux/selectors/getAccountRewards.ts @@ -10,6 +10,7 @@ import { getStaking } from "./getStaking"; import { INetTvlFarmRewards } from "../../interfaces"; import { hasAssets, toUsd } from "../utils"; import { cloneObj } from "../../helpers/helpers"; +import { lpTokenPrefix, DEFAULT_POSITION } from "../../utils/config"; interface IPortfolioReward { icon: string; @@ -90,6 +91,7 @@ export const computePoolsDailyAmount = ( farmData: FarmData, boosterDecimals: number, ) => { + const position = asset.token_id.indexOf(lpTokenPrefix) > -1 ? asset.token_id : DEFAULT_POSITION; const boosterLogBase = Number( shrinkToken(farmData.asset_farm_reward.booster_log_base, boosterDecimals), ); @@ -115,10 +117,16 @@ export const computePoolsDailyAmount = ( shrinkToken(portfolio.supplied[asset.token_id]?.shares || 0, assetDecimals), ); const collateralShares = Number( - shrinkToken(portfolio.collateral?.[asset.token_id]?.shares || 0, assetDecimals), + shrinkToken( + portfolio.positions[position].collateral?.[asset.token_id]?.shares || 0, + assetDecimals, + ), ); const borrowedShares = Number( - shrinkToken(portfolio.borrowed?.[asset.token_id]?.shares || 0, assetDecimals), + shrinkToken( + portfolio.positions[position].borrowed?.[asset.token_id]?.shares || 0, + assetDecimals, + ), ); const shares = type === "supplied" ? suppliedShares + collateralShares : borrowedShares; diff --git a/screens/Market/APYCell.tsx b/screens/Market/APYCell.tsx index 75e2fbba..fce9a18a 100644 --- a/screens/Market/APYCell.tsx +++ b/screens/Market/APYCell.tsx @@ -59,7 +59,6 @@ const ToolTip = ({ isBorrow, onlyMarket, }); - return ( { const { symbol, icon } = metadata; - const rewardAPY = computeRewardAPY( metadata.token_id, rewards.reward_per_day,