@lifi/sdk 0.0.0-preview-f5cf9f8
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 +1213 -0
- package/LICENSE +201 -0
- package/README.md +79 -0
- package/dist/cjs/actions/getChains.d.ts +17 -0
- package/dist/cjs/actions/getChains.js +28 -0
- package/dist/cjs/actions/getChains.js.map +1 -0
- package/dist/cjs/actions/getConnections.d.ts +15 -0
- package/dist/cjs/actions/getConnections.js +34 -0
- package/dist/cjs/actions/getConnections.js.map +1 -0
- package/dist/cjs/actions/getContractCallsQuote.d.ts +16 -0
- package/dist/cjs/actions/getContractCallsQuote.js +45 -0
- package/dist/cjs/actions/getContractCallsQuote.js.map +1 -0
- package/dist/cjs/actions/getGasRecommendation.d.ts +16 -0
- package/dist/cjs/actions/getGasRecommendation.js +24 -0
- package/dist/cjs/actions/getGasRecommendation.js.map +1 -0
- package/dist/cjs/actions/getNameServiceAddress.d.ts +15 -0
- package/dist/cjs/actions/getNameServiceAddress.js +29 -0
- package/dist/cjs/actions/getNameServiceAddress.js.map +1 -0
- package/dist/cjs/actions/getQuote.d.ts +18 -0
- package/dist/cjs/actions/getQuote.js +35 -0
- package/dist/cjs/actions/getQuote.js.map +1 -0
- package/dist/cjs/actions/getRelayedTransactionStatus.d.ts +16 -0
- package/dist/cjs/actions/getRelayedTransactionStatus.js +30 -0
- package/dist/cjs/actions/getRelayedTransactionStatus.js.map +1 -0
- package/dist/cjs/actions/getRelayerQuote.d.ts +17 -0
- package/dist/cjs/actions/getRelayerQuote.js +44 -0
- package/dist/cjs/actions/getRelayerQuote.js.map +1 -0
- package/dist/cjs/actions/getRoutes.d.ts +16 -0
- package/dist/cjs/actions/getRoutes.js +32 -0
- package/dist/cjs/actions/getRoutes.js.map +1 -0
- package/dist/cjs/actions/getStatus.d.ts +17 -0
- package/dist/cjs/actions/getStatus.js +22 -0
- package/dist/cjs/actions/getStatus.js.map +1 -0
- package/dist/cjs/actions/getStepTransaction.d.ts +16 -0
- package/dist/cjs/actions/getStepTransaction.js +36 -0
- package/dist/cjs/actions/getStepTransaction.js.map +1 -0
- package/dist/cjs/actions/getToken.d.ts +17 -0
- package/dist/cjs/actions/getToken.js +26 -0
- package/dist/cjs/actions/getToken.js.map +1 -0
- package/dist/cjs/actions/getTokenBalance.d.ts +17 -0
- package/dist/cjs/actions/getTokenBalance.js +20 -0
- package/dist/cjs/actions/getTokenBalance.js.map +1 -0
- package/dist/cjs/actions/getTokenBalances.d.ts +17 -0
- package/dist/cjs/actions/getTokenBalances.js +15 -0
- package/dist/cjs/actions/getTokenBalances.js.map +1 -0
- package/dist/cjs/actions/getTokenBalancesByChain.d.ts +21 -0
- package/dist/cjs/actions/getTokenBalancesByChain.js +25 -0
- package/dist/cjs/actions/getTokenBalancesByChain.js.map +1 -0
- package/dist/cjs/actions/getTokens.d.ts +20 -0
- package/dist/cjs/actions/getTokens.js +17 -0
- package/dist/cjs/actions/getTokens.js.map +1 -0
- package/dist/cjs/actions/getTools.d.ts +15 -0
- package/dist/cjs/actions/getTools.js +21 -0
- package/dist/cjs/actions/getTools.js.map +1 -0
- package/dist/cjs/actions/getTransactionHistory.d.ts +26 -0
- package/dist/cjs/actions/getTransactionHistory.js +31 -0
- package/dist/cjs/actions/getTransactionHistory.js.map +1 -0
- package/dist/cjs/actions/getWalletBalances.d.ts +16 -0
- package/dist/cjs/actions/getWalletBalances.js +20 -0
- package/dist/cjs/actions/getWalletBalances.js.map +1 -0
- package/dist/cjs/actions/index.d.ts +172 -0
- package/dist/cjs/actions/index.js +52 -0
- package/dist/cjs/actions/index.js.map +1 -0
- package/dist/cjs/actions/patchContractCalls.d.ts +15 -0
- package/dist/cjs/actions/patchContractCalls.js +15 -0
- package/dist/cjs/actions/patchContractCalls.js.map +1 -0
- package/dist/cjs/actions/relayTransaction.d.ts +16 -0
- package/dist/cjs/actions/relayTransaction.js +34 -0
- package/dist/cjs/actions/relayTransaction.js.map +1 -0
- package/dist/cjs/client/createClient.d.ts +7 -0
- package/dist/cjs/client/createClient.js +70 -0
- package/dist/cjs/client/createClient.js.map +1 -0
- package/dist/cjs/client/getClientStorage.d.ts +14 -0
- package/dist/cjs/client/getClientStorage.js +48 -0
- package/dist/cjs/client/getClientStorage.js.map +1 -0
- package/dist/cjs/core/BaseStepExecutionTask.d.ts +10 -0
- package/dist/cjs/core/BaseStepExecutionTask.js +11 -0
- package/dist/cjs/core/BaseStepExecutionTask.js.map +1 -0
- package/dist/cjs/core/BaseStepExecutor.d.ts +24 -0
- package/dist/cjs/core/BaseStepExecutor.js +71 -0
- package/dist/cjs/core/BaseStepExecutor.js.map +1 -0
- package/dist/cjs/core/StatusManager.d.ts +83 -0
- package/dist/cjs/core/StatusManager.js +160 -0
- package/dist/cjs/core/StatusManager.js.map +1 -0
- package/dist/cjs/core/TaskPipeline.d.ts +12 -0
- package/dist/cjs/core/TaskPipeline.js +21 -0
- package/dist/cjs/core/TaskPipeline.js.map +1 -0
- package/dist/cjs/core/actionMessages.d.ts +9 -0
- package/dist/cjs/core/actionMessages.js +81 -0
- package/dist/cjs/core/actionMessages.js.map +1 -0
- package/dist/cjs/core/execution.d.ts +48 -0
- package/dist/cjs/core/execution.js +147 -0
- package/dist/cjs/core/execution.js.map +1 -0
- package/dist/cjs/core/executionState.d.ts +21 -0
- package/dist/cjs/core/executionState.js +29 -0
- package/dist/cjs/core/executionState.js.map +1 -0
- package/dist/cjs/core/prepareRestart.d.ts +7 -0
- package/dist/cjs/core/prepareRestart.js +21 -0
- package/dist/cjs/core/prepareRestart.js.map +1 -0
- package/dist/cjs/core/storage.d.ts +21 -0
- package/dist/cjs/core/storage.js +35 -0
- package/dist/cjs/core/storage.js.map +1 -0
- package/dist/cjs/core/tasks/CheckBalanceTask.d.ts +19 -0
- package/dist/cjs/core/tasks/CheckBalanceTask.js +35 -0
- package/dist/cjs/core/tasks/CheckBalanceTask.js.map +1 -0
- package/dist/cjs/core/tasks/PrepareTransactionTask.d.ts +10 -0
- package/dist/cjs/core/tasks/PrepareTransactionTask.js +30 -0
- package/dist/cjs/core/tasks/PrepareTransactionTask.js.map +1 -0
- package/dist/cjs/core/tasks/WaitForTransactionStatusTask.d.ts +13 -0
- package/dist/cjs/core/tasks/WaitForTransactionStatusTask.js +63 -0
- package/dist/cjs/core/tasks/WaitForTransactionStatusTask.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/checkBalance.d.ts +30 -0
- package/dist/cjs/core/tasks/helpers/checkBalance.js +108 -0
- package/dist/cjs/core/tasks/helpers/checkBalance.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/getTransactionRequestData.d.ts +7 -0
- package/dist/cjs/core/tasks/helpers/getTransactionRequestData.js +25 -0
- package/dist/cjs/core/tasks/helpers/getTransactionRequestData.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/stepComparison.d.ts +21 -0
- package/dist/cjs/core/tasks/helpers/stepComparison.js +32 -0
- package/dist/cjs/core/tasks/helpers/stepComparison.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.d.ts +9 -0
- package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.js +48 -0
- package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.js.map +1 -0
- package/dist/cjs/core/utils.d.ts +17 -0
- package/dist/cjs/core/utils.js +42 -0
- package/dist/cjs/core/utils.js.map +1 -0
- package/dist/cjs/errors/SDKError.d.ts +17 -0
- package/dist/cjs/errors/SDKError.js +24 -0
- package/dist/cjs/errors/SDKError.js.map +1 -0
- package/dist/cjs/errors/baseError.d.ts +11 -0
- package/dist/cjs/errors/baseError.js +19 -0
- package/dist/cjs/errors/baseError.js.map +1 -0
- package/dist/cjs/errors/constants.d.ts +55 -0
- package/dist/cjs/errors/constants.js +61 -0
- package/dist/cjs/errors/constants.js.map +1 -0
- package/dist/cjs/errors/errors.d.ts +38 -0
- package/dist/cjs/errors/errors.js +62 -0
- package/dist/cjs/errors/errors.js.map +1 -0
- package/dist/cjs/errors/httpError.d.ts +24 -0
- package/dist/cjs/errors/httpError.js +70 -0
- package/dist/cjs/errors/httpError.js.map +1 -0
- package/dist/cjs/errors/utils/baseErrorRootCause.d.ts +8 -0
- package/dist/cjs/errors/utils/baseErrorRootCause.js +18 -0
- package/dist/cjs/errors/utils/baseErrorRootCause.js.map +1 -0
- package/dist/cjs/errors/utils/rootCause.d.ts +5 -0
- package/dist/cjs/errors/utils/rootCause.js +11 -0
- package/dist/cjs/errors/utils/rootCause.js.map +1 -0
- package/dist/cjs/index.d.ts +55 -0
- package/dist/cjs/index.js +130 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types/actions.d.ts +14 -0
- package/dist/cjs/types/actions.js +0 -0
- package/dist/cjs/types/core.d.ts +184 -0
- package/dist/cjs/types/core.js +0 -0
- package/dist/cjs/types/execution.d.ts +28 -0
- package/dist/cjs/types/execution.js +0 -0
- package/dist/cjs/types/request.d.ts +7 -0
- package/dist/cjs/types/request.js +0 -0
- package/dist/cjs/utils/checkPackageUpdates.d.ts +5 -0
- package/dist/cjs/utils/checkPackageUpdates.js +15 -0
- package/dist/cjs/utils/checkPackageUpdates.js.map +1 -0
- package/dist/cjs/utils/convertQuoteToRoute.d.ts +22 -0
- package/dist/cjs/utils/convertQuoteToRoute.js +88 -0
- package/dist/cjs/utils/convertQuoteToRoute.js.map +1 -0
- package/dist/cjs/utils/decode.d.ts +5 -0
- package/dist/cjs/utils/decode.js +9 -0
- package/dist/cjs/utils/decode.js.map +1 -0
- package/dist/cjs/utils/fetchTxErrorDetails.d.ts +5 -0
- package/dist/cjs/utils/fetchTxErrorDetails.js +13 -0
- package/dist/cjs/utils/fetchTxErrorDetails.js.map +1 -0
- package/dist/cjs/utils/formatUnits.d.ts +8 -0
- package/dist/cjs/utils/formatUnits.js +18 -0
- package/dist/cjs/utils/formatUnits.js.map +1 -0
- package/dist/cjs/utils/getTransactionMessage.d.ts +8 -0
- package/dist/cjs/utils/getTransactionMessage.js +12 -0
- package/dist/cjs/utils/getTransactionMessage.js.map +1 -0
- package/dist/cjs/utils/isHex.d.ts +10 -0
- package/dist/cjs/utils/isHex.js +11 -0
- package/dist/cjs/utils/isHex.js.map +1 -0
- package/dist/cjs/utils/isRoutesRequest.d.ts +7 -0
- package/dist/cjs/utils/isRoutesRequest.js +11 -0
- package/dist/cjs/utils/isRoutesRequest.js.map +1 -0
- package/dist/cjs/utils/isStep.d.ts +7 -0
- package/dist/cjs/utils/isStep.js +23 -0
- package/dist/cjs/utils/isStep.js.map +1 -0
- package/dist/cjs/utils/isToken.d.ts +7 -0
- package/dist/cjs/utils/isToken.js +10 -0
- package/dist/cjs/utils/isToken.js.map +1 -0
- package/dist/cjs/utils/parseUnits.d.ts +8 -0
- package/dist/cjs/utils/parseUnits.js +35 -0
- package/dist/cjs/utils/parseUnits.js.map +1 -0
- package/dist/cjs/utils/request.d.ts +11 -0
- package/dist/cjs/utils/request.js +56 -0
- package/dist/cjs/utils/request.js.map +1 -0
- package/dist/cjs/utils/sleep.d.ts +5 -0
- package/dist/cjs/utils/sleep.js +11 -0
- package/dist/cjs/utils/sleep.js.map +1 -0
- package/dist/cjs/utils/waitForResult.d.ts +14 -0
- package/dist/cjs/utils/waitForResult.js +36 -0
- package/dist/cjs/utils/waitForResult.js.map +1 -0
- package/dist/cjs/utils/withDedupe.d.ts +23 -0
- package/dist/cjs/utils/withDedupe.js +34 -0
- package/dist/cjs/utils/withDedupe.js.map +1 -0
- package/dist/cjs/utils/withTimeout.d.ts +26 -0
- package/dist/cjs/utils/withTimeout.js +35 -0
- package/dist/cjs/utils/withTimeout.js.map +1 -0
- package/dist/cjs/version.d.ts +6 -0
- package/dist/cjs/version.js +9 -0
- package/dist/cjs/version.js.map +1 -0
- package/dist/esm/actions/getChains.d.ts +17 -0
- package/dist/esm/actions/getChains.d.ts.map +1 -0
- package/dist/esm/actions/getChains.js +26 -0
- package/dist/esm/actions/getChains.js.map +1 -0
- package/dist/esm/actions/getConnections.d.ts +15 -0
- package/dist/esm/actions/getConnections.d.ts.map +1 -0
- package/dist/esm/actions/getConnections.js +33 -0
- package/dist/esm/actions/getConnections.js.map +1 -0
- package/dist/esm/actions/getContractCallsQuote.d.ts +16 -0
- package/dist/esm/actions/getContractCallsQuote.d.ts.map +1 -0
- package/dist/esm/actions/getContractCallsQuote.js +44 -0
- package/dist/esm/actions/getContractCallsQuote.js.map +1 -0
- package/dist/esm/actions/getGasRecommendation.d.ts +16 -0
- package/dist/esm/actions/getGasRecommendation.d.ts.map +1 -0
- package/dist/esm/actions/getGasRecommendation.js +23 -0
- package/dist/esm/actions/getGasRecommendation.js.map +1 -0
- package/dist/esm/actions/getNameServiceAddress.d.ts +15 -0
- package/dist/esm/actions/getNameServiceAddress.d.ts.map +1 -0
- package/dist/esm/actions/getNameServiceAddress.js +28 -0
- package/dist/esm/actions/getNameServiceAddress.js.map +1 -0
- package/dist/esm/actions/getQuote.d.ts +18 -0
- package/dist/esm/actions/getQuote.d.ts.map +1 -0
- package/dist/esm/actions/getQuote.js +34 -0
- package/dist/esm/actions/getQuote.js.map +1 -0
- package/dist/esm/actions/getRelayedTransactionStatus.d.ts +16 -0
- package/dist/esm/actions/getRelayedTransactionStatus.d.ts.map +1 -0
- package/dist/esm/actions/getRelayedTransactionStatus.js +29 -0
- package/dist/esm/actions/getRelayedTransactionStatus.js.map +1 -0
- package/dist/esm/actions/getRelayerQuote.d.ts +17 -0
- package/dist/esm/actions/getRelayerQuote.d.ts.map +1 -0
- package/dist/esm/actions/getRelayerQuote.js +43 -0
- package/dist/esm/actions/getRelayerQuote.js.map +1 -0
- package/dist/esm/actions/getRoutes.d.ts +16 -0
- package/dist/esm/actions/getRoutes.d.ts.map +1 -0
- package/dist/esm/actions/getRoutes.js +31 -0
- package/dist/esm/actions/getRoutes.js.map +1 -0
- package/dist/esm/actions/getStatus.d.ts +17 -0
- package/dist/esm/actions/getStatus.d.ts.map +1 -0
- package/dist/esm/actions/getStatus.js +21 -0
- package/dist/esm/actions/getStatus.js.map +1 -0
- package/dist/esm/actions/getStepTransaction.d.ts +16 -0
- package/dist/esm/actions/getStepTransaction.d.ts.map +1 -0
- package/dist/esm/actions/getStepTransaction.js +35 -0
- package/dist/esm/actions/getStepTransaction.js.map +1 -0
- package/dist/esm/actions/getToken.d.ts +17 -0
- package/dist/esm/actions/getToken.d.ts.map +1 -0
- package/dist/esm/actions/getToken.js +25 -0
- package/dist/esm/actions/getToken.js.map +1 -0
- package/dist/esm/actions/getTokenBalance.d.ts +17 -0
- package/dist/esm/actions/getTokenBalance.d.ts.map +1 -0
- package/dist/esm/actions/getTokenBalance.js +19 -0
- package/dist/esm/actions/getTokenBalance.js.map +1 -0
- package/dist/esm/actions/getTokenBalances.d.ts +17 -0
- package/dist/esm/actions/getTokenBalances.d.ts.map +1 -0
- package/dist/esm/actions/getTokenBalances.js +14 -0
- package/dist/esm/actions/getTokenBalances.js.map +1 -0
- package/dist/esm/actions/getTokenBalancesByChain.d.ts +21 -0
- package/dist/esm/actions/getTokenBalancesByChain.d.ts.map +1 -0
- package/dist/esm/actions/getTokenBalancesByChain.js +24 -0
- package/dist/esm/actions/getTokenBalancesByChain.js.map +1 -0
- package/dist/esm/actions/getTokens.d.ts +20 -0
- package/dist/esm/actions/getTokens.d.ts.map +1 -0
- package/dist/esm/actions/getTokens.js +16 -0
- package/dist/esm/actions/getTokens.js.map +1 -0
- package/dist/esm/actions/getTools.d.ts +15 -0
- package/dist/esm/actions/getTools.d.ts.map +1 -0
- package/dist/esm/actions/getTools.js +20 -0
- package/dist/esm/actions/getTools.js.map +1 -0
- package/dist/esm/actions/getTransactionHistory.d.ts +26 -0
- package/dist/esm/actions/getTransactionHistory.d.ts.map +1 -0
- package/dist/esm/actions/getTransactionHistory.js +30 -0
- package/dist/esm/actions/getTransactionHistory.js.map +1 -0
- package/dist/esm/actions/getWalletBalances.d.ts +16 -0
- package/dist/esm/actions/getWalletBalances.d.ts.map +1 -0
- package/dist/esm/actions/getWalletBalances.js +19 -0
- package/dist/esm/actions/getWalletBalances.js.map +1 -0
- package/dist/esm/actions/index.d.ts +172 -0
- package/dist/esm/actions/index.d.ts.map +1 -0
- package/dist/esm/actions/index.js +51 -0
- package/dist/esm/actions/index.js.map +1 -0
- package/dist/esm/actions/patchContractCalls.d.ts +15 -0
- package/dist/esm/actions/patchContractCalls.d.ts.map +1 -0
- package/dist/esm/actions/patchContractCalls.js +14 -0
- package/dist/esm/actions/patchContractCalls.js.map +1 -0
- package/dist/esm/actions/relayTransaction.d.ts +16 -0
- package/dist/esm/actions/relayTransaction.d.ts.map +1 -0
- package/dist/esm/actions/relayTransaction.js +33 -0
- package/dist/esm/actions/relayTransaction.js.map +1 -0
- package/dist/esm/client/createClient.d.ts +7 -0
- package/dist/esm/client/createClient.d.ts.map +1 -0
- package/dist/esm/client/createClient.js +69 -0
- package/dist/esm/client/createClient.js.map +1 -0
- package/dist/esm/client/getClientStorage.d.ts +14 -0
- package/dist/esm/client/getClientStorage.d.ts.map +1 -0
- package/dist/esm/client/getClientStorage.js +47 -0
- package/dist/esm/client/getClientStorage.js.map +1 -0
- package/dist/esm/core/BaseStepExecutionTask.d.ts +10 -0
- package/dist/esm/core/BaseStepExecutionTask.d.ts.map +1 -0
- package/dist/esm/core/BaseStepExecutionTask.js +10 -0
- package/dist/esm/core/BaseStepExecutionTask.js.map +1 -0
- package/dist/esm/core/BaseStepExecutor.d.ts +24 -0
- package/dist/esm/core/BaseStepExecutor.d.ts.map +1 -0
- package/dist/esm/core/BaseStepExecutor.js +70 -0
- package/dist/esm/core/BaseStepExecutor.js.map +1 -0
- package/dist/esm/core/StatusManager.d.ts +83 -0
- package/dist/esm/core/StatusManager.d.ts.map +1 -0
- package/dist/esm/core/StatusManager.js +159 -0
- package/dist/esm/core/StatusManager.js.map +1 -0
- package/dist/esm/core/TaskPipeline.d.ts +12 -0
- package/dist/esm/core/TaskPipeline.d.ts.map +1 -0
- package/dist/esm/core/TaskPipeline.js +20 -0
- package/dist/esm/core/TaskPipeline.js.map +1 -0
- package/dist/esm/core/actionMessages.d.ts +9 -0
- package/dist/esm/core/actionMessages.d.ts.map +1 -0
- package/dist/esm/core/actionMessages.js +79 -0
- package/dist/esm/core/actionMessages.js.map +1 -0
- package/dist/esm/core/execution.d.ts +48 -0
- package/dist/esm/core/execution.d.ts.map +1 -0
- package/dist/esm/core/execution.js +141 -0
- package/dist/esm/core/execution.js.map +1 -0
- package/dist/esm/core/executionState.d.ts +21 -0
- package/dist/esm/core/executionState.d.ts.map +1 -0
- package/dist/esm/core/executionState.js +28 -0
- package/dist/esm/core/executionState.js.map +1 -0
- package/dist/esm/core/prepareRestart.d.ts +7 -0
- package/dist/esm/core/prepareRestart.d.ts.map +1 -0
- package/dist/esm/core/prepareRestart.js +20 -0
- package/dist/esm/core/prepareRestart.js.map +1 -0
- package/dist/esm/core/storage.d.ts +21 -0
- package/dist/esm/core/storage.d.ts.map +1 -0
- package/dist/esm/core/storage.js +32 -0
- package/dist/esm/core/storage.js.map +1 -0
- package/dist/esm/core/tasks/CheckBalanceTask.d.ts +19 -0
- package/dist/esm/core/tasks/CheckBalanceTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/CheckBalanceTask.js +34 -0
- package/dist/esm/core/tasks/CheckBalanceTask.js.map +1 -0
- package/dist/esm/core/tasks/PrepareTransactionTask.d.ts +10 -0
- package/dist/esm/core/tasks/PrepareTransactionTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/PrepareTransactionTask.js +29 -0
- package/dist/esm/core/tasks/PrepareTransactionTask.js.map +1 -0
- package/dist/esm/core/tasks/WaitForTransactionStatusTask.d.ts +13 -0
- package/dist/esm/core/tasks/WaitForTransactionStatusTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/WaitForTransactionStatusTask.js +61 -0
- package/dist/esm/core/tasks/WaitForTransactionStatusTask.js.map +1 -0
- package/dist/esm/core/tasks/helpers/checkBalance.d.ts +30 -0
- package/dist/esm/core/tasks/helpers/checkBalance.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/checkBalance.js +107 -0
- package/dist/esm/core/tasks/helpers/checkBalance.js.map +1 -0
- package/dist/esm/core/tasks/helpers/getTransactionRequestData.d.ts +7 -0
- package/dist/esm/core/tasks/helpers/getTransactionRequestData.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/getTransactionRequestData.js +24 -0
- package/dist/esm/core/tasks/helpers/getTransactionRequestData.js.map +1 -0
- package/dist/esm/core/tasks/helpers/stepComparison.d.ts +21 -0
- package/dist/esm/core/tasks/helpers/stepComparison.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/stepComparison.js +31 -0
- package/dist/esm/core/tasks/helpers/stepComparison.js.map +1 -0
- package/dist/esm/core/tasks/helpers/waitForTransactionStatus.d.ts +9 -0
- package/dist/esm/core/tasks/helpers/waitForTransactionStatus.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/waitForTransactionStatus.js +47 -0
- package/dist/esm/core/tasks/helpers/waitForTransactionStatus.js.map +1 -0
- package/dist/esm/core/utils.d.ts +17 -0
- package/dist/esm/core/utils.d.ts.map +1 -0
- package/dist/esm/core/utils.js +40 -0
- package/dist/esm/core/utils.js.map +1 -0
- package/dist/esm/errors/SDKError.d.ts +17 -0
- package/dist/esm/errors/SDKError.d.ts.map +1 -0
- package/dist/esm/errors/SDKError.js +23 -0
- package/dist/esm/errors/SDKError.js.map +1 -0
- package/dist/esm/errors/baseError.d.ts +11 -0
- package/dist/esm/errors/baseError.d.ts.map +1 -0
- package/dist/esm/errors/baseError.js +18 -0
- package/dist/esm/errors/baseError.js.map +1 -0
- package/dist/esm/errors/constants.d.ts +55 -0
- package/dist/esm/errors/constants.d.ts.map +1 -0
- package/dist/esm/errors/constants.js +58 -0
- package/dist/esm/errors/constants.js.map +1 -0
- package/dist/esm/errors/errors.d.ts +38 -0
- package/dist/esm/errors/errors.d.ts.map +1 -0
- package/dist/esm/errors/errors.js +54 -0
- package/dist/esm/errors/errors.js.map +1 -0
- package/dist/esm/errors/httpError.d.ts +24 -0
- package/dist/esm/errors/httpError.d.ts.map +1 -0
- package/dist/esm/errors/httpError.js +69 -0
- package/dist/esm/errors/httpError.js.map +1 -0
- package/dist/esm/errors/utils/baseErrorRootCause.d.ts +8 -0
- package/dist/esm/errors/utils/baseErrorRootCause.d.ts.map +1 -0
- package/dist/esm/errors/utils/baseErrorRootCause.js +16 -0
- package/dist/esm/errors/utils/baseErrorRootCause.js.map +1 -0
- package/dist/esm/errors/utils/rootCause.d.ts +5 -0
- package/dist/esm/errors/utils/rootCause.d.ts.map +1 -0
- package/dist/esm/errors/utils/rootCause.js +10 -0
- package/dist/esm/errors/utils/rootCause.js.map +1 -0
- package/dist/esm/index.d.ts +55 -0
- package/dist/esm/index.js +53 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/types/actions.d.ts +14 -0
- package/dist/esm/types/actions.d.ts.map +1 -0
- package/dist/esm/types/actions.js +1 -0
- package/dist/esm/types/core.d.ts +184 -0
- package/dist/esm/types/core.d.ts.map +1 -0
- package/dist/esm/types/core.js +1 -0
- package/dist/esm/types/execution.d.ts +28 -0
- package/dist/esm/types/execution.d.ts.map +1 -0
- package/dist/esm/types/execution.js +1 -0
- package/dist/esm/types/request.d.ts +7 -0
- package/dist/esm/types/request.d.ts.map +1 -0
- package/dist/esm/types/request.js +1 -0
- package/dist/esm/utils/checkPackageUpdates.d.ts +5 -0
- package/dist/esm/utils/checkPackageUpdates.d.ts.map +1 -0
- package/dist/esm/utils/checkPackageUpdates.js +14 -0
- package/dist/esm/utils/checkPackageUpdates.js.map +1 -0
- package/dist/esm/utils/convertQuoteToRoute.d.ts +22 -0
- package/dist/esm/utils/convertQuoteToRoute.d.ts.map +1 -0
- package/dist/esm/utils/convertQuoteToRoute.js +86 -0
- package/dist/esm/utils/convertQuoteToRoute.js.map +1 -0
- package/dist/esm/utils/decode.d.ts +5 -0
- package/dist/esm/utils/decode.d.ts.map +1 -0
- package/dist/esm/utils/decode.js +8 -0
- package/dist/esm/utils/decode.js.map +1 -0
- package/dist/esm/utils/fetchTxErrorDetails.d.ts +5 -0
- package/dist/esm/utils/fetchTxErrorDetails.d.ts.map +1 -0
- package/dist/esm/utils/fetchTxErrorDetails.js +12 -0
- package/dist/esm/utils/fetchTxErrorDetails.js.map +1 -0
- package/dist/esm/utils/formatUnits.d.ts +8 -0
- package/dist/esm/utils/formatUnits.d.ts.map +1 -0
- package/dist/esm/utils/formatUnits.js +17 -0
- package/dist/esm/utils/formatUnits.js.map +1 -0
- package/dist/esm/utils/getTransactionMessage.d.ts +8 -0
- package/dist/esm/utils/getTransactionMessage.d.ts.map +1 -0
- package/dist/esm/utils/getTransactionMessage.js +11 -0
- package/dist/esm/utils/getTransactionMessage.js.map +1 -0
- package/dist/esm/utils/isHex.d.ts +10 -0
- package/dist/esm/utils/isHex.d.ts.map +1 -0
- package/dist/esm/utils/isHex.js +10 -0
- package/dist/esm/utils/isHex.js.map +1 -0
- package/dist/esm/utils/isRoutesRequest.d.ts +7 -0
- package/dist/esm/utils/isRoutesRequest.d.ts.map +1 -0
- package/dist/esm/utils/isRoutesRequest.js +10 -0
- package/dist/esm/utils/isRoutesRequest.js.map +1 -0
- package/dist/esm/utils/isStep.d.ts +7 -0
- package/dist/esm/utils/isStep.d.ts.map +1 -0
- package/dist/esm/utils/isStep.js +22 -0
- package/dist/esm/utils/isStep.js.map +1 -0
- package/dist/esm/utils/isToken.d.ts +7 -0
- package/dist/esm/utils/isToken.d.ts.map +1 -0
- package/dist/esm/utils/isToken.js +9 -0
- package/dist/esm/utils/isToken.js.map +1 -0
- package/dist/esm/utils/parseUnits.d.ts +8 -0
- package/dist/esm/utils/parseUnits.d.ts.map +1 -0
- package/dist/esm/utils/parseUnits.js +34 -0
- package/dist/esm/utils/parseUnits.js.map +1 -0
- package/dist/esm/utils/request.d.ts +11 -0
- package/dist/esm/utils/request.d.ts.map +1 -0
- package/dist/esm/utils/request.js +54 -0
- package/dist/esm/utils/request.js.map +1 -0
- package/dist/esm/utils/sleep.d.ts +5 -0
- package/dist/esm/utils/sleep.d.ts.map +1 -0
- package/dist/esm/utils/sleep.js +10 -0
- package/dist/esm/utils/sleep.js.map +1 -0
- package/dist/esm/utils/waitForResult.d.ts +14 -0
- package/dist/esm/utils/waitForResult.d.ts.map +1 -0
- package/dist/esm/utils/waitForResult.js +35 -0
- package/dist/esm/utils/waitForResult.js.map +1 -0
- package/dist/esm/utils/withDedupe.d.ts +23 -0
- package/dist/esm/utils/withDedupe.d.ts.map +1 -0
- package/dist/esm/utils/withDedupe.js +32 -0
- package/dist/esm/utils/withDedupe.js.map +1 -0
- package/dist/esm/utils/withTimeout.d.ts +26 -0
- package/dist/esm/utils/withTimeout.d.ts.map +1 -0
- package/dist/esm/utils/withTimeout.js +34 -0
- package/dist/esm/utils/withTimeout.js.map +1 -0
- package/dist/esm/version.d.ts +6 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +7 -0
- package/dist/esm/version.js.map +1 -0
- package/package.json +75 -0
- package/src/actions/getChains.ts +55 -0
- package/src/actions/getConnections.ts +55 -0
- package/src/actions/getContractCallsQuote.ts +81 -0
- package/src/actions/getGasRecommendation.ts +47 -0
- package/src/actions/getNameServiceAddress.ts +42 -0
- package/src/actions/getQuote.ts +105 -0
- package/src/actions/getRelayedTransactionStatus.ts +67 -0
- package/src/actions/getRelayerQuote.ts +86 -0
- package/src/actions/getRoutes.ts +43 -0
- package/src/actions/getStatus.ts +41 -0
- package/src/actions/getStepTransaction.ts +52 -0
- package/src/actions/getToken.ts +47 -0
- package/src/actions/getTokenBalance.ts +21 -0
- package/src/actions/getTokenBalances.ts +47 -0
- package/src/actions/getTokenBalancesByChain.ts +76 -0
- package/src/actions/getTokens.ts +57 -0
- package/src/actions/getTools.ts +34 -0
- package/src/actions/getTransactionHistory.ts +54 -0
- package/src/actions/getWalletBalances.ts +36 -0
- package/src/actions/index.ts +347 -0
- package/src/actions/patchContractCalls.ts +30 -0
- package/src/actions/relayTransaction.ts +74 -0
- package/src/client/createClient.ts +100 -0
- package/src/client/getClientStorage.ts +65 -0
- package/src/core/BaseStepExecutionTask.ts +9 -0
- package/src/core/BaseStepExecutor.ts +129 -0
- package/src/core/StatusManager.ts +245 -0
- package/src/core/TaskPipeline.ts +28 -0
- package/src/core/actionMessages.ts +103 -0
- package/src/core/execution.ts +243 -0
- package/src/core/executionState.ts +48 -0
- package/src/core/prepareRestart.ts +28 -0
- package/src/core/storage.ts +42 -0
- package/src/core/tasks/CheckBalanceTask.ts +46 -0
- package/src/core/tasks/PrepareTransactionTask.ts +62 -0
- package/src/core/tasks/WaitForTransactionStatusTask.ts +114 -0
- package/src/core/tasks/helpers/checkBalance.ts +218 -0
- package/src/core/tasks/helpers/getTransactionRequestData.ts +47 -0
- package/src/core/tasks/helpers/stepComparison.ts +50 -0
- package/src/core/tasks/helpers/waitForTransactionStatus.ts +76 -0
- package/src/core/utils.ts +59 -0
- package/src/errors/SDKError.ts +26 -0
- package/src/errors/baseError.ts +22 -0
- package/src/errors/constants.ts +54 -0
- package/src/errors/errors.ts +68 -0
- package/src/errors/httpError.ts +92 -0
- package/src/errors/utils/baseErrorRootCause.ts +18 -0
- package/src/errors/utils/rootCause.ts +7 -0
- package/src/index.ts +122 -0
- package/src/types/actions.ts +16 -0
- package/src/types/core.ts +264 -0
- package/src/types/execution.ts +32 -0
- package/src/types/request.ts +3 -0
- package/src/utils/checkPackageUpdates.ts +22 -0
- package/src/utils/convertQuoteToRoute.ts +154 -0
- package/src/utils/decode.ts +13 -0
- package/src/utils/fetchTxErrorDetails.ts +15 -0
- package/src/utils/formatUnits.ts +22 -0
- package/src/utils/getTransactionMessage.ts +17 -0
- package/src/utils/isHex.ts +14 -0
- package/src/utils/isRoutesRequest.ts +31 -0
- package/src/utils/isStep.ts +41 -0
- package/src/utils/isToken.ts +11 -0
- package/src/utils/parseUnits.ts +50 -0
- package/src/utils/request.ts +100 -0
- package/src/utils/sleep.ts +5 -0
- package/src/utils/waitForResult.ts +45 -0
- package/src/utils/withDedupe.ts +45 -0
- package/src/utils/withTimeout.ts +50 -0
- package/src/version.ts +2 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RelayRequest,
|
|
3
|
+
RelayResponse,
|
|
4
|
+
RelayResponseData,
|
|
5
|
+
RequestOptions,
|
|
6
|
+
} from '@lifi/types'
|
|
7
|
+
import { BaseError } from '../errors/baseError.js'
|
|
8
|
+
import { ErrorName } from '../errors/constants.js'
|
|
9
|
+
import { ValidationError } from '../errors/errors.js'
|
|
10
|
+
import { SDKError } from '../errors/SDKError.js'
|
|
11
|
+
import type { SDKClient } from '../types/core.js'
|
|
12
|
+
import { request } from '../utils/request.js'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Relay a transaction through the relayer service
|
|
16
|
+
* @param client - The SDK client
|
|
17
|
+
* @param params - The configuration for the relay request
|
|
18
|
+
* @param options - Request options
|
|
19
|
+
* @throws {LiFiError} - Throws a LiFiError if request fails
|
|
20
|
+
* @returns Task ID and transaction link for the relayed transaction
|
|
21
|
+
*/
|
|
22
|
+
export const relayTransaction = async (
|
|
23
|
+
client: SDKClient,
|
|
24
|
+
params: RelayRequest,
|
|
25
|
+
options?: RequestOptions
|
|
26
|
+
): Promise<RelayResponseData> => {
|
|
27
|
+
const requiredParameters: Array<keyof RelayRequest> = ['typedData']
|
|
28
|
+
|
|
29
|
+
for (const requiredParameter of requiredParameters) {
|
|
30
|
+
if (!params[requiredParameter]) {
|
|
31
|
+
throw new SDKError(
|
|
32
|
+
new ValidationError(
|
|
33
|
+
`Required parameter "${requiredParameter}" is missing.`
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Determine if the request is for a gasless relayer service or advanced relayer service
|
|
40
|
+
// We will use the same endpoint for both after the gasless relayer service is deprecated
|
|
41
|
+
const relayerPath = params.typedData.some(
|
|
42
|
+
(t) => t.primaryType === 'PermitWitnessTransferFrom'
|
|
43
|
+
)
|
|
44
|
+
? '/relayer/relay'
|
|
45
|
+
: '/advanced/relay'
|
|
46
|
+
|
|
47
|
+
const result = await request<RelayResponse>(
|
|
48
|
+
client.config,
|
|
49
|
+
`${client.config.apiUrl}${relayerPath}`,
|
|
50
|
+
{
|
|
51
|
+
method: 'POST',
|
|
52
|
+
headers: {
|
|
53
|
+
'Content-Type': 'application/json',
|
|
54
|
+
},
|
|
55
|
+
body: JSON.stringify(params, (_, value) => {
|
|
56
|
+
if (typeof value === 'bigint') {
|
|
57
|
+
return value.toString()
|
|
58
|
+
}
|
|
59
|
+
return value
|
|
60
|
+
}),
|
|
61
|
+
signal: options?.signal,
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
if (result.status === 'error') {
|
|
66
|
+
throw new BaseError(
|
|
67
|
+
ErrorName.ServerError,
|
|
68
|
+
result.data.code,
|
|
69
|
+
result.data.message
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return result.data
|
|
74
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { ChainId, ChainType, ExtendedChain } from '@lifi/types'
|
|
2
|
+
import type {
|
|
3
|
+
SDKBaseConfig,
|
|
4
|
+
SDKClient,
|
|
5
|
+
SDKConfig,
|
|
6
|
+
SDKProvider,
|
|
7
|
+
} from '../types/core.js'
|
|
8
|
+
import { checkPackageUpdates } from '../utils/checkPackageUpdates.js'
|
|
9
|
+
import { name, version } from '../version.js'
|
|
10
|
+
import { getClientStorage } from './getClientStorage.js'
|
|
11
|
+
|
|
12
|
+
export function createClient(options: SDKConfig): SDKClient {
|
|
13
|
+
if (!options.integrator) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
'Integrator not found. Please see documentation https://docs.li.fi/integrate-li.fi-js-sdk/set-up-the-sdk'
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!options.disableVersionCheck && process.env.NODE_ENV === 'development') {
|
|
20
|
+
checkPackageUpdates(name, version)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const { providers, ...configOptions } = options
|
|
24
|
+
|
|
25
|
+
const _config: SDKBaseConfig = {
|
|
26
|
+
...configOptions,
|
|
27
|
+
apiUrl: configOptions?.apiUrl ?? 'https://li.quest/v1',
|
|
28
|
+
rpcUrls: configOptions?.rpcUrls ?? {},
|
|
29
|
+
debug: configOptions?.debug ?? false,
|
|
30
|
+
preloadChains: configOptions?.preloadChains ?? true,
|
|
31
|
+
integrator: configOptions?.integrator ?? 'lifi-sdk',
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let _providers: SDKProvider[] = providers ?? []
|
|
35
|
+
const _storage = getClientStorage(_config)
|
|
36
|
+
|
|
37
|
+
const client: SDKClient = {
|
|
38
|
+
get config() {
|
|
39
|
+
return _config
|
|
40
|
+
},
|
|
41
|
+
get providers() {
|
|
42
|
+
return _providers
|
|
43
|
+
},
|
|
44
|
+
getProvider(type: ChainType) {
|
|
45
|
+
return this.providers.find((provider) => provider.type === type)
|
|
46
|
+
},
|
|
47
|
+
setProviders(newProviders: SDKProvider[]) {
|
|
48
|
+
const providerMap = new Map(
|
|
49
|
+
this.providers.map((provider) => [provider.type, provider])
|
|
50
|
+
)
|
|
51
|
+
for (const provider of newProviders) {
|
|
52
|
+
providerMap.set(provider.type, provider)
|
|
53
|
+
}
|
|
54
|
+
_providers = Array.from(providerMap.values())
|
|
55
|
+
},
|
|
56
|
+
setChains(chains: ExtendedChain[]) {
|
|
57
|
+
_storage.setChains(chains)
|
|
58
|
+
},
|
|
59
|
+
async getChains() {
|
|
60
|
+
return await _storage.getChains()
|
|
61
|
+
},
|
|
62
|
+
async getChainById(chainId: ChainId) {
|
|
63
|
+
const chains = await this.getChains()
|
|
64
|
+
const chain = chains?.find((chain) => chain.id === chainId)
|
|
65
|
+
if (!chain) {
|
|
66
|
+
throw new Error(`ChainId ${chainId} not found`)
|
|
67
|
+
}
|
|
68
|
+
return chain
|
|
69
|
+
},
|
|
70
|
+
async getRpcUrls() {
|
|
71
|
+
return await _storage.getRpcUrls()
|
|
72
|
+
},
|
|
73
|
+
async getRpcUrlsByChainId(chainId: ChainId) {
|
|
74
|
+
const rpcUrls = await this.getRpcUrls()
|
|
75
|
+
const chainRpcUrls = rpcUrls[chainId]
|
|
76
|
+
if (!chainRpcUrls?.length) {
|
|
77
|
+
throw new Error(`RPC URL not found for chainId: ${chainId}`)
|
|
78
|
+
}
|
|
79
|
+
return chainRpcUrls
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function extend<TClient extends SDKClient>(
|
|
84
|
+
base: TClient
|
|
85
|
+
): <TExtensions extends Record<string, any>>(
|
|
86
|
+
extendFn: (client: TClient) => TExtensions
|
|
87
|
+
) => TClient & TExtensions {
|
|
88
|
+
return (extendFn) => {
|
|
89
|
+
const extensions = extendFn(base)
|
|
90
|
+
const extended = { ...base, ...extensions } as TClient & typeof extensions
|
|
91
|
+
|
|
92
|
+
// Preserve the extend function for further extensions
|
|
93
|
+
return Object.assign(extended, {
|
|
94
|
+
extend: extend(extended),
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return Object.assign(client, { extend: extend(client) })
|
|
100
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ChainId, ChainType, type ExtendedChain } from '@lifi/types'
|
|
2
|
+
import { _getChains } from '../actions/getChains.js'
|
|
3
|
+
import { getRpcUrlsFromChains } from '../core/utils.js'
|
|
4
|
+
import type { RPCUrls, SDKBaseConfig } from '../types/core.js'
|
|
5
|
+
|
|
6
|
+
// 6 hours in milliseconds
|
|
7
|
+
const chainsRefreshInterval = 1000 * 60 * 60 * 6
|
|
8
|
+
|
|
9
|
+
export interface ClientStorage {
|
|
10
|
+
readonly needReset: boolean
|
|
11
|
+
setChains(chains: ExtendedChain[]): void
|
|
12
|
+
getChains(): Promise<ExtendedChain[]>
|
|
13
|
+
getRpcUrls(): Promise<RPCUrls>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const getClientStorage = (config: SDKBaseConfig): ClientStorage => {
|
|
17
|
+
let _chains = [] as ExtendedChain[]
|
|
18
|
+
let _rpcUrls = { ...config.rpcUrls } as RPCUrls
|
|
19
|
+
let _chainsUpdatedAt: number | undefined
|
|
20
|
+
|
|
21
|
+
const updateRpcUrls = () => {
|
|
22
|
+
_rpcUrls = { ...config.rpcUrls }
|
|
23
|
+
_rpcUrls = getRpcUrlsFromChains(_rpcUrls, _chains, [ChainId.SOL])
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
get needReset() {
|
|
28
|
+
return (
|
|
29
|
+
!_chainsUpdatedAt ||
|
|
30
|
+
Date.now() - _chainsUpdatedAt >= chainsRefreshInterval
|
|
31
|
+
)
|
|
32
|
+
},
|
|
33
|
+
setChains(chains: ExtendedChain[]) {
|
|
34
|
+
_chains = chains
|
|
35
|
+
_chainsUpdatedAt = Date.now()
|
|
36
|
+
updateRpcUrls()
|
|
37
|
+
},
|
|
38
|
+
async getChains() {
|
|
39
|
+
// When preloadChains is false, SDK does not auto-fetch chains
|
|
40
|
+
// External consumer is responsible for calling setChains
|
|
41
|
+
if (!config.preloadChains) {
|
|
42
|
+
return _chains
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (this.needReset || !_chains.length) {
|
|
46
|
+
_chains = await _getChains(config, {
|
|
47
|
+
chainTypes: [
|
|
48
|
+
ChainType.EVM,
|
|
49
|
+
ChainType.SVM,
|
|
50
|
+
ChainType.UTXO,
|
|
51
|
+
ChainType.MVM,
|
|
52
|
+
ChainType.TVM,
|
|
53
|
+
],
|
|
54
|
+
})
|
|
55
|
+
_chainsUpdatedAt = Date.now()
|
|
56
|
+
updateRpcUrls()
|
|
57
|
+
}
|
|
58
|
+
return _chains
|
|
59
|
+
},
|
|
60
|
+
async getRpcUrls() {
|
|
61
|
+
await this.getChains() // _rpcUrls is updated when needed
|
|
62
|
+
return _rpcUrls
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { StepExecutorContext, TaskResult } from '../types/execution.js'
|
|
2
|
+
|
|
3
|
+
export abstract class BaseStepExecutionTask {
|
|
4
|
+
shouldRun(_context: StepExecutorContext): Promise<boolean> {
|
|
5
|
+
return Promise.resolve(true)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
abstract run(context: StepExecutorContext): Promise<TaskResult>
|
|
9
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { ExecuteStepRetryError } from '../errors/errors.js'
|
|
2
|
+
import type { SDKError } from '../errors/SDKError.js'
|
|
3
|
+
import type {
|
|
4
|
+
ExecuteStepRetryParams,
|
|
5
|
+
ExecutionAction,
|
|
6
|
+
ExecutionOptions,
|
|
7
|
+
InteractionSettings,
|
|
8
|
+
LiFiStepExtended,
|
|
9
|
+
SDKClient,
|
|
10
|
+
StepExecutor,
|
|
11
|
+
StepExecutorOptions,
|
|
12
|
+
} from '../types/core.js'
|
|
13
|
+
import type {
|
|
14
|
+
StepExecutorBaseContext,
|
|
15
|
+
StepExecutorContext,
|
|
16
|
+
} from '../types/execution.js'
|
|
17
|
+
import { StatusManager } from './StatusManager.js'
|
|
18
|
+
import type { TaskPipeline } from './TaskPipeline.js'
|
|
19
|
+
|
|
20
|
+
// Please be careful when changing the defaults as it may break the behavior (e.g., background execution)
|
|
21
|
+
const defaultInteractionSettings = {
|
|
22
|
+
allowInteraction: true,
|
|
23
|
+
allowUpdates: true,
|
|
24
|
+
allowExecution: true,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export abstract class BaseStepExecutor implements StepExecutor {
|
|
28
|
+
protected executionOptions?: ExecutionOptions
|
|
29
|
+
protected statusManager: StatusManager
|
|
30
|
+
|
|
31
|
+
public allowUserInteraction = true
|
|
32
|
+
public allowExecution = true
|
|
33
|
+
|
|
34
|
+
constructor(options: StepExecutorOptions) {
|
|
35
|
+
this.statusManager = new StatusManager(options.routeId)
|
|
36
|
+
this.executionOptions = options.executionOptions
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setInteraction = (settings?: InteractionSettings): void => {
|
|
40
|
+
const interactionSettings = {
|
|
41
|
+
...defaultInteractionSettings,
|
|
42
|
+
...settings,
|
|
43
|
+
}
|
|
44
|
+
this.allowUserInteraction = interactionSettings.allowInteraction
|
|
45
|
+
this.statusManager.allowUpdates(interactionSettings.allowUpdates)
|
|
46
|
+
this.allowExecution = interactionSettings.allowExecution
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private createBaseContext = async (
|
|
50
|
+
client: SDKClient,
|
|
51
|
+
step: LiFiStepExtended,
|
|
52
|
+
retryParams?: ExecuteStepRetryParams
|
|
53
|
+
): Promise<StepExecutorBaseContext> => {
|
|
54
|
+
const fromChain = await client.getChainById(step.action.fromChainId)
|
|
55
|
+
const toChain = await client.getChainById(step.action.toChainId)
|
|
56
|
+
|
|
57
|
+
const isBridgeExecution = fromChain.id !== toChain.id
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
client,
|
|
61
|
+
step,
|
|
62
|
+
fromChain,
|
|
63
|
+
toChain,
|
|
64
|
+
isBridgeExecution,
|
|
65
|
+
retryParams,
|
|
66
|
+
statusManager: this.statusManager,
|
|
67
|
+
executionOptions: this.executionOptions,
|
|
68
|
+
allowUserInteraction: this.allowUserInteraction,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
abstract createContext(
|
|
73
|
+
baseContext: StepExecutorBaseContext
|
|
74
|
+
): Promise<StepExecutorContext>
|
|
75
|
+
|
|
76
|
+
abstract createPipeline(context: StepExecutorContext): TaskPipeline
|
|
77
|
+
|
|
78
|
+
abstract parseErrors(
|
|
79
|
+
error: Error,
|
|
80
|
+
step?: LiFiStepExtended,
|
|
81
|
+
action?: ExecutionAction,
|
|
82
|
+
retryParams?: ExecuteStepRetryParams
|
|
83
|
+
): Promise<SDKError | ExecuteStepRetryError>
|
|
84
|
+
|
|
85
|
+
executeStep = async (
|
|
86
|
+
client: SDKClient,
|
|
87
|
+
step: LiFiStepExtended,
|
|
88
|
+
retryParams?: ExecuteStepRetryParams
|
|
89
|
+
): Promise<LiFiStepExtended> => {
|
|
90
|
+
try {
|
|
91
|
+
step.execution = this.statusManager.initializeExecution(step)
|
|
92
|
+
|
|
93
|
+
const baseContext = await this.createBaseContext(
|
|
94
|
+
client,
|
|
95
|
+
step,
|
|
96
|
+
retryParams
|
|
97
|
+
)
|
|
98
|
+
const context = await this.createContext(baseContext)
|
|
99
|
+
const pipeline = this.createPipeline(context)
|
|
100
|
+
|
|
101
|
+
await pipeline.run(context)
|
|
102
|
+
|
|
103
|
+
return step
|
|
104
|
+
} catch (error: any) {
|
|
105
|
+
// Derive failing action from last in execution.actions
|
|
106
|
+
const action = step.execution?.actions?.at(-1)
|
|
107
|
+
const parsed = await this.parseErrors(error, step, action, retryParams)
|
|
108
|
+
if (!(parsed instanceof ExecuteStepRetryError)) {
|
|
109
|
+
if (action) {
|
|
110
|
+
this.statusManager.updateAction(step, action.type, 'FAILED', {
|
|
111
|
+
error: {
|
|
112
|
+
message: parsed.cause?.message,
|
|
113
|
+
code: parsed.code,
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
} else {
|
|
117
|
+
this.statusManager.updateExecution(step, {
|
|
118
|
+
status: 'FAILED',
|
|
119
|
+
error: {
|
|
120
|
+
message: parsed.cause?.message,
|
|
121
|
+
code: parsed.code,
|
|
122
|
+
},
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
throw parsed
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import type { ChainId, LiFiStep } from '@lifi/types'
|
|
2
|
+
import type {
|
|
3
|
+
Execution,
|
|
4
|
+
ExecutionAction,
|
|
5
|
+
ExecutionActionStatus,
|
|
6
|
+
ExecutionActionType,
|
|
7
|
+
LiFiStepExtended,
|
|
8
|
+
} from '../types/core.js'
|
|
9
|
+
import { getActionMessage } from './actionMessages.js'
|
|
10
|
+
import { executionState } from './executionState.js'
|
|
11
|
+
|
|
12
|
+
type ActionProps = {
|
|
13
|
+
step: LiFiStepExtended
|
|
14
|
+
type: ExecutionActionType
|
|
15
|
+
chainId: ChainId
|
|
16
|
+
status: ExecutionActionStatus
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Manages status updates of a route and provides various functions for tracking actions.
|
|
21
|
+
*/
|
|
22
|
+
export class StatusManager {
|
|
23
|
+
private readonly routeId: string
|
|
24
|
+
private shouldUpdate = true
|
|
25
|
+
|
|
26
|
+
constructor(routeId: string) {
|
|
27
|
+
this.routeId = routeId
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Initializes the execution object of a Step.
|
|
32
|
+
* @param step The current step in execution
|
|
33
|
+
* @returns The initialized execution object for this step
|
|
34
|
+
*/
|
|
35
|
+
initializeExecution = (step: LiFiStepExtended): Execution => {
|
|
36
|
+
if (!step.execution) {
|
|
37
|
+
step.execution = {
|
|
38
|
+
startedAt: Date.now(),
|
|
39
|
+
status: 'PENDING',
|
|
40
|
+
actions: [],
|
|
41
|
+
}
|
|
42
|
+
this.updateStepInRoute(step)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Change status to PENDING after resuming from FAILED
|
|
46
|
+
if (step.execution.status === 'FAILED') {
|
|
47
|
+
step.execution.startedAt = Date.now()
|
|
48
|
+
step.execution.status = 'PENDING'
|
|
49
|
+
step.execution.signedAt = undefined
|
|
50
|
+
step.execution.error = undefined
|
|
51
|
+
this.updateStepInRoute(step)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return step.execution
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Updates the execution object of a Step.
|
|
59
|
+
* @param step The current step in execution
|
|
60
|
+
* @param execution Partial execution data to merge
|
|
61
|
+
* @returns The step with the updated execution object
|
|
62
|
+
*/
|
|
63
|
+
updateExecution(
|
|
64
|
+
step: LiFiStepExtended,
|
|
65
|
+
execution: Partial<Execution>
|
|
66
|
+
): LiFiStep {
|
|
67
|
+
if (!step.execution) {
|
|
68
|
+
throw Error("Can't update empty execution.")
|
|
69
|
+
}
|
|
70
|
+
step.execution = {
|
|
71
|
+
...step.execution,
|
|
72
|
+
...execution,
|
|
73
|
+
}
|
|
74
|
+
this.updateStepInRoute(step)
|
|
75
|
+
return step
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Finds an action of the specified type in the step's execution
|
|
80
|
+
* @param step The step to search in
|
|
81
|
+
* @param type The action type to find
|
|
82
|
+
* @returns The found action or undefined if not found
|
|
83
|
+
*/
|
|
84
|
+
findAction(
|
|
85
|
+
step: LiFiStepExtended,
|
|
86
|
+
type: ExecutionActionType
|
|
87
|
+
): ExecutionAction | undefined {
|
|
88
|
+
if (!step.execution?.actions) {
|
|
89
|
+
throw new Error("Execution hasn't been initialized.")
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const action = step.execution.actions.find((p) => p.type === type)
|
|
93
|
+
|
|
94
|
+
return action
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Create and push a new action into the execution.
|
|
99
|
+
* Caller is responsible for ensuring an action of this type does not already exist.
|
|
100
|
+
* @param step The step that should contain the new action.
|
|
101
|
+
* @param type Type of the action.
|
|
102
|
+
* @param chainId Chain Id of the action.
|
|
103
|
+
* @param status The initial status for the new action.
|
|
104
|
+
* @returns The created action.
|
|
105
|
+
*/
|
|
106
|
+
createAction = ({
|
|
107
|
+
step,
|
|
108
|
+
type,
|
|
109
|
+
chainId,
|
|
110
|
+
status,
|
|
111
|
+
}: ActionProps): ExecutionAction => {
|
|
112
|
+
if (!step.execution) {
|
|
113
|
+
throw new Error("Execution hasn't been initialized.")
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const newAction: ExecutionAction = {
|
|
117
|
+
type,
|
|
118
|
+
message: getActionMessage(type, status),
|
|
119
|
+
status,
|
|
120
|
+
chainId,
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
step.execution.actions.push(newAction)
|
|
124
|
+
this.updateStepInRoute(step)
|
|
125
|
+
return newAction
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Find an existing action by type and update it, or create a new one if none exists.
|
|
130
|
+
* @param step The step that should contain the action.
|
|
131
|
+
* @param type Type of the action. Used to identify already existing actions.
|
|
132
|
+
* @param chainId Chain Id of the action (used when creating).
|
|
133
|
+
* @param status The status to set on the found or newly created action.
|
|
134
|
+
* @returns The updated or newly created action.
|
|
135
|
+
*/
|
|
136
|
+
initializeAction = ({
|
|
137
|
+
step,
|
|
138
|
+
type,
|
|
139
|
+
chainId,
|
|
140
|
+
status,
|
|
141
|
+
}: ActionProps): ExecutionAction => {
|
|
142
|
+
const action = this.findAction(step, type)
|
|
143
|
+
|
|
144
|
+
if (action) {
|
|
145
|
+
return this.updateAction(step, type, status, {
|
|
146
|
+
error: undefined,
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return this.createAction({ step, type, chainId, status })
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Update an action object.
|
|
155
|
+
* @param step The step where the action should be updated
|
|
156
|
+
* @param type The action type to update
|
|
157
|
+
* @param status The status the action gets.
|
|
158
|
+
* @param [params] Additional parameters to append to the action.
|
|
159
|
+
* @returns The updated action
|
|
160
|
+
*/
|
|
161
|
+
updateAction = (
|
|
162
|
+
step: LiFiStepExtended,
|
|
163
|
+
type: ExecutionActionType,
|
|
164
|
+
status: ExecutionActionStatus,
|
|
165
|
+
params?: Partial<ExecutionAction & { signedAt?: number }>
|
|
166
|
+
): ExecutionAction => {
|
|
167
|
+
if (!step.execution) {
|
|
168
|
+
throw new Error("Can't update an empty step execution.")
|
|
169
|
+
}
|
|
170
|
+
const currentAction = this.findAction(step, type)
|
|
171
|
+
|
|
172
|
+
if (!currentAction) {
|
|
173
|
+
throw new Error("Can't find an action for the given type.")
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
switch (status) {
|
|
177
|
+
case 'CANCELLED':
|
|
178
|
+
break
|
|
179
|
+
case 'FAILED':
|
|
180
|
+
step.execution.status = 'FAILED'
|
|
181
|
+
if (params?.error) {
|
|
182
|
+
step.execution.error = params.error
|
|
183
|
+
}
|
|
184
|
+
break
|
|
185
|
+
case 'DONE':
|
|
186
|
+
break
|
|
187
|
+
case 'PENDING':
|
|
188
|
+
step.execution.status = 'PENDING'
|
|
189
|
+
if (params?.signedAt) {
|
|
190
|
+
step.execution.signedAt = params.signedAt
|
|
191
|
+
}
|
|
192
|
+
break
|
|
193
|
+
case 'RESET_REQUIRED':
|
|
194
|
+
case 'MESSAGE_REQUIRED':
|
|
195
|
+
case 'ACTION_REQUIRED':
|
|
196
|
+
step.execution.status = 'ACTION_REQUIRED'
|
|
197
|
+
break
|
|
198
|
+
default:
|
|
199
|
+
break
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
currentAction.status = status
|
|
203
|
+
currentAction.message = getActionMessage(type, status)
|
|
204
|
+
// set extra parameters or overwrite the standard params set in the switch statement
|
|
205
|
+
if (params) {
|
|
206
|
+
const { signedAt: _signedAt, ...rest } = params
|
|
207
|
+
Object.assign(currentAction, rest)
|
|
208
|
+
}
|
|
209
|
+
// Sort actions, the ones with DONE status go first
|
|
210
|
+
step.execution.actions = [
|
|
211
|
+
...step.execution.actions.filter((action) => action.status === 'DONE'),
|
|
212
|
+
...step.execution.actions.filter((action) => action.status !== 'DONE'),
|
|
213
|
+
]
|
|
214
|
+
this.updateStepInRoute(step) // updates the step in the route
|
|
215
|
+
return currentAction
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
updateStepInRoute = (step: LiFiStep): LiFiStep => {
|
|
219
|
+
if (!this.shouldUpdate) {
|
|
220
|
+
return step
|
|
221
|
+
}
|
|
222
|
+
const data = executionState.get(this.routeId)
|
|
223
|
+
|
|
224
|
+
if (!data) {
|
|
225
|
+
throw new Error('Execution data not found.')
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const stepIndex = data.route.steps.findIndex(
|
|
229
|
+
(routeStep) => routeStep.id === step.id
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
if (stepIndex === -1) {
|
|
233
|
+
throw new Error("Couldn't find a step to update.")
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
data.route.steps[stepIndex] = { ...data.route.steps[stepIndex], ...step }
|
|
237
|
+
|
|
238
|
+
data.executionOptions?.updateRouteHook?.(data.route)
|
|
239
|
+
return data.route.steps[stepIndex]
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
allowUpdates(value: boolean): void {
|
|
243
|
+
this.shouldUpdate = value
|
|
244
|
+
}
|
|
245
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { StepExecutorContext, TaskResult } from '../types/execution.js'
|
|
2
|
+
import type { BaseStepExecutionTask } from './BaseStepExecutionTask.js'
|
|
3
|
+
|
|
4
|
+
export class TaskPipeline {
|
|
5
|
+
private readonly tasks: BaseStepExecutionTask[]
|
|
6
|
+
|
|
7
|
+
constructor(tasks: BaseStepExecutionTask[]) {
|
|
8
|
+
this.tasks = tasks
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async run(context: StepExecutorContext): Promise<TaskResult> {
|
|
12
|
+
for (const task of this.tasks) {
|
|
13
|
+
const shouldRun = await task.shouldRun(context)
|
|
14
|
+
if (!shouldRun) {
|
|
15
|
+
continue
|
|
16
|
+
}
|
|
17
|
+
const result = await task.run(context)
|
|
18
|
+
if (result.status === 'PAUSED') {
|
|
19
|
+
return { status: 'PAUSED' }
|
|
20
|
+
}
|
|
21
|
+
if (result.context && typeof result.context === 'object') {
|
|
22
|
+
Object.assign(context, result.context)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return { status: 'COMPLETED' }
|
|
27
|
+
}
|
|
28
|
+
}
|