Skip to content

Commit

Permalink
fixed market tokens data hook to work with passed glvs
Browse files Browse the repository at this point in the history
  • Loading branch information
hubert-de-lalye committed Oct 3, 2024
1 parent a4bb06f commit 8f3fbb3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/components/TokenCard/TokenCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ export default function TokenCard({ showRedirectModal }: Props) {
const maxGlvApyText = useMemo(() => {
const arb = !arbGlvApy
? "...%"
: `${formatAmount(calculateMaxApr({ ...arbGlvApy, ...arbGlvIncentiveApr }, {}, ARBITRUM), 28, 2)}%`;
: `${formatAmount(calculateMaxApr(arbGlvApy, arbGlvIncentiveApr ?? {}, ARBITRUM), 28, 2)}%`;
const avax = !avaxGlvApy
? "...%"
: `${formatAmount(calculateMaxApr({ ...avaxGlvApy, ...avaxGlvIncentiveApr }, {}, AVALANCHE), 28, 2)}%`;
: `${formatAmount(calculateMaxApr(avaxGlvApy, avaxGlvIncentiveApr ?? {}, AVALANCHE), 28, 2)}%`;
return {
[ARBITRUM]: isGlvEnabled(ARBITRUM) ? arb : undefined,
[AVALANCHE]: isGlvEnabled(AVALANCHE) ? avax : undefined,
Expand Down
13 changes: 9 additions & 4 deletions src/domain/synthetics/markets/useGmMarketsApy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useTokensDataRequest } from "../tokens";
import { GlvAndGmMarketsInfoData, MarketInfo, MarketTokensAPRData } from "./types";
import { useDaysConsideredInMarketsApr } from "./useDaysConsideredInMarketsApr";
import { useMarketTokensData } from "./useMarketTokensData";
import { getPoolUsdWithoutPnl, isMarketInfo } from "domain/synthetics/markets";
import { getPoolUsdWithoutPnl, GlvInfoData, isMarketInfo } from "domain/synthetics/markets";
import { getTokenBySymbolSafe } from "config/tokens";

import TokenAbi from "abis/Token.json";
Expand Down Expand Up @@ -139,11 +139,15 @@ function useExcludedLiquidityMarketMap(
return excludedBalancesMulticall.data ?? {};
}

function useIncentivesBonusApr(chainId: number, marketsInfoData: GlvAndGmMarketsInfoData | undefined) {
function useIncentivesBonusApr(
chainId: number,
marketsInfoData: GlvAndGmMarketsInfoData | undefined,
glvData: GlvInfoData | undefined
) {
const liquidityProvidersIncentives = useLiquidityProvidersIncentives(chainId);
const { tokensData } = useTokensDataRequest(chainId);
const marketAddresses = useMarketAddresses(marketsInfoData);
const { marketTokensData } = useMarketTokensData(chainId, { isDeposit: false });
const { marketTokensData } = useMarketTokensData(chainId, { isDeposit: false, withGlv: true, glvData });
const tokenAddress = liquidityProvidersIncentives?.token;
const excludedLiquidityMarketMap = useExcludedLiquidityMarketMap(chainId, marketsInfoData);

Expand Down Expand Up @@ -194,6 +198,7 @@ function useIncentivesBonusApr(chainId: number, marketsInfoData: GlvAndGmMarkets
if (!market) {
continue;
}

const marketToken = marketTokensData?.[marketAddress];
const poolValue = market?.poolValueMin;

Expand Down Expand Up @@ -407,7 +412,7 @@ export function useGmMarketsApy(chainId: number): GmGlvTokensAPRResult {
},
});

const marketsTokensIncentiveAprData = useIncentivesBonusApr(chainId, marketsInfoData);
const marketsTokensIncentiveAprData = useIncentivesBonusApr(chainId, marketsInfoData, glvData);

const glvApyInfoData = useMemo(() => {
if (!glvData || !data?.marketsTokensApyData) {
Expand Down
6 changes: 4 additions & 2 deletions src/domain/synthetics/markets/useMarketTokensData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,13 @@ export function useMarketTokensDataRequest(

export function useMarketTokensData(
chainId: number,
p: { isDeposit: boolean; withGlv?: boolean }
p: { isDeposit: boolean; withGlv?: boolean; glvData?: GlvInfoData }
): MarketTokensDataResult {
const { isDeposit } = p;
const account = useSelector((s) => s.globals.account);
const glvData = useSelector(selectGlvInfo);
const storedGlvData = useSelector(selectGlvInfo);

const glvData = p.glvData || storedGlvData;

return useMarketTokensDataRequest(chainId, {
isDeposit,
Expand Down

0 comments on commit 8f3fbb3

Please sign in to comment.