@lifi/sdk 4.9.0 → 4.11.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 (185) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +9 -0
  3. package/dist/cjs/client/createClient.js +6 -4
  4. package/dist/cjs/client/createClient.js.map +1 -1
  5. package/dist/cjs/client/findProvider.d.ts +10 -0
  6. package/dist/cjs/client/findProvider.js +11 -0
  7. package/dist/cjs/client/findProvider.js.map +1 -0
  8. package/dist/cjs/core/BaseStepExecutor.d.ts +1 -1
  9. package/dist/cjs/core/BaseStepExecutor.js +21 -9
  10. package/dist/cjs/core/BaseStepExecutor.js.map +1 -1
  11. package/dist/cjs/core/StatusManager.d.ts +10 -0
  12. package/dist/cjs/core/StatusManager.js +105 -3
  13. package/dist/cjs/core/StatusManager.js.map +1 -1
  14. package/dist/cjs/core/execution.js +30 -14
  15. package/dist/cjs/core/execution.js.map +1 -1
  16. package/dist/cjs/core/executionState.d.ts +34 -2
  17. package/dist/cjs/core/executionState.js +44 -1
  18. package/dist/cjs/core/executionState.js.map +1 -1
  19. package/dist/cjs/core/prepareRestart.js +14 -6
  20. package/dist/cjs/core/prepareRestart.js.map +1 -1
  21. package/dist/cjs/core/tasks/WaitForTransactionStatusTask.js +4 -2
  22. package/dist/cjs/core/tasks/WaitForTransactionStatusTask.js.map +1 -1
  23. package/dist/cjs/core/tasks/helpers/checkBalance.js +6 -3
  24. package/dist/cjs/core/tasks/helpers/checkBalance.js.map +1 -1
  25. package/dist/cjs/core/tasks/helpers/getStepStatusRequest.d.ts +10 -0
  26. package/dist/cjs/core/tasks/helpers/getStepStatusRequest.js +20 -0
  27. package/dist/cjs/core/tasks/helpers/getStepStatusRequest.js.map +1 -0
  28. package/dist/cjs/core/tasks/helpers/isKnownToStatusApi.d.ts +21 -0
  29. package/dist/cjs/core/tasks/helpers/isKnownToStatusApi.js +44 -0
  30. package/dist/cjs/core/tasks/helpers/isKnownToStatusApi.js.map +1 -0
  31. package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.d.ts +22 -1
  32. package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.js +76 -17
  33. package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.js.map +1 -1
  34. package/dist/cjs/core/transactionState.d.ts +121 -0
  35. package/dist/cjs/core/transactionState.js +164 -0
  36. package/dist/cjs/core/transactionState.js.map +1 -0
  37. package/dist/cjs/errors/errors.d.ts +13 -2
  38. package/dist/cjs/errors/errors.js +5 -2
  39. package/dist/cjs/errors/errors.js.map +1 -1
  40. package/dist/cjs/index.d.ts +7 -3
  41. package/dist/cjs/index.js +16 -1
  42. package/dist/cjs/types/core.d.ts +49 -3
  43. package/dist/cjs/types/execution.d.ts +8 -0
  44. package/dist/cjs/utils/abort.d.ts +6 -0
  45. package/dist/cjs/utils/abort.js +10 -0
  46. package/dist/cjs/utils/abort.js.map +1 -0
  47. package/dist/cjs/utils/checkPackageUpdates.js +1 -1
  48. package/dist/cjs/utils/formatUnits.js +1 -0
  49. package/dist/cjs/utils/formatUnits.js.map +1 -1
  50. package/dist/cjs/utils/lru.d.ts +14 -0
  51. package/dist/cjs/utils/lru.js +35 -0
  52. package/dist/cjs/utils/lru.js.map +1 -0
  53. package/dist/cjs/utils/parseUnits.js +30 -16
  54. package/dist/cjs/utils/parseUnits.js.map +1 -1
  55. package/dist/cjs/utils/sleep.d.ts +7 -1
  56. package/dist/cjs/utils/sleep.js +22 -3
  57. package/dist/cjs/utils/sleep.js.map +1 -1
  58. package/dist/cjs/utils/waitForResult.d.ts +7 -5
  59. package/dist/cjs/utils/waitForResult.js +19 -14
  60. package/dist/cjs/utils/waitForResult.js.map +1 -1
  61. package/dist/cjs/utils/withDedupe.d.ts +0 -10
  62. package/dist/cjs/utils/withDedupe.js +4 -23
  63. package/dist/cjs/utils/withDedupe.js.map +1 -1
  64. package/dist/cjs/utils/withTimeout.js +6 -2
  65. package/dist/cjs/utils/withTimeout.js.map +1 -1
  66. package/dist/cjs/version.d.ts +1 -1
  67. package/dist/cjs/version.js +1 -1
  68. package/dist/cjs/version.js.map +1 -1
  69. package/dist/esm/actions/getRoutes.d.ts.map +1 -1
  70. package/dist/esm/actions/index.d.ts.map +1 -1
  71. package/dist/esm/client/createClient.d.ts.map +1 -1
  72. package/dist/esm/client/createClient.js +6 -4
  73. package/dist/esm/client/createClient.js.map +1 -1
  74. package/dist/esm/client/findProvider.d.ts +10 -0
  75. package/dist/esm/client/findProvider.d.ts.map +1 -0
  76. package/dist/esm/client/findProvider.js +10 -0
  77. package/dist/esm/client/findProvider.js.map +1 -0
  78. package/dist/esm/core/BaseStepExecutor.d.ts +1 -1
  79. package/dist/esm/core/BaseStepExecutor.d.ts.map +1 -1
  80. package/dist/esm/core/BaseStepExecutor.js +22 -10
  81. package/dist/esm/core/BaseStepExecutor.js.map +1 -1
  82. package/dist/esm/core/StatusManager.d.ts +10 -0
  83. package/dist/esm/core/StatusManager.d.ts.map +1 -1
  84. package/dist/esm/core/StatusManager.js +105 -3
  85. package/dist/esm/core/StatusManager.js.map +1 -1
  86. package/dist/esm/core/execution.d.ts.map +1 -1
  87. package/dist/esm/core/execution.js +30 -14
  88. package/dist/esm/core/execution.js.map +1 -1
  89. package/dist/esm/core/executionState.d.ts +34 -2
  90. package/dist/esm/core/executionState.d.ts.map +1 -1
  91. package/dist/esm/core/executionState.js +44 -1
  92. package/dist/esm/core/executionState.js.map +1 -1
  93. package/dist/esm/core/prepareRestart.d.ts.map +1 -1
  94. package/dist/esm/core/prepareRestart.js +14 -6
  95. package/dist/esm/core/prepareRestart.js.map +1 -1
  96. package/dist/esm/core/tasks/WaitForTransactionStatusTask.d.ts.map +1 -1
  97. package/dist/esm/core/tasks/WaitForTransactionStatusTask.js +4 -2
  98. package/dist/esm/core/tasks/WaitForTransactionStatusTask.js.map +1 -1
  99. package/dist/esm/core/tasks/helpers/checkBalance.js +6 -3
  100. package/dist/esm/core/tasks/helpers/checkBalance.js.map +1 -1
  101. package/dist/esm/core/tasks/helpers/getStepStatusRequest.d.ts +10 -0
  102. package/dist/esm/core/tasks/helpers/getStepStatusRequest.d.ts.map +1 -0
  103. package/dist/esm/core/tasks/helpers/getStepStatusRequest.js +19 -0
  104. package/dist/esm/core/tasks/helpers/getStepStatusRequest.js.map +1 -0
  105. package/dist/esm/core/tasks/helpers/isKnownToStatusApi.d.ts +21 -0
  106. package/dist/esm/core/tasks/helpers/isKnownToStatusApi.d.ts.map +1 -0
  107. package/dist/esm/core/tasks/helpers/isKnownToStatusApi.js +43 -0
  108. package/dist/esm/core/tasks/helpers/isKnownToStatusApi.js.map +1 -0
  109. package/dist/esm/core/tasks/helpers/waitForTransactionStatus.d.ts +22 -1
  110. package/dist/esm/core/tasks/helpers/waitForTransactionStatus.d.ts.map +1 -1
  111. package/dist/esm/core/tasks/helpers/waitForTransactionStatus.js +76 -18
  112. package/dist/esm/core/tasks/helpers/waitForTransactionStatus.js.map +1 -1
  113. package/dist/esm/core/transactionState.d.ts +121 -0
  114. package/dist/esm/core/transactionState.d.ts.map +1 -0
  115. package/dist/esm/core/transactionState.js +152 -0
  116. package/dist/esm/core/transactionState.js.map +1 -0
  117. package/dist/esm/errors/errors.d.ts +13 -2
  118. package/dist/esm/errors/errors.d.ts.map +1 -1
  119. package/dist/esm/errors/errors.js +5 -2
  120. package/dist/esm/errors/errors.js.map +1 -1
  121. package/dist/esm/index.d.ts +7 -3
  122. package/dist/esm/index.js +6 -2
  123. package/dist/esm/types/actions.d.ts.map +1 -1
  124. package/dist/esm/types/core.d.ts +49 -3
  125. package/dist/esm/types/core.d.ts.map +1 -1
  126. package/dist/esm/types/execution.d.ts +8 -0
  127. package/dist/esm/types/execution.d.ts.map +1 -1
  128. package/dist/esm/utils/abort.d.ts +6 -0
  129. package/dist/esm/utils/abort.d.ts.map +1 -0
  130. package/dist/esm/utils/abort.js +8 -0
  131. package/dist/esm/utils/abort.js.map +1 -0
  132. package/dist/esm/utils/checkPackageUpdates.js +1 -1
  133. package/dist/esm/utils/formatUnits.js +1 -0
  134. package/dist/esm/utils/formatUnits.js.map +1 -1
  135. package/dist/esm/utils/lru.d.ts +14 -0
  136. package/dist/esm/utils/lru.d.ts.map +1 -0
  137. package/dist/esm/utils/lru.js +34 -0
  138. package/dist/esm/utils/lru.js.map +1 -0
  139. package/dist/esm/utils/parseUnits.js +30 -16
  140. package/dist/esm/utils/parseUnits.js.map +1 -1
  141. package/dist/esm/utils/sleep.d.ts +7 -1
  142. package/dist/esm/utils/sleep.d.ts.map +1 -1
  143. package/dist/esm/utils/sleep.js +22 -3
  144. package/dist/esm/utils/sleep.js.map +1 -1
  145. package/dist/esm/utils/waitForResult.d.ts +7 -5
  146. package/dist/esm/utils/waitForResult.d.ts.map +1 -1
  147. package/dist/esm/utils/waitForResult.js +19 -14
  148. package/dist/esm/utils/waitForResult.js.map +1 -1
  149. package/dist/esm/utils/withDedupe.d.ts +0 -10
  150. package/dist/esm/utils/withDedupe.d.ts.map +1 -1
  151. package/dist/esm/utils/withDedupe.js +5 -22
  152. package/dist/esm/utils/withDedupe.js.map +1 -1
  153. package/dist/esm/utils/withTimeout.d.ts.map +1 -1
  154. package/dist/esm/utils/withTimeout.js +6 -2
  155. package/dist/esm/utils/withTimeout.js.map +1 -1
  156. package/dist/esm/version.d.ts +1 -1
  157. package/dist/esm/version.js +1 -1
  158. package/dist/esm/version.js.map +1 -1
  159. package/package.json +2 -2
  160. package/src/client/createClient.ts +12 -4
  161. package/src/client/findProvider.ts +21 -0
  162. package/src/core/BaseStepExecutor.ts +40 -6
  163. package/src/core/StatusManager.ts +211 -2
  164. package/src/core/execution.ts +69 -20
  165. package/src/core/executionState.ts +84 -1
  166. package/src/core/prepareRestart.ts +29 -13
  167. package/src/core/tasks/WaitForTransactionStatusTask.ts +10 -1
  168. package/src/core/tasks/helpers/checkBalance.ts +11 -3
  169. package/src/core/tasks/helpers/getStepStatusRequest.ts +20 -0
  170. package/src/core/tasks/helpers/isKnownToStatusApi.ts +57 -0
  171. package/src/core/tasks/helpers/waitForTransactionStatus.ts +128 -17
  172. package/src/core/transactionState.ts +194 -0
  173. package/src/errors/errors.ts +21 -2
  174. package/src/index.ts +16 -1
  175. package/src/types/core.ts +50 -3
  176. package/src/types/execution.ts +8 -0
  177. package/src/utils/abort.ts +10 -0
  178. package/src/utils/formatUnits.ts +6 -0
  179. package/src/utils/lru.ts +38 -0
  180. package/src/utils/parseUnits.ts +53 -20
  181. package/src/utils/sleep.ts +27 -3
  182. package/src/utils/waitForResult.ts +20 -10
  183. package/src/utils/withDedupe.ts +4 -28
  184. package/src/utils/withTimeout.ts +7 -2
  185. package/src/version.ts +1 -1
@@ -2,6 +2,27 @@ import { ExecutionActionType, SDKClient } from "../../../types/core.js";
2
2
  import { StatusManager } from "../../StatusManager.js";
3
3
  import { LiFiStep, StatusResponse } from "@lifi/types";
4
4
  //#region src/core/tasks/helpers/waitForTransactionStatus.d.ts
5
- export declare function waitForTransactionStatus(client: SDKClient, statusManager: StatusManager, txHash: string, step: LiFiStep, actionType: ExecutionActionType, interval?: number): Promise<StatusResponse>;
5
+ type Waiter = {
6
+ resolve: (status: StatusResponse) => void;
7
+ reject: (error: unknown) => void;
8
+ };
9
+ /** The `/status` poll of one transaction hash, shared by all its callers. */
10
+ type StatusPoll = {
11
+ promise: Promise<StatusResponse>;
12
+ controller: AbortController;
13
+ /** Callers with a signal that still wait, once the first one joined. */
14
+ waiters?: Set<Waiter>;
15
+ /** A caller without a signal joined, so the poll runs until it settles. */
16
+ pinned: boolean;
17
+ };
18
+ /** @internal The running poll per transaction hash. Exported for tests. */
19
+ export declare const TRANSACTION_HASH_OBSERVERS: Partial<Record<string, StatusPoll>>;
20
+ /**
21
+ * Waits for the final status of `txHash`. Callers that wait for the same hash
22
+ * share one poll. A caller whose `signal` aborts leaves at once with the abort
23
+ * reason; the poll itself ends only when every caller with a signal has left
24
+ * and no caller without a signal joined it.
25
+ */
26
+ export declare function waitForTransactionStatus(client: SDKClient, statusManager: StatusManager, txHash: string, step: LiFiStep, actionType: ExecutionActionType, interval?: number, signal?: AbortSignal): Promise<StatusResponse>;
6
27
  //#endregion
7
28
  //# sourceMappingURL=waitForTransactionStatus.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"waitForTransactionStatus.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/waitForTransactionStatus.ts"],"mappings":";;;;wBAUsB,yBACpB,QAAQ,WACR,eAAe,eACf,gBACA,MAAM,UACN,YAAY,qBACZ,oBACC,QAAQ"}
1
+ {"version":3,"file":"waitForTransactionStatus.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/waitForTransactionStatus.ts"],"mappings":";;;;KAUK;EACH,UAAU,QAAQ;EAClB,SAAS;;;KAIN;EACH,SAAS,QAAQ;EACjB,YAAY;;EAEZ,UAAU,IAAI;;EAEd;;;qBAIW,4BAA4B,QAAQ,eAAe;;;;;;;wBAS1C,yBACpB,QAAQ,WACR,eAAe,eACf,gBACA,MAAM,UACN,YAAY,qBACZ,mBACA,SAAS,cACR,QAAQ"}
@@ -1,19 +1,22 @@
1
1
  import { ServerError } from "../../../errors/errors.js";
2
+ import { getAbortError } from "../../../utils/abort.js";
2
3
  import { getStatus } from "../../../actions/getStatus.js";
3
4
  import { getSubstatusMessage } from "../../actionMessages.js";
5
+ import { getStepStatusRequest } from "./getStepStatusRequest.js";
4
6
  import { waitForResult } from "../../../utils/waitForResult.js";
5
7
  //#region src/core/tasks/helpers/waitForTransactionStatus.ts
8
+ /** @internal The running poll per transaction hash. Exported for tests. */
6
9
  const TRANSACTION_HASH_OBSERVERS = {};
7
- async function waitForTransactionStatus(client, statusManager, txHash, step, actionType, interval = 5e3) {
8
- const _getStatus = () => {
9
- return getStatus(client, {
10
- fromChain: step.action.fromChainId,
11
- fromAddress: step.action.fromAddress,
12
- toChain: step.action.toChainId,
13
- txHash,
14
- ...step.tool !== "custom" && { bridge: step.tool },
15
- ...step.transactionId && { transactionId: step.transactionId }
16
- }).then((statusResponse) => {
10
+ /**
11
+ * Waits for the final status of `txHash`. Callers that wait for the same hash
12
+ * share one poll. A caller whose `signal` aborts leaves at once with the abort
13
+ * reason; the poll itself ends only when every caller with a signal has left
14
+ * and no caller without a signal joined it.
15
+ */
16
+ async function waitForTransactionStatus(client, statusManager, txHash, step, actionType, interval = 5e3, signal) {
17
+ if (signal?.aborted) throw getAbortError(signal);
18
+ const _getStatus = (pollSignal) => {
19
+ return getStatus(client, getStepStatusRequest(step, txHash), { signal: pollSignal }).then((statusResponse) => {
17
20
  switch (statusResponse.status) {
18
21
  case "DONE": return statusResponse;
19
22
  case "PENDING": {
@@ -32,18 +35,73 @@ async function waitForTransactionStatus(client, statusManager, txHash, step, act
32
35
  if (process.env.NODE_ENV === "development") console.debug("Fetching status from backend failed.", e);
33
36
  });
34
37
  };
35
- let status = TRANSACTION_HASH_OBSERVERS[txHash];
36
- if (!status) {
37
- status = waitForResult(_getStatus, interval).finally(() => {
38
- delete TRANSACTION_HASH_OBSERVERS[txHash];
39
- });
40
- TRANSACTION_HASH_OBSERVERS[txHash] = status;
38
+ let poll = TRANSACTION_HASH_OBSERVERS[txHash];
39
+ if (!poll) {
40
+ const controller = new AbortController();
41
+ const promise = waitForResult(() => _getStatus(controller.signal), interval, void 0, void 0, controller.signal).finally(() => removePoll(txHash, promise));
42
+ poll = {
43
+ promise,
44
+ controller,
45
+ pinned: false
46
+ };
47
+ TRANSACTION_HASH_OBSERVERS[txHash] = poll;
41
48
  }
42
- const resolvedStatus = await status;
49
+ const resolvedStatus = await joinPoll(txHash, poll, signal);
43
50
  if (!("receiving" in resolvedStatus)) throw new ServerError("Status doesn't contain destination chain information.");
44
51
  return resolvedStatus;
45
52
  }
53
+ function joinPoll(txHash, poll, signal) {
54
+ if (!signal) {
55
+ poll.pinned = true;
56
+ return poll.promise;
57
+ }
58
+ const waiters = poll.waiters ?? subscribe(poll);
59
+ return new Promise((resolve, reject) => {
60
+ const waiter = {
61
+ resolve: (status) => {
62
+ signal.removeEventListener("abort", leave);
63
+ resolve(status);
64
+ },
65
+ reject: (error) => {
66
+ signal.removeEventListener("abort", leave);
67
+ reject(error);
68
+ }
69
+ };
70
+ const leave = () => {
71
+ signal.removeEventListener("abort", leave);
72
+ waiters.delete(waiter);
73
+ const reason = getAbortError(signal);
74
+ reject(reason);
75
+ if (!poll.pinned && waiters.size === 0) {
76
+ removePoll(txHash, poll.promise);
77
+ poll.controller.abort(reason);
78
+ }
79
+ };
80
+ waiters.add(waiter);
81
+ signal.addEventListener("abort", leave, { once: true });
82
+ if (signal.aborted) leave();
83
+ });
84
+ }
85
+ /**
86
+ * Hands the result to the callers with a signal, through one reaction per
87
+ * poll, so a caller that leaves holds nothing here. It also handles the
88
+ * rejection of a poll that every caller left.
89
+ */
90
+ function subscribe(poll) {
91
+ const waiters = /* @__PURE__ */ new Set();
92
+ poll.waiters = waiters;
93
+ poll.promise.then((status) => {
94
+ for (const waiter of waiters) waiter.resolve(status);
95
+ }, (error) => {
96
+ for (const waiter of waiters) waiter.reject(error);
97
+ });
98
+ return waiters;
99
+ }
100
+ /** Drops the entry for `txHash` only while it still holds this poll. */
101
+ function removePoll(txHash, promise) {
102
+ if (TRANSACTION_HASH_OBSERVERS[txHash]?.promise === promise) delete TRANSACTION_HASH_OBSERVERS[txHash];
103
+ }
46
104
  //#endregion
47
- export { waitForTransactionStatus };
105
+ export { TRANSACTION_HASH_OBSERVERS, waitForTransactionStatus };
48
106
 
49
107
  //# sourceMappingURL=waitForTransactionStatus.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"waitForTransactionStatus.js","names":[],"sources":["../../../../../src/core/tasks/helpers/waitForTransactionStatus.ts"],"sourcesContent":["import type { FullStatusData, LiFiStep, StatusResponse } from '@lifi/types'\nimport { getStatus } from '../../../actions/getStatus.js'\nimport { ServerError } from '../../../errors/errors.js'\nimport type { ExecutionActionType, SDKClient } from '../../../types/core.js'\nimport { waitForResult } from '../../../utils/waitForResult.js'\nimport { getSubstatusMessage } from '../../actionMessages.js'\nimport type { StatusManager } from '../../StatusManager.js'\n\nconst TRANSACTION_HASH_OBSERVERS: Record<string, Promise<StatusResponse>> = {}\n\nexport async function waitForTransactionStatus(\n client: SDKClient,\n statusManager: StatusManager,\n txHash: string,\n step: LiFiStep,\n actionType: ExecutionActionType,\n interval = 5_000\n): Promise<StatusResponse> {\n const _getStatus = (): Promise<StatusResponse | undefined> => {\n return getStatus(client, {\n fromChain: step.action.fromChainId,\n fromAddress: step.action.fromAddress,\n toChain: step.action.toChainId,\n txHash,\n ...(step.tool !== 'custom' && { bridge: step.tool }),\n ...(step.transactionId && { transactionId: step.transactionId }),\n })\n .then((statusResponse) => {\n switch (statusResponse.status) {\n case 'DONE':\n return statusResponse\n case 'PENDING': {\n const pendingStatus = statusResponse as FullStatusData\n statusManager?.updateAction(step, actionType, 'PENDING', {\n substatus: statusResponse.substatus,\n substatusMessage:\n statusResponse.substatusMessage ||\n getSubstatusMessage(\n statusResponse.status,\n statusResponse.substatus\n ),\n // Most bridges implement no `getExplorerLink`, so fall back to\n // the LI.FI explorer rather than leave the user with no link.\n txLink:\n pendingStatus.bridgeExplorerLink ??\n pendingStatus.lifiExplorerLink,\n })\n return undefined\n }\n case 'NOT_FOUND':\n return undefined\n default:\n return Promise.reject()\n }\n })\n .catch((e) => {\n if (process.env.NODE_ENV === 'development') {\n console.debug('Fetching status from backend failed.', e)\n }\n return undefined\n })\n }\n\n let status = TRANSACTION_HASH_OBSERVERS[txHash]\n\n if (!status) {\n status = waitForResult(_getStatus, interval).finally(() => {\n delete TRANSACTION_HASH_OBSERVERS[txHash]\n })\n TRANSACTION_HASH_OBSERVERS[txHash] = status\n }\n\n const resolvedStatus = await status\n\n if (!('receiving' in resolvedStatus)) {\n throw new ServerError(\n \"Status doesn't contain destination chain information.\"\n )\n }\n\n return resolvedStatus\n}\n"],"mappings":";;;;;AAQA,MAAM,6BAAsE,CAAC;AAE7E,eAAsB,yBACpB,QACA,eACA,QACA,MACA,YACA,WAAW,KACc;CACzB,MAAM,mBAAwD;EAC5D,OAAO,UAAU,QAAQ;GACvB,WAAW,KAAK,OAAO;GACvB,aAAa,KAAK,OAAO;GACzB,SAAS,KAAK,OAAO;GACrB;GACA,GAAI,KAAK,SAAS,YAAY,EAAE,QAAQ,KAAK,KAAK;GAClD,GAAI,KAAK,iBAAiB,EAAE,eAAe,KAAK,cAAc;EAChE,CAAC,CAAC,CACC,MAAM,mBAAmB;GACxB,QAAQ,eAAe,QAAvB;IACE,KAAK,QACH,OAAO;IACT,KAAK,WAAW;KACd,MAAM,gBAAgB;KACtB,eAAe,aAAa,MAAM,YAAY,WAAW;MACvD,WAAW,eAAe;MAC1B,kBACE,eAAe,oBACf,oBACE,eAAe,QACf,eAAe,SACjB;MAGF,QACE,cAAc,sBACd,cAAc;KAClB,CAAC;KACD;IACF;IACA,KAAK,aACH;IACF,SACE,OAAO,QAAQ,OAAO;GAC1B;EACF,CAAC,CAAC,CACD,OAAO,MAAM;GACZ,IAAI,QAAQ,IAAI,aAAa,eAC3B,QAAQ,MAAM,wCAAwC,CAAC;EAG3D,CAAC;CACL;CAEA,IAAI,SAAS,2BAA2B;CAExC,IAAI,CAAC,QAAQ;EACX,SAAS,cAAc,YAAY,QAAQ,CAAC,CAAC,cAAc;GACzD,OAAO,2BAA2B;EACpC,CAAC;EACD,2BAA2B,UAAU;CACvC;CAEA,MAAM,iBAAiB,MAAM;CAE7B,IAAI,EAAE,eAAe,iBACnB,MAAM,IAAI,YACR,uDACF;CAGF,OAAO;AACT"}
1
+ {"version":3,"file":"waitForTransactionStatus.js","names":[],"sources":["../../../../../src/core/tasks/helpers/waitForTransactionStatus.ts"],"sourcesContent":["import type { FullStatusData, LiFiStep, StatusResponse } from '@lifi/types'\nimport { getStatus } from '../../../actions/getStatus.js'\nimport { ServerError } from '../../../errors/errors.js'\nimport type { ExecutionActionType, SDKClient } from '../../../types/core.js'\nimport { getAbortError } from '../../../utils/abort.js'\nimport { waitForResult } from '../../../utils/waitForResult.js'\nimport { getSubstatusMessage } from '../../actionMessages.js'\nimport type { StatusManager } from '../../StatusManager.js'\nimport { getStepStatusRequest } from './getStepStatusRequest.js'\n\ntype Waiter = {\n resolve: (status: StatusResponse) => void\n reject: (error: unknown) => void\n}\n\n/** The `/status` poll of one transaction hash, shared by all its callers. */\ntype StatusPoll = {\n promise: Promise<StatusResponse>\n controller: AbortController\n /** Callers with a signal that still wait, once the first one joined. */\n waiters?: Set<Waiter>\n /** A caller without a signal joined, so the poll runs until it settles. */\n pinned: boolean\n}\n\n/** @internal The running poll per transaction hash. Exported for tests. */\nexport const TRANSACTION_HASH_OBSERVERS: Partial<Record<string, StatusPoll>> =\n {}\n\n/**\n * Waits for the final status of `txHash`. Callers that wait for the same hash\n * share one poll. A caller whose `signal` aborts leaves at once with the abort\n * reason; the poll itself ends only when every caller with a signal has left\n * and no caller without a signal joined it.\n */\nexport async function waitForTransactionStatus(\n client: SDKClient,\n statusManager: StatusManager,\n txHash: string,\n step: LiFiStep,\n actionType: ExecutionActionType,\n interval = 5_000,\n signal?: AbortSignal\n): Promise<StatusResponse> {\n if (signal?.aborted) {\n throw getAbortError(signal)\n }\n\n const _getStatus = (\n pollSignal: AbortSignal\n ): Promise<StatusResponse | undefined> => {\n return getStatus(client, getStepStatusRequest(step, txHash), {\n signal: pollSignal,\n })\n .then((statusResponse) => {\n switch (statusResponse.status) {\n case 'DONE':\n return statusResponse\n case 'PENDING': {\n const pendingStatus = statusResponse as FullStatusData\n statusManager?.updateAction(step, actionType, 'PENDING', {\n substatus: statusResponse.substatus,\n substatusMessage:\n statusResponse.substatusMessage ||\n getSubstatusMessage(\n statusResponse.status,\n statusResponse.substatus\n ),\n // Most bridges implement no `getExplorerLink`, so fall back to\n // the LI.FI explorer rather than leave the user with no link.\n txLink:\n pendingStatus.bridgeExplorerLink ??\n pendingStatus.lifiExplorerLink,\n })\n return undefined\n }\n case 'NOT_FOUND':\n return undefined\n default:\n return Promise.reject()\n }\n })\n .catch((e) => {\n if (process.env.NODE_ENV === 'development') {\n console.debug('Fetching status from backend failed.', e)\n }\n return undefined\n })\n }\n\n let poll = TRANSACTION_HASH_OBSERVERS[txHash]\n\n if (!poll) {\n const controller = new AbortController()\n const promise: Promise<StatusResponse> = waitForResult(\n () => _getStatus(controller.signal),\n interval,\n undefined,\n undefined,\n controller.signal\n ).finally(() => removePoll(txHash, promise))\n poll = { promise, controller, pinned: false }\n TRANSACTION_HASH_OBSERVERS[txHash] = poll\n }\n\n const resolvedStatus = await joinPoll(txHash, poll, signal)\n\n if (!('receiving' in resolvedStatus)) {\n throw new ServerError(\n \"Status doesn't contain destination chain information.\"\n )\n }\n\n return resolvedStatus\n}\n\nfunction joinPoll(\n txHash: string,\n poll: StatusPoll,\n signal: AbortSignal | undefined\n): Promise<StatusResponse> {\n if (!signal) {\n poll.pinned = true\n return poll.promise\n }\n const waiters = poll.waiters ?? subscribe(poll)\n return new Promise<StatusResponse>((resolve, reject) => {\n // Stop listening before settling, so a later abort cannot reach the poll.\n const waiter: Waiter = {\n resolve: (status) => {\n signal.removeEventListener('abort', leave)\n resolve(status)\n },\n reject: (error) => {\n signal.removeEventListener('abort', leave)\n reject(error)\n },\n }\n const leave = (): void => {\n // `leave` can run without the event, so the listener is not always gone.\n signal.removeEventListener('abort', leave)\n waiters.delete(waiter)\n const reason = getAbortError(signal)\n reject(reason)\n if (!poll.pinned && waiters.size === 0) {\n // A caller arriving now must start a new poll, not join this one.\n removePoll(txHash, poll.promise)\n poll.controller.abort(reason)\n }\n }\n waiters.add(waiter)\n signal.addEventListener('abort', leave, { once: true })\n // Defensive; this branch does not run today. The check at the top of\n // `waitForTransactionStatus` throws for an aborted signal, and no await\n // runs between that check and this one. An aborted signal fires no more\n // abort event, so without the branch a caller that joins with an aborted\n // signal would not leave: it would wait, and keep the poll running,\n // until the poll settles.\n if (signal.aborted) {\n leave()\n }\n })\n}\n\n/**\n * Hands the result to the callers with a signal, through one reaction per\n * poll, so a caller that leaves holds nothing here. It also handles the\n * rejection of a poll that every caller left.\n */\nfunction subscribe(poll: StatusPoll): Set<Waiter> {\n const waiters = new Set<Waiter>()\n poll.waiters = waiters\n poll.promise.then(\n (status) => {\n for (const waiter of waiters) {\n waiter.resolve(status)\n }\n },\n (error: unknown) => {\n for (const waiter of waiters) {\n waiter.reject(error)\n }\n }\n )\n return waiters\n}\n\n/** Drops the entry for `txHash` only while it still holds this poll. */\nfunction removePoll(txHash: string, promise: Promise<StatusResponse>): void {\n if (TRANSACTION_HASH_OBSERVERS[txHash]?.promise === promise) {\n delete TRANSACTION_HASH_OBSERVERS[txHash]\n }\n}\n"],"mappings":";;;;;;;;AA0BA,MAAa,6BACX,CAAC;;;;;;;AAQH,eAAsB,yBACpB,QACA,eACA,QACA,MACA,YACA,WAAW,KACX,QACyB;CACzB,IAAI,QAAQ,SACV,MAAM,cAAc,MAAM;CAG5B,MAAM,cACJ,eACwC;EACxC,OAAO,UAAU,QAAQ,qBAAqB,MAAM,MAAM,GAAG,EAC3D,QAAQ,WACV,CAAC,CAAC,CACC,MAAM,mBAAmB;GACxB,QAAQ,eAAe,QAAvB;IACE,KAAK,QACH,OAAO;IACT,KAAK,WAAW;KACd,MAAM,gBAAgB;KACtB,eAAe,aAAa,MAAM,YAAY,WAAW;MACvD,WAAW,eAAe;MAC1B,kBACE,eAAe,oBACf,oBACE,eAAe,QACf,eAAe,SACjB;MAGF,QACE,cAAc,sBACd,cAAc;KAClB,CAAC;KACD;IACF;IACA,KAAK,aACH;IACF,SACE,OAAO,QAAQ,OAAO;GAC1B;EACF,CAAC,CAAC,CACD,OAAO,MAAM;GACZ,IAAI,QAAQ,IAAI,aAAa,eAC3B,QAAQ,MAAM,wCAAwC,CAAC;EAG3D,CAAC;CACL;CAEA,IAAI,OAAO,2BAA2B;CAEtC,IAAI,CAAC,MAAM;EACT,MAAM,aAAa,IAAI,gBAAgB;EACvC,MAAM,UAAmC,oBACjC,WAAW,WAAW,MAAM,GAClC,UACA,KAAA,GACA,KAAA,GACA,WAAW,MACb,CAAC,CAAC,cAAc,WAAW,QAAQ,OAAO,CAAC;EAC3C,OAAO;GAAE;GAAS;GAAY,QAAQ;EAAM;EAC5C,2BAA2B,UAAU;CACvC;CAEA,MAAM,iBAAiB,MAAM,SAAS,QAAQ,MAAM,MAAM;CAE1D,IAAI,EAAE,eAAe,iBACnB,MAAM,IAAI,YACR,uDACF;CAGF,OAAO;AACT;AAEA,SAAS,SACP,QACA,MACA,QACyB;CACzB,IAAI,CAAC,QAAQ;EACX,KAAK,SAAS;EACd,OAAO,KAAK;CACd;CACA,MAAM,UAAU,KAAK,WAAW,UAAU,IAAI;CAC9C,OAAO,IAAI,SAAyB,SAAS,WAAW;EAEtD,MAAM,SAAiB;GACrB,UAAU,WAAW;IACnB,OAAO,oBAAoB,SAAS,KAAK;IACzC,QAAQ,MAAM;GAChB;GACA,SAAS,UAAU;IACjB,OAAO,oBAAoB,SAAS,KAAK;IACzC,OAAO,KAAK;GACd;EACF;EACA,MAAM,cAAoB;GAExB,OAAO,oBAAoB,SAAS,KAAK;GACzC,QAAQ,OAAO,MAAM;GACrB,MAAM,SAAS,cAAc,MAAM;GACnC,OAAO,MAAM;GACb,IAAI,CAAC,KAAK,UAAU,QAAQ,SAAS,GAAG;IAEtC,WAAW,QAAQ,KAAK,OAAO;IAC/B,KAAK,WAAW,MAAM,MAAM;GAC9B;EACF;EACA,QAAQ,IAAI,MAAM;EAClB,OAAO,iBAAiB,SAAS,OAAO,EAAE,MAAM,KAAK,CAAC;EAOtD,IAAI,OAAO,SACT,MAAM;CAEV,CAAC;AACH;;;;;;AAOA,SAAS,UAAU,MAA+B;CAChD,MAAM,0BAAU,IAAI,IAAY;CAChC,KAAK,UAAU;CACf,KAAK,QAAQ,MACV,WAAW;EACV,KAAK,MAAM,UAAU,SACnB,OAAO,QAAQ,MAAM;CAEzB,IACC,UAAmB;EAClB,KAAK,MAAM,UAAU,SACnB,OAAO,OAAO,KAAK;CAEvB,CACF;CACA,OAAO;AACT;;AAGA,SAAS,WAAW,QAAgB,SAAwC;CAC1E,IAAI,2BAA2B,OAAO,EAAE,YAAY,SAClD,OAAO,2BAA2B;AAEtC"}
@@ -0,0 +1,121 @@
1
+ import { ExecutionAction, ExecutionActionType, LiFiStepExtended } from "../types/core.js";
2
+ import { TransactionError } from "../errors/errors.js";
3
+ //#region src/core/transactionState.d.ts
4
+ /**
5
+ * Action types that carry the step's own transaction.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare const TRANSACTION_ACTION_TYPES: readonly ExecutionActionType[];
10
+ /**
11
+ * Stored bytes on a chain without its own expiry (Sui, Solana with a durable
12
+ * nonce, Bitcoin) are resent only this long after signing. Past it, a page
13
+ * load could otherwise execute a swap on a quote the user no longer expects.
14
+ *
15
+ * @internal
16
+ */
17
+ export declare const MAX_RESEND_AGE_MS = 12e4;
18
+ /**
19
+ * Without an expiry verdict, a signature younger than this is never declared
20
+ * dropped. Solana blockhashes and Tron transactions expire well before it.
21
+ *
22
+ * @internal
23
+ */
24
+ export declare const DROPPED_FALLBACK_AGE_MS = 3e5;
25
+ /**
26
+ * Subtracted from `execution.signedAt` (the device clock) when it anchors a
27
+ * history-coverage check, so a device clock that runs fast cannot make a node
28
+ * look like it covers the signing time when it does not.
29
+ *
30
+ * @internal
31
+ */
32
+ export declare const CLOCK_SKEW_MARGIN_MS = 6e5;
33
+ /**
34
+ * Fields a sign task clears before it writes a new transaction's data, and
35
+ * that re-initializing a final-failed action clears. `taskId` is included: a
36
+ * stale relayed or batched task id would otherwise keep the action open.
37
+ *
38
+ * @internal
39
+ */
40
+ export declare const CLEARED_TRANSACTION_FIELDS: Readonly<Pick<ExecutionAction, "txHash" | "txLink" | "txHex" | "txFinal" | "taskId">>;
41
+ /**
42
+ * True when the action has a transaction to follow, landed or not: a hash, a
43
+ * task id or stored signed bytes, unless the action FAILED with a final
44
+ * outcome. Every resume decision uses this one predicate, so the pipeline
45
+ * selector and the pre-sign guard can never disagree.
46
+ *
47
+ * Resume rules for providers. A step never signs or sends a second
48
+ * transaction while an earlier one can still land:
49
+ * 1. Pick the first task with this predicate: open and DONE, the status
50
+ * wait; open, the provider's wait task; otherwise the first task.
51
+ * 2. In the sign task, call `assertNoOpenTransaction` at the start, right
52
+ * before each wallet call and, where the SDK sends, right after the
53
+ * wallet returns. Write the new data with `CLEARED_TRANSACTION_FIELDS`
54
+ * and `signedAt`.
55
+ * 3. From the last check, nothing awaits until the send or, where the SDK
56
+ * sends signed bytes, until they are stored as `txHex`, before the first
57
+ * send. Clear `txHex` only when the outcome is known, no node can still
58
+ * hold the bytes, or they no longer decode.
59
+ * 4. A resume never signs. It looks the transaction up and resends the
60
+ * stored bytes only while `isResendAllowed` (or the chain's own expiry)
61
+ * allows it; otherwise it only waits.
62
+ * 5. Mark an error final only on a verdict about the transaction: failed
63
+ * or reverted (on chain or at the relayer), cancelled, replaced, or
64
+ * dropped with proof. Dropped needs all three: the transaction can no
65
+ * longer land, a node that covers its window reports it absent (in the
66
+ * same response where the chain allows it), and `isKnownToStatusApi` is
67
+ * false. In doubt, throw without the marker and keep the fields.
68
+ * 6. Give `context.signal` only to waits that start after the broadcast. On
69
+ * abort, return `PAUSED` and write nothing.
70
+ */
71
+ export declare function hasOpenTransaction(action?: ExecutionAction): boolean;
72
+ /**
73
+ * True when any SWAP / CROSS_CHAIN action of the step has an open transaction.
74
+ *
75
+ * @internal
76
+ */
77
+ export declare function hasStepOpenTransaction(step: LiFiStepExtended): boolean;
78
+ /**
79
+ * Walks the error and its `cause` chain. Parsers may rebuild errors, so the
80
+ * marker is read from the original error. A property check instead of
81
+ * `instanceof` keeps it working across duplicated installs.
82
+ *
83
+ * @internal
84
+ */
85
+ export declare function isFinalTransactionError(error: unknown): boolean;
86
+ /**
87
+ * The error of a step that would sign a second transaction while its first
88
+ * one may still land.
89
+ *
90
+ * @internal
91
+ */
92
+ export declare function transactionConflictError(): TransactionError;
93
+ /**
94
+ * Called first in every sign task. With correct pipeline selectors it never
95
+ * throws; it stops a second signature if a selector ever routes an open
96
+ * transaction back to signing. Every sign task calls it again on the freshly
97
+ * found action right before its wallet call: a late write of an older run can
98
+ * merge a transaction into the action during the awaits in between. A sign
99
+ * task that sends the transaction itself calls it once more after the wallet
100
+ * returns, before it writes or sends anything: the merge can also land while
101
+ * the prompt is open.
102
+ *
103
+ * @internal
104
+ */
105
+ export declare function assertNoOpenTransaction(action?: ExecutionAction): void;
106
+ /**
107
+ * Unknown signing time never allows a resend. Nor does a signing time in the
108
+ * future: a device clock that ran ahead at signing and was corrected later
109
+ * would otherwise stretch the cap by the clock error.
110
+ *
111
+ * @internal
112
+ */
113
+ export declare function isResendAllowed(signedAt: number | undefined, now?: number): boolean;
114
+ /**
115
+ * Unknown signing time never allows a drop.
116
+ *
117
+ * @internal
118
+ */
119
+ export declare function isOldEnoughToDrop(signedAt: number | undefined, now?: number): boolean;
120
+ //#endregion
121
+ //# sourceMappingURL=transactionState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactionState.d.ts","names":[],"sources":["../../../src/core/transactionState.ts"],"mappings":";;;;;;;;qBAaa,mCAAmC;;;;;;;;qBAYnC;;;;;;;qBAQA;;;;;;;;qBASA;;;;;;;;qBASA,4BAA4B,SACvC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAuCS,mBAAmB,SAAS;;;;;;wBAe5B,uBAAuB,MAAM;;;;;;;;wBAe7B,wBAAwB;;;;;;;wBAmBxB,4BAA4B;;;;;;;;;;;;;wBAmB5B,wBAAwB,SAAS;;;;;;;;wBAajC,gBACd,8BACA;;;;;;wBAcc,kBACd,8BACA"}
@@ -0,0 +1,152 @@
1
+ import "../errors/constants.js";
2
+ import { TransactionError } from "../errors/errors.js";
3
+ //#region src/core/transactionState.ts
4
+ /**
5
+ * Action types that carry the step's own transaction.
6
+ *
7
+ * @internal
8
+ */
9
+ const TRANSACTION_ACTION_TYPES = ["SWAP", "CROSS_CHAIN"];
10
+ /**
11
+ * Stored bytes on a chain without its own expiry (Sui, Solana with a durable
12
+ * nonce, Bitcoin) are resent only this long after signing. Past it, a page
13
+ * load could otherwise execute a swap on a quote the user no longer expects.
14
+ *
15
+ * @internal
16
+ */
17
+ const MAX_RESEND_AGE_MS = 12e4;
18
+ /**
19
+ * Without an expiry verdict, a signature younger than this is never declared
20
+ * dropped. Solana blockhashes and Tron transactions expire well before it.
21
+ *
22
+ * @internal
23
+ */
24
+ const DROPPED_FALLBACK_AGE_MS = 3e5;
25
+ /**
26
+ * Subtracted from `execution.signedAt` (the device clock) when it anchors a
27
+ * history-coverage check, so a device clock that runs fast cannot make a node
28
+ * look like it covers the signing time when it does not.
29
+ *
30
+ * @internal
31
+ */
32
+ const CLOCK_SKEW_MARGIN_MS = 6e5;
33
+ /**
34
+ * Fields a sign task clears before it writes a new transaction's data, and
35
+ * that re-initializing a final-failed action clears. `taskId` is included: a
36
+ * stale relayed or batched task id would otherwise keep the action open.
37
+ *
38
+ * @internal
39
+ */
40
+ const CLEARED_TRANSACTION_FIELDS = Object.freeze({
41
+ txHash: void 0,
42
+ txLink: void 0,
43
+ txHex: void 0,
44
+ txFinal: void 0,
45
+ taskId: void 0
46
+ });
47
+ /**
48
+ * True when the action has a transaction to follow, landed or not: a hash, a
49
+ * task id or stored signed bytes, unless the action FAILED with a final
50
+ * outcome. Every resume decision uses this one predicate, so the pipeline
51
+ * selector and the pre-sign guard can never disagree.
52
+ *
53
+ * Resume rules for providers. A step never signs or sends a second
54
+ * transaction while an earlier one can still land:
55
+ * 1. Pick the first task with this predicate: open and DONE, the status
56
+ * wait; open, the provider's wait task; otherwise the first task.
57
+ * 2. In the sign task, call `assertNoOpenTransaction` at the start, right
58
+ * before each wallet call and, where the SDK sends, right after the
59
+ * wallet returns. Write the new data with `CLEARED_TRANSACTION_FIELDS`
60
+ * and `signedAt`.
61
+ * 3. From the last check, nothing awaits until the send or, where the SDK
62
+ * sends signed bytes, until they are stored as `txHex`, before the first
63
+ * send. Clear `txHex` only when the outcome is known, no node can still
64
+ * hold the bytes, or they no longer decode.
65
+ * 4. A resume never signs. It looks the transaction up and resends the
66
+ * stored bytes only while `isResendAllowed` (or the chain's own expiry)
67
+ * allows it; otherwise it only waits.
68
+ * 5. Mark an error final only on a verdict about the transaction: failed
69
+ * or reverted (on chain or at the relayer), cancelled, replaced, or
70
+ * dropped with proof. Dropped needs all three: the transaction can no
71
+ * longer land, a node that covers its window reports it absent (in the
72
+ * same response where the chain allows it), and `isKnownToStatusApi` is
73
+ * false. In doubt, throw without the marker and keep the fields.
74
+ * 6. Give `context.signal` only to waits that start after the broadcast. On
75
+ * abort, return `PAUSED` and write nothing.
76
+ */
77
+ function hasOpenTransaction(action) {
78
+ if (!action) return false;
79
+ if (!(action.txHash || action.taskId || action.txHex)) return false;
80
+ return !(action.status === "FAILED" && action.txFinal === true);
81
+ }
82
+ /**
83
+ * True when any SWAP / CROSS_CHAIN action of the step has an open transaction.
84
+ *
85
+ * @internal
86
+ */
87
+ function hasStepOpenTransaction(step) {
88
+ return !!step.execution?.actions?.some((action) => TRANSACTION_ACTION_TYPES.includes(action.type) && hasOpenTransaction(action));
89
+ }
90
+ /**
91
+ * Walks the error and its `cause` chain. Parsers may rebuild errors, so the
92
+ * marker is read from the original error. A property check instead of
93
+ * `instanceof` keeps it working across duplicated installs.
94
+ *
95
+ * @internal
96
+ */
97
+ function isFinalTransactionError(error) {
98
+ const seen = /* @__PURE__ */ new Set();
99
+ let current = error;
100
+ while (current && typeof current === "object" && !seen.has(current)) {
101
+ seen.add(current);
102
+ if (current.final === true) return true;
103
+ current = current.cause;
104
+ }
105
+ return false;
106
+ }
107
+ /**
108
+ * The error of a step that would sign a second transaction while its first
109
+ * one may still land.
110
+ *
111
+ * @internal
112
+ */
113
+ function transactionConflictError() {
114
+ return new TransactionError(1020, "A transaction for this step was already signed and may still land. Resume the route to wait for it instead of signing a new one.");
115
+ }
116
+ /**
117
+ * Called first in every sign task. With correct pipeline selectors it never
118
+ * throws; it stops a second signature if a selector ever routes an open
119
+ * transaction back to signing. Every sign task calls it again on the freshly
120
+ * found action right before its wallet call: a late write of an older run can
121
+ * merge a transaction into the action during the awaits in between. A sign
122
+ * task that sends the transaction itself calls it once more after the wallet
123
+ * returns, before it writes or sends anything: the merge can also land while
124
+ * the prompt is open.
125
+ *
126
+ * @internal
127
+ */
128
+ function assertNoOpenTransaction(action) {
129
+ if (hasOpenTransaction(action)) throw transactionConflictError();
130
+ }
131
+ /**
132
+ * Unknown signing time never allows a resend. Nor does a signing time in the
133
+ * future: a device clock that ran ahead at signing and was corrected later
134
+ * would otherwise stretch the cap by the clock error.
135
+ *
136
+ * @internal
137
+ */
138
+ function isResendAllowed(signedAt, now = Date.now()) {
139
+ return signedAt !== void 0 && now >= signedAt && now - signedAt < 12e4;
140
+ }
141
+ /**
142
+ * Unknown signing time never allows a drop.
143
+ *
144
+ * @internal
145
+ */
146
+ function isOldEnoughToDrop(signedAt, now = Date.now()) {
147
+ return signedAt !== void 0 && now - signedAt > 3e5;
148
+ }
149
+ //#endregion
150
+ export { CLEARED_TRANSACTION_FIELDS, CLOCK_SKEW_MARGIN_MS, DROPPED_FALLBACK_AGE_MS, MAX_RESEND_AGE_MS, TRANSACTION_ACTION_TYPES, assertNoOpenTransaction, hasOpenTransaction, hasStepOpenTransaction, isFinalTransactionError, isOldEnoughToDrop, isResendAllowed, transactionConflictError };
151
+
152
+ //# sourceMappingURL=transactionState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactionState.js","names":[],"sources":["../../../src/core/transactionState.ts"],"sourcesContent":["import { LiFiErrorCode } from '../errors/constants.js'\nimport { TransactionError } from '../errors/errors.js'\nimport type {\n ExecutionAction,\n ExecutionActionType,\n LiFiStepExtended,\n} from '../types/core.js'\n\n/**\n * Action types that carry the step's own transaction.\n *\n * @internal\n */\nexport const TRANSACTION_ACTION_TYPES: readonly ExecutionActionType[] = [\n 'SWAP',\n 'CROSS_CHAIN',\n]\n\n/**\n * Stored bytes on a chain without its own expiry (Sui, Solana with a durable\n * nonce, Bitcoin) are resent only this long after signing. Past it, a page\n * load could otherwise execute a swap on a quote the user no longer expects.\n *\n * @internal\n */\nexport const MAX_RESEND_AGE_MS = 120_000\n\n/**\n * Without an expiry verdict, a signature younger than this is never declared\n * dropped. Solana blockhashes and Tron transactions expire well before it.\n *\n * @internal\n */\nexport const DROPPED_FALLBACK_AGE_MS = 300_000\n\n/**\n * Subtracted from `execution.signedAt` (the device clock) when it anchors a\n * history-coverage check, so a device clock that runs fast cannot make a node\n * look like it covers the signing time when it does not.\n *\n * @internal\n */\nexport const CLOCK_SKEW_MARGIN_MS = 600_000\n\n/**\n * Fields a sign task clears before it writes a new transaction's data, and\n * that re-initializing a final-failed action clears. `taskId` is included: a\n * stale relayed or batched task id would otherwise keep the action open.\n *\n * @internal\n */\nexport const CLEARED_TRANSACTION_FIELDS: Readonly<\n Pick<ExecutionAction, 'txHash' | 'txLink' | 'txHex' | 'txFinal' | 'taskId'>\n> = Object.freeze({\n txHash: undefined,\n txLink: undefined,\n txHex: undefined,\n txFinal: undefined,\n taskId: undefined,\n})\n\n/**\n * True when the action has a transaction to follow, landed or not: a hash, a\n * task id or stored signed bytes, unless the action FAILED with a final\n * outcome. Every resume decision uses this one predicate, so the pipeline\n * selector and the pre-sign guard can never disagree.\n *\n * Resume rules for providers. A step never signs or sends a second\n * transaction while an earlier one can still land:\n * 1. Pick the first task with this predicate: open and DONE, the status\n * wait; open, the provider's wait task; otherwise the first task.\n * 2. In the sign task, call `assertNoOpenTransaction` at the start, right\n * before each wallet call and, where the SDK sends, right after the\n * wallet returns. Write the new data with `CLEARED_TRANSACTION_FIELDS`\n * and `signedAt`.\n * 3. From the last check, nothing awaits until the send or, where the SDK\n * sends signed bytes, until they are stored as `txHex`, before the first\n * send. Clear `txHex` only when the outcome is known, no node can still\n * hold the bytes, or they no longer decode.\n * 4. A resume never signs. It looks the transaction up and resends the\n * stored bytes only while `isResendAllowed` (or the chain's own expiry)\n * allows it; otherwise it only waits.\n * 5. Mark an error final only on a verdict about the transaction: failed\n * or reverted (on chain or at the relayer), cancelled, replaced, or\n * dropped with proof. Dropped needs all three: the transaction can no\n * longer land, a node that covers its window reports it absent (in the\n * same response where the chain allows it), and `isKnownToStatusApi` is\n * false. In doubt, throw without the marker and keep the fields.\n * 6. Give `context.signal` only to waits that start after the broadcast. On\n * abort, return `PAUSED` and write nothing.\n */\nexport function hasOpenTransaction(action?: ExecutionAction): boolean {\n if (!action) {\n return false\n }\n if (!(action.txHash || action.taskId || action.txHex)) {\n return false\n }\n return !(action.status === 'FAILED' && action.txFinal === true)\n}\n\n/**\n * True when any SWAP / CROSS_CHAIN action of the step has an open transaction.\n *\n * @internal\n */\nexport function hasStepOpenTransaction(step: LiFiStepExtended): boolean {\n return !!step.execution?.actions?.some(\n (action) =>\n TRANSACTION_ACTION_TYPES.includes(action.type) &&\n hasOpenTransaction(action)\n )\n}\n\n/**\n * Walks the error and its `cause` chain. Parsers may rebuild errors, so the\n * marker is read from the original error. A property check instead of\n * `instanceof` keeps it working across duplicated installs.\n *\n * @internal\n */\nexport function isFinalTransactionError(error: unknown): boolean {\n const seen = new Set<unknown>()\n let current: unknown = error\n while (current && typeof current === 'object' && !seen.has(current)) {\n seen.add(current)\n if ((current as { final?: unknown }).final === true) {\n return true\n }\n current = (current as { cause?: unknown }).cause\n }\n return false\n}\n\n/**\n * The error of a step that would sign a second transaction while its first\n * one may still land.\n *\n * @internal\n */\nexport function transactionConflictError(): TransactionError {\n return new TransactionError(\n LiFiErrorCode.TransactionConflict,\n 'A transaction for this step was already signed and may still land. Resume the route to wait for it instead of signing a new one.'\n )\n}\n\n/**\n * Called first in every sign task. With correct pipeline selectors it never\n * throws; it stops a second signature if a selector ever routes an open\n * transaction back to signing. Every sign task calls it again on the freshly\n * found action right before its wallet call: a late write of an older run can\n * merge a transaction into the action during the awaits in between. A sign\n * task that sends the transaction itself calls it once more after the wallet\n * returns, before it writes or sends anything: the merge can also land while\n * the prompt is open.\n *\n * @internal\n */\nexport function assertNoOpenTransaction(action?: ExecutionAction): void {\n if (hasOpenTransaction(action)) {\n throw transactionConflictError()\n }\n}\n\n/**\n * Unknown signing time never allows a resend. Nor does a signing time in the\n * future: a device clock that ran ahead at signing and was corrected later\n * would otherwise stretch the cap by the clock error.\n *\n * @internal\n */\nexport function isResendAllowed(\n signedAt: number | undefined,\n now: number = Date.now()\n): boolean {\n return (\n signedAt !== undefined &&\n now >= signedAt &&\n now - signedAt < MAX_RESEND_AGE_MS\n )\n}\n\n/**\n * Unknown signing time never allows a drop.\n *\n * @internal\n */\nexport function isOldEnoughToDrop(\n signedAt: number | undefined,\n now: number = Date.now()\n): boolean {\n return signedAt !== undefined && now - signedAt > DROPPED_FALLBACK_AGE_MS\n}\n"],"mappings":";;;;;;;;AAaA,MAAa,2BAA2D,CACtE,QACA,aACF;;;;;;;;AASA,MAAa,oBAAoB;;;;;;;AAQjC,MAAa,0BAA0B;;;;;;;;AASvC,MAAa,uBAAuB;;;;;;;;AASpC,MAAa,6BAET,OAAO,OAAO;CAChB,QAAQ,KAAA;CACR,QAAQ,KAAA;CACR,OAAO,KAAA;CACP,SAAS,KAAA;CACT,QAAQ,KAAA;AACV,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCD,SAAgB,mBAAmB,QAAmC;CACpE,IAAI,CAAC,QACH,OAAO;CAET,IAAI,EAAE,OAAO,UAAU,OAAO,UAAU,OAAO,QAC7C,OAAO;CAET,OAAO,EAAE,OAAO,WAAW,YAAY,OAAO,YAAY;AAC5D;;;;;;AAOA,SAAgB,uBAAuB,MAAiC;CACtE,OAAO,CAAC,CAAC,KAAK,WAAW,SAAS,MAC/B,WACC,yBAAyB,SAAS,OAAO,IAAI,KAC7C,mBAAmB,MAAM,CAC7B;AACF;;;;;;;;AASA,SAAgB,wBAAwB,OAAyB;CAC/D,MAAM,uBAAO,IAAI,IAAa;CAC9B,IAAI,UAAmB;CACvB,OAAO,WAAW,OAAO,YAAY,YAAY,CAAC,KAAK,IAAI,OAAO,GAAG;EACnE,KAAK,IAAI,OAAO;EAChB,IAAK,QAAgC,UAAU,MAC7C,OAAO;EAET,UAAW,QAAgC;CAC7C;CACA,OAAO;AACT;;;;;;;AAQA,SAAgB,2BAA6C;CAC3D,OAAO,IAAI,iBAAA,MAET,kIACF;AACF;;;;;;;;;;;;;AAcA,SAAgB,wBAAwB,QAAgC;CACtE,IAAI,mBAAmB,MAAM,GAC3B,MAAM,yBAAyB;AAEnC;;;;;;;;AASA,SAAgB,gBACd,UACA,MAAc,KAAK,IAAI,GACd;CACT,OACE,aAAa,KAAA,KACb,OAAO,YACP,MAAM,WAAA;AAEV;;;;;;AAOA,SAAgB,kBACd,UACA,MAAc,KAAK,IAAI,GACd;CACT,OAAO,aAAa,KAAA,KAAa,MAAM,WAAA;AACzC"}
@@ -8,8 +8,18 @@ export declare class RPCError extends BaseError {
8
8
  export declare class ProviderError extends BaseError {
9
9
  constructor(code: LiFiErrorCode, message: string, cause?: Error);
10
10
  }
11
+ export interface TransactionErrorOptions {
12
+ /**
13
+ * A definite verdict about the transaction (failed or reverted on chain or
14
+ * at the relayer, cancelled, replaced, or dropped with proof). The step
15
+ * executor then flags the failed action with `txFinal`, so a restart signs
16
+ * a new transaction.
17
+ */
18
+ final?: boolean;
19
+ }
11
20
  export declare class TransactionError extends BaseError {
12
- constructor(code: LiFiErrorCode, message: string, cause?: Error);
21
+ readonly final: boolean;
22
+ constructor(code: LiFiErrorCode, message: string, cause?: Error, options?: TransactionErrorOptions);
13
23
  }
14
24
  export declare class UnknownError extends BaseError {
15
25
  constructor(message: string, cause?: Error);
@@ -26,7 +36,8 @@ export declare class ValidationError extends BaseError {
26
36
  /**
27
37
  * Thrown by a step executor when executeStep should be retried with the given params
28
38
  * (e.g. wallet rejected 7702 upgrade → retry with atomicityNotReady).
29
- * The execution layer catches this and retries executeStep(client, step, retryParams).
39
+ * The execution layer catches this and retries executeStep(client, step, retryParams),
40
+ * unless the route was stopped or the step has an open transaction.
30
41
  */
31
42
  export declare class ExecuteStepRetryError extends BaseError {
32
43
  readonly retryParams: ExecuteStepRetryParams;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","names":[],"sources":["../../../src/errors/errors.ts"],"mappings":";;;;qBAIa,iBAAiB;EAC5B,YAAY,MAAM,eAAe,iBAAiB,QAAQ;;qBAK/C,sBAAsB;EACjC,YAAY,MAAM,eAAe,iBAAiB,QAAQ;;qBAK/C,yBAAyB;EACpC,YAAY,MAAM,eAAe,iBAAiB,QAAQ;;qBAK/C,qBAAqB;EAChC,YAAY,iBAAiB,QAAQ;;qBAK1B,qBAAqB;EAChC,YAAY,iBAAiB,QAAQ;;qBAK1B,oBAAoB;EAC/B,YAAY;;qBAKD,wBAAwB;EACnC,YAAY;;;;;;;qBAUD,8BAA8B;WAChC,aAAa;EAEtB,YACE,iBACA,aAAa,wBACb,QAAQ"}
1
+ {"version":3,"file":"errors.d.ts","names":[],"sources":["../../../src/errors/errors.ts"],"mappings":";;;;qBAIa,iBAAiB;EAC5B,YAAY,MAAM,eAAe,iBAAiB,QAAQ;;qBAK/C,sBAAsB;EACjC,YAAY,MAAM,eAAe,iBAAiB,QAAQ;;iBAK3C;;;;;;;EAOf;;qBAGW,yBAAyB;WAC3B;EAET,YACE,MAAM,eACN,iBACA,QAAQ,OACR,UAAU;;qBAOD,qBAAqB;EAChC,YAAY,iBAAiB,QAAQ;;qBAK1B,qBAAqB;EAChC,YAAY,iBAAiB,QAAQ;;qBAK1B,oBAAoB;EAC/B,YAAY;;qBAKD,wBAAwB;EACnC,YAAY;;;;;;;;qBAWD,8BAA8B;WAChC,aAAa;EAEtB,YACE,iBACA,aAAa,wBACb,QAAQ"}
@@ -12,8 +12,10 @@ var ProviderError = class extends BaseError {
12
12
  }
13
13
  };
14
14
  var TransactionError = class extends BaseError {
15
- constructor(code, message, cause) {
15
+ final;
16
+ constructor(code, message, cause, options) {
16
17
  super("TransactionError", code, message, cause);
18
+ this.final = options?.final ?? false;
17
19
  }
18
20
  };
19
21
  var UnknownError = class extends BaseError {
@@ -39,7 +41,8 @@ var ValidationError = class extends BaseError {
39
41
  /**
40
42
  * Thrown by a step executor when executeStep should be retried with the given params
41
43
  * (e.g. wallet rejected 7702 upgrade → retry with atomicityNotReady).
42
- * The execution layer catches this and retries executeStep(client, step, retryParams).
44
+ * The execution layer catches this and retries executeStep(client, step, retryParams),
45
+ * unless the route was stopped or the step has an open transaction.
43
46
  */
44
47
  var ExecuteStepRetryError = class extends BaseError {
45
48
  retryParams;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../../../src/errors/errors.ts"],"sourcesContent":["import type { ExecuteStepRetryParams } from '../types/core.js'\nimport { BaseError } from './baseError.js'\nimport { ErrorName, LiFiErrorCode } from './constants.js'\n\nexport class RPCError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.RPCError, code, message, cause)\n }\n}\n\nexport class ProviderError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.ProviderError, code, message, cause)\n }\n}\n\nexport class TransactionError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.TransactionError, code, message, cause)\n }\n}\n\nexport class UnknownError extends BaseError {\n constructor(message: string, cause?: Error) {\n super(ErrorName.UnknownError, LiFiErrorCode.InternalError, message, cause)\n }\n}\n\nexport class BalanceError extends BaseError {\n constructor(message: string, cause?: Error) {\n super(ErrorName.BalanceError, LiFiErrorCode.BalanceError, message, cause)\n }\n}\n\nexport class ServerError extends BaseError {\n constructor(message: string) {\n super(ErrorName.ServerError, LiFiErrorCode.InternalError, message)\n }\n}\n\nexport class ValidationError extends BaseError {\n constructor(message: string) {\n super(ErrorName.ValidationError, LiFiErrorCode.ValidationError, message)\n }\n}\n\n/**\n * Thrown by a step executor when executeStep should be retried with the given params\n * (e.g. wallet rejected 7702 upgrade → retry with atomicityNotReady).\n * The execution layer catches this and retries executeStep(client, step, retryParams).\n */\nexport class ExecuteStepRetryError extends BaseError {\n readonly retryParams: ExecuteStepRetryParams\n\n constructor(\n message: string,\n retryParams: ExecuteStepRetryParams,\n cause?: Error\n ) {\n super(\n ErrorName.ExecuteStepRetryError,\n LiFiErrorCode.InternalError,\n message,\n cause\n )\n this.retryParams = retryParams\n }\n}\n"],"mappings":";;;AAIA,IAAa,WAAb,cAA8B,UAAU;CACtC,YAAY,MAAqB,SAAiB,OAAe;EAC/D,MAAA,YAA0B,MAAM,SAAS,KAAK;CAChD;AACF;AAEA,IAAa,gBAAb,cAAmC,UAAU;CAC3C,YAAY,MAAqB,SAAiB,OAAe;EAC/D,MAAA,iBAA+B,MAAM,SAAS,KAAK;CACrD;AACF;AAEA,IAAa,mBAAb,cAAsC,UAAU;CAC9C,YAAY,MAAqB,SAAiB,OAAe;EAC/D,MAAA,oBAAkC,MAAM,SAAS,KAAK;CACxD;AACF;AAEA,IAAa,eAAb,cAAkC,UAAU;CAC1C,YAAY,SAAiB,OAAe;EAC1C,MAAA,gBAAA,KAA2D,SAAS,KAAK;CAC3E;AACF;AAEA,IAAa,eAAb,cAAkC,UAAU;CAC1C,YAAY,SAAiB,OAAe;EAC1C,MAAA,gBAAA,MAA0D,SAAS,KAAK;CAC1E;AACF;AAEA,IAAa,cAAb,cAAiC,UAAU;CACzC,YAAY,SAAiB;EAC3B,MAAA,eAAA,KAA0D,OAAO;CACnE;AACF;AAEA,IAAa,kBAAb,cAAqC,UAAU;CAC7C,YAAY,SAAiB;EAC3B,MAAA,mBAAA,MAAgE,OAAO;CACzE;AACF;;;;;;AAOA,IAAa,wBAAb,cAA2C,UAAU;CACnD;CAEA,YACE,SACA,aACA,OACA;EACA,MAAA,yBAAA,KAGE,SACA,KACF;EACA,KAAK,cAAc;CACrB;AACF"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../../../src/errors/errors.ts"],"sourcesContent":["import type { ExecuteStepRetryParams } from '../types/core.js'\nimport { BaseError } from './baseError.js'\nimport { ErrorName, LiFiErrorCode } from './constants.js'\n\nexport class RPCError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.RPCError, code, message, cause)\n }\n}\n\nexport class ProviderError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.ProviderError, code, message, cause)\n }\n}\n\nexport interface TransactionErrorOptions {\n /**\n * A definite verdict about the transaction (failed or reverted on chain or\n * at the relayer, cancelled, replaced, or dropped with proof). The step\n * executor then flags the failed action with `txFinal`, so a restart signs\n * a new transaction.\n */\n final?: boolean\n}\n\nexport class TransactionError extends BaseError {\n readonly final: boolean\n\n constructor(\n code: LiFiErrorCode,\n message: string,\n cause?: Error,\n options?: TransactionErrorOptions\n ) {\n super(ErrorName.TransactionError, code, message, cause)\n this.final = options?.final ?? false\n }\n}\n\nexport class UnknownError extends BaseError {\n constructor(message: string, cause?: Error) {\n super(ErrorName.UnknownError, LiFiErrorCode.InternalError, message, cause)\n }\n}\n\nexport class BalanceError extends BaseError {\n constructor(message: string, cause?: Error) {\n super(ErrorName.BalanceError, LiFiErrorCode.BalanceError, message, cause)\n }\n}\n\nexport class ServerError extends BaseError {\n constructor(message: string) {\n super(ErrorName.ServerError, LiFiErrorCode.InternalError, message)\n }\n}\n\nexport class ValidationError extends BaseError {\n constructor(message: string) {\n super(ErrorName.ValidationError, LiFiErrorCode.ValidationError, message)\n }\n}\n\n/**\n * Thrown by a step executor when executeStep should be retried with the given params\n * (e.g. wallet rejected 7702 upgrade → retry with atomicityNotReady).\n * The execution layer catches this and retries executeStep(client, step, retryParams),\n * unless the route was stopped or the step has an open transaction.\n */\nexport class ExecuteStepRetryError extends BaseError {\n readonly retryParams: ExecuteStepRetryParams\n\n constructor(\n message: string,\n retryParams: ExecuteStepRetryParams,\n cause?: Error\n ) {\n super(\n ErrorName.ExecuteStepRetryError,\n LiFiErrorCode.InternalError,\n message,\n cause\n )\n this.retryParams = retryParams\n }\n}\n"],"mappings":";;;AAIA,IAAa,WAAb,cAA8B,UAAU;CACtC,YAAY,MAAqB,SAAiB,OAAe;EAC/D,MAAA,YAA0B,MAAM,SAAS,KAAK;CAChD;AACF;AAEA,IAAa,gBAAb,cAAmC,UAAU;CAC3C,YAAY,MAAqB,SAAiB,OAAe;EAC/D,MAAA,iBAA+B,MAAM,SAAS,KAAK;CACrD;AACF;AAYA,IAAa,mBAAb,cAAsC,UAAU;CAC9C;CAEA,YACE,MACA,SACA,OACA,SACA;EACA,MAAA,oBAAkC,MAAM,SAAS,KAAK;EACtD,KAAK,QAAQ,SAAS,SAAS;CACjC;AACF;AAEA,IAAa,eAAb,cAAkC,UAAU;CAC1C,YAAY,SAAiB,OAAe;EAC1C,MAAA,gBAAA,KAA2D,SAAS,KAAK;CAC3E;AACF;AAEA,IAAa,eAAb,cAAkC,UAAU;CAC1C,YAAY,SAAiB,OAAe;EAC1C,MAAA,gBAAA,MAA0D,SAAS,KAAK;CAC1E;AACF;AAEA,IAAa,cAAb,cAAiC,UAAU;CACzC,YAAY,SAAiB;EAC3B,MAAA,eAAA,KAA0D,OAAO;CACnE;AACF;AAEA,IAAa,kBAAb,cAAqC,UAAU;CAC7C,YAAY,SAAiB;EAC3B,MAAA,mBAAA,MAAgE,OAAO;CACzE;AACF;;;;;;;AAQA,IAAa,wBAAb,cAA2C,UAAU;CACnD;CAEA,YACE,SACA,aACA,OACA;EACA,MAAA,yBAAA,KAGE,SACA,KACF;EACA,KAAK,cAAc;CACrB;AACF"}
@@ -23,12 +23,13 @@ import { patchContractCalls } from "./actions/patchContractCalls.js";
23
23
  import { actions } from "./actions/index.js";
24
24
  import { relayTransaction } from "./actions/relayTransaction.js";
25
25
  import { createClient } from "./client/createClient.js";
26
+ import { findProvider } from "./client/findProvider.js";
26
27
  import { StatusManager } from "./core/StatusManager.js";
27
28
  import { StepExecutorBaseContext, StepExecutorContext, TaskResult, TaskStatus } from "./types/execution.js";
28
29
  import { BaseStepExecutionTask } from "./core/BaseStepExecutionTask.js";
29
30
  import { ErrorCode, ErrorMessage, ErrorName, LiFiErrorCode } from "./errors/constants.js";
30
31
  import { BaseError } from "./errors/baseError.js";
31
- import { BalanceError, ExecuteStepRetryError, ProviderError, RPCError, ServerError, TransactionError, UnknownError, ValidationError } from "./errors/errors.js";
32
+ import { BalanceError, ExecuteStepRetryError, ProviderError, RPCError, ServerError, TransactionError, TransactionErrorOptions, UnknownError, ValidationError } from "./errors/errors.js";
32
33
  import { SDKError } from "./errors/SDKError.js";
33
34
  import { TaskPipeline } from "./core/TaskPipeline.js";
34
35
  import { BaseStepExecutor } from "./core/BaseStepExecutor.js";
@@ -39,18 +40,21 @@ import { CheckBalanceTask } from "./core/tasks/CheckBalanceTask.js";
39
40
  import { PrepareTransactionTask } from "./core/tasks/PrepareTransactionTask.js";
40
41
  import { WaitForTransactionStatusTask } from "./core/tasks/WaitForTransactionStatusTask.js";
41
42
  import { getTransactionRequestData } from "./core/tasks/helpers/getTransactionRequestData.js";
43
+ import { isKnownToStatusApi } from "./core/tasks/helpers/isKnownToStatusApi.js";
42
44
  import { stepComparison } from "./core/tasks/helpers/stepComparison.js";
45
+ import { CLEARED_TRANSACTION_FIELDS, CLOCK_SKEW_MARGIN_MS, DROPPED_FALLBACK_AGE_MS, MAX_RESEND_AGE_MS, assertNoOpenTransaction, hasOpenTransaction, isFinalTransactionError, isOldEnoughToDrop, isResendAllowed } from "./core/transactionState.js";
43
46
  import { HTTPError } from "./errors/httpError.js";
44
47
  import { checkPackageUpdates } from "./utils/checkPackageUpdates.js";
45
48
  import { convertQuoteToRoute } from "./utils/convertQuoteToRoute.js";
46
49
  import { fetchTxErrorDetails } from "./utils/fetchTxErrorDetails.js";
47
50
  import { formatUnits } from "./utils/formatUnits.js";
48
51
  import { isHex } from "./utils/isHex.js";
52
+ import { LruMap } from "./utils/lru.js";
49
53
  import { parseUnits } from "./utils/parseUnits.js";
50
54
  import { sleep } from "./utils/sleep.js";
51
55
  import { waitForResult } from "./utils/waitForResult.js";
52
- import { LruMap, withDedupe } from "./utils/withDedupe.js";
56
+ import { withDedupe } from "./utils/withDedupe.js";
53
57
  import { withTimeout } from "./utils/withTimeout.js";
54
58
  import { name, version } from "./version.js";
55
59
  export * from "@lifi/types";
56
- export { type AcceptExchangeRateUpdateHook, type AcceptSlippageUpdateHook, type AcceptSlippageUpdateHookParams, BalanceError, BaseError, BaseStepExecutionTask, BaseStepExecutor, type CheckBalanceOptions, CheckBalanceTask, type ContractCallParams, type ContractTool, type ErrorCode, ErrorMessage, ErrorName, type ExchangeRateUpdateParams, ExecuteStepRetryError, type ExecuteStepRetryParams, type Execution, type ExecutionAction, type ExecutionActionStatus, type ExecutionActionType, type ExecutionOptions, type ExecutionStatus, type GetContractCallsHook, type GetContractCallsResult, type GetStatusRequestExtended, HTTPError, InMemoryStorage, type InteractionSettings, LiFiErrorCode, type LiFiStepExtended, type LiFiStepRequest, LocalStorageAdapter, LruMap, PrepareTransactionTask, ProviderError, type QuoteRequest, type QuoteRequestFromAmount, type QuoteRequestToAmount, RPCError, type RPCUrls, type RPCUrlsByRole, type RPCUrlsConfig, type RequestInterceptor, type RouteExecutionData, type RouteExecutionDataDictionary, type RouteExecutionDictionary, type RouteExtended, type SDKBaseConfig, type SDKClient, type SDKConfig, SDKError, type SDKProvider, type SDKStorage, ServerError, StatusManager, type StepExecutor, type StepExecutorBaseContext, type StepExecutorContext, type StepExecutorOptions, type StepExtended, TaskPipeline, type TaskResult, type TaskStatus, TransactionError, type TransactionMethodType, type TransactionParameters, type TransactionRequestParameters, type TransactionRequestUpdateHook, UnknownError, type UpdateRouteHook, ValidationError, WaitForTransactionStatusTask, actions, checkBalance, checkPackageUpdates, convertQuoteToRoute, createClient, createDefaultStorage, executeRoute, fetchTxErrorDetails, formatUnits, getActionMessage, getActiveRoute, getActiveRoutes, getChains, getConnections, getContractCallsQuote, getGasRecommendation, getNameServiceAddress, getQuote, getRelayedTransactionStatus, getRelayerQuote, getRoutes, getStatus, getStepTransaction, getSubstatusMessage, getToken, getTokenBalance, getTokenBalances, getTokenBalancesByChain, getTokens, getTools, getTransactionHistory, getTransactionRequestData, isHex, name, parseUnits, patchContractCalls, relayTransaction, resumeRoute, sleep, stepComparison, stopRouteExecution, updateRouteExecution, version, waitForResult, withDedupe, withTimeout };
60
+ export { type AcceptExchangeRateUpdateHook, type AcceptSlippageUpdateHook, type AcceptSlippageUpdateHookParams, BalanceError, BaseError, BaseStepExecutionTask, BaseStepExecutor, CLEARED_TRANSACTION_FIELDS, CLOCK_SKEW_MARGIN_MS, type CheckBalanceOptions, CheckBalanceTask, type ContractCallParams, type ContractTool, DROPPED_FALLBACK_AGE_MS, type ErrorCode, ErrorMessage, ErrorName, type ExchangeRateUpdateParams, ExecuteStepRetryError, type ExecuteStepRetryParams, type Execution, type ExecutionAction, type ExecutionActionStatus, type ExecutionActionType, type ExecutionOptions, type ExecutionStatus, type GetContractCallsHook, type GetContractCallsResult, type GetStatusRequestExtended, HTTPError, InMemoryStorage, type InteractionSettings, LiFiErrorCode, type LiFiStepExtended, type LiFiStepRequest, LocalStorageAdapter, LruMap, MAX_RESEND_AGE_MS, PrepareTransactionTask, ProviderError, type QuoteRequest, type QuoteRequestFromAmount, type QuoteRequestToAmount, RPCError, type RPCUrls, type RPCUrlsByRole, type RPCUrlsConfig, type RequestInterceptor, type RouteExecutionData, type RouteExecutionDataDictionary, type RouteExecutionDictionary, type RouteExtended, type SDKBaseConfig, type SDKClient, type SDKConfig, SDKError, type SDKProvider, type SDKStorage, ServerError, StatusManager, type StepExecutor, type StepExecutorBaseContext, type StepExecutorContext, type StepExecutorOptions, type StepExtended, TaskPipeline, type TaskResult, type TaskStatus, TransactionError, type TransactionErrorOptions, type TransactionMethodType, type TransactionParameters, type TransactionRequestParameters, type TransactionRequestUpdateHook, UnknownError, type UpdateRouteHook, ValidationError, WaitForTransactionStatusTask, actions, assertNoOpenTransaction, checkBalance, checkPackageUpdates, convertQuoteToRoute, createClient, createDefaultStorage, executeRoute, fetchTxErrorDetails, findProvider, formatUnits, getActionMessage, getActiveRoute, getActiveRoutes, getChains, getConnections, getContractCallsQuote, getGasRecommendation, getNameServiceAddress, getQuote, getRelayedTransactionStatus, getRelayerQuote, getRoutes, getStatus, getStepTransaction, getSubstatusMessage, getToken, getTokenBalance, getTokenBalances, getTokenBalancesByChain, getTokens, getTools, getTransactionHistory, getTransactionRequestData, hasOpenTransaction, isFinalTransactionError, isHex, isKnownToStatusApi, isOldEnoughToDrop, isResendAllowed, name, parseUnits, patchContractCalls, relayTransaction, resumeRoute, sleep, stepComparison, stopRouteExecution, updateRouteExecution, version, waitForResult, withDedupe, withTimeout };