@lifi/sdk 4.0.0-beta.10 → 4.0.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/dist/cjs/actions/getChains.js.map +1 -1
  2. package/dist/cjs/actions/getConnections.js.map +1 -1
  3. package/dist/cjs/actions/getContractCallsQuote.js.map +1 -1
  4. package/dist/cjs/actions/getGasRecommendation.js.map +1 -1
  5. package/dist/cjs/actions/getNameServiceAddress.js.map +1 -1
  6. package/dist/cjs/actions/getQuote.js.map +1 -1
  7. package/dist/cjs/actions/getRelayedTransactionStatus.js.map +1 -1
  8. package/dist/cjs/actions/getRelayerQuote.js.map +1 -1
  9. package/dist/cjs/actions/getRoutes.js.map +1 -1
  10. package/dist/cjs/actions/getStatus.js.map +1 -1
  11. package/dist/cjs/actions/getStepTransaction.js.map +1 -1
  12. package/dist/cjs/actions/getToken.js.map +1 -1
  13. package/dist/cjs/actions/getTokenBalance.js.map +1 -1
  14. package/dist/cjs/actions/getTokenBalances.js.map +1 -1
  15. package/dist/cjs/actions/getTokenBalancesByChain.js.map +1 -1
  16. package/dist/cjs/actions/getTokens.js.map +1 -1
  17. package/dist/cjs/actions/getTools.js.map +1 -1
  18. package/dist/cjs/actions/getTransactionHistory.js.map +1 -1
  19. package/dist/cjs/actions/getWalletBalances.js.map +1 -1
  20. package/dist/cjs/actions/index.js.map +1 -1
  21. package/dist/cjs/actions/patchContractCalls.js.map +1 -1
  22. package/dist/cjs/actions/relayTransaction.js.map +1 -1
  23. package/dist/cjs/client/createClient.js.map +1 -1
  24. package/dist/cjs/client/getClientStorage.js.map +1 -1
  25. package/dist/cjs/core/BaseStepExecutionTask.js.map +1 -1
  26. package/dist/cjs/core/BaseStepExecutor.js.map +1 -1
  27. package/dist/cjs/core/StatusManager.js.map +1 -1
  28. package/dist/cjs/core/TaskPipeline.js.map +1 -1
  29. package/dist/cjs/core/actionMessages.js.map +1 -1
  30. package/dist/cjs/core/execution.js.map +1 -1
  31. package/dist/cjs/core/executionState.js.map +1 -1
  32. package/dist/cjs/core/prepareRestart.js.map +1 -1
  33. package/dist/cjs/core/storage.js.map +1 -1
  34. package/dist/cjs/core/tasks/CheckBalanceTask.js.map +1 -1
  35. package/dist/cjs/core/tasks/PrepareTransactionTask.js.map +1 -1
  36. package/dist/cjs/core/tasks/WaitForTransactionStatusTask.js.map +1 -1
  37. package/dist/cjs/core/tasks/helpers/checkBalance.js +2 -1
  38. package/dist/cjs/core/tasks/helpers/checkBalance.js.map +1 -1
  39. package/dist/cjs/core/tasks/helpers/getTransactionRequestData.js.map +1 -1
  40. package/dist/cjs/core/tasks/helpers/stepComparison.js.map +1 -1
  41. package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.js.map +1 -1
  42. package/dist/cjs/core/utils.js.map +1 -1
  43. package/dist/cjs/errors/SDKError.js.map +1 -1
  44. package/dist/cjs/errors/baseError.js.map +1 -1
  45. package/dist/cjs/errors/constants.js.map +1 -1
  46. package/dist/cjs/errors/errors.js.map +1 -1
  47. package/dist/cjs/errors/httpError.js.map +1 -1
  48. package/dist/cjs/errors/utils/baseErrorRootCause.js.map +1 -1
  49. package/dist/cjs/errors/utils/rootCause.js.map +1 -1
  50. package/dist/cjs/utils/checkPackageUpdates.js +1 -1
  51. package/dist/cjs/utils/checkPackageUpdates.js.map +1 -1
  52. package/dist/cjs/utils/convertQuoteToRoute.js.map +1 -1
  53. package/dist/cjs/utils/decode.js.map +1 -1
  54. package/dist/cjs/utils/fetchTxErrorDetails.js.map +1 -1
  55. package/dist/cjs/utils/formatUnits.js.map +1 -1
  56. package/dist/cjs/utils/getTransactionMessage.js.map +1 -1
  57. package/dist/cjs/utils/isHex.js.map +1 -1
  58. package/dist/cjs/utils/isRoutesRequest.js.map +1 -1
  59. package/dist/cjs/utils/isStep.js.map +1 -1
  60. package/dist/cjs/utils/isToken.js.map +1 -1
  61. package/dist/cjs/utils/parseUnits.js.map +1 -1
  62. package/dist/cjs/utils/request.js.map +1 -1
  63. package/dist/cjs/utils/sleep.js.map +1 -1
  64. package/dist/cjs/utils/waitForResult.js.map +1 -1
  65. package/dist/cjs/utils/withDedupe.js.map +1 -1
  66. package/dist/cjs/utils/withTimeout.js.map +1 -1
  67. package/dist/cjs/version.d.ts +1 -1
  68. package/dist/cjs/version.js +1 -1
  69. package/dist/cjs/version.js.map +1 -1
  70. package/dist/esm/actions/getChains.js.map +1 -1
  71. package/dist/esm/actions/getConnections.js.map +1 -1
  72. package/dist/esm/actions/getContractCallsQuote.js.map +1 -1
  73. package/dist/esm/actions/getGasRecommendation.js.map +1 -1
  74. package/dist/esm/actions/getNameServiceAddress.js.map +1 -1
  75. package/dist/esm/actions/getQuote.js.map +1 -1
  76. package/dist/esm/actions/getRelayedTransactionStatus.js.map +1 -1
  77. package/dist/esm/actions/getRelayerQuote.js.map +1 -1
  78. package/dist/esm/actions/getRoutes.js.map +1 -1
  79. package/dist/esm/actions/getStatus.js.map +1 -1
  80. package/dist/esm/actions/getStepTransaction.js.map +1 -1
  81. package/dist/esm/actions/getToken.js.map +1 -1
  82. package/dist/esm/actions/getTokenBalance.js.map +1 -1
  83. package/dist/esm/actions/getTokenBalances.js.map +1 -1
  84. package/dist/esm/actions/getTokenBalancesByChain.js.map +1 -1
  85. package/dist/esm/actions/getTokens.js.map +1 -1
  86. package/dist/esm/actions/getTools.js.map +1 -1
  87. package/dist/esm/actions/getTransactionHistory.js.map +1 -1
  88. package/dist/esm/actions/getWalletBalances.js.map +1 -1
  89. package/dist/esm/actions/index.js.map +1 -1
  90. package/dist/esm/actions/patchContractCalls.js.map +1 -1
  91. package/dist/esm/actions/relayTransaction.js.map +1 -1
  92. package/dist/esm/client/createClient.js.map +1 -1
  93. package/dist/esm/client/getClientStorage.js.map +1 -1
  94. package/dist/esm/core/BaseStepExecutionTask.js.map +1 -1
  95. package/dist/esm/core/BaseStepExecutor.js.map +1 -1
  96. package/dist/esm/core/StatusManager.d.ts.map +1 -1
  97. package/dist/esm/core/StatusManager.js.map +1 -1
  98. package/dist/esm/core/TaskPipeline.js.map +1 -1
  99. package/dist/esm/core/actionMessages.js.map +1 -1
  100. package/dist/esm/core/execution.d.ts.map +1 -1
  101. package/dist/esm/core/execution.js.map +1 -1
  102. package/dist/esm/core/executionState.js.map +1 -1
  103. package/dist/esm/core/prepareRestart.d.ts.map +1 -1
  104. package/dist/esm/core/prepareRestart.js.map +1 -1
  105. package/dist/esm/core/storage.js.map +1 -1
  106. package/dist/esm/core/tasks/CheckBalanceTask.js.map +1 -1
  107. package/dist/esm/core/tasks/PrepareTransactionTask.js.map +1 -1
  108. package/dist/esm/core/tasks/WaitForTransactionStatusTask.js.map +1 -1
  109. package/dist/esm/core/tasks/helpers/checkBalance.d.ts.map +1 -1
  110. package/dist/esm/core/tasks/helpers/checkBalance.js +2 -1
  111. package/dist/esm/core/tasks/helpers/checkBalance.js.map +1 -1
  112. package/dist/esm/core/tasks/helpers/getTransactionRequestData.js.map +1 -1
  113. package/dist/esm/core/tasks/helpers/stepComparison.js.map +1 -1
  114. package/dist/esm/core/tasks/helpers/waitForTransactionStatus.js.map +1 -1
  115. package/dist/esm/core/utils.js.map +1 -1
  116. package/dist/esm/errors/SDKError.js.map +1 -1
  117. package/dist/esm/errors/baseError.js.map +1 -1
  118. package/dist/esm/errors/constants.js.map +1 -1
  119. package/dist/esm/errors/errors.js.map +1 -1
  120. package/dist/esm/errors/httpError.js.map +1 -1
  121. package/dist/esm/errors/utils/baseErrorRootCause.d.ts.map +1 -1
  122. package/dist/esm/errors/utils/baseErrorRootCause.js.map +1 -1
  123. package/dist/esm/errors/utils/rootCause.js.map +1 -1
  124. package/dist/esm/types/core.d.ts.map +1 -1
  125. package/dist/esm/utils/checkPackageUpdates.js +1 -1
  126. package/dist/esm/utils/checkPackageUpdates.js.map +1 -1
  127. package/dist/esm/utils/convertQuoteToRoute.js.map +1 -1
  128. package/dist/esm/utils/decode.js.map +1 -1
  129. package/dist/esm/utils/fetchTxErrorDetails.js.map +1 -1
  130. package/dist/esm/utils/formatUnits.js.map +1 -1
  131. package/dist/esm/utils/getTransactionMessage.js.map +1 -1
  132. package/dist/esm/utils/isHex.js.map +1 -1
  133. package/dist/esm/utils/isRoutesRequest.js.map +1 -1
  134. package/dist/esm/utils/isStep.js.map +1 -1
  135. package/dist/esm/utils/isToken.js.map +1 -1
  136. package/dist/esm/utils/parseUnits.js.map +1 -1
  137. package/dist/esm/utils/request.js.map +1 -1
  138. package/dist/esm/utils/sleep.js.map +1 -1
  139. package/dist/esm/utils/waitForResult.js.map +1 -1
  140. package/dist/esm/utils/withDedupe.js.map +1 -1
  141. package/dist/esm/utils/withTimeout.js.map +1 -1
  142. package/dist/esm/version.d.ts +1 -1
  143. package/dist/esm/version.js +1 -1
  144. package/dist/esm/version.js.map +1 -1
  145. package/package.json +2 -2
  146. package/src/core/tasks/helpers/checkBalance.ts +6 -1
  147. package/src/version.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"checkPackageUpdates.js","names":[],"sources":["../../../src/utils/checkPackageUpdates.ts"],"sourcesContent":["import { name, version } from '../version.js'\n\nexport const checkPackageUpdates = async (\n packageName?: string,\n packageVersion?: string\n): Promise<void> => {\n try {\n const pkgName = packageName ?? name\n const response = await fetch(`https://registry.npmjs.org/${pkgName}/latest`)\n const reponseBody = await response.json()\n const latestVersion = reponseBody.version\n const currentVersion = packageVersion ?? version\n\n if (latestVersion > currentVersion) {\n console.warn(\n `${pkgName}: new package version is available. Please update as soon as possible to enjoy the newest features. Current version: ${currentVersion}. Latest version: ${latestVersion}.`\n )\n }\n } catch (_error) {\n // Cannot verify version, might be network error etc. We don't bother showing anything in that case\n }\n}\n"],"mappings":";;AAEA,MAAa,sBAAsB,OACjC,aACA,mBACkB;CAClB,IAAI;EACF,MAAM,UAAU,eAAA;EAGhB,MAAM,iBAAgB,OADI,MADH,MAAM,8BAA8B,QAAQ,SAAS,EACzC,MAAM,EACP;EAClC,MAAM,iBAAiB,kBAAA;EAEvB,IAAI,gBAAgB,gBAClB,QAAQ,KACN,GAAG,QAAQ,uHAAuH,eAAe,oBAAoB,cAAc,GACpL;UAEI,QAAQ"}
1
+ {"version":3,"file":"checkPackageUpdates.js","names":[],"sources":["../../../src/utils/checkPackageUpdates.ts"],"sourcesContent":["import { name, version } from '../version.js'\n\nexport const checkPackageUpdates = async (\n packageName?: string,\n packageVersion?: string\n): Promise<void> => {\n try {\n const pkgName = packageName ?? name\n const response = await fetch(`https://registry.npmjs.org/${pkgName}/latest`)\n const reponseBody = await response.json()\n const latestVersion = reponseBody.version\n const currentVersion = packageVersion ?? version\n\n if (latestVersion > currentVersion) {\n console.warn(\n `${pkgName}: new package version is available. Please update as soon as possible to enjoy the newest features. Current version: ${currentVersion}. Latest version: ${latestVersion}.`\n )\n }\n } catch (_error) {\n // Cannot verify version, might be network error etc. We don't bother showing anything in that case\n }\n}\n"],"mappings":";;AAEA,MAAa,sBAAsB,OACjC,aACA,mBACkB;CAClB,IAAI;EACF,MAAM,UAAU,eAAA;EAGhB,MAAM,iBAAgB,OADI,MADH,MAAM,8BAA8B,QAAQ,QAAQ,GACxC,KAAK,GACN;EAClC,MAAM,iBAAiB,kBAAA;EAEvB,IAAI,gBAAgB,gBAClB,QAAQ,KACN,GAAG,QAAQ,uHAAuH,eAAe,oBAAoB,cAAc,EACrL;CAEJ,SAAS,QAAQ,CAEjB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"convertQuoteToRoute.js","names":[],"sources":["../../../src/utils/convertQuoteToRoute.ts"],"sourcesContent":["import type { LiFiStep, Route, Step } from '@lifi/types'\nimport { ValidationError } from '../errors/errors.js'\nimport { SDKError } from '../errors/SDKError.js'\nimport { formatUnits } from './formatUnits.js'\n\ninterface ConvertQuoteToRouteOptions {\n /**\n * When true, if the quote has zero output values (toAmount, toAmountMin, toAmountUSD),\n * use the values from the previous included step that has non-zero output.\n */\n adjustZeroOutputFromPreviousStep?: boolean\n}\n\nconst parseBigInt = (value: string | undefined): bigint => {\n if (!value) {\n return 0n\n }\n try {\n return BigInt(value)\n } catch {\n return 0n\n }\n}\n\nconst parseNumber = (value: string | undefined): number => {\n if (!value) {\n return 0\n }\n const parsed = Number(value)\n return Number.isNaN(parsed) ? 0 : parsed\n}\n\nconst isZeroOutput = (\n toAmount: string,\n toAmountMin: string,\n toAmountUSD?: string\n): boolean => {\n return (\n !parseBigInt(toAmount) &&\n !parseBigInt(toAmountMin) &&\n !parseNumber(toAmountUSD)\n )\n}\n\nconst hasNonZeroOutput = (step: Step): boolean => {\n return (\n !!parseBigInt(step.estimate.toAmount) ||\n !!parseBigInt(step.estimate.toAmountMin)\n )\n}\n\nconst findPreviousNonZeroStep = (steps: Step[]): Step | undefined => {\n // Find the last step that has non-zero output (the step before the zero output step)\n for (let i = steps.length - 1; i >= 0; i--) {\n const step = steps[i]\n if (hasNonZeroOutput(step)) {\n return step\n }\n }\n return undefined\n}\n\nexport function formatTokenPrice(\n amount?: string | bigint,\n price?: string,\n decimals?: number\n): number {\n if (!amount || !price) {\n return 0\n }\n\n const formattedAmount =\n typeof amount === 'bigint' && decimals !== undefined\n ? formatUnits(amount, decimals)\n : amount.toString()\n\n if (Number.isNaN(Number(formattedAmount)) || Number.isNaN(Number(price))) {\n return 0\n }\n return Number.parseFloat(formattedAmount) * Number.parseFloat(price)\n}\n\n/**\n * Converts a quote to Route\n * @param quote - Step returned from the quote endpoint.\n * @param options - Optional configuration for handling edge cases.\n * @returns - The route to be executed.\n * @throws {BaseError} Throws a ValidationError if the step has missing values.\n */\nexport const convertQuoteToRoute = (\n quote: LiFiStep,\n options?: ConvertQuoteToRouteOptions\n): Route => {\n let toAmount = quote.estimate.toAmount\n let toAmountMin = quote.estimate.toAmountMin\n let toAmountUSD = quote.estimate.toAmountUSD\n\n // Handle zero output values by looking at previous included step\n if (\n options?.adjustZeroOutputFromPreviousStep &&\n quote.includedSteps?.length &&\n isZeroOutput(toAmount, toAmountMin, toAmountUSD)\n ) {\n const previousStep = findPreviousNonZeroStep(quote.includedSteps)\n if (previousStep) {\n toAmount = previousStep.estimate.toAmount\n toAmountMin = previousStep.estimate.toAmountMin\n toAmountUSD = formatTokenPrice(\n parseBigInt(toAmount),\n previousStep.action.toToken.priceUSD,\n previousStep.action.toToken.decimals\n ).toFixed(2)\n\n // Update the last included step's estimate with the adjusted values\n const lastStep = quote.includedSteps[quote.includedSteps.length - 1]\n if (lastStep && !hasNonZeroOutput(lastStep)) {\n lastStep.estimate.toAmount = toAmount\n lastStep.estimate.toAmountMin = toAmountMin\n }\n }\n }\n\n if (!quote.estimate.fromAmountUSD) {\n throw new SDKError(\n new ValidationError(\"Missing 'fromAmountUSD' in step estimate.\")\n )\n }\n\n if (!toAmountUSD) {\n throw new SDKError(\n new ValidationError(\"Missing 'toAmountUSD' in step estimate.\")\n )\n }\n\n const route: Route = {\n id: quote.id,\n fromChainId: quote.action.fromToken.chainId,\n fromToken: quote.action.fromToken,\n fromAmount: quote.action.fromAmount,\n fromAmountUSD: quote.estimate.fromAmountUSD,\n fromAddress: quote.action.fromAddress,\n toChainId: quote.action.toToken.chainId,\n toToken: quote.action.toToken,\n toAmount,\n toAmountMin,\n toAmountUSD,\n toAddress: quote.action.toAddress || quote.action.fromAddress,\n gasCostUSD: quote.estimate.gasCosts?.[0]?.amountUSD || '0',\n steps: [quote],\n insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },\n }\n\n return route\n}\n"],"mappings":";;;;AAaA,MAAM,eAAe,UAAsC;CACzD,IAAI,CAAC,OACH,OAAO;CAET,IAAI;EACF,OAAO,OAAO,MAAM;SACd;EACN,OAAO;;;AAIX,MAAM,eAAe,UAAsC;CACzD,IAAI,CAAC,OACH,OAAO;CAET,MAAM,SAAS,OAAO,MAAM;CAC5B,OAAO,OAAO,MAAM,OAAO,GAAG,IAAI;;AAGpC,MAAM,gBACJ,UACA,aACA,gBACY;CACZ,OACE,CAAC,YAAY,SAAS,IACtB,CAAC,YAAY,YAAY,IACzB,CAAC,YAAY,YAAY;;AAI7B,MAAM,oBAAoB,SAAwB;CAChD,OACE,CAAC,CAAC,YAAY,KAAK,SAAS,SAAS,IACrC,CAAC,CAAC,YAAY,KAAK,SAAS,YAAY;;AAI5C,MAAM,2BAA2B,UAAoC;CAEnE,KAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;EAC1C,MAAM,OAAO,MAAM;EACnB,IAAI,iBAAiB,KAAK,EACxB,OAAO;;;AAMb,SAAgB,iBACd,QACA,OACA,UACQ;CACR,IAAI,CAAC,UAAU,CAAC,OACd,OAAO;CAGT,MAAM,kBACJ,OAAO,WAAW,YAAY,aAAa,KAAA,IACvC,YAAY,QAAQ,SAAS,GAC7B,OAAO,UAAU;CAEvB,IAAI,OAAO,MAAM,OAAO,gBAAgB,CAAC,IAAI,OAAO,MAAM,OAAO,MAAM,CAAC,EACtE,OAAO;CAET,OAAO,OAAO,WAAW,gBAAgB,GAAG,OAAO,WAAW,MAAM;;;;;;;;;AAUtE,MAAa,uBACX,OACA,YACU;CACV,IAAI,WAAW,MAAM,SAAS;CAC9B,IAAI,cAAc,MAAM,SAAS;CACjC,IAAI,cAAc,MAAM,SAAS;CAGjC,IACE,SAAS,oCACT,MAAM,eAAe,UACrB,aAAa,UAAU,aAAa,YAAY,EAChD;EACA,MAAM,eAAe,wBAAwB,MAAM,cAAc;EACjE,IAAI,cAAc;GAChB,WAAW,aAAa,SAAS;GACjC,cAAc,aAAa,SAAS;GACpC,cAAc,iBACZ,YAAY,SAAS,EACrB,aAAa,OAAO,QAAQ,UAC5B,aAAa,OAAO,QAAQ,SAC7B,CAAC,QAAQ,EAAE;GAGZ,MAAM,WAAW,MAAM,cAAc,MAAM,cAAc,SAAS;GAClE,IAAI,YAAY,CAAC,iBAAiB,SAAS,EAAE;IAC3C,SAAS,SAAS,WAAW;IAC7B,SAAS,SAAS,cAAc;;;;CAKtC,IAAI,CAAC,MAAM,SAAS,eAClB,MAAM,IAAI,SACR,IAAI,gBAAgB,4CAA4C,CACjE;CAGH,IAAI,CAAC,aACH,MAAM,IAAI,SACR,IAAI,gBAAgB,0CAA0C,CAC/D;CAqBH,OAAO;EAjBL,IAAI,MAAM;EACV,aAAa,MAAM,OAAO,UAAU;EACpC,WAAW,MAAM,OAAO;EACxB,YAAY,MAAM,OAAO;EACzB,eAAe,MAAM,SAAS;EAC9B,aAAa,MAAM,OAAO;EAC1B,WAAW,MAAM,OAAO,QAAQ;EAChC,SAAS,MAAM,OAAO;EACtB;EACA;EACA;EACA,WAAW,MAAM,OAAO,aAAa,MAAM,OAAO;EAClD,YAAY,MAAM,SAAS,WAAW,IAAI,aAAa;EACvD,OAAO,CAAC,MAAM;EACd,WAAW;GAAE,OAAO;GAAiB,cAAc;GAAK;EAG9C"}
1
+ {"version":3,"file":"convertQuoteToRoute.js","names":[],"sources":["../../../src/utils/convertQuoteToRoute.ts"],"sourcesContent":["import type { LiFiStep, Route, Step } from '@lifi/types'\nimport { ValidationError } from '../errors/errors.js'\nimport { SDKError } from '../errors/SDKError.js'\nimport { formatUnits } from './formatUnits.js'\n\ninterface ConvertQuoteToRouteOptions {\n /**\n * When true, if the quote has zero output values (toAmount, toAmountMin, toAmountUSD),\n * use the values from the previous included step that has non-zero output.\n */\n adjustZeroOutputFromPreviousStep?: boolean\n}\n\nconst parseBigInt = (value: string | undefined): bigint => {\n if (!value) {\n return 0n\n }\n try {\n return BigInt(value)\n } catch {\n return 0n\n }\n}\n\nconst parseNumber = (value: string | undefined): number => {\n if (!value) {\n return 0\n }\n const parsed = Number(value)\n return Number.isNaN(parsed) ? 0 : parsed\n}\n\nconst isZeroOutput = (\n toAmount: string,\n toAmountMin: string,\n toAmountUSD?: string\n): boolean => {\n return (\n !parseBigInt(toAmount) &&\n !parseBigInt(toAmountMin) &&\n !parseNumber(toAmountUSD)\n )\n}\n\nconst hasNonZeroOutput = (step: Step): boolean => {\n return (\n !!parseBigInt(step.estimate.toAmount) ||\n !!parseBigInt(step.estimate.toAmountMin)\n )\n}\n\nconst findPreviousNonZeroStep = (steps: Step[]): Step | undefined => {\n // Find the last step that has non-zero output (the step before the zero output step)\n for (let i = steps.length - 1; i >= 0; i--) {\n const step = steps[i]\n if (hasNonZeroOutput(step)) {\n return step\n }\n }\n return undefined\n}\n\nexport function formatTokenPrice(\n amount?: string | bigint,\n price?: string,\n decimals?: number\n): number {\n if (!amount || !price) {\n return 0\n }\n\n const formattedAmount =\n typeof amount === 'bigint' && decimals !== undefined\n ? formatUnits(amount, decimals)\n : amount.toString()\n\n if (Number.isNaN(Number(formattedAmount)) || Number.isNaN(Number(price))) {\n return 0\n }\n return Number.parseFloat(formattedAmount) * Number.parseFloat(price)\n}\n\n/**\n * Converts a quote to Route\n * @param quote - Step returned from the quote endpoint.\n * @param options - Optional configuration for handling edge cases.\n * @returns - The route to be executed.\n * @throws {BaseError} Throws a ValidationError if the step has missing values.\n */\nexport const convertQuoteToRoute = (\n quote: LiFiStep,\n options?: ConvertQuoteToRouteOptions\n): Route => {\n let toAmount = quote.estimate.toAmount\n let toAmountMin = quote.estimate.toAmountMin\n let toAmountUSD = quote.estimate.toAmountUSD\n\n // Handle zero output values by looking at previous included step\n if (\n options?.adjustZeroOutputFromPreviousStep &&\n quote.includedSteps?.length &&\n isZeroOutput(toAmount, toAmountMin, toAmountUSD)\n ) {\n const previousStep = findPreviousNonZeroStep(quote.includedSteps)\n if (previousStep) {\n toAmount = previousStep.estimate.toAmount\n toAmountMin = previousStep.estimate.toAmountMin\n toAmountUSD = formatTokenPrice(\n parseBigInt(toAmount),\n previousStep.action.toToken.priceUSD,\n previousStep.action.toToken.decimals\n ).toFixed(2)\n\n // Update the last included step's estimate with the adjusted values\n const lastStep = quote.includedSteps[quote.includedSteps.length - 1]\n if (lastStep && !hasNonZeroOutput(lastStep)) {\n lastStep.estimate.toAmount = toAmount\n lastStep.estimate.toAmountMin = toAmountMin\n }\n }\n }\n\n if (!quote.estimate.fromAmountUSD) {\n throw new SDKError(\n new ValidationError(\"Missing 'fromAmountUSD' in step estimate.\")\n )\n }\n\n if (!toAmountUSD) {\n throw new SDKError(\n new ValidationError(\"Missing 'toAmountUSD' in step estimate.\")\n )\n }\n\n const route: Route = {\n id: quote.id,\n fromChainId: quote.action.fromToken.chainId,\n fromToken: quote.action.fromToken,\n fromAmount: quote.action.fromAmount,\n fromAmountUSD: quote.estimate.fromAmountUSD,\n fromAddress: quote.action.fromAddress,\n toChainId: quote.action.toToken.chainId,\n toToken: quote.action.toToken,\n toAmount,\n toAmountMin,\n toAmountUSD,\n toAddress: quote.action.toAddress || quote.action.fromAddress,\n gasCostUSD: quote.estimate.gasCosts?.[0]?.amountUSD || '0',\n steps: [quote],\n insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },\n }\n\n return route\n}\n"],"mappings":";;;;AAaA,MAAM,eAAe,UAAsC;CACzD,IAAI,CAAC,OACH,OAAO;CAET,IAAI;EACF,OAAO,OAAO,KAAK;CACrB,QAAQ;EACN,OAAO;CACT;AACF;AAEA,MAAM,eAAe,UAAsC;CACzD,IAAI,CAAC,OACH,OAAO;CAET,MAAM,SAAS,OAAO,KAAK;CAC3B,OAAO,OAAO,MAAM,MAAM,IAAI,IAAI;AACpC;AAEA,MAAM,gBACJ,UACA,aACA,gBACY;CACZ,OACE,CAAC,YAAY,QAAQ,KACrB,CAAC,YAAY,WAAW,KACxB,CAAC,YAAY,WAAW;AAE5B;AAEA,MAAM,oBAAoB,SAAwB;CAChD,OACE,CAAC,CAAC,YAAY,KAAK,SAAS,QAAQ,KACpC,CAAC,CAAC,YAAY,KAAK,SAAS,WAAW;AAE3C;AAEA,MAAM,2BAA2B,UAAoC;CAEnE,KAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;EAC1C,MAAM,OAAO,MAAM;EACnB,IAAI,iBAAiB,IAAI,GACvB,OAAO;CAEX;AAEF;AAEA,SAAgB,iBACd,QACA,OACA,UACQ;CACR,IAAI,CAAC,UAAU,CAAC,OACd,OAAO;CAGT,MAAM,kBACJ,OAAO,WAAW,YAAY,aAAa,KAAA,IACvC,YAAY,QAAQ,QAAQ,IAC5B,OAAO,SAAS;CAEtB,IAAI,OAAO,MAAM,OAAO,eAAe,CAAC,KAAK,OAAO,MAAM,OAAO,KAAK,CAAC,GACrE,OAAO;CAET,OAAO,OAAO,WAAW,eAAe,IAAI,OAAO,WAAW,KAAK;AACrE;;;;;;;;AASA,MAAa,uBACX,OACA,YACU;CACV,IAAI,WAAW,MAAM,SAAS;CAC9B,IAAI,cAAc,MAAM,SAAS;CACjC,IAAI,cAAc,MAAM,SAAS;CAGjC,IACE,SAAS,oCACT,MAAM,eAAe,UACrB,aAAa,UAAU,aAAa,WAAW,GAC/C;EACA,MAAM,eAAe,wBAAwB,MAAM,aAAa;EAChE,IAAI,cAAc;GAChB,WAAW,aAAa,SAAS;GACjC,cAAc,aAAa,SAAS;GACpC,cAAc,iBACZ,YAAY,QAAQ,GACpB,aAAa,OAAO,QAAQ,UAC5B,aAAa,OAAO,QAAQ,QAC9B,EAAE,QAAQ,CAAC;GAGX,MAAM,WAAW,MAAM,cAAc,MAAM,cAAc,SAAS;GAClE,IAAI,YAAY,CAAC,iBAAiB,QAAQ,GAAG;IAC3C,SAAS,SAAS,WAAW;IAC7B,SAAS,SAAS,cAAc;GAClC;EACF;CACF;CAEA,IAAI,CAAC,MAAM,SAAS,eAClB,MAAM,IAAI,SACR,IAAI,gBAAgB,2CAA2C,CACjE;CAGF,IAAI,CAAC,aACH,MAAM,IAAI,SACR,IAAI,gBAAgB,yCAAyC,CAC/D;CAqBF,OAAO;EAjBL,IAAI,MAAM;EACV,aAAa,MAAM,OAAO,UAAU;EACpC,WAAW,MAAM,OAAO;EACxB,YAAY,MAAM,OAAO;EACzB,eAAe,MAAM,SAAS;EAC9B,aAAa,MAAM,OAAO;EAC1B,WAAW,MAAM,OAAO,QAAQ;EAChC,SAAS,MAAM,OAAO;EACtB;EACA;EACA;EACA,WAAW,MAAM,OAAO,aAAa,MAAM,OAAO;EAClD,YAAY,MAAM,SAAS,WAAW,IAAI,aAAa;EACvD,OAAO,CAAC,KAAK;EACb,WAAW;GAAE,OAAO;GAAiB,cAAc;EAAI;CAG9C;AACb"}
@@ -1 +1 @@
1
- {"version":3,"file":"decode.js","names":[],"sources":["../../../src/utils/decode.ts"],"sourcesContent":["export const decodeTaskId = (taskId: string): string[] => {\n const decoded = new TextDecoder()\n .decode(\n new Uint8Array(\n taskId\n .slice(2)\n .match(/.{1,2}/g)\n ?.map((byte) => Number.parseInt(byte, 16)) ?? []\n )\n )\n .split('|')\n return decoded\n}\n"],"mappings":";AAAA,MAAa,gBAAgB,WAA6B;CAWxD,OAVgB,IAAI,aAAa,CAC9B,OACC,IAAI,WACF,OACG,MAAM,EAAE,CACR,MAAM,UAAU,EACf,KAAK,SAAS,OAAO,SAAS,MAAM,GAAG,CAAC,IAAI,EAAE,CACnD,CACF,CACA,MAAM,IACK"}
1
+ {"version":3,"file":"decode.js","names":[],"sources":["../../../src/utils/decode.ts"],"sourcesContent":["export const decodeTaskId = (taskId: string): string[] => {\n const decoded = new TextDecoder()\n .decode(\n new Uint8Array(\n taskId\n .slice(2)\n .match(/.{1,2}/g)\n ?.map((byte) => Number.parseInt(byte, 16)) ?? []\n )\n )\n .split('|')\n return decoded\n}\n"],"mappings":";AAAA,MAAa,gBAAgB,WAA6B;CAWxD,OAVgB,IAAI,YAAY,EAC7B,OACC,IAAI,WACF,OACG,MAAM,CAAC,EACP,MAAM,SAAS,GACd,KAAK,SAAS,OAAO,SAAS,MAAM,EAAE,CAAC,KAAK,CAAC,CACnD,CACF,EACC,MAAM,GACI;AACf"}
@@ -1 +1 @@
1
- {"version":3,"file":"fetchTxErrorDetails.js","names":[],"sources":["../../../src/utils/fetchTxErrorDetails.ts"],"sourcesContent":["export const fetchTxErrorDetails = async (\n txHash: string,\n chainId: number\n): Promise<unknown> => {\n try {\n const response = await fetch(\n `https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`\n )\n const reponseBody = await response.json()\n\n return reponseBody\n } catch (_) {\n return undefined\n }\n}\n"],"mappings":";AAAA,MAAa,sBAAsB,OACjC,QACA,YACqB;CACrB,IAAI;EAMF,OAAO,OAFmB,MAHH,MACrB,kDAAkD,QAAQ,MAAM,SACjE,EACkC,MAAM;UAGlC,GAAG;EACV"}
1
+ {"version":3,"file":"fetchTxErrorDetails.js","names":[],"sources":["../../../src/utils/fetchTxErrorDetails.ts"],"sourcesContent":["export const fetchTxErrorDetails = async (\n txHash: string,\n chainId: number\n): Promise<unknown> => {\n try {\n const response = await fetch(\n `https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`\n )\n const reponseBody = await response.json()\n\n return reponseBody\n } catch (_) {\n return undefined\n }\n}\n"],"mappings":";AAAA,MAAa,sBAAsB,OACjC,QACA,YACqB;CACrB,IAAI;EAMF,OAAO,OAFmB,MAHH,MACrB,kDAAkD,QAAQ,MAAM,QAClE,GACmC,KAAK;CAG1C,SAAS,GAAG;EACV;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"formatUnits.js","names":[],"sources":["../../../src/utils/formatUnits.ts"],"sourcesContent":["/**\n * Divides a number by a given exponent of base 10 (10exponent), and formats it into a string representation of the number.\n */\nexport function formatUnits(value: bigint, decimals: number): string {\n let display = value.toString()\n\n const negative = display.startsWith('-')\n if (negative) {\n display = display.slice(1)\n }\n\n display = display.padStart(decimals, '0')\n\n let [integer, fraction] = [\n display.slice(0, display.length - decimals),\n display.slice(display.length - decimals),\n ]\n fraction = fraction.replace(/(0+)$/, '')\n return `${negative ? '-' : ''}${integer || '0'}${\n fraction ? `.${fraction}` : ''\n }`\n}\n"],"mappings":";;;;AAGA,SAAgB,YAAY,OAAe,UAA0B;CACnE,IAAI,UAAU,MAAM,UAAU;CAE9B,MAAM,WAAW,QAAQ,WAAW,IAAI;CACxC,IAAI,UACF,UAAU,QAAQ,MAAM,EAAE;CAG5B,UAAU,QAAQ,SAAS,UAAU,IAAI;CAEzC,IAAI,CAAC,SAAS,YAAY,CACxB,QAAQ,MAAM,GAAG,QAAQ,SAAS,SAAS,EAC3C,QAAQ,MAAM,QAAQ,SAAS,SAAS,CACzC;CACD,WAAW,SAAS,QAAQ,SAAS,GAAG;CACxC,OAAO,GAAG,WAAW,MAAM,KAAK,WAAW,MACzC,WAAW,IAAI,aAAa"}
1
+ {"version":3,"file":"formatUnits.js","names":[],"sources":["../../../src/utils/formatUnits.ts"],"sourcesContent":["/**\n * Divides a number by a given exponent of base 10 (10exponent), and formats it into a string representation of the number.\n */\nexport function formatUnits(value: bigint, decimals: number): string {\n let display = value.toString()\n\n const negative = display.startsWith('-')\n if (negative) {\n display = display.slice(1)\n }\n\n display = display.padStart(decimals, '0')\n\n let [integer, fraction] = [\n display.slice(0, display.length - decimals),\n display.slice(display.length - decimals),\n ]\n fraction = fraction.replace(/(0+)$/, '')\n return `${negative ? '-' : ''}${integer || '0'}${\n fraction ? `.${fraction}` : ''\n }`\n}\n"],"mappings":";;;;AAGA,SAAgB,YAAY,OAAe,UAA0B;CACnE,IAAI,UAAU,MAAM,SAAS;CAE7B,MAAM,WAAW,QAAQ,WAAW,GAAG;CACvC,IAAI,UACF,UAAU,QAAQ,MAAM,CAAC;CAG3B,UAAU,QAAQ,SAAS,UAAU,GAAG;CAExC,IAAI,CAAC,SAAS,YAAY,CACxB,QAAQ,MAAM,GAAG,QAAQ,SAAS,QAAQ,GAC1C,QAAQ,MAAM,QAAQ,SAAS,QAAQ,CACzC;CACA,WAAW,SAAS,QAAQ,SAAS,EAAE;CACvC,OAAO,GAAG,WAAW,MAAM,KAAK,WAAW,MACzC,WAAW,IAAI,aAAa;AAEhC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getTransactionMessage.js","names":[],"sources":["../../../src/utils/getTransactionMessage.ts"],"sourcesContent":["import type { LiFiStep } from '@lifi/types'\nimport type { SDKClient } from '../types/core.js'\n\nexport const getTransactionFailedMessage = async (\n client: SDKClient,\n step: LiFiStep,\n txLink?: string\n): Promise<string> => {\n const chain = await client.getChainById(step.action.toChainId)\n\n const baseString = `It appears that your transaction may not have been successful.\n However, to confirm this, please check your ${chain.name} wallet for ${step.action.toToken.symbol}.`\n return txLink\n ? `${baseString}\n You can also check the&nbsp;<a href=\"${txLink}\" target=\"_blank\" rel=\"nofollow noreferrer\">block explorer</a> for more information.`\n : baseString\n}\n"],"mappings":";AAGA,MAAa,8BAA8B,OACzC,QACA,MACA,WACoB;CAGpB,MAAM,aAAa;iDAC2B,MAH1B,OAAO,aAAa,KAAK,OAAO,UAAU,EAGV,KAAK,cAAc,KAAK,OAAO,QAAQ,OAAO;CAClG,OAAO,SACH,GAAG,WAAW;2CACuB,OAAO,wFAC5C"}
1
+ {"version":3,"file":"getTransactionMessage.js","names":[],"sources":["../../../src/utils/getTransactionMessage.ts"],"sourcesContent":["import type { LiFiStep } from '@lifi/types'\nimport type { SDKClient } from '../types/core.js'\n\nexport const getTransactionFailedMessage = async (\n client: SDKClient,\n step: LiFiStep,\n txLink?: string\n): Promise<string> => {\n const chain = await client.getChainById(step.action.toChainId)\n\n const baseString = `It appears that your transaction may not have been successful.\n However, to confirm this, please check your ${chain.name} wallet for ${step.action.toToken.symbol}.`\n return txLink\n ? `${baseString}\n You can also check the&nbsp;<a href=\"${txLink}\" target=\"_blank\" rel=\"nofollow noreferrer\">block explorer</a> for more information.`\n : baseString\n}\n"],"mappings":";AAGA,MAAa,8BAA8B,OACzC,QACA,MACA,WACoB;CAGpB,MAAM,aAAa;iDAC2B,MAH1B,OAAO,aAAa,KAAK,OAAO,SAAS,GAGT,KAAK,cAAc,KAAK,OAAO,QAAQ,OAAO;CAClG,OAAO,SACH,GAAG,WAAW;2CACuB,OAAO,wFAC5C;AACN"}
@@ -1 +1 @@
1
- {"version":3,"file":"isHex.js","names":[],"sources":["../../../src/utils/isHex.ts"],"sourcesContent":["export type Hex = `0x${string}`\n\nexport function isHex(\n value: unknown,\n { strict = true }: { strict?: boolean | undefined } = {}\n): value is Hex {\n if (!value) {\n return false\n }\n if (typeof value !== 'string') {\n return false\n }\n return strict ? /^0x[0-9a-fA-F]*$/.test(value) : value.startsWith('0x')\n}\n"],"mappings":";AAEA,SAAgB,MACd,OACA,EAAE,SAAS,SAA2C,EAAE,EAC1C;CACd,IAAI,CAAC,OACH,OAAO;CAET,IAAI,OAAO,UAAU,UACnB,OAAO;CAET,OAAO,SAAS,mBAAmB,KAAK,MAAM,GAAG,MAAM,WAAW,KAAK"}
1
+ {"version":3,"file":"isHex.js","names":[],"sources":["../../../src/utils/isHex.ts"],"sourcesContent":["export type Hex = `0x${string}`\n\nexport function isHex(\n value: unknown,\n { strict = true }: { strict?: boolean | undefined } = {}\n): value is Hex {\n if (!value) {\n return false\n }\n if (typeof value !== 'string') {\n return false\n }\n return strict ? /^0x[0-9a-fA-F]*$/.test(value) : value.startsWith('0x')\n}\n"],"mappings":";AAEA,SAAgB,MACd,OACA,EAAE,SAAS,SAA2C,CAAC,GACzC;CACd,IAAI,CAAC,OACH,OAAO;CAET,IAAI,OAAO,UAAU,UACnB,OAAO;CAET,OAAO,SAAS,mBAAmB,KAAK,KAAK,IAAI,MAAM,WAAW,IAAI;AACxE"}
@@ -1 +1 @@
1
- {"version":3,"file":"isRoutesRequest.js","names":[],"sources":["../../../src/utils/isRoutesRequest.ts"],"sourcesContent":["import type { RouteOptions, RoutesRequest } from '@lifi/types'\n\nconst isRoutesOptions = (\n routeOptions: RouteOptions\n): routeOptions is RouteOptions =>\n !routeOptions?.slippage || typeof routeOptions.slippage === 'number'\n\nexport const isRoutesRequest = (\n routesRequest: RoutesRequest\n): routesRequest is RoutesRequest => {\n const {\n fromChainId,\n fromAmount,\n fromTokenAddress,\n toChainId,\n toTokenAddress,\n options,\n } = routesRequest\n\n return (\n typeof fromChainId === 'number' &&\n typeof fromAmount === 'string' &&\n fromAmount !== '' &&\n typeof fromTokenAddress === 'string' &&\n fromTokenAddress !== '' &&\n typeof toChainId === 'number' &&\n typeof toTokenAddress === 'string' &&\n toTokenAddress !== '' &&\n (!options || isRoutesOptions(options))\n )\n}\n"],"mappings":";AAEA,MAAM,mBACJ,iBAEA,CAAC,cAAc,YAAY,OAAO,aAAa,aAAa;AAE9D,MAAa,mBACX,kBACmC;CACnC,MAAM,EACJ,aACA,YACA,kBACA,WACA,gBACA,YACE;CAEJ,OACE,OAAO,gBAAgB,YACvB,OAAO,eAAe,YACtB,eAAe,MACf,OAAO,qBAAqB,YAC5B,qBAAqB,MACrB,OAAO,cAAc,YACrB,OAAO,mBAAmB,YAC1B,mBAAmB,OAClB,CAAC,WAAW,gBAAgB,QAAQ"}
1
+ {"version":3,"file":"isRoutesRequest.js","names":[],"sources":["../../../src/utils/isRoutesRequest.ts"],"sourcesContent":["import type { RouteOptions, RoutesRequest } from '@lifi/types'\n\nconst isRoutesOptions = (\n routeOptions: RouteOptions\n): routeOptions is RouteOptions =>\n !routeOptions?.slippage || typeof routeOptions.slippage === 'number'\n\nexport const isRoutesRequest = (\n routesRequest: RoutesRequest\n): routesRequest is RoutesRequest => {\n const {\n fromChainId,\n fromAmount,\n fromTokenAddress,\n toChainId,\n toTokenAddress,\n options,\n } = routesRequest\n\n return (\n typeof fromChainId === 'number' &&\n typeof fromAmount === 'string' &&\n fromAmount !== '' &&\n typeof fromTokenAddress === 'string' &&\n fromTokenAddress !== '' &&\n typeof toChainId === 'number' &&\n typeof toTokenAddress === 'string' &&\n toTokenAddress !== '' &&\n (!options || isRoutesOptions(options))\n )\n}\n"],"mappings":";AAEA,MAAM,mBACJ,iBAEA,CAAC,cAAc,YAAY,OAAO,aAAa,aAAa;AAE9D,MAAa,mBACX,kBACmC;CACnC,MAAM,EACJ,aACA,YACA,kBACA,WACA,gBACA,YACE;CAEJ,OACE,OAAO,gBAAgB,YACvB,OAAO,eAAe,YACtB,eAAe,MACf,OAAO,qBAAqB,YAC5B,qBAAqB,MACrB,OAAO,cAAc,YACrB,OAAO,mBAAmB,YAC1B,mBAAmB,OAClB,CAAC,WAAW,gBAAgB,OAAO;AAExC"}
@@ -1 +1 @@
1
- {"version":3,"file":"isStep.js","names":[],"sources":["../../../src/utils/isStep.ts"],"sourcesContent":["import type { Action, Estimate, LiFiStep } from '@lifi/types'\nimport { isToken } from './isToken.js'\n\nconst isAction = (action: Action): action is Action => {\n const { fromChainId, fromAmount, fromToken, toChainId, toToken } = action\n\n return (\n typeof fromChainId === 'number' &&\n typeof fromAmount === 'string' &&\n fromAmount !== '' &&\n isToken(fromToken) &&\n typeof toChainId === 'number' &&\n isToken(toToken)\n )\n}\n\nconst isEstimate = (estimate: Estimate): estimate is Estimate => {\n const { fromAmount, toAmount, toAmountMin, approvalAddress } = estimate\n\n return (\n typeof fromAmount === 'string' &&\n fromAmount !== '' &&\n typeof toAmount === 'string' &&\n toAmount !== '' &&\n typeof toAmountMin === 'string' &&\n toAmountMin !== '' &&\n (typeof approvalAddress === 'string' || approvalAddress === null)\n )\n}\n\nexport const isStep = (step: LiFiStep): step is LiFiStep => {\n const { id, type, tool, action, estimate } = step\n\n return (\n typeof id === 'string' &&\n ['swap', 'cross', 'lifi'].includes(type) &&\n typeof tool === 'string' &&\n isAction(action) &&\n isEstimate(estimate)\n )\n}\n"],"mappings":";;AAGA,MAAM,YAAY,WAAqC;CACrD,MAAM,EAAE,aAAa,YAAY,WAAW,WAAW,YAAY;CAEnE,OACE,OAAO,gBAAgB,YACvB,OAAO,eAAe,YACtB,eAAe,MACf,QAAQ,UAAU,IAClB,OAAO,cAAc,YACrB,QAAQ,QAAQ;;AAIpB,MAAM,cAAc,aAA6C;CAC/D,MAAM,EAAE,YAAY,UAAU,aAAa,oBAAoB;CAE/D,OACE,OAAO,eAAe,YACtB,eAAe,MACf,OAAO,aAAa,YACpB,aAAa,MACb,OAAO,gBAAgB,YACvB,gBAAgB,OACf,OAAO,oBAAoB,YAAY,oBAAoB;;AAIhE,MAAa,UAAU,SAAqC;CAC1D,MAAM,EAAE,IAAI,MAAM,MAAM,QAAQ,aAAa;CAE7C,OACE,OAAO,OAAO,YACd;EAAC;EAAQ;EAAS;EAAO,CAAC,SAAS,KAAK,IACxC,OAAO,SAAS,YAChB,SAAS,OAAO,IAChB,WAAW,SAAS"}
1
+ {"version":3,"file":"isStep.js","names":[],"sources":["../../../src/utils/isStep.ts"],"sourcesContent":["import type { Action, Estimate, LiFiStep } from '@lifi/types'\nimport { isToken } from './isToken.js'\n\nconst isAction = (action: Action): action is Action => {\n const { fromChainId, fromAmount, fromToken, toChainId, toToken } = action\n\n return (\n typeof fromChainId === 'number' &&\n typeof fromAmount === 'string' &&\n fromAmount !== '' &&\n isToken(fromToken) &&\n typeof toChainId === 'number' &&\n isToken(toToken)\n )\n}\n\nconst isEstimate = (estimate: Estimate): estimate is Estimate => {\n const { fromAmount, toAmount, toAmountMin, approvalAddress } = estimate\n\n return (\n typeof fromAmount === 'string' &&\n fromAmount !== '' &&\n typeof toAmount === 'string' &&\n toAmount !== '' &&\n typeof toAmountMin === 'string' &&\n toAmountMin !== '' &&\n (typeof approvalAddress === 'string' || approvalAddress === null)\n )\n}\n\nexport const isStep = (step: LiFiStep): step is LiFiStep => {\n const { id, type, tool, action, estimate } = step\n\n return (\n typeof id === 'string' &&\n ['swap', 'cross', 'lifi'].includes(type) &&\n typeof tool === 'string' &&\n isAction(action) &&\n isEstimate(estimate)\n )\n}\n"],"mappings":";;AAGA,MAAM,YAAY,WAAqC;CACrD,MAAM,EAAE,aAAa,YAAY,WAAW,WAAW,YAAY;CAEnE,OACE,OAAO,gBAAgB,YACvB,OAAO,eAAe,YACtB,eAAe,MACf,QAAQ,SAAS,KACjB,OAAO,cAAc,YACrB,QAAQ,OAAO;AAEnB;AAEA,MAAM,cAAc,aAA6C;CAC/D,MAAM,EAAE,YAAY,UAAU,aAAa,oBAAoB;CAE/D,OACE,OAAO,eAAe,YACtB,eAAe,MACf,OAAO,aAAa,YACpB,aAAa,MACb,OAAO,gBAAgB,YACvB,gBAAgB,OACf,OAAO,oBAAoB,YAAY,oBAAoB;AAEhE;AAEA,MAAa,UAAU,SAAqC;CAC1D,MAAM,EAAE,IAAI,MAAM,MAAM,QAAQ,aAAa;CAE7C,OACE,OAAO,OAAO,YACd;EAAC;EAAQ;EAAS;CAAM,EAAE,SAAS,IAAI,KACvC,OAAO,SAAS,YAChB,SAAS,MAAM,KACf,WAAW,QAAQ;AAEvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"isToken.js","names":[],"sources":["../../../src/utils/isToken.ts"],"sourcesContent":["import type { StaticToken } from '@lifi/types'\n\nexport const isToken = (token: StaticToken): token is StaticToken => {\n const { address, decimals, chainId } = token\n\n return (\n typeof address === 'string' &&\n typeof decimals === 'number' &&\n typeof chainId === 'number'\n )\n}\n"],"mappings":";AAEA,MAAa,WAAW,UAA6C;CACnE,MAAM,EAAE,SAAS,UAAU,YAAY;CAEvC,OACE,OAAO,YAAY,YACnB,OAAO,aAAa,YACpB,OAAO,YAAY"}
1
+ {"version":3,"file":"isToken.js","names":[],"sources":["../../../src/utils/isToken.ts"],"sourcesContent":["import type { StaticToken } from '@lifi/types'\n\nexport const isToken = (token: StaticToken): token is StaticToken => {\n const { address, decimals, chainId } = token\n\n return (\n typeof address === 'string' &&\n typeof decimals === 'number' &&\n typeof chainId === 'number'\n )\n}\n"],"mappings":";AAEA,MAAa,WAAW,UAA6C;CACnE,MAAM,EAAE,SAAS,UAAU,YAAY;CAEvC,OACE,OAAO,YAAY,YACnB,OAAO,aAAa,YACpB,OAAO,YAAY;AAEvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"parseUnits.js","names":[],"sources":["../../../src/utils/parseUnits.ts"],"sourcesContent":["/**\n * Multiplies a string representation of a number by a given exponent of base 10 (10exponent).\n */\nexport function parseUnits(value: string, decimals: number): bigint {\n if (!/^(-?)([0-9]*)\\.?([0-9]*)$/.test(value)) {\n throw new Error(`Number \\`${value}\\` is not a valid decimal number.`)\n }\n\n let [integer, fraction = '0'] = value.split('.')\n\n const negative = integer.startsWith('-')\n if (negative) {\n integer = integer.slice(1)\n }\n\n // trim trailing zeros.\n fraction = fraction.replace(/(0+)$/, '')\n\n // round off if the fraction is larger than the number of decimals.\n if (decimals === 0) {\n if (Math.round(Number(`.${fraction}`)) === 1) {\n integer = `${BigInt(integer) + 1n}`\n }\n fraction = ''\n } else if (fraction.length > decimals) {\n const [left, unit, right] = [\n fraction.slice(0, decimals - 1),\n fraction.slice(decimals - 1, decimals),\n fraction.slice(decimals),\n ]\n\n const rounded = Math.round(Number(`${unit}.${right}`))\n if (rounded > 9) {\n fraction = `${BigInt(left) + BigInt(1)}0`.padStart(left.length + 1, '0')\n } else {\n fraction = `${left}${rounded}`\n }\n\n if (fraction.length > decimals) {\n fraction = fraction.slice(1)\n integer = `${BigInt(integer) + 1n}`\n }\n\n fraction = fraction.slice(0, decimals)\n } else {\n fraction = fraction.padEnd(decimals, '0')\n }\n\n return BigInt(`${negative ? '-' : ''}${integer}${fraction}`)\n}\n"],"mappings":";;;;AAGA,SAAgB,WAAW,OAAe,UAA0B;CAClE,IAAI,CAAC,4BAA4B,KAAK,MAAM,EAC1C,MAAM,IAAI,MAAM,YAAY,MAAM,mCAAmC;CAGvE,IAAI,CAAC,SAAS,WAAW,OAAO,MAAM,MAAM,IAAI;CAEhD,MAAM,WAAW,QAAQ,WAAW,IAAI;CACxC,IAAI,UACF,UAAU,QAAQ,MAAM,EAAE;CAI5B,WAAW,SAAS,QAAQ,SAAS,GAAG;CAGxC,IAAI,aAAa,GAAG;EAClB,IAAI,KAAK,MAAM,OAAO,IAAI,WAAW,CAAC,KAAK,GACzC,UAAU,GAAG,OAAO,QAAQ,GAAG;EAEjC,WAAW;QACN,IAAI,SAAS,SAAS,UAAU;EACrC,MAAM,CAAC,MAAM,MAAM,SAAS;GAC1B,SAAS,MAAM,GAAG,WAAW,EAAE;GAC/B,SAAS,MAAM,WAAW,GAAG,SAAS;GACtC,SAAS,MAAM,SAAS;GACzB;EAED,MAAM,UAAU,KAAK,MAAM,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC;EACtD,IAAI,UAAU,GACZ,WAAW,GAAG,OAAO,KAAK,GAAG,OAAO,EAAE,CAAC,GAAG,SAAS,KAAK,SAAS,GAAG,IAAI;OAExE,WAAW,GAAG,OAAO;EAGvB,IAAI,SAAS,SAAS,UAAU;GAC9B,WAAW,SAAS,MAAM,EAAE;GAC5B,UAAU,GAAG,OAAO,QAAQ,GAAG;;EAGjC,WAAW,SAAS,MAAM,GAAG,SAAS;QAEtC,WAAW,SAAS,OAAO,UAAU,IAAI;CAG3C,OAAO,OAAO,GAAG,WAAW,MAAM,KAAK,UAAU,WAAW"}
1
+ {"version":3,"file":"parseUnits.js","names":[],"sources":["../../../src/utils/parseUnits.ts"],"sourcesContent":["/**\n * Multiplies a string representation of a number by a given exponent of base 10 (10exponent).\n */\nexport function parseUnits(value: string, decimals: number): bigint {\n if (!/^(-?)([0-9]*)\\.?([0-9]*)$/.test(value)) {\n throw new Error(`Number \\`${value}\\` is not a valid decimal number.`)\n }\n\n let [integer, fraction = '0'] = value.split('.')\n\n const negative = integer.startsWith('-')\n if (negative) {\n integer = integer.slice(1)\n }\n\n // trim trailing zeros.\n fraction = fraction.replace(/(0+)$/, '')\n\n // round off if the fraction is larger than the number of decimals.\n if (decimals === 0) {\n if (Math.round(Number(`.${fraction}`)) === 1) {\n integer = `${BigInt(integer) + 1n}`\n }\n fraction = ''\n } else if (fraction.length > decimals) {\n const [left, unit, right] = [\n fraction.slice(0, decimals - 1),\n fraction.slice(decimals - 1, decimals),\n fraction.slice(decimals),\n ]\n\n const rounded = Math.round(Number(`${unit}.${right}`))\n if (rounded > 9) {\n fraction = `${BigInt(left) + BigInt(1)}0`.padStart(left.length + 1, '0')\n } else {\n fraction = `${left}${rounded}`\n }\n\n if (fraction.length > decimals) {\n fraction = fraction.slice(1)\n integer = `${BigInt(integer) + 1n}`\n }\n\n fraction = fraction.slice(0, decimals)\n } else {\n fraction = fraction.padEnd(decimals, '0')\n }\n\n return BigInt(`${negative ? '-' : ''}${integer}${fraction}`)\n}\n"],"mappings":";;;;AAGA,SAAgB,WAAW,OAAe,UAA0B;CAClE,IAAI,CAAC,4BAA4B,KAAK,KAAK,GACzC,MAAM,IAAI,MAAM,YAAY,MAAM,kCAAkC;CAGtE,IAAI,CAAC,SAAS,WAAW,OAAO,MAAM,MAAM,GAAG;CAE/C,MAAM,WAAW,QAAQ,WAAW,GAAG;CACvC,IAAI,UACF,UAAU,QAAQ,MAAM,CAAC;CAI3B,WAAW,SAAS,QAAQ,SAAS,EAAE;CAGvC,IAAI,aAAa,GAAG;EAClB,IAAI,KAAK,MAAM,OAAO,IAAI,UAAU,CAAC,MAAM,GACzC,UAAU,GAAG,OAAO,OAAO,IAAI;EAEjC,WAAW;CACb,OAAO,IAAI,SAAS,SAAS,UAAU;EACrC,MAAM,CAAC,MAAM,MAAM,SAAS;GAC1B,SAAS,MAAM,GAAG,WAAW,CAAC;GAC9B,SAAS,MAAM,WAAW,GAAG,QAAQ;GACrC,SAAS,MAAM,QAAQ;EACzB;EAEA,MAAM,UAAU,KAAK,MAAM,OAAO,GAAG,KAAK,GAAG,OAAO,CAAC;EACrD,IAAI,UAAU,GACZ,WAAW,GAAG,OAAO,IAAI,IAAI,OAAO,CAAC,EAAE,GAAG,SAAS,KAAK,SAAS,GAAG,GAAG;OAEvE,WAAW,GAAG,OAAO;EAGvB,IAAI,SAAS,SAAS,UAAU;GAC9B,WAAW,SAAS,MAAM,CAAC;GAC3B,UAAU,GAAG,OAAO,OAAO,IAAI;EACjC;EAEA,WAAW,SAAS,MAAM,GAAG,QAAQ;CACvC,OACE,WAAW,SAAS,OAAO,UAAU,GAAG;CAG1C,OAAO,OAAO,GAAG,WAAW,MAAM,KAAK,UAAU,UAAU;AAC7D"}
@@ -1 +1 @@
1
- {"version":3,"file":"request.js","names":[],"sources":["../../../src/utils/request.ts"],"sourcesContent":["import { ValidationError } from '../errors/errors.js'\nimport { HTTPError } from '../errors/httpError.js'\nimport { SDKError } from '../errors/SDKError.js'\nimport type { SDKBaseConfig } from '../types/core.js'\nimport type { ExtendedRequestInit } from '../types/request.js'\nimport { version } from '../version.js'\nimport { sleep } from './sleep.js'\n\nexport const requestSettings = {\n retries: 1,\n}\n\nconst stripExtendRequestInitProperties = ({\n retries,\n ...rest\n}: ExtendedRequestInit): RequestInit => ({\n ...rest,\n})\n\nexport const request = async <T = Response>(\n config: SDKBaseConfig,\n url: RequestInfo | URL,\n options: ExtendedRequestInit = {\n retries: requestSettings.retries,\n }\n): Promise<T> => {\n const { userId, integrator, widgetVersion, apiKey, requestInterceptor } =\n config\n\n if (!integrator) {\n throw new SDKError(\n new ValidationError(\n 'You need to provide the Integrator property. Please see documentation https://docs.li.fi/integrate-li.fi-js-sdk/set-up-the-sdk'\n )\n )\n }\n\n options.retries = options.retries ?? requestSettings.retries\n\n try {\n if (apiKey) {\n options.headers = {\n ...options.headers,\n 'x-lifi-api-key': apiKey,\n }\n }\n\n if (userId) {\n options.headers = {\n ...options.headers,\n 'x-lifi-userid': userId,\n }\n }\n\n if (widgetVersion) {\n options.headers = {\n ...options.headers,\n 'x-lifi-widget': widgetVersion,\n }\n }\n\n if (version) {\n options.headers = {\n ...options.headers,\n 'x-lifi-sdk': version,\n }\n }\n\n // integrator is mandatory during SDK initialization\n options.headers = {\n ...options.headers,\n 'x-lifi-integrator': integrator,\n }\n\n if (requestInterceptor) {\n options = await requestInterceptor(options)\n }\n\n const response: Response = await fetch(\n url,\n stripExtendRequestInitProperties(options)\n )\n\n if (!response.ok) {\n throw new HTTPError(response, url, options)\n }\n\n return await response.json()\n } catch (error) {\n const retries = options.retries ?? 0\n if (retries > 0 && (error as HTTPError).status === 500) {\n await sleep(500)\n return request<T>(config, url, { ...options, retries: retries - 1 })\n }\n\n await (error as HTTPError).buildAdditionalDetails?.()\n\n throw new SDKError(error as HTTPError)\n }\n}\n"],"mappings":";;;;;;AAQA,MAAa,kBAAkB,EAC7B,SAAS,GACV;AAED,MAAM,oCAAoC,EACxC,SACA,GAAG,YACoC,EACvC,GAAG,MACJ;AAED,MAAa,UAAU,OACrB,QACA,KACA,UAA+B,EAC7B,SAAS,gBAAgB,SAC1B,KACc;CACf,MAAM,EAAE,QAAQ,YAAY,eAAe,QAAQ,uBACjD;CAEF,IAAI,CAAC,YACH,MAAM,IAAI,SACR,IAAI,gBACF,iIACD,CACF;CAGH,QAAQ,UAAU,QAAQ,WAAW,gBAAgB;CAErD,IAAI;EACF,IAAI,QACF,QAAQ,UAAU;GAChB,GAAG,QAAQ;GACX,kBAAkB;GACnB;EAGH,IAAI,QACF,QAAQ,UAAU;GAChB,GAAG,QAAQ;GACX,iBAAiB;GAClB;EAGH,IAAI,eACF,QAAQ,UAAU;GAChB,GAAG,QAAQ;GACX,iBAAiB;GAClB;EAID,QAAQ,UAAU;GAChB,GAAG,QAAQ;GACX,cAAc;GACf;EAIH,QAAQ,UAAU;GAChB,GAAG,QAAQ;GACX,qBAAqB;GACtB;EAED,IAAI,oBACF,UAAU,MAAM,mBAAmB,QAAQ;EAG7C,MAAM,WAAqB,MAAM,MAC/B,KACA,iCAAiC,QAAQ,CAC1C;EAED,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,UAAU,UAAU,KAAK,QAAQ;EAG7C,OAAO,MAAM,SAAS,MAAM;UACrB,OAAO;EACd,MAAM,UAAU,QAAQ,WAAW;EACnC,IAAI,UAAU,KAAM,MAAoB,WAAW,KAAK;GACtD,MAAM,MAAM,IAAI;GAChB,OAAO,QAAW,QAAQ,KAAK;IAAE,GAAG;IAAS,SAAS,UAAU;IAAG,CAAC;;EAGtE,MAAO,MAAoB,0BAA0B;EAErD,MAAM,IAAI,SAAS,MAAmB"}
1
+ {"version":3,"file":"request.js","names":[],"sources":["../../../src/utils/request.ts"],"sourcesContent":["import { ValidationError } from '../errors/errors.js'\nimport { HTTPError } from '../errors/httpError.js'\nimport { SDKError } from '../errors/SDKError.js'\nimport type { SDKBaseConfig } from '../types/core.js'\nimport type { ExtendedRequestInit } from '../types/request.js'\nimport { version } from '../version.js'\nimport { sleep } from './sleep.js'\n\nexport const requestSettings = {\n retries: 1,\n}\n\nconst stripExtendRequestInitProperties = ({\n retries,\n ...rest\n}: ExtendedRequestInit): RequestInit => ({\n ...rest,\n})\n\nexport const request = async <T = Response>(\n config: SDKBaseConfig,\n url: RequestInfo | URL,\n options: ExtendedRequestInit = {\n retries: requestSettings.retries,\n }\n): Promise<T> => {\n const { userId, integrator, widgetVersion, apiKey, requestInterceptor } =\n config\n\n if (!integrator) {\n throw new SDKError(\n new ValidationError(\n 'You need to provide the Integrator property. Please see documentation https://docs.li.fi/integrate-li.fi-js-sdk/set-up-the-sdk'\n )\n )\n }\n\n options.retries = options.retries ?? requestSettings.retries\n\n try {\n if (apiKey) {\n options.headers = {\n ...options.headers,\n 'x-lifi-api-key': apiKey,\n }\n }\n\n if (userId) {\n options.headers = {\n ...options.headers,\n 'x-lifi-userid': userId,\n }\n }\n\n if (widgetVersion) {\n options.headers = {\n ...options.headers,\n 'x-lifi-widget': widgetVersion,\n }\n }\n\n if (version) {\n options.headers = {\n ...options.headers,\n 'x-lifi-sdk': version,\n }\n }\n\n // integrator is mandatory during SDK initialization\n options.headers = {\n ...options.headers,\n 'x-lifi-integrator': integrator,\n }\n\n if (requestInterceptor) {\n options = await requestInterceptor(options)\n }\n\n const response: Response = await fetch(\n url,\n stripExtendRequestInitProperties(options)\n )\n\n if (!response.ok) {\n throw new HTTPError(response, url, options)\n }\n\n return await response.json()\n } catch (error) {\n const retries = options.retries ?? 0\n if (retries > 0 && (error as HTTPError).status === 500) {\n await sleep(500)\n return request<T>(config, url, { ...options, retries: retries - 1 })\n }\n\n await (error as HTTPError).buildAdditionalDetails?.()\n\n throw new SDKError(error as HTTPError)\n }\n}\n"],"mappings":";;;;;;AAQA,MAAa,kBAAkB,EAC7B,SAAS,EACX;AAEA,MAAM,oCAAoC,EACxC,SACA,GAAG,YACoC,EACvC,GAAG,KACL;AAEA,MAAa,UAAU,OACrB,QACA,KACA,UAA+B,EAC7B,SAAS,gBAAgB,QAC3B,MACe;CACf,MAAM,EAAE,QAAQ,YAAY,eAAe,QAAQ,uBACjD;CAEF,IAAI,CAAC,YACH,MAAM,IAAI,SACR,IAAI,gBACF,gIACF,CACF;CAGF,QAAQ,UAAU,QAAQ,WAAW,gBAAgB;CAErD,IAAI;EACF,IAAI,QACF,QAAQ,UAAU;GAChB,GAAG,QAAQ;GACX,kBAAkB;EACpB;EAGF,IAAI,QACF,QAAQ,UAAU;GAChB,GAAG,QAAQ;GACX,iBAAiB;EACnB;EAGF,IAAI,eACF,QAAQ,UAAU;GAChB,GAAG,QAAQ;GACX,iBAAiB;EACnB;EAIA,QAAQ,UAAU;GAChB,GAAG,QAAQ;GACX,cAAc;EAChB;EAIF,QAAQ,UAAU;GAChB,GAAG,QAAQ;GACX,qBAAqB;EACvB;EAEA,IAAI,oBACF,UAAU,MAAM,mBAAmB,OAAO;EAG5C,MAAM,WAAqB,MAAM,MAC/B,KACA,iCAAiC,OAAO,CAC1C;EAEA,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,UAAU,UAAU,KAAK,OAAO;EAG5C,OAAO,MAAM,SAAS,KAAK;CAC7B,SAAS,OAAO;EACd,MAAM,UAAU,QAAQ,WAAW;EACnC,IAAI,UAAU,KAAM,MAAoB,WAAW,KAAK;GACtD,MAAM,MAAM,GAAG;GACf,OAAO,QAAW,QAAQ,KAAK;IAAE,GAAG;IAAS,SAAS,UAAU;GAAE,CAAC;EACrE;EAEA,MAAO,MAAoB,yBAAyB;EAEpD,MAAM,IAAI,SAAS,KAAkB;CACvC;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"sleep.js","names":[],"sources":["../../../src/utils/sleep.ts"],"sourcesContent":["export function sleep(ms: number): Promise<null> {\n return new Promise((resolve) => {\n setTimeout(() => resolve(null), ms)\n })\n}\n"],"mappings":";AAAA,SAAgB,MAAM,IAA2B;CAC/C,OAAO,IAAI,SAAS,YAAY;EAC9B,iBAAiB,QAAQ,KAAK,EAAE,GAAG;GACnC"}
1
+ {"version":3,"file":"sleep.js","names":[],"sources":["../../../src/utils/sleep.ts"],"sourcesContent":["export function sleep(ms: number): Promise<null> {\n return new Promise((resolve) => {\n setTimeout(() => resolve(null), ms)\n })\n}\n"],"mappings":";AAAA,SAAgB,MAAM,IAA2B;CAC/C,OAAO,IAAI,SAAS,YAAY;EAC9B,iBAAiB,QAAQ,IAAI,GAAG,EAAE;CACpC,CAAC;AACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"waitForResult.js","names":[],"sources":["../../../src/utils/waitForResult.ts"],"sourcesContent":["import { sleep } from './sleep.js'\n\n/**\n * Repeatedly calls a given asynchronous function until it resolves with a value\n * @param fn The function that should be repeated\n * @param interval The timeout in milliseconds between retries, or a function that receives the current poll count and returns the interval. Defaults to 5000\n * @param maxRetries Maximum number of retries before throwing an error, defaults to 3\n * @param shouldRetry Optional predicate to determine if an error should trigger a retry\n * @returns The result of the fn function\n * @throws Error if maximum retries is reached, if function keeps returning undefined, or if shouldRetry returns false\n */\nexport const waitForResult = async <T>(\n fn: () => Promise<T | undefined>,\n interval: number | ((poll: number) => number) = 5000,\n maxRetries = 3,\n shouldRetry: (count: number, error: unknown) => boolean = () => true\n): Promise<T> => {\n let result: T | undefined\n let attempts = 0\n let polls = 0\n\n const getInterval = typeof interval === 'function' ? interval : () => interval\n\n while (!result) {\n try {\n result = await fn()\n if (!result) {\n await sleep(getInterval(polls))\n polls++\n }\n } catch (error) {\n if (!shouldRetry(attempts, error)) {\n throw error\n }\n attempts++\n if (attempts === maxRetries) {\n throw error\n }\n await sleep(getInterval(polls))\n polls++\n }\n }\n\n return result\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,gBAAgB,OAC3B,IACA,WAAgD,KAChD,aAAa,GACb,oBAAgE,SACjD;CACf,IAAI;CACJ,IAAI,WAAW;CACf,IAAI,QAAQ;CAEZ,MAAM,cAAc,OAAO,aAAa,aAAa,iBAAiB;CAEtE,OAAO,CAAC,QACN,IAAI;EACF,SAAS,MAAM,IAAI;EACnB,IAAI,CAAC,QAAQ;GACX,MAAM,MAAM,YAAY,MAAM,CAAC;GAC/B;;UAEK,OAAO;EACd,IAAI,CAAC,YAAY,UAAU,MAAM,EAC/B,MAAM;EAER;EACA,IAAI,aAAa,YACf,MAAM;EAER,MAAM,MAAM,YAAY,MAAM,CAAC;EAC/B;;CAIJ,OAAO"}
1
+ {"version":3,"file":"waitForResult.js","names":[],"sources":["../../../src/utils/waitForResult.ts"],"sourcesContent":["import { sleep } from './sleep.js'\n\n/**\n * Repeatedly calls a given asynchronous function until it resolves with a value\n * @param fn The function that should be repeated\n * @param interval The timeout in milliseconds between retries, or a function that receives the current poll count and returns the interval. Defaults to 5000\n * @param maxRetries Maximum number of retries before throwing an error, defaults to 3\n * @param shouldRetry Optional predicate to determine if an error should trigger a retry\n * @returns The result of the fn function\n * @throws Error if maximum retries is reached, if function keeps returning undefined, or if shouldRetry returns false\n */\nexport const waitForResult = async <T>(\n fn: () => Promise<T | undefined>,\n interval: number | ((poll: number) => number) = 5000,\n maxRetries = 3,\n shouldRetry: (count: number, error: unknown) => boolean = () => true\n): Promise<T> => {\n let result: T | undefined\n let attempts = 0\n let polls = 0\n\n const getInterval = typeof interval === 'function' ? interval : () => interval\n\n while (!result) {\n try {\n result = await fn()\n if (!result) {\n await sleep(getInterval(polls))\n polls++\n }\n } catch (error) {\n if (!shouldRetry(attempts, error)) {\n throw error\n }\n attempts++\n if (attempts === maxRetries) {\n throw error\n }\n await sleep(getInterval(polls))\n polls++\n }\n }\n\n return result\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,gBAAgB,OAC3B,IACA,WAAgD,KAChD,aAAa,GACb,oBAAgE,SACjD;CACf,IAAI;CACJ,IAAI,WAAW;CACf,IAAI,QAAQ;CAEZ,MAAM,cAAc,OAAO,aAAa,aAAa,iBAAiB;CAEtE,OAAO,CAAC,QACN,IAAI;EACF,SAAS,MAAM,GAAG;EAClB,IAAI,CAAC,QAAQ;GACX,MAAM,MAAM,YAAY,KAAK,CAAC;GAC9B;EACF;CACF,SAAS,OAAO;EACd,IAAI,CAAC,YAAY,UAAU,KAAK,GAC9B,MAAM;EAER;EACA,IAAI,aAAa,YACf,MAAM;EAER,MAAM,MAAM,YAAY,KAAK,CAAC;EAC9B;CACF;CAGF,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"withDedupe.js","names":[],"sources":["../../../src/utils/withDedupe.ts"],"sourcesContent":["/**\n * Map with a LRU (Least recently used) policy.\n *\n * https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU\n */\nexport class LruMap<value = unknown> extends Map<string, value> {\n maxSize: number\n\n constructor(size: number) {\n super()\n this.maxSize = size\n }\n\n override set(key: string, value: value): this {\n super.set(key, value)\n if (this.maxSize && this.size > this.maxSize) {\n this.delete(this.keys().next().value!)\n }\n return this\n }\n}\n\n/** @internal */\nconst promiseCache = /*#__PURE__*/ new LruMap<Promise<any>>(8192)\n\ntype WithDedupeOptions = {\n enabled?: boolean | undefined\n id?: string | undefined\n}\n\n/** Deduplicates in-flight promises. */\nexport function withDedupe<T>(\n fn: () => Promise<T>,\n { enabled = true, id }: WithDedupeOptions\n): Promise<T> {\n if (!enabled || !id) {\n return fn()\n }\n if (promiseCache.get(id)) {\n return promiseCache.get(id)!\n }\n const promise = fn().finally(() => promiseCache.delete(id))\n promiseCache.set(id, promise)\n return promise\n}\n"],"mappings":";;;;;;AAKA,IAAa,SAAb,cAA6C,IAAmB;CAC9D;CAEA,YAAY,MAAc;EACxB,OAAO;EACP,KAAK,UAAU;;CAGjB,IAAa,KAAa,OAAoB;EAC5C,MAAM,IAAI,KAAK,MAAM;EACrB,IAAI,KAAK,WAAW,KAAK,OAAO,KAAK,SACnC,KAAK,OAAO,KAAK,MAAM,CAAC,MAAM,CAAC,MAAO;EAExC,OAAO;;;;AAKX,MAAM,+BAA6B,IAAI,OAAqB,KAAK;;AAQjE,SAAgB,WACd,IACA,EAAE,UAAU,MAAM,MACN;CACZ,IAAI,CAAC,WAAW,CAAC,IACf,OAAO,IAAI;CAEb,IAAI,aAAa,IAAI,GAAG,EACtB,OAAO,aAAa,IAAI,GAAG;CAE7B,MAAM,UAAU,IAAI,CAAC,cAAc,aAAa,OAAO,GAAG,CAAC;CAC3D,aAAa,IAAI,IAAI,QAAQ;CAC7B,OAAO"}
1
+ {"version":3,"file":"withDedupe.js","names":[],"sources":["../../../src/utils/withDedupe.ts"],"sourcesContent":["/**\n * Map with a LRU (Least recently used) policy.\n *\n * https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU\n */\nexport class LruMap<value = unknown> extends Map<string, value> {\n maxSize: number\n\n constructor(size: number) {\n super()\n this.maxSize = size\n }\n\n override set(key: string, value: value): this {\n super.set(key, value)\n if (this.maxSize && this.size > this.maxSize) {\n this.delete(this.keys().next().value!)\n }\n return this\n }\n}\n\n/** @internal */\nconst promiseCache = /*#__PURE__*/ new LruMap<Promise<any>>(8192)\n\ntype WithDedupeOptions = {\n enabled?: boolean | undefined\n id?: string | undefined\n}\n\n/** Deduplicates in-flight promises. */\nexport function withDedupe<T>(\n fn: () => Promise<T>,\n { enabled = true, id }: WithDedupeOptions\n): Promise<T> {\n if (!enabled || !id) {\n return fn()\n }\n if (promiseCache.get(id)) {\n return promiseCache.get(id)!\n }\n const promise = fn().finally(() => promiseCache.delete(id))\n promiseCache.set(id, promise)\n return promise\n}\n"],"mappings":";;;;;;AAKA,IAAa,SAAb,cAA6C,IAAmB;CAC9D;CAEA,YAAY,MAAc;EACxB,MAAM;EACN,KAAK,UAAU;CACjB;CAEA,IAAa,KAAa,OAAoB;EAC5C,MAAM,IAAI,KAAK,KAAK;EACpB,IAAI,KAAK,WAAW,KAAK,OAAO,KAAK,SACnC,KAAK,OAAO,KAAK,KAAK,EAAE,KAAK,EAAE,KAAM;EAEvC,OAAO;CACT;AACF;;AAGA,MAAM,+BAA6B,IAAI,OAAqB,IAAI;;AAQhE,SAAgB,WACd,IACA,EAAE,UAAU,MAAM,MACN;CACZ,IAAI,CAAC,WAAW,CAAC,IACf,OAAO,GAAG;CAEZ,IAAI,aAAa,IAAI,EAAE,GACrB,OAAO,aAAa,IAAI,EAAE;CAE5B,MAAM,UAAU,GAAG,EAAE,cAAc,aAAa,OAAO,EAAE,CAAC;CAC1D,aAAa,IAAI,IAAI,OAAO;CAC5B,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"withTimeout.js","names":[],"sources":["../../../src/utils/withTimeout.ts"],"sourcesContent":["/**\n * Wraps a function in a timeout.\n * Based on viem's withTimeout implementation.\n * @param fn - The function to wrap.\n * @param timeout - The timeout in milliseconds.\n * @param errorInstance - The error instance to throw when the timeout is reached.\n * @param signal - Whether or not the timeout should use an abort signal.\n * @returns The result of the function.\n */\nexport function withTimeout<T>(\n fn: ({ signal }: { signal: AbortController['signal'] | null }) => Promise<T>,\n {\n errorInstance = new Error('Timed out after waiting for too long.'),\n timeout,\n signal,\n }: {\n // The error instance to throw when the timeout is reached.\n errorInstance?: Error | undefined\n // The timeout (in ms).\n timeout: number\n // Whether or not the timeout should use an abort signal.\n signal?: boolean | undefined\n }\n): Promise<T> {\n return new Promise((resolve, reject) => {\n ;(async () => {\n let timeoutId!: NodeJS.Timeout\n try {\n const controller = new AbortController()\n if (timeout > 0) {\n timeoutId = setTimeout(() => {\n if (signal) {\n controller.abort()\n } else {\n reject(errorInstance)\n }\n }, timeout) as NodeJS.Timeout // need to cast because bun globals.d.ts overrides @types/node\n }\n resolve(await fn({ signal: controller?.signal || null }))\n } catch (err) {\n if ((err as Error)?.name === 'AbortError') {\n reject(errorInstance)\n }\n reject(err)\n } finally {\n clearTimeout(timeoutId)\n }\n })()\n })\n}\n"],"mappings":";;;;;;;;;;AASA,SAAgB,YACd,IACA,EACE,gCAAgB,IAAI,MAAM,wCAAwC,EAClE,SACA,UASU;CACZ,OAAO,IAAI,SAAS,SAAS,WAAW;EACrC,CAAC,YAAY;GACZ,IAAI;GACJ,IAAI;IACF,MAAM,aAAa,IAAI,iBAAiB;IACxC,IAAI,UAAU,GACZ,YAAY,iBAAiB;KAC3B,IAAI,QACF,WAAW,OAAO;UAElB,OAAO,cAAc;OAEtB,QAAQ;IAEb,QAAQ,MAAM,GAAG,EAAE,QAAQ,YAAY,UAAU,MAAM,CAAC,CAAC;YAClD,KAAK;IACZ,IAAK,KAAe,SAAS,cAC3B,OAAO,cAAc;IAEvB,OAAO,IAAI;aACH;IACR,aAAa,UAAU;;MAEvB;GACJ"}
1
+ {"version":3,"file":"withTimeout.js","names":[],"sources":["../../../src/utils/withTimeout.ts"],"sourcesContent":["/**\n * Wraps a function in a timeout.\n * Based on viem's withTimeout implementation.\n * @param fn - The function to wrap.\n * @param timeout - The timeout in milliseconds.\n * @param errorInstance - The error instance to throw when the timeout is reached.\n * @param signal - Whether or not the timeout should use an abort signal.\n * @returns The result of the function.\n */\nexport function withTimeout<T>(\n fn: ({ signal }: { signal: AbortController['signal'] | null }) => Promise<T>,\n {\n errorInstance = new Error('Timed out after waiting for too long.'),\n timeout,\n signal,\n }: {\n // The error instance to throw when the timeout is reached.\n errorInstance?: Error | undefined\n // The timeout (in ms).\n timeout: number\n // Whether or not the timeout should use an abort signal.\n signal?: boolean | undefined\n }\n): Promise<T> {\n return new Promise((resolve, reject) => {\n ;(async () => {\n let timeoutId!: NodeJS.Timeout\n try {\n const controller = new AbortController()\n if (timeout > 0) {\n timeoutId = setTimeout(() => {\n if (signal) {\n controller.abort()\n } else {\n reject(errorInstance)\n }\n }, timeout) as NodeJS.Timeout // need to cast because bun globals.d.ts overrides @types/node\n }\n resolve(await fn({ signal: controller?.signal || null }))\n } catch (err) {\n if ((err as Error)?.name === 'AbortError') {\n reject(errorInstance)\n }\n reject(err)\n } finally {\n clearTimeout(timeoutId)\n }\n })()\n })\n}\n"],"mappings":";;;;;;;;;;AASA,SAAgB,YACd,IACA,EACE,gCAAgB,IAAI,MAAM,uCAAuC,GACjE,SACA,UASU;CACZ,OAAO,IAAI,SAAS,SAAS,WAAW;EACrC,CAAC,YAAY;GACZ,IAAI;GACJ,IAAI;IACF,MAAM,aAAa,IAAI,gBAAgB;IACvC,IAAI,UAAU,GACZ,YAAY,iBAAiB;KAC3B,IAAI,QACF,WAAW,MAAM;UAEjB,OAAO,aAAa;IAExB,GAAG,OAAO;IAEZ,QAAQ,MAAM,GAAG,EAAE,QAAQ,YAAY,UAAU,KAAK,CAAC,CAAC;GAC1D,SAAS,KAAK;IACZ,IAAK,KAAe,SAAS,cAC3B,OAAO,aAAa;IAEtB,OAAO,GAAG;GACZ,UAAU;IACR,aAAa,SAAS;GACxB;EACF,GAAG;CACL,CAAC;AACH"}
@@ -1,6 +1,6 @@
1
1
  //#region src/version.d.ts
2
2
  declare const name = "@lifi/sdk";
3
- declare const version = "4.0.0-beta.10";
3
+ declare const version = "4.0.0-beta.11";
4
4
  //#endregion
5
5
  export { name, version };
6
6
  //# sourceMappingURL=version.d.ts.map
@@ -1,6 +1,6 @@
1
1
  //#region src/version.ts
2
2
  const name = "@lifi/sdk";
3
- const version = "4.0.0-beta.10";
3
+ const version = "4.0.0-beta.11";
4
4
  //#endregion
5
5
  export { name, version };
6
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk'\nexport const version = '4.0.0-beta.10'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
1
+ {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk'\nexport const version = '4.0.0-beta.11'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/sdk",
3
- "version": "4.0.0-beta.10",
3
+ "version": "4.0.0-beta.11",
4
4
  "description": "LI.FI SDK for Any-to-Any Cross-Chain-Swap",
5
5
  "homepage": "https://github.com/lifinance/sdk",
6
6
  "bugs": {
@@ -28,7 +28,7 @@
28
28
  "./package.json": "./package.json"
29
29
  },
30
30
  "dependencies": {
31
- "@lifi/types": "17.80.0"
31
+ "@lifi/types": "17.82.1"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
@@ -49,8 +49,13 @@ export const checkBalance = async (
49
49
  step: LiFiStep,
50
50
  options: CheckBalanceOptions = {}
51
51
  ): Promise<void> => {
52
- const walletPaysGas = options.walletPaysGas ?? true
53
52
  const fromChainId = step.action.fromChainId
53
+ // Chains with non-standard native decimals (e.g. Tempo, Stable) report
54
+ // gas costs in units that don't align with wallet balances — drop the
55
+ // gas portion of the check on those chains.
56
+ const fromChain = await client.getChainById(fromChainId)
57
+ const walletPaysGas =
58
+ (options.walletPaysGas ?? true) && !fromChain.nonStandardNativeDecimals
54
59
  const requirements = new Map<string, Requirement>()
55
60
  const add = (token: Token, amount: bigint, bucket: Bucket): void => {
56
61
  if (token.chainId !== fromChainId || amount === 0n) {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk'
2
- export const version = '4.0.0-beta.10'
2
+ export const version = '4.0.0-beta.11'