@lifi/sdk 4.1.0 → 4.3.0
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.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/actions/getChains.d.ts +7 -8
- package/dist/cjs/actions/getConnections.d.ts +6 -7
- package/dist/cjs/actions/getContractCallsQuote.d.ts +7 -8
- package/dist/cjs/actions/getGasRecommendation.d.ts +7 -8
- package/dist/cjs/actions/getNameServiceAddress.d.ts +6 -7
- package/dist/cjs/actions/getQuote.d.ts +7 -8
- package/dist/cjs/actions/getRelayedTransactionStatus.d.ts +7 -8
- package/dist/cjs/actions/getRelayerQuote.d.ts +7 -8
- package/dist/cjs/actions/getRoutes.d.ts +7 -8
- package/dist/cjs/actions/getStatus.d.ts +7 -8
- package/dist/cjs/actions/getStepTransaction.d.ts +7 -8
- package/dist/cjs/actions/getStepTransaction.js +2 -0
- package/dist/cjs/actions/getStepTransaction.js.map +1 -1
- package/dist/cjs/actions/getToken.d.ts +8 -9
- package/dist/cjs/actions/getTokenBalance.d.ts +8 -9
- package/dist/cjs/actions/getTokenBalances.d.ts +8 -9
- package/dist/cjs/actions/getTokenBalancesByChain.d.ts +8 -9
- package/dist/cjs/actions/getTokenBalancesByChain.js +4 -2
- package/dist/cjs/actions/getTokenBalancesByChain.js.map +1 -1
- package/dist/cjs/actions/getTokens.d.ts +6 -7
- package/dist/cjs/actions/getTools.d.ts +6 -7
- package/dist/cjs/actions/getTransactionHistory.d.ts +13 -19
- package/dist/cjs/actions/index.d.ts +105 -113
- package/dist/cjs/actions/index.js +0 -2
- package/dist/cjs/actions/index.js.map +1 -1
- package/dist/cjs/actions/patchContractCalls.d.ts +0 -1
- package/dist/cjs/actions/relayTransaction.d.ts +7 -8
- package/dist/cjs/client/createClient.d.ts +0 -1
- package/dist/cjs/client/getClientStorage.d.ts +0 -1
- package/dist/cjs/core/BaseStepExecutionTask.d.ts +0 -1
- package/dist/cjs/core/BaseStepExecutor.d.ts +0 -1
- package/dist/cjs/core/StatusManager.d.ts +40 -51
- package/dist/cjs/core/TaskPipeline.d.ts +0 -1
- package/dist/cjs/core/actionMessages.d.ts +0 -1
- package/dist/cjs/core/execution.d.ts +29 -30
- package/dist/cjs/core/execution.js.map +1 -1
- package/dist/cjs/core/executionState.d.ts +0 -1
- package/dist/cjs/core/prepareRestart.d.ts +0 -1
- package/dist/cjs/core/tasks/CheckBalanceTask.d.ts +6 -7
- package/dist/cjs/core/tasks/PrepareTransactionTask.d.ts +0 -1
- package/dist/cjs/core/tasks/WaitForTransactionStatusTask.d.ts +0 -1
- package/dist/cjs/core/tasks/helpers/checkBalance.d.ts +17 -18
- package/dist/cjs/core/tasks/helpers/getTransactionRequestData.d.ts +0 -1
- package/dist/cjs/core/tasks/helpers/stepComparison.d.ts +11 -12
- package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.d.ts +0 -1
- package/dist/cjs/core/utils.d.ts +7 -8
- package/dist/cjs/errors/SDKError.d.ts +0 -1
- package/dist/cjs/errors/baseError.d.ts +0 -1
- package/dist/cjs/errors/errors.d.ts +4 -5
- package/dist/cjs/errors/httpError.d.ts +0 -1
- package/dist/cjs/errors/utils/baseErrorRootCause.d.ts +0 -1
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.js +0 -2
- package/dist/cjs/types/actions.d.ts +7 -7
- package/dist/cjs/types/core.d.ts +3 -4
- package/dist/cjs/types/execution.d.ts +0 -1
- package/dist/cjs/utils/checkPackageUpdates.js +1 -1
- package/dist/cjs/utils/convertQuoteToRoute.d.ts +9 -10
- package/dist/cjs/utils/formatUnits.d.ts +2 -2
- package/dist/cjs/utils/getTransactionMessage.d.ts +0 -1
- package/dist/cjs/utils/isHex.d.ts +1 -3
- package/dist/cjs/utils/isRoutesRequest.d.ts +0 -1
- package/dist/cjs/utils/isStep.d.ts +0 -1
- package/dist/cjs/utils/isToken.d.ts +0 -1
- package/dist/cjs/utils/parseUnits.d.ts +2 -2
- package/dist/cjs/utils/request.d.ts +0 -1
- package/dist/cjs/utils/waitForResult.d.ts +8 -8
- package/dist/cjs/utils/withDedupe.d.ts +5 -8
- package/dist/cjs/utils/withTimeout.d.ts +10 -16
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/actions/getChains.d.ts +7 -8
- package/dist/esm/actions/getChains.d.ts.map +1 -1
- package/dist/esm/actions/getConnections.d.ts +6 -7
- package/dist/esm/actions/getConnections.d.ts.map +1 -1
- package/dist/esm/actions/getContractCallsQuote.d.ts +7 -8
- package/dist/esm/actions/getContractCallsQuote.d.ts.map +1 -1
- package/dist/esm/actions/getGasRecommendation.d.ts +7 -8
- package/dist/esm/actions/getGasRecommendation.d.ts.map +1 -1
- package/dist/esm/actions/getNameServiceAddress.d.ts +6 -7
- package/dist/esm/actions/getNameServiceAddress.d.ts.map +1 -1
- package/dist/esm/actions/getQuote.d.ts +7 -8
- package/dist/esm/actions/getQuote.d.ts.map +1 -1
- package/dist/esm/actions/getRelayedTransactionStatus.d.ts +7 -8
- package/dist/esm/actions/getRelayedTransactionStatus.d.ts.map +1 -1
- package/dist/esm/actions/getRelayerQuote.d.ts +7 -8
- package/dist/esm/actions/getRelayerQuote.d.ts.map +1 -1
- package/dist/esm/actions/getRoutes.d.ts +7 -8
- package/dist/esm/actions/getRoutes.d.ts.map +1 -1
- package/dist/esm/actions/getStatus.d.ts +7 -8
- package/dist/esm/actions/getStatus.d.ts.map +1 -1
- package/dist/esm/actions/getStepTransaction.d.ts +7 -8
- package/dist/esm/actions/getStepTransaction.d.ts.map +1 -1
- package/dist/esm/actions/getStepTransaction.js +2 -0
- package/dist/esm/actions/getStepTransaction.js.map +1 -1
- package/dist/esm/actions/getToken.d.ts +8 -9
- package/dist/esm/actions/getToken.d.ts.map +1 -1
- package/dist/esm/actions/getTokenBalance.d.ts +8 -9
- package/dist/esm/actions/getTokenBalance.d.ts.map +1 -1
- package/dist/esm/actions/getTokenBalances.d.ts +8 -9
- package/dist/esm/actions/getTokenBalances.d.ts.map +1 -1
- package/dist/esm/actions/getTokenBalancesByChain.d.ts +8 -9
- package/dist/esm/actions/getTokenBalancesByChain.d.ts.map +1 -1
- package/dist/esm/actions/getTokenBalancesByChain.js +4 -2
- package/dist/esm/actions/getTokenBalancesByChain.js.map +1 -1
- package/dist/esm/actions/getTokens.d.ts +6 -7
- package/dist/esm/actions/getTokens.d.ts.map +1 -1
- package/dist/esm/actions/getTools.d.ts +6 -7
- package/dist/esm/actions/getTools.d.ts.map +1 -1
- package/dist/esm/actions/getTransactionHistory.d.ts +13 -19
- package/dist/esm/actions/getTransactionHistory.d.ts.map +1 -1
- package/dist/esm/actions/index.d.ts +105 -113
- package/dist/esm/actions/index.d.ts.map +1 -1
- package/dist/esm/actions/index.js +0 -2
- package/dist/esm/actions/index.js.map +1 -1
- package/dist/esm/actions/patchContractCalls.d.ts +0 -1
- package/dist/esm/actions/patchContractCalls.d.ts.map +1 -1
- package/dist/esm/actions/relayTransaction.d.ts +7 -8
- package/dist/esm/actions/relayTransaction.d.ts.map +1 -1
- package/dist/esm/client/createClient.d.ts +0 -1
- package/dist/esm/client/createClient.d.ts.map +1 -1
- package/dist/esm/client/getClientStorage.d.ts +0 -1
- package/dist/esm/client/getClientStorage.d.ts.map +1 -1
- package/dist/esm/core/BaseStepExecutionTask.d.ts +0 -1
- package/dist/esm/core/BaseStepExecutionTask.d.ts.map +1 -1
- package/dist/esm/core/BaseStepExecutor.d.ts +0 -1
- package/dist/esm/core/BaseStepExecutor.d.ts.map +1 -1
- package/dist/esm/core/StatusManager.d.ts +40 -51
- package/dist/esm/core/StatusManager.d.ts.map +1 -1
- package/dist/esm/core/TaskPipeline.d.ts +0 -1
- package/dist/esm/core/TaskPipeline.d.ts.map +1 -1
- package/dist/esm/core/actionMessages.d.ts +0 -1
- package/dist/esm/core/actionMessages.d.ts.map +1 -1
- package/dist/esm/core/execution.d.ts +29 -30
- package/dist/esm/core/execution.d.ts.map +1 -1
- package/dist/esm/core/execution.js.map +1 -1
- package/dist/esm/core/executionState.d.ts +0 -1
- package/dist/esm/core/executionState.d.ts.map +1 -1
- package/dist/esm/core/prepareRestart.d.ts +0 -1
- package/dist/esm/core/prepareRestart.d.ts.map +1 -1
- package/dist/esm/core/storage.d.ts.map +1 -1
- package/dist/esm/core/tasks/CheckBalanceTask.d.ts +6 -7
- package/dist/esm/core/tasks/CheckBalanceTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/PrepareTransactionTask.d.ts +0 -1
- package/dist/esm/core/tasks/PrepareTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/WaitForTransactionStatusTask.d.ts +0 -1
- package/dist/esm/core/tasks/WaitForTransactionStatusTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/checkBalance.d.ts +17 -18
- package/dist/esm/core/tasks/helpers/checkBalance.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/getTransactionRequestData.d.ts +0 -1
- package/dist/esm/core/tasks/helpers/getTransactionRequestData.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/stepComparison.d.ts +11 -12
- package/dist/esm/core/tasks/helpers/stepComparison.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/waitForTransactionStatus.d.ts +0 -1
- package/dist/esm/core/tasks/helpers/waitForTransactionStatus.d.ts.map +1 -1
- package/dist/esm/core/utils.d.ts +7 -8
- package/dist/esm/core/utils.d.ts.map +1 -1
- package/dist/esm/errors/SDKError.d.ts +0 -1
- package/dist/esm/errors/SDKError.d.ts.map +1 -1
- package/dist/esm/errors/baseError.d.ts +0 -1
- package/dist/esm/errors/baseError.d.ts.map +1 -1
- package/dist/esm/errors/constants.d.ts.map +1 -1
- package/dist/esm/errors/errors.d.ts +4 -5
- package/dist/esm/errors/errors.d.ts.map +1 -1
- package/dist/esm/errors/httpError.d.ts +0 -1
- package/dist/esm/errors/httpError.d.ts.map +1 -1
- package/dist/esm/errors/utils/baseErrorRootCause.d.ts +0 -1
- package/dist/esm/errors/utils/baseErrorRootCause.d.ts.map +1 -1
- package/dist/esm/errors/utils/rootCause.d.ts.map +1 -1
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.js +1 -2
- package/dist/esm/types/actions.d.ts +7 -7
- package/dist/esm/types/actions.d.ts.map +1 -1
- package/dist/esm/types/core.d.ts +3 -4
- package/dist/esm/types/core.d.ts.map +1 -1
- package/dist/esm/types/execution.d.ts +0 -1
- package/dist/esm/types/execution.d.ts.map +1 -1
- package/dist/esm/types/request.d.ts.map +1 -1
- package/dist/esm/utils/checkPackageUpdates.d.ts.map +1 -1
- package/dist/esm/utils/checkPackageUpdates.js +1 -1
- package/dist/esm/utils/convertQuoteToRoute.d.ts +9 -10
- package/dist/esm/utils/convertQuoteToRoute.d.ts.map +1 -1
- package/dist/esm/utils/decode.d.ts.map +1 -1
- package/dist/esm/utils/fetchTxErrorDetails.d.ts.map +1 -1
- package/dist/esm/utils/formatUnits.d.ts +2 -2
- package/dist/esm/utils/formatUnits.d.ts.map +1 -1
- package/dist/esm/utils/getTransactionMessage.d.ts +0 -1
- package/dist/esm/utils/getTransactionMessage.d.ts.map +1 -1
- package/dist/esm/utils/isHex.d.ts +1 -3
- package/dist/esm/utils/isHex.d.ts.map +1 -1
- package/dist/esm/utils/isRoutesRequest.d.ts +0 -1
- package/dist/esm/utils/isRoutesRequest.d.ts.map +1 -1
- package/dist/esm/utils/isStep.d.ts +0 -1
- package/dist/esm/utils/isStep.d.ts.map +1 -1
- package/dist/esm/utils/isToken.d.ts +0 -1
- package/dist/esm/utils/isToken.d.ts.map +1 -1
- package/dist/esm/utils/parseUnits.d.ts +2 -2
- package/dist/esm/utils/parseUnits.d.ts.map +1 -1
- package/dist/esm/utils/request.d.ts +0 -1
- package/dist/esm/utils/request.d.ts.map +1 -1
- package/dist/esm/utils/sleep.d.ts.map +1 -1
- package/dist/esm/utils/toQueryString.d.ts.map +1 -1
- package/dist/esm/utils/waitForResult.d.ts +8 -8
- package/dist/esm/utils/waitForResult.d.ts.map +1 -1
- package/dist/esm/utils/withDedupe.d.ts +5 -8
- package/dist/esm/utils/withDedupe.d.ts.map +1 -1
- package/dist/esm/utils/withTimeout.d.ts +10 -16
- package/dist/esm/utils/withTimeout.d.ts.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.d.ts.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +2 -2
- package/src/actions/getStepTransaction.ts +4 -0
- package/src/actions/index.ts +0 -15
- package/src/index.ts +0 -1
- package/src/version.ts +1 -1
- package/dist/cjs/actions/getWalletBalances.d.ts +0 -16
- package/dist/cjs/actions/getWalletBalances.js +0 -20
- package/dist/cjs/actions/getWalletBalances.js.map +0 -1
- package/dist/esm/actions/getWalletBalances.d.ts +0 -16
- package/dist/esm/actions/getWalletBalances.d.ts.map +0 -1
- package/dist/esm/actions/getWalletBalances.js +0 -19
- package/dist/esm/actions/getWalletBalances.js.map +0 -1
- package/src/actions/getWalletBalances.ts +0 -36
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution.js","names":["executionState","ProviderError","ExecuteStepRetryError"],"sources":["../../../src/core/execution.ts"],"sourcesContent":["import type { Route } from '@lifi/types'\nimport { LiFiErrorCode } from '../errors/constants.js'\nimport { ExecuteStepRetryError, ProviderError } from '../errors/errors.js'\nimport type {\n ExecutionOptions,\n LiFiStepExtended,\n RouteExtended,\n SDKClient,\n SDKProvider,\n} from '../types/core.js'\nimport { executionState } from './executionState.js'\nimport { prepareRestart } from './prepareRestart.js'\n\n/**\n * Execute a route.\n * @param client - The SDK client.\n * @param route - The route that should be executed. Cannot be an active route.\n * @param executionOptions - An object containing settings and callbacks.\n * @returns The executed route.\n * @throws {LiFiError} Throws a LiFiError if the execution fails.\n */\nexport const executeRoute = async (\n client: SDKClient,\n route: Route,\n executionOptions?: ExecutionOptions\n): Promise<RouteExtended> => {\n // Deep clone to prevent side effects\n const clonedRoute = structuredClone<Route>(route)\n\n let executionPromise = executionState.get(clonedRoute.id)?.promise\n // Check if route is already running\n if (executionPromise) {\n return executionPromise\n }\n\n executionState.create({ route: clonedRoute, executionOptions })\n executionPromise = executeSteps(client, clonedRoute)\n executionState.update({\n route: clonedRoute,\n promise: executionPromise,\n })\n\n return executionPromise\n}\n\n/**\n * Resume the execution of a route that has been stopped or had an error while executing.\n * @param client - The SDK client.\n * @param route - The route that is to be executed. Cannot be an active route.\n * @param executionOptions - An object containing settings and callbacks.\n * @returns The executed route.\n * @throws {LiFiError} Throws a LiFiError if the execution fails.\n */\nexport const resumeRoute = async (\n client: SDKClient,\n route: Route,\n executionOptions?: ExecutionOptions\n): Promise<RouteExtended> => {\n const execution = executionState.get(route.id)\n\n if (execution) {\n const executionHalted = execution.executors.some(\n (executor) => !executor.allowExecution\n )\n if (!executionHalted) {\n // Check if we want to resume route execution in the background\n updateRouteExecution(route, {\n executeInBackground: executionOptions?.executeInBackground,\n })\n if (!execution.promise) {\n // We should never reach this point if we do clean-up properly\n throw new Error('Route execution promise not found.')\n }\n return execution.promise\n }\n }\n\n prepareRestart(route)\n\n return executeRoute(client, route, executionOptions)\n}\n\nconst executeSteps = async (\n client: SDKClient,\n route: RouteExtended\n): Promise<RouteExtended> => {\n // Loop over steps and execute them\n for (let index = 0; index < route.steps.length; index++) {\n const execution = executionState.get(route.id)\n // Check if execution has stopped in the meantime\n if (!execution) {\n break\n }\n\n const step = route.steps[index]\n const previousStep = route.steps[index - 1]\n // Check if the step is already done\n if (step.execution?.status === 'DONE') {\n continue\n }\n\n // Update step fromAmount using output of the previous step execution. In the future this should be handled by calling `updateRoute`\n if (previousStep?.execution?.toAmount) {\n step.action.fromAmount = previousStep.execution.toAmount\n if (step.includedSteps?.length) {\n step.includedSteps[0].action.fromAmount =\n previousStep.execution.toAmount\n }\n }\n\n try {\n const fromAddress = step.action.fromAddress\n if (!fromAddress) {\n throw new Error('Action fromAddress is not specified.')\n }\n\n const provider = client.providers.find((provider: SDKProvider) =>\n provider.isAddress(fromAddress)\n )\n\n if (!provider) {\n throw new ProviderError(\n LiFiErrorCode.ProviderUnavailable,\n 'SDK Execution Provider not found.'\n )\n }\n\n const stepExecutor = await provider.getStepExecutor({\n routeId: route.id,\n executionOptions: execution.executionOptions,\n })\n execution.executors.push(stepExecutor)\n\n // Check if we want to execute this step in the background\n if (execution.executionOptions) {\n updateRouteExecution(route, execution.executionOptions)\n }\n\n let executedStep: LiFiStepExtended\n try {\n executedStep = await stepExecutor.executeStep(client, step)\n } catch (e) {\n if (e instanceof ExecuteStepRetryError) {\n step.execution = undefined\n executedStep = await stepExecutor.executeStep(\n client,\n step,\n e.retryParams\n )\n } else {\n throw e\n }\n }\n\n // We may reach this point if user interaction isn't allowed. We want to stop execution until we resume it\n if (executedStep.execution?.status !== 'DONE') {\n stopRouteExecution(route)\n }\n\n // Execution stopped during the current step, we don't want to continue to the next step so we return already\n if (!stepExecutor.allowExecution) {\n return route\n }\n } catch (e) {\n stopRouteExecution(route)\n throw e\n }\n }\n\n // Clean up after the execution\n executionState.delete(route.id)\n return route\n}\n\n/**\n * Updates route execution to background or foreground state.\n * @param route - A route that is currently in execution.\n * @param options - An object with execution settings.\n */\nexport const updateRouteExecution = (\n route: Route,\n options: ExecutionOptions\n): void => {\n const execution = executionState.get(route.id)\n if (!execution) {\n return\n }\n\n if ('executeInBackground' in options) {\n for (const executor of execution.executors) {\n executor.setInteraction({\n allowInteraction: !options?.executeInBackground,\n allowUpdates: true,\n })\n }\n }\n // Update active route settings so we know what the current state of execution is\n execution.executionOptions = {\n ...execution.executionOptions,\n ...options,\n }\n}\n\n/**\n * Stops the execution of an active route.\n * @param route - A route that is currently in execution.\n * @returns The stopped route.\n */\nexport const stopRouteExecution = (route: Route): Route => {\n const execution = executionState.get(route.id)\n if (!execution) {\n return route\n }\n\n for (const executor of execution.executors) {\n executor.setInteraction({\n allowInteraction: false,\n allowUpdates: false,\n allowExecution: false,\n })\n }\n executionState.delete(route.id)\n return execution.route\n}\n\n/**\n * Get the list of active routes.\n * @returns A list of routes.\n */\nexport const getActiveRoutes = (): RouteExtended[] => {\n return Object.values(executionState.state)\n .map((dict) => dict?.route)\n .filter(Boolean) as RouteExtended[]\n}\n\n/**\n * Return the current route information for given route. The route has to be active.\n * @param routeId - A route id.\n * @returns The updated route.\n */\nexport const getActiveRoute = (routeId: string): RouteExtended | undefined => {\n return executionState.get(routeId)?.route\n}\n"],"mappings":";;;;;;;;;;;;;;AAqBA,MAAa,eAAe,OAC1B,QACA,OACA,qBAC2B;CAE3B,MAAM,cAAc,gBAAuB,KAAK;CAEhD,IAAI,mBAAmBA,4BAAAA,eAAe,IAAI,YAAY,EAAE,CAAC,EAAE;CAE3D,IAAI,kBACF,OAAO;CAGT,4BAAA,eAAe,OAAO;EAAE,OAAO;EAAa;CAAiB,CAAC;CAC9D,mBAAmB,aAAa,QAAQ,WAAW;CACnD,4BAAA,eAAe,OAAO;EACpB,OAAO;EACP,SAAS;CACX,CAAC;CAED,OAAO;AACT;;;;;;;;;AAUA,MAAa,cAAc,OACzB,QACA,OACA,qBAC2B;CAC3B,MAAM,YAAYA,4BAAAA,eAAe,IAAI,MAAM,EAAE;CAE7C,IAAI;
|
|
1
|
+
{"version":3,"file":"execution.js","names":["executionState","ProviderError","ExecuteStepRetryError"],"sources":["../../../src/core/execution.ts"],"sourcesContent":["import type { Route } from '@lifi/types'\nimport { LiFiErrorCode } from '../errors/constants.js'\nimport { ExecuteStepRetryError, ProviderError } from '../errors/errors.js'\nimport type {\n ExecutionOptions,\n LiFiStepExtended,\n RouteExtended,\n SDKClient,\n SDKProvider,\n} from '../types/core.js'\nimport { executionState } from './executionState.js'\nimport { prepareRestart } from './prepareRestart.js'\n\n/**\n * Execute a route.\n * @param client - The SDK client.\n * @param route - The route that should be executed. Cannot be an active route.\n * @param executionOptions - An object containing settings and callbacks.\n * @returns The executed route.\n * @throws {LiFiError} Throws a LiFiError if the execution fails.\n */\nexport const executeRoute = async (\n client: SDKClient,\n route: Route,\n executionOptions?: ExecutionOptions\n): Promise<RouteExtended> => {\n // Deep clone to prevent side effects\n const clonedRoute = structuredClone<Route>(route)\n\n let executionPromise = executionState.get(clonedRoute.id)?.promise\n // Check if route is already running\n if (executionPromise) {\n return executionPromise\n }\n\n executionState.create({ route: clonedRoute, executionOptions })\n executionPromise = executeSteps(client, clonedRoute)\n executionState.update({\n route: clonedRoute,\n promise: executionPromise,\n })\n\n return executionPromise\n}\n\n/**\n * Resume the execution of a route that has been stopped or had an error while executing.\n * @param client - The SDK client.\n * @param route - The route that is to be executed. Cannot be an active route.\n * @param executionOptions - An object containing settings and callbacks.\n * @returns The executed route.\n * @throws {LiFiError} Throws a LiFiError if the execution fails.\n */\nexport const resumeRoute = async (\n client: SDKClient,\n route: Route,\n executionOptions?: ExecutionOptions\n): Promise<RouteExtended> => {\n const execution = executionState.get(route.id)\n\n if (execution) {\n const executionHalted = execution.executors.some(\n (executor) => !executor.allowExecution\n )\n if (!executionHalted) {\n // Check if we want to resume route execution in the background\n updateRouteExecution(route, {\n executeInBackground: executionOptions?.executeInBackground,\n })\n if (!execution.promise) {\n // We should never reach this point if we do clean-up properly\n throw new Error('Route execution promise not found.')\n }\n return execution.promise\n }\n }\n\n prepareRestart(route)\n\n return executeRoute(client, route, executionOptions)\n}\n\nconst executeSteps = async (\n client: SDKClient,\n route: RouteExtended\n): Promise<RouteExtended> => {\n // Loop over steps and execute them\n for (let index = 0; index < route.steps.length; index++) {\n const execution = executionState.get(route.id)\n // Check if execution has stopped in the meantime\n if (!execution) {\n break\n }\n\n const step = route.steps[index]\n const previousStep = route.steps[index - 1]\n // Check if the step is already done\n if (step.execution?.status === 'DONE') {\n continue\n }\n\n // Update step fromAmount using output of the previous step execution. In the future this should be handled by calling `updateRoute`\n if (previousStep?.execution?.toAmount) {\n step.action.fromAmount = previousStep.execution.toAmount\n if (step.includedSteps?.length) {\n step.includedSteps[0].action.fromAmount =\n previousStep.execution.toAmount\n }\n }\n\n try {\n const fromAddress = step.action.fromAddress\n if (!fromAddress) {\n throw new Error('Action fromAddress is not specified.')\n }\n\n const provider = client.providers.find((provider: SDKProvider) =>\n provider.isAddress(fromAddress)\n )\n\n if (!provider) {\n throw new ProviderError(\n LiFiErrorCode.ProviderUnavailable,\n 'SDK Execution Provider not found.'\n )\n }\n\n const stepExecutor = await provider.getStepExecutor({\n routeId: route.id,\n executionOptions: execution.executionOptions,\n })\n execution.executors.push(stepExecutor)\n\n // Check if we want to execute this step in the background\n if (execution.executionOptions) {\n updateRouteExecution(route, execution.executionOptions)\n }\n\n let executedStep: LiFiStepExtended\n try {\n executedStep = await stepExecutor.executeStep(client, step)\n } catch (e) {\n if (e instanceof ExecuteStepRetryError) {\n step.execution = undefined\n executedStep = await stepExecutor.executeStep(\n client,\n step,\n e.retryParams\n )\n } else {\n throw e\n }\n }\n\n // We may reach this point if user interaction isn't allowed. We want to stop execution until we resume it\n if (executedStep.execution?.status !== 'DONE') {\n stopRouteExecution(route)\n }\n\n // Execution stopped during the current step, we don't want to continue to the next step so we return already\n if (!stepExecutor.allowExecution) {\n return route\n }\n } catch (e) {\n stopRouteExecution(route)\n throw e\n }\n }\n\n // Clean up after the execution\n executionState.delete(route.id)\n return route\n}\n\n/**\n * Updates route execution to background or foreground state.\n * @param route - A route that is currently in execution.\n * @param options - An object with execution settings.\n */\nexport const updateRouteExecution = (\n route: Route,\n options: ExecutionOptions\n): void => {\n const execution = executionState.get(route.id)\n if (!execution) {\n return\n }\n\n if ('executeInBackground' in options) {\n for (const executor of execution.executors) {\n executor.setInteraction({\n allowInteraction: !options?.executeInBackground,\n allowUpdates: true,\n })\n }\n }\n // Update active route settings so we know what the current state of execution is\n execution.executionOptions = {\n ...execution.executionOptions,\n ...options,\n }\n}\n\n/**\n * Stops the execution of an active route.\n * @param route - A route that is currently in execution.\n * @returns The stopped route.\n */\nexport const stopRouteExecution = (route: Route): Route => {\n const execution = executionState.get(route.id)\n if (!execution) {\n return route\n }\n\n for (const executor of execution.executors) {\n executor.setInteraction({\n allowInteraction: false,\n allowUpdates: false,\n allowExecution: false,\n })\n }\n executionState.delete(route.id)\n return execution.route\n}\n\n/**\n * Get the list of active routes.\n * @returns A list of routes.\n */\nexport const getActiveRoutes = (): RouteExtended[] => {\n return Object.values(executionState.state)\n .map((dict) => dict?.route)\n .filter(Boolean) as RouteExtended[]\n}\n\n/**\n * Return the current route information for given route. The route has to be active.\n * @param routeId - A route id.\n * @returns The updated route.\n */\nexport const getActiveRoute = (routeId: string): RouteExtended | undefined => {\n return executionState.get(routeId)?.route\n}\n"],"mappings":"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"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { StepExecutorContext, TaskResult } from "../../types/execution.js";
|
|
2
2
|
import { BaseStepExecutionTask } from "../BaseStepExecutionTask.js";
|
|
3
3
|
import { CheckBalanceOptions } from "./helpers/checkBalance.js";
|
|
4
|
-
|
|
5
4
|
//#region src/core/tasks/CheckBalanceTask.d.ts
|
|
6
5
|
declare class CheckBalanceTask extends BaseStepExecutionTask {
|
|
7
6
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
* Per-step options hook for chain-specific subclasses (e.g. skip the
|
|
8
|
+
* gas check for smart-contract wallets or relayed steps). Default `{}`
|
|
9
|
+
* keeps behavior unchanged for every provider that doesn't override.
|
|
10
|
+
* Resolved lazily inside `run()` — pipelines that resume past
|
|
11
|
+
* `CheckBalance` pay no cost.
|
|
12
|
+
*/
|
|
14
13
|
protected getCheckBalanceOptions(_context: StepExecutorContext): Promise<CheckBalanceOptions>;
|
|
15
14
|
run(context: StepExecutorContext): Promise<TaskResult>;
|
|
16
15
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { StepExecutorContext, TaskResult } from "../../types/execution.js";
|
|
2
2
|
import { BaseStepExecutionTask } from "../BaseStepExecutionTask.js";
|
|
3
|
-
|
|
4
3
|
//#region src/core/tasks/PrepareTransactionTask.d.ts
|
|
5
4
|
declare class PrepareTransactionTask extends BaseStepExecutionTask {
|
|
6
5
|
run(context: StepExecutorContext): Promise<TaskResult>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ExecutionActionType } from "../../types/core.js";
|
|
2
2
|
import { StepExecutorContext, TaskResult } from "../../types/execution.js";
|
|
3
3
|
import { BaseStepExecutionTask } from "../BaseStepExecutionTask.js";
|
|
4
|
-
|
|
5
4
|
//#region src/core/tasks/WaitForTransactionStatusTask.d.ts
|
|
6
5
|
declare class WaitForTransactionStatusTask extends BaseStepExecutionTask {
|
|
7
6
|
readonly actionType: ExecutionActionType;
|
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
import { SDKClient } from "../../../types/core.js";
|
|
2
2
|
import { LiFiStep } from "@lifi/types";
|
|
3
|
-
|
|
4
3
|
//#region src/core/tasks/helpers/checkBalance.d.ts
|
|
5
4
|
type CheckBalanceOptions = {
|
|
6
5
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
* Set to `false` when outer-tx gas is paid by something other than
|
|
7
|
+
* `walletAddress` (SCA executor, 4337 bundler / paymaster, relayer):
|
|
8
|
+
* `gasPart` is excluded from the sufficiency check and slippage rescue.
|
|
9
|
+
* Source amount and non-included fees (e.g. LZ `msg.value`) are still
|
|
10
|
+
* verified. Defaults to `true` (strict, today's behavior).
|
|
11
|
+
*/
|
|
13
12
|
walletPaysGas?: boolean;
|
|
14
13
|
};
|
|
15
14
|
/**
|
|
16
|
-
* Verifies that the wallet holds enough of every token required to execute
|
|
17
|
-
* the step on its source chain — the source-token amount, any gas costs, and
|
|
18
|
-
* any non-included fee costs. Reads all balances in one batched provider
|
|
19
|
-
* call, retries within a bounded budget to absorb transient RPC failures and
|
|
20
|
-
* post-confirmation propagation lag, and applies slippage to the source-token
|
|
21
|
-
* portion only as a last resort (overhead is never trimmed).
|
|
22
|
-
*
|
|
23
|
-
* Throws BalanceError("The balance is too low.") on a genuine shortfall, or
|
|
24
|
-
* BalanceError("Could not read wallet balance.") if the balance can't be read
|
|
25
|
-
* after retries.
|
|
26
|
-
*/
|
|
15
|
+
* Verifies that the wallet holds enough of every token required to execute
|
|
16
|
+
* the step on its source chain — the source-token amount, any gas costs, and
|
|
17
|
+
* any non-included fee costs. Reads all balances in one batched provider
|
|
18
|
+
* call, retries within a bounded budget to absorb transient RPC failures and
|
|
19
|
+
* post-confirmation propagation lag, and applies slippage to the source-token
|
|
20
|
+
* portion only as a last resort (overhead is never trimmed).
|
|
21
|
+
*
|
|
22
|
+
* Throws BalanceError("The balance is too low.") on a genuine shortfall, or
|
|
23
|
+
* BalanceError("Could not read wallet balance.") if the balance can't be read
|
|
24
|
+
* after retries.
|
|
25
|
+
*/
|
|
27
26
|
declare const checkBalance: (client: SDKClient, walletAddress: string, step: LiFiStep, options?: CheckBalanceOptions) => Promise<void>;
|
|
28
27
|
//#endregion
|
|
29
28
|
export { CheckBalanceOptions, checkBalance };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ExecutionOptions, LiFiStepExtended } from "../../../types/core.js";
|
|
2
|
-
|
|
3
2
|
//#region src/core/tasks/helpers/getTransactionRequestData.d.ts
|
|
4
3
|
declare const getTransactionRequestData: (step: LiFiStepExtended, executionOptions?: ExecutionOptions) => Promise<string>;
|
|
5
4
|
//#endregion
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { ExecutionOptions } from "../../../types/core.js";
|
|
2
2
|
import { StatusManager } from "../../StatusManager.js";
|
|
3
3
|
import { LiFiStep } from "@lifi/types";
|
|
4
|
-
|
|
5
4
|
//#region src/core/tasks/helpers/stepComparison.d.ts
|
|
6
5
|
/**
|
|
7
|
-
* This method checks whether the new and updated Step meets the required exchange rate conditions.
|
|
8
|
-
* If yes it returns the updated Step.
|
|
9
|
-
* If no and if user interaction is allowed it triggers the acceptExchangeRateUpdateHook. If no user interaction is allowed it aborts.
|
|
10
|
-
* @param statusManager
|
|
11
|
-
* @param oldStep
|
|
12
|
-
* @param newStep
|
|
13
|
-
* @param settings
|
|
14
|
-
* @param allowUserInteraction
|
|
15
|
-
* @param executionOptions
|
|
16
|
-
* @returns Return LiFiStep
|
|
17
|
-
*/
|
|
6
|
+
* This method checks whether the new and updated Step meets the required exchange rate conditions.
|
|
7
|
+
* If yes it returns the updated Step.
|
|
8
|
+
* If no and if user interaction is allowed it triggers the acceptExchangeRateUpdateHook. If no user interaction is allowed it aborts.
|
|
9
|
+
* @param statusManager
|
|
10
|
+
* @param oldStep
|
|
11
|
+
* @param newStep
|
|
12
|
+
* @param settings
|
|
13
|
+
* @param allowUserInteraction
|
|
14
|
+
* @param executionOptions
|
|
15
|
+
* @returns Return LiFiStep
|
|
16
|
+
*/
|
|
18
17
|
declare const stepComparison: (statusManager: StatusManager, oldStep: LiFiStep, newStep: LiFiStep, allowUserInteraction: boolean, executionOptions?: ExecutionOptions) => Promise<LiFiStep>;
|
|
19
18
|
//#endregion
|
|
20
19
|
export { stepComparison };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ExecutionActionType, SDKClient } from "../../../types/core.js";
|
|
2
2
|
import { StatusManager } from "../../StatusManager.js";
|
|
3
3
|
import { LiFiStep, StatusResponse } from "@lifi/types";
|
|
4
|
-
|
|
5
4
|
//#region src/core/tasks/helpers/waitForTransactionStatus.d.ts
|
|
6
5
|
declare function waitForTransactionStatus(client: SDKClient, statusManager: StatusManager, txHash: string, step: LiFiStep, actionType: ExecutionActionType, interval?: number): Promise<StatusResponse>;
|
|
7
6
|
//#endregion
|
package/dist/cjs/core/utils.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { RPCUrls } from "../types/core.js";
|
|
2
2
|
import { ChainId, ExtendedChain, LiFiStep } from "@lifi/types";
|
|
3
|
-
|
|
4
3
|
//#region src/core/utils.d.ts
|
|
5
4
|
/**
|
|
6
|
-
* Used to check if changed exchange rate is in the range of slippage threshold.
|
|
7
|
-
* We use a slippage value as a threshold to trigger the rate change hook.
|
|
8
|
-
* This can result in almost doubled slippage for the user and need to be revisited.
|
|
9
|
-
* @param oldStep - old step
|
|
10
|
-
* @param newStep - new step
|
|
11
|
-
* @returns Boolean
|
|
12
|
-
*/
|
|
5
|
+
* Used to check if changed exchange rate is in the range of slippage threshold.
|
|
6
|
+
* We use a slippage value as a threshold to trigger the rate change hook.
|
|
7
|
+
* This can result in almost doubled slippage for the user and need to be revisited.
|
|
8
|
+
* @param oldStep - old step
|
|
9
|
+
* @param newStep - new step
|
|
10
|
+
* @returns Boolean
|
|
11
|
+
*/
|
|
13
12
|
declare function checkStepSlippageThreshold(oldStep: LiFiStep, newStep: LiFiStep): boolean;
|
|
14
13
|
declare function getRpcUrlsFromChains(existingRpcUrls: RPCUrls, chains: ExtendedChain[], skipChains?: ChainId[]): RPCUrls;
|
|
15
14
|
//#endregion
|
|
@@ -2,7 +2,6 @@ import { ExecutionAction } from "../types/core.js";
|
|
|
2
2
|
import { ErrorCode } from "./constants.js";
|
|
3
3
|
import { BaseError } from "./baseError.js";
|
|
4
4
|
import { LiFiStep } from "@lifi/types";
|
|
5
|
-
|
|
6
5
|
//#region src/errors/SDKError.d.ts
|
|
7
6
|
declare class SDKError extends Error {
|
|
8
7
|
step?: LiFiStep;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ExecuteStepRetryParams } from "../types/core.js";
|
|
2
2
|
import { LiFiErrorCode } from "./constants.js";
|
|
3
3
|
import { BaseError } from "./baseError.js";
|
|
4
|
-
|
|
5
4
|
//#region src/errors/errors.d.ts
|
|
6
5
|
declare class RPCError extends BaseError {
|
|
7
6
|
constructor(code: LiFiErrorCode, message: string, cause?: Error);
|
|
@@ -25,10 +24,10 @@ declare class ValidationError extends BaseError {
|
|
|
25
24
|
constructor(message: string);
|
|
26
25
|
}
|
|
27
26
|
/**
|
|
28
|
-
* Thrown by a step executor when executeStep should be retried with the given params
|
|
29
|
-
* (e.g. wallet rejected 7702 upgrade → retry with atomicityNotReady).
|
|
30
|
-
* The execution layer catches this and retries executeStep(client, step, retryParams).
|
|
31
|
-
*/
|
|
27
|
+
* Thrown by a step executor when executeStep should be retried with the given params
|
|
28
|
+
* (e.g. wallet rejected 7702 upgrade → retry with atomicityNotReady).
|
|
29
|
+
* The execution layer catches this and retries executeStep(client, step, retryParams).
|
|
30
|
+
*/
|
|
32
31
|
declare class ExecuteStepRetryError extends BaseError {
|
|
33
32
|
readonly retryParams: ExecuteStepRetryParams;
|
|
34
33
|
constructor(message: string, retryParams: ExecuteStepRetryParams, cause?: Error);
|
|
@@ -2,7 +2,6 @@ import { ExtendedRequestInit } from "../types/request.js";
|
|
|
2
2
|
import { ErrorName } from "./constants.js";
|
|
3
3
|
import { BaseError } from "./baseError.js";
|
|
4
4
|
import { UnavailableRoutes } from "@lifi/types";
|
|
5
|
-
|
|
6
5
|
//#region src/errors/httpError.d.ts
|
|
7
6
|
interface ServerErrorResponseBody {
|
|
8
7
|
code: number;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -19,7 +19,6 @@ import { getTokenBalancesByChain } from "./actions/getTokenBalancesByChain.js";
|
|
|
19
19
|
import { getTokens } from "./actions/getTokens.js";
|
|
20
20
|
import { getTools } from "./actions/getTools.js";
|
|
21
21
|
import { getTransactionHistory } from "./actions/getTransactionHistory.js";
|
|
22
|
-
import { getWalletBalances } from "./actions/getWalletBalances.js";
|
|
23
22
|
import { patchContractCalls } from "./actions/patchContractCalls.js";
|
|
24
23
|
import { actions } from "./actions/index.js";
|
|
25
24
|
import { relayTransaction } from "./actions/relayTransaction.js";
|
|
@@ -53,4 +52,4 @@ import { waitForResult } from "./utils/waitForResult.js";
|
|
|
53
52
|
import { LruMap, withDedupe } from "./utils/withDedupe.js";
|
|
54
53
|
import { withTimeout } from "./utils/withTimeout.js";
|
|
55
54
|
export * from "@lifi/types";
|
|
56
|
-
export { type AcceptExchangeRateUpdateHook, type AcceptSlippageUpdateHook, type AcceptSlippageUpdateHookParams, BalanceError, BaseError, BaseStepExecutionTask, BaseStepExecutor, type CheckBalanceOptions, CheckBalanceTask, type ContractCallParams, type ContractTool, type ErrorCode, ErrorMessage, ErrorName, type ExchangeRateUpdateParams, ExecuteStepRetryError, type ExecuteStepRetryParams, type Execution, type ExecutionAction, type ExecutionActionStatus, type ExecutionActionType, type ExecutionOptions, type ExecutionStatus, type GetContractCallsHook, type GetContractCallsResult, type GetStatusRequestExtended, HTTPError, InMemoryStorage, type InteractionSettings, LiFiErrorCode, type LiFiStepExtended, type LiFiStepRequest, LocalStorageAdapter, LruMap, PrepareTransactionTask, ProviderError, type QuoteRequest, type QuoteRequestFromAmount, type QuoteRequestToAmount, RPCError, type RPCUrls, type RequestInterceptor, type RouteExecutionData, type RouteExecutionDataDictionary, type RouteExecutionDictionary, type RouteExtended, type SDKBaseConfig, type SDKClient, type SDKConfig, SDKError, type SDKProvider, type SDKStorage, ServerError, StatusManager, type StepExecutor, type StepExecutorBaseContext, type StepExecutorContext, type StepExecutorOptions, type StepExtended, TaskPipeline, type TaskResult, type TaskStatus, TransactionError, type TransactionMethodType, type TransactionParameters, type TransactionRequestParameters, type TransactionRequestUpdateHook, UnknownError, type UpdateRouteHook, ValidationError, WaitForTransactionStatusTask, actions, checkBalance, checkPackageUpdates, convertQuoteToRoute, createClient, createDefaultStorage, executeRoute, fetchTxErrorDetails, formatUnits, getActionMessage, getActiveRoute, getActiveRoutes, getChains, getConnections, getContractCallsQuote, getGasRecommendation, getNameServiceAddress, getQuote, getRelayedTransactionStatus, getRelayerQuote, getRoutes, getStatus, getStepTransaction, getSubstatusMessage, getToken, getTokenBalance, getTokenBalances, getTokenBalancesByChain, getTokens, getTools, getTransactionHistory, getTransactionRequestData,
|
|
55
|
+
export { type AcceptExchangeRateUpdateHook, type AcceptSlippageUpdateHook, type AcceptSlippageUpdateHookParams, BalanceError, BaseError, BaseStepExecutionTask, BaseStepExecutor, type CheckBalanceOptions, CheckBalanceTask, type ContractCallParams, type ContractTool, type ErrorCode, ErrorMessage, ErrorName, type ExchangeRateUpdateParams, ExecuteStepRetryError, type ExecuteStepRetryParams, type Execution, type ExecutionAction, type ExecutionActionStatus, type ExecutionActionType, type ExecutionOptions, type ExecutionStatus, type GetContractCallsHook, type GetContractCallsResult, type GetStatusRequestExtended, HTTPError, InMemoryStorage, type InteractionSettings, LiFiErrorCode, type LiFiStepExtended, type LiFiStepRequest, LocalStorageAdapter, LruMap, PrepareTransactionTask, ProviderError, type QuoteRequest, type QuoteRequestFromAmount, type QuoteRequestToAmount, RPCError, type RPCUrls, type RequestInterceptor, type RouteExecutionData, type RouteExecutionDataDictionary, type RouteExecutionDictionary, type RouteExtended, type SDKBaseConfig, type SDKClient, type SDKConfig, SDKError, type SDKProvider, type SDKStorage, ServerError, StatusManager, type StepExecutor, type StepExecutorBaseContext, type StepExecutorContext, type StepExecutorOptions, type StepExtended, TaskPipeline, type TaskResult, type TaskStatus, TransactionError, type TransactionMethodType, type TransactionParameters, type TransactionRequestParameters, type TransactionRequestUpdateHook, UnknownError, type UpdateRouteHook, ValidationError, WaitForTransactionStatusTask, actions, checkBalance, checkPackageUpdates, convertQuoteToRoute, createClient, createDefaultStorage, executeRoute, fetchTxErrorDetails, formatUnits, getActionMessage, getActiveRoute, getActiveRoutes, getChains, getConnections, getContractCallsQuote, getGasRecommendation, getNameServiceAddress, getQuote, getRelayedTransactionStatus, getRelayerQuote, getRoutes, getStatus, getStepTransaction, getSubstatusMessage, getToken, getTokenBalance, getTokenBalances, getTokenBalancesByChain, getTokens, getTools, getTransactionHistory, getTransactionRequestData, isHex, parseUnits, patchContractCalls, relayTransaction, resumeRoute, sleep, stepComparison, stopRouteExecution, updateRouteExecution, waitForResult, withDedupe, withTimeout };
|
package/dist/cjs/index.js
CHANGED
|
@@ -24,7 +24,6 @@ const require_actions_getTokenBalance = require("./actions/getTokenBalance.js");
|
|
|
24
24
|
const require_actions_getTokens = require("./actions/getTokens.js");
|
|
25
25
|
const require_actions_getTools = require("./actions/getTools.js");
|
|
26
26
|
const require_actions_getTransactionHistory = require("./actions/getTransactionHistory.js");
|
|
27
|
-
const require_actions_getWalletBalances = require("./actions/getWalletBalances.js");
|
|
28
27
|
const require_actions_patchContractCalls = require("./actions/patchContractCalls.js");
|
|
29
28
|
const require_actions_relayTransaction = require("./actions/relayTransaction.js");
|
|
30
29
|
const require_actions_index = require("./actions/index.js");
|
|
@@ -106,7 +105,6 @@ exports.getTokens = require_actions_getTokens.getTokens;
|
|
|
106
105
|
exports.getTools = require_actions_getTools.getTools;
|
|
107
106
|
exports.getTransactionHistory = require_actions_getTransactionHistory.getTransactionHistory;
|
|
108
107
|
exports.getTransactionRequestData = require_core_tasks_helpers_getTransactionRequestData.getTransactionRequestData;
|
|
109
|
-
exports.getWalletBalances = require_actions_getWalletBalances.getWalletBalances;
|
|
110
108
|
exports.isHex = require_utils_isHex.isHex;
|
|
111
109
|
exports.parseUnits = require_utils_parseUnits.parseUnits;
|
|
112
110
|
exports.patchContractCalls = require_actions_patchContractCalls.patchContractCalls;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { Action, GetStatusRequest, LiFiStep, QuoteRequest as QuoteRequest$1, RoutesRequest as RoutesRequest$1, SignedLiFiStep } from "@lifi/types";
|
|
2
|
-
|
|
3
2
|
//#region src/types/actions.d.ts
|
|
4
3
|
type GetStatusRequestExtended = GetStatusRequest & {
|
|
5
4
|
fromAddress?: string;
|
|
6
5
|
};
|
|
7
6
|
/**
|
|
8
|
-
* Optional limit-order fields. Supplying them opts a request into limit-order
|
|
9
|
-
* handling; resolution happens on the backend.
|
|
10
|
-
*/
|
|
7
|
+
* Optional limit-order fields. Supplying them opts a request into limit-order
|
|
8
|
+
* handling; resolution happens on the backend.
|
|
9
|
+
*/
|
|
11
10
|
type OrderFields = {
|
|
12
11
|
toAmount?: string;
|
|
13
12
|
validUntil?: number;
|
|
@@ -15,12 +14,13 @@ type OrderFields = {
|
|
|
15
14
|
};
|
|
16
15
|
type RoutesRequest = Omit<RoutesRequest$1, "options"> & OrderFields & {
|
|
17
16
|
options?: RoutesRequest$1["options"] & {
|
|
18
|
-
/** (default: false) Whether to request private routes */
|
|
17
|
+
/** (default: false) Whether to request private routes */
|
|
18
|
+
private?: boolean;
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
|
-
* A step request that may carry the optional limit-order `action` fields.
|
|
23
|
-
*/
|
|
22
|
+
* A step request that may carry the optional limit-order `action` fields.
|
|
23
|
+
*/
|
|
24
24
|
type LiFiStepRequest = (LiFiStep | SignedLiFiStep) & {
|
|
25
25
|
action: Action & OrderFields;
|
|
26
26
|
};
|
package/dist/cjs/types/core.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { SDKStorage } from "../core/storage.js";
|
|
2
2
|
import { ExtendedRequestInit } from "./request.js";
|
|
3
3
|
import { ChainId, ChainType, CoinKey, ContractCall, ExtendedChain, FeeCost, GasCost, LiFiStep, Route, RouteOptions, Step, Substatus, Token, TokenAmount } from "@lifi/types";
|
|
4
|
-
|
|
5
4
|
//#region src/types/core.d.ts
|
|
6
5
|
type RequestInterceptor = (request: ExtendedRequestInit) => ExtendedRequestInit | Promise<ExtendedRequestInit>;
|
|
7
6
|
interface SDKBaseConfig {
|
|
@@ -53,9 +52,9 @@ interface InteractionSettings {
|
|
|
53
52
|
allowExecution?: boolean;
|
|
54
53
|
}
|
|
55
54
|
/**
|
|
56
|
-
* Params passed when retrying executeStep after an ExecuteStepRetryError.
|
|
57
|
-
* Providers can use this to pass strategy-specific retry options (e.g. atomicityNotReady for Ethereum 7702).
|
|
58
|
-
*/
|
|
55
|
+
* Params passed when retrying executeStep after an ExecuteStepRetryError.
|
|
56
|
+
* Providers can use this to pass strategy-specific retry options (e.g. atomicityNotReady for Ethereum 7702).
|
|
57
|
+
*/
|
|
59
58
|
type ExecuteStepRetryParams = Record<string, unknown>;
|
|
60
59
|
interface StepExecutor {
|
|
61
60
|
allowUserInteraction: boolean;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ExecuteStepRetryParams, ExecutionOptions, LiFiStepExtended, SDKClient } from "./core.js";
|
|
2
2
|
import { StatusManager } from "../core/StatusManager.js";
|
|
3
3
|
import { ExtendedChain } from "@lifi/types";
|
|
4
|
-
|
|
5
4
|
//#region src/types/execution.d.ts
|
|
6
5
|
interface StepExecutorBaseContext {
|
|
7
6
|
statusManager: StatusManager;
|
|
@@ -5,7 +5,7 @@ const checkPackageUpdates = async (packageName, packageVersion) => {
|
|
|
5
5
|
try {
|
|
6
6
|
const pkgName = packageName ?? "@lifi/sdk";
|
|
7
7
|
const latestVersion = (await (await fetch(`https://registry.npmjs.org/${pkgName}/latest`)).json()).version;
|
|
8
|
-
const currentVersion = packageVersion ?? "4.
|
|
8
|
+
const currentVersion = packageVersion ?? "4.3.0";
|
|
9
9
|
if (latestVersion > currentVersion) console.warn(`${pkgName}: new package version is available. Please update as soon as possible to enjoy the newest features. Current version: ${currentVersion}. Latest version: ${latestVersion}.`);
|
|
10
10
|
} catch (_error) {}
|
|
11
11
|
};
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { LiFiStep, Route } from "@lifi/types";
|
|
2
|
-
|
|
3
2
|
//#region src/utils/convertQuoteToRoute.d.ts
|
|
4
3
|
interface ConvertQuoteToRouteOptions {
|
|
5
4
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
* When true, if the quote has zero output values (toAmount, toAmountMin, toAmountUSD),
|
|
6
|
+
* use the values from the previous included step that has non-zero output.
|
|
7
|
+
*/
|
|
9
8
|
adjustZeroOutputFromPreviousStep?: boolean;
|
|
10
9
|
}
|
|
11
10
|
declare function formatTokenPrice(amount?: string | bigint, price?: string, decimals?: number): number;
|
|
12
11
|
/**
|
|
13
|
-
* Converts a quote to Route
|
|
14
|
-
* @param quote - Step returned from the quote endpoint.
|
|
15
|
-
* @param options - Optional configuration for handling edge cases.
|
|
16
|
-
* @returns - The route to be executed.
|
|
17
|
-
* @throws {BaseError} Throws a ValidationError if the step has missing values.
|
|
18
|
-
*/
|
|
12
|
+
* Converts a quote to Route
|
|
13
|
+
* @param quote - Step returned from the quote endpoint.
|
|
14
|
+
* @param options - Optional configuration for handling edge cases.
|
|
15
|
+
* @returns - The route to be executed.
|
|
16
|
+
* @throws {BaseError} Throws a ValidationError if the step has missing values.
|
|
17
|
+
*/
|
|
19
18
|
declare const convertQuoteToRoute: (quote: LiFiStep, options?: ConvertQuoteToRouteOptions) => Route;
|
|
20
19
|
//#endregion
|
|
21
20
|
export { convertQuoteToRoute, formatTokenPrice };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/utils/formatUnits.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* Divides a number by a given exponent of base 10 (10exponent), and formats it into a string representation of the number.
|
|
4
|
-
*/
|
|
3
|
+
* Divides a number by a given exponent of base 10 (10exponent), and formats it into a string representation of the number.
|
|
4
|
+
*/
|
|
5
5
|
declare function formatUnits(value: bigint, decimals: number): string;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { formatUnits };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { SDKClient } from "../types/core.js";
|
|
2
2
|
import { LiFiStep } from "@lifi/types";
|
|
3
|
-
|
|
4
3
|
//#region src/utils/getTransactionMessage.d.ts
|
|
5
4
|
declare const getTransactionFailedMessage: (client: SDKClient, step: LiFiStep, txLink?: string) => Promise<string>;
|
|
6
5
|
//#endregion
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/utils/parseUnits.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* Multiplies a string representation of a number by a given exponent of base 10 (10exponent).
|
|
4
|
-
*/
|
|
3
|
+
* Multiplies a string representation of a number by a given exponent of base 10 (10exponent).
|
|
4
|
+
*/
|
|
5
5
|
declare function parseUnits(value: string, decimals: number): bigint;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { parseUnits };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
//#region src/utils/waitForResult.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* Repeatedly calls a given asynchronous function until it resolves with a value
|
|
4
|
-
* @param fn The function that should be repeated
|
|
5
|
-
* @param interval The timeout in milliseconds between retries, or a function that receives the current poll count and returns the interval. Defaults to 5000
|
|
6
|
-
* @param maxRetries Maximum number of retries before throwing an error, defaults to 3
|
|
7
|
-
* @param shouldRetry Optional predicate to determine if an error should trigger a retry
|
|
8
|
-
* @returns The result of the fn function
|
|
9
|
-
* @throws Error if maximum retries is reached, if function keeps returning undefined, or if shouldRetry returns false
|
|
10
|
-
*/
|
|
3
|
+
* Repeatedly calls a given asynchronous function until it resolves with a value
|
|
4
|
+
* @param fn The function that should be repeated
|
|
5
|
+
* @param interval The timeout in milliseconds between retries, or a function that receives the current poll count and returns the interval. Defaults to 5000
|
|
6
|
+
* @param maxRetries Maximum number of retries before throwing an error, defaults to 3
|
|
7
|
+
* @param shouldRetry Optional predicate to determine if an error should trigger a retry
|
|
8
|
+
* @returns The result of the fn function
|
|
9
|
+
* @throws Error if maximum retries is reached, if function keeps returning undefined, or if shouldRetry returns false
|
|
10
|
+
*/
|
|
11
11
|
declare const waitForResult: <T>(fn: () => Promise<T | undefined>, interval?: number | ((poll: number) => number), maxRetries?: number, shouldRetry?: (count: number, error: unknown) => boolean) => Promise<T>;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { waitForResult };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
//#region src/utils/withDedupe.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* Map with a LRU (Least recently used) policy.
|
|
4
|
-
*
|
|
5
|
-
* https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU
|
|
6
|
-
*/
|
|
3
|
+
* Map with a LRU (Least recently used) policy.
|
|
4
|
+
*
|
|
5
|
+
* https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU
|
|
6
|
+
*/
|
|
7
7
|
declare class LruMap<value = unknown> extends Map<string, value> {
|
|
8
8
|
maxSize: number;
|
|
9
9
|
constructor(size: number);
|
|
@@ -14,10 +14,7 @@ type WithDedupeOptions = {
|
|
|
14
14
|
id?: string | undefined;
|
|
15
15
|
};
|
|
16
16
|
/** Deduplicates in-flight promises. */
|
|
17
|
-
declare function withDedupe<T>(fn: () => Promise<T>, {
|
|
18
|
-
enabled,
|
|
19
|
-
id
|
|
20
|
-
}: WithDedupeOptions): Promise<T>;
|
|
17
|
+
declare function withDedupe<T>(fn: () => Promise<T>, { enabled, id }: WithDedupeOptions): Promise<T>;
|
|
21
18
|
//#endregion
|
|
22
19
|
export { LruMap, withDedupe };
|
|
23
20
|
//# sourceMappingURL=withDedupe.d.ts.map
|
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
//#region src/utils/withTimeout.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* Wraps a function in a timeout.
|
|
4
|
-
* Based on viem's withTimeout implementation.
|
|
5
|
-
* @param fn - The function to wrap.
|
|
6
|
-
* @param timeout - The timeout in milliseconds.
|
|
7
|
-
* @param errorInstance - The error instance to throw when the timeout is reached.
|
|
8
|
-
* @param signal - Whether or not the timeout should use an abort signal.
|
|
9
|
-
* @returns The result of the function.
|
|
10
|
-
*/
|
|
11
|
-
declare function withTimeout<T>(fn: ({
|
|
12
|
-
signal
|
|
13
|
-
}: {
|
|
3
|
+
* Wraps a function in a timeout.
|
|
4
|
+
* Based on viem's withTimeout implementation.
|
|
5
|
+
* @param fn - The function to wrap.
|
|
6
|
+
* @param timeout - The timeout in milliseconds.
|
|
7
|
+
* @param errorInstance - The error instance to throw when the timeout is reached.
|
|
8
|
+
* @param signal - Whether or not the timeout should use an abort signal.
|
|
9
|
+
* @returns The result of the function.
|
|
10
|
+
*/
|
|
11
|
+
declare function withTimeout<T>(fn: ({ signal }: {
|
|
14
12
|
signal: AbortController["signal"] | null;
|
|
15
|
-
}) => Promise<T>, {
|
|
16
|
-
errorInstance,
|
|
17
|
-
timeout,
|
|
18
|
-
signal
|
|
19
|
-
}: {
|
|
13
|
+
}) => Promise<T>, { errorInstance, timeout, signal }: {
|
|
20
14
|
errorInstance?: Error | undefined;
|
|
21
15
|
timeout: number;
|
|
22
16
|
signal?: boolean | undefined;
|
package/dist/cjs/version.d.ts
CHANGED
package/dist/cjs/version.js
CHANGED
package/dist/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk'\nexport const version = '4.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk'\nexport const version = '4.3.0'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|