Skip to content

Commit

Permalink
fix your apy issue
Browse files Browse the repository at this point in the history
  • Loading branch information
xieqiancaosissi committed Jan 1, 2024
1 parent 08d0ec1 commit fc4b195
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
12 changes: 8 additions & 4 deletions hooks/useExtraAPY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -87,7 +92,6 @@ export function useExtraAPY({
((totalDailyRewards * price * 365 * multiplier) /
((totalUserAssetUSD * totalBoostedShares) / shares)) *
100;

return apy || 0;
};

Expand Down
12 changes: 10 additions & 2 deletions redux/selectors/getAccountRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
);
Expand All @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions screens/Market/APYCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const ToolTip = ({
isBorrow,
onlyMarket,
});

return (
<HtmlTooltip
open={showTooltip}
Expand All @@ -82,7 +81,6 @@ const ToolTip = ({
]}
{list.map(({ rewards, metadata, price, config }) => {
const { symbol, icon } = metadata;

const rewardAPY = computeRewardAPY(
metadata.token_id,
rewards.reward_per_day,
Expand Down

0 comments on commit fc4b195

Please sign in to comment.