import { getToken } from '@lifi/sdk'; import retry from 'async-retry'; import { type Address } from 'viem'; /** * Get token price information from LiFi with caching * @param chainId - The chain ID * @param tokenAddress - The token address * @returns The token price information */ export async function getTokenPrice(chainId: number, tokenAddress: Address): Promise { const tokenInfo = await retry( async (bail) => { try { return await getToken(chainId, tokenAddress); } catch (error) { if (error instanceof Error && error.message.includes('404')) { bail(error); } throw error; } }, { retries: 3, minTimeout: 1000, maxTimeout: 5000, }, ); if (!tokenInfo) { throw new Error(`Token not found for ${tokenAddress} on chain ${chainId}`); } return Number(tokenInfo.priceUSD); }