@lifi/sdk 4.0.0-alpha.9 → 4.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/dist/cjs/actions/getQuote.js +2 -1
  2. package/dist/cjs/actions/getQuote.js.map +1 -1
  3. package/dist/cjs/actions/getRelayedTransactionStatus.js +1 -1
  4. package/dist/cjs/actions/getRelayedTransactionStatus.js.map +1 -1
  5. package/dist/cjs/actions/getRelayerQuote.js +2 -1
  6. package/dist/cjs/actions/getRelayerQuote.js.map +1 -1
  7. package/dist/cjs/actions/getStepTransaction.js +18 -1
  8. package/dist/cjs/actions/getStepTransaction.js.map +1 -1
  9. package/dist/cjs/core/BaseStepExecutionTask.d.ts +5 -0
  10. package/dist/cjs/core/BaseStepExecutionTask.js +10 -0
  11. package/dist/cjs/core/BaseStepExecutionTask.js.map +1 -0
  12. package/dist/cjs/core/BaseStepExecutor.d.ts +10 -3
  13. package/dist/cjs/core/BaseStepExecutor.js +53 -0
  14. package/dist/cjs/core/BaseStepExecutor.js.map +1 -1
  15. package/dist/cjs/core/StatusManager.d.ts +12 -10
  16. package/dist/cjs/core/StatusManager.js +35 -33
  17. package/dist/cjs/core/StatusManager.js.map +1 -1
  18. package/dist/cjs/core/TaskPipeline.d.ts +7 -0
  19. package/dist/cjs/core/TaskPipeline.js +27 -0
  20. package/dist/cjs/core/TaskPipeline.js.map +1 -0
  21. package/dist/cjs/core/actionMessages.js +19 -3
  22. package/dist/cjs/core/actionMessages.js.map +1 -1
  23. package/dist/cjs/core/execution.js +13 -1
  24. package/dist/cjs/core/execution.js.map +1 -1
  25. package/dist/cjs/core/prepareRestart.js +3 -3
  26. package/dist/cjs/core/prepareRestart.js.map +1 -1
  27. package/dist/cjs/core/storage.d.ts +17 -0
  28. package/dist/cjs/core/storage.js +36 -0
  29. package/dist/cjs/core/storage.js.map +1 -0
  30. package/dist/cjs/core/tasks/CheckBalanceTask.d.ts +5 -0
  31. package/dist/cjs/core/tasks/CheckBalanceTask.js +26 -0
  32. package/dist/cjs/core/tasks/CheckBalanceTask.js.map +1 -0
  33. package/dist/cjs/core/tasks/PrepareTransactionTask.d.ts +5 -0
  34. package/dist/cjs/core/tasks/PrepareTransactionTask.js +36 -0
  35. package/dist/cjs/core/tasks/PrepareTransactionTask.js.map +1 -0
  36. package/dist/cjs/core/tasks/WaitForTransactionStatusTask.d.ts +8 -0
  37. package/dist/cjs/core/tasks/WaitForTransactionStatusTask.js +73 -0
  38. package/dist/cjs/core/tasks/WaitForTransactionStatusTask.js.map +1 -0
  39. package/dist/cjs/core/{checkBalance.d.ts → tasks/helpers/checkBalance.d.ts} +1 -1
  40. package/dist/cjs/core/{checkBalance.js → tasks/helpers/checkBalance.js} +4 -4
  41. package/dist/cjs/core/tasks/helpers/checkBalance.js.map +1 -0
  42. package/dist/cjs/core/tasks/helpers/getTransactionRequestData.d.ts +2 -0
  43. package/dist/cjs/core/tasks/helpers/getTransactionRequestData.js +30 -0
  44. package/dist/cjs/core/tasks/helpers/getTransactionRequestData.js.map +1 -0
  45. package/dist/cjs/core/{stepComparison.d.ts → tasks/helpers/stepComparison.d.ts} +2 -2
  46. package/dist/cjs/core/{stepComparison.js → tasks/helpers/stepComparison.js} +3 -3
  47. package/dist/cjs/core/tasks/helpers/stepComparison.js.map +1 -0
  48. package/dist/cjs/core/{waitForTransactionStatus.d.ts → tasks/helpers/waitForTransactionStatus.d.ts} +2 -2
  49. package/dist/cjs/core/{waitForTransactionStatus.js → tasks/helpers/waitForTransactionStatus.js} +7 -5
  50. package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.js.map +1 -0
  51. package/dist/cjs/core/utils.d.ts +6 -1
  52. package/dist/cjs/errors/constants.d.ts +2 -1
  53. package/dist/cjs/errors/constants.js +1 -0
  54. package/dist/cjs/errors/constants.js.map +1 -1
  55. package/dist/cjs/errors/errors.d.ts +5 -0
  56. package/dist/cjs/errors/errors.js +9 -1
  57. package/dist/cjs/errors/errors.js.map +1 -1
  58. package/dist/cjs/index.d.ts +15 -6
  59. package/dist/cjs/index.js +26 -7
  60. package/dist/cjs/index.js.map +1 -1
  61. package/dist/cjs/types/core.d.ts +15 -6
  62. package/dist/cjs/types/execution.d.ts +22 -0
  63. package/dist/cjs/types/execution.js +3 -0
  64. package/dist/cjs/types/execution.js.map +1 -0
  65. package/dist/cjs/utils/waitForResult.d.ts +1 -1
  66. package/dist/cjs/utils/waitForResult.js +6 -2
  67. package/dist/cjs/utils/waitForResult.js.map +1 -1
  68. package/dist/cjs/utils/withDedupe.d.ts +5 -0
  69. package/dist/cjs/utils/withDedupe.js +2 -0
  70. package/dist/cjs/utils/withDedupe.js.map +1 -1
  71. package/dist/cjs/version.d.ts +1 -1
  72. package/dist/cjs/version.js +1 -1
  73. package/dist/cjs/version.js.map +1 -1
  74. package/dist/esm/actions/getQuote.js +2 -1
  75. package/dist/esm/actions/getQuote.js.map +1 -1
  76. package/dist/esm/actions/getRelayedTransactionStatus.js +1 -1
  77. package/dist/esm/actions/getRelayedTransactionStatus.js.map +1 -1
  78. package/dist/esm/actions/getRelayerQuote.js +2 -1
  79. package/dist/esm/actions/getRelayerQuote.js.map +1 -1
  80. package/dist/esm/actions/getStepTransaction.js +18 -1
  81. package/dist/esm/actions/getStepTransaction.js.map +1 -1
  82. package/dist/esm/core/BaseStepExecutionTask.d.ts +5 -0
  83. package/dist/esm/core/BaseStepExecutionTask.js +6 -0
  84. package/dist/esm/core/BaseStepExecutionTask.js.map +1 -0
  85. package/dist/esm/core/BaseStepExecutor.d.ts +10 -3
  86. package/dist/esm/core/BaseStepExecutor.js +53 -0
  87. package/dist/esm/core/BaseStepExecutor.js.map +1 -1
  88. package/dist/esm/core/StatusManager.d.ts +29 -27
  89. package/dist/esm/core/StatusManager.js +52 -50
  90. package/dist/esm/core/StatusManager.js.map +1 -1
  91. package/dist/esm/core/TaskPipeline.d.ts +7 -0
  92. package/dist/esm/core/TaskPipeline.js +23 -0
  93. package/dist/esm/core/TaskPipeline.js.map +1 -0
  94. package/dist/esm/core/actionMessages.js +19 -3
  95. package/dist/esm/core/actionMessages.js.map +1 -1
  96. package/dist/esm/core/execution.js +14 -3
  97. package/dist/esm/core/execution.js.map +1 -1
  98. package/dist/esm/core/prepareRestart.js +4 -3
  99. package/dist/esm/core/prepareRestart.js.map +1 -1
  100. package/dist/esm/core/storage.d.ts +17 -0
  101. package/dist/esm/core/storage.js +30 -0
  102. package/dist/esm/core/storage.js.map +1 -0
  103. package/dist/esm/core/tasks/CheckBalanceTask.d.ts +5 -0
  104. package/dist/esm/core/tasks/CheckBalanceTask.js +22 -0
  105. package/dist/esm/core/tasks/CheckBalanceTask.js.map +1 -0
  106. package/dist/esm/core/tasks/PrepareTransactionTask.d.ts +5 -0
  107. package/dist/esm/core/tasks/PrepareTransactionTask.js +32 -0
  108. package/dist/esm/core/tasks/PrepareTransactionTask.js.map +1 -0
  109. package/dist/esm/core/tasks/WaitForTransactionStatusTask.d.ts +8 -0
  110. package/dist/esm/core/tasks/WaitForTransactionStatusTask.js +74 -0
  111. package/dist/esm/core/tasks/WaitForTransactionStatusTask.js.map +1 -0
  112. package/dist/esm/core/{checkBalance.d.ts → tasks/helpers/checkBalance.d.ts} +1 -1
  113. package/dist/esm/core/{checkBalance.js → tasks/helpers/checkBalance.js} +4 -4
  114. package/dist/esm/core/tasks/helpers/checkBalance.js.map +1 -0
  115. package/dist/esm/core/tasks/helpers/getTransactionRequestData.d.ts +2 -0
  116. package/dist/esm/core/tasks/helpers/getTransactionRequestData.js +26 -0
  117. package/dist/esm/core/tasks/helpers/getTransactionRequestData.js.map +1 -0
  118. package/dist/esm/core/{stepComparison.d.ts → tasks/helpers/stepComparison.d.ts} +2 -2
  119. package/dist/esm/core/{stepComparison.js → tasks/helpers/stepComparison.js} +3 -3
  120. package/dist/esm/core/tasks/helpers/stepComparison.js.map +1 -0
  121. package/dist/esm/core/{waitForTransactionStatus.d.ts → tasks/helpers/waitForTransactionStatus.d.ts} +2 -2
  122. package/dist/esm/core/{waitForTransactionStatus.js → tasks/helpers/waitForTransactionStatus.js} +7 -5
  123. package/dist/esm/core/tasks/helpers/waitForTransactionStatus.js.map +1 -0
  124. package/dist/esm/core/utils.d.ts +6 -1
  125. package/dist/esm/errors/constants.d.ts +2 -1
  126. package/dist/esm/errors/constants.js +1 -0
  127. package/dist/esm/errors/constants.js.map +1 -1
  128. package/dist/esm/errors/errors.d.ts +10 -0
  129. package/dist/esm/errors/errors.js +12 -0
  130. package/dist/esm/errors/errors.js.map +1 -1
  131. package/dist/esm/index.d.ts +15 -6
  132. package/dist/esm/index.js +12 -5
  133. package/dist/esm/index.js.map +1 -1
  134. package/dist/esm/types/core.d.ts +19 -6
  135. package/dist/esm/types/execution.d.ts +23 -0
  136. package/dist/esm/types/execution.js +2 -0
  137. package/dist/esm/types/execution.js.map +1 -0
  138. package/dist/esm/utils/waitForResult.d.ts +2 -2
  139. package/dist/esm/utils/waitForResult.js +7 -3
  140. package/dist/esm/utils/waitForResult.js.map +1 -1
  141. package/dist/esm/utils/withDedupe.d.ts +10 -0
  142. package/dist/esm/utils/withDedupe.js +1 -1
  143. package/dist/esm/utils/withDedupe.js.map +1 -1
  144. package/dist/esm/version.d.ts +1 -1
  145. package/dist/esm/version.js +1 -1
  146. package/dist/esm/version.js.map +1 -1
  147. package/dist/types/actions/getRelayerQuote.d.ts.map +1 -1
  148. package/dist/types/actions/getStepTransaction.d.ts.map +1 -1
  149. package/dist/types/core/BaseStepExecutionTask.d.ts +6 -0
  150. package/dist/types/core/BaseStepExecutionTask.d.ts.map +1 -0
  151. package/dist/types/core/BaseStepExecutor.d.ts +10 -3
  152. package/dist/types/core/BaseStepExecutor.d.ts.map +1 -1
  153. package/dist/types/core/StatusManager.d.ts +29 -27
  154. package/dist/types/core/StatusManager.d.ts.map +1 -1
  155. package/dist/types/core/TaskPipeline.d.ts +8 -0
  156. package/dist/types/core/TaskPipeline.d.ts.map +1 -0
  157. package/dist/types/core/actionMessages.d.ts.map +1 -1
  158. package/dist/types/core/execution.d.ts.map +1 -1
  159. package/dist/types/core/prepareRestart.d.ts.map +1 -1
  160. package/dist/types/core/storage.d.ts +18 -0
  161. package/dist/types/core/storage.d.ts.map +1 -0
  162. package/dist/types/core/tasks/CheckBalanceTask.d.ts +6 -0
  163. package/dist/types/core/tasks/CheckBalanceTask.d.ts.map +1 -0
  164. package/dist/types/core/tasks/PrepareTransactionTask.d.ts +6 -0
  165. package/dist/types/core/tasks/PrepareTransactionTask.d.ts.map +1 -0
  166. package/dist/types/core/tasks/WaitForTransactionStatusTask.d.ts +9 -0
  167. package/dist/types/core/tasks/WaitForTransactionStatusTask.d.ts.map +1 -0
  168. package/dist/types/core/{checkBalance.d.ts → tasks/helpers/checkBalance.d.ts} +1 -1
  169. package/dist/types/core/tasks/helpers/checkBalance.d.ts.map +1 -0
  170. package/dist/types/core/tasks/helpers/getTransactionRequestData.d.ts +3 -0
  171. package/dist/types/core/tasks/helpers/getTransactionRequestData.d.ts.map +1 -0
  172. package/dist/types/core/{stepComparison.d.ts → tasks/helpers/stepComparison.d.ts} +2 -2
  173. package/dist/types/core/tasks/helpers/stepComparison.d.ts.map +1 -0
  174. package/dist/types/core/{waitForTransactionStatus.d.ts → tasks/helpers/waitForTransactionStatus.d.ts} +2 -2
  175. package/dist/types/core/tasks/helpers/waitForTransactionStatus.d.ts.map +1 -0
  176. package/dist/types/core/utils.d.ts +6 -1
  177. package/dist/types/core/utils.d.ts.map +1 -1
  178. package/dist/types/errors/constants.d.ts +2 -1
  179. package/dist/types/errors/constants.d.ts.map +1 -1
  180. package/dist/types/errors/errors.d.ts +10 -0
  181. package/dist/types/errors/errors.d.ts.map +1 -1
  182. package/dist/types/index.d.ts +15 -6
  183. package/dist/types/index.d.ts.map +1 -1
  184. package/dist/types/types/core.d.ts +19 -6
  185. package/dist/types/types/core.d.ts.map +1 -1
  186. package/dist/types/types/execution.d.ts +24 -0
  187. package/dist/types/types/execution.d.ts.map +1 -0
  188. package/dist/types/utils/waitForResult.d.ts +2 -2
  189. package/dist/types/utils/waitForResult.d.ts.map +1 -1
  190. package/dist/types/utils/withDedupe.d.ts +10 -0
  191. package/dist/types/utils/withDedupe.d.ts.map +1 -1
  192. package/dist/types/version.d.ts +1 -1
  193. package/dist/types/version.d.ts.map +1 -1
  194. package/package.json +2 -2
  195. package/src/actions/getQuote.ts +4 -1
  196. package/src/actions/getRelayedTransactionStatus.ts +1 -1
  197. package/src/actions/getRelayerQuote.ts +4 -1
  198. package/src/actions/getStepTransaction.ts +27 -11
  199. package/src/core/BaseStepExecutionTask.ts +9 -0
  200. package/src/core/BaseStepExecutor.ts +91 -2
  201. package/src/core/StatusManager.ts +66 -61
  202. package/src/core/TaskPipeline.ts +28 -0
  203. package/src/core/actionMessages.ts +20 -3
  204. package/src/core/execution.ts +17 -3
  205. package/src/core/prepareRestart.ts +4 -3
  206. package/src/core/storage.ts +42 -0
  207. package/src/core/tasks/CheckBalanceTask.ts +29 -0
  208. package/src/core/tasks/PrepareTransactionTask.ts +62 -0
  209. package/src/core/tasks/WaitForTransactionStatusTask.ts +114 -0
  210. package/src/core/{checkBalance.ts → tasks/helpers/checkBalance.ts} +5 -5
  211. package/src/core/tasks/helpers/getTransactionRequestData.ts +47 -0
  212. package/src/core/{stepComparison.ts → tasks/helpers/stepComparison.ts} +5 -5
  213. package/src/core/{waitForTransactionStatus.ts → tasks/helpers/waitForTransactionStatus.ts} +9 -7
  214. package/src/errors/constants.ts +1 -0
  215. package/src/errors/errors.ts +24 -0
  216. package/src/index.ts +24 -4
  217. package/src/types/core.ts +23 -13
  218. package/src/types/execution.ts +32 -0
  219. package/src/utils/waitForResult.ts +9 -4
  220. package/src/utils/withDedupe.ts +1 -1
  221. package/src/version.ts +1 -1
  222. package/dist/cjs/core/checkBalance.js.map +0 -1
  223. package/dist/cjs/core/stepComparison.js.map +0 -1
  224. package/dist/cjs/core/waitForDestinationChainTransaction.d.ts +0 -4
  225. package/dist/cjs/core/waitForDestinationChainTransaction.js +0 -71
  226. package/dist/cjs/core/waitForDestinationChainTransaction.js.map +0 -1
  227. package/dist/cjs/core/waitForTransactionStatus.js.map +0 -1
  228. package/dist/esm/core/checkBalance.js.map +0 -1
  229. package/dist/esm/core/stepComparison.js.map +0 -1
  230. package/dist/esm/core/waitForDestinationChainTransaction.d.ts +0 -4
  231. package/dist/esm/core/waitForDestinationChainTransaction.js +0 -74
  232. package/dist/esm/core/waitForDestinationChainTransaction.js.map +0 -1
  233. package/dist/esm/core/waitForTransactionStatus.js.map +0 -1
  234. package/dist/types/core/checkBalance.d.ts.map +0 -1
  235. package/dist/types/core/stepComparison.d.ts.map +0 -1
  236. package/dist/types/core/waitForDestinationChainTransaction.d.ts +0 -5
  237. package/dist/types/core/waitForDestinationChainTransaction.d.ts.map +0 -1
  238. package/dist/types/core/waitForTransactionStatus.d.ts.map +0 -1
  239. package/src/core/waitForDestinationChainTransaction.ts +0 -112
@@ -0,0 +1,62 @@
1
+ import { getStepTransaction } from '../../actions/getStepTransaction.js'
2
+ import { LiFiErrorCode } from '../../errors/constants.js'
3
+ import { TransactionError } from '../../errors/errors.js'
4
+ import type { StepExecutorContext, TaskResult } from '../../types/execution.js'
5
+ import { BaseStepExecutionTask } from '../BaseStepExecutionTask.js'
6
+ import { stepComparison } from './helpers/stepComparison.js'
7
+
8
+ export class PrepareTransactionTask extends BaseStepExecutionTask {
9
+ async run(context: StepExecutorContext): Promise<TaskResult> {
10
+ const {
11
+ client,
12
+ step,
13
+ statusManager,
14
+ allowUserInteraction,
15
+ executionOptions,
16
+ isBridgeExecution,
17
+ } = context
18
+
19
+ const action = statusManager.findAction(
20
+ step,
21
+ isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
22
+ )
23
+
24
+ if (!action) {
25
+ throw new TransactionError(
26
+ LiFiErrorCode.TransactionUnprepared,
27
+ 'Unable to prepare transaction. Action not found.'
28
+ )
29
+ }
30
+
31
+ if (!step.transactionRequest) {
32
+ const { execution, ...stepBase } = step
33
+ const updatedStep = await getStepTransaction(client, stepBase)
34
+ const comparedStep = await stepComparison(
35
+ statusManager,
36
+ step,
37
+ updatedStep,
38
+ allowUserInteraction,
39
+ executionOptions
40
+ )
41
+ Object.assign(step, {
42
+ ...comparedStep,
43
+ execution: step.execution,
44
+ })
45
+ }
46
+
47
+ if (!step.transactionRequest?.data) {
48
+ throw new TransactionError(
49
+ LiFiErrorCode.TransactionUnprepared,
50
+ 'Unable to prepare transaction. Transaction request data is not found.'
51
+ )
52
+ }
53
+
54
+ statusManager.updateAction(step, action.type, 'ACTION_REQUIRED')
55
+
56
+ if (!allowUserInteraction) {
57
+ return { status: 'PAUSED' }
58
+ }
59
+
60
+ return { status: 'COMPLETED' }
61
+ }
62
+ }
@@ -0,0 +1,114 @@
1
+ import type { ExtendedTransactionInfo, FullStatusData } from '@lifi/types'
2
+ import { LiFiErrorCode } from '../../errors/constants.js'
3
+ import { TransactionError } from '../../errors/errors.js'
4
+ import type { ExecutionActionType } from '../../types/core.js'
5
+ import type { StepExecutorContext, TaskResult } from '../../types/execution.js'
6
+ import { getTransactionFailedMessage } from '../../utils/getTransactionMessage.js'
7
+ import { BaseStepExecutionTask } from '../BaseStepExecutionTask.js'
8
+ import { waitForTransactionStatus } from './helpers/waitForTransactionStatus.js'
9
+
10
+ export class WaitForTransactionStatusTask extends BaseStepExecutionTask {
11
+ readonly actionType: ExecutionActionType
12
+
13
+ constructor(actionType: ExecutionActionType) {
14
+ super()
15
+ this.actionType = actionType
16
+ }
17
+
18
+ async run(context: StepExecutorContext): Promise<TaskResult> {
19
+ const {
20
+ client,
21
+ step,
22
+ statusManager,
23
+ pollingIntervalMs,
24
+ toChain,
25
+ isBridgeExecution,
26
+ } = context
27
+
28
+ // At this point, we should have a txHash or taskId
29
+ // taskId is used for custom integrations that don't use the standard transaction hash
30
+ let transactionHash: string | undefined
31
+ try {
32
+ const swapOrBridgeAction = statusManager.findAction(
33
+ step,
34
+ isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
35
+ )
36
+ transactionHash = swapOrBridgeAction?.txHash || swapOrBridgeAction?.taskId
37
+
38
+ // Wait for the transaction status on the destination chain
39
+ if (!transactionHash) {
40
+ throw new Error('Transaction hash is undefined.')
41
+ }
42
+
43
+ const action = statusManager.initializeAction({
44
+ step,
45
+ type: this.actionType,
46
+ chainId:
47
+ this.actionType === 'RECEIVING_CHAIN'
48
+ ? step.action.toChainId
49
+ : step.action.fromChainId,
50
+ status: 'PENDING',
51
+ })
52
+
53
+ const statusResponse = (await waitForTransactionStatus(
54
+ client,
55
+ statusManager,
56
+ transactionHash,
57
+ step,
58
+ action.type,
59
+ pollingIntervalMs
60
+ )) as FullStatusData
61
+
62
+ const statusReceiving =
63
+ statusResponse.receiving as ExtendedTransactionInfo
64
+
65
+ // Update action status
66
+ statusManager.updateAction(step, action.type, 'DONE', {
67
+ chainId: statusReceiving?.chainId || toChain.id,
68
+ substatus: statusResponse.substatus,
69
+ substatusMessage: statusResponse.substatusMessage,
70
+ txHash: statusReceiving?.txHash,
71
+ txLink:
72
+ statusReceiving?.txLink ||
73
+ `${toChain.metamask.blockExplorerUrls[0]}tx/${statusReceiving?.txHash}`,
74
+ })
75
+
76
+ // Update execution status
77
+ statusManager.updateExecution(step, {
78
+ status: 'DONE',
79
+ ...(statusResponse.sending.amount && {
80
+ fromAmount: statusResponse.sending.amount,
81
+ }),
82
+ ...(statusReceiving?.amount && { toAmount: statusReceiving.amount }),
83
+ ...(statusReceiving?.token && { toToken: statusReceiving.token }),
84
+ internalTxLink: statusResponse?.lifiExplorerLink,
85
+ externalTxLink: statusResponse?.bridgeExplorerLink,
86
+ gasCosts: [
87
+ {
88
+ amount: statusResponse.sending.gasAmount,
89
+ amountUSD: statusResponse.sending.gasAmountUSD,
90
+ token: statusResponse.sending.gasToken,
91
+ estimate: statusResponse.sending.gasUsed,
92
+ limit: statusResponse.sending.gasUsed,
93
+ price: statusResponse.sending.gasPrice,
94
+ type: 'SEND',
95
+ },
96
+ ],
97
+ })
98
+
99
+ return { status: 'COMPLETED' }
100
+ } catch (e: any) {
101
+ const htmlMessage = await getTransactionFailedMessage(
102
+ client,
103
+ step,
104
+ `${toChain.metamask.blockExplorerUrls[0]}tx/${transactionHash}`
105
+ )
106
+ throw new TransactionError(
107
+ LiFiErrorCode.TransactionFailed,
108
+ htmlMessage ??
109
+ 'Failed while waiting for status of destination chain transaction.',
110
+ e
111
+ )
112
+ }
113
+ }
114
+ }
@@ -1,9 +1,9 @@
1
1
  import type { LiFiStep } from '@lifi/types'
2
- import { getTokenBalance } from '../actions/getTokenBalance.js'
3
- import { BalanceError } from '../errors/errors.js'
4
- import type { SDKClient } from '../types/core.js'
5
- import { formatUnits } from '../utils/formatUnits.js'
6
- import { sleep } from '../utils/sleep.js'
2
+ import { getTokenBalance } from '../../../actions/getTokenBalance.js'
3
+ import { BalanceError } from '../../../errors/errors.js'
4
+ import type { SDKClient } from '../../../types/core.js'
5
+ import { formatUnits } from '../../../utils/formatUnits.js'
6
+ import { sleep } from '../../../utils/sleep.js'
7
7
 
8
8
  export const checkBalance = async (
9
9
  client: SDKClient,
@@ -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
+ }
@@ -1,9 +1,9 @@
1
1
  import type { LiFiStep } from '@lifi/types'
2
- import { LiFiErrorCode } from '../errors/constants.js'
3
- import { TransactionError } from '../errors/errors.js'
4
- import type { ExecutionOptions } from '../types/core.js'
5
- import type { StatusManager } from './StatusManager.js'
6
- import { checkStepSlippageThreshold } from './utils.js'
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
7
 
8
8
  /**
9
9
  * This method checks whether the new and updated Step meets the required exchange rate conditions.
@@ -1,10 +1,10 @@
1
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'
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
8
 
9
9
  const TRANSACTION_HASH_OBSERVERS: Record<string, Promise<StatusResponse>> = {}
10
10
 
@@ -57,7 +57,9 @@ export async function waitForTransactionStatus(
57
57
  let status = TRANSACTION_HASH_OBSERVERS[txHash]
58
58
 
59
59
  if (!status) {
60
- status = waitForResult(_getStatus, interval)
60
+ status = waitForResult(_getStatus, interval).finally(() => {
61
+ delete TRANSACTION_HASH_OBSERVERS[txHash]
62
+ })
61
63
  TRANSACTION_HASH_OBSERVERS[txHash] = status
62
64
  }
63
65
 
@@ -10,6 +10,7 @@ export enum ErrorName {
10
10
  SlippageError = 'SlippageError',
11
11
  HTTPError = 'HTTPError',
12
12
  ConfigError = 'ConfigError',
13
+ ExecuteStepRetryError = 'ExecuteStepRetryError',
13
14
  }
14
15
 
15
16
  export type ErrorCode = LiFiErrorCode
@@ -1,3 +1,4 @@
1
+ import type { ExecuteStepRetryParams } from '../types/core.js'
1
2
  import { BaseError } from './baseError.js'
2
3
  import { ErrorName, LiFiErrorCode } from './constants.js'
3
4
 
@@ -42,3 +43,26 @@ export class ValidationError extends BaseError {
42
43
  super(ErrorName.ValidationError, LiFiErrorCode.ValidationError, message)
43
44
  }
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
+ }
package/src/index.ts CHANGED
@@ -24,8 +24,9 @@ export { actions } from './actions/index.js'
24
24
  export { patchContractCalls } from './actions/patchContractCalls.js'
25
25
  export { relayTransaction } from './actions/relayTransaction.js'
26
26
  export { createClient } from './client/createClient.js'
27
+ export { getActionMessage, getSubstatusMessage } from './core/actionMessages.js'
28
+ export { BaseStepExecutionTask } from './core/BaseStepExecutionTask.js'
27
29
  export { BaseStepExecutor } from './core/BaseStepExecutor.js'
28
- export { checkBalance } from './core/checkBalance.js'
29
30
  export {
30
31
  executeRoute,
31
32
  getActiveRoute,
@@ -35,13 +36,25 @@ export {
35
36
  updateRouteExecution,
36
37
  } from './core/execution.js'
37
38
  export { StatusManager } from './core/StatusManager.js'
38
- export { stepComparison } from './core/stepComparison.js'
39
- export { waitForDestinationChainTransaction } from './core/waitForDestinationChainTransaction.js'
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'
40
52
  export { BaseError } from './errors/baseError.js'
41
53
  export type { ErrorCode } from './errors/constants.js'
42
54
  export { ErrorMessage, ErrorName, LiFiErrorCode } from './errors/constants.js'
43
55
  export {
44
56
  BalanceError,
57
+ ExecuteStepRetryError,
45
58
  ProviderError,
46
59
  RPCError,
47
60
  ServerError,
@@ -58,6 +71,7 @@ export type {
58
71
  ContractCallParams,
59
72
  ContractTool,
60
73
  ExchangeRateUpdateParams,
74
+ ExecuteStepRetryParams,
61
75
  Execution,
62
76
  ExecutionAction,
63
77
  ExecutionActionStatus,
@@ -87,6 +101,12 @@ export type {
87
101
  TransactionRequestUpdateHook,
88
102
  UpdateRouteHook,
89
103
  } from './types/core.js'
104
+ export type {
105
+ StepExecutorBaseContext,
106
+ StepExecutorContext,
107
+ TaskResult,
108
+ TaskStatus,
109
+ } from './types/execution.js'
90
110
  export { checkPackageUpdates } from './utils/checkPackageUpdates.js'
91
111
  export { convertQuoteToRoute } from './utils/convertQuoteToRoute.js'
92
112
  export { fetchTxErrorDetails } from './utils/fetchTxErrorDetails.js'
@@ -95,4 +115,4 @@ export { isHex } from './utils/isHex.js'
95
115
  export { parseUnits } from './utils/parseUnits.js'
96
116
  export { sleep } from './utils/sleep.js'
97
117
  export { waitForResult } from './utils/waitForResult.js'
98
- export { withDedupe } from './utils/withDedupe.js'
118
+ export { LruMap, withDedupe } from './utils/withDedupe.js'
package/src/types/core.ts CHANGED
@@ -14,6 +14,7 @@ import type {
14
14
  Token,
15
15
  TokenAmount,
16
16
  } from '@lifi/types'
17
+ import type { SDKStorage } from '../core/storage.js'
17
18
  import type { ExtendedRequestInit } from './request.js'
18
19
 
19
20
  export type RequestInterceptor = (
@@ -34,6 +35,7 @@ export interface SDKBaseConfig {
34
35
  preloadChains?: boolean
35
36
  chainsRefetchInterval?: number
36
37
  requestInterceptor?: RequestInterceptor
38
+ storage?: SDKStorage
37
39
  }
38
40
 
39
41
  export interface SDKConfig extends Partial<Omit<SDKBaseConfig, 'integrator'>> {
@@ -82,13 +84,20 @@ export interface InteractionSettings {
82
84
  allowExecution?: boolean
83
85
  }
84
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
+
85
93
  export interface StepExecutor {
86
94
  allowUserInteraction: boolean
87
95
  allowExecution: boolean
88
96
  setInteraction(settings?: InteractionSettings): void
89
97
  executeStep(
90
98
  client: SDKClient,
91
- step: LiFiStepExtended
99
+ step: LiFiStepExtended,
100
+ retryParams?: ExecuteStepRetryParams
92
101
  ): Promise<LiFiStepExtended>
93
102
  }
94
103
 
@@ -195,7 +204,6 @@ export interface ExecutionOptions {
195
204
  getContractCalls?: GetContractCallsHook
196
205
  adjustZeroOutputFromPreviousStep?: boolean
197
206
  executeInBackground?: boolean
198
- disableMessageSigning?: boolean
199
207
  /**
200
208
  * @deprecated
201
209
  */
@@ -215,8 +223,11 @@ export type ExecutionActionStatus =
215
223
  | 'CANCELLED'
216
224
 
217
225
  export type ExecutionActionType =
218
- | 'TOKEN_ALLOWANCE'
219
226
  | 'PERMIT'
227
+ | 'CHECK_ALLOWANCE'
228
+ | 'NATIVE_PERMIT'
229
+ | 'RESET_ALLOWANCE'
230
+ | 'SET_ALLOWANCE'
220
231
  | 'SWAP'
221
232
  | 'CROSS_CHAIN'
222
233
  | 'RECEIVING_CHAIN'
@@ -224,21 +235,17 @@ export type ExecutionActionType =
224
235
  export type ExecutionAction = {
225
236
  type: ExecutionActionType
226
237
  status: ExecutionActionStatus
238
+ message?: string
227
239
  substatus?: Substatus
240
+ substatusMessage?: string
228
241
  chainId?: number
229
242
  txHash?: string
230
- taskId?: string
231
243
  txLink?: string
244
+ taskId?: string
232
245
  txType?: TransactionMethodType
233
- message?: string
234
- error?: {
235
- code: string | number
236
- message: string
237
- htmlMessage?: string
238
- }
239
-
240
- // additional information
241
- [key: string]: any
246
+ txHex?: string
247
+ // Errors occured during the action execution (within tasks)
248
+ error?: { code: string | number; message: string; htmlMessage?: string }
242
249
  }
243
250
 
244
251
  export interface Execution {
@@ -246,6 +253,7 @@ export interface Execution {
246
253
  signedAt?: number
247
254
  status: ExecutionStatus
248
255
  actions: Array<ExecutionAction>
256
+ lastActionType?: ExecutionActionType
249
257
  fromAmount?: string
250
258
  toAmount?: string
251
259
  toToken?: Token
@@ -253,6 +261,8 @@ export interface Execution {
253
261
  gasCosts?: GasCost[]
254
262
  internalTxLink?: string
255
263
  externalTxLink?: string
264
+ // Errors occured outside of actions (e.g. during context creation)
265
+ error?: { code: string | number; message: string; htmlMessage?: string }
256
266
  }
257
267
 
258
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'
@@ -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, defaults to 5000
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(interval)
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(interval)
39
+ await sleep(getInterval(polls))
40
+ polls++
36
41
  }
37
42
  }
38
43
 
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU
5
5
  */
6
- class LruMap<value = unknown> extends Map<string, value> {
6
+ export class LruMap<value = unknown> extends Map<string, value> {
7
7
  maxSize: number
8
8
 
9
9
  constructor(size: number) {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk'
2
- export const version = '4.0.0-alpha.9'
2
+ export const version = '4.0.0-beta.0'
@@ -1 +0,0 @@
1
- {"version":3,"file":"checkBalance.js","sourceRoot":"","sources":["../../../src/core/checkBalance.ts"],"names":[],"mappings":";;;AACA,sEAA+D;AAC/D,mDAAkD;AAElD,4DAAqD;AACrD,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,4BAAW,EAAC,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;gBACzD,MAAM,OAAO,GAAG,IAAA,4BAAW,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 +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"}
@@ -1,4 +0,0 @@
1
- import type { ExtendedChain } from '@lifi/types';
2
- import type { ExecutionAction, LiFiStepExtended, SDKClient } from '../types/core.js';
3
- import type { StatusManager } from './StatusManager.js';
4
- export declare function waitForDestinationChainTransaction(client: SDKClient, step: LiFiStepExtended, action: ExecutionAction, fromChain: ExtendedChain, toChain: ExtendedChain, statusManager: StatusManager, pollingInterval?: number): Promise<LiFiStepExtended>;
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.waitForDestinationChainTransaction = waitForDestinationChainTransaction;
4
- const constants_js_1 = require("../errors/constants.js");
5
- const getTransactionMessage_js_1 = require("../utils/getTransactionMessage.js");
6
- const waitForTransactionStatus_js_1 = require("./waitForTransactionStatus.js");
7
- async function waitForDestinationChainTransaction(client, step, action, fromChain, toChain, statusManager, pollingInterval) {
8
- const transactionHash = action.txHash || action.taskId;
9
- let actionType = action.type;
10
- try {
11
- if (!transactionHash) {
12
- throw new Error('Transaction hash is undefined.');
13
- }
14
- const isBridgeExecution = fromChain.id !== toChain.id;
15
- if (isBridgeExecution) {
16
- const receivingChainAction = statusManager.findOrCreateAction({
17
- step,
18
- type: 'RECEIVING_CHAIN',
19
- status: 'PENDING',
20
- chainId: toChain.id,
21
- });
22
- actionType = receivingChainAction.type;
23
- }
24
- step = statusManager.updateExecution(step, 'PENDING', {
25
- signedAt: Date.now(),
26
- });
27
- const statusResponse = (await (0, waitForTransactionStatus_js_1.waitForTransactionStatus)(client, statusManager, transactionHash, step, actionType, pollingInterval));
28
- const statusReceiving = statusResponse.receiving;
29
- statusManager.updateAction(step, actionType, 'DONE', {
30
- chainId: statusReceiving?.chainId || toChain.id,
31
- substatus: statusResponse.substatus,
32
- substatusMessage: statusResponse.substatusMessage,
33
- txHash: statusReceiving?.txHash,
34
- txLink: statusReceiving?.txLink ||
35
- `${toChain.metamask.blockExplorerUrls[0]}tx/${statusReceiving?.txHash}`,
36
- });
37
- statusManager.updateExecution(step, 'DONE', {
38
- ...(statusResponse.sending.amount && {
39
- fromAmount: statusResponse.sending.amount,
40
- }),
41
- ...(statusReceiving?.amount && { toAmount: statusReceiving.amount }),
42
- ...(statusReceiving?.token && { toToken: statusReceiving.token }),
43
- internalTxLink: statusResponse?.lifiExplorerLink,
44
- externalTxLink: statusResponse?.bridgeExplorerLink,
45
- gasCosts: [
46
- {
47
- amount: statusResponse.sending.gasAmount,
48
- amountUSD: statusResponse.sending.gasAmountUSD,
49
- token: statusResponse.sending.gasToken,
50
- estimate: statusResponse.sending.gasUsed,
51
- limit: statusResponse.sending.gasUsed,
52
- price: statusResponse.sending.gasPrice,
53
- type: 'SEND',
54
- },
55
- ],
56
- });
57
- return step;
58
- }
59
- catch (e) {
60
- const htmlMessage = await (0, getTransactionMessage_js_1.getTransactionFailedMessage)(client, step, `${toChain.metamask.blockExplorerUrls[0]}tx/${transactionHash}`);
61
- statusManager.updateAction(step, actionType, 'FAILED', {
62
- error: {
63
- code: constants_js_1.LiFiErrorCode.TransactionFailed,
64
- message: 'Failed while waiting for status of destination chain transaction.',
65
- htmlMessage,
66
- },
67
- });
68
- throw e;
69
- }
70
- }
71
- //# sourceMappingURL=waitForDestinationChainTransaction.js.map