@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,218 @@
|
|
|
1
|
+
import type { LiFiStep, Token, TokenAmount } from '@lifi/types'
|
|
2
|
+
import { BalanceError } from '../../../errors/errors.js'
|
|
3
|
+
import type { SDKClient } from '../../../types/core.js'
|
|
4
|
+
import { formatUnits } from '../../../utils/formatUnits.js'
|
|
5
|
+
import { sleep } from '../../../utils/sleep.js'
|
|
6
|
+
import { withTimeout } from '../../../utils/withTimeout.js'
|
|
7
|
+
|
|
8
|
+
const MAX_ATTEMPTS = 6
|
|
9
|
+
// Exponential backoff: 150, 300, 600, 1200, 2400 → ≈4.65s of sleep total.
|
|
10
|
+
const BACKOFF_BASE_MS = 150
|
|
11
|
+
const OVERALL_TIMEOUT_MS = 10_000
|
|
12
|
+
const SLIPPAGE_PRECISION = 1_000_000_000n
|
|
13
|
+
|
|
14
|
+
type Bucket = 'source' | 'gas' | 'fee'
|
|
15
|
+
|
|
16
|
+
type Requirement = {
|
|
17
|
+
token: Token
|
|
18
|
+
sourcePart: bigint // step.action.fromAmount
|
|
19
|
+
gasPart: bigint // step.estimate.gasCosts in this token
|
|
20
|
+
feePart: bigint // non-included step.estimate.feeCosts in this token
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type CheckBalanceOptions = {
|
|
24
|
+
/**
|
|
25
|
+
* Set to `false` when outer-tx gas is paid by something other than
|
|
26
|
+
* `walletAddress` (SCA executor, 4337 bundler / paymaster, relayer):
|
|
27
|
+
* `gasPart` is excluded from the sufficiency check and slippage rescue.
|
|
28
|
+
* Source amount and non-included fees (e.g. LZ `msg.value`) are still
|
|
29
|
+
* verified. Defaults to `true` (strict, today's behavior).
|
|
30
|
+
*/
|
|
31
|
+
walletPaysGas?: boolean
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Verifies that the wallet holds enough of every token required to execute
|
|
36
|
+
* the step on its source chain — the source-token amount, any gas costs, and
|
|
37
|
+
* any non-included fee costs. Reads all balances in one batched provider
|
|
38
|
+
* call, retries within a bounded budget to absorb transient RPC failures and
|
|
39
|
+
* post-confirmation propagation lag, and applies slippage to the source-token
|
|
40
|
+
* portion only as a last resort (overhead is never trimmed).
|
|
41
|
+
*
|
|
42
|
+
* Throws BalanceError("The balance is too low.") on a genuine shortfall, or
|
|
43
|
+
* BalanceError("Could not read wallet balance.") if the balance can't be read
|
|
44
|
+
* after retries.
|
|
45
|
+
*/
|
|
46
|
+
export const checkBalance = async (
|
|
47
|
+
client: SDKClient,
|
|
48
|
+
walletAddress: string,
|
|
49
|
+
step: LiFiStep,
|
|
50
|
+
options: CheckBalanceOptions = {}
|
|
51
|
+
): Promise<void> => {
|
|
52
|
+
const fromChainId = step.action.fromChainId
|
|
53
|
+
// Chains with non-standard native decimals (e.g. Tempo, Stable) report
|
|
54
|
+
// gas costs in units that don't align with wallet balances — drop the
|
|
55
|
+
// gas portion of the check on those chains.
|
|
56
|
+
const fromChain = await client.getChainById(fromChainId)
|
|
57
|
+
const walletPaysGas =
|
|
58
|
+
(options.walletPaysGas ?? true) && !fromChain.nonStandardNativeDecimals
|
|
59
|
+
const requirements = new Map<string, Requirement>()
|
|
60
|
+
const add = (token: Token, amount: bigint, bucket: Bucket): void => {
|
|
61
|
+
if (token.chainId !== fromChainId || amount === 0n) {
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
const key = token.address.toLowerCase()
|
|
65
|
+
const req = requirements.get(key) ?? {
|
|
66
|
+
token,
|
|
67
|
+
sourcePart: 0n,
|
|
68
|
+
gasPart: 0n,
|
|
69
|
+
feePart: 0n,
|
|
70
|
+
}
|
|
71
|
+
if (bucket === 'source') {
|
|
72
|
+
req.sourcePart += amount
|
|
73
|
+
} else if (bucket === 'gas') {
|
|
74
|
+
req.gasPart += amount
|
|
75
|
+
} else {
|
|
76
|
+
req.feePart += amount
|
|
77
|
+
}
|
|
78
|
+
requirements.set(key, req)
|
|
79
|
+
}
|
|
80
|
+
add(step.action.fromToken, BigInt(step.action.fromAmount), 'source')
|
|
81
|
+
for (const gas of step.estimate?.gasCosts ?? []) {
|
|
82
|
+
add(gas.token, BigInt(gas.amount), 'gas')
|
|
83
|
+
}
|
|
84
|
+
for (const fee of step.estimate?.feeCosts ?? []) {
|
|
85
|
+
// Included fees are already part of fromAmount — don't count twice.
|
|
86
|
+
if (!fee.included) {
|
|
87
|
+
add(fee.token, BigInt(fee.amount), 'fee')
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const reservedOverhead = (r: Requirement): bigint =>
|
|
92
|
+
r.feePart + (walletPaysGas ? r.gasPart : 0n)
|
|
93
|
+
const need = (r: Requirement): bigint => r.sourcePart + reservedOverhead(r)
|
|
94
|
+
|
|
95
|
+
// Drop pure-gas entries when `walletPaysGas` is false (e.g. native ETH
|
|
96
|
+
// on Safe Apps with only `gasPart`) — saves one balance read each.
|
|
97
|
+
for (const [key, req] of requirements) {
|
|
98
|
+
if (need(req) === 0n) {
|
|
99
|
+
requirements.delete(key)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (requirements.size === 0) {
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Provider is dispatched by wallet address; all requirements share the
|
|
108
|
+
// source chain, which matches this provider by virtue of the address.
|
|
109
|
+
const provider = client.providers.find((p) => p.isAddress(walletAddress))
|
|
110
|
+
if (!provider) {
|
|
111
|
+
throw new Error(`SDK Token Provider for ${walletAddress} is not found.`)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const reqs = Array.from(requirements.values())
|
|
115
|
+
const tokens = reqs.map((r) => r.token)
|
|
116
|
+
const slippage = step.action.slippage ?? 0
|
|
117
|
+
const slippageScaled = BigInt(
|
|
118
|
+
Math.floor((1 - slippage) * Number(SLIPPAGE_PRECISION))
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
await withTimeout(
|
|
122
|
+
async () => {
|
|
123
|
+
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
|
|
124
|
+
const isFinal = attempt === MAX_ATTEMPTS - 1
|
|
125
|
+
|
|
126
|
+
let balances: TokenAmount[]
|
|
127
|
+
try {
|
|
128
|
+
balances = await provider.getBalance(client, walletAddress, tokens)
|
|
129
|
+
} catch (error) {
|
|
130
|
+
if (isFinal) {
|
|
131
|
+
throw new BalanceError(
|
|
132
|
+
'Could not read wallet balance.',
|
|
133
|
+
error as Error
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
await sleep(BACKOFF_BASE_MS * 2 ** attempt)
|
|
137
|
+
continue
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const balanceByAddress = new Map(
|
|
141
|
+
balances.map((b) => [b.address.toLowerCase(), b.amount] as const)
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
const unknown: Token[] = []
|
|
145
|
+
const insufficient: { req: Requirement; have: bigint }[] = []
|
|
146
|
+
for (const req of reqs) {
|
|
147
|
+
const have = balanceByAddress.get(req.token.address.toLowerCase())
|
|
148
|
+
if (have === undefined) {
|
|
149
|
+
unknown.push(req.token)
|
|
150
|
+
} else if (have < need(req)) {
|
|
151
|
+
insufficient.push({ req, have })
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (unknown.length === 0 && insufficient.length === 0) {
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Final-attempt slippage rescue: only when the sole shortfall is
|
|
160
|
+
// the source-token portion. Trim source to (balance − reserved
|
|
161
|
+
// overhead) so the overhead reserve is preserved.
|
|
162
|
+
if (
|
|
163
|
+
isFinal &&
|
|
164
|
+
unknown.length === 0 &&
|
|
165
|
+
insufficient.length === 1 &&
|
|
166
|
+
insufficient[0].req.sourcePart > 0n
|
|
167
|
+
) {
|
|
168
|
+
const { req, have } = insufficient[0]
|
|
169
|
+
const reserved = reservedOverhead(req)
|
|
170
|
+
const minAcceptable =
|
|
171
|
+
(req.sourcePart * slippageScaled) / SLIPPAGE_PRECISION + reserved
|
|
172
|
+
if (have >= minAcceptable) {
|
|
173
|
+
const newFromAmount = (have - reserved).toString()
|
|
174
|
+
step.action.fromAmount = newFromAmount
|
|
175
|
+
if (step.includedSteps?.length) {
|
|
176
|
+
step.includedSteps[0].action.fromAmount = newFromAmount
|
|
177
|
+
}
|
|
178
|
+
return
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (isFinal) {
|
|
183
|
+
if (unknown.length > 0) {
|
|
184
|
+
throw new BalanceError(
|
|
185
|
+
'Could not read wallet balance.',
|
|
186
|
+
new Error(
|
|
187
|
+
`Could not read balance for: ${unknown
|
|
188
|
+
.map((t) => t.symbol || t.address)
|
|
189
|
+
.join(', ')}.`
|
|
190
|
+
)
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
const lines = insufficient.map(({ req, have }) => {
|
|
194
|
+
const needed = formatUnits(need(req), req.token.decimals)
|
|
195
|
+
const current = formatUnits(have, req.token.decimals)
|
|
196
|
+
const symbol = req.token.symbol
|
|
197
|
+
// The "fees" branch covers pure-overhead tokens; with
|
|
198
|
+
// walletPaysGas=false, gas is excluded from `need(req)` so it
|
|
199
|
+
// only fires for genuine fee shortfalls.
|
|
200
|
+
return req.sourcePart > 0n
|
|
201
|
+
? `Your ${symbol} balance is too low, you try to transfer ${needed} ${symbol}, but your wallet only holds ${current} ${symbol}.`
|
|
202
|
+
: `Insufficient ${symbol} for fees: need ${needed} ${symbol}, have ${current} ${symbol}.`
|
|
203
|
+
})
|
|
204
|
+
throw new BalanceError(
|
|
205
|
+
'The balance is too low.',
|
|
206
|
+
new Error(`${lines.join(' ')} No funds have been sent.`)
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
await sleep(BACKOFF_BASE_MS * 2 ** attempt)
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
timeout: OVERALL_TIMEOUT_MS,
|
|
215
|
+
errorInstance: new BalanceError('Could not read wallet balance.'),
|
|
216
|
+
}
|
|
217
|
+
)
|
|
218
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { LiFiErrorCode } from '../../../errors/constants.js'
|
|
2
|
+
import { TransactionError } from '../../../errors/errors.js'
|
|
3
|
+
import type {
|
|
4
|
+
ExecutionOptions,
|
|
5
|
+
LiFiStepExtended,
|
|
6
|
+
TransactionParameters,
|
|
7
|
+
} from '../../../types/core.js'
|
|
8
|
+
|
|
9
|
+
export const getTransactionRequestData = async (
|
|
10
|
+
step: LiFiStepExtended,
|
|
11
|
+
executionOptions?: ExecutionOptions
|
|
12
|
+
): Promise<string> => {
|
|
13
|
+
if (!step.transactionRequest?.data) {
|
|
14
|
+
throw new TransactionError(
|
|
15
|
+
LiFiErrorCode.TransactionUnprepared,
|
|
16
|
+
'Unable to prepare transaction. Transaction request data is not found.'
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let transactionRequest: TransactionParameters = {
|
|
21
|
+
data: step.transactionRequest.data,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (executionOptions?.updateTransactionRequestHook) {
|
|
25
|
+
const customizedTransactionRequest: TransactionParameters =
|
|
26
|
+
await executionOptions.updateTransactionRequestHook({
|
|
27
|
+
requestType: 'transaction',
|
|
28
|
+
...transactionRequest,
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
transactionRequest = {
|
|
32
|
+
...transactionRequest,
|
|
33
|
+
...customizedTransactionRequest,
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const transactionRequestData = transactionRequest.data
|
|
38
|
+
|
|
39
|
+
if (!transactionRequestData) {
|
|
40
|
+
throw new TransactionError(
|
|
41
|
+
LiFiErrorCode.TransactionUnprepared,
|
|
42
|
+
'Unable to prepare transaction. Transaction request data is not found.'
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return transactionRequestData
|
|
47
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { LiFiStep } from '@lifi/types'
|
|
2
|
+
import type { StatusManager } from '../../../core/StatusManager.js'
|
|
3
|
+
import { checkStepSlippageThreshold } from '../../../core/utils.js'
|
|
4
|
+
import { LiFiErrorCode } from '../../../errors/constants.js'
|
|
5
|
+
import { TransactionError } from '../../../errors/errors.js'
|
|
6
|
+
import type { ExecutionOptions } from '../../../types/core.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This method checks whether the new and updated Step meets the required exchange rate conditions.
|
|
10
|
+
* If yes it returns the updated Step.
|
|
11
|
+
* If no and if user interaction is allowed it triggers the acceptExchangeRateUpdateHook. If no user interaction is allowed it aborts.
|
|
12
|
+
* @param statusManager
|
|
13
|
+
* @param oldStep
|
|
14
|
+
* @param newStep
|
|
15
|
+
* @param settings
|
|
16
|
+
* @param allowUserInteraction
|
|
17
|
+
* @param executionOptions
|
|
18
|
+
* @returns Return LiFiStep
|
|
19
|
+
*/
|
|
20
|
+
export const stepComparison = async (
|
|
21
|
+
statusManager: StatusManager,
|
|
22
|
+
oldStep: LiFiStep,
|
|
23
|
+
newStep: LiFiStep,
|
|
24
|
+
allowUserInteraction: boolean,
|
|
25
|
+
executionOptions?: ExecutionOptions
|
|
26
|
+
): Promise<LiFiStep> => {
|
|
27
|
+
// Check if changed exchange rate is in the range of slippage threshold
|
|
28
|
+
if (checkStepSlippageThreshold(oldStep, newStep)) {
|
|
29
|
+
return statusManager.updateStepInRoute(newStep)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let allowStepUpdate: boolean | undefined
|
|
33
|
+
if (allowUserInteraction) {
|
|
34
|
+
allowStepUpdate = await executionOptions?.acceptExchangeRateUpdateHook?.({
|
|
35
|
+
oldToAmount: oldStep.estimate.toAmount,
|
|
36
|
+
newToAmount: newStep.estimate.toAmount,
|
|
37
|
+
toToken: newStep.action.toToken,
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!allowStepUpdate) {
|
|
42
|
+
// The user declined the new exchange rate, so we are not going to proceed
|
|
43
|
+
throw new TransactionError(
|
|
44
|
+
LiFiErrorCode.ExchangeRateUpdateCanceled,
|
|
45
|
+
'Exchange rate has changed!\nTransaction was not sent, your funds are still in your wallet.\nThe exchange rate has changed and the previous estimation can not be fulfilled due to value loss.'
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return statusManager.updateStepInRoute(newStep)
|
|
50
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { FullStatusData, LiFiStep, StatusResponse } from '@lifi/types'
|
|
2
|
+
import { getStatus } from '../../../actions/getStatus.js'
|
|
3
|
+
import { ServerError } from '../../../errors/errors.js'
|
|
4
|
+
import type { ExecutionActionType, SDKClient } from '../../../types/core.js'
|
|
5
|
+
import { waitForResult } from '../../../utils/waitForResult.js'
|
|
6
|
+
import { getSubstatusMessage } from '../../actionMessages.js'
|
|
7
|
+
import type { StatusManager } from '../../StatusManager.js'
|
|
8
|
+
|
|
9
|
+
const TRANSACTION_HASH_OBSERVERS: Record<string, Promise<StatusResponse>> = {}
|
|
10
|
+
|
|
11
|
+
export async function waitForTransactionStatus(
|
|
12
|
+
client: SDKClient,
|
|
13
|
+
statusManager: StatusManager,
|
|
14
|
+
txHash: string,
|
|
15
|
+
step: LiFiStep,
|
|
16
|
+
actionType: ExecutionActionType,
|
|
17
|
+
interval = 5_000
|
|
18
|
+
): Promise<StatusResponse> {
|
|
19
|
+
const _getStatus = (): Promise<StatusResponse | undefined> => {
|
|
20
|
+
return getStatus(client, {
|
|
21
|
+
fromChain: step.action.fromChainId,
|
|
22
|
+
fromAddress: step.action.fromAddress,
|
|
23
|
+
toChain: step.action.toChainId,
|
|
24
|
+
txHash,
|
|
25
|
+
...(step.tool !== 'custom' && { bridge: step.tool }),
|
|
26
|
+
...(step.transactionId && { transactionId: step.transactionId }),
|
|
27
|
+
})
|
|
28
|
+
.then((statusResponse) => {
|
|
29
|
+
switch (statusResponse.status) {
|
|
30
|
+
case 'DONE':
|
|
31
|
+
return statusResponse
|
|
32
|
+
case 'PENDING':
|
|
33
|
+
statusManager?.updateAction(step, actionType, 'PENDING', {
|
|
34
|
+
substatus: statusResponse.substatus,
|
|
35
|
+
substatusMessage:
|
|
36
|
+
statusResponse.substatusMessage ||
|
|
37
|
+
getSubstatusMessage(
|
|
38
|
+
statusResponse.status,
|
|
39
|
+
statusResponse.substatus
|
|
40
|
+
),
|
|
41
|
+
txLink: (statusResponse as FullStatusData).bridgeExplorerLink,
|
|
42
|
+
})
|
|
43
|
+
return undefined
|
|
44
|
+
case 'NOT_FOUND':
|
|
45
|
+
return undefined
|
|
46
|
+
default:
|
|
47
|
+
return Promise.reject()
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
.catch((e) => {
|
|
51
|
+
if (process.env.NODE_ENV === 'development') {
|
|
52
|
+
console.debug('Fetching status from backend failed.', e)
|
|
53
|
+
}
|
|
54
|
+
return undefined
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let status = TRANSACTION_HASH_OBSERVERS[txHash]
|
|
59
|
+
|
|
60
|
+
if (!status) {
|
|
61
|
+
status = waitForResult(_getStatus, interval).finally(() => {
|
|
62
|
+
delete TRANSACTION_HASH_OBSERVERS[txHash]
|
|
63
|
+
})
|
|
64
|
+
TRANSACTION_HASH_OBSERVERS[txHash] = status
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const resolvedStatus = await status
|
|
68
|
+
|
|
69
|
+
if (!('receiving' in resolvedStatus)) {
|
|
70
|
+
throw new ServerError(
|
|
71
|
+
"Status doesn't contain destination chain information."
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return resolvedStatus
|
|
76
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ChainId, ExtendedChain, LiFiStep } from '@lifi/types'
|
|
2
|
+
import type { RPCUrls } from '../types/core.js'
|
|
3
|
+
|
|
4
|
+
// Standard threshold for destination amount difference (0.5%)
|
|
5
|
+
const standardThreshold = 0.005
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Used to check if changed exchange rate is in the range of slippage threshold.
|
|
9
|
+
* We use a slippage value as a threshold to trigger the rate change hook.
|
|
10
|
+
* This can result in almost doubled slippage for the user and need to be revisited.
|
|
11
|
+
* @param oldStep - old step
|
|
12
|
+
* @param newStep - new step
|
|
13
|
+
* @returns Boolean
|
|
14
|
+
*/
|
|
15
|
+
export function checkStepSlippageThreshold(
|
|
16
|
+
oldStep: LiFiStep,
|
|
17
|
+
newStep: LiFiStep
|
|
18
|
+
): boolean {
|
|
19
|
+
const setSlippage = oldStep.action.slippage || standardThreshold
|
|
20
|
+
const oldEstimatedToAmount = BigInt(oldStep.estimate.toAmountMin)
|
|
21
|
+
const newEstimatedToAmount = BigInt(newStep.estimate.toAmountMin)
|
|
22
|
+
const amountDifference = oldEstimatedToAmount - newEstimatedToAmount
|
|
23
|
+
// oldEstimatedToAmount can be 0 when we use contract calls
|
|
24
|
+
let actualSlippage = 0
|
|
25
|
+
if (oldEstimatedToAmount > 0) {
|
|
26
|
+
actualSlippage =
|
|
27
|
+
Number((amountDifference * 1_000_000_000n) / oldEstimatedToAmount) /
|
|
28
|
+
1_000_000_000
|
|
29
|
+
}
|
|
30
|
+
return actualSlippage <= setSlippage
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function getRpcUrlsFromChains(
|
|
34
|
+
existingRpcUrls: RPCUrls,
|
|
35
|
+
chains: ExtendedChain[],
|
|
36
|
+
skipChains?: ChainId[]
|
|
37
|
+
): RPCUrls {
|
|
38
|
+
const rpcUrlsFromChains = chains.reduce((rpcUrls, chain) => {
|
|
39
|
+
if (chain.metamask?.rpcUrls?.length) {
|
|
40
|
+
rpcUrls[chain.id as ChainId] = chain.metamask.rpcUrls
|
|
41
|
+
}
|
|
42
|
+
return rpcUrls
|
|
43
|
+
}, {} as RPCUrls)
|
|
44
|
+
const result = { ...existingRpcUrls }
|
|
45
|
+
for (const rpcUrlsKey in rpcUrlsFromChains) {
|
|
46
|
+
const chainId = Number(rpcUrlsKey) as ChainId
|
|
47
|
+
const urls = rpcUrlsFromChains[chainId]
|
|
48
|
+
if (!urls?.length) {
|
|
49
|
+
continue
|
|
50
|
+
}
|
|
51
|
+
if (!result[chainId]?.length) {
|
|
52
|
+
result[chainId] = Array.from(urls)
|
|
53
|
+
} else if (!skipChains?.includes(chainId)) {
|
|
54
|
+
const filteredUrls = urls.filter((url) => !result[chainId]?.includes(url))
|
|
55
|
+
result[chainId].push(...filteredUrls)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return result
|
|
59
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { LiFiStep } from '@lifi/types'
|
|
2
|
+
import type { ExecutionAction } from '../types/core.js'
|
|
3
|
+
import { version } from '../version.js'
|
|
4
|
+
import type { BaseError } from './baseError.js'
|
|
5
|
+
import type { ErrorCode } from './constants.js'
|
|
6
|
+
|
|
7
|
+
// Note: SDKError is used to wrapper and present errors at the top level
|
|
8
|
+
// Where opportunity allows we also add the step and the action related to the error
|
|
9
|
+
export class SDKError extends Error {
|
|
10
|
+
step?: LiFiStep
|
|
11
|
+
action?: ExecutionAction
|
|
12
|
+
code: ErrorCode
|
|
13
|
+
override name = 'SDKError'
|
|
14
|
+
override cause: BaseError
|
|
15
|
+
|
|
16
|
+
constructor(cause: BaseError, step?: LiFiStep, action?: ExecutionAction) {
|
|
17
|
+
const errorMessage = `${cause.message ? `[${cause.name}] ${cause.message}` : 'Unknown error occurred'}\nLI.FI SDK version: ${version}`
|
|
18
|
+
super(errorMessage)
|
|
19
|
+
this.name = 'SDKError'
|
|
20
|
+
this.step = step
|
|
21
|
+
this.action = action
|
|
22
|
+
this.cause = cause
|
|
23
|
+
this.stack = this.cause.stack
|
|
24
|
+
this.code = cause.code
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ErrorCode, ErrorName } from './constants.js'
|
|
2
|
+
import { getRootCause } from './utils/rootCause.js'
|
|
3
|
+
|
|
4
|
+
// Note: we use the BaseErrors to capture errors at specific points in the code
|
|
5
|
+
// they can carry addition to help give more context
|
|
6
|
+
export class BaseError extends Error {
|
|
7
|
+
code: ErrorCode
|
|
8
|
+
override cause?: Error
|
|
9
|
+
|
|
10
|
+
constructor(name: ErrorName, code: number, message: string, cause?: Error) {
|
|
11
|
+
super(message)
|
|
12
|
+
|
|
13
|
+
this.name = name
|
|
14
|
+
this.code = code
|
|
15
|
+
this.cause = cause
|
|
16
|
+
|
|
17
|
+
const rootCause = getRootCause(this.cause)
|
|
18
|
+
if (rootCause?.stack) {
|
|
19
|
+
this.stack = rootCause.stack
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export enum ErrorName {
|
|
2
|
+
RPCError = 'RPCError',
|
|
3
|
+
ProviderError = 'ProviderError',
|
|
4
|
+
ServerError = 'ServerError',
|
|
5
|
+
TransactionError = 'TransactionError',
|
|
6
|
+
ValidationError = 'ValidationError',
|
|
7
|
+
BalanceError = 'BalanceError',
|
|
8
|
+
NotFoundError = 'NotFoundError',
|
|
9
|
+
UnknownError = 'UnknownError',
|
|
10
|
+
SlippageError = 'SlippageError',
|
|
11
|
+
HTTPError = 'HTTPError',
|
|
12
|
+
ConfigError = 'ConfigError',
|
|
13
|
+
ExecuteStepRetryError = 'ExecuteStepRetryError',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type ErrorCode = LiFiErrorCode
|
|
17
|
+
|
|
18
|
+
export enum LiFiErrorCode {
|
|
19
|
+
InternalError = 1000,
|
|
20
|
+
ValidationError = 1001,
|
|
21
|
+
TransactionUnderpriced = 1002,
|
|
22
|
+
TransactionFailed = 1003,
|
|
23
|
+
Timeout = 1004,
|
|
24
|
+
ProviderUnavailable = 1005,
|
|
25
|
+
NotFound = 1006,
|
|
26
|
+
ChainSwitchError = 1007,
|
|
27
|
+
TransactionUnprepared = 1008,
|
|
28
|
+
GasLimitError = 1009,
|
|
29
|
+
TransactionCanceled = 1010,
|
|
30
|
+
SlippageError = 1011,
|
|
31
|
+
SignatureRejected = 1012,
|
|
32
|
+
BalanceError = 1013,
|
|
33
|
+
AllowanceRequired = 1014,
|
|
34
|
+
InsufficientFunds = 1015,
|
|
35
|
+
ExchangeRateUpdateCanceled = 1016,
|
|
36
|
+
WalletChangedDuringExecution = 1017,
|
|
37
|
+
TransactionExpired = 1018,
|
|
38
|
+
TransactionSimulationFailed = 1019,
|
|
39
|
+
TransactionConflict = 1020,
|
|
40
|
+
TransactionNotFound = 1021,
|
|
41
|
+
TransactionRejected = 1022,
|
|
42
|
+
RateLimitExceeded = 1023,
|
|
43
|
+
ThirdPartyError = 1024,
|
|
44
|
+
InsufficientGas = 1025,
|
|
45
|
+
ConfigError = 1026,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export enum ErrorMessage {
|
|
49
|
+
UnknownError = 'Unknown error occurred.',
|
|
50
|
+
SlippageError = 'The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.',
|
|
51
|
+
GasLimitLow = 'Gas limit is too low.',
|
|
52
|
+
TransactionUnderpriced = 'Transaction is underpriced.',
|
|
53
|
+
TransactionReverted = 'Transaction was reverted.',
|
|
54
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ExecuteStepRetryParams } from '../types/core.js'
|
|
2
|
+
import { BaseError } from './baseError.js'
|
|
3
|
+
import { ErrorName, LiFiErrorCode } from './constants.js'
|
|
4
|
+
|
|
5
|
+
export class RPCError extends BaseError {
|
|
6
|
+
constructor(code: LiFiErrorCode, message: string, cause?: Error) {
|
|
7
|
+
super(ErrorName.RPCError, code, message, cause)
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class ProviderError extends BaseError {
|
|
12
|
+
constructor(code: LiFiErrorCode, message: string, cause?: Error) {
|
|
13
|
+
super(ErrorName.ProviderError, code, message, cause)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class TransactionError extends BaseError {
|
|
18
|
+
constructor(code: LiFiErrorCode, message: string, cause?: Error) {
|
|
19
|
+
super(ErrorName.TransactionError, code, message, cause)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class UnknownError extends BaseError {
|
|
24
|
+
constructor(message: string, cause?: Error) {
|
|
25
|
+
super(ErrorName.UnknownError, LiFiErrorCode.InternalError, message, cause)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class BalanceError extends BaseError {
|
|
30
|
+
constructor(message: string, cause?: Error) {
|
|
31
|
+
super(ErrorName.BalanceError, LiFiErrorCode.BalanceError, message, cause)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class ServerError extends BaseError {
|
|
36
|
+
constructor(message: string) {
|
|
37
|
+
super(ErrorName.ServerError, LiFiErrorCode.InternalError, message)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class ValidationError extends BaseError {
|
|
42
|
+
constructor(message: string) {
|
|
43
|
+
super(ErrorName.ValidationError, LiFiErrorCode.ValidationError, message)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Thrown by a step executor when executeStep should be retried with the given params
|
|
49
|
+
* (e.g. wallet rejected 7702 upgrade → retry with atomicityNotReady).
|
|
50
|
+
* The execution layer catches this and retries executeStep(client, step, retryParams).
|
|
51
|
+
*/
|
|
52
|
+
export class ExecuteStepRetryError extends BaseError {
|
|
53
|
+
readonly retryParams: ExecuteStepRetryParams
|
|
54
|
+
|
|
55
|
+
constructor(
|
|
56
|
+
message: string,
|
|
57
|
+
retryParams: ExecuteStepRetryParams,
|
|
58
|
+
cause?: Error
|
|
59
|
+
) {
|
|
60
|
+
super(
|
|
61
|
+
ErrorName.ExecuteStepRetryError,
|
|
62
|
+
LiFiErrorCode.InternalError,
|
|
63
|
+
message,
|
|
64
|
+
cause
|
|
65
|
+
)
|
|
66
|
+
this.retryParams = retryParams
|
|
67
|
+
}
|
|
68
|
+
}
|