const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); export const retryOperation = async ( operation: () => Promise, maxRetries: number = 3, delayMs: number = 1000, ): Promise => { let lastError: any; for (let attempt = 1; attempt <= maxRetries; attempt++) { try { return await operation(); } catch (error) { lastError = error; console.error(`Attempt ${attempt} failed:`, error); if (attempt < maxRetries) { await delay(delayMs * attempt); // Exponential backoff continue; } } } throw lastError; }; export const handleFormatValue = ( fromTokenPriceUSD: any, fromTokenDecimals: any, toTokenPriceUSD: any, toTokenDecimals: any, inputAmount: any, outputAmount: any, ) => { const fromValue = fromTokenPriceUSD ? (Number(inputAmount) * Number(fromTokenPriceUSD)) / 10 ** (fromTokenDecimals || 18) : 0; const toValue = toTokenPriceUSD ? (Number(outputAmount) * Number(toTokenPriceUSD)) / 10 ** (toTokenDecimals || 18) : 0; return { fromValue: fromValue || 0, toValue: toValue || 0, }; };