diff --git a/.vscode/settings.json b/.vscode/settings.json index 12f1627cf..17ca72fae 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,6 +9,7 @@ "delvtech", "dnum", "fixedpointmath", + "hyperdrive", "hyperwasm", "ihyperdrive", "mintable", diff --git a/apps/hyperdrive-trading/src/base/formatRate.ts b/apps/hyperdrive-trading/src/base/formatRate.ts index 403dbe7ce..78ab9abb2 100644 --- a/apps/hyperdrive-trading/src/base/formatRate.ts +++ b/apps/hyperdrive-trading/src/base/formatRate.ts @@ -5,12 +5,18 @@ export function formatRate( decimals = 18, includePercentSign = true, ): string { - const formatted = fixed(rate, decimals).format({ + let formatted = fixed(rate, decimals).format({ percent: true, decimals: 2, }); - if (includePercentSign) { - return formatted; + + if (formatted === "-0.00%") { + formatted = "0.00%"; + } + + if (!includePercentSign) { + formatted = formatted.split("%")[0]; } - return formatted.split("%")[0]; + + return formatted; } diff --git a/apps/hyperdrive-trading/src/hyperdrive/getLpApy.ts b/apps/hyperdrive-trading/src/hyperdrive/getLpApy.ts new file mode 100644 index 000000000..04fb92a1d --- /dev/null +++ b/apps/hyperdrive-trading/src/hyperdrive/getLpApy.ts @@ -0,0 +1,76 @@ +import { Block, ReadHyperdrive } from "@delvtech/hyperdrive-viem"; +import { appConfig, HyperdriveConfig } from "@hyperdrive/appconfig"; +import { convertMillisecondsToDays } from "src/base/convertMillisecondsToDays"; +import { isForkChain } from "src/chains/isForkChain"; + +export type LpApyResult = { + ratePeriodDays: number; +} & ( + | { + lpApy: bigint; + isNew: false; + } + | { + lpApy: undefined; + isNew: true; + } +); + +export async function getLpApy({ + readHyperdrive, + hyperdrive, +}: { + readHyperdrive: ReadHyperdrive; + hyperdrive: HyperdriveConfig; +}): Promise { + const currentBlock = (await readHyperdrive.network.getBlock()) as Block; + const currentBlockNumber = currentBlock.blockNumber!; + + // Appconfig tells us how many days to look back for historical rates + const numBlocksForHistoricalRate = isForkChain(hyperdrive.chainId) + ? 1000n // roughly 3 hours for cloudchain + : appConfig.chains[hyperdrive.chainId].dailyAverageBlocks * + BigInt( + appConfig.yieldSources[hyperdrive.yieldSource].historicalRatePeriod, + ); + const targetFromBlock = currentBlockNumber - numBlocksForHistoricalRate; + + let lpApy: bigint | undefined; + + const blocksSinceInitialization = + (currentBlockNumber || 0n) - hyperdrive.initializationBlock; + const isYoungerThanOneDay = + blocksSinceInitialization < + appConfig.chains[hyperdrive.chainId].dailyAverageBlocks; + + // if the pool was deployed less than one day ago, it's new. + if (!isYoungerThanOneDay) { + const lpApyResult = await readHyperdrive.getLpApy({ + fromBlock: [31337].includes(hyperdrive.chainId) + ? // local devnets don't have a lot of blocks, so start from the beginning + 1n + : targetFromBlock, + }); + lpApy = lpApyResult.lpApy; + } + + // Figure out if the pool is younger than 1 rate period + const isPoolYoungerThanOneRatePeriod = + hyperdrive.initializationBlock > targetFromBlock; + + // If we don't have enough blocks to go back 1 full historical period, then + // grab the all-time rate instead. + let ratePeriodDays = + appConfig.yieldSources[hyperdrive.yieldSource].historicalRatePeriod; + if (isPoolYoungerThanOneRatePeriod) { + ratePeriodDays = convertMillisecondsToDays( + Date.now() - Number(hyperdrive.initializationTimestamp * 1000n), + ); + } + + return { + lpApy, + ratePeriodDays, + isNew: lpApy === undefined, + } as LpApyResult; +} diff --git a/apps/hyperdrive-trading/src/token/getTokenFiatPrice.ts b/apps/hyperdrive-trading/src/token/getTokenFiatPrice.ts new file mode 100644 index 000000000..af290b385 --- /dev/null +++ b/apps/hyperdrive-trading/src/token/getTokenFiatPrice.ts @@ -0,0 +1,32 @@ +import { parseFixed } from "@delvtech/fixed-point-wasm"; +import { ETH_MAGIC_NUMBER } from "src/token/ETH_MAGIC_NUMBER"; +import { gnosis, linea, mainnet } from "viem/chains"; + +export async function getTokenFiatPrice({ + tokenAddress, + chainId, +}: { + tokenAddress: string; + chainId: number; +}): Promise { + // Always use mainnet ETH as the reference for native ETH price, regardless of + // the current chain. + let defiLlamaTokenId = `${defiLlamaChainNameIdentifier[chainId]}:${tokenAddress}`; + if (tokenAddress === ETH_MAGIC_NUMBER) { + defiLlamaTokenId = `ethereum:${ETH_MAGIC_NUMBER}`; + } + + const response = await fetch( + `https://coins.llama.fi/prices/current/${defiLlamaTokenId}`, + ); + const data = await response.json(); + const { price } = data.coins[defiLlamaTokenId]; + return parseFixed(price).bigint; +} + +// NOTE: DefiLlama chain name identifier must be lower case. +export const defiLlamaChainNameIdentifier: Record = { + [mainnet.id]: "ethereum", + [gnosis.id]: "gnosis", + [linea.id]: "linea", +}; diff --git a/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useLpApy.ts b/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useLpApy.ts index 7b580d38a..cbf4dc67f 100644 --- a/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useLpApy.ts +++ b/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useLpApy.ts @@ -1,10 +1,7 @@ -import { Block } from "@delvtech/hyperdrive-viem"; import { appConfig, findHyperdriveConfig } from "@hyperdrive/appconfig"; import { useQuery } from "@tanstack/react-query"; -import { convertMillisecondsToDays } from "src/base/convertMillisecondsToDays"; -import { formatRate } from "src/base/formatRate"; import { makeQueryKey } from "src/base/makeQueryKey"; -import { isForkChain } from "src/chains/isForkChain"; +import { getLpApy, LpApyResult } from "src/hyperdrive/getLpApy"; import { usePoolInfo } from "src/ui/hyperdrive/hooks/usePoolInfo"; import { useReadHyperdrive } from "src/ui/hyperdrive/hooks/useReadHyperdrive"; import { Address } from "viem"; @@ -17,9 +14,7 @@ export function useLpApy({ hyperdriveAddress: Address; chainId: number; }): { - lpApy: - | { lpApy: bigint; formatted: string; ratePeriodDays: number } - | undefined; + lpApy: LpApyResult | undefined; lpApyStatus: "error" | "success" | "loading"; } { const { poolInfo: currentPoolInfo } = usePoolInfo({ @@ -45,45 +40,11 @@ export function useLpApy({ hyperdrive: hyperdriveAddress, }), queryFn: queryEnabled - ? async () => { - const numBlocksForHistoricalRate = isForkChain(chainId) - ? 1000n // roughly 3 hours for cloudchain - : appConfig.chains[hyperdrive.chainId].dailyAverageBlocks * - BigInt( - appConfig.yieldSources[hyperdrive.yieldSource] - .historicalRatePeriod, - ); - const { lpApy } = await readHyperdrive.getLpApy({ - fromBlock: [31337].includes(chainId) - ? // local devnets don't have a lot of blocks, so start from the beginning - 1n - : // Appconfig tells us how many days to look back for historical rates - blockNumber - numBlocksForHistoricalRate, - }); - - // Figure out if the pool is younger than 1 rate period - const currentBlock = - (await readHyperdrive.network.getBlock()) as Block; - const isPoolYoungerThanOneRatePeriod = - hyperdrive.initializationBlock > - currentBlock.blockNumber! - numBlocksForHistoricalRate; - - // If we don't have enough blocks to go back 1 full historical period, then - // grab the all-time rate instead. - let ratePeriodDays = - appConfig.yieldSources[hyperdrive.yieldSource].historicalRatePeriod; - if (isPoolYoungerThanOneRatePeriod) { - ratePeriodDays = convertMillisecondsToDays( - Date.now() - Number(hyperdrive.initializationTimestamp * 1000n), - ); - } - - return { - lpApy, - ratePeriodDays, - formatted: formatRate(lpApy), - }; - } + ? async () => + getLpApy({ + readHyperdrive, + hyperdrive, + }) : undefined, enabled: queryEnabled, }); diff --git a/apps/hyperdrive-trading/src/ui/hyperdrive/lp/AddLiquidityForm/AddLiquidityForm.tsx b/apps/hyperdrive-trading/src/ui/hyperdrive/lp/AddLiquidityForm/AddLiquidityForm.tsx index f9d326949..01421c31f 100644 --- a/apps/hyperdrive-trading/src/ui/hyperdrive/lp/AddLiquidityForm/AddLiquidityForm.tsx +++ b/apps/hyperdrive-trading/src/ui/hyperdrive/lp/AddLiquidityForm/AddLiquidityForm.tsx @@ -11,6 +11,7 @@ import classNames from "classnames"; import { MouseEvent, ReactElement } from "react"; import Skeleton from "react-loading-skeleton"; import { calculateRatio } from "src/base/calculateRatio"; +import { formatRate } from "src/base/formatRate"; import { isTestnetChain } from "src/chains/isTestnetChain"; import { getHasEnoughAllowance } from "src/token/getHasEnoughAllowance"; import { getHasEnoughBalance } from "src/token/getHasEnoughBalance"; @@ -20,7 +21,6 @@ import { PrimaryStat } from "src/ui/base/components/PrimaryStat"; import { formatBalance } from "src/ui/base/formatting/formatBalance"; import { useNumericInput } from "src/ui/base/hooks/useNumericInput"; import { TransactionView } from "src/ui/hyperdrive/TransactionView"; -import { useIsNewPool } from "src/ui/hyperdrive/hooks/useIsNewPool"; import { useLpApy } from "src/ui/hyperdrive/hooks/useLpApy"; import { usePoolInfo } from "src/ui/hyperdrive/hooks/usePoolInfo"; import { useFixedRate } from "src/ui/hyperdrive/longs/hooks/useFixedRate"; @@ -217,7 +217,6 @@ export function AddLiquidityForm({ status: addLiquidityPreviewStatus, previewAddLiquidityError, } = usePreviewAddLiquidity(addLiquidityParams); - const isNewPool = useIsNewPool({ hyperdrive }); const { lpSharesTotalSupply } = useLpSharesTotalSupply({ chainId: hyperdrive.chainId, @@ -227,7 +226,6 @@ export function AddLiquidityForm({ lpSharesBalanceOf, lpSharesOut, lpSharesTotalSupply, - hyperdrive, baseToken, }); const { fiatPrice: activeTokenPrice } = useTokenFiatPrice({ @@ -360,10 +358,10 @@ export function AddLiquidityForm({ ✨New✨ ) : ( - `${lpApy.formatted === "-0.00" ? "0.00" : lpApy.formatted}` + `${formatRate(lpApy.lpApy)}` ) } tooltipContent="The annual percentage yield projection for providing liquidity." @@ -469,13 +467,11 @@ function calculatePoolShare({ lpSharesBalanceOf, lpSharesOut, lpSharesTotalSupply, - hyperdrive, baseToken, }: { lpSharesBalanceOf: bigint | undefined; lpSharesOut: bigint | undefined; lpSharesTotalSupply: bigint | undefined; - hyperdrive: HyperdriveConfig; baseToken: TokenConfig; }) { if (!lpSharesOut || !lpSharesTotalSupply || lpSharesBalanceOf === undefined) { diff --git a/apps/hyperdrive-trading/src/ui/hyperdrive/lp/AddLiquidityForm/AddLiquidityForm2.tsx b/apps/hyperdrive-trading/src/ui/hyperdrive/lp/AddLiquidityForm/AddLiquidityForm2.tsx index 02e33e0ce..b1d3df29c 100644 --- a/apps/hyperdrive-trading/src/ui/hyperdrive/lp/AddLiquidityForm/AddLiquidityForm2.tsx +++ b/apps/hyperdrive-trading/src/ui/hyperdrive/lp/AddLiquidityForm/AddLiquidityForm2.tsx @@ -11,6 +11,7 @@ import classNames from "classnames"; import { MouseEvent, ReactElement } from "react"; import Skeleton from "react-loading-skeleton"; import { calculateRatio } from "src/base/calculateRatio"; +import { formatRate } from "src/base/formatRate"; import { isTestnetChain } from "src/chains/isTestnetChain"; import { getHasEnoughAllowance } from "src/token/getHasEnoughAllowance"; import { getHasEnoughBalance } from "src/token/getHasEnoughBalance"; @@ -503,11 +504,11 @@ function LpApyStat({ hyperdrive }: { hyperdrive: HyperdriveConfig }) { if (showSkeleton) { return ; } - if (isNewPool) { + if (lpApy === undefined || lpApy.isNew) { return
✨New✨
; } - return `${lpApy?.formatted === "-0.00" ? "0.00" : lpApy?.formatted}`; + return `${formatRate(lpApy?.lpApy)}`; })()} tooltipContent="The annual percentage yield projection for providing liquidity." tooltipPosition="left" diff --git a/apps/hyperdrive-trading/src/ui/markets/PoolRow/PoolRow.tsx b/apps/hyperdrive-trading/src/ui/markets/PoolRow/PoolRow.tsx index d95711bf3..7b6f03ad6 100644 --- a/apps/hyperdrive-trading/src/ui/markets/PoolRow/PoolRow.tsx +++ b/apps/hyperdrive-trading/src/ui/markets/PoolRow/PoolRow.tsx @@ -1,4 +1,3 @@ -import { fixed } from "@delvtech/fixed-point-wasm"; import { ClockIcon } from "@heroicons/react/16/solid"; import { HyperdriveConfig, @@ -11,82 +10,40 @@ import classNames from "classnames"; import { ReactElement, ReactNode } from "react"; import Skeleton from "react-loading-skeleton"; import { formatRate } from "src/base/formatRate"; -import { isTestnetChain } from "src/chains/isTestnetChain"; +import { LpApyResult } from "src/hyperdrive/getLpApy"; import { Well } from "src/ui/base/components/Well/Well"; import { formatCompact } from "src/ui/base/formatting/formatCompact"; -import { useIsNewPool } from "src/ui/hyperdrive/hooks/useIsNewPool"; -import { useLpApy } from "src/ui/hyperdrive/hooks/useLpApy"; -import { usePresentValue } from "src/ui/hyperdrive/hooks/usePresentValue"; -import { useFixedRate } from "src/ui/hyperdrive/longs/hooks/useFixedRate"; import { AssetStack } from "src/ui/markets/AssetStack"; import { formatTermLength2 } from "src/ui/markets/formatTermLength"; import { MARKET_DETAILS_ROUTE } from "src/ui/markets/routes"; import { RewardsTooltip } from "src/ui/rewards/RewardsTooltip"; -import { useTokenFiatPrice } from "src/ui/token/hooks/useTokenFiatPrice"; -import { useYieldSourceRate } from "src/ui/vaults/useYieldSourceRate"; + +export interface PoolRowProps { + hyperdrive: HyperdriveConfig; + tvl: bigint; + isFiat: boolean; + fixedApr: bigint; + vaultRate: bigint; + lpApy: LpApyResult; +} export function PoolRow({ hyperdrive, -}: { - hyperdrive: HyperdriveConfig; -}): ReactElement { + tvl, + isFiat, + fixedApr, + vaultRate, + lpApy, +}: PoolRowProps): ReactElement { const navigate = useNavigate(); - const { yieldSources, chains } = appConfig; - const chainInfo = chains[hyperdrive.chainId]; - const { fixedApr, fixedRateStatus } = useFixedRate({ - chainId: hyperdrive.chainId, - hyperdriveAddress: hyperdrive.address, - }); - const { vaultRate, vaultRateStatus } = useYieldSourceRate({ - chainId: hyperdrive.chainId, - hyperdriveAddress: hyperdrive.address, - }); - const { lpApy, lpApyStatus } = useLpApy({ - hyperdriveAddress: hyperdrive.address, - chainId: hyperdrive.chainId, - }); - - // if the pool was deployed less than one historical period ago, it's new. - const isYoungerThanOneDay = useIsNewPool({ hyperdrive }); - - const isLpApyNew = - isYoungerThanOneDay || (lpApyStatus !== "loading" && lpApy === undefined); - // Display TVL as base value on testnet due to lack of reliable fiat pricing. - // On mainnet and others, use DeFiLlama's fiat price. - const { presentValue } = usePresentValue({ - chainId: hyperdrive.chainId, - hyperdriveAddress: hyperdrive.address, - }); - const isFiatPriceEnabled = !isTestnetChain(chainInfo.id); const baseToken = findBaseToken({ hyperdriveChainId: hyperdrive.chainId, hyperdriveAddress: hyperdrive.address, appConfig, }); - const { fiatPrice } = useTokenFiatPrice({ - chainId: baseToken.chainId, - tokenAddress: isFiatPriceEnabled - ? hyperdrive.poolConfig.baseToken - : undefined, - }); - let tvlLabel = `${formatCompact({ - value: presentValue || 0n, - decimals: hyperdrive.decimals, - })} ${baseToken.symbol}`; - - if (isFiatPriceEnabled) { - const presentValueFiat = - presentValue && fiatPrice && isFiatPriceEnabled - ? fixed(presentValue, hyperdrive.decimals).mul(fiatPrice).bigint - : 0n; - tvlLabel = `$${formatCompact({ - value: presentValueFiat || 0n, - decimals: hyperdrive.decimals, - })}`; - } const sharesToken = findToken({ chainId: hyperdrive.chainId, @@ -137,7 +94,15 @@ export function PoolRow({
TVL{" "} - {tvlLabel} + {isFiat + ? `$${formatCompact({ + value: tvl, + decimals: hyperdrive.decimals, + })}` + : `${formatCompact({ + value: tvl, + decimals: hyperdrive.decimals, + })} ${baseToken.symbol}`}
@@ -184,14 +149,7 @@ export function PoolRow({
- ) : ( - "-" - ) - } + value={} variant="gradient" action={ - + ) : ( "-" @@ -248,10 +203,9 @@ export function PoolRow({ /> ("TVL"); + + function handleSortChange(option: SortOption) { + setSort(option); + } + + const list = pools?.slice().sort((a, b) => { + switch (sort) { + case "Chain": + const chainA = appConfig.chains[a.hyperdrive.chainId] || {}; + const chainB = appConfig.chains[b.hyperdrive.chainId] || {}; + return chainA.name.localeCompare(chainB.name); + case "Fixed APR": + return Number(b.fixedApr - a.fixedApr); + case "LP APY": + return Number((b.lpApy.lpApy || 0n) - (a.lpApy.lpApy || 0n)); + case "Variable APY": + return Number(b.vaultRate - a.vaultRate); + case "TVL": + return fixed(b.tvl, b.hyperdrive.decimals) + .sub(a.tvl, a.hyperdrive.decimals) + .toNumber(); + default: + return 0; + } + }); + return (
{ // Show the newest pools first - status === "loading" && !hyperdrives ? ( + status === "loading" && !list ? ( - ) : hyperdrives ? ( - [...hyperdrives] - .sort((a, b) => { - return ( - Number(b.initializationTimestamp) - - Number(a.initializationTimestamp) - ); - }) - .map((hyperdrive) => ( - - )) + ) : list ? ( + <> + {/* Sorting & Filtering */} +
+
+
+
+ {sort} + +
+
    + {sortOptions.map((option) => ( +
  • + +
  • + ))} +
+
+
+
+ {list.map( + ({ fixedApr, hyperdrive, isFiat, lpApy, tvl, vaultRate }) => ( + + ), + )} + ) : null }
); } -function usePoolsListHyperdriveConfigs(): { - hyperdrives: HyperdriveConfig[] | undefined; +function usePoolsList(): { + pools: PoolRowProps[] | undefined; status: QueryStatus; } { // Only show testnet and fork pools if the user is connected to a testnet @@ -53,10 +133,11 @@ function usePoolsListHyperdriveConfigs(): { const connectedChainId = useChainId(); const { data, status } = useQuery({ - queryKey: ["poolsListHyperdriveConfigs", { connectedChainId }], + queryKey: ["poolsList", { connectedChainId }], queryFn: async () => { - // We only show hyperdrives that are not paused - const marketStates = await Promise.all( + const pools: PoolRowProps[] = []; + + await Promise.all( appConfigForConnectedChain.hyperdrives.map(async (hyperdrive) => { const publicClient = getPublicClient(wagmiConfig as any, { chainId: hyperdrive.chainId, @@ -67,15 +148,58 @@ function usePoolsListHyperdriveConfigs(): { publicClient: publicClient as PublicClient, }); - return readHyperdrive.getMarketState(); + // We only show hyperdrives that are not paused + const { isPaused } = await readHyperdrive.getMarketState(); + if (isPaused) { + return; + } + + const fixedApr = await readHyperdrive.getFixedApr(); + const vaultRate = await getYieldSourceRate( + readHyperdrive, + appConfigForConnectedChain, + ); + const lpApy = await getLpApy({ + hyperdrive, + readHyperdrive, + }); + + // Display TVL as base value on testnet due to lack of reliable + // fiat pricing. On mainnet and others, use DeFiLlama's fiat + // price. + let tvl = await readHyperdrive.getPresentValue(); + let isFiatSupported = !isTestnetChain(hyperdrive.chainId); + if (isFiatSupported) { + const baseToken = findBaseToken({ + hyperdriveChainId: hyperdrive.chainId, + hyperdriveAddress: hyperdrive.address, + appConfig, + }); + const fiatPrice = await getTokenFiatPrice({ + chainId: hyperdrive.chainId, + tokenAddress: baseToken.address, + }); + if (fiatPrice === undefined) { + isFiatSupported = false; + return; + } + tvl = fixed(tvl, hyperdrive.decimals).mul(fiatPrice).bigint; + } + + pools.push({ + fixedApr, + hyperdrive, + isFiat: isFiatSupported, + lpApy, + tvl, + vaultRate: vaultRate.rate, + }); }), ); - return appConfigForConnectedChain.hyperdrives.filter( - (hyperdrive, i) => !marketStates[i].isPaused, - ); + return pools; }, }); - return { hyperdrives: data, status }; + return { pools: data, status }; } diff --git a/apps/hyperdrive-trading/src/ui/token/hooks/useTokenFiatPrice.ts b/apps/hyperdrive-trading/src/ui/token/hooks/useTokenFiatPrice.ts index f5ddff0a9..04cab535b 100644 --- a/apps/hyperdrive-trading/src/ui/token/hooks/useTokenFiatPrice.ts +++ b/apps/hyperdrive-trading/src/ui/token/hooks/useTokenFiatPrice.ts @@ -1,17 +1,9 @@ -import { parseFixed } from "@delvtech/fixed-point-wasm"; import { useQuery } from "@tanstack/react-query"; import { makeQueryKey } from "src/base/makeQueryKey"; import { isTestnetChain } from "src/chains/isTestnetChain"; -import { ETH_MAGIC_NUMBER } from "src/token/ETH_MAGIC_NUMBER"; +import { getTokenFiatPrice } from "src/token/getTokenFiatPrice"; import { Address } from "viem"; -import { gnosis, linea, mainnet } from "viem/chains"; -// NOTE: DefiLlama chain name identifier must be lower case. -const defiLlamaChainNameIdentifier: Record = { - [mainnet.id]: "ethereum", - [gnosis.id]: "gnosis", - [linea.id]: "linea", -}; export function useTokenFiatPrice({ tokenAddress, chainId, @@ -21,27 +13,17 @@ export function useTokenFiatPrice({ }): { fiatPrice: bigint | undefined; } { - // Always use mainnet ETH as the reference for native ETH price, regardless of - // the current chain. - let defiLlamaTokenId = `${defiLlamaChainNameIdentifier[chainId]}:${tokenAddress}`; - if (tokenAddress === ETH_MAGIC_NUMBER) { - defiLlamaTokenId = `ethereum:${ETH_MAGIC_NUMBER}`; - } - const queryEnabled = !isTestnetChain(chainId) && !!tokenAddress; const { data } = useQuery({ - queryKey: makeQueryKey("tokenFiatPrice", { defiLlamaTokenId }), + queryKey: makeQueryKey("tokenFiatPrice", { chainId, tokenAddress }), enabled: queryEnabled, queryFn: queryEnabled - ? async () => { - const response = await fetch( - `https://coins.llama.fi/prices/current/${defiLlamaTokenId}`, - ); - const data = await response.json(); - const { price } = data.coins[defiLlamaTokenId]; - return parseFixed(price).bigint; - } + ? async () => + getTokenFiatPrice({ + tokenAddress, + chainId, + }) : undefined, }); return { fiatPrice: data };