@lifi/sdk-provider-ethereum 4.2.6 → 4.2.8

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 (174) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +9 -0
  3. package/dist/cjs/EthereumProvider.js +5 -1
  4. package/dist/cjs/EthereumProvider.js.map +1 -1
  5. package/dist/cjs/actions/waitForBatchTransactionReceipt.d.ts +25 -1
  6. package/dist/cjs/actions/waitForBatchTransactionReceipt.js +55 -7
  7. package/dist/cjs/actions/waitForBatchTransactionReceipt.js.map +1 -1
  8. package/dist/cjs/actions/waitForRelayedTransactionReceipt.d.ts +13 -1
  9. package/dist/cjs/actions/waitForRelayedTransactionReceipt.js +19 -5
  10. package/dist/cjs/actions/waitForRelayedTransactionReceipt.js.map +1 -1
  11. package/dist/cjs/actions/waitForSafeTransactionExecution.js +2 -2
  12. package/dist/cjs/actions/waitForSafeTransactionExecution.js.map +1 -1
  13. package/dist/cjs/actions/waitForTransactionReceipt.js +2 -2
  14. package/dist/cjs/actions/waitForTransactionReceipt.js.map +1 -1
  15. package/dist/cjs/client/publicClient.js +14 -5
  16. package/dist/cjs/client/publicClient.js.map +1 -1
  17. package/dist/cjs/core/EthereumStepExecutor.js +1 -1
  18. package/dist/cjs/core/EthereumStepExecutor.js.map +1 -1
  19. package/dist/cjs/core/tasks/EthereumBatchedSignAndExecuteTask.js +3 -0
  20. package/dist/cjs/core/tasks/EthereumBatchedSignAndExecuteTask.js.map +1 -1
  21. package/dist/cjs/core/tasks/EthereumBatchedWaitForTransactionTask.js +7 -3
  22. package/dist/cjs/core/tasks/EthereumBatchedWaitForTransactionTask.js.map +1 -1
  23. package/dist/cjs/core/tasks/EthereumCheckAllowanceTask.js +5 -4
  24. package/dist/cjs/core/tasks/EthereumCheckAllowanceTask.js.map +1 -1
  25. package/dist/cjs/core/tasks/EthereumPrepareTransactionTask.js +10 -1
  26. package/dist/cjs/core/tasks/EthereumPrepareTransactionTask.js.map +1 -1
  27. package/dist/cjs/core/tasks/EthereumRelayedSignAndExecuteTask.js +5 -2
  28. package/dist/cjs/core/tasks/EthereumRelayedSignAndExecuteTask.js.map +1 -1
  29. package/dist/cjs/core/tasks/EthereumRelayedWaitForTransactionTask.js +10 -2
  30. package/dist/cjs/core/tasks/EthereumRelayedWaitForTransactionTask.js.map +1 -1
  31. package/dist/cjs/core/tasks/EthereumResetAllowanceTask.js +2 -2
  32. package/dist/cjs/core/tasks/EthereumResetAllowanceTask.js.map +1 -1
  33. package/dist/cjs/core/tasks/EthereumSetAllowanceTask.js +2 -3
  34. package/dist/cjs/core/tasks/EthereumSetAllowanceTask.js.map +1 -1
  35. package/dist/cjs/core/tasks/EthereumSignAndExecuteTask.js +1 -0
  36. package/dist/cjs/core/tasks/EthereumSignAndExecuteTask.js.map +1 -1
  37. package/dist/cjs/core/tasks/EthereumStandardSignAndExecuteTask.js +2 -0
  38. package/dist/cjs/core/tasks/EthereumStandardSignAndExecuteTask.js.map +1 -1
  39. package/dist/cjs/core/tasks/EthereumWaitForTransactionTask.js +8 -1
  40. package/dist/cjs/core/tasks/EthereumWaitForTransactionTask.js.map +1 -1
  41. package/dist/cjs/core/tasks/helpers/getEthereumExecutionStrategy.d.ts +6 -0
  42. package/dist/cjs/core/tasks/helpers/getEthereumExecutionStrategy.js +15 -0
  43. package/dist/cjs/core/tasks/helpers/getEthereumExecutionStrategy.js.map +1 -1
  44. package/dist/cjs/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.d.ts +17 -0
  45. package/dist/cjs/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.js +27 -0
  46. package/dist/cjs/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.js.map +1 -0
  47. package/dist/cjs/core/tasks/helpers/resolveAllowanceSpender.d.ts +16 -0
  48. package/dist/cjs/core/tasks/helpers/resolveAllowanceSpender.js +21 -0
  49. package/dist/cjs/core/tasks/helpers/resolveAllowanceSpender.js.map +1 -0
  50. package/dist/cjs/core/tasks/helpers/shouldCheckForAllowance.js +2 -1
  51. package/dist/cjs/core/tasks/helpers/shouldCheckForAllowance.js.map +1 -1
  52. package/dist/cjs/core/tasks/helpers/signHyperliquidTypedData.d.ts +5 -1
  53. package/dist/cjs/core/tasks/helpers/signHyperliquidTypedData.js +8 -1
  54. package/dist/cjs/core/tasks/helpers/signHyperliquidTypedData.js.map +1 -1
  55. package/dist/cjs/core/tasks/helpers/signTypedDataEntries.d.ts +6 -2
  56. package/dist/cjs/core/tasks/helpers/signTypedDataEntries.js +7 -2
  57. package/dist/cjs/core/tasks/helpers/signTypedDataEntries.js.map +1 -1
  58. package/dist/cjs/errors/parseEthereumErrors.js +10 -2
  59. package/dist/cjs/errors/parseEthereumErrors.js.map +1 -1
  60. package/dist/cjs/types.d.ts +6 -0
  61. package/dist/cjs/types.js.map +1 -1
  62. package/dist/cjs/version.d.ts +1 -1
  63. package/dist/cjs/version.js +1 -1
  64. package/dist/cjs/version.js.map +1 -1
  65. package/dist/esm/EthereumProvider.d.ts.map +1 -1
  66. package/dist/esm/EthereumProvider.js +5 -1
  67. package/dist/esm/EthereumProvider.js.map +1 -1
  68. package/dist/esm/actions/waitForBatchTransactionReceipt.d.ts +25 -1
  69. package/dist/esm/actions/waitForBatchTransactionReceipt.d.ts.map +1 -1
  70. package/dist/esm/actions/waitForBatchTransactionReceipt.js +55 -7
  71. package/dist/esm/actions/waitForBatchTransactionReceipt.js.map +1 -1
  72. package/dist/esm/actions/waitForRelayedTransactionReceipt.d.ts +13 -1
  73. package/dist/esm/actions/waitForRelayedTransactionReceipt.d.ts.map +1 -1
  74. package/dist/esm/actions/waitForRelayedTransactionReceipt.js +19 -5
  75. package/dist/esm/actions/waitForRelayedTransactionReceipt.js.map +1 -1
  76. package/dist/esm/actions/waitForSafeTransactionExecution.js +2 -2
  77. package/dist/esm/actions/waitForSafeTransactionExecution.js.map +1 -1
  78. package/dist/esm/actions/waitForTransactionReceipt.js +2 -2
  79. package/dist/esm/actions/waitForTransactionReceipt.js.map +1 -1
  80. package/dist/esm/client/publicClient.d.ts.map +1 -1
  81. package/dist/esm/client/publicClient.js +14 -5
  82. package/dist/esm/client/publicClient.js.map +1 -1
  83. package/dist/esm/core/EthereumStepExecutor.d.ts.map +1 -1
  84. package/dist/esm/core/EthereumStepExecutor.js +2 -2
  85. package/dist/esm/core/EthereumStepExecutor.js.map +1 -1
  86. package/dist/esm/core/tasks/EthereumBatchedSignAndExecuteTask.d.ts.map +1 -1
  87. package/dist/esm/core/tasks/EthereumBatchedSignAndExecuteTask.js +4 -1
  88. package/dist/esm/core/tasks/EthereumBatchedSignAndExecuteTask.js.map +1 -1
  89. package/dist/esm/core/tasks/EthereumBatchedWaitForTransactionTask.js +7 -3
  90. package/dist/esm/core/tasks/EthereumBatchedWaitForTransactionTask.js.map +1 -1
  91. package/dist/esm/core/tasks/EthereumCheckAllowanceTask.js +5 -4
  92. package/dist/esm/core/tasks/EthereumCheckAllowanceTask.js.map +1 -1
  93. package/dist/esm/core/tasks/EthereumPrepareTransactionTask.d.ts.map +1 -1
  94. package/dist/esm/core/tasks/EthereumPrepareTransactionTask.js +12 -3
  95. package/dist/esm/core/tasks/EthereumPrepareTransactionTask.js.map +1 -1
  96. package/dist/esm/core/tasks/EthereumRelayedSignAndExecuteTask.d.ts.map +1 -1
  97. package/dist/esm/core/tasks/EthereumRelayedSignAndExecuteTask.js +6 -3
  98. package/dist/esm/core/tasks/EthereumRelayedSignAndExecuteTask.js.map +1 -1
  99. package/dist/esm/core/tasks/EthereumRelayedWaitForTransactionTask.d.ts.map +1 -1
  100. package/dist/esm/core/tasks/EthereumRelayedWaitForTransactionTask.js +10 -2
  101. package/dist/esm/core/tasks/EthereumRelayedWaitForTransactionTask.js.map +1 -1
  102. package/dist/esm/core/tasks/EthereumResetAllowanceTask.js +2 -2
  103. package/dist/esm/core/tasks/EthereumResetAllowanceTask.js.map +1 -1
  104. package/dist/esm/core/tasks/EthereumSetAllowanceTask.js +2 -3
  105. package/dist/esm/core/tasks/EthereumSetAllowanceTask.js.map +1 -1
  106. package/dist/esm/core/tasks/EthereumSignAndExecuteTask.d.ts.map +1 -1
  107. package/dist/esm/core/tasks/EthereumSignAndExecuteTask.js +2 -1
  108. package/dist/esm/core/tasks/EthereumSignAndExecuteTask.js.map +1 -1
  109. package/dist/esm/core/tasks/EthereumStandardSignAndExecuteTask.d.ts.map +1 -1
  110. package/dist/esm/core/tasks/EthereumStandardSignAndExecuteTask.js +3 -1
  111. package/dist/esm/core/tasks/EthereumStandardSignAndExecuteTask.js.map +1 -1
  112. package/dist/esm/core/tasks/EthereumWaitForTransactionTask.d.ts.map +1 -1
  113. package/dist/esm/core/tasks/EthereumWaitForTransactionTask.js +9 -2
  114. package/dist/esm/core/tasks/EthereumWaitForTransactionTask.js.map +1 -1
  115. package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.d.ts +6 -0
  116. package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.d.ts.map +1 -1
  117. package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.js +15 -1
  118. package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.js.map +1 -1
  119. package/dist/esm/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.d.ts +17 -0
  120. package/dist/esm/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.d.ts.map +1 -0
  121. package/dist/esm/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.js +26 -0
  122. package/dist/esm/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.js.map +1 -0
  123. package/dist/esm/core/tasks/helpers/resolveAllowanceSpender.d.ts +16 -0
  124. package/dist/esm/core/tasks/helpers/resolveAllowanceSpender.d.ts.map +1 -0
  125. package/dist/esm/core/tasks/helpers/resolveAllowanceSpender.js +20 -0
  126. package/dist/esm/core/tasks/helpers/resolveAllowanceSpender.js.map +1 -0
  127. package/dist/esm/core/tasks/helpers/shouldCheckForAllowance.d.ts.map +1 -1
  128. package/dist/esm/core/tasks/helpers/shouldCheckForAllowance.js +2 -1
  129. package/dist/esm/core/tasks/helpers/shouldCheckForAllowance.js.map +1 -1
  130. package/dist/esm/core/tasks/helpers/signHyperliquidTypedData.d.ts +5 -1
  131. package/dist/esm/core/tasks/helpers/signHyperliquidTypedData.d.ts.map +1 -1
  132. package/dist/esm/core/tasks/helpers/signHyperliquidTypedData.js +8 -1
  133. package/dist/esm/core/tasks/helpers/signHyperliquidTypedData.js.map +1 -1
  134. package/dist/esm/core/tasks/helpers/signTypedDataEntries.d.ts +6 -2
  135. package/dist/esm/core/tasks/helpers/signTypedDataEntries.d.ts.map +1 -1
  136. package/dist/esm/core/tasks/helpers/signTypedDataEntries.js +7 -2
  137. package/dist/esm/core/tasks/helpers/signTypedDataEntries.js.map +1 -1
  138. package/dist/esm/errors/parseEthereumErrors.d.ts.map +1 -1
  139. package/dist/esm/errors/parseEthereumErrors.js +10 -2
  140. package/dist/esm/errors/parseEthereumErrors.js.map +1 -1
  141. package/dist/esm/types.d.ts +6 -0
  142. package/dist/esm/types.d.ts.map +1 -1
  143. package/dist/esm/types.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/package.json +3 -3
  148. package/src/EthereumProvider.ts +6 -1
  149. package/src/actions/waitForBatchTransactionReceipt.ts +119 -13
  150. package/src/actions/waitForRelayedTransactionReceipt.ts +45 -10
  151. package/src/actions/waitForSafeTransactionExecution.ts +6 -2
  152. package/src/actions/waitForTransactionReceipt.ts +6 -2
  153. package/src/client/publicClient.ts +20 -8
  154. package/src/core/EthereumStepExecutor.ts +8 -6
  155. package/src/core/tasks/EthereumBatchedSignAndExecuteTask.ts +11 -0
  156. package/src/core/tasks/EthereumBatchedWaitForTransactionTask.ts +17 -13
  157. package/src/core/tasks/EthereumCheckAllowanceTask.ts +5 -7
  158. package/src/core/tasks/EthereumPrepareTransactionTask.ts +47 -4
  159. package/src/core/tasks/EthereumRelayedSignAndExecuteTask.ts +22 -2
  160. package/src/core/tasks/EthereumRelayedWaitForTransactionTask.ts +40 -8
  161. package/src/core/tasks/EthereumResetAllowanceTask.ts +3 -6
  162. package/src/core/tasks/EthereumSetAllowanceTask.ts +4 -8
  163. package/src/core/tasks/EthereumSignAndExecuteTask.ts +5 -0
  164. package/src/core/tasks/EthereumStandardSignAndExecuteTask.ts +10 -0
  165. package/src/core/tasks/EthereumWaitForTransactionTask.ts +33 -2
  166. package/src/core/tasks/helpers/getEthereumExecutionStrategy.ts +28 -0
  167. package/src/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.ts +37 -0
  168. package/src/core/tasks/helpers/resolveAllowanceSpender.ts +24 -0
  169. package/src/core/tasks/helpers/shouldCheckForAllowance.ts +9 -5
  170. package/src/core/tasks/helpers/signHyperliquidTypedData.ts +9 -1
  171. package/src/core/tasks/helpers/signTypedDataEntries.ts +8 -2
  172. package/src/errors/parseEthereumErrors.ts +18 -10
  173. package/src/types.ts +6 -0
  174. package/src/version.ts +1 -1
@@ -7,7 +7,11 @@ export type SignTypedDataEntriesResult = {
7
7
  status: "COMPLETED";
8
8
  signedTypedData: SignedTypedData[];
9
9
  };
10
- /** Signs the entries in order, switching chains per entry, and appends the signatures. */
11
- export declare function signTypedDataEntries(context: EthereumStepExecutorContext, entries: TypedData[], actionType: ExecutionActionType, actionStatus?: ExecutionActionStatus): Promise<SignTypedDataEntriesResult>;
10
+ /**
11
+ * Signs the entries in order, switching chains per entry, and appends the
12
+ * signatures. `beforeSignature` runs right before each wallet call, after the
13
+ * chain switch; it throws to stop the signing.
14
+ */
15
+ export declare function signTypedDataEntries(context: EthereumStepExecutorContext, entries: TypedData[], actionType: ExecutionActionType, actionStatus?: ExecutionActionStatus, beforeSignature?: () => void): Promise<SignTypedDataEntriesResult>;
12
16
  //#endregion
13
17
  //# sourceMappingURL=signTypedDataEntries.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signTypedDataEntries.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/signTypedDataEntries.ts"],"mappings":";;;YAYY;EACN;;EACA;EAAqB,iBAAiB;;;wBAGtB,qBACpB,SAAS,6BACT,SAAS,aACT,YAAY,qBACZ,eAAc,wBACb,QAAQ"}
1
+ {"version":3,"file":"signTypedDataEntries.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/signTypedDataEntries.ts"],"mappings":";;;YAYY;EACN;;EACA;EAAqB,iBAAiB;;;;;;;wBAOtB,qBACpB,SAAS,6BACT,SAAS,aACT,YAAY,qBACZ,eAAc,uBACd,+BACC,QAAQ"}
@@ -3,8 +3,12 @@ import { assertValidSignature } from "../../../utils/isValidSignature.js";
3
3
  import { signTypedData } from "viem/actions";
4
4
  import { getAction } from "viem/utils";
5
5
  //#region src/core/tasks/helpers/signTypedDataEntries.ts
6
- /** Signs the entries in order, switching chains per entry, and appends the signatures. */
7
- async function signTypedDataEntries(context, entries, actionType, actionStatus = "ACTION_REQUIRED") {
6
+ /**
7
+ * Signs the entries in order, switching chains per entry, and appends the
8
+ * signatures. `beforeSignature` runs right before each wallet call, after the
9
+ * chain switch; it throws to stop the signing.
10
+ */
11
+ async function signTypedDataEntries(context, entries, actionType, actionStatus = "ACTION_REQUIRED", beforeSignature) {
8
12
  const { step, statusManager, allowUserInteraction, checkClient, signedTypedData: currentSignedTypedData } = context;
9
13
  const signedTypedData = [...currentSignedTypedData];
10
14
  if (entries.length) statusManager.updateAction(step, actionType, actionStatus);
@@ -12,6 +16,7 @@ async function signTypedDataEntries(context, entries, actionType, actionStatus =
12
16
  if (!allowUserInteraction) return { status: "PAUSED" };
13
17
  const client = await checkClient(step, getDomainChainId(typedData.domain) || step.action.fromChainId);
14
18
  if (!client) return { status: "PAUSED" };
19
+ beforeSignature?.();
15
20
  const signature = await getAction(client, signTypedData, "signTypedData")({
16
21
  account: client.account,
17
22
  domain: typedData.domain,
@@ -1 +1 @@
1
- {"version":3,"file":"signTypedDataEntries.js","names":[],"sources":["../../../../../src/core/tasks/helpers/signTypedDataEntries.ts"],"sourcesContent":["import type {\n ExecutionActionStatus,\n ExecutionActionType,\n SignedTypedData,\n TypedData,\n} from '@lifi/sdk'\nimport { signTypedData } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { getDomainChainId } from '../../../utils/getDomainChainId.js'\nimport { assertValidSignature } from '../../../utils/isValidSignature.js'\n\nexport type SignTypedDataEntriesResult =\n | { status: 'PAUSED' }\n | { status: 'COMPLETED'; signedTypedData: SignedTypedData[] }\n\n/** Signs the entries in order, switching chains per entry, and appends the signatures. */\nexport async function signTypedDataEntries(\n context: EthereumStepExecutorContext,\n entries: TypedData[],\n actionType: ExecutionActionType,\n actionStatus: ExecutionActionStatus = 'ACTION_REQUIRED'\n): Promise<SignTypedDataEntriesResult> {\n const {\n step,\n statusManager,\n allowUserInteraction,\n checkClient,\n signedTypedData: currentSignedTypedData,\n } = context\n\n const signedTypedData = [...currentSignedTypedData]\n\n // Announced once for the round, not once per entry. Relay-from-Hyperliquid\n // carries two messages, and main told the consumer `MESSAGE_REQUIRED` once.\n if (entries.length) {\n statusManager.updateAction(step, actionType, actionStatus)\n }\n\n for (const typedData of entries) {\n if (!allowUserInteraction) {\n return { status: 'PAUSED' }\n }\n\n const typedDataChainId =\n getDomainChainId(typedData.domain) || step.action.fromChainId\n\n const client = await checkClient(step, typedDataChainId)\n if (!client) {\n return { status: 'PAUSED' }\n }\n\n const signature = await getAction(\n client,\n signTypedData,\n 'signTypedData'\n )({\n account: client.account!,\n domain: typedData.domain,\n types: typedData.types,\n primaryType: typedData.primaryType,\n message: typedData.message,\n })\n assertValidSignature(signature)\n\n signedTypedData.push({ ...typedData, signature })\n }\n\n return { status: 'COMPLETED', signedTypedData }\n}\n"],"mappings":";;;;;;AAiBA,eAAsB,qBACpB,SACA,SACA,YACA,eAAsC,mBACD;CACrC,MAAM,EACJ,MACA,eACA,sBACA,aACA,iBAAiB,2BACf;CAEJ,MAAM,kBAAkB,CAAC,GAAG,sBAAsB;CAIlD,IAAI,QAAQ,QACV,cAAc,aAAa,MAAM,YAAY,YAAY;CAG3D,KAAK,MAAM,aAAa,SAAS;EAC/B,IAAI,CAAC,sBACH,OAAO,EAAE,QAAQ,SAAS;EAM5B,MAAM,SAAS,MAAM,YAAY,MAF/B,iBAAiB,UAAU,MAAM,KAAK,KAAK,OAAO,WAEG;EACvD,IAAI,CAAC,QACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,MAAM,YAAY,MAAM,UACtB,QACA,eACA,eACF,CAAC,CAAC;GACA,SAAS,OAAO;GAChB,QAAQ,UAAU;GAClB,OAAO,UAAU;GACjB,aAAa,UAAU;GACvB,SAAS,UAAU;EACrB,CAAC;EACD,qBAAqB,SAAS;EAE9B,gBAAgB,KAAK;GAAE,GAAG;GAAW;EAAU,CAAC;CAClD;CAEA,OAAO;EAAE,QAAQ;EAAa;CAAgB;AAChD"}
1
+ {"version":3,"file":"signTypedDataEntries.js","names":[],"sources":["../../../../../src/core/tasks/helpers/signTypedDataEntries.ts"],"sourcesContent":["import type {\n ExecutionActionStatus,\n ExecutionActionType,\n SignedTypedData,\n TypedData,\n} from '@lifi/sdk'\nimport { signTypedData } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { getDomainChainId } from '../../../utils/getDomainChainId.js'\nimport { assertValidSignature } from '../../../utils/isValidSignature.js'\n\nexport type SignTypedDataEntriesResult =\n | { status: 'PAUSED' }\n | { status: 'COMPLETED'; signedTypedData: SignedTypedData[] }\n\n/**\n * Signs the entries in order, switching chains per entry, and appends the\n * signatures. `beforeSignature` runs right before each wallet call, after the\n * chain switch; it throws to stop the signing.\n */\nexport async function signTypedDataEntries(\n context: EthereumStepExecutorContext,\n entries: TypedData[],\n actionType: ExecutionActionType,\n actionStatus: ExecutionActionStatus = 'ACTION_REQUIRED',\n beforeSignature?: () => void\n): Promise<SignTypedDataEntriesResult> {\n const {\n step,\n statusManager,\n allowUserInteraction,\n checkClient,\n signedTypedData: currentSignedTypedData,\n } = context\n\n const signedTypedData = [...currentSignedTypedData]\n\n // Announced once for the round, not once per entry. Relay-from-Hyperliquid\n // carries two messages, and main told the consumer `MESSAGE_REQUIRED` once.\n if (entries.length) {\n statusManager.updateAction(step, actionType, actionStatus)\n }\n\n for (const typedData of entries) {\n if (!allowUserInteraction) {\n return { status: 'PAUSED' }\n }\n\n const typedDataChainId =\n getDomainChainId(typedData.domain) || step.action.fromChainId\n\n const client = await checkClient(step, typedDataChainId)\n if (!client) {\n return { status: 'PAUSED' }\n }\n\n beforeSignature?.()\n const signature = await getAction(\n client,\n signTypedData,\n 'signTypedData'\n )({\n account: client.account!,\n domain: typedData.domain,\n types: typedData.types,\n primaryType: typedData.primaryType,\n message: typedData.message,\n })\n assertValidSignature(signature)\n\n signedTypedData.push({ ...typedData, signature })\n }\n\n return { status: 'COMPLETED', signedTypedData }\n}\n"],"mappings":";;;;;;;;;;AAqBA,eAAsB,qBACpB,SACA,SACA,YACA,eAAsC,mBACtC,iBACqC;CACrC,MAAM,EACJ,MACA,eACA,sBACA,aACA,iBAAiB,2BACf;CAEJ,MAAM,kBAAkB,CAAC,GAAG,sBAAsB;CAIlD,IAAI,QAAQ,QACV,cAAc,aAAa,MAAM,YAAY,YAAY;CAG3D,KAAK,MAAM,aAAa,SAAS;EAC/B,IAAI,CAAC,sBACH,OAAO,EAAE,QAAQ,SAAS;EAM5B,MAAM,SAAS,MAAM,YAAY,MAF/B,iBAAiB,UAAU,MAAM,KAAK,KAAK,OAAO,WAEG;EACvD,IAAI,CAAC,QACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,kBAAkB;EAClB,MAAM,YAAY,MAAM,UACtB,QACA,eACA,eACF,CAAC,CAAC;GACA,SAAS,OAAO;GAChB,QAAQ,UAAU;GAClB,OAAO,UAAU;GACjB,aAAa,UAAU;GACvB,SAAS,UAAU;EACrB,CAAC;EACD,qBAAqB,SAAS;EAE9B,gBAAgB,KAAK;GAAE,GAAG;GAAW;EAAU,CAAC;CAClD;CAEA,OAAO;EAAE,QAAQ;EAAa;CAAgB;AAChD"}
@@ -1 +1 @@
1
- {"version":3,"file":"parseEthereumErrors.d.ts","names":[],"sources":["../../../src/errors/parseEthereumErrors.ts"],"mappings":";;qBAea,sBACX,GAAG,OACH,OAAO,UACP,SAAS,iBACT,cAAc,2BACb,QAAQ,WAAW;qBA0GT,0CAA2C"}
1
+ {"version":3,"file":"parseEthereumErrors.d.ts","names":[],"sources":["../../../src/errors/parseEthereumErrors.ts"],"mappings":";;qBAea,sBACX,GAAG,OACH,OAAO,UACP,SAAS,iBACT,cAAc,2BACb,QAAQ,WAAW;qBAkHT,0CAA2C"}
@@ -2,7 +2,8 @@ import { BaseError, ErrorMessage, ExecuteStepRetryError, LiFiErrorCode, SDKError
2
2
  import { AtomicReadyWalletRejectedUpgradeError } from "viem";
3
3
  //#region src/errors/parseEthereumErrors.ts
4
4
  const parseEthereumErrors = async (e, step, action, retryParams) => {
5
- if (isAtomicReadyWalletRejectedUpgradeError(e) && !retryParams?.atomicityNotReady) return new ExecuteStepRetryError("Wallet rejected 7702 upgrade based on the EIP-5792 capabilities; retry with atomicityNotReady", { atomicityNotReady: true }, e);
5
+ if (e instanceof ExecuteStepRetryError) return e;
6
+ if (isAtomicReadyWalletRejectedUpgradeError(e) && !retryParams) return new ExecuteStepRetryError("Wallet rejected 7702 upgrade based on the EIP-5792 capabilities; retry with atomicityNotReady", { atomicityNotReady: true }, e);
6
7
  if (e instanceof SDKError) {
7
8
  e.step = e.step ?? step;
8
9
  e.action = e.action ?? action;
@@ -12,7 +13,14 @@ const parseEthereumErrors = async (e, step, action, retryParams) => {
12
13
  return new SDKError(baseError, step, action);
13
14
  };
14
15
  const handleSpecificErrors = async (e, step, action) => {
15
- if (e.name === "UserRejectedRequestError" || e.cause?.name === "UserRejectedRequestError" || e.name === "UnknownBundleIdError") return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e);
16
+ if (e.name === "UserRejectedRequestError" || e.cause?.name === "UserRejectedRequestError") return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e);
17
+ /**
18
+ * The wallet has no record of an EIP-5792 bundle (5730), so the outcome is unknown: the bundle may still land.
19
+ * No call reaches this branch today, because `waitForBatchTransactionReceipt` handles 5730 first. A later call that reaches it gets the unknown outcome.
20
+ * Only the error itself matches: an error of the batched wait carries it as a cause and keeps its own code.
21
+ * @see https://github.com/MetaMask/core/blob/main/packages/eip-5792-middleware/src/hooks/getCallsStatus.ts
22
+ */
23
+ if (e.name === "UnknownBundleIdError") return new TransactionError(LiFiErrorCode.CallBundleNotFound, e.message, e);
16
24
  /**
17
25
  * Safe Wallet via WalletConnect returns -32000 code when user rejects the signature
18
26
  * {
@@ -1 +1 @@
1
- {"version":3,"file":"parseEthereumErrors.js","names":[],"sources":["../../../src/errors/parseEthereumErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n ExecuteStepRetryError,\n type ExecuteStepRetryParams,\n type ExecutionAction,\n fetchTxErrorDetails,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\nimport { AtomicReadyWalletRejectedUpgradeError } from 'viem'\n\nexport const parseEthereumErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction,\n retryParams?: ExecuteStepRetryParams\n): Promise<SDKError | ExecuteStepRetryError> => {\n if (\n isAtomicReadyWalletRejectedUpgradeError(e) &&\n !retryParams?.atomicityNotReady\n ) {\n return new ExecuteStepRetryError(\n 'Wallet rejected 7702 upgrade based on the EIP-5792 capabilities; retry with atomicityNotReady',\n { atomicityNotReady: true },\n e\n )\n }\n\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = await handleSpecificErrors(e, step, action)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = async (\n e: any,\n step?: LiFiStep,\n action?: ExecutionAction\n) => {\n if (\n e.name === 'UserRejectedRequestError' ||\n e.cause?.name === 'UserRejectedRequestError' ||\n /**\n * This error is specific to MetaMask and thrown when the user rejects the signature of the native token transfer, at that point, the bundle id is unknown.\n * @see https://github.com/MetaMask/metamask-extension/blob/main/app/scripts/lib/transaction/eip5792.ts#L141-L146\n */\n e.name === 'UnknownBundleIdError'\n ) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n /**\n * Safe Wallet via WalletConnect returns -32000 code when user rejects the signature\n * {\n * code: -32000,\n * message: 'User rejected transaction',\n * }\n */\n if (\n e.cause?.code === -32000 ||\n // Safe doesn't return proper code, but the error details includes 'rejected'\n (e.name === 'TransactionExecutionError' &&\n e.cause?.details?.includes('rejected'))\n ) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n /**\n * Some wallets reject transactions sometimes with this code because of internal and JSON-RPC errors, e.g.:\n * {\n * \"code\": -32603,\n * \"message\": \"Pop up window failed to open\",\n * \"docUrl\": \"https://docs.cloud.coinbase.com/wallet-sdk/docs/errors\"\n * }\n */\n if (e.cause?.code === -32603) {\n return new TransactionError(LiFiErrorCode.TransactionRejected, e.message, e)\n }\n\n /**\n * This error is specific to Smart Accounts and thrown when the user doesn't have enough gas to pay for the transaction.\n */\n if (\n e.name === 'InsufficientPrefundError' ||\n e.cause?.name === 'InsufficientPrefundError' ||\n e.cause?.cause?.name === 'InsufficientPrefundError'\n ) {\n return new TransactionError(LiFiErrorCode.InsufficientGas, e.message, e)\n }\n\n if (\n step &&\n action?.txHash &&\n e.code === LiFiErrorCode.TransactionFailed &&\n e.message === ErrorMessage.TransactionReverted\n ) {\n const response = await fetchTxErrorDetails(\n action.txHash,\n step.action.fromChainId\n )\n\n const errorMessage = (response as Record<string, string>)?.error_message\n\n if (errorMessage?.toLowerCase().includes('out of gas')) {\n return new TransactionError(\n LiFiErrorCode.GasLimitError,\n ErrorMessage.GasLimitLow,\n e\n )\n }\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n\nexport const isAtomicReadyWalletRejectedUpgradeError = (e: any): boolean => {\n if (e.cause?.code === AtomicReadyWalletRejectedUpgradeError.code) {\n return true\n }\n\n const details = e.cause?.details?.toLowerCase()\n const isTransactionError =\n e.name === 'TransactionExecutionError' ||\n e.cause?.name === 'TransactionExecutionError'\n const hasRejectedUpgrade =\n details?.includes('rejected') && details?.includes('upgrade')\n const has7702ErrorCode = details?.includes('7702')\n\n return isTransactionError && (hasRejectedUpgrade || has7702ErrorCode)\n}\n"],"mappings":";;;AAeA,MAAa,sBAAsB,OACjC,GACA,MACA,QACA,gBAC8C;CAC9C,IACE,wCAAwC,CAAC,KACzC,CAAC,aAAa,mBAEd,OAAO,IAAI,sBACT,iGACA,EAAE,mBAAmB,KAAK,GAC1B,CACF;CAGF,IAAI,aAAa,UAAU;EACzB,EAAE,OAAO,EAAE,QAAQ;EACnB,EAAE,SAAS,EAAE,UAAU;EACvB,OAAO;CACT;CAEA,MAAM,YAAY,MAAM,qBAAqB,GAAG,MAAM,MAAM;CAE5D,OAAO,IAAI,SAAS,WAAW,MAAM,MAAM;AAC7C;AAEA,MAAM,uBAAuB,OAC3B,GACA,MACA,WACG;CACH,IACE,EAAE,SAAS,8BACX,EAAE,OAAO,SAAS,8BAKlB,EAAE,SAAS,wBAEX,OAAO,IAAI,iBAAiB,cAAc,mBAAmB,EAAE,SAAS,CAAC;;;;;;;;CAS3E,IACE,EAAE,OAAO,SAAS,SAEjB,EAAE,SAAS,+BACV,EAAE,OAAO,SAAS,SAAS,UAAU,GAEvC,OAAO,IAAI,iBAAiB,cAAc,mBAAmB,EAAE,SAAS,CAAC;;;;;;;;;CAU3E,IAAI,EAAE,OAAO,SAAS,QACpB,OAAO,IAAI,iBAAiB,cAAc,qBAAqB,EAAE,SAAS,CAAC;;;;CAM7E,IACE,EAAE,SAAS,8BACX,EAAE,OAAO,SAAS,8BAClB,EAAE,OAAO,OAAO,SAAS,4BAEzB,OAAO,IAAI,iBAAiB,cAAc,iBAAiB,EAAE,SAAS,CAAC;CAGzE,IACE,QACA,QAAQ,UACR,EAAE,SAAS,cAAc,qBACzB,EAAE,YAAY,aAAa,qBAOL;QAAA,MALC,oBACrB,OAAO,QACP,KAAK,OAAO,WACd,EAAA,EAE2D,cAAA,EAEzC,YAAY,CAAC,CAAC,SAAS,YAAY,GACnD,OAAO,IAAI,iBACT,cAAc,eACd,aAAa,aACb,CACF;CAAA;CAIJ,IAAI,aAAa,WACf,OAAO;CAGT,OAAO,IAAI,aAAa,EAAE,WAAW,aAAa,cAAc,CAAC;AACnE;AAEA,MAAa,2CAA2C,MAAoB;CAC1E,IAAI,EAAE,OAAO,SAAS,sCAAsC,MAC1D,OAAO;CAGT,MAAM,UAAU,EAAE,OAAO,SAAS,YAAY;CAC9C,MAAM,qBACJ,EAAE,SAAS,+BACX,EAAE,OAAO,SAAS;CACpB,MAAM,qBACJ,SAAS,SAAS,UAAU,KAAK,SAAS,SAAS,SAAS;CAC9D,MAAM,mBAAmB,SAAS,SAAS,MAAM;CAEjD,OAAO,uBAAuB,sBAAsB;AACtD"}
1
+ {"version":3,"file":"parseEthereumErrors.js","names":[],"sources":["../../../src/errors/parseEthereumErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n ExecuteStepRetryError,\n type ExecuteStepRetryParams,\n type ExecutionAction,\n fetchTxErrorDetails,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\nimport { AtomicReadyWalletRejectedUpgradeError } from 'viem'\n\nexport const parseEthereumErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction,\n retryParams?: ExecuteStepRetryParams\n): Promise<SDKError | ExecuteStepRetryError> => {\n // A task raised it to request a replay; it is not an error to classify.\n if (e instanceof ExecuteStepRetryError) {\n return e\n }\n\n // `executeRoute` replays a step only once, so only the first attempt asks for\n // this retry.\n if (isAtomicReadyWalletRejectedUpgradeError(e) && !retryParams) {\n return new ExecuteStepRetryError(\n 'Wallet rejected 7702 upgrade based on the EIP-5792 capabilities; retry with atomicityNotReady',\n { atomicityNotReady: true },\n e\n )\n }\n\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = await handleSpecificErrors(e, step, action)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = async (\n e: any,\n step?: LiFiStep,\n action?: ExecutionAction\n) => {\n if (\n e.name === 'UserRejectedRequestError' ||\n e.cause?.name === 'UserRejectedRequestError'\n ) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n /**\n * The wallet has no record of an EIP-5792 bundle (5730), so the outcome is unknown: the bundle may still land.\n * No call reaches this branch today, because `waitForBatchTransactionReceipt` handles 5730 first. A later call that reaches it gets the unknown outcome.\n * Only the error itself matches: an error of the batched wait carries it as a cause and keeps its own code.\n * @see https://github.com/MetaMask/core/blob/main/packages/eip-5792-middleware/src/hooks/getCallsStatus.ts\n */\n if (e.name === 'UnknownBundleIdError') {\n return new TransactionError(LiFiErrorCode.CallBundleNotFound, e.message, e)\n }\n /**\n * Safe Wallet via WalletConnect returns -32000 code when user rejects the signature\n * {\n * code: -32000,\n * message: 'User rejected transaction',\n * }\n */\n if (\n e.cause?.code === -32000 ||\n // Safe doesn't return proper code, but the error details includes 'rejected'\n (e.name === 'TransactionExecutionError' &&\n e.cause?.details?.includes('rejected'))\n ) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n /**\n * Some wallets reject transactions sometimes with this code because of internal and JSON-RPC errors, e.g.:\n * {\n * \"code\": -32603,\n * \"message\": \"Pop up window failed to open\",\n * \"docUrl\": \"https://docs.cloud.coinbase.com/wallet-sdk/docs/errors\"\n * }\n */\n if (e.cause?.code === -32603) {\n return new TransactionError(LiFiErrorCode.TransactionRejected, e.message, e)\n }\n\n /**\n * This error is specific to Smart Accounts and thrown when the user doesn't have enough gas to pay for the transaction.\n */\n if (\n e.name === 'InsufficientPrefundError' ||\n e.cause?.name === 'InsufficientPrefundError' ||\n e.cause?.cause?.name === 'InsufficientPrefundError'\n ) {\n return new TransactionError(LiFiErrorCode.InsufficientGas, e.message, e)\n }\n\n if (\n step &&\n action?.txHash &&\n e.code === LiFiErrorCode.TransactionFailed &&\n e.message === ErrorMessage.TransactionReverted\n ) {\n const response = await fetchTxErrorDetails(\n action.txHash,\n step.action.fromChainId\n )\n\n const errorMessage = (response as Record<string, string>)?.error_message\n\n if (errorMessage?.toLowerCase().includes('out of gas')) {\n return new TransactionError(\n LiFiErrorCode.GasLimitError,\n ErrorMessage.GasLimitLow,\n e\n )\n }\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n\nexport const isAtomicReadyWalletRejectedUpgradeError = (e: any): boolean => {\n if (e.cause?.code === AtomicReadyWalletRejectedUpgradeError.code) {\n return true\n }\n\n const details = e.cause?.details?.toLowerCase()\n const isTransactionError =\n e.name === 'TransactionExecutionError' ||\n e.cause?.name === 'TransactionExecutionError'\n const hasRejectedUpgrade =\n details?.includes('rejected') && details?.includes('upgrade')\n const has7702ErrorCode = details?.includes('7702')\n\n return isTransactionError && (hasRejectedUpgrade || has7702ErrorCode)\n}\n"],"mappings":";;;AAeA,MAAa,sBAAsB,OACjC,GACA,MACA,QACA,gBAC8C;CAE9C,IAAI,aAAa,uBACf,OAAO;CAKT,IAAI,wCAAwC,CAAC,KAAK,CAAC,aACjD,OAAO,IAAI,sBACT,iGACA,EAAE,mBAAmB,KAAK,GAC1B,CACF;CAGF,IAAI,aAAa,UAAU;EACzB,EAAE,OAAO,EAAE,QAAQ;EACnB,EAAE,SAAS,EAAE,UAAU;EACvB,OAAO;CACT;CAEA,MAAM,YAAY,MAAM,qBAAqB,GAAG,MAAM,MAAM;CAE5D,OAAO,IAAI,SAAS,WAAW,MAAM,MAAM;AAC7C;AAEA,MAAM,uBAAuB,OAC3B,GACA,MACA,WACG;CACH,IACE,EAAE,SAAS,8BACX,EAAE,OAAO,SAAS,4BAElB,OAAO,IAAI,iBAAiB,cAAc,mBAAmB,EAAE,SAAS,CAAC;;;;;;;CAQ3E,IAAI,EAAE,SAAS,wBACb,OAAO,IAAI,iBAAiB,cAAc,oBAAoB,EAAE,SAAS,CAAC;;;;;;;;CAS5E,IACE,EAAE,OAAO,SAAS,SAEjB,EAAE,SAAS,+BACV,EAAE,OAAO,SAAS,SAAS,UAAU,GAEvC,OAAO,IAAI,iBAAiB,cAAc,mBAAmB,EAAE,SAAS,CAAC;;;;;;;;;CAU3E,IAAI,EAAE,OAAO,SAAS,QACpB,OAAO,IAAI,iBAAiB,cAAc,qBAAqB,EAAE,SAAS,CAAC;;;;CAM7E,IACE,EAAE,SAAS,8BACX,EAAE,OAAO,SAAS,8BAClB,EAAE,OAAO,OAAO,SAAS,4BAEzB,OAAO,IAAI,iBAAiB,cAAc,iBAAiB,EAAE,SAAS,CAAC;CAGzE,IACE,QACA,QAAQ,UACR,EAAE,SAAS,cAAc,qBACzB,EAAE,YAAY,aAAa,qBAOL;QAAA,MALC,oBACrB,OAAO,QACP,KAAK,OAAO,WACd,EAAA,EAE2D,cAAA,EAEzC,YAAY,CAAC,CAAC,SAAS,YAAY,GACnD,OAAO,IAAI,iBACT,cAAc,eACd,aAAa,aACb,CACF;CAAA;CAIJ,IAAI,aAAa,WACf,OAAO;CAGT,OAAO,IAAI,aAAa,EAAE,WAAW,aAAa,cAAc,CAAC;AACnE;AAEA,MAAa,2CAA2C,MAAoB;CAC1E,IAAI,EAAE,OAAO,SAAS,sCAAsC,MAC1D,OAAO;CAGT,MAAM,UAAU,EAAE,OAAO,SAAS,YAAY;CAC9C,MAAM,qBACJ,EAAE,SAAS,+BACX,EAAE,OAAO,SAAS;CACpB,MAAM,qBACJ,SAAS,SAAS,UAAU,KAAK,SAAS,SAAS,SAAS;CAC9D,MAAM,mBAAmB,SAAS,SAAS,MAAM;CAEjD,OAAO,uBAAuB,sBAAsB;AACtD"}
@@ -17,6 +17,12 @@ export interface EthereumTaskContext {
17
17
  hasMatchingPermit?: boolean;
18
18
  hasAllowance?: boolean;
19
19
  hasSufficientAllowance?: boolean;
20
+ /**
21
+ * The spender `EthereumCheckAllowanceTask` checked the allowance against. The
22
+ * other allowance tasks approve the same one. Prepare compares it with the
23
+ * spender of the strategy it establishes.
24
+ */
25
+ allowanceSpender?: Address;
20
26
  /**
21
27
  * Whether the signer can produce a Permit2-verifiable signature — the
22
28
  * in-flight or settled lookup, memoized per execution by
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":["_WalletCallReceipt"],"sources":["../../src/types.ts"],"mappings":";;;iBAqBiB;EACf,wBAAwB,QAAQ;EAChC,eAAe,oBAAoB,QAAQ;EAC3C,0BAA0B;EAC1B;EACA;;iBAGe;EACf;EACA,qBAAqB;EACrB,oBAAoB;EACpB,OAAO;EACP,iBAAiB;EACjB;EACA;EACA;;;;;;;;;EASA,yBAAyB;;iBAGV,oCACP,qBACN;EACF;EACA,gBAAgB;EAChB,cACE,MAAM,kBACN,2BACG,QAAQ;EACb,eAAe,oBAAoB,QAAQ;EAC3C,aAAa,QAAQ,cAAc;;EAEnC,cAAc;;iBAGC,4BAA4B;EAC3C,SAAS;EACT,WAAW,SAAS;EACpB,oBAAoB,QAAQ;;wBAGd,mBACd,UAAU,cACT,YAAY;YAIH;EACV,OAAO;EACP;;YAGU;EACV,OAAO;EACP;;YAGU;EACV,OAAO;EACP;EACA;;iBAGe;EACf,cAAc;EACd,OAAO;EACP;EACA;;iBAGe;EACf,cAAc;EACd,OAAO;EACP;;YAGU;EACV,IAAI;EACJ,OAAO;EACP;EACA;;YAGU,oBAAoBA;EAI9B;;YAGU,eAAe,mBAAmB;EAC5C,WAAW,aAAa,mBAAmB"}
1
+ {"version":3,"file":"types.d.ts","names":["_WalletCallReceipt"],"sources":["../../src/types.ts"],"mappings":";;;iBAqBiB;EACf,wBAAwB,QAAQ;EAChC,eAAe,oBAAoB,QAAQ;EAC3C,0BAA0B;EAC1B;EACA;;iBAGe;EACf;EACA,qBAAqB;EACrB,oBAAoB;EACpB,OAAO;EACP,iBAAiB;EACjB;EACA;EACA;;;;;;EAMA,mBAAmB;;;;;;;;;EASnB,yBAAyB;;iBAGV,oCACP,qBACN;EACF;EACA,gBAAgB;EAChB,cACE,MAAM,kBACN,2BACG,QAAQ;EACb,eAAe,oBAAoB,QAAQ;EAC3C,aAAa,QAAQ,cAAc;;EAEnC,cAAc;;iBAGC,4BAA4B;EAC3C,SAAS;EACT,WAAW,SAAS;EACpB,oBAAoB,QAAQ;;wBAGd,mBACd,UAAU,cACT,YAAY;YAIH;EACV,OAAO;EACP;;YAGU;EACV,OAAO;EACP;;YAGU;EACV,OAAO;EACP;EACA;;iBAGe;EACf,cAAc;EACd,OAAO;EACP;EACA;;iBAGe;EACf,cAAc;EACd,OAAO;EACP;;YAGU;EACV,IAAI;EACJ,OAAO;EACP;EACA;;YAGU,oBAAoBA;EAI9B;;YAGU,eAAe,mBAAmB;EAC5C,WAAW,aAAa,mBAAmB"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../src/types.ts"],"sourcesContent":["import {\n type BaseToken,\n ChainType,\n type LiFiStep,\n type LiFiStepExtended,\n type SDKClient,\n type SDKProvider,\n type SDKStorage,\n type SignedTypedData,\n type StepExecutorContext,\n type TransactionMethodType,\n type TransactionParameters,\n} from '@lifi/sdk'\nimport type {\n WalletCallReceipt as _WalletCallReceipt,\n Address,\n Client,\n FallbackTransportConfig,\n Hex,\n} from 'viem'\n\nexport interface EthereumProviderOptions {\n getWalletClient?: () => Promise<Client>\n switchChain?: (chainId: number) => Promise<Client | undefined>\n fallbackTransportConfig?: FallbackTransportConfig\n safeApiKey?: string\n disableMessageSigning?: boolean\n}\n\nexport interface EthereumTaskContext {\n disableMessageSigning: boolean\n transactionRequest?: TransactionParameters\n executionStrategy?: TransactionMethodType\n calls: Call[]\n signedTypedData: SignedTypedData[]\n hasMatchingPermit?: boolean\n hasAllowance?: boolean\n hasSufficientAllowance?: boolean\n /**\n * Whether the signer can produce a Permit2-verifiable signature — the\n * in-flight or settled lookup, memoized per execution by\n * `resolvePermit2Support` so the allowance tasks and the sign-and-execute task\n * can't disagree. Deliberately the promise and not a `boolean`: that would\n * be a tri-state (unresolved / yes / no) whose `false` case is\n * indistinguishable from \"not looked up yet\" under a truthiness check.\n */\n permit2SignerSupported?: Promise<boolean>\n}\n\nexport interface EthereumStepExecutorContext\n extends StepExecutorContext,\n EthereumTaskContext {\n isFromNativeToken: boolean\n ethereumClient: Client\n checkClient: (\n step: LiFiStepExtended,\n targetChainId?: number\n ) => Promise<Client | undefined>\n switchChain?: (chainId: number) => Promise<Client | undefined>\n getStorage: (client: SDKClient) => SDKStorage\n /** Params passed when retrying executeStep (e.g. atomicityNotReady for 7702). */\n retryParams?: Record<string, unknown>\n}\n\nexport interface EthereumSDKProvider extends SDKProvider {\n options: EthereumProviderOptions\n setOptions(options: EthereumProviderOptions): void\n getWalletClient?(): Promise<Client>\n}\n\nexport function isEthereumProvider(\n provider: SDKProvider\n): provider is EthereumSDKProvider {\n return provider.type === ChainType.EVM\n}\n\nexport type TokenSpender = {\n token: BaseToken\n spenderAddress: string\n}\n\nexport type TokenAllowance = {\n token: BaseToken\n allowance?: bigint\n}\n\nexport type TokenSpenderAllowance = {\n token: BaseToken\n spenderAddress: string\n allowance?: bigint\n}\n\nexport interface ApproveTokenRequest {\n walletClient: Client\n token: BaseToken\n spenderAddress: string\n amount: bigint\n}\n\nexport interface RevokeApprovalRequest {\n walletClient: Client\n token: BaseToken\n spenderAddress: string\n}\n\nexport type Call = {\n to: Address\n data?: Hex\n value?: bigint\n chainId?: number\n}\n\nexport type WalletCallReceipt = _WalletCallReceipt<\n bigint,\n 'success' | 'reverted'\n> & {\n transactionLink?: string\n}\n\nexport type RelayerStep = (LiFiStepExtended | LiFiStep) & {\n typedData: NonNullable<(LiFiStepExtended | LiFiStep)['typedData']>\n}\n"],"mappings":";;AAsEA,SAAgB,mBACd,UACiC;CACjC,OAAO,SAAS,SAAS,UAAU;AACrC"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../src/types.ts"],"sourcesContent":["import {\n type BaseToken,\n ChainType,\n type LiFiStep,\n type LiFiStepExtended,\n type SDKClient,\n type SDKProvider,\n type SDKStorage,\n type SignedTypedData,\n type StepExecutorContext,\n type TransactionMethodType,\n type TransactionParameters,\n} from '@lifi/sdk'\nimport type {\n WalletCallReceipt as _WalletCallReceipt,\n Address,\n Client,\n FallbackTransportConfig,\n Hex,\n} from 'viem'\n\nexport interface EthereumProviderOptions {\n getWalletClient?: () => Promise<Client>\n switchChain?: (chainId: number) => Promise<Client | undefined>\n fallbackTransportConfig?: FallbackTransportConfig\n safeApiKey?: string\n disableMessageSigning?: boolean\n}\n\nexport interface EthereumTaskContext {\n disableMessageSigning: boolean\n transactionRequest?: TransactionParameters\n executionStrategy?: TransactionMethodType\n calls: Call[]\n signedTypedData: SignedTypedData[]\n hasMatchingPermit?: boolean\n hasAllowance?: boolean\n hasSufficientAllowance?: boolean\n /**\n * The spender `EthereumCheckAllowanceTask` checked the allowance against. The\n * other allowance tasks approve the same one. Prepare compares it with the\n * spender of the strategy it establishes.\n */\n allowanceSpender?: Address\n /**\n * Whether the signer can produce a Permit2-verifiable signature — the\n * in-flight or settled lookup, memoized per execution by\n * `resolvePermit2Support` so the allowance tasks and the sign-and-execute task\n * can't disagree. Deliberately the promise and not a `boolean`: that would\n * be a tri-state (unresolved / yes / no) whose `false` case is\n * indistinguishable from \"not looked up yet\" under a truthiness check.\n */\n permit2SignerSupported?: Promise<boolean>\n}\n\nexport interface EthereumStepExecutorContext\n extends StepExecutorContext,\n EthereumTaskContext {\n isFromNativeToken: boolean\n ethereumClient: Client\n checkClient: (\n step: LiFiStepExtended,\n targetChainId?: number\n ) => Promise<Client | undefined>\n switchChain?: (chainId: number) => Promise<Client | undefined>\n getStorage: (client: SDKClient) => SDKStorage\n /** Params passed when retrying executeStep (e.g. atomicityNotReady for 7702). */\n retryParams?: Record<string, unknown>\n}\n\nexport interface EthereumSDKProvider extends SDKProvider {\n options: EthereumProviderOptions\n setOptions(options: EthereumProviderOptions): void\n getWalletClient?(): Promise<Client>\n}\n\nexport function isEthereumProvider(\n provider: SDKProvider\n): provider is EthereumSDKProvider {\n return provider.type === ChainType.EVM\n}\n\nexport type TokenSpender = {\n token: BaseToken\n spenderAddress: string\n}\n\nexport type TokenAllowance = {\n token: BaseToken\n allowance?: bigint\n}\n\nexport type TokenSpenderAllowance = {\n token: BaseToken\n spenderAddress: string\n allowance?: bigint\n}\n\nexport interface ApproveTokenRequest {\n walletClient: Client\n token: BaseToken\n spenderAddress: string\n amount: bigint\n}\n\nexport interface RevokeApprovalRequest {\n walletClient: Client\n token: BaseToken\n spenderAddress: string\n}\n\nexport type Call = {\n to: Address\n data?: Hex\n value?: bigint\n chainId?: number\n}\n\nexport type WalletCallReceipt = _WalletCallReceipt<\n bigint,\n 'success' | 'reverted'\n> & {\n transactionLink?: string\n}\n\nexport type RelayerStep = (LiFiStepExtended | LiFiStep) & {\n typedData: NonNullable<(LiFiStepExtended | LiFiStep)['typedData']>\n}\n"],"mappings":";;AA4EA,SAAgB,mBACd,UACiC;CACjC,OAAO,SAAS,SAAS,UAAU;AACrC"}
@@ -1,5 +1,5 @@
1
1
  //#region src/version.d.ts
2
2
  export declare const name = "@lifi/sdk-provider-ethereum";
3
- export declare const version = "4.2.6";
3
+ export declare const version = "4.2.8";
4
4
  //#endregion
5
5
  //# sourceMappingURL=version.d.ts.map
@@ -1,6 +1,6 @@
1
1
  //#region src/version.ts
2
2
  const name = "@lifi/sdk-provider-ethereum";
3
- const version = "4.2.6";
3
+ const version = "4.2.8";
4
4
  //#endregion
5
5
  export { name, version };
6
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-ethereum'\nexport const version = '4.2.6'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
1
+ {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-ethereum'\nexport const version = '4.2.8'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/sdk-provider-ethereum",
3
- "version": "4.2.6",
3
+ "version": "4.2.8",
4
4
  "description": "LI.FI Ethereum SDK Provider for Any-to-Any Cross-Chain-Swap",
5
5
  "homepage": "https://github.com/lifinance/sdk",
6
6
  "bugs": {
@@ -28,8 +28,8 @@
28
28
  "./package.json": "./package.json"
29
29
  },
30
30
  "dependencies": {
31
- "@lifi/sdk": "4.10.0",
32
- "viem": "^2.57.1"
31
+ "@lifi/sdk": "4.12.0",
32
+ "viem": "^2.57.3"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"
@@ -10,6 +10,11 @@ function isEthereumTokenAddress(address: string): boolean {
10
10
  return isAddress(address, { strict: false })
11
11
  }
12
12
 
13
+ /** viem reads a second argument as options, so a chain ID must not reach it. */
14
+ function isEthereumAddress(address: string): boolean {
15
+ return isAddress(address)
16
+ }
17
+
13
18
  export function EthereumProvider(
14
19
  options?: EthereumProviderOptions
15
20
  ): EthereumSDKProvider {
@@ -21,7 +26,7 @@ export function EthereumProvider(
21
26
  get options() {
22
27
  return _options
23
28
  },
24
- isAddress,
29
+ isAddress: isEthereumAddress,
25
30
  isTokenAddress: isEthereumTokenAddress,
26
31
  resolveAddress: resolveEthereumAddress,
27
32
  getBalance: getEthereumBalance,
@@ -1,28 +1,122 @@
1
1
  import { LiFiErrorCode, TransactionError } from '@lifi/sdk'
2
- import type { Client, Hash } from 'viem'
2
+ import { type Client, type Hash, UnknownBundleIdError } from 'viem'
3
3
  import { type GetCallsStatusReturnType, waitForCallsStatus } from 'viem/actions'
4
4
  import { getAction } from 'viem/utils'
5
5
  import type { WalletCallReceipt } from '../types.js'
6
6
 
7
+ // Some wallets answer from a remote service that can forget an old bundle.
8
+ const DROPPED_BUNDLE_MAX_AGE_MS = 10 * 60_000
9
+
10
+ const isUnknownBundleIdError = (error: any): boolean =>
11
+ error?.name === 'UnknownBundleIdError' ||
12
+ error?.cause?.name === 'UnknownBundleIdError' ||
13
+ error?.code === UnknownBundleIdError.code
14
+
15
+ /**
16
+ * Unknown signing time is never in the window. Nor is a signing time in the
17
+ * future, as in `isResendAllowed`.
18
+ */
19
+ const isWithinDropWindow = (signedAt: number | undefined): boolean => {
20
+ const now = Date.now()
21
+ return (
22
+ signedAt !== undefined &&
23
+ now >= signedAt &&
24
+ now - signedAt < DROPPED_BUNDLE_MAX_AGE_MS
25
+ )
26
+ }
27
+
28
+ /**
29
+ * Waits until the wallet reports the EIP-5792 call bundle as done or failed.
30
+ *
31
+ * MetaMask returns the id of a single-call bundle before the user approves
32
+ * it, and removes the bundle on a reject: `wallet_getCallsStatus` then fails
33
+ * with 5730 (`UnknownBundleIdError`). It returns the id of a bundle of two or
34
+ * more calls only after it sent the bundle. Thus the SDK treats a bundle as
35
+ * never sent only when all of these are true: its stored `callCount` is 1,
36
+ * the wallet answered for it in this wait and then has no record of it, and
37
+ * this happens within `DROPPED_BUNDLE_MAX_AGE_MS` of signing.
38
+ *
39
+ * @param client - The wallet client that sent the bundle.
40
+ * @param batchHash - The bundle id that `wallet_sendCalls` returned.
41
+ * @param options.onFailed - Gets the wallet's answer for a failed bundle, before the error is thrown.
42
+ * @param options.signedAt - The signing time of the step (`execution.signedAt`).
43
+ * @param options.callCount - The stored number of calls of the bundle (`action.callCount`).
44
+ * @returns The receipt of the last call of the bundle.
45
+ * @throws {TransactionError} If the bundle failed, was canceled, or the wallet has no record of it. A bundle that the SDK treats as never sent is a final `SignatureRejected`. Any other bundle without a record is `CallBundleNotFound`, which is not final.
46
+ * @throws Any other error of the wallet, unchanged.
47
+ */
7
48
  export const waitForBatchTransactionReceipt = async (
8
49
  client: Client,
9
50
  batchHash: Hash,
10
- onFailed?: (result: GetCallsStatusReturnType) => void
51
+ {
52
+ onFailed,
53
+ signedAt,
54
+ callCount,
55
+ }: {
56
+ onFailed?: (result: GetCallsStatusReturnType) => void
57
+ signedAt?: number
58
+ callCount?: number
59
+ } = {}
11
60
  ): Promise<WalletCallReceipt> => {
12
- const result = await getAction(
13
- client,
14
- waitForCallsStatus,
15
- 'waitForCallsStatus'
16
- )({
17
- id: batchHash,
18
- timeout: 3_600_000 * 24,
19
- })
61
+ let known = false
62
+ let result: GetCallsStatusReturnType
63
+ try {
64
+ result = await getAction(
65
+ client,
66
+ waitForCallsStatus,
67
+ 'waitForCallsStatus'
68
+ )({
69
+ id: batchHash,
70
+ timeout: 3_600_000 * 24,
71
+ // viem's default, and a record that the wallet answered for this id.
72
+ // viem shares one poll between waits for the same client and id, and
73
+ // calls only the predicate of the wait that started it.
74
+ status: ({ statusCode }) => {
75
+ known = true
76
+ return statusCode === 200 || statusCode >= 300
77
+ },
78
+ })
79
+ } catch (error) {
80
+ if (!isUnknownBundleIdError(error)) {
81
+ throw error
82
+ }
83
+ // MetaMask removes a single-call bundle in this way only before it sends
84
+ // it. The SDK treats the bundle as never sent: a final rejection, so
85
+ // "Try again" signs anew.
86
+ if (known && callCount === 1 && isWithinDropWindow(signedAt)) {
87
+ throw new TransactionError(
88
+ LiFiErrorCode.SignatureRejected,
89
+ 'The wallet has no record of the call bundle. The SDK treats it as never sent.',
90
+ error as Error,
91
+ { final: true }
92
+ )
93
+ }
94
+ // Unknown from the first answer (a reload after the reject, another
95
+ // wallet), too long after signing, or no stored count of one call (two
96
+ // or more calls, or a route stored without the count): the bundle may
97
+ // still land.
98
+ throw new TransactionError(
99
+ LiFiErrorCode.CallBundleNotFound,
100
+ 'The wallet has no record of the call bundle.',
101
+ error as Error
102
+ )
103
+ }
20
104
 
21
105
  if (result.status === 'success') {
106
+ if (result.receipts?.some((receipt) => receipt.status === 'reverted')) {
107
+ onFailed?.(result)
108
+ throw new TransactionError(
109
+ LiFiErrorCode.TransactionFailed,
110
+ 'Transaction was reverted.',
111
+ undefined,
112
+ { final: true }
113
+ )
114
+ }
115
+ // The wallet reports the batch as executed, but without a complete set of
116
+ // receipts we cannot prove the outcome: it stays unknown.
22
117
  if (
23
118
  !result.receipts?.length ||
24
- !result.receipts.every((receipt) => receipt.transactionHash) ||
25
- result.receipts.some((receipt) => receipt.status === 'reverted')
119
+ !result.receipts.every((receipt) => receipt.transactionHash)
26
120
  ) {
27
121
  onFailed?.(result)
28
122
  throw new TransactionError(
@@ -37,10 +131,22 @@ export const waitForBatchTransactionReceipt = async (
37
131
  onFailed?.(result)
38
132
  throw new TransactionError(
39
133
  LiFiErrorCode.TransactionCanceled,
40
- 'Transaction was canceled.'
134
+ 'Transaction was canceled.',
135
+ undefined,
136
+ { final: true }
41
137
  )
42
138
  }
43
139
  onFailed?.(result)
140
+ // Only 500 (reverted completely) is final. Some calls of a partial batch
141
+ // (600) may be onchain, and other codes are undefined: the outcome is unknown.
142
+ if (result.statusCode === 500) {
143
+ throw new TransactionError(
144
+ LiFiErrorCode.TransactionFailed,
145
+ 'Transaction failed.',
146
+ undefined,
147
+ { final: true }
148
+ )
149
+ }
44
150
  throw new TransactionError(
45
151
  LiFiErrorCode.TransactionFailed,
46
152
  'Transaction failed.'
@@ -11,20 +11,52 @@ import {
11
11
  import type { Hash } from 'viem'
12
12
  import type { WalletCallReceipt } from '../types.js'
13
13
 
14
+ /**
15
+ * Polls the relayer until the relayed transaction is done or has failed.
16
+ *
17
+ * @param client - {@link SDKClient}
18
+ * @param taskId - The relayer task id.
19
+ * @param step - The step the task belongs to.
20
+ * @param timeout - How long to wait for a result in milliseconds. Defaults to 24 hours.
21
+ * @param signal - Ends the wait: no status request starts after it aborts, and the request in flight and the sleep end at once.
22
+ * @returns The receipt of the relayed transaction.
23
+ * @throws {TransactionError} If the transaction failed, was not found, or no result arrived before the timeout. Only the failed transaction is a final outcome.
24
+ * @throws The abort reason of `signal` once it aborts.
25
+ */
14
26
  export const waitForRelayedTransactionReceipt = async (
15
27
  client: SDKClient,
16
28
  taskId: Hash,
17
- step: LiFiStep
29
+ step: LiFiStep,
30
+ timeout: number = 3_600_000 * 24,
31
+ signal?: AbortSignal
18
32
  ): Promise<WalletCallReceipt> => {
33
+ const startTime = Date.now()
19
34
  return waitForResult(
20
35
  async () => {
21
- const result = await getRelayedTransactionStatus(client, {
22
- taskId,
23
- fromChain: step.action.fromChainId,
24
- toChain: step.action.toChainId,
25
- ...(step.tool !== 'custom' && { bridge: step.tool }),
26
- }).catch((e) => {
27
- if (process.env.NODE_ENV === 'development') {
36
+ // Without this check, a task that stays PENDING is polled forever:
37
+ // PENDING is not an error, so the retry limit does not apply.
38
+ // TransactionFailed is not retried, so this ends the poll. Not final:
39
+ // the relayer may still execute the task, so the action keeps its task
40
+ // id and a resume waits for it again instead of signing a new one.
41
+ if (Date.now() - startTime > timeout) {
42
+ throw new TransactionError(
43
+ LiFiErrorCode.TransactionFailed,
44
+ 'Relayed transaction timed out waiting for a result.'
45
+ )
46
+ }
47
+
48
+ const result = await getRelayedTransactionStatus(
49
+ client,
50
+ {
51
+ taskId,
52
+ fromChain: step.action.fromChainId,
53
+ toChain: step.action.toChainId,
54
+ ...(step.tool !== 'custom' && { bridge: step.tool }),
55
+ },
56
+ { signal }
57
+ ).catch((e) => {
58
+ // A request that the abort ended is no failure of the relayer.
59
+ if (process.env.NODE_ENV === 'development' && !signal?.aborted) {
28
60
  console.debug('Fetching status from relayer failed.', e)
29
61
  }
30
62
  return undefined
@@ -48,7 +80,9 @@ export const waitForRelayedTransactionReceipt = async (
48
80
  case 'FAILED':
49
81
  throw new TransactionError(
50
82
  LiFiErrorCode.TransactionFailed,
51
- 'Transaction was reverted.'
83
+ 'Transaction was reverted.',
84
+ undefined,
85
+ { final: true }
52
86
  )
53
87
  default:
54
88
  throw new TransactionError(
@@ -64,6 +98,7 @@ export const waitForRelayedTransactionReceipt = async (
64
98
  error instanceof TransactionError &&
65
99
  error.code === LiFiErrorCode.TransactionFailed
66
100
  )
67
- }
101
+ },
102
+ signal
68
103
  )
69
104
  }
@@ -77,7 +77,9 @@ export async function waitForSafeTransactionExecution(
77
77
  if (!tx.isSuccessful) {
78
78
  throw new TransactionError(
79
79
  LiFiErrorCode.TransactionFailed,
80
- 'Safe transaction failed.'
80
+ 'Safe transaction failed.',
81
+ undefined,
82
+ { final: true }
81
83
  )
82
84
  }
83
85
  if (!tx.transactionHash) {
@@ -101,7 +103,9 @@ export async function waitForSafeTransactionExecution(
101
103
  if (replaced) {
102
104
  throw new TransactionError(
103
105
  LiFiErrorCode.TransactionCanceled,
104
- 'Safe transaction was replaced by another transaction.'
106
+ 'Safe transaction was replaced by another transaction.',
107
+ undefined,
108
+ { final: true }
105
109
  )
106
110
  }
107
111
  }
@@ -47,7 +47,9 @@ export async function waitForTransactionReceipt(
47
47
  if (transactionReceipt?.status === 'reverted') {
48
48
  throw new TransactionError(
49
49
  LiFiErrorCode.TransactionFailed,
50
- 'Transaction was reverted.'
50
+ 'Transaction was reverted.',
51
+ undefined,
52
+ { final: true }
51
53
  )
52
54
  }
53
55
  // We should only allow repriced transaction to continue the execution.
@@ -55,7 +57,9 @@ export async function waitForTransactionReceipt(
55
57
  if (replacementReason === 'cancelled' || replacementReason === 'replaced') {
56
58
  throw new TransactionError(
57
59
  LiFiErrorCode.TransactionCanceled,
58
- 'Transaction was canceled or replaced.'
60
+ 'Transaction was canceled or replaced.',
61
+ undefined,
62
+ { final: true }
59
63
  )
60
64
  }
61
65
 
@@ -5,8 +5,10 @@ import { type Chain, mainnet } from 'viem/chains'
5
5
  import { UNS_PROXY_READER_ADDRESSES } from '../actions/constants.js'
6
6
  import type { EthereumSDKProvider } from '../types.js'
7
7
 
8
- // cached providers
9
- const publicClients: Record<number, Client> = {}
8
+ // One client per chain. The cache holds the build promise, not the client,
9
+ // so concurrent first calls share one build: each extra client would keep
10
+ // its own fallback ranking loop running.
11
+ const publicClients = new Map<number, Promise<Client>>()
10
12
 
11
13
  /**
12
14
  * Get an instance of a provider for a specific chain
@@ -14,14 +16,26 @@ const publicClients: Record<number, Client> = {}
14
16
  * @param chainId - Id of the chain the provider is for
15
17
  * @returns The public client for the given chain
16
18
  */
17
- export const getPublicClient = async (
19
+ export const getPublicClient = (
18
20
  client: SDKClient,
19
21
  chainId: number
20
22
  ): Promise<Client> => {
21
- if (publicClients[chainId]) {
22
- return publicClients[chainId]
23
+ let publicClient = publicClients.get(chainId)
24
+ if (!publicClient) {
25
+ // A failed build is removed, so the next call builds again.
26
+ publicClient = buildPublicClient(client, chainId).catch((error) => {
27
+ publicClients.delete(chainId)
28
+ throw error
29
+ })
30
+ publicClients.set(chainId, publicClient)
23
31
  }
32
+ return publicClient
33
+ }
24
34
 
35
+ const buildPublicClient = async (
36
+ client: SDKClient,
37
+ chainId: number
38
+ ): Promise<Client> => {
25
39
  const urls = await client.getRpcUrlsByChainId(chainId)
26
40
  const fallbackTransports = urls.map((url) =>
27
41
  url.startsWith('wss')
@@ -63,7 +77,7 @@ export const getPublicClient = async (
63
77
  const provider = client.getProvider(ChainType.EVM) as
64
78
  | EthereumSDKProvider
65
79
  | undefined
66
- publicClients[chainId] = createClient({
80
+ return createClient({
67
81
  chain: chain,
68
82
  transport: fallback(
69
83
  fallbackTransports,
@@ -73,6 +87,4 @@ export const getPublicClient = async (
73
87
  multicall: true,
74
88
  },
75
89
  })
76
-
77
- return publicClients[chainId]
78
90
  }
@@ -4,6 +4,7 @@ import {
4
4
  type ExecuteStepRetryError,
5
5
  type ExecuteStepRetryParams,
6
6
  type ExecutionAction,
7
+ hasOpenTransaction,
7
8
  LiFiErrorCode,
8
9
  type LiFiStepExtended,
9
10
  type SDKClient,
@@ -170,12 +171,13 @@ export class EthereumStepExecutor extends BaseStepExecutor {
170
171
  step,
171
172
  isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
172
173
  )
173
- firstTask =
174
- swapOrBridgeAction?.txHash || swapOrBridgeAction?.taskId
175
- ? swapOrBridgeAction?.status === 'DONE'
176
- ? EthereumWaitForTransactionStatusTask
177
- : EthereumWaitForTransactionTask
178
- : EthereumCheckBalanceTask
174
+ // Same predicate as the pre-sign guard: an open transaction is waited
175
+ // for, a FAILED action with a final outcome signs again.
176
+ firstTask = hasOpenTransaction(swapOrBridgeAction)
177
+ ? swapOrBridgeAction?.status === 'DONE'
178
+ ? EthereumWaitForTransactionStatusTask
179
+ : EthereumWaitForTransactionTask
180
+ : EthereumCheckBalanceTask
179
181
  }
180
182
 
181
183
  // Compare classes, not names: a minifier can give two task classes the
@@ -1,5 +1,7 @@
1
1
  import {
2
+ assertNoOpenTransaction,
2
3
  BaseStepExecutionTask,
4
+ CLEARED_TRANSACTION_FIELDS,
3
5
  LiFiErrorCode,
4
6
  type TaskResult,
5
7
  TransactionError,
@@ -56,6 +58,11 @@ export class EthereumBatchedSignAndExecuteTask extends BaseStepExecutionTask {
56
58
 
57
59
  calls.push(transferCall)
58
60
 
61
+ // Checked again right before the wallet: a late write of an older run
62
+ // can merge its transaction into this action during the awaits above
63
+ // (strategy, chain switch).
64
+ assertNoOpenTransaction(statusManager.findAction(step, action.type))
65
+
59
66
  const { id } = await getAction(
60
67
  updatedClient,
61
68
  sendCalls,
@@ -66,8 +73,12 @@ export class EthereumBatchedSignAndExecuteTask extends BaseStepExecutionTask {
66
73
  })
67
74
 
68
75
  statusManager.updateAction(step, action.type, 'PENDING', {
76
+ // A new transaction: nothing of the previous one may survive, least of
77
+ // all its `txFinal` verdict.
78
+ ...CLEARED_TRANSACTION_FIELDS,
69
79
  taskId: id as Hash,
70
80
  txType: 'batched',
81
+ callCount: calls.length,
71
82
  signedAt: Date.now(),
72
83
  })
73
84