@lifi/sdk 4.0.0-alpha.2 → 4.0.0-alpha.21
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/dist/cjs/actions/getChains.d.ts +1 -1
- package/dist/cjs/actions/getChains.js +4 -4
- package/dist/cjs/actions/getChains.js.map +1 -1
- package/dist/cjs/actions/getRelayedTransactionStatus.js +1 -1
- package/dist/cjs/actions/getRelayedTransactionStatus.js.map +1 -1
- package/dist/cjs/actions/getStepTransaction.js +9 -1
- package/dist/cjs/actions/getStepTransaction.js.map +1 -1
- package/dist/cjs/actions/index.d.ts +3 -1
- package/dist/cjs/actions/index.js +2 -0
- package/dist/cjs/actions/index.js.map +1 -1
- package/dist/cjs/actions/patchContractCalls.d.ts +10 -0
- package/dist/cjs/actions/patchContractCalls.js +16 -0
- package/dist/cjs/actions/patchContractCalls.js.map +1 -0
- package/dist/cjs/client/createClient.js +4 -0
- package/dist/cjs/client/createClient.js.map +1 -1
- package/dist/cjs/client/getClientStorage.d.ts +1 -0
- package/dist/cjs/client/getClientStorage.js +18 -6
- package/dist/cjs/client/getClientStorage.js.map +1 -1
- package/dist/cjs/core/BaseStepExecutionTask.d.ts +5 -0
- package/dist/cjs/core/BaseStepExecutionTask.js +10 -0
- package/dist/cjs/core/BaseStepExecutionTask.js.map +1 -0
- package/dist/cjs/core/BaseStepExecutor.d.ts +10 -3
- package/dist/cjs/core/BaseStepExecutor.js +53 -0
- package/dist/cjs/core/BaseStepExecutor.js.map +1 -1
- package/dist/cjs/core/StatusManager.d.ts +13 -12
- package/dist/cjs/core/StatusManager.js +55 -61
- package/dist/cjs/core/StatusManager.js.map +1 -1
- package/dist/cjs/core/TaskPipeline.d.ts +7 -0
- package/dist/cjs/core/TaskPipeline.js +27 -0
- package/dist/cjs/core/TaskPipeline.js.map +1 -0
- package/dist/cjs/core/actionMessages.d.ts +4 -0
- package/dist/cjs/core/{processMessages.js → actionMessages.js} +25 -9
- package/dist/cjs/core/actionMessages.js.map +1 -0
- package/dist/cjs/core/execution.js +13 -1
- package/dist/cjs/core/execution.js.map +1 -1
- package/dist/cjs/core/prepareRestart.js +6 -6
- package/dist/cjs/core/prepareRestart.js.map +1 -1
- package/dist/cjs/core/storage.d.ts +17 -0
- package/dist/cjs/core/storage.js +36 -0
- package/dist/cjs/core/storage.js.map +1 -0
- package/dist/cjs/core/tasks/CheckBalanceTask.d.ts +5 -0
- package/dist/cjs/core/tasks/CheckBalanceTask.js +26 -0
- package/dist/cjs/core/tasks/CheckBalanceTask.js.map +1 -0
- package/dist/cjs/core/tasks/PrepareTransactionTask.d.ts +5 -0
- package/dist/cjs/core/tasks/PrepareTransactionTask.js +36 -0
- package/dist/cjs/core/tasks/PrepareTransactionTask.js.map +1 -0
- package/dist/cjs/core/tasks/WaitForTransactionStatusTask.d.ts +8 -0
- package/dist/cjs/core/tasks/WaitForTransactionStatusTask.js +73 -0
- package/dist/cjs/core/tasks/WaitForTransactionStatusTask.js.map +1 -0
- package/dist/cjs/core/{checkBalance.d.ts → tasks/helpers/checkBalance.d.ts} +1 -1
- package/dist/cjs/core/{checkBalance.js → tasks/helpers/checkBalance.js} +6 -6
- package/dist/cjs/core/tasks/helpers/checkBalance.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/getTransactionRequestData.d.ts +2 -0
- package/dist/cjs/core/tasks/helpers/getTransactionRequestData.js +30 -0
- package/dist/cjs/core/tasks/helpers/getTransactionRequestData.js.map +1 -0
- package/dist/cjs/core/{stepComparison.d.ts → tasks/helpers/stepComparison.d.ts} +2 -2
- package/dist/cjs/core/{stepComparison.js → tasks/helpers/stepComparison.js} +3 -3
- package/dist/cjs/core/tasks/helpers/stepComparison.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.d.ts +4 -0
- package/dist/cjs/core/{waitForTransactionStatus.js → tasks/helpers/waitForTransactionStatus.js} +10 -8
- package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.js.map +1 -0
- package/dist/cjs/core/utils.d.ts +9 -3
- package/dist/cjs/core/utils.js +0 -5
- package/dist/cjs/core/utils.js.map +1 -1
- package/dist/cjs/errors/SDKError.d.ts +3 -3
- package/dist/cjs/errors/SDKError.js +3 -3
- package/dist/cjs/errors/SDKError.js.map +1 -1
- package/dist/cjs/errors/constants.d.ts +5 -2
- package/dist/cjs/errors/constants.js +3 -0
- package/dist/cjs/errors/constants.js.map +1 -1
- package/dist/cjs/errors/errors.d.ts +5 -0
- package/dist/cjs/errors/errors.js +9 -1
- package/dist/cjs/errors/errors.js.map +1 -1
- package/dist/cjs/index.d.ts +20 -10
- package/dist/cjs/index.js +34 -14
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/core.d.ts +51 -21
- package/dist/cjs/types/execution.d.ts +22 -0
- package/dist/cjs/types/execution.js +3 -0
- package/dist/cjs/types/execution.js.map +1 -0
- package/dist/cjs/utils/convertQuoteToRoute.d.ts +6 -1
- package/dist/cjs/utils/convertQuoteToRoute.js +73 -5
- package/dist/cjs/utils/convertQuoteToRoute.js.map +1 -1
- package/dist/cjs/utils/formatUnits.d.ts +1 -0
- package/dist/cjs/utils/formatUnits.js +18 -0
- package/dist/cjs/utils/formatUnits.js.map +1 -0
- package/dist/cjs/utils/isHex.d.ts +4 -0
- package/dist/cjs/utils/isHex.js +13 -0
- package/dist/cjs/utils/isHex.js.map +1 -0
- package/dist/cjs/utils/parseUnits.d.ts +1 -0
- package/dist/cjs/utils/parseUnits.js +44 -0
- package/dist/cjs/utils/parseUnits.js.map +1 -0
- package/dist/cjs/utils/request.js +7 -6
- package/dist/cjs/utils/request.js.map +1 -1
- package/dist/cjs/utils/waitForResult.d.ts +1 -1
- package/dist/cjs/utils/waitForResult.js +6 -2
- package/dist/cjs/utils/waitForResult.js.map +1 -1
- package/dist/cjs/utils/withDedupe.d.ts +5 -0
- package/dist/cjs/utils/withDedupe.js +2 -0
- package/dist/cjs/utils/withDedupe.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/actions/getChains.d.ts +1 -1
- package/dist/esm/actions/getChains.js +2 -2
- package/dist/esm/actions/getChains.js.map +1 -1
- package/dist/esm/actions/getRelayedTransactionStatus.js +1 -1
- package/dist/esm/actions/getRelayedTransactionStatus.js.map +1 -1
- package/dist/esm/actions/getStepTransaction.js +10 -1
- package/dist/esm/actions/getStepTransaction.js.map +1 -1
- package/dist/esm/actions/index.d.ts +9 -1
- package/dist/esm/actions/index.js +2 -0
- package/dist/esm/actions/index.js.map +1 -1
- package/dist/esm/actions/patchContractCalls.d.ts +10 -0
- package/dist/esm/actions/patchContractCalls.js +12 -0
- package/dist/esm/actions/patchContractCalls.js.map +1 -0
- package/dist/esm/client/createClient.js +4 -0
- package/dist/esm/client/createClient.js.map +1 -1
- package/dist/esm/client/getClientStorage.d.ts +1 -0
- package/dist/esm/client/getClientStorage.js +22 -7
- package/dist/esm/client/getClientStorage.js.map +1 -1
- package/dist/esm/core/BaseStepExecutionTask.d.ts +5 -0
- package/dist/esm/core/BaseStepExecutionTask.js +6 -0
- package/dist/esm/core/BaseStepExecutionTask.js.map +1 -0
- package/dist/esm/core/BaseStepExecutor.d.ts +10 -3
- package/dist/esm/core/BaseStepExecutor.js +53 -0
- package/dist/esm/core/BaseStepExecutor.js.map +1 -1
- package/dist/esm/core/StatusManager.d.ts +40 -39
- package/dist/esm/core/StatusManager.js +86 -92
- package/dist/esm/core/StatusManager.js.map +1 -1
- package/dist/esm/core/TaskPipeline.d.ts +7 -0
- package/dist/esm/core/TaskPipeline.js +23 -0
- package/dist/esm/core/TaskPipeline.js.map +1 -0
- package/dist/esm/core/actionMessages.d.ts +4 -0
- package/dist/esm/core/{processMessages.js → actionMessages.js} +24 -8
- package/dist/esm/core/actionMessages.js.map +1 -0
- package/dist/esm/core/execution.js +14 -3
- package/dist/esm/core/execution.js.map +1 -1
- package/dist/esm/core/prepareRestart.js +10 -9
- package/dist/esm/core/prepareRestart.js.map +1 -1
- package/dist/esm/core/storage.d.ts +17 -0
- package/dist/esm/core/storage.js +30 -0
- package/dist/esm/core/storage.js.map +1 -0
- package/dist/esm/core/tasks/CheckBalanceTask.d.ts +5 -0
- package/dist/esm/core/tasks/CheckBalanceTask.js +22 -0
- package/dist/esm/core/tasks/CheckBalanceTask.js.map +1 -0
- package/dist/esm/core/tasks/PrepareTransactionTask.d.ts +5 -0
- package/dist/esm/core/tasks/PrepareTransactionTask.js +32 -0
- package/dist/esm/core/tasks/PrepareTransactionTask.js.map +1 -0
- package/dist/esm/core/tasks/WaitForTransactionStatusTask.d.ts +8 -0
- package/dist/esm/core/tasks/WaitForTransactionStatusTask.js +74 -0
- package/dist/esm/core/tasks/WaitForTransactionStatusTask.js.map +1 -0
- package/dist/esm/core/{checkBalance.d.ts → tasks/helpers/checkBalance.d.ts} +1 -1
- package/dist/esm/core/{checkBalance.js → tasks/helpers/checkBalance.js} +4 -4
- package/dist/esm/core/tasks/helpers/checkBalance.js.map +1 -0
- package/dist/esm/core/tasks/helpers/getTransactionRequestData.d.ts +2 -0
- package/dist/esm/core/tasks/helpers/getTransactionRequestData.js +26 -0
- package/dist/esm/core/tasks/helpers/getTransactionRequestData.js.map +1 -0
- package/dist/esm/core/{stepComparison.d.ts → tasks/helpers/stepComparison.d.ts} +2 -2
- package/dist/esm/core/{stepComparison.js → tasks/helpers/stepComparison.js} +3 -3
- package/dist/esm/core/tasks/helpers/stepComparison.js.map +1 -0
- package/dist/esm/core/tasks/helpers/waitForTransactionStatus.d.ts +4 -0
- package/dist/esm/core/{waitForTransactionStatus.js → tasks/helpers/waitForTransactionStatus.js} +9 -7
- package/dist/esm/core/tasks/helpers/waitForTransactionStatus.js.map +1 -0
- package/dist/esm/core/utils.d.ts +9 -11
- package/dist/esm/core/utils.js +0 -11
- package/dist/esm/core/utils.js.map +1 -1
- package/dist/esm/errors/SDKError.d.ts +3 -3
- package/dist/esm/errors/SDKError.js +4 -4
- package/dist/esm/errors/SDKError.js.map +1 -1
- package/dist/esm/errors/constants.d.ts +5 -2
- package/dist/esm/errors/constants.js +3 -0
- package/dist/esm/errors/constants.js.map +1 -1
- package/dist/esm/errors/errors.d.ts +10 -0
- package/dist/esm/errors/errors.js +12 -0
- package/dist/esm/errors/errors.js.map +1 -1
- package/dist/esm/index.d.ts +20 -10
- package/dist/esm/index.js +17 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/core.d.ts +55 -21
- package/dist/esm/types/execution.d.ts +23 -0
- package/dist/esm/types/execution.js +2 -0
- package/dist/esm/types/execution.js.map +1 -0
- package/dist/esm/utils/convertQuoteToRoute.d.ts +11 -3
- package/dist/esm/utils/convertQuoteToRoute.js +76 -7
- package/dist/esm/utils/convertQuoteToRoute.js.map +1 -1
- package/dist/esm/utils/formatUnits.d.ts +4 -0
- package/dist/esm/utils/formatUnits.js +18 -0
- package/dist/esm/utils/formatUnits.js.map +1 -0
- package/dist/esm/utils/isHex.d.ts +4 -0
- package/dist/esm/utils/isHex.js +10 -0
- package/dist/esm/utils/isHex.js.map +1 -0
- package/dist/esm/utils/parseUnits.d.ts +4 -0
- package/dist/esm/utils/parseUnits.js +46 -0
- package/dist/esm/utils/parseUnits.js.map +1 -0
- package/dist/esm/utils/request.js +7 -6
- package/dist/esm/utils/request.js.map +1 -1
- package/dist/esm/utils/waitForResult.d.ts +2 -2
- package/dist/esm/utils/waitForResult.js +7 -3
- package/dist/esm/utils/waitForResult.js.map +1 -1
- package/dist/esm/utils/withDedupe.d.ts +10 -0
- package/dist/esm/utils/withDedupe.js +1 -1
- package/dist/esm/utils/withDedupe.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/actions/getChains.d.ts +1 -1
- package/dist/types/actions/getChains.d.ts.map +1 -1
- package/dist/types/actions/getStepTransaction.d.ts.map +1 -1
- package/dist/types/actions/index.d.ts +9 -1
- package/dist/types/actions/index.d.ts.map +1 -1
- package/dist/types/actions/patchContractCalls.d.ts +11 -0
- package/dist/types/actions/patchContractCalls.d.ts.map +1 -0
- package/dist/types/client/createClient.d.ts.map +1 -1
- package/dist/types/client/getClientStorage.d.ts +1 -0
- package/dist/types/client/getClientStorage.d.ts.map +1 -1
- package/dist/types/core/BaseStepExecutionTask.d.ts +6 -0
- package/dist/types/core/BaseStepExecutionTask.d.ts.map +1 -0
- package/dist/types/core/BaseStepExecutor.d.ts +10 -3
- package/dist/types/core/BaseStepExecutor.d.ts.map +1 -1
- package/dist/types/core/StatusManager.d.ts +40 -39
- package/dist/types/core/StatusManager.d.ts.map +1 -1
- package/dist/types/core/TaskPipeline.d.ts +8 -0
- package/dist/types/core/TaskPipeline.d.ts.map +1 -0
- package/dist/types/core/actionMessages.d.ts +5 -0
- package/dist/types/core/actionMessages.d.ts.map +1 -0
- package/dist/types/core/execution.d.ts.map +1 -1
- package/dist/types/core/prepareRestart.d.ts.map +1 -1
- package/dist/types/core/storage.d.ts +18 -0
- package/dist/types/core/storage.d.ts.map +1 -0
- package/dist/types/core/tasks/CheckBalanceTask.d.ts +6 -0
- package/dist/types/core/tasks/CheckBalanceTask.d.ts.map +1 -0
- package/dist/types/core/tasks/PrepareTransactionTask.d.ts +6 -0
- package/dist/types/core/tasks/PrepareTransactionTask.d.ts.map +1 -0
- package/dist/types/core/tasks/WaitForTransactionStatusTask.d.ts +9 -0
- package/dist/types/core/tasks/WaitForTransactionStatusTask.d.ts.map +1 -0
- package/dist/types/core/{checkBalance.d.ts → tasks/helpers/checkBalance.d.ts} +1 -1
- package/dist/types/core/tasks/helpers/checkBalance.d.ts.map +1 -0
- package/dist/types/core/tasks/helpers/getTransactionRequestData.d.ts +3 -0
- package/dist/types/core/tasks/helpers/getTransactionRequestData.d.ts.map +1 -0
- package/dist/types/core/{stepComparison.d.ts → tasks/helpers/stepComparison.d.ts} +2 -2
- package/dist/types/core/tasks/helpers/stepComparison.d.ts.map +1 -0
- package/dist/types/core/tasks/helpers/waitForTransactionStatus.d.ts +5 -0
- package/dist/types/core/tasks/helpers/waitForTransactionStatus.d.ts.map +1 -0
- package/dist/types/core/utils.d.ts +9 -11
- package/dist/types/core/utils.d.ts.map +1 -1
- package/dist/types/errors/SDKError.d.ts +3 -3
- package/dist/types/errors/SDKError.d.ts.map +1 -1
- package/dist/types/errors/constants.d.ts +5 -2
- package/dist/types/errors/constants.d.ts.map +1 -1
- package/dist/types/errors/errors.d.ts +10 -0
- package/dist/types/errors/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +20 -10
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/core.d.ts +55 -21
- package/dist/types/types/core.d.ts.map +1 -1
- package/dist/types/types/execution.d.ts +24 -0
- package/dist/types/types/execution.d.ts.map +1 -0
- package/dist/types/utils/convertQuoteToRoute.d.ts +11 -3
- package/dist/types/utils/convertQuoteToRoute.d.ts.map +1 -1
- package/dist/types/utils/formatUnits.d.ts +5 -0
- package/dist/types/utils/formatUnits.d.ts.map +1 -0
- package/dist/types/utils/isHex.d.ts +5 -0
- package/dist/types/utils/isHex.d.ts.map +1 -0
- package/dist/types/utils/parseUnits.d.ts +5 -0
- package/dist/types/utils/parseUnits.d.ts.map +1 -0
- package/dist/types/utils/request.d.ts.map +1 -1
- package/dist/types/utils/waitForResult.d.ts +2 -2
- package/dist/types/utils/waitForResult.d.ts.map +1 -1
- package/dist/types/utils/withDedupe.d.ts +10 -0
- package/dist/types/utils/withDedupe.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/actions/getChains.ts +2 -2
- package/src/actions/getRelayedTransactionStatus.ts +1 -1
- package/src/actions/getStepTransaction.ts +20 -12
- package/src/actions/index.ts +18 -0
- package/src/actions/patchContractCalls.ts +30 -0
- package/src/client/createClient.ts +5 -1
- package/src/client/getClientStorage.ts +25 -7
- package/src/core/BaseStepExecutionTask.ts +9 -0
- package/src/core/BaseStepExecutor.ts +91 -2
- package/src/core/StatusManager.ts +108 -113
- package/src/core/TaskPipeline.ts +28 -0
- package/src/core/{processMessages.ts → actionMessages.ts} +32 -12
- package/src/core/execution.ts +17 -3
- package/src/core/prepareRestart.ts +12 -11
- package/src/core/storage.ts +42 -0
- package/src/core/tasks/CheckBalanceTask.ts +29 -0
- package/src/core/tasks/PrepareTransactionTask.ts +62 -0
- package/src/core/tasks/WaitForTransactionStatusTask.ts +114 -0
- package/src/core/{checkBalance.ts → tasks/helpers/checkBalance.ts} +5 -5
- package/src/core/tasks/helpers/getTransactionRequestData.ts +47 -0
- package/src/core/{stepComparison.ts → tasks/helpers/stepComparison.ts} +5 -5
- package/src/core/{waitForTransactionStatus.ts → tasks/helpers/waitForTransactionStatus.ts} +11 -9
- package/src/core/utils.ts +1 -13
- package/src/errors/SDKError.ts +5 -5
- package/src/errors/constants.ts +3 -0
- package/src/errors/errors.ts +24 -0
- package/src/index.ts +37 -12
- package/src/types/core.ts +69 -29
- package/src/types/execution.ts +32 -0
- package/src/utils/convertQuoteToRoute.ts +117 -8
- package/src/utils/formatUnits.ts +22 -0
- package/src/utils/isHex.ts +14 -0
- package/src/utils/parseUnits.ts +50 -0
- package/src/utils/request.ts +9 -6
- package/src/utils/waitForResult.ts +9 -4
- package/src/utils/withDedupe.ts +1 -1
- package/src/version.ts +1 -1
- package/dist/cjs/core/checkBalance.js.map +0 -1
- package/dist/cjs/core/processMessages.d.ts +0 -4
- package/dist/cjs/core/processMessages.js.map +0 -1
- package/dist/cjs/core/stepComparison.js.map +0 -1
- package/dist/cjs/core/waitForDestinationChainTransaction.d.ts +0 -4
- package/dist/cjs/core/waitForDestinationChainTransaction.js +0 -69
- package/dist/cjs/core/waitForDestinationChainTransaction.js.map +0 -1
- package/dist/cjs/core/waitForTransactionStatus.d.ts +0 -4
- package/dist/cjs/core/waitForTransactionStatus.js.map +0 -1
- package/dist/esm/core/checkBalance.js.map +0 -1
- package/dist/esm/core/processMessages.d.ts +0 -4
- package/dist/esm/core/processMessages.js.map +0 -1
- package/dist/esm/core/stepComparison.js.map +0 -1
- package/dist/esm/core/waitForDestinationChainTransaction.d.ts +0 -4
- package/dist/esm/core/waitForDestinationChainTransaction.js +0 -71
- package/dist/esm/core/waitForDestinationChainTransaction.js.map +0 -1
- package/dist/esm/core/waitForTransactionStatus.d.ts +0 -4
- package/dist/esm/core/waitForTransactionStatus.js.map +0 -1
- package/dist/types/core/checkBalance.d.ts.map +0 -1
- package/dist/types/core/processMessages.d.ts +0 -5
- package/dist/types/core/processMessages.d.ts.map +0 -1
- package/dist/types/core/stepComparison.d.ts.map +0 -1
- package/dist/types/core/waitForDestinationChainTransaction.d.ts +0 -5
- package/dist/types/core/waitForDestinationChainTransaction.d.ts.map +0 -1
- package/dist/types/core/waitForTransactionStatus.d.ts +0 -5
- package/dist/types/core/waitForTransactionStatus.d.ts.map +0 -1
- package/src/core/waitForDestinationChainTransaction.ts +0 -106
package/src/index.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// biome-ignore lint/performance/noBarrelFile: module entrypoint
|
|
2
2
|
// biome-ignore lint/performance/noReExportAll: types
|
|
3
3
|
export * from '@lifi/types'
|
|
4
|
-
export
|
|
5
|
-
export { formatUnits, isHex, parseUnits } from 'viem/utils'
|
|
6
|
-
export { getChains, getChainsFromConfig } from './actions/getChains.js'
|
|
4
|
+
export { getChains } from './actions/getChains.js'
|
|
7
5
|
export { getConnections } from './actions/getConnections.js'
|
|
8
6
|
export { getContractCallsQuote } from './actions/getContractCallsQuote.js'
|
|
9
7
|
export { getGasRecommendation } from './actions/getGasRecommendation.js'
|
|
@@ -23,10 +21,12 @@ export { getTools } from './actions/getTools.js'
|
|
|
23
21
|
export { getTransactionHistory } from './actions/getTransactionHistory.js'
|
|
24
22
|
export { getWalletBalances } from './actions/getWalletBalances.js'
|
|
25
23
|
export { actions } from './actions/index.js'
|
|
24
|
+
export { patchContractCalls } from './actions/patchContractCalls.js'
|
|
26
25
|
export { relayTransaction } from './actions/relayTransaction.js'
|
|
27
26
|
export { createClient } from './client/createClient.js'
|
|
27
|
+
export { getActionMessage, getSubstatusMessage } from './core/actionMessages.js'
|
|
28
|
+
export { BaseStepExecutionTask } from './core/BaseStepExecutionTask.js'
|
|
28
29
|
export { BaseStepExecutor } from './core/BaseStepExecutor.js'
|
|
29
|
-
export { checkBalance } from './core/checkBalance.js'
|
|
30
30
|
export {
|
|
31
31
|
executeRoute,
|
|
32
32
|
getActiveRoute,
|
|
@@ -36,14 +36,25 @@ export {
|
|
|
36
36
|
updateRouteExecution,
|
|
37
37
|
} from './core/execution.js'
|
|
38
38
|
export { StatusManager } from './core/StatusManager.js'
|
|
39
|
-
export {
|
|
40
|
-
export {
|
|
41
|
-
|
|
39
|
+
export type { SDKStorage } from './core/storage.js'
|
|
40
|
+
export {
|
|
41
|
+
createDefaultStorage,
|
|
42
|
+
InMemoryStorage,
|
|
43
|
+
LocalStorageAdapter,
|
|
44
|
+
} from './core/storage.js'
|
|
45
|
+
export { TaskPipeline } from './core/TaskPipeline.js'
|
|
46
|
+
export { CheckBalanceTask } from './core/tasks/CheckBalanceTask.js'
|
|
47
|
+
export { checkBalance } from './core/tasks/helpers/checkBalance.js'
|
|
48
|
+
export { getTransactionRequestData } from './core/tasks/helpers/getTransactionRequestData.js'
|
|
49
|
+
export { stepComparison } from './core/tasks/helpers/stepComparison.js'
|
|
50
|
+
export { PrepareTransactionTask } from './core/tasks/PrepareTransactionTask.js'
|
|
51
|
+
export { WaitForTransactionStatusTask } from './core/tasks/WaitForTransactionStatusTask.js'
|
|
42
52
|
export { BaseError } from './errors/baseError.js'
|
|
43
53
|
export type { ErrorCode } from './errors/constants.js'
|
|
44
54
|
export { ErrorMessage, ErrorName, LiFiErrorCode } from './errors/constants.js'
|
|
45
55
|
export {
|
|
46
56
|
BalanceError,
|
|
57
|
+
ExecuteStepRetryError,
|
|
47
58
|
ProviderError,
|
|
48
59
|
RPCError,
|
|
49
60
|
ServerError,
|
|
@@ -57,15 +68,21 @@ export type {
|
|
|
57
68
|
AcceptExchangeRateUpdateHook,
|
|
58
69
|
AcceptSlippageUpdateHook,
|
|
59
70
|
AcceptSlippageUpdateHookParams,
|
|
71
|
+
ContractCallParams,
|
|
72
|
+
ContractTool,
|
|
60
73
|
ExchangeRateUpdateParams,
|
|
74
|
+
ExecuteStepRetryParams,
|
|
61
75
|
Execution,
|
|
76
|
+
ExecutionAction,
|
|
77
|
+
ExecutionActionStatus,
|
|
78
|
+
ExecutionActionType,
|
|
62
79
|
ExecutionOptions,
|
|
63
80
|
ExecutionStatus,
|
|
81
|
+
GetContractCallsHook,
|
|
82
|
+
GetContractCallsResult,
|
|
64
83
|
InteractionSettings,
|
|
65
84
|
LiFiStepExtended,
|
|
66
|
-
|
|
67
|
-
ProcessStatus,
|
|
68
|
-
ProcessType,
|
|
85
|
+
RequestInterceptor,
|
|
69
86
|
RouteExecutionData,
|
|
70
87
|
RouteExecutionDataDictionary,
|
|
71
88
|
RouteExecutionDictionary,
|
|
@@ -78,16 +95,24 @@ export type {
|
|
|
78
95
|
StepExecutor,
|
|
79
96
|
StepExecutorOptions,
|
|
80
97
|
StepExtended,
|
|
81
|
-
SwitchChainHook,
|
|
82
98
|
TransactionMethodType,
|
|
83
99
|
TransactionParameters,
|
|
84
100
|
TransactionRequestParameters,
|
|
85
101
|
TransactionRequestUpdateHook,
|
|
86
102
|
UpdateRouteHook,
|
|
87
103
|
} from './types/core.js'
|
|
104
|
+
export type {
|
|
105
|
+
StepExecutorBaseContext,
|
|
106
|
+
StepExecutorContext,
|
|
107
|
+
TaskResult,
|
|
108
|
+
TaskStatus,
|
|
109
|
+
} from './types/execution.js'
|
|
88
110
|
export { checkPackageUpdates } from './utils/checkPackageUpdates.js'
|
|
89
111
|
export { convertQuoteToRoute } from './utils/convertQuoteToRoute.js'
|
|
90
112
|
export { fetchTxErrorDetails } from './utils/fetchTxErrorDetails.js'
|
|
113
|
+
export { formatUnits } from './utils/formatUnits.js'
|
|
114
|
+
export { isHex } from './utils/isHex.js'
|
|
115
|
+
export { parseUnits } from './utils/parseUnits.js'
|
|
91
116
|
export { sleep } from './utils/sleep.js'
|
|
92
117
|
export { waitForResult } from './utils/waitForResult.js'
|
|
93
|
-
export { withDedupe } from './utils/withDedupe.js'
|
|
118
|
+
export { LruMap, withDedupe } from './utils/withDedupe.js'
|
package/src/types/core.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
ChainId,
|
|
3
3
|
ChainType,
|
|
4
4
|
CoinKey,
|
|
5
|
+
ContractCall,
|
|
5
6
|
ExtendedChain,
|
|
6
7
|
FeeCost,
|
|
7
8
|
GasCost,
|
|
@@ -13,7 +14,12 @@ import type {
|
|
|
13
14
|
Token,
|
|
14
15
|
TokenAmount,
|
|
15
16
|
} from '@lifi/types'
|
|
16
|
-
import type {
|
|
17
|
+
import type { SDKStorage } from '../core/storage.js'
|
|
18
|
+
import type { ExtendedRequestInit } from './request.js'
|
|
19
|
+
|
|
20
|
+
export type RequestInterceptor = (
|
|
21
|
+
request: ExtendedRequestInit
|
|
22
|
+
) => ExtendedRequestInit | Promise<ExtendedRequestInit>
|
|
17
23
|
|
|
18
24
|
export interface SDKBaseConfig {
|
|
19
25
|
apiKey?: string
|
|
@@ -26,6 +32,10 @@ export interface SDKBaseConfig {
|
|
|
26
32
|
disableVersionCheck?: boolean
|
|
27
33
|
widgetVersion?: string
|
|
28
34
|
debug: boolean
|
|
35
|
+
preloadChains?: boolean
|
|
36
|
+
chainsRefetchInterval?: number
|
|
37
|
+
requestInterceptor?: RequestInterceptor
|
|
38
|
+
storage?: SDKStorage
|
|
29
39
|
}
|
|
30
40
|
|
|
31
41
|
export interface SDKConfig extends Partial<Omit<SDKBaseConfig, 'integrator'>> {
|
|
@@ -56,6 +66,7 @@ export interface SDKClient {
|
|
|
56
66
|
providers: SDKProvider[]
|
|
57
67
|
getProvider(type: ChainType): SDKProvider | undefined
|
|
58
68
|
setProviders(providers: SDKProvider[]): void
|
|
69
|
+
setChains(chains: ExtendedChain[]): void
|
|
59
70
|
getChains(): Promise<ExtendedChain[]>
|
|
60
71
|
getChainById(chainId: ChainId): Promise<ExtendedChain>
|
|
61
72
|
getRpcUrls(): Promise<RPCUrls>
|
|
@@ -73,13 +84,20 @@ export interface InteractionSettings {
|
|
|
73
84
|
allowExecution?: boolean
|
|
74
85
|
}
|
|
75
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Params passed when retrying executeStep after an ExecuteStepRetryError.
|
|
89
|
+
* Providers can use this to pass strategy-specific retry options (e.g. atomicityNotReady for Ethereum 7702).
|
|
90
|
+
*/
|
|
91
|
+
export type ExecuteStepRetryParams = Record<string, unknown>
|
|
92
|
+
|
|
76
93
|
export interface StepExecutor {
|
|
77
94
|
allowUserInteraction: boolean
|
|
78
95
|
allowExecution: boolean
|
|
79
96
|
setInteraction(settings?: InteractionSettings): void
|
|
80
97
|
executeStep(
|
|
81
98
|
client: SDKClient,
|
|
82
|
-
step: LiFiStepExtended
|
|
99
|
+
step: LiFiStepExtended,
|
|
100
|
+
retryParams?: ExecuteStepRetryParams
|
|
83
101
|
): Promise<LiFiStepExtended>
|
|
84
102
|
}
|
|
85
103
|
|
|
@@ -130,8 +148,6 @@ export type TransactionRequestUpdateHook = (
|
|
|
130
148
|
updatedTxRequest: TransactionRequestParameters
|
|
131
149
|
) => Promise<TransactionParameters>
|
|
132
150
|
|
|
133
|
-
export type SwitchChainHook = (chainId: number) => Promise<Client | undefined>
|
|
134
|
-
|
|
135
151
|
export interface AcceptSlippageUpdateHookParams {
|
|
136
152
|
toToken: Token
|
|
137
153
|
oldToAmount: string
|
|
@@ -154,13 +170,40 @@ export type AcceptExchangeRateUpdateHook = (
|
|
|
154
170
|
params: ExchangeRateUpdateParams
|
|
155
171
|
) => Promise<boolean | undefined>
|
|
156
172
|
|
|
173
|
+
export interface ContractCallParams {
|
|
174
|
+
fromChainId: number
|
|
175
|
+
toChainId: number
|
|
176
|
+
fromTokenAddress: string
|
|
177
|
+
toTokenAddress: string
|
|
178
|
+
fromAddress: string
|
|
179
|
+
toAddress?: string
|
|
180
|
+
fromAmount: bigint
|
|
181
|
+
toAmount: bigint
|
|
182
|
+
slippage?: number
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface ContractTool {
|
|
186
|
+
name: string
|
|
187
|
+
logoURI: string
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface GetContractCallsResult {
|
|
191
|
+
contractCalls: ContractCall[]
|
|
192
|
+
patcher?: boolean
|
|
193
|
+
contractTool?: ContractTool
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export type GetContractCallsHook = (
|
|
197
|
+
params: ContractCallParams
|
|
198
|
+
) => Promise<GetContractCallsResult>
|
|
199
|
+
|
|
157
200
|
export interface ExecutionOptions {
|
|
158
201
|
acceptExchangeRateUpdateHook?: AcceptExchangeRateUpdateHook
|
|
159
|
-
switchChainHook?: SwitchChainHook
|
|
160
202
|
updateRouteHook?: UpdateRouteHook
|
|
161
203
|
updateTransactionRequestHook?: TransactionRequestUpdateHook
|
|
204
|
+
getContractCalls?: GetContractCallsHook
|
|
205
|
+
adjustZeroOutputFromPreviousStep?: boolean
|
|
162
206
|
executeInBackground?: boolean
|
|
163
|
-
disableMessageSigning?: boolean
|
|
164
207
|
/**
|
|
165
208
|
* @deprecated
|
|
166
209
|
*/
|
|
@@ -169,7 +212,7 @@ export interface ExecutionOptions {
|
|
|
169
212
|
|
|
170
213
|
export type ExecutionStatus = 'ACTION_REQUIRED' | 'PENDING' | 'FAILED' | 'DONE'
|
|
171
214
|
|
|
172
|
-
export type
|
|
215
|
+
export type ExecutionActionStatus =
|
|
173
216
|
| 'STARTED'
|
|
174
217
|
| 'ACTION_REQUIRED'
|
|
175
218
|
| 'MESSAGE_REQUIRED'
|
|
@@ -179,43 +222,38 @@ export type ProcessStatus =
|
|
|
179
222
|
| 'DONE'
|
|
180
223
|
| 'CANCELLED'
|
|
181
224
|
|
|
182
|
-
export type
|
|
183
|
-
| 'TOKEN_ALLOWANCE'
|
|
225
|
+
export type ExecutionActionType =
|
|
184
226
|
| 'PERMIT'
|
|
227
|
+
| 'CHECK_ALLOWANCE'
|
|
228
|
+
| 'NATIVE_PERMIT'
|
|
229
|
+
| 'RESET_ALLOWANCE'
|
|
230
|
+
| 'SET_ALLOWANCE'
|
|
185
231
|
| 'SWAP'
|
|
186
232
|
| 'CROSS_CHAIN'
|
|
187
233
|
| 'RECEIVING_CHAIN'
|
|
188
234
|
|
|
189
|
-
export type
|
|
190
|
-
type:
|
|
191
|
-
status:
|
|
235
|
+
export type ExecutionAction = {
|
|
236
|
+
type: ExecutionActionType
|
|
237
|
+
status: ExecutionActionStatus
|
|
238
|
+
message?: string
|
|
192
239
|
substatus?: Substatus
|
|
240
|
+
substatusMessage?: string
|
|
193
241
|
chainId?: number
|
|
194
242
|
txHash?: string
|
|
195
|
-
taskId?: string
|
|
196
243
|
txLink?: string
|
|
244
|
+
taskId?: string
|
|
197
245
|
txType?: TransactionMethodType
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
pendingAt?: number
|
|
202
|
-
startedAt: number
|
|
203
|
-
message?: string
|
|
204
|
-
error?: {
|
|
205
|
-
code: string | number
|
|
206
|
-
message: string
|
|
207
|
-
htmlMessage?: string
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// additional information
|
|
211
|
-
[key: string]: any
|
|
246
|
+
txHex?: string
|
|
247
|
+
// Errors occured during the action execution (within tasks)
|
|
248
|
+
error?: { code: string | number; message: string; htmlMessage?: string }
|
|
212
249
|
}
|
|
213
250
|
|
|
214
251
|
export interface Execution {
|
|
215
252
|
startedAt: number
|
|
216
|
-
|
|
253
|
+
signedAt?: number
|
|
217
254
|
status: ExecutionStatus
|
|
218
|
-
|
|
255
|
+
actions: Array<ExecutionAction>
|
|
256
|
+
lastActionType?: ExecutionActionType
|
|
219
257
|
fromAmount?: string
|
|
220
258
|
toAmount?: string
|
|
221
259
|
toToken?: Token
|
|
@@ -223,6 +261,8 @@ export interface Execution {
|
|
|
223
261
|
gasCosts?: GasCost[]
|
|
224
262
|
internalTxLink?: string
|
|
225
263
|
externalTxLink?: string
|
|
264
|
+
// Errors occured outside of actions (e.g. during context creation)
|
|
265
|
+
error?: { code: string | number; message: string; htmlMessage?: string }
|
|
226
266
|
}
|
|
227
267
|
|
|
228
268
|
export type TransactionMethodType = 'standard' | 'relayed' | 'batched'
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ExtendedChain } from '@lifi/types'
|
|
2
|
+
import type { StatusManager } from '../core/StatusManager.js'
|
|
3
|
+
import type {
|
|
4
|
+
ExecuteStepRetryParams,
|
|
5
|
+
ExecutionOptions,
|
|
6
|
+
LiFiStepExtended,
|
|
7
|
+
SDKClient,
|
|
8
|
+
} from './core.js'
|
|
9
|
+
|
|
10
|
+
export interface StepExecutorBaseContext {
|
|
11
|
+
statusManager: StatusManager
|
|
12
|
+
executionOptions?: ExecutionOptions
|
|
13
|
+
fromChain: ExtendedChain
|
|
14
|
+
toChain: ExtendedChain
|
|
15
|
+
isBridgeExecution: boolean
|
|
16
|
+
client: SDKClient
|
|
17
|
+
step: LiFiStepExtended
|
|
18
|
+
allowUserInteraction: boolean
|
|
19
|
+
retryParams?: ExecuteStepRetryParams
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface StepExecutorContext extends StepExecutorBaseContext {
|
|
23
|
+
pollingIntervalMs?: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface TaskResult<TContext = Record<string, unknown>> {
|
|
27
|
+
status: TaskStatus
|
|
28
|
+
/** Optional: data produced for downstream tasks. Pipeline merges into the executor context. */
|
|
29
|
+
context?: TContext
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type TaskStatus = 'COMPLETED' | 'PAUSED'
|
|
@@ -1,23 +1,132 @@
|
|
|
1
|
-
import type { LiFiStep, Route } from '@lifi/types'
|
|
1
|
+
import type { LiFiStep, Route, Step } from '@lifi/types'
|
|
2
2
|
import { ValidationError } from '../errors/errors.js'
|
|
3
3
|
import { SDKError } from '../errors/SDKError.js'
|
|
4
|
+
import { formatUnits } from './formatUnits.js'
|
|
5
|
+
|
|
6
|
+
interface ConvertQuoteToRouteOptions {
|
|
7
|
+
/**
|
|
8
|
+
* When true, if the quote has zero output values (toAmount, toAmountMin, toAmountUSD),
|
|
9
|
+
* use the values from the previous included step that has non-zero output.
|
|
10
|
+
*/
|
|
11
|
+
adjustZeroOutputFromPreviousStep?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const parseBigInt = (value: string | undefined): bigint => {
|
|
15
|
+
if (!value) {
|
|
16
|
+
return 0n
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
return BigInt(value)
|
|
20
|
+
} catch {
|
|
21
|
+
return 0n
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const parseNumber = (value: string | undefined): number => {
|
|
26
|
+
if (!value) {
|
|
27
|
+
return 0
|
|
28
|
+
}
|
|
29
|
+
const parsed = Number(value)
|
|
30
|
+
return Number.isNaN(parsed) ? 0 : parsed
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const isZeroOutput = (
|
|
34
|
+
toAmount: string,
|
|
35
|
+
toAmountMin: string,
|
|
36
|
+
toAmountUSD?: string
|
|
37
|
+
): boolean => {
|
|
38
|
+
return (
|
|
39
|
+
!parseBigInt(toAmount) &&
|
|
40
|
+
!parseBigInt(toAmountMin) &&
|
|
41
|
+
!parseNumber(toAmountUSD)
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const hasNonZeroOutput = (step: Step): boolean => {
|
|
46
|
+
return (
|
|
47
|
+
!!parseBigInt(step.estimate.toAmount) ||
|
|
48
|
+
!!parseBigInt(step.estimate.toAmountMin)
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const findPreviousNonZeroStep = (steps: Step[]): Step | undefined => {
|
|
53
|
+
// Find the last step that has non-zero output (the step before the zero output step)
|
|
54
|
+
for (let i = steps.length - 1; i >= 0; i--) {
|
|
55
|
+
const step = steps[i]
|
|
56
|
+
if (hasNonZeroOutput(step)) {
|
|
57
|
+
return step
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return undefined
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function formatTokenPrice(
|
|
64
|
+
amount?: string | bigint,
|
|
65
|
+
price?: string,
|
|
66
|
+
decimals?: number
|
|
67
|
+
) {
|
|
68
|
+
if (!amount || !price) {
|
|
69
|
+
return 0
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const formattedAmount =
|
|
73
|
+
typeof amount === 'bigint' && decimals !== undefined
|
|
74
|
+
? formatUnits(amount, decimals)
|
|
75
|
+
: amount.toString()
|
|
76
|
+
|
|
77
|
+
if (Number.isNaN(Number(formattedAmount)) || Number.isNaN(Number(price))) {
|
|
78
|
+
return 0
|
|
79
|
+
}
|
|
80
|
+
return Number.parseFloat(formattedAmount) * Number.parseFloat(price)
|
|
81
|
+
}
|
|
4
82
|
|
|
5
83
|
/**
|
|
6
84
|
* Converts a quote to Route
|
|
7
85
|
* @param quote - Step returned from the quote endpoint.
|
|
8
|
-
* @param
|
|
9
|
-
* @param chainId
|
|
86
|
+
* @param options - Optional configuration for handling edge cases.
|
|
10
87
|
* @returns - The route to be executed.
|
|
11
88
|
* @throws {BaseError} Throws a ValidationError if the step has missing values.
|
|
12
89
|
*/
|
|
13
|
-
export const convertQuoteToRoute = (
|
|
90
|
+
export const convertQuoteToRoute = (
|
|
91
|
+
quote: LiFiStep,
|
|
92
|
+
options?: ConvertQuoteToRouteOptions
|
|
93
|
+
): Route => {
|
|
94
|
+
let toAmount = quote.estimate.toAmount
|
|
95
|
+
let toAmountMin = quote.estimate.toAmountMin
|
|
96
|
+
let toAmountUSD = quote.estimate.toAmountUSD
|
|
97
|
+
|
|
98
|
+
// Handle zero output values by looking at previous included step
|
|
99
|
+
if (
|
|
100
|
+
options?.adjustZeroOutputFromPreviousStep &&
|
|
101
|
+
quote.includedSteps?.length &&
|
|
102
|
+
isZeroOutput(toAmount, toAmountMin, toAmountUSD)
|
|
103
|
+
) {
|
|
104
|
+
const previousStep = findPreviousNonZeroStep(quote.includedSteps)
|
|
105
|
+
if (previousStep) {
|
|
106
|
+
toAmount = previousStep.estimate.toAmount
|
|
107
|
+
toAmountMin = previousStep.estimate.toAmountMin
|
|
108
|
+
toAmountUSD = formatTokenPrice(
|
|
109
|
+
parseBigInt(toAmount),
|
|
110
|
+
previousStep.action.toToken.priceUSD,
|
|
111
|
+
previousStep.action.toToken.decimals
|
|
112
|
+
).toFixed(2)
|
|
113
|
+
|
|
114
|
+
// Update the last included step's estimate with the adjusted values
|
|
115
|
+
const lastStep = quote.includedSteps[quote.includedSteps.length - 1]
|
|
116
|
+
if (lastStep && !hasNonZeroOutput(lastStep)) {
|
|
117
|
+
lastStep.estimate.toAmount = toAmount
|
|
118
|
+
lastStep.estimate.toAmountMin = toAmountMin
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
14
123
|
if (!quote.estimate.fromAmountUSD) {
|
|
15
124
|
throw new SDKError(
|
|
16
125
|
new ValidationError("Missing 'fromAmountUSD' in step estimate.")
|
|
17
126
|
)
|
|
18
127
|
}
|
|
19
128
|
|
|
20
|
-
if (!
|
|
129
|
+
if (!toAmountUSD) {
|
|
21
130
|
throw new SDKError(
|
|
22
131
|
new ValidationError("Missing 'toAmountUSD' in step estimate.")
|
|
23
132
|
)
|
|
@@ -32,9 +141,9 @@ export const convertQuoteToRoute = (quote: LiFiStep): Route => {
|
|
|
32
141
|
fromAddress: quote.action.fromAddress,
|
|
33
142
|
toChainId: quote.action.toToken.chainId,
|
|
34
143
|
toToken: quote.action.toToken,
|
|
35
|
-
toAmount
|
|
36
|
-
toAmountMin
|
|
37
|
-
toAmountUSD
|
|
144
|
+
toAmount,
|
|
145
|
+
toAmountMin,
|
|
146
|
+
toAmountUSD,
|
|
38
147
|
toAddress: quote.action.toAddress || quote.action.fromAddress,
|
|
39
148
|
gasCostUSD: quote.estimate.gasCosts?.[0]?.amountUSD || '0',
|
|
40
149
|
steps: [quote],
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Divides a number by a given exponent of base 10 (10exponent), and formats it into a string representation of the number.
|
|
3
|
+
*/
|
|
4
|
+
export function formatUnits(value: bigint, decimals: number) {
|
|
5
|
+
let display = value.toString()
|
|
6
|
+
|
|
7
|
+
const negative = display.startsWith('-')
|
|
8
|
+
if (negative) {
|
|
9
|
+
display = display.slice(1)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
display = display.padStart(decimals, '0')
|
|
13
|
+
|
|
14
|
+
let [integer, fraction] = [
|
|
15
|
+
display.slice(0, display.length - decimals),
|
|
16
|
+
display.slice(display.length - decimals),
|
|
17
|
+
]
|
|
18
|
+
fraction = fraction.replace(/(0+)$/, '')
|
|
19
|
+
return `${negative ? '-' : ''}${integer || '0'}${
|
|
20
|
+
fraction ? `.${fraction}` : ''
|
|
21
|
+
}`
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type Hex = `0x${string}`
|
|
2
|
+
|
|
3
|
+
export function isHex(
|
|
4
|
+
value: unknown,
|
|
5
|
+
{ strict = true }: { strict?: boolean | undefined } = {}
|
|
6
|
+
): value is Hex {
|
|
7
|
+
if (!value) {
|
|
8
|
+
return false
|
|
9
|
+
}
|
|
10
|
+
if (typeof value !== 'string') {
|
|
11
|
+
return false
|
|
12
|
+
}
|
|
13
|
+
return strict ? /^0x[0-9a-fA-F]*$/.test(value) : value.startsWith('0x')
|
|
14
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multiplies a string representation of a number by a given exponent of base 10 (10exponent).
|
|
3
|
+
*/
|
|
4
|
+
export function parseUnits(value: string, decimals: number) {
|
|
5
|
+
if (!/^(-?)([0-9]*)\.?([0-9]*)$/.test(value)) {
|
|
6
|
+
throw new Error(`Number \`${value}\` is not a valid decimal number.`)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let [integer, fraction = '0'] = value.split('.')
|
|
10
|
+
|
|
11
|
+
const negative = integer.startsWith('-')
|
|
12
|
+
if (negative) {
|
|
13
|
+
integer = integer.slice(1)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// trim trailing zeros.
|
|
17
|
+
fraction = fraction.replace(/(0+)$/, '')
|
|
18
|
+
|
|
19
|
+
// round off if the fraction is larger than the number of decimals.
|
|
20
|
+
if (decimals === 0) {
|
|
21
|
+
if (Math.round(Number(`.${fraction}`)) === 1) {
|
|
22
|
+
integer = `${BigInt(integer) + 1n}`
|
|
23
|
+
}
|
|
24
|
+
fraction = ''
|
|
25
|
+
} else if (fraction.length > decimals) {
|
|
26
|
+
const [left, unit, right] = [
|
|
27
|
+
fraction.slice(0, decimals - 1),
|
|
28
|
+
fraction.slice(decimals - 1, decimals),
|
|
29
|
+
fraction.slice(decimals),
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
const rounded = Math.round(Number(`${unit}.${right}`))
|
|
33
|
+
if (rounded > 9) {
|
|
34
|
+
fraction = `${BigInt(left) + BigInt(1)}0`.padStart(left.length + 1, '0')
|
|
35
|
+
} else {
|
|
36
|
+
fraction = `${left}${rounded}`
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (fraction.length > decimals) {
|
|
40
|
+
fraction = fraction.slice(1)
|
|
41
|
+
integer = `${BigInt(integer) + 1n}`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fraction = fraction.slice(0, decimals)
|
|
45
|
+
} else {
|
|
46
|
+
fraction = fraction.padEnd(decimals, '0')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return BigInt(`${negative ? '-' : ''}${integer}${fraction}`)
|
|
50
|
+
}
|
package/src/utils/request.ts
CHANGED
|
@@ -24,7 +24,8 @@ export const request = async <T = Response>(
|
|
|
24
24
|
retries: requestSettings.retries,
|
|
25
25
|
}
|
|
26
26
|
): Promise<T> => {
|
|
27
|
-
const { userId, integrator, widgetVersion, apiKey } =
|
|
27
|
+
const { userId, integrator, widgetVersion, apiKey, requestInterceptor } =
|
|
28
|
+
config
|
|
28
29
|
|
|
29
30
|
if (!integrator) {
|
|
30
31
|
throw new SDKError(
|
|
@@ -71,6 +72,10 @@ export const request = async <T = Response>(
|
|
|
71
72
|
'x-lifi-integrator': integrator,
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
if (requestInterceptor) {
|
|
76
|
+
options = await requestInterceptor(options)
|
|
77
|
+
}
|
|
78
|
+
|
|
74
79
|
const response: Response = await fetch(
|
|
75
80
|
url,
|
|
76
81
|
stripExtendRequestInitProperties(options)
|
|
@@ -82,12 +87,10 @@ export const request = async <T = Response>(
|
|
|
82
87
|
|
|
83
88
|
return await response.json()
|
|
84
89
|
} catch (error) {
|
|
85
|
-
|
|
90
|
+
const retries = options.retries ?? 0
|
|
91
|
+
if (retries > 0 && (error as HTTPError).status === 500) {
|
|
86
92
|
await sleep(500)
|
|
87
|
-
return request<T>(config, url, {
|
|
88
|
-
...options,
|
|
89
|
-
retries: options.retries - 1,
|
|
90
|
-
})
|
|
93
|
+
return request<T>(config, url, { ...options, retries: retries - 1 })
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
await (error as HTTPError).buildAdditionalDetails?.()
|
|
@@ -3,7 +3,7 @@ import { sleep } from './sleep.js'
|
|
|
3
3
|
/**
|
|
4
4
|
* Repeatedly calls a given asynchronous function until it resolves with a value
|
|
5
5
|
* @param fn The function that should be repeated
|
|
6
|
-
* @param interval The timeout in milliseconds between retries,
|
|
6
|
+
* @param interval The timeout in milliseconds between retries, or a function that receives the current poll count and returns the interval. Defaults to 5000
|
|
7
7
|
* @param maxRetries Maximum number of retries before throwing an error, defaults to 3
|
|
8
8
|
* @param shouldRetry Optional predicate to determine if an error should trigger a retry
|
|
9
9
|
* @returns The result of the fn function
|
|
@@ -11,18 +11,22 @@ import { sleep } from './sleep.js'
|
|
|
11
11
|
*/
|
|
12
12
|
export const waitForResult = async <T>(
|
|
13
13
|
fn: () => Promise<T | undefined>,
|
|
14
|
-
interval = 5000,
|
|
14
|
+
interval: number | ((poll: number) => number) = 5000,
|
|
15
15
|
maxRetries = 3,
|
|
16
16
|
shouldRetry: (count: number, error: unknown) => boolean = () => true
|
|
17
17
|
): Promise<T> => {
|
|
18
18
|
let result: T | undefined
|
|
19
19
|
let attempts = 0
|
|
20
|
+
let polls = 0
|
|
21
|
+
|
|
22
|
+
const getInterval = typeof interval === 'function' ? interval : () => interval
|
|
20
23
|
|
|
21
24
|
while (!result) {
|
|
22
25
|
try {
|
|
23
26
|
result = await fn()
|
|
24
27
|
if (!result) {
|
|
25
|
-
await sleep(
|
|
28
|
+
await sleep(getInterval(polls))
|
|
29
|
+
polls++
|
|
26
30
|
}
|
|
27
31
|
} catch (error) {
|
|
28
32
|
if (!shouldRetry(attempts, error)) {
|
|
@@ -32,7 +36,8 @@ export const waitForResult = async <T>(
|
|
|
32
36
|
if (attempts === maxRetries) {
|
|
33
37
|
throw error
|
|
34
38
|
}
|
|
35
|
-
await sleep(
|
|
39
|
+
await sleep(getInterval(polls))
|
|
40
|
+
polls++
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
43
|
|
package/src/utils/withDedupe.ts
CHANGED
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk'
|
|
2
|
-
export const version = '4.0.0-alpha.
|
|
2
|
+
export const version = '4.0.0-alpha.21'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkBalance.js","sourceRoot":"","sources":["../../../src/core/checkBalance.ts"],"names":[],"mappings":";;;AACA,+BAAkC;AAClC,sEAA+D;AAC/D,mDAAkD;AAElD,gDAAyC;AAElC,MAAM,YAAY,GAAG,KAAK,EAC/B,MAAiB,EACjB,aAAqB,EACrB,IAAc,EACd,KAAK,GAAG,CAAC,EACM,EAAE;IACjB,MAAM,KAAK,GAAG,MAAM,IAAA,oCAAe,EACjC,MAAM,EACN,aAAa,EACb,IAAI,CAAC,MAAM,CAAC,SAAS,CACtB,CAAA;IACD,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,IAAI,EAAE,CAAA;QACzC,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;QAEpD,IAAI,cAAc,GAAG,aAAa,EAAE,CAAC;YACnC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;gBACf,MAAM,IAAA,gBAAK,EAAC,GAAG,CAAC,CAAA;gBAChB,MAAM,IAAA,oBAAY,EAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,CAAA;YAC5D,CAAC;iBAAM,IACL,CAAC,aAAa;gBACZ,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC;gBAC1D,WAAc;gBAChB,cAAc,EACd,CAAC;gBAED,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,cAAc,CAAC,QAAQ,EAAE,CAAA;YACpD,CAAC;iBAAM,CAAC;gBACN,MAAM,MAAM,GAAG,IAAA,kBAAW,EAAC,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;gBACzD,MAAM,OAAO,GAAG,IAAA,kBAAW,EAAC,cAAc,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;gBAC3D,IAAI,YAAY,GAAG,QAAQ,KAAK,CAAC,MAAM,4CAA4C,MAAM,IAAI,KAAK,CAAC,MAAM,gCAAgC,OAAO,IAAI,KAAK,CAAC,MAAM,4BAA4B,CAAA;gBAE5L,IAAI,cAAc,KAAK,EAAE,EAAE,CAAC;oBAC1B,YAAY,IAAI,8FAA8F,OAAO,IAAI,KAAK,CAAC,MAAM,GAAG,CAAA;gBAC1I,CAAC;gBAED,MAAM,IAAI,wBAAY,CACpB,yBAAyB,EACzB,IAAI,KAAK,CAAC,YAAY,CAAC,CACxB,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAA;AA3CY,QAAA,YAAY,gBA2CxB"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { StatusMessage, Substatus } from '@lifi/types';
|
|
2
|
-
import type { ProcessStatus, ProcessType } from '../types/core.js';
|
|
3
|
-
export declare function getProcessMessage(type: ProcessType, status: ProcessStatus): string | undefined;
|
|
4
|
-
export declare function getSubstatusMessage(status: StatusMessage, substatus?: Substatus): string | undefined;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"processMessages.js","sourceRoot":"","sources":["../../../src/core/processMessages.ts"],"names":[],"mappings":";;AAiEA,8CAMC;AAED,kDASC;AA/ED,MAAM,eAAe,GAGjB;IACF,eAAe,EAAE;QACf,OAAO,EAAE,yBAAyB;QAClC,eAAe,EAAE,qBAAqB;QACtC,cAAc,EAAE,2BAA2B;QAC3C,gBAAgB,EAAE,8BAA8B;QAChD,OAAO,EAAE,6BAA6B;QACtC,IAAI,EAAE,qBAAqB;KAC5B;IACD,IAAI,EAAE;QACJ,OAAO,EAAE,4BAA4B;QACrC,eAAe,EAAE,uBAAuB;QACxC,gBAAgB,EAAE,mBAAmB;QACrC,OAAO,EAAE,8BAA8B;QACvC,IAAI,EAAE,gBAAgB;KACvB;IACD,WAAW,EAAE;QACX,OAAO,EAAE,8BAA8B;QACvC,eAAe,EAAE,yBAAyB;QAC1C,gBAAgB,EAAE,qBAAqB;QACvC,OAAO,EAAE,gCAAgC;QACzC,IAAI,EAAE,8BAA8B;KACrC;IACD,eAAe,EAAE;QACf,OAAO,EAAE,+BAA+B;QACxC,IAAI,EAAE,kBAAkB;KACzB;IACD,MAAM,EAAE;QACN,OAAO,EAAE,uBAAuB;QAChC,eAAe,EAAE,qBAAqB;QACtC,OAAO,EAAE,4BAA4B;QACrC,IAAI,EAAE,uBAAuB;KAC9B;CACF,CAAA;AACD,MAAM,iBAAiB,GAGnB;IACF,OAAO,EAAE;QACP,oBAAoB,EAAE,kDAAkD;QACxE,mBAAmB,EAAE,+CAA+C;QACpE,aAAa,EACX,mFAAmF;QACrF,yBAAyB,EACvB,kHAAkH;QACpH,4BAA4B,EAC1B,4GAA4G;KAC/G;IACD,IAAI,EAAE;QACJ,OAAO,EACL,uEAAuE;QACzE,QAAQ,EAAE,iDAAiD;QAC3D,SAAS,EAAE,2BAA2B;KACvC;IACD,MAAM,EAAE,EAAE;IACV,OAAO,EAAE,EAAE;IACX,SAAS,EAAE,EAAE;CACd,CAAA;AAED,SAAgB,iBAAiB,CAC/B,IAAiB,EACjB,MAAqB;IAErB,MAAM,cAAc,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAA;IACpD,OAAO,cAAc,CAAA;AACvB,CAAC;AAED,SAAgB,mBAAmB,CACjC,MAAqB,EACrB,SAAqB;IAErB,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAM;IACR,CAAC;IACD,MAAM,OAAO,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAA;IACpD,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stepComparison.js","sourceRoot":"","sources":["../../../src/core/stepComparison.ts"],"names":[],"mappings":";;;AACA,yDAAsD;AACtD,mDAAsD;AAGtD,yCAAuD;AAchD,MAAM,cAAc,GAAG,KAAK,EACjC,aAA4B,EAC5B,OAAiB,EACjB,OAAiB,EACjB,oBAA6B,EAC7B,gBAAmC,EAChB,EAAE;IAErB,IAAI,IAAA,qCAA0B,EAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;QACjD,OAAO,aAAa,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;IACjD,CAAC;IAED,IAAI,eAAoC,CAAA;IACxC,IAAI,oBAAoB,EAAE,CAAC;QACzB,eAAe,GAAG,MAAM,gBAAgB,EAAE,4BAA4B,EAAE,CAAC;YACvE,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,QAAQ;YACtC,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,QAAQ;YACtC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO;SAChC,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,CAAC,eAAe,EAAE,CAAC;QAErB,MAAM,IAAI,4BAAgB,CACxB,4BAAa,CAAC,0BAA0B,EACxC,+LAA+L,CAChM,CAAA;IACH,CAAC;IAED,OAAO,aAAa,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;AACjD,CAAC,CAAA;AA9BY,QAAA,cAAc,kBA8B1B"}
|