@lifi/sdk-provider-ethereum 4.2.10 → 4.2.12

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 (44) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/actions/isSafeWallet.js +1 -1
  3. package/dist/cjs/actions/isSafeWallet.js.map +1 -1
  4. package/dist/cjs/actions/waitForBatchTransactionReceipt.js +31 -5
  5. package/dist/cjs/actions/waitForBatchTransactionReceipt.js.map +1 -1
  6. package/dist/cjs/core/EthereumStepExecutor.js +5 -3
  7. package/dist/cjs/core/EthereumStepExecutor.js.map +1 -1
  8. package/dist/cjs/core/tasks/EthereumCheckAllowanceAfterPrepareTask.d.ts +20 -0
  9. package/dist/cjs/core/tasks/EthereumCheckAllowanceAfterPrepareTask.js +34 -0
  10. package/dist/cjs/core/tasks/EthereumCheckAllowanceAfterPrepareTask.js.map +1 -0
  11. package/dist/cjs/core/tasks/helpers/hasApprovalAddressAppearedAtPrepare.d.ts +11 -0
  12. package/dist/cjs/core/tasks/helpers/hasApprovalAddressAppearedAtPrepare.js +17 -0
  13. package/dist/cjs/core/tasks/helpers/hasApprovalAddressAppearedAtPrepare.js.map +1 -0
  14. package/dist/cjs/index.js +2 -2
  15. package/dist/cjs/permits/getNativePermit.js +1 -1
  16. package/dist/cjs/version.d.ts +1 -1
  17. package/dist/cjs/version.js +1 -1
  18. package/dist/cjs/version.js.map +1 -1
  19. package/dist/esm/actions/isSafeWallet.js +1 -1
  20. package/dist/esm/actions/waitForBatchTransactionReceipt.d.ts.map +1 -1
  21. package/dist/esm/actions/waitForBatchTransactionReceipt.js +31 -5
  22. package/dist/esm/actions/waitForBatchTransactionReceipt.js.map +1 -1
  23. package/dist/esm/core/EthereumStepExecutor.d.ts.map +1 -1
  24. package/dist/esm/core/EthereumStepExecutor.js +5 -3
  25. package/dist/esm/core/EthereumStepExecutor.js.map +1 -1
  26. package/dist/esm/core/tasks/EthereumCheckAllowanceAfterPrepareTask.d.ts +20 -0
  27. package/dist/esm/core/tasks/EthereumCheckAllowanceAfterPrepareTask.d.ts.map +1 -0
  28. package/dist/esm/core/tasks/EthereumCheckAllowanceAfterPrepareTask.js +33 -0
  29. package/dist/esm/core/tasks/EthereumCheckAllowanceAfterPrepareTask.js.map +1 -0
  30. package/dist/esm/core/tasks/helpers/hasApprovalAddressAppearedAtPrepare.d.ts +11 -0
  31. package/dist/esm/core/tasks/helpers/hasApprovalAddressAppearedAtPrepare.d.ts.map +1 -0
  32. package/dist/esm/core/tasks/helpers/hasApprovalAddressAppearedAtPrepare.js +16 -0
  33. package/dist/esm/core/tasks/helpers/hasApprovalAddressAppearedAtPrepare.js.map +1 -0
  34. package/dist/esm/index.js +2 -2
  35. package/dist/esm/permits/getNativePermit.js +1 -1
  36. package/dist/esm/version.d.ts +1 -1
  37. package/dist/esm/version.js +1 -1
  38. package/dist/esm/version.js.map +1 -1
  39. package/package.json +2 -2
  40. package/src/actions/waitForBatchTransactionReceipt.ts +49 -8
  41. package/src/core/EthereumStepExecutor.ts +2 -0
  42. package/src/core/tasks/EthereumCheckAllowanceAfterPrepareTask.ts +34 -0
  43. package/src/core/tasks/helpers/hasApprovalAddressAppearedAtPrepare.ts +29 -0
  44. package/src/version.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @lifi/sdk-provider-ethereum
2
2
 
3
+ ## 4.2.12
4
+
5
+ ### Patch Changes
6
+
7
+ - [#521](https://github.com/lifinance/sdk/pull/521) [`7d9a726`](https://github.com/lifinance/sdk/commit/7d9a726e565345e75852a87ec5b65656c49140d7) Thanks [@Kayanski](https://github.com/Kayanski)! - An ERC-20 step can now get its spender from `/stepTransaction`. Some providers, such as Relay, only know the spender once they build the executable transaction, so the routing-time step carries no `estimate.approvalAddress`. Before, such a step skipped the allowance tasks, and its transaction went out against a spender with no allowance and reverted.
8
+
9
+ Now a new task runs after the transaction is prepared and before it is signed. When the step had no `approvalAddress` before prepare and the re-quote brings one, the task reads the allowance for it, and resets and sets it only if it falls short. In `batched`, the approval goes into the batch with the transaction.
10
+
11
+ On a chain with Permit2, the approval goes to the Permit2 contract, as it would before prepare.
12
+
13
+ A step that already had an `approvalAddress` before prepare behaves as before, even if the re-quote changes it. The task also does not run when the step skips approval.
14
+
15
+ ## 4.2.11
16
+
17
+ ### Patch Changes
18
+
19
+ - [#523](https://github.com/lifinance/sdk/pull/523) [`cdbc058`](https://github.com/lifinance/sdk/commit/cdbc0584d1750d9d765a85970a0cb87fbd0d6c01) Thanks [@chybisov](https://github.com/chybisov)! - Keep one wallet poll per call bundle with every viem version. Since viem 2.57.5 a wait for a call bundle shares its poll only when it passes the same `status` function. The SDK passed a new function on each call. Two waits for one bundle then polled the wallet twice, and the second wait could report a final `SignatureRejected` for a bundle that it did not start. Now all waits for one bundle pass the same function.
20
+
21
+ - [#525](https://github.com/lifinance/sdk/pull/525) [`abb0ab6`](https://github.com/lifinance/sdk/commit/abb0ab658007a7b4d73301d8fea3d89bbfe467cd) Thanks [@chybisov](https://github.com/chybisov)! - Raise the `viem` range to `^2.57.7`.
22
+
3
23
  ## 4.2.10
4
24
 
5
25
  ### Patch Changes
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_actions_getAccountCode = require("./getAccountCode.js");
3
- const require_actions_isSmartContractWallet = require("./isSmartContractWallet.js");
4
3
  const require_client_safeClient = require("../client/safeClient.js");
4
+ const require_actions_isSmartContractWallet = require("./isSmartContractWallet.js");
5
5
  //#region src/actions/isSafeWallet.ts
6
6
  const safeWalletCache = new (require("@lifi/sdk")).LruMap(12);
7
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"isSafeWallet.js","names":["LruMap","getAccountCode","isSmartContractWalletCode","getSafeClient"],"sources":["../../../src/actions/isSafeWallet.ts"],"sourcesContent":["import { LruMap, type SDKClient } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { getSafeClient } from '../client/safeClient.js'\nimport { getAccountCode } from './getAccountCode.js'\nimport { isSmartContractWalletCode } from './isSmartContractWallet.js'\n\n// Caches the Safe Transaction Service verdict (network round trip). The\n// underlying `eth_getCode` is intentionally uncached — see `getAccountCode`.\nconst safeWalletCache = new LruMap<boolean>(12)\n\ntype IsSafeWalletParams = {\n client: SDKClient\n chainId: number\n address: Address\n safeApiKey?: string\n}\n\n/**\n * Check if an address is a Safe wallet via the Safe Transaction Service,\n * short-circuiting on `eth_getCode` for EOAs (incl. EIP-7702 delegated).\n */\nexport async function isSafeWallet({\n client,\n chainId,\n address,\n safeApiKey,\n}: IsSafeWalletParams): Promise<boolean> {\n if (!address) {\n return false\n }\n const cacheKey = `${chainId}:${address.toLowerCase()}`\n const cached = safeWalletCache.get(cacheKey)\n if (cached !== undefined) {\n return cached\n }\n\n // Defined-and-EOA-shaped (`'0x'` or 7702 designator) → short-circuit. RPC\n // failure (`code === undefined`) falls through to the Safe API as an\n // independent fallback — Safe Transaction Service doesn't depend on the\n // chain RPC, so a flaky chain shouldn't blind us to a real Safe.\n const code = await getAccountCode({ client, chainId, address })\n if (code !== undefined && !isSmartContractWalletCode(code)) {\n safeWalletCache.set(cacheKey, false)\n return false\n }\n\n try {\n await getSafeClient(chainId, safeApiKey).getInfo(address)\n safeWalletCache.set(cacheKey, true)\n return true\n } catch {\n safeWalletCache.set(cacheKey, false)\n return false\n }\n}\n"],"mappings":";;;;;AAQA,MAAM,kBAAkB,wBAAIA,EAAAA,CAAAA,OAAgB,EAAE;;;;;AAa9C,eAAsB,aAAa,EACjC,QACA,SACA,SACA,cACuC;CACvC,IAAI,CAAC,SACH,OAAO;CAET,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,YAAY;CACnD,MAAM,SAAS,gBAAgB,IAAI,QAAQ;CAC3C,IAAI,WAAW,KAAA,GACb,OAAO;CAOT,MAAM,OAAO,MAAMC,+BAAAA,eAAe;EAAE;EAAQ;EAAS;CAAQ,CAAC;CAC9D,IAAI,SAAS,KAAA,KAAa,CAACC,sCAAAA,0BAA0B,IAAI,GAAG;EAC1D,gBAAgB,IAAI,UAAU,KAAK;EACnC,OAAO;CACT;CAEA,IAAI;EACF,MAAMC,0BAAAA,cAAc,SAAS,UAAU,CAAC,CAAC,QAAQ,OAAO;EACxD,gBAAgB,IAAI,UAAU,IAAI;EAClC,OAAO;CACT,QAAQ;EACN,gBAAgB,IAAI,UAAU,KAAK;EACnC,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"isSafeWallet.js","names":["LruMap","getAccountCode","isSmartContractWalletCode","getSafeClient"],"sources":["../../../src/actions/isSafeWallet.ts"],"sourcesContent":["import { LruMap, type SDKClient } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { getSafeClient } from '../client/safeClient.js'\nimport { getAccountCode } from './getAccountCode.js'\nimport { isSmartContractWalletCode } from './isSmartContractWallet.js'\n\n// Caches the Safe Transaction Service verdict (network round trip). The\n// underlying `eth_getCode` is intentionally uncached — see `getAccountCode`.\nconst safeWalletCache = new LruMap<boolean>(12)\n\ntype IsSafeWalletParams = {\n client: SDKClient\n chainId: number\n address: Address\n safeApiKey?: string\n}\n\n/**\n * Check if an address is a Safe wallet via the Safe Transaction Service,\n * short-circuiting on `eth_getCode` for EOAs (incl. EIP-7702 delegated).\n */\nexport async function isSafeWallet({\n client,\n chainId,\n address,\n safeApiKey,\n}: IsSafeWalletParams): Promise<boolean> {\n if (!address) {\n return false\n }\n const cacheKey = `${chainId}:${address.toLowerCase()}`\n const cached = safeWalletCache.get(cacheKey)\n if (cached !== undefined) {\n return cached\n }\n\n // Defined-and-EOA-shaped (`'0x'` or 7702 designator) → short-circuit. RPC\n // failure (`code === undefined`) falls through to the Safe API as an\n // independent fallback — Safe Transaction Service doesn't depend on the\n // chain RPC, so a flaky chain shouldn't blind us to a real Safe.\n const code = await getAccountCode({ client, chainId, address })\n if (code !== undefined && !isSmartContractWalletCode(code)) {\n safeWalletCache.set(cacheKey, false)\n return false\n }\n\n try {\n await getSafeClient(chainId, safeApiKey).getInfo(address)\n safeWalletCache.set(cacheKey, true)\n return true\n } catch {\n safeWalletCache.set(cacheKey, false)\n return false\n }\n}\n"],"mappings":";;;;;AAQA,MAAM,kBAAkB,K,mBAAIA,EAAAA,CAAAA,OAAgB,EAAE;;;;;AAa9C,eAAsB,aAAa,EACjC,QACA,SACA,SACA,cACuC;CACvC,IAAI,CAAC,SACH,OAAO;CAET,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,YAAY;CACnD,MAAM,SAAS,gBAAgB,IAAI,QAAQ;CAC3C,IAAI,WAAW,KAAA,GACb,OAAO;CAOT,MAAM,OAAO,MAAMC,+BAAAA,eAAe;EAAE;EAAQ;EAAS;CAAQ,CAAC;CAC9D,IAAI,SAAS,KAAA,KAAa,CAACC,sCAAAA,0BAA0B,IAAI,GAAG;EAC1D,gBAAgB,IAAI,UAAU,KAAK;EACnC,OAAO;CACT;CAEA,IAAI;EACF,MAAMC,0BAAAA,cAAc,SAAS,UAAU,CAAC,CAAC,QAAQ,OAAO;EACxD,gBAAgB,IAAI,UAAU,IAAI;EAClC,OAAO;CACT,QAAQ;EACN,gBAAgB,IAAI,UAAU,KAAK;EACnC,OAAO;CACT;AACF"}
@@ -5,6 +5,15 @@ let viem_actions = require("viem/actions");
5
5
  let viem_utils = require("viem/utils");
6
6
  //#region src/actions/waitForBatchTransactionReceipt.ts
7
7
  const DROPPED_BUNDLE_MAX_AGE_MS = 6e5;
8
+ /**
9
+ * viem shares one poll between the waits for the same client and id, and
10
+ * calls only the predicate of the wait that started it. Since viem 2.57.5 the
11
+ * shared poll also needs the same `status` function (compared by identity).
12
+ * All waits for one bundle thus pass the same predicate from this map. Then
13
+ * they share one poll in every viem version, and only the first wait of the
14
+ * bundle can see the wallet's answers.
15
+ */
16
+ const bundleWaits = /* @__PURE__ */ new Map();
8
17
  const isUnknownBundleIdError = (error) => error?.name === "UnknownBundleIdError" || error?.cause?.name === "UnknownBundleIdError" || error?.code === viem.UnknownBundleIdError.code;
9
18
  /**
10
19
  * Unknown signing time is never in the window. Nor is a signing time in the
@@ -35,21 +44,38 @@ const isWithinDropWindow = (signedAt) => {
35
44
  * @throws Any other error of the wallet, unchanged.
36
45
  */
37
46
  const waitForBatchTransactionReceipt = async (client, batchHash, { onFailed, signedAt, callCount } = {}) => {
38
- let known = false;
47
+ const waitKey = `${client.uid}:${batchHash}`;
48
+ let bundleWait = bundleWaits.get(waitKey);
49
+ const startedPoll = !bundleWait;
50
+ if (!bundleWait) {
51
+ const created = {
52
+ status: ({ statusCode }) => {
53
+ created.answered = true;
54
+ return statusCode === 200 || statusCode >= 300;
55
+ },
56
+ answered: false,
57
+ waiters: 0
58
+ };
59
+ bundleWait = created;
60
+ bundleWaits.set(waitKey, created);
61
+ }
62
+ const sharedWait = bundleWait;
63
+ sharedWait.waiters += 1;
39
64
  let result;
40
65
  try {
41
66
  result = await (0, viem_utils.getAction)(client, viem_actions.waitForCallsStatus, "waitForCallsStatus")({
42
67
  id: batchHash,
43
68
  timeout: 864e5,
44
- status: ({ statusCode }) => {
45
- known = true;
46
- return statusCode === 200 || statusCode >= 300;
47
- }
69
+ status: sharedWait.status
48
70
  });
49
71
  } catch (error) {
72
+ const known = startedPoll && sharedWait.answered;
50
73
  if (!isUnknownBundleIdError(error)) throw error;
51
74
  if (known && callCount === 1 && isWithinDropWindow(signedAt)) throw new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.SignatureRejected, "The wallet has no record of the call bundle. The SDK treats it as never sent.", error, { final: true });
52
75
  throw new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.CallBundleNotFound, "The wallet has no record of the call bundle.", error);
76
+ } finally {
77
+ sharedWait.waiters -= 1;
78
+ if (sharedWait.waiters === 0 && bundleWaits.get(waitKey) === sharedWait) bundleWaits.delete(waitKey);
53
79
  }
54
80
  if (result.status === "success") {
55
81
  if (result.receipts?.some((receipt) => receipt.status === "reverted")) {
@@ -1 +1 @@
1
- {"version":3,"file":"waitForBatchTransactionReceipt.js","names":["UnknownBundleIdError","getAction","waitForCallsStatus","TransactionError","LiFiErrorCode"],"sources":["../../../src/actions/waitForBatchTransactionReceipt.ts"],"sourcesContent":["import { LiFiErrorCode, TransactionError } from '@lifi/sdk'\nimport { type Client, type Hash, UnknownBundleIdError } from 'viem'\nimport { type GetCallsStatusReturnType, waitForCallsStatus } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { WalletCallReceipt } from '../types.js'\n\n// Some wallets answer from a remote service that can forget an old bundle.\nconst DROPPED_BUNDLE_MAX_AGE_MS = 10 * 60_000\n\nconst isUnknownBundleIdError = (error: any): boolean =>\n error?.name === 'UnknownBundleIdError' ||\n error?.cause?.name === 'UnknownBundleIdError' ||\n error?.code === UnknownBundleIdError.code\n\n/**\n * Unknown signing time is never in the window. Nor is a signing time in the\n * future, as in `isResendAllowed`.\n */\nconst isWithinDropWindow = (signedAt: number | undefined): boolean => {\n const now = Date.now()\n return (\n signedAt !== undefined &&\n now >= signedAt &&\n now - signedAt < DROPPED_BUNDLE_MAX_AGE_MS\n )\n}\n\n/**\n * Waits until the wallet reports the EIP-5792 call bundle as done or failed.\n *\n * MetaMask returns the id of a single-call bundle before the user approves\n * it, and removes the bundle on a reject: `wallet_getCallsStatus` then fails\n * with 5730 (`UnknownBundleIdError`). It returns the id of a bundle of two or\n * more calls only after it sent the bundle. Thus the SDK treats a bundle as\n * never sent only when all of these are true: its stored `callCount` is 1,\n * the wallet answered for it in this wait and then has no record of it, and\n * this happens within `DROPPED_BUNDLE_MAX_AGE_MS` of signing.\n *\n * @param client - The wallet client that sent the bundle.\n * @param batchHash - The bundle id that `wallet_sendCalls` returned.\n * @param options.onFailed - Gets the wallet's answer for a failed bundle, before the error is thrown.\n * @param options.signedAt - The signing time of the step (`execution.signedAt`).\n * @param options.callCount - The stored number of calls of the bundle (`action.callCount`).\n * @returns The receipt of the last call of the bundle.\n * @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.\n * @throws Any other error of the wallet, unchanged.\n */\nexport const waitForBatchTransactionReceipt = async (\n client: Client,\n batchHash: Hash,\n {\n onFailed,\n signedAt,\n callCount,\n }: {\n onFailed?: (result: GetCallsStatusReturnType) => void\n signedAt?: number\n callCount?: number\n } = {}\n): Promise<WalletCallReceipt> => {\n let known = false\n let result: GetCallsStatusReturnType\n try {\n result = await getAction(\n client,\n waitForCallsStatus,\n 'waitForCallsStatus'\n )({\n id: batchHash,\n timeout: 3_600_000 * 24,\n // viem's default, and a record that the wallet answered for this id.\n // viem shares one poll between waits for the same client and id, and\n // calls only the predicate of the wait that started it.\n status: ({ statusCode }) => {\n known = true\n return statusCode === 200 || statusCode >= 300\n },\n })\n } catch (error) {\n if (!isUnknownBundleIdError(error)) {\n throw error\n }\n // MetaMask removes a single-call bundle in this way only before it sends\n // it. The SDK treats the bundle as never sent: a final rejection, so\n // \"Try again\" signs anew.\n if (known && callCount === 1 && isWithinDropWindow(signedAt)) {\n throw new TransactionError(\n LiFiErrorCode.SignatureRejected,\n 'The wallet has no record of the call bundle. The SDK treats it as never sent.',\n error as Error,\n { final: true }\n )\n }\n // Unknown from the first answer (a reload after the reject, another\n // wallet), too long after signing, or no stored count of one call (two\n // or more calls, or a route stored without the count): the bundle may\n // still land.\n throw new TransactionError(\n LiFiErrorCode.CallBundleNotFound,\n 'The wallet has no record of the call bundle.',\n error as Error\n )\n }\n\n if (result.status === 'success') {\n if (result.receipts?.some((receipt) => receipt.status === 'reverted')) {\n onFailed?.(result)\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction was reverted.',\n undefined,\n { final: true }\n )\n }\n // The wallet reports the batch as executed, but without a complete set of\n // receipts we cannot prove the outcome: it stays unknown.\n if (\n !result.receipts?.length ||\n !result.receipts.every((receipt) => receipt.transactionHash)\n ) {\n onFailed?.(result)\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction was reverted.'\n )\n }\n const transactionReceipt = result.receipts.at(-1)!\n return transactionReceipt\n }\n if (result.statusCode >= 400 && result.statusCode < 500) {\n onFailed?.(result)\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'Transaction was canceled.',\n undefined,\n { final: true }\n )\n }\n onFailed?.(result)\n // Only 500 (reverted completely) is final. Some calls of a partial batch\n // (600) may be onchain, and other codes are undefined: the outcome is unknown.\n if (result.statusCode === 500) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction failed.',\n undefined,\n { final: true }\n )\n }\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction failed.'\n )\n}\n"],"mappings":";;;;;;AAOA,MAAM,4BAA4B;AAElC,MAAM,0BAA0B,UAC9B,OAAO,SAAS,0BAChB,OAAO,OAAO,SAAS,0BACvB,OAAO,SAASA,KAAAA,qBAAqB;;;;;AAMvC,MAAM,sBAAsB,aAA0C;CACpE,MAAM,MAAM,KAAK,IAAI;CACrB,OACE,aAAa,KAAA,KACb,OAAO,YACP,MAAM,WAAW;AAErB;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,iCAAiC,OAC5C,QACA,WACA,EACE,UACA,UACA,cAKE,CAAC,MAC0B;CAC/B,IAAI,QAAQ;CACZ,IAAI;CACJ,IAAI;EACF,SAAS,OAAA,GAAMC,WAAAA,UAAAA,CACb,QACAC,aAAAA,oBACA,oBACF,CAAC,CAAC;GACA,IAAI;GACJ,SAAS;GAIT,SAAS,EAAE,iBAAiB;IAC1B,QAAQ;IACR,OAAO,eAAe,OAAO,cAAc;GAC7C;EACF,CAAC;CACH,SAAS,OAAO;EACd,IAAI,CAAC,uBAAuB,KAAK,GAC/B,MAAM;EAKR,IAAI,SAAS,cAAc,KAAK,mBAAmB,QAAQ,GACzD,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,mBACd,iFACA,OACA,EAAE,OAAO,KAAK,CAChB;EAMF,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,oBACd,gDACA,KACF;CACF;CAEA,IAAI,OAAO,WAAW,WAAW;EAC/B,IAAI,OAAO,UAAU,MAAM,YAAY,QAAQ,WAAW,UAAU,GAAG;GACrE,WAAW,MAAM;GACjB,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,mBACd,6BACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;EACF;EAGA,IACE,CAAC,OAAO,UAAU,UAClB,CAAC,OAAO,SAAS,OAAO,YAAY,QAAQ,eAAe,GAC3D;GACA,WAAW,MAAM;GACjB,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,mBACd,2BACF;EACF;EAEA,OAD2B,OAAO,SAAS,GAAG,EACtB;CAC1B;CACA,IAAI,OAAO,cAAc,OAAO,OAAO,aAAa,KAAK;EACvD,WAAW,MAAM;EACjB,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,qBACd,6BACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;CACF;CACA,WAAW,MAAM;CAGjB,IAAI,OAAO,eAAe,KACxB,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,mBACd,uBACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;CAEF,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,mBACd,qBACF;AACF"}
1
+ {"version":3,"file":"waitForBatchTransactionReceipt.js","names":["UnknownBundleIdError","getAction","waitForCallsStatus","TransactionError","LiFiErrorCode"],"sources":["../../../src/actions/waitForBatchTransactionReceipt.ts"],"sourcesContent":["import { LiFiErrorCode, TransactionError } from '@lifi/sdk'\nimport { type Client, type Hash, UnknownBundleIdError } from 'viem'\nimport { type GetCallsStatusReturnType, waitForCallsStatus } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { WalletCallReceipt } from '../types.js'\n\n// Some wallets answer from a remote service that can forget an old bundle.\nconst DROPPED_BUNDLE_MAX_AGE_MS = 10 * 60_000\n\ntype BundleWait = {\n /** The one `status` predicate that every wait for the bundle passes. */\n status: (result: { statusCode: number }) => boolean\n /** True after the wallet answered for the bundle in the shared poll. */\n answered: boolean\n /** The waits that did not finish yet. */\n waiters: number\n}\n\n/**\n * viem shares one poll between the waits for the same client and id, and\n * calls only the predicate of the wait that started it. Since viem 2.57.5 the\n * shared poll also needs the same `status` function (compared by identity).\n * All waits for one bundle thus pass the same predicate from this map. Then\n * they share one poll in every viem version, and only the first wait of the\n * bundle can see the wallet's answers.\n */\nconst bundleWaits = new Map<string, BundleWait>()\n\nconst isUnknownBundleIdError = (error: any): boolean =>\n error?.name === 'UnknownBundleIdError' ||\n error?.cause?.name === 'UnknownBundleIdError' ||\n error?.code === UnknownBundleIdError.code\n\n/**\n * Unknown signing time is never in the window. Nor is a signing time in the\n * future, as in `isResendAllowed`.\n */\nconst isWithinDropWindow = (signedAt: number | undefined): boolean => {\n const now = Date.now()\n return (\n signedAt !== undefined &&\n now >= signedAt &&\n now - signedAt < DROPPED_BUNDLE_MAX_AGE_MS\n )\n}\n\n/**\n * Waits until the wallet reports the EIP-5792 call bundle as done or failed.\n *\n * MetaMask returns the id of a single-call bundle before the user approves\n * it, and removes the bundle on a reject: `wallet_getCallsStatus` then fails\n * with 5730 (`UnknownBundleIdError`). It returns the id of a bundle of two or\n * more calls only after it sent the bundle. Thus the SDK treats a bundle as\n * never sent only when all of these are true: its stored `callCount` is 1,\n * the wallet answered for it in this wait and then has no record of it, and\n * this happens within `DROPPED_BUNDLE_MAX_AGE_MS` of signing.\n *\n * @param client - The wallet client that sent the bundle.\n * @param batchHash - The bundle id that `wallet_sendCalls` returned.\n * @param options.onFailed - Gets the wallet's answer for a failed bundle, before the error is thrown.\n * @param options.signedAt - The signing time of the step (`execution.signedAt`).\n * @param options.callCount - The stored number of calls of the bundle (`action.callCount`).\n * @returns The receipt of the last call of the bundle.\n * @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.\n * @throws Any other error of the wallet, unchanged.\n */\nexport const waitForBatchTransactionReceipt = async (\n client: Client,\n batchHash: Hash,\n {\n onFailed,\n signedAt,\n callCount,\n }: {\n onFailed?: (result: GetCallsStatusReturnType) => void\n signedAt?: number\n callCount?: number\n } = {}\n): Promise<WalletCallReceipt> => {\n const waitKey = `${client.uid}:${batchHash}`\n let bundleWait = bundleWaits.get(waitKey)\n // The first wait of a bundle starts the poll. A wait that joins it does not\n // see the wallet's answers, so it never has a record of them.\n const startedPoll = !bundleWait\n if (!bundleWait) {\n const created: BundleWait = {\n // viem's default, and a record that the wallet answered for this id.\n status: ({ statusCode }) => {\n created.answered = true\n return statusCode === 200 || statusCode >= 300\n },\n answered: false,\n waiters: 0,\n }\n bundleWait = created\n bundleWaits.set(waitKey, created)\n }\n const sharedWait = bundleWait\n sharedWait.waiters += 1\n\n let result: GetCallsStatusReturnType\n try {\n result = await getAction(\n client,\n waitForCallsStatus,\n 'waitForCallsStatus'\n )({\n id: batchHash,\n timeout: 3_600_000 * 24,\n status: sharedWait.status,\n })\n } catch (error) {\n const known = startedPoll && sharedWait.answered\n if (!isUnknownBundleIdError(error)) {\n throw error\n }\n // MetaMask removes a single-call bundle in this way only before it sends\n // it. The SDK treats the bundle as never sent: a final rejection, so\n // \"Try again\" signs anew.\n if (known && callCount === 1 && isWithinDropWindow(signedAt)) {\n throw new TransactionError(\n LiFiErrorCode.SignatureRejected,\n 'The wallet has no record of the call bundle. The SDK treats it as never sent.',\n error as Error,\n { final: true }\n )\n }\n // Unknown from the first answer (a reload after the reject, another\n // wallet), too long after signing, or no stored count of one call (two\n // or more calls, or a route stored without the count): the bundle may\n // still land.\n throw new TransactionError(\n LiFiErrorCode.CallBundleNotFound,\n 'The wallet has no record of the call bundle.',\n error as Error\n )\n } finally {\n // The last wait of the bundle removes the shared predicate. A later wait\n // then starts a new poll and sees the wallet's answers again.\n sharedWait.waiters -= 1\n if (sharedWait.waiters === 0 && bundleWaits.get(waitKey) === sharedWait) {\n bundleWaits.delete(waitKey)\n }\n }\n\n if (result.status === 'success') {\n if (result.receipts?.some((receipt) => receipt.status === 'reverted')) {\n onFailed?.(result)\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction was reverted.',\n undefined,\n { final: true }\n )\n }\n // The wallet reports the batch as executed, but without a complete set of\n // receipts we cannot prove the outcome: it stays unknown.\n if (\n !result.receipts?.length ||\n !result.receipts.every((receipt) => receipt.transactionHash)\n ) {\n onFailed?.(result)\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction was reverted.'\n )\n }\n const transactionReceipt = result.receipts.at(-1)!\n return transactionReceipt\n }\n if (result.statusCode >= 400 && result.statusCode < 500) {\n onFailed?.(result)\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'Transaction was canceled.',\n undefined,\n { final: true }\n )\n }\n onFailed?.(result)\n // Only 500 (reverted completely) is final. Some calls of a partial batch\n // (600) may be onchain, and other codes are undefined: the outcome is unknown.\n if (result.statusCode === 500) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction failed.',\n undefined,\n { final: true }\n )\n }\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction failed.'\n )\n}\n"],"mappings":";;;;;;AAOA,MAAM,4BAA4B;;;;;;;;;AAmBlC,MAAM,8BAAc,IAAI,IAAwB;AAEhD,MAAM,0BAA0B,UAC9B,OAAO,SAAS,0BAChB,OAAO,OAAO,SAAS,0BACvB,OAAO,SAASA,KAAAA,qBAAqB;;;;;AAMvC,MAAM,sBAAsB,aAA0C;CACpE,MAAM,MAAM,KAAK,IAAI;CACrB,OACE,aAAa,KAAA,KACb,OAAO,YACP,MAAM,WAAW;AAErB;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,iCAAiC,OAC5C,QACA,WACA,EACE,UACA,UACA,cAKE,CAAC,MAC0B;CAC/B,MAAM,UAAU,GAAG,OAAO,IAAI,GAAG;CACjC,IAAI,aAAa,YAAY,IAAI,OAAO;CAGxC,MAAM,cAAc,CAAC;CACrB,IAAI,CAAC,YAAY;EACf,MAAM,UAAsB;GAE1B,SAAS,EAAE,iBAAiB;IAC1B,QAAQ,WAAW;IACnB,OAAO,eAAe,OAAO,cAAc;GAC7C;GACA,UAAU;GACV,SAAS;EACX;EACA,aAAa;EACb,YAAY,IAAI,SAAS,OAAO;CAClC;CACA,MAAM,aAAa;CACnB,WAAW,WAAW;CAEtB,IAAI;CACJ,IAAI;EACF,SAAS,OAAA,GAAMC,WAAAA,UAAAA,CACb,QACAC,aAAAA,oBACA,oBACF,CAAC,CAAC;GACA,IAAI;GACJ,SAAS;GACT,QAAQ,WAAW;EACrB,CAAC;CACH,SAAS,OAAO;EACd,MAAM,QAAQ,eAAe,WAAW;EACxC,IAAI,CAAC,uBAAuB,KAAK,GAC/B,MAAM;EAKR,IAAI,SAAS,cAAc,KAAK,mBAAmB,QAAQ,GACzD,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,mBACd,iFACA,OACA,EAAE,OAAO,KAAK,CAChB;EAMF,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,oBACd,gDACA,KACF;CACF,UAAU;EAGR,WAAW,WAAW;EACtB,IAAI,WAAW,YAAY,KAAK,YAAY,IAAI,OAAO,MAAM,YAC3D,YAAY,OAAO,OAAO;CAE9B;CAEA,IAAI,OAAO,WAAW,WAAW;EAC/B,IAAI,OAAO,UAAU,MAAM,YAAY,QAAQ,WAAW,UAAU,GAAG;GACrE,WAAW,MAAM;GACjB,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,mBACd,6BACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;EACF;EAGA,IACE,CAAC,OAAO,UAAU,UAClB,CAAC,OAAO,SAAS,OAAO,YAAY,QAAQ,eAAe,GAC3D;GACA,WAAW,MAAM;GACjB,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,mBACd,2BACF;EACF;EAEA,OAD2B,OAAO,SAAS,GAAG,EACtB;CAC1B;CACA,IAAI,OAAO,cAAc,OAAO,OAAO,aAAa,KAAK;EACvD,WAAW,MAAM;EACjB,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,qBACd,6BACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;CACF;CACA,WAAW,MAAM;CAGjB,IAAI,OAAO,eAAe,KACxB,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,mBACd,uBACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;CAEF,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,mBACd,qBACF;AACF"}
@@ -2,17 +2,18 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_utils_isZeroAddress = require("../utils/isZeroAddress.js");
3
3
  const require_errors_parseEthereumErrors = require("../errors/parseEthereumErrors.js");
4
4
  const require_core_tasks_EthereumCheckAllowanceTask = require("./tasks/EthereumCheckAllowanceTask.js");
5
+ const require_core_tasks_EthereumResetAllowanceTask = require("./tasks/EthereumResetAllowanceTask.js");
6
+ const require_core_tasks_EthereumSetAllowanceTask = require("./tasks/EthereumSetAllowanceTask.js");
7
+ const require_core_tasks_helpers_shouldCheckForAllowance = require("./tasks/helpers/shouldCheckForAllowance.js");
8
+ const require_core_tasks_EthereumCheckAllowanceAfterPrepareTask = require("./tasks/EthereumCheckAllowanceAfterPrepareTask.js");
5
9
  const require_core_tasks_EthereumCheckBalanceTask = require("./tasks/EthereumCheckBalanceTask.js");
6
10
  const require_core_tasks_EthereumCheckPermitsTask = require("./tasks/EthereumCheckPermitsTask.js");
7
11
  const require_core_tasks_EthereumNativePermitTask = require("./tasks/EthereumNativePermitTask.js");
8
12
  const require_core_tasks_EthereumPermit2AllowanceTask = require("./tasks/EthereumPermit2AllowanceTask.js");
9
13
  const require_core_tasks_EthereumPrepareTransactionTask = require("./tasks/EthereumPrepareTransactionTask.js");
10
- const require_core_tasks_EthereumResetAllowanceTask = require("./tasks/EthereumResetAllowanceTask.js");
11
- const require_core_tasks_EthereumSetAllowanceTask = require("./tasks/EthereumSetAllowanceTask.js");
12
14
  const require_core_tasks_EthereumSignAndExecuteTask = require("./tasks/EthereumSignAndExecuteTask.js");
13
15
  const require_core_tasks_EthereumWaitForTransactionStatusTask = require("./tasks/EthereumWaitForTransactionStatusTask.js");
14
16
  const require_core_tasks_EthereumWaitForTransactionTask = require("./tasks/EthereumWaitForTransactionTask.js");
15
- const require_core_tasks_helpers_shouldCheckForAllowance = require("./tasks/helpers/shouldCheckForAllowance.js");
16
17
  const require_core_tasks_helpers_switchChain = require("./tasks/helpers/switchChain.js");
17
18
  let _lifi_sdk = require("@lifi/sdk");
18
19
  let viem_actions = require("viem/actions");
@@ -68,6 +69,7 @@ var EthereumStepExecutor = class extends _lifi_sdk.BaseStepExecutor {
68
69
  new require_core_tasks_EthereumCheckBalanceTask.EthereumCheckBalanceTask(),
69
70
  new require_core_tasks_EthereumPermit2AllowanceTask.EthereumPermit2AllowanceTask(),
70
71
  new require_core_tasks_EthereumPrepareTransactionTask.EthereumPrepareTransactionTask(),
72
+ new require_core_tasks_EthereumCheckAllowanceAfterPrepareTask.EthereumCheckAllowanceAfterPrepareTask(),
71
73
  new require_core_tasks_EthereumSignAndExecuteTask.EthereumSignAndExecuteTask(),
72
74
  new require_core_tasks_EthereumWaitForTransactionTask.EthereumWaitForTransactionTask(),
73
75
  new require_core_tasks_EthereumWaitForTransactionStatusTask.EthereumWaitForTransactionStatusTask()
@@ -1 +1 @@
1
- {"version":3,"file":"EthereumStepExecutor.js","names":["BaseStepExecutor","createDefaultStorage","parseEthereumErrors","switchChain","getAction","getAddresses","TransactionError","LiFiErrorCode","isZeroAddress","EthereumCheckPermitsTask","EthereumCheckAllowanceTask","EthereumNativePermitTask","EthereumResetAllowanceTask","EthereumSetAllowanceTask","EthereumCheckBalanceTask","EthereumPermit2AllowanceTask","EthereumPrepareTransactionTask","EthereumSignAndExecuteTask","EthereumWaitForTransactionTask","EthereumWaitForTransactionStatusTask","shouldCheckForAllowance","hasOpenTransaction","TaskPipeline"],"sources":["../../../src/core/EthereumStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n createDefaultStorage,\n type ExecuteStepRetryError,\n type ExecuteStepRetryParams,\n type ExecutionAction,\n hasOpenTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n type SDKClient,\n type SDKError,\n type SDKStorage,\n type StepExecutorBaseContext,\n type StepExecutorOptions,\n TaskPipeline,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Client, GetAddressesReturnType } from 'viem'\nimport { getAddresses } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { parseEthereumErrors } from '../errors/parseEthereumErrors.js'\nimport type { EthereumStepExecutorContext } from '../types.js'\nimport { isZeroAddress } from '../utils/isZeroAddress.js'\nimport { EthereumCheckAllowanceTask } from './tasks/EthereumCheckAllowanceTask.js'\nimport { EthereumCheckBalanceTask } from './tasks/EthereumCheckBalanceTask.js'\nimport { EthereumCheckPermitsTask } from './tasks/EthereumCheckPermitsTask.js'\nimport { EthereumNativePermitTask } from './tasks/EthereumNativePermitTask.js'\nimport { EthereumPermit2AllowanceTask } from './tasks/EthereumPermit2AllowanceTask.js'\nimport { EthereumPrepareTransactionTask } from './tasks/EthereumPrepareTransactionTask.js'\nimport { EthereumResetAllowanceTask } from './tasks/EthereumResetAllowanceTask.js'\nimport { EthereumSetAllowanceTask } from './tasks/EthereumSetAllowanceTask.js'\nimport { EthereumSignAndExecuteTask } from './tasks/EthereumSignAndExecuteTask.js'\nimport { EthereumWaitForTransactionStatusTask } from './tasks/EthereumWaitForTransactionStatusTask.js'\nimport { EthereumWaitForTransactionTask } from './tasks/EthereumWaitForTransactionTask.js'\nimport { shouldCheckForAllowance } from './tasks/helpers/shouldCheckForAllowance.js'\nimport { switchChain } from './tasks/helpers/switchChain.js'\n\ninterface EthereumStepExecutorOptions extends StepExecutorOptions {\n client: Client\n switchChain?: (chainId: number) => Promise<Client | undefined>\n disableMessageSigning?: boolean\n}\n\nexport class EthereumStepExecutor extends BaseStepExecutor {\n private client: Client\n private switchChain?: (chainId: number) => Promise<Client | undefined>\n private storage?: SDKStorage\n private disableMessageSigning?: boolean\n\n constructor(options: EthereumStepExecutorOptions) {\n super(options)\n this.client = options.client\n this.switchChain = options.switchChain\n this.disableMessageSigning = options.disableMessageSigning\n }\n\n private getStorage = (client: SDKClient): SDKStorage => {\n if (!this.storage) {\n this.storage = client.config.storage ?? createDefaultStorage()\n }\n return this.storage\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction,\n retryParams?: ExecuteStepRetryParams\n ): Promise<SDKError | ExecuteStepRetryError> =>\n parseEthereumErrors(error, step, action, retryParams)\n\n // Ensure that we are using the right chain and wallet when executing transactions.\n checkClient = async (\n step: LiFiStepExtended,\n targetChainId?: number\n ): Promise<Client | undefined> => {\n const updatedClient = await switchChain(\n this.client,\n targetChainId ?? step.action.fromChainId,\n this.allowUserInteraction,\n this.switchChain\n )\n if (updatedClient) {\n this.client = updatedClient\n }\n\n // Prevent execution of the quote by wallet different from the one which requested the quote\n let accountAddress = this.client.account?.address\n if (!accountAddress) {\n const accountAddresses = (await getAction(\n this.client,\n getAddresses,\n 'getAddresses'\n )(undefined)) as GetAddressesReturnType\n accountAddress = accountAddresses?.[0]\n }\n if (\n accountAddress?.toLowerCase() !== step.action.fromAddress?.toLowerCase()\n ) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n return updatedClient\n }\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<EthereumStepExecutorContext> => {\n const { step, fromChain } = baseContext\n\n const isFromNativeToken =\n fromChain.nativeToken.address === step.action.fromToken.address &&\n isZeroAddress(step.action.fromToken.address)\n\n // Check if message signing is disabled - useful for smart contract wallets\n // We also disable message signing for custom steps\n const disableMessageSigning =\n !!this.disableMessageSigning || step.type !== 'lifi'\n\n return {\n ...baseContext,\n isFromNativeToken,\n disableMessageSigning,\n ethereumClient: this.client,\n checkClient: this.checkClient,\n getStorage: this.getStorage,\n // Signed typed data for native permits and other messages\n signedTypedData: [],\n // Calls for atomic batch transactions (EIP-5792)\n calls: [],\n }\n }\n\n override createPipeline = (\n context: EthereumStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution, isFromNativeToken } = context\n\n const tasks = [\n new EthereumCheckPermitsTask(),\n new EthereumCheckAllowanceTask(),\n new EthereumNativePermitTask(),\n new EthereumResetAllowanceTask(),\n new EthereumSetAllowanceTask(),\n new EthereumCheckBalanceTask(),\n new EthereumPermit2AllowanceTask(),\n new EthereumPrepareTransactionTask(),\n new EthereumSignAndExecuteTask(),\n new EthereumWaitForTransactionTask(),\n new EthereumWaitForTransactionStatusTask(),\n ]\n\n const doCheckAllowance = shouldCheckForAllowance(\n step,\n isBridgeExecution,\n isFromNativeToken,\n this.statusManager\n )\n\n let firstTask:\n | typeof EthereumCheckPermitsTask\n | typeof EthereumCheckBalanceTask\n | typeof EthereumWaitForTransactionTask\n | typeof EthereumWaitForTransactionStatusTask\n if (doCheckAllowance) {\n firstTask = EthereumCheckPermitsTask\n } else {\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n // Same predicate as the pre-sign guard: an open transaction is waited\n // for, a FAILED action with a final outcome signs again.\n firstTask = hasOpenTransaction(swapOrBridgeAction)\n ? swapOrBridgeAction?.status === 'DONE'\n ? EthereumWaitForTransactionStatusTask\n : EthereumWaitForTransactionTask\n : EthereumCheckBalanceTask\n }\n\n // Compare classes, not names: a minifier can give two task classes the\n // same name.\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor === firstTask\n )\n if (firstTaskIndex === -1) {\n throw new TransactionError(\n LiFiErrorCode.InternalError,\n 'EthereumStepExecutor.createPipeline: first task not found'\n )\n }\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,uBAAb,cAA0CA,UAAAA,iBAAiB;CACzD;CACA;CACA;CACA;CAEA,YAAY,SAAsC;EAChD,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;EACtB,KAAK,cAAc,QAAQ;EAC3B,KAAK,wBAAwB,QAAQ;CACvC;CAEA,cAAsB,WAAkC;EACtD,IAAI,CAAC,KAAK,SACR,KAAK,UAAU,OAAO,OAAO,YAAA,GAAWC,UAAAA,qBAAAA,CAAqB;EAE/D,OAAO,KAAK;CACd;CAEA,eACE,OACA,MACA,QACA,gBAEAC,mCAAAA,oBAAoB,OAAO,MAAM,QAAQ,WAAW;CAGtD,cAAc,OACZ,MACA,kBACgC;EAChC,MAAM,gBAAgB,MAAMC,uCAAAA,YAC1B,KAAK,QACL,iBAAiB,KAAK,OAAO,aAC7B,KAAK,sBACL,KAAK,WACP;EACA,IAAI,eACF,KAAK,SAAS;EAIhB,IAAI,iBAAiB,KAAK,OAAO,SAAS;EAC1C,IAAI,CAAC,gBAMH,kBAAiB,OAAA,GALeC,WAAAA,UAAAA,CAC9B,KAAK,QACLC,aAAAA,cACA,cACF,CAAC,CAAC,KAAA,CAAS,EAAA,GACyB;EAEtC,IACE,gBAAgB,YAAY,MAAM,KAAK,OAAO,aAAa,YAAY,GAEvE,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,8BACd,mHACF;EAEF,OAAO;CACT;CAEA,gBAAyB,OACvB,gBACyC;EACzC,MAAM,EAAE,MAAM,cAAc;EAE5B,MAAM,oBACJ,UAAU,YAAY,YAAY,KAAK,OAAO,UAAU,WACxDC,4BAAAA,cAAc,KAAK,OAAO,UAAU,OAAO;EAI7C,MAAM,wBACJ,CAAC,CAAC,KAAK,yBAAyB,KAAK,SAAS;EAEhD,OAAO;GACL,GAAG;GACH;GACA;GACA,gBAAgB,KAAK;GACrB,aAAa,KAAK;GAClB,YAAY,KAAK;GAEjB,iBAAiB,CAAC;GAElB,OAAO,CAAC;EACV;CACF;CAEA,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,mBAAmB,sBAAsB;EAEvD,MAAM,QAAQ;GACZ,IAAIC,4CAAAA,yBAAyB;GAC7B,IAAIC,8CAAAA,2BAA2B;GAC/B,IAAIC,4CAAAA,yBAAyB;GAC7B,IAAIC,8CAAAA,2BAA2B;GAC/B,IAAIC,4CAAAA,yBAAyB;GAC7B,IAAIC,4CAAAA,yBAAyB;GAC7B,IAAIC,gDAAAA,6BAA6B;GACjC,IAAIC,kDAAAA,+BAA+B;GACnC,IAAIC,8CAAAA,2BAA2B;GAC/B,IAAIC,kDAAAA,+BAA+B;GACnC,IAAIC,wDAAAA,qCAAqC;EAC3C;EAEA,MAAM,mBAAmBC,mDAAAA,wBACvB,MACA,mBACA,mBACA,KAAK,aACP;EAEA,IAAI;EAKJ,IAAI,kBACF,YAAYX,4CAAAA;OACP;GACL,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;GAGA,aAAA,GAAYY,UAAAA,mBAAAA,CAAmB,kBAAkB,IAC7C,oBAAoB,WAAW,SAC7BF,wDAAAA,uCACAD,kDAAAA,iCACFJ,4CAAAA;EACN;EAIA,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,gBAAgB,SACjC;EACA,IAAI,mBAAmB,IACrB,MAAM,IAAIR,UAAAA,iBACRC,UAAAA,cAAc,eACd,2DACF;EAGF,MAAM,aAAa,MAAM,MAAM,cAAc;EAE7C,OAAO,IAAIe,UAAAA,aAAa,UAAU;CACpC;AACF"}
1
+ {"version":3,"file":"EthereumStepExecutor.js","names":["BaseStepExecutor","createDefaultStorage","parseEthereumErrors","switchChain","getAction","getAddresses","TransactionError","LiFiErrorCode","isZeroAddress","EthereumCheckPermitsTask","EthereumCheckAllowanceTask","EthereumNativePermitTask","EthereumResetAllowanceTask","EthereumSetAllowanceTask","EthereumCheckBalanceTask","EthereumPermit2AllowanceTask","EthereumPrepareTransactionTask","EthereumCheckAllowanceAfterPrepareTask","EthereumSignAndExecuteTask","EthereumWaitForTransactionTask","EthereumWaitForTransactionStatusTask","shouldCheckForAllowance","hasOpenTransaction","TaskPipeline"],"sources":["../../../src/core/EthereumStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n createDefaultStorage,\n type ExecuteStepRetryError,\n type ExecuteStepRetryParams,\n type ExecutionAction,\n hasOpenTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n type SDKClient,\n type SDKError,\n type SDKStorage,\n type StepExecutorBaseContext,\n type StepExecutorOptions,\n TaskPipeline,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Client, GetAddressesReturnType } from 'viem'\nimport { getAddresses } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { parseEthereumErrors } from '../errors/parseEthereumErrors.js'\nimport type { EthereumStepExecutorContext } from '../types.js'\nimport { isZeroAddress } from '../utils/isZeroAddress.js'\nimport { EthereumCheckAllowanceAfterPrepareTask } from './tasks/EthereumCheckAllowanceAfterPrepareTask.js'\nimport { EthereumCheckAllowanceTask } from './tasks/EthereumCheckAllowanceTask.js'\nimport { EthereumCheckBalanceTask } from './tasks/EthereumCheckBalanceTask.js'\nimport { EthereumCheckPermitsTask } from './tasks/EthereumCheckPermitsTask.js'\nimport { EthereumNativePermitTask } from './tasks/EthereumNativePermitTask.js'\nimport { EthereumPermit2AllowanceTask } from './tasks/EthereumPermit2AllowanceTask.js'\nimport { EthereumPrepareTransactionTask } from './tasks/EthereumPrepareTransactionTask.js'\nimport { EthereumResetAllowanceTask } from './tasks/EthereumResetAllowanceTask.js'\nimport { EthereumSetAllowanceTask } from './tasks/EthereumSetAllowanceTask.js'\nimport { EthereumSignAndExecuteTask } from './tasks/EthereumSignAndExecuteTask.js'\nimport { EthereumWaitForTransactionStatusTask } from './tasks/EthereumWaitForTransactionStatusTask.js'\nimport { EthereumWaitForTransactionTask } from './tasks/EthereumWaitForTransactionTask.js'\nimport { shouldCheckForAllowance } from './tasks/helpers/shouldCheckForAllowance.js'\nimport { switchChain } from './tasks/helpers/switchChain.js'\n\ninterface EthereumStepExecutorOptions extends StepExecutorOptions {\n client: Client\n switchChain?: (chainId: number) => Promise<Client | undefined>\n disableMessageSigning?: boolean\n}\n\nexport class EthereumStepExecutor extends BaseStepExecutor {\n private client: Client\n private switchChain?: (chainId: number) => Promise<Client | undefined>\n private storage?: SDKStorage\n private disableMessageSigning?: boolean\n\n constructor(options: EthereumStepExecutorOptions) {\n super(options)\n this.client = options.client\n this.switchChain = options.switchChain\n this.disableMessageSigning = options.disableMessageSigning\n }\n\n private getStorage = (client: SDKClient): SDKStorage => {\n if (!this.storage) {\n this.storage = client.config.storage ?? createDefaultStorage()\n }\n return this.storage\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction,\n retryParams?: ExecuteStepRetryParams\n ): Promise<SDKError | ExecuteStepRetryError> =>\n parseEthereumErrors(error, step, action, retryParams)\n\n // Ensure that we are using the right chain and wallet when executing transactions.\n checkClient = async (\n step: LiFiStepExtended,\n targetChainId?: number\n ): Promise<Client | undefined> => {\n const updatedClient = await switchChain(\n this.client,\n targetChainId ?? step.action.fromChainId,\n this.allowUserInteraction,\n this.switchChain\n )\n if (updatedClient) {\n this.client = updatedClient\n }\n\n // Prevent execution of the quote by wallet different from the one which requested the quote\n let accountAddress = this.client.account?.address\n if (!accountAddress) {\n const accountAddresses = (await getAction(\n this.client,\n getAddresses,\n 'getAddresses'\n )(undefined)) as GetAddressesReturnType\n accountAddress = accountAddresses?.[0]\n }\n if (\n accountAddress?.toLowerCase() !== step.action.fromAddress?.toLowerCase()\n ) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n return updatedClient\n }\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<EthereumStepExecutorContext> => {\n const { step, fromChain } = baseContext\n\n const isFromNativeToken =\n fromChain.nativeToken.address === step.action.fromToken.address &&\n isZeroAddress(step.action.fromToken.address)\n\n // Check if message signing is disabled - useful for smart contract wallets\n // We also disable message signing for custom steps\n const disableMessageSigning =\n !!this.disableMessageSigning || step.type !== 'lifi'\n\n return {\n ...baseContext,\n isFromNativeToken,\n disableMessageSigning,\n ethereumClient: this.client,\n checkClient: this.checkClient,\n getStorage: this.getStorage,\n // Signed typed data for native permits and other messages\n signedTypedData: [],\n // Calls for atomic batch transactions (EIP-5792)\n calls: [],\n }\n }\n\n override createPipeline = (\n context: EthereumStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution, isFromNativeToken } = context\n\n const tasks = [\n new EthereumCheckPermitsTask(),\n new EthereumCheckAllowanceTask(),\n new EthereumNativePermitTask(),\n new EthereumResetAllowanceTask(),\n new EthereumSetAllowanceTask(),\n new EthereumCheckBalanceTask(),\n new EthereumPermit2AllowanceTask(),\n new EthereumPrepareTransactionTask(),\n new EthereumCheckAllowanceAfterPrepareTask(),\n new EthereumSignAndExecuteTask(),\n new EthereumWaitForTransactionTask(),\n new EthereumWaitForTransactionStatusTask(),\n ]\n\n const doCheckAllowance = shouldCheckForAllowance(\n step,\n isBridgeExecution,\n isFromNativeToken,\n this.statusManager\n )\n\n let firstTask:\n | typeof EthereumCheckPermitsTask\n | typeof EthereumCheckBalanceTask\n | typeof EthereumWaitForTransactionTask\n | typeof EthereumWaitForTransactionStatusTask\n if (doCheckAllowance) {\n firstTask = EthereumCheckPermitsTask\n } else {\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n // Same predicate as the pre-sign guard: an open transaction is waited\n // for, a FAILED action with a final outcome signs again.\n firstTask = hasOpenTransaction(swapOrBridgeAction)\n ? swapOrBridgeAction?.status === 'DONE'\n ? EthereumWaitForTransactionStatusTask\n : EthereumWaitForTransactionTask\n : EthereumCheckBalanceTask\n }\n\n // Compare classes, not names: a minifier can give two task classes the\n // same name.\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor === firstTask\n )\n if (firstTaskIndex === -1) {\n throw new TransactionError(\n LiFiErrorCode.InternalError,\n 'EthereumStepExecutor.createPipeline: first task not found'\n )\n }\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4CA,IAAa,uBAAb,cAA0CA,UAAAA,iBAAiB;CACzD;CACA;CACA;CACA;CAEA,YAAY,SAAsC;EAChD,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;EACtB,KAAK,cAAc,QAAQ;EAC3B,KAAK,wBAAwB,QAAQ;CACvC;CAEA,cAAsB,WAAkC;EACtD,IAAI,CAAC,KAAK,SACR,KAAK,UAAU,OAAO,OAAO,YAAA,GAAWC,UAAAA,qBAAAA,CAAqB;EAE/D,OAAO,KAAK;CACd;CAEA,eACE,OACA,MACA,QACA,gBAEAC,mCAAAA,oBAAoB,OAAO,MAAM,QAAQ,WAAW;CAGtD,cAAc,OACZ,MACA,kBACgC;EAChC,MAAM,gBAAgB,MAAMC,uCAAAA,YAC1B,KAAK,QACL,iBAAiB,KAAK,OAAO,aAC7B,KAAK,sBACL,KAAK,WACP;EACA,IAAI,eACF,KAAK,SAAS;EAIhB,IAAI,iBAAiB,KAAK,OAAO,SAAS;EAC1C,IAAI,CAAC,gBAMH,kBAAiB,OAAA,GALeC,WAAAA,UAAAA,CAC9B,KAAK,QACLC,aAAAA,cACA,cACF,CAAC,CAAC,KAAA,CAAS,EAAA,GACyB;EAEtC,IACE,gBAAgB,YAAY,MAAM,KAAK,OAAO,aAAa,YAAY,GAEvE,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,8BACd,mHACF;EAEF,OAAO;CACT;CAEA,gBAAyB,OACvB,gBACyC;EACzC,MAAM,EAAE,MAAM,cAAc;EAE5B,MAAM,oBACJ,UAAU,YAAY,YAAY,KAAK,OAAO,UAAU,WACxDC,4BAAAA,cAAc,KAAK,OAAO,UAAU,OAAO;EAI7C,MAAM,wBACJ,CAAC,CAAC,KAAK,yBAAyB,KAAK,SAAS;EAEhD,OAAO;GACL,GAAG;GACH;GACA;GACA,gBAAgB,KAAK;GACrB,aAAa,KAAK;GAClB,YAAY,KAAK;GAEjB,iBAAiB,CAAC;GAElB,OAAO,CAAC;EACV;CACF;CAEA,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,mBAAmB,sBAAsB;EAEvD,MAAM,QAAQ;GACZ,IAAIC,4CAAAA,yBAAyB;GAC7B,IAAIC,8CAAAA,2BAA2B;GAC/B,IAAIC,4CAAAA,yBAAyB;GAC7B,IAAIC,8CAAAA,2BAA2B;GAC/B,IAAIC,4CAAAA,yBAAyB;GAC7B,IAAIC,4CAAAA,yBAAyB;GAC7B,IAAIC,gDAAAA,6BAA6B;GACjC,IAAIC,kDAAAA,+BAA+B;GACnC,IAAIC,0DAAAA,uCAAuC;GAC3C,IAAIC,8CAAAA,2BAA2B;GAC/B,IAAIC,kDAAAA,+BAA+B;GACnC,IAAIC,wDAAAA,qCAAqC;EAC3C;EAEA,MAAM,mBAAmBC,mDAAAA,wBACvB,MACA,mBACA,mBACA,KAAK,aACP;EAEA,IAAI;EAKJ,IAAI,kBACF,YAAYZ,4CAAAA;OACP;GACL,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;GAGA,aAAA,GAAYa,UAAAA,mBAAAA,CAAmB,kBAAkB,IAC7C,oBAAoB,WAAW,SAC7BF,wDAAAA,uCACAD,kDAAAA,iCACFL,4CAAAA;EACN;EAIA,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,gBAAgB,SACjC;EACA,IAAI,mBAAmB,IACrB,MAAM,IAAIR,UAAAA,iBACRC,UAAAA,cAAc,eACd,2DACF;EAGF,MAAM,aAAa,MAAM,MAAM,cAAc;EAE7C,OAAO,IAAIgB,UAAAA,aAAa,UAAU;CACpC;AACF"}
@@ -0,0 +1,20 @@
1
+ import { EthereumStepExecutorContext } from "../../types.js";
2
+ import { BaseStepExecutionTask, TaskResult } from "@lifi/sdk";
3
+ //#region src/core/tasks/EthereumCheckAllowanceAfterPrepareTask.d.ts
4
+ /**
5
+ * Runs after PrepareTransaction. Some providers only know the spender once
6
+ * `/stepTransaction` builds the executable transaction, so the routing-time
7
+ * step carries no `estimate.approvalAddress` and the allowance tasks before
8
+ * prepare do not run. When the re-quote brings one, the allowance is read for
9
+ * it, and reset and set only if it falls short, before the transaction is
10
+ * signed.
11
+ *
12
+ * A spender that was already set before prepare is not checked again here.
13
+ */
14
+ export declare class EthereumCheckAllowanceAfterPrepareTask extends BaseStepExecutionTask {
15
+ private readonly allowancePipeline;
16
+ override shouldRun(context: EthereumStepExecutorContext): Promise<boolean>;
17
+ run(context: EthereumStepExecutorContext): Promise<TaskResult>;
18
+ }
19
+ //#endregion
20
+ //# sourceMappingURL=EthereumCheckAllowanceAfterPrepareTask.d.ts.map
@@ -0,0 +1,34 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_core_tasks_EthereumCheckAllowanceTask = require("./EthereumCheckAllowanceTask.js");
3
+ const require_core_tasks_EthereumResetAllowanceTask = require("./EthereumResetAllowanceTask.js");
4
+ const require_core_tasks_EthereumSetAllowanceTask = require("./EthereumSetAllowanceTask.js");
5
+ const require_core_tasks_helpers_hasApprovalAddressAppearedAtPrepare = require("./helpers/hasApprovalAddressAppearedAtPrepare.js");
6
+ let _lifi_sdk = require("@lifi/sdk");
7
+ //#region src/core/tasks/EthereumCheckAllowanceAfterPrepareTask.ts
8
+ /**
9
+ * Runs after PrepareTransaction. Some providers only know the spender once
10
+ * `/stepTransaction` builds the executable transaction, so the routing-time
11
+ * step carries no `estimate.approvalAddress` and the allowance tasks before
12
+ * prepare do not run. When the re-quote brings one, the allowance is read for
13
+ * it, and reset and set only if it falls short, before the transaction is
14
+ * signed.
15
+ *
16
+ * A spender that was already set before prepare is not checked again here.
17
+ */
18
+ var EthereumCheckAllowanceAfterPrepareTask = class extends _lifi_sdk.BaseStepExecutionTask {
19
+ allowancePipeline = new _lifi_sdk.TaskPipeline([
20
+ new require_core_tasks_EthereumCheckAllowanceTask.EthereumCheckAllowanceTask(),
21
+ new require_core_tasks_EthereumResetAllowanceTask.EthereumResetAllowanceTask(),
22
+ new require_core_tasks_EthereumSetAllowanceTask.EthereumSetAllowanceTask()
23
+ ]);
24
+ async shouldRun(context) {
25
+ return require_core_tasks_helpers_hasApprovalAddressAppearedAtPrepare.hasApprovalAddressAppearedAtPrepare(context);
26
+ }
27
+ async run(context) {
28
+ return this.allowancePipeline.run(context);
29
+ }
30
+ };
31
+ //#endregion
32
+ exports.EthereumCheckAllowanceAfterPrepareTask = EthereumCheckAllowanceAfterPrepareTask;
33
+
34
+ //# sourceMappingURL=EthereumCheckAllowanceAfterPrepareTask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EthereumCheckAllowanceAfterPrepareTask.js","names":["BaseStepExecutionTask","TaskPipeline","EthereumCheckAllowanceTask","EthereumResetAllowanceTask","EthereumSetAllowanceTask","hasApprovalAddressAppearedAtPrepare"],"sources":["../../../../src/core/tasks/EthereumCheckAllowanceAfterPrepareTask.ts"],"sourcesContent":["import { BaseStepExecutionTask, TaskPipeline, type TaskResult } from '@lifi/sdk'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { EthereumCheckAllowanceTask } from './EthereumCheckAllowanceTask.js'\nimport { EthereumResetAllowanceTask } from './EthereumResetAllowanceTask.js'\nimport { EthereumSetAllowanceTask } from './EthereumSetAllowanceTask.js'\nimport { hasApprovalAddressAppearedAtPrepare } from './helpers/hasApprovalAddressAppearedAtPrepare.js'\n\n/**\n * Runs after PrepareTransaction. Some providers only know the spender once\n * `/stepTransaction` builds the executable transaction, so the routing-time\n * step carries no `estimate.approvalAddress` and the allowance tasks before\n * prepare do not run. When the re-quote brings one, the allowance is read for\n * it, and reset and set only if it falls short, before the transaction is\n * signed.\n *\n * A spender that was already set before prepare is not checked again here.\n */\nexport class EthereumCheckAllowanceAfterPrepareTask extends BaseStepExecutionTask {\n private readonly allowancePipeline = new TaskPipeline([\n new EthereumCheckAllowanceTask(),\n new EthereumResetAllowanceTask(),\n new EthereumSetAllowanceTask(),\n ])\n\n override async shouldRun(\n context: EthereumStepExecutorContext\n ): Promise<boolean> {\n return hasApprovalAddressAppearedAtPrepare(context)\n }\n\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n return this.allowancePipeline.run(context)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,IAAa,yCAAb,cAA4DA,UAAAA,sBAAsB;CAChF,oBAAqC,IAAIC,UAAAA,aAAa;EACpD,IAAIC,8CAAAA,2BAA2B;EAC/B,IAAIC,8CAAAA,2BAA2B;EAC/B,IAAIC,4CAAAA,yBAAyB;CAC/B,CAAC;CAED,MAAe,UACb,SACkB;EAClB,OAAOC,+DAAAA,oCAAoC,OAAO;CACpD;CAEA,MAAM,IAAI,SAA2D;EACnE,OAAO,KAAK,kBAAkB,IAAI,OAAO;CAC3C;AACF"}
@@ -0,0 +1,11 @@
1
+ import { EthereumStepExecutorContext } from "../../../types.js";
2
+ //#region src/core/tasks/helpers/hasApprovalAddressAppearedAtPrepare.d.ts
3
+ /**
4
+ * Whether the step had no `estimate.approvalAddress` before prepare and the
5
+ * re-quote brought one. No allowance was checked then (`allowanceSpender` is
6
+ * unset), and the step now needs it checked. The allowance tasks resolve the
7
+ * spender themselves, so on a Permit2 chain they approve `fromChain.permit2`.
8
+ */
9
+ export declare const hasApprovalAddressAppearedAtPrepare: (context: EthereumStepExecutorContext) => boolean;
10
+ //#endregion
11
+ //# sourceMappingURL=hasApprovalAddressAppearedAtPrepare.d.ts.map
@@ -0,0 +1,17 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_core_tasks_helpers_shouldCheckForAllowance = require("./shouldCheckForAllowance.js");
3
+ //#region src/core/tasks/helpers/hasApprovalAddressAppearedAtPrepare.ts
4
+ /**
5
+ * Whether the step had no `estimate.approvalAddress` before prepare and the
6
+ * re-quote brought one. No allowance was checked then (`allowanceSpender` is
7
+ * unset), and the step now needs it checked. The allowance tasks resolve the
8
+ * spender themselves, so on a Permit2 chain they approve `fromChain.permit2`.
9
+ */
10
+ const hasApprovalAddressAppearedAtPrepare = (context) => {
11
+ const { step, allowanceSpender, isBridgeExecution, isFromNativeToken, statusManager } = context;
12
+ return !allowanceSpender && require_core_tasks_helpers_shouldCheckForAllowance.shouldCheckForAllowance(step, isBridgeExecution, isFromNativeToken, statusManager);
13
+ };
14
+ //#endregion
15
+ exports.hasApprovalAddressAppearedAtPrepare = hasApprovalAddressAppearedAtPrepare;
16
+
17
+ //# sourceMappingURL=hasApprovalAddressAppearedAtPrepare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasApprovalAddressAppearedAtPrepare.js","names":["shouldCheckForAllowance"],"sources":["../../../../../src/core/tasks/helpers/hasApprovalAddressAppearedAtPrepare.ts"],"sourcesContent":["import type { EthereumStepExecutorContext } from '../../../types.js'\nimport { shouldCheckForAllowance } from './shouldCheckForAllowance.js'\n\n/**\n * Whether the step had no `estimate.approvalAddress` before prepare and the\n * re-quote brought one. No allowance was checked then (`allowanceSpender` is\n * unset), and the step now needs it checked. The allowance tasks resolve the\n * spender themselves, so on a Permit2 chain they approve `fromChain.permit2`.\n */\nexport const hasApprovalAddressAppearedAtPrepare = (\n context: EthereumStepExecutorContext\n): boolean => {\n const {\n step,\n allowanceSpender,\n isBridgeExecution,\n isFromNativeToken,\n statusManager,\n } = context\n return (\n !allowanceSpender &&\n shouldCheckForAllowance(\n step,\n isBridgeExecution,\n isFromNativeToken,\n statusManager\n )\n )\n}\n"],"mappings":";;;;;;;;;AASA,MAAa,uCACX,YACY;CACZ,MAAM,EACJ,MACA,kBACA,mBACA,mBACA,kBACE;CACJ,OACE,CAAC,oBACDA,mDAAAA,wBACE,MACA,mBACA,mBACA,aACF;AAEJ"}
package/dist/cjs/index.js CHANGED
@@ -3,12 +3,12 @@ const require_utils_isZeroAddress = require("./utils/isZeroAddress.js");
3
3
  const require_actions_getAllowance = require("./actions/getAllowance.js");
4
4
  const require_actions_isBatchingSupported = require("./actions/isBatchingSupported.js");
5
5
  const require_utils_isGaslessStep = require("./utils/isGaslessStep.js");
6
+ const require_types = require("./types.js");
6
7
  const require_permits_isDelegationDesignatorCode = require("./permits/isDelegationDesignatorCode.js");
8
+ const require_actions_setAllowance = require("./actions/setAllowance.js");
7
9
  const require_permits_constants = require("./permits/constants.js");
8
10
  const require_permits_getNativePermit = require("./permits/getNativePermit.js");
9
11
  const require_utils_isContractCallStep = require("./utils/isContractCallStep.js");
10
- const require_types = require("./types.js");
11
- const require_actions_setAllowance = require("./actions/setAllowance.js");
12
12
  const require_hyperliquid_isHyperliquidAgentStep = require("./hyperliquid/isHyperliquidAgentStep.js");
13
13
  const require_utils_convertExtendedChain = require("./utils/convertExtendedChain.js");
14
14
  const require_EthereumProvider = require("./EthereumProvider.js");
@@ -2,8 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_utils_abi = require("../utils/abi.js");
3
3
  const require_actions_getMulticallAddress = require("../actions/getMulticallAddress.js");
4
4
  const require_utils_getActionWithFallback = require("../utils/getActionWithFallback.js");
5
- const require_permits_canAccountUseNativePermits = require("./canAccountUseNativePermits.js");
6
5
  const require_permits_constants = require("./constants.js");
6
+ const require_permits_canAccountUseNativePermits = require("./canAccountUseNativePermits.js");
7
7
  let viem = require("viem");
8
8
  let viem_actions = require("viem/actions");
9
9
  //#region src/permits/getNativePermit.ts
@@ -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.10";
3
+ export declare const version = "4.2.12";
4
4
  //#endregion
5
5
  //# sourceMappingURL=version.d.ts.map
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/version.ts
3
3
  const name = "@lifi/sdk-provider-ethereum";
4
- const version = "4.2.10";
4
+ const version = "4.2.12";
5
5
  //#endregion
6
6
  exports.name = name;
7
7
  exports.version = version;
@@ -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.10'\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.12'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
@@ -1,6 +1,6 @@
1
1
  import { getAccountCode } from "./getAccountCode.js";
2
- import { isSmartContractWalletCode } from "./isSmartContractWallet.js";
3
2
  import { getSafeClient } from "../client/safeClient.js";
3
+ import { isSmartContractWalletCode } from "./isSmartContractWallet.js";
4
4
  import { LruMap } from "@lifi/sdk";
5
5
  //#region src/actions/isSafeWallet.ts
6
6
  const safeWalletCache = new LruMap(12);
@@ -1 +1 @@
1
- {"version":3,"file":"waitForBatchTransactionReceipt.d.ts","names":["WalletCallReceipt"],"sources":["../../../src/actions/waitForBatchTransactionReceipt.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;qBA+Ca,iCACX,QAAQ,QACR,WAAW,QAET,UACA,UACA;EAEA,YAAY,QAAQ;EACpB;EACA;MAED,QAAQA"}
1
+ {"version":3,"file":"waitForBatchTransactionReceipt.d.ts","names":["WalletCallReceipt"],"sources":["../../../src/actions/waitForBatchTransactionReceipt.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;qBAkEa,iCACX,QAAQ,QACR,WAAW,QAET,UACA,UACA;EAEA,YAAY,QAAQ;EACpB;EACA;MAED,QAAQA"}
@@ -4,6 +4,15 @@ import { waitForCallsStatus } from "viem/actions";
4
4
  import { getAction } from "viem/utils";
5
5
  //#region src/actions/waitForBatchTransactionReceipt.ts
6
6
  const DROPPED_BUNDLE_MAX_AGE_MS = 6e5;
7
+ /**
8
+ * viem shares one poll between the waits for the same client and id, and
9
+ * calls only the predicate of the wait that started it. Since viem 2.57.5 the
10
+ * shared poll also needs the same `status` function (compared by identity).
11
+ * All waits for one bundle thus pass the same predicate from this map. Then
12
+ * they share one poll in every viem version, and only the first wait of the
13
+ * bundle can see the wallet's answers.
14
+ */
15
+ const bundleWaits = /* @__PURE__ */ new Map();
7
16
  const isUnknownBundleIdError = (error) => error?.name === "UnknownBundleIdError" || error?.cause?.name === "UnknownBundleIdError" || error?.code === UnknownBundleIdError.code;
8
17
  /**
9
18
  * Unknown signing time is never in the window. Nor is a signing time in the
@@ -34,21 +43,38 @@ const isWithinDropWindow = (signedAt) => {
34
43
  * @throws Any other error of the wallet, unchanged.
35
44
  */
36
45
  const waitForBatchTransactionReceipt = async (client, batchHash, { onFailed, signedAt, callCount } = {}) => {
37
- let known = false;
46
+ const waitKey = `${client.uid}:${batchHash}`;
47
+ let bundleWait = bundleWaits.get(waitKey);
48
+ const startedPoll = !bundleWait;
49
+ if (!bundleWait) {
50
+ const created = {
51
+ status: ({ statusCode }) => {
52
+ created.answered = true;
53
+ return statusCode === 200 || statusCode >= 300;
54
+ },
55
+ answered: false,
56
+ waiters: 0
57
+ };
58
+ bundleWait = created;
59
+ bundleWaits.set(waitKey, created);
60
+ }
61
+ const sharedWait = bundleWait;
62
+ sharedWait.waiters += 1;
38
63
  let result;
39
64
  try {
40
65
  result = await getAction(client, waitForCallsStatus, "waitForCallsStatus")({
41
66
  id: batchHash,
42
67
  timeout: 864e5,
43
- status: ({ statusCode }) => {
44
- known = true;
45
- return statusCode === 200 || statusCode >= 300;
46
- }
68
+ status: sharedWait.status
47
69
  });
48
70
  } catch (error) {
71
+ const known = startedPoll && sharedWait.answered;
49
72
  if (!isUnknownBundleIdError(error)) throw error;
50
73
  if (known && callCount === 1 && isWithinDropWindow(signedAt)) throw new TransactionError(LiFiErrorCode.SignatureRejected, "The wallet has no record of the call bundle. The SDK treats it as never sent.", error, { final: true });
51
74
  throw new TransactionError(LiFiErrorCode.CallBundleNotFound, "The wallet has no record of the call bundle.", error);
75
+ } finally {
76
+ sharedWait.waiters -= 1;
77
+ if (sharedWait.waiters === 0 && bundleWaits.get(waitKey) === sharedWait) bundleWaits.delete(waitKey);
52
78
  }
53
79
  if (result.status === "success") {
54
80
  if (result.receipts?.some((receipt) => receipt.status === "reverted")) {
@@ -1 +1 @@
1
- {"version":3,"file":"waitForBatchTransactionReceipt.js","names":[],"sources":["../../../src/actions/waitForBatchTransactionReceipt.ts"],"sourcesContent":["import { LiFiErrorCode, TransactionError } from '@lifi/sdk'\nimport { type Client, type Hash, UnknownBundleIdError } from 'viem'\nimport { type GetCallsStatusReturnType, waitForCallsStatus } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { WalletCallReceipt } from '../types.js'\n\n// Some wallets answer from a remote service that can forget an old bundle.\nconst DROPPED_BUNDLE_MAX_AGE_MS = 10 * 60_000\n\nconst isUnknownBundleIdError = (error: any): boolean =>\n error?.name === 'UnknownBundleIdError' ||\n error?.cause?.name === 'UnknownBundleIdError' ||\n error?.code === UnknownBundleIdError.code\n\n/**\n * Unknown signing time is never in the window. Nor is a signing time in the\n * future, as in `isResendAllowed`.\n */\nconst isWithinDropWindow = (signedAt: number | undefined): boolean => {\n const now = Date.now()\n return (\n signedAt !== undefined &&\n now >= signedAt &&\n now - signedAt < DROPPED_BUNDLE_MAX_AGE_MS\n )\n}\n\n/**\n * Waits until the wallet reports the EIP-5792 call bundle as done or failed.\n *\n * MetaMask returns the id of a single-call bundle before the user approves\n * it, and removes the bundle on a reject: `wallet_getCallsStatus` then fails\n * with 5730 (`UnknownBundleIdError`). It returns the id of a bundle of two or\n * more calls only after it sent the bundle. Thus the SDK treats a bundle as\n * never sent only when all of these are true: its stored `callCount` is 1,\n * the wallet answered for it in this wait and then has no record of it, and\n * this happens within `DROPPED_BUNDLE_MAX_AGE_MS` of signing.\n *\n * @param client - The wallet client that sent the bundle.\n * @param batchHash - The bundle id that `wallet_sendCalls` returned.\n * @param options.onFailed - Gets the wallet's answer for a failed bundle, before the error is thrown.\n * @param options.signedAt - The signing time of the step (`execution.signedAt`).\n * @param options.callCount - The stored number of calls of the bundle (`action.callCount`).\n * @returns The receipt of the last call of the bundle.\n * @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.\n * @throws Any other error of the wallet, unchanged.\n */\nexport const waitForBatchTransactionReceipt = async (\n client: Client,\n batchHash: Hash,\n {\n onFailed,\n signedAt,\n callCount,\n }: {\n onFailed?: (result: GetCallsStatusReturnType) => void\n signedAt?: number\n callCount?: number\n } = {}\n): Promise<WalletCallReceipt> => {\n let known = false\n let result: GetCallsStatusReturnType\n try {\n result = await getAction(\n client,\n waitForCallsStatus,\n 'waitForCallsStatus'\n )({\n id: batchHash,\n timeout: 3_600_000 * 24,\n // viem's default, and a record that the wallet answered for this id.\n // viem shares one poll between waits for the same client and id, and\n // calls only the predicate of the wait that started it.\n status: ({ statusCode }) => {\n known = true\n return statusCode === 200 || statusCode >= 300\n },\n })\n } catch (error) {\n if (!isUnknownBundleIdError(error)) {\n throw error\n }\n // MetaMask removes a single-call bundle in this way only before it sends\n // it. The SDK treats the bundle as never sent: a final rejection, so\n // \"Try again\" signs anew.\n if (known && callCount === 1 && isWithinDropWindow(signedAt)) {\n throw new TransactionError(\n LiFiErrorCode.SignatureRejected,\n 'The wallet has no record of the call bundle. The SDK treats it as never sent.',\n error as Error,\n { final: true }\n )\n }\n // Unknown from the first answer (a reload after the reject, another\n // wallet), too long after signing, or no stored count of one call (two\n // or more calls, or a route stored without the count): the bundle may\n // still land.\n throw new TransactionError(\n LiFiErrorCode.CallBundleNotFound,\n 'The wallet has no record of the call bundle.',\n error as Error\n )\n }\n\n if (result.status === 'success') {\n if (result.receipts?.some((receipt) => receipt.status === 'reverted')) {\n onFailed?.(result)\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction was reverted.',\n undefined,\n { final: true }\n )\n }\n // The wallet reports the batch as executed, but without a complete set of\n // receipts we cannot prove the outcome: it stays unknown.\n if (\n !result.receipts?.length ||\n !result.receipts.every((receipt) => receipt.transactionHash)\n ) {\n onFailed?.(result)\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction was reverted.'\n )\n }\n const transactionReceipt = result.receipts.at(-1)!\n return transactionReceipt\n }\n if (result.statusCode >= 400 && result.statusCode < 500) {\n onFailed?.(result)\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'Transaction was canceled.',\n undefined,\n { final: true }\n )\n }\n onFailed?.(result)\n // Only 500 (reverted completely) is final. Some calls of a partial batch\n // (600) may be onchain, and other codes are undefined: the outcome is unknown.\n if (result.statusCode === 500) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction failed.',\n undefined,\n { final: true }\n )\n }\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction failed.'\n )\n}\n"],"mappings":";;;;;AAOA,MAAM,4BAA4B;AAElC,MAAM,0BAA0B,UAC9B,OAAO,SAAS,0BAChB,OAAO,OAAO,SAAS,0BACvB,OAAO,SAAS,qBAAqB;;;;;AAMvC,MAAM,sBAAsB,aAA0C;CACpE,MAAM,MAAM,KAAK,IAAI;CACrB,OACE,aAAa,KAAA,KACb,OAAO,YACP,MAAM,WAAW;AAErB;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,iCAAiC,OAC5C,QACA,WACA,EACE,UACA,UACA,cAKE,CAAC,MAC0B;CAC/B,IAAI,QAAQ;CACZ,IAAI;CACJ,IAAI;EACF,SAAS,MAAM,UACb,QACA,oBACA,oBACF,CAAC,CAAC;GACA,IAAI;GACJ,SAAS;GAIT,SAAS,EAAE,iBAAiB;IAC1B,QAAQ;IACR,OAAO,eAAe,OAAO,cAAc;GAC7C;EACF,CAAC;CACH,SAAS,OAAO;EACd,IAAI,CAAC,uBAAuB,KAAK,GAC/B,MAAM;EAKR,IAAI,SAAS,cAAc,KAAK,mBAAmB,QAAQ,GACzD,MAAM,IAAI,iBACR,cAAc,mBACd,iFACA,OACA,EAAE,OAAO,KAAK,CAChB;EAMF,MAAM,IAAI,iBACR,cAAc,oBACd,gDACA,KACF;CACF;CAEA,IAAI,OAAO,WAAW,WAAW;EAC/B,IAAI,OAAO,UAAU,MAAM,YAAY,QAAQ,WAAW,UAAU,GAAG;GACrE,WAAW,MAAM;GACjB,MAAM,IAAI,iBACR,cAAc,mBACd,6BACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;EACF;EAGA,IACE,CAAC,OAAO,UAAU,UAClB,CAAC,OAAO,SAAS,OAAO,YAAY,QAAQ,eAAe,GAC3D;GACA,WAAW,MAAM;GACjB,MAAM,IAAI,iBACR,cAAc,mBACd,2BACF;EACF;EAEA,OAD2B,OAAO,SAAS,GAAG,EACtB;CAC1B;CACA,IAAI,OAAO,cAAc,OAAO,OAAO,aAAa,KAAK;EACvD,WAAW,MAAM;EACjB,MAAM,IAAI,iBACR,cAAc,qBACd,6BACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;CACF;CACA,WAAW,MAAM;CAGjB,IAAI,OAAO,eAAe,KACxB,MAAM,IAAI,iBACR,cAAc,mBACd,uBACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;CAEF,MAAM,IAAI,iBACR,cAAc,mBACd,qBACF;AACF"}
1
+ {"version":3,"file":"waitForBatchTransactionReceipt.js","names":[],"sources":["../../../src/actions/waitForBatchTransactionReceipt.ts"],"sourcesContent":["import { LiFiErrorCode, TransactionError } from '@lifi/sdk'\nimport { type Client, type Hash, UnknownBundleIdError } from 'viem'\nimport { type GetCallsStatusReturnType, waitForCallsStatus } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { WalletCallReceipt } from '../types.js'\n\n// Some wallets answer from a remote service that can forget an old bundle.\nconst DROPPED_BUNDLE_MAX_AGE_MS = 10 * 60_000\n\ntype BundleWait = {\n /** The one `status` predicate that every wait for the bundle passes. */\n status: (result: { statusCode: number }) => boolean\n /** True after the wallet answered for the bundle in the shared poll. */\n answered: boolean\n /** The waits that did not finish yet. */\n waiters: number\n}\n\n/**\n * viem shares one poll between the waits for the same client and id, and\n * calls only the predicate of the wait that started it. Since viem 2.57.5 the\n * shared poll also needs the same `status` function (compared by identity).\n * All waits for one bundle thus pass the same predicate from this map. Then\n * they share one poll in every viem version, and only the first wait of the\n * bundle can see the wallet's answers.\n */\nconst bundleWaits = new Map<string, BundleWait>()\n\nconst isUnknownBundleIdError = (error: any): boolean =>\n error?.name === 'UnknownBundleIdError' ||\n error?.cause?.name === 'UnknownBundleIdError' ||\n error?.code === UnknownBundleIdError.code\n\n/**\n * Unknown signing time is never in the window. Nor is a signing time in the\n * future, as in `isResendAllowed`.\n */\nconst isWithinDropWindow = (signedAt: number | undefined): boolean => {\n const now = Date.now()\n return (\n signedAt !== undefined &&\n now >= signedAt &&\n now - signedAt < DROPPED_BUNDLE_MAX_AGE_MS\n )\n}\n\n/**\n * Waits until the wallet reports the EIP-5792 call bundle as done or failed.\n *\n * MetaMask returns the id of a single-call bundle before the user approves\n * it, and removes the bundle on a reject: `wallet_getCallsStatus` then fails\n * with 5730 (`UnknownBundleIdError`). It returns the id of a bundle of two or\n * more calls only after it sent the bundle. Thus the SDK treats a bundle as\n * never sent only when all of these are true: its stored `callCount` is 1,\n * the wallet answered for it in this wait and then has no record of it, and\n * this happens within `DROPPED_BUNDLE_MAX_AGE_MS` of signing.\n *\n * @param client - The wallet client that sent the bundle.\n * @param batchHash - The bundle id that `wallet_sendCalls` returned.\n * @param options.onFailed - Gets the wallet's answer for a failed bundle, before the error is thrown.\n * @param options.signedAt - The signing time of the step (`execution.signedAt`).\n * @param options.callCount - The stored number of calls of the bundle (`action.callCount`).\n * @returns The receipt of the last call of the bundle.\n * @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.\n * @throws Any other error of the wallet, unchanged.\n */\nexport const waitForBatchTransactionReceipt = async (\n client: Client,\n batchHash: Hash,\n {\n onFailed,\n signedAt,\n callCount,\n }: {\n onFailed?: (result: GetCallsStatusReturnType) => void\n signedAt?: number\n callCount?: number\n } = {}\n): Promise<WalletCallReceipt> => {\n const waitKey = `${client.uid}:${batchHash}`\n let bundleWait = bundleWaits.get(waitKey)\n // The first wait of a bundle starts the poll. A wait that joins it does not\n // see the wallet's answers, so it never has a record of them.\n const startedPoll = !bundleWait\n if (!bundleWait) {\n const created: BundleWait = {\n // viem's default, and a record that the wallet answered for this id.\n status: ({ statusCode }) => {\n created.answered = true\n return statusCode === 200 || statusCode >= 300\n },\n answered: false,\n waiters: 0,\n }\n bundleWait = created\n bundleWaits.set(waitKey, created)\n }\n const sharedWait = bundleWait\n sharedWait.waiters += 1\n\n let result: GetCallsStatusReturnType\n try {\n result = await getAction(\n client,\n waitForCallsStatus,\n 'waitForCallsStatus'\n )({\n id: batchHash,\n timeout: 3_600_000 * 24,\n status: sharedWait.status,\n })\n } catch (error) {\n const known = startedPoll && sharedWait.answered\n if (!isUnknownBundleIdError(error)) {\n throw error\n }\n // MetaMask removes a single-call bundle in this way only before it sends\n // it. The SDK treats the bundle as never sent: a final rejection, so\n // \"Try again\" signs anew.\n if (known && callCount === 1 && isWithinDropWindow(signedAt)) {\n throw new TransactionError(\n LiFiErrorCode.SignatureRejected,\n 'The wallet has no record of the call bundle. The SDK treats it as never sent.',\n error as Error,\n { final: true }\n )\n }\n // Unknown from the first answer (a reload after the reject, another\n // wallet), too long after signing, or no stored count of one call (two\n // or more calls, or a route stored without the count): the bundle may\n // still land.\n throw new TransactionError(\n LiFiErrorCode.CallBundleNotFound,\n 'The wallet has no record of the call bundle.',\n error as Error\n )\n } finally {\n // The last wait of the bundle removes the shared predicate. A later wait\n // then starts a new poll and sees the wallet's answers again.\n sharedWait.waiters -= 1\n if (sharedWait.waiters === 0 && bundleWaits.get(waitKey) === sharedWait) {\n bundleWaits.delete(waitKey)\n }\n }\n\n if (result.status === 'success') {\n if (result.receipts?.some((receipt) => receipt.status === 'reverted')) {\n onFailed?.(result)\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction was reverted.',\n undefined,\n { final: true }\n )\n }\n // The wallet reports the batch as executed, but without a complete set of\n // receipts we cannot prove the outcome: it stays unknown.\n if (\n !result.receipts?.length ||\n !result.receipts.every((receipt) => receipt.transactionHash)\n ) {\n onFailed?.(result)\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction was reverted.'\n )\n }\n const transactionReceipt = result.receipts.at(-1)!\n return transactionReceipt\n }\n if (result.statusCode >= 400 && result.statusCode < 500) {\n onFailed?.(result)\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'Transaction was canceled.',\n undefined,\n { final: true }\n )\n }\n onFailed?.(result)\n // Only 500 (reverted completely) is final. Some calls of a partial batch\n // (600) may be onchain, and other codes are undefined: the outcome is unknown.\n if (result.statusCode === 500) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction failed.',\n undefined,\n { final: true }\n )\n }\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction failed.'\n )\n}\n"],"mappings":";;;;;AAOA,MAAM,4BAA4B;;;;;;;;;AAmBlC,MAAM,8BAAc,IAAI,IAAwB;AAEhD,MAAM,0BAA0B,UAC9B,OAAO,SAAS,0BAChB,OAAO,OAAO,SAAS,0BACvB,OAAO,SAAS,qBAAqB;;;;;AAMvC,MAAM,sBAAsB,aAA0C;CACpE,MAAM,MAAM,KAAK,IAAI;CACrB,OACE,aAAa,KAAA,KACb,OAAO,YACP,MAAM,WAAW;AAErB;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,iCAAiC,OAC5C,QACA,WACA,EACE,UACA,UACA,cAKE,CAAC,MAC0B;CAC/B,MAAM,UAAU,GAAG,OAAO,IAAI,GAAG;CACjC,IAAI,aAAa,YAAY,IAAI,OAAO;CAGxC,MAAM,cAAc,CAAC;CACrB,IAAI,CAAC,YAAY;EACf,MAAM,UAAsB;GAE1B,SAAS,EAAE,iBAAiB;IAC1B,QAAQ,WAAW;IACnB,OAAO,eAAe,OAAO,cAAc;GAC7C;GACA,UAAU;GACV,SAAS;EACX;EACA,aAAa;EACb,YAAY,IAAI,SAAS,OAAO;CAClC;CACA,MAAM,aAAa;CACnB,WAAW,WAAW;CAEtB,IAAI;CACJ,IAAI;EACF,SAAS,MAAM,UACb,QACA,oBACA,oBACF,CAAC,CAAC;GACA,IAAI;GACJ,SAAS;GACT,QAAQ,WAAW;EACrB,CAAC;CACH,SAAS,OAAO;EACd,MAAM,QAAQ,eAAe,WAAW;EACxC,IAAI,CAAC,uBAAuB,KAAK,GAC/B,MAAM;EAKR,IAAI,SAAS,cAAc,KAAK,mBAAmB,QAAQ,GACzD,MAAM,IAAI,iBACR,cAAc,mBACd,iFACA,OACA,EAAE,OAAO,KAAK,CAChB;EAMF,MAAM,IAAI,iBACR,cAAc,oBACd,gDACA,KACF;CACF,UAAU;EAGR,WAAW,WAAW;EACtB,IAAI,WAAW,YAAY,KAAK,YAAY,IAAI,OAAO,MAAM,YAC3D,YAAY,OAAO,OAAO;CAE9B;CAEA,IAAI,OAAO,WAAW,WAAW;EAC/B,IAAI,OAAO,UAAU,MAAM,YAAY,QAAQ,WAAW,UAAU,GAAG;GACrE,WAAW,MAAM;GACjB,MAAM,IAAI,iBACR,cAAc,mBACd,6BACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;EACF;EAGA,IACE,CAAC,OAAO,UAAU,UAClB,CAAC,OAAO,SAAS,OAAO,YAAY,QAAQ,eAAe,GAC3D;GACA,WAAW,MAAM;GACjB,MAAM,IAAI,iBACR,cAAc,mBACd,2BACF;EACF;EAEA,OAD2B,OAAO,SAAS,GAAG,EACtB;CAC1B;CACA,IAAI,OAAO,cAAc,OAAO,OAAO,aAAa,KAAK;EACvD,WAAW,MAAM;EACjB,MAAM,IAAI,iBACR,cAAc,qBACd,6BACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;CACF;CACA,WAAW,MAAM;CAGjB,IAAI,OAAO,eAAe,KACxB,MAAM,IAAI,iBACR,cAAc,mBACd,uBACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;CAEF,MAAM,IAAI,iBACR,cAAc,mBACd,qBACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"EthereumStepExecutor.d.ts","names":[],"sources":["../../../src/core/EthereumStepExecutor.ts"],"mappings":";;;;UAqCU,oCAAoC;EAC5C,QAAQ;EACR,eAAe,oBAAoB,QAAQ;EAC3C;;qBAGW,6BAA6B;UAChC;UACA;UACA;UACA;EAER,YAAY,SAAS;UAOb;WAOC,cACP,OAAO,OACP,OAAO,kBACP,SAAS,iBACT,cAAc,2BACb,QAAQ,WAAW;EAItB,cACE,MAAM,kBACN,2BACC,QAAQ;WAgCF,gBACP,aAAa,4BACZ,QAAQ;WA0BF,iBACP,SAAS,gCACR"}
1
+ {"version":3,"file":"EthereumStepExecutor.d.ts","names":[],"sources":["../../../src/core/EthereumStepExecutor.ts"],"mappings":";;;;UAsCU,oCAAoC;EAC5C,QAAQ;EACR,eAAe,oBAAoB,QAAQ;EAC3C;;qBAGW,6BAA6B;UAChC;UACA;UACA;UACA;EAER,YAAY,SAAS;UAOb;WAOC,cACP,OAAO,OACP,OAAO,kBACP,SAAS,iBACT,cAAc,2BACb,QAAQ,WAAW;EAItB,cACE,MAAM,kBACN,2BACC,QAAQ;WAgCF,gBACP,aAAa,4BACZ,QAAQ;WA0BF,iBACP,SAAS,gCACR"}
@@ -1,17 +1,18 @@
1
1
  import { isZeroAddress } from "../utils/isZeroAddress.js";
2
2
  import { parseEthereumErrors } from "../errors/parseEthereumErrors.js";
3
3
  import { EthereumCheckAllowanceTask } from "./tasks/EthereumCheckAllowanceTask.js";
4
+ import { EthereumResetAllowanceTask } from "./tasks/EthereumResetAllowanceTask.js";
5
+ import { EthereumSetAllowanceTask } from "./tasks/EthereumSetAllowanceTask.js";
6
+ import { shouldCheckForAllowance } from "./tasks/helpers/shouldCheckForAllowance.js";
7
+ import { EthereumCheckAllowanceAfterPrepareTask } from "./tasks/EthereumCheckAllowanceAfterPrepareTask.js";
4
8
  import { EthereumCheckBalanceTask } from "./tasks/EthereumCheckBalanceTask.js";
5
9
  import { EthereumCheckPermitsTask } from "./tasks/EthereumCheckPermitsTask.js";
6
10
  import { EthereumNativePermitTask } from "./tasks/EthereumNativePermitTask.js";
7
11
  import { EthereumPermit2AllowanceTask } from "./tasks/EthereumPermit2AllowanceTask.js";
8
12
  import { EthereumPrepareTransactionTask } from "./tasks/EthereumPrepareTransactionTask.js";
9
- import { EthereumResetAllowanceTask } from "./tasks/EthereumResetAllowanceTask.js";
10
- import { EthereumSetAllowanceTask } from "./tasks/EthereumSetAllowanceTask.js";
11
13
  import { EthereumSignAndExecuteTask } from "./tasks/EthereumSignAndExecuteTask.js";
12
14
  import { EthereumWaitForTransactionStatusTask } from "./tasks/EthereumWaitForTransactionStatusTask.js";
13
15
  import { EthereumWaitForTransactionTask } from "./tasks/EthereumWaitForTransactionTask.js";
14
- import { shouldCheckForAllowance } from "./tasks/helpers/shouldCheckForAllowance.js";
15
16
  import { switchChain } from "./tasks/helpers/switchChain.js";
16
17
  import { BaseStepExecutor, LiFiErrorCode, TaskPipeline, TransactionError, createDefaultStorage, hasOpenTransaction } from "@lifi/sdk";
17
18
  import { getAddresses } from "viem/actions";
@@ -67,6 +68,7 @@ var EthereumStepExecutor = class extends BaseStepExecutor {
67
68
  new EthereumCheckBalanceTask(),
68
69
  new EthereumPermit2AllowanceTask(),
69
70
  new EthereumPrepareTransactionTask(),
71
+ new EthereumCheckAllowanceAfterPrepareTask(),
70
72
  new EthereumSignAndExecuteTask(),
71
73
  new EthereumWaitForTransactionTask(),
72
74
  new EthereumWaitForTransactionStatusTask()
@@ -1 +1 @@
1
- {"version":3,"file":"EthereumStepExecutor.js","names":[],"sources":["../../../src/core/EthereumStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n createDefaultStorage,\n type ExecuteStepRetryError,\n type ExecuteStepRetryParams,\n type ExecutionAction,\n hasOpenTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n type SDKClient,\n type SDKError,\n type SDKStorage,\n type StepExecutorBaseContext,\n type StepExecutorOptions,\n TaskPipeline,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Client, GetAddressesReturnType } from 'viem'\nimport { getAddresses } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { parseEthereumErrors } from '../errors/parseEthereumErrors.js'\nimport type { EthereumStepExecutorContext } from '../types.js'\nimport { isZeroAddress } from '../utils/isZeroAddress.js'\nimport { EthereumCheckAllowanceTask } from './tasks/EthereumCheckAllowanceTask.js'\nimport { EthereumCheckBalanceTask } from './tasks/EthereumCheckBalanceTask.js'\nimport { EthereumCheckPermitsTask } from './tasks/EthereumCheckPermitsTask.js'\nimport { EthereumNativePermitTask } from './tasks/EthereumNativePermitTask.js'\nimport { EthereumPermit2AllowanceTask } from './tasks/EthereumPermit2AllowanceTask.js'\nimport { EthereumPrepareTransactionTask } from './tasks/EthereumPrepareTransactionTask.js'\nimport { EthereumResetAllowanceTask } from './tasks/EthereumResetAllowanceTask.js'\nimport { EthereumSetAllowanceTask } from './tasks/EthereumSetAllowanceTask.js'\nimport { EthereumSignAndExecuteTask } from './tasks/EthereumSignAndExecuteTask.js'\nimport { EthereumWaitForTransactionStatusTask } from './tasks/EthereumWaitForTransactionStatusTask.js'\nimport { EthereumWaitForTransactionTask } from './tasks/EthereumWaitForTransactionTask.js'\nimport { shouldCheckForAllowance } from './tasks/helpers/shouldCheckForAllowance.js'\nimport { switchChain } from './tasks/helpers/switchChain.js'\n\ninterface EthereumStepExecutorOptions extends StepExecutorOptions {\n client: Client\n switchChain?: (chainId: number) => Promise<Client | undefined>\n disableMessageSigning?: boolean\n}\n\nexport class EthereumStepExecutor extends BaseStepExecutor {\n private client: Client\n private switchChain?: (chainId: number) => Promise<Client | undefined>\n private storage?: SDKStorage\n private disableMessageSigning?: boolean\n\n constructor(options: EthereumStepExecutorOptions) {\n super(options)\n this.client = options.client\n this.switchChain = options.switchChain\n this.disableMessageSigning = options.disableMessageSigning\n }\n\n private getStorage = (client: SDKClient): SDKStorage => {\n if (!this.storage) {\n this.storage = client.config.storage ?? createDefaultStorage()\n }\n return this.storage\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction,\n retryParams?: ExecuteStepRetryParams\n ): Promise<SDKError | ExecuteStepRetryError> =>\n parseEthereumErrors(error, step, action, retryParams)\n\n // Ensure that we are using the right chain and wallet when executing transactions.\n checkClient = async (\n step: LiFiStepExtended,\n targetChainId?: number\n ): Promise<Client | undefined> => {\n const updatedClient = await switchChain(\n this.client,\n targetChainId ?? step.action.fromChainId,\n this.allowUserInteraction,\n this.switchChain\n )\n if (updatedClient) {\n this.client = updatedClient\n }\n\n // Prevent execution of the quote by wallet different from the one which requested the quote\n let accountAddress = this.client.account?.address\n if (!accountAddress) {\n const accountAddresses = (await getAction(\n this.client,\n getAddresses,\n 'getAddresses'\n )(undefined)) as GetAddressesReturnType\n accountAddress = accountAddresses?.[0]\n }\n if (\n accountAddress?.toLowerCase() !== step.action.fromAddress?.toLowerCase()\n ) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n return updatedClient\n }\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<EthereumStepExecutorContext> => {\n const { step, fromChain } = baseContext\n\n const isFromNativeToken =\n fromChain.nativeToken.address === step.action.fromToken.address &&\n isZeroAddress(step.action.fromToken.address)\n\n // Check if message signing is disabled - useful for smart contract wallets\n // We also disable message signing for custom steps\n const disableMessageSigning =\n !!this.disableMessageSigning || step.type !== 'lifi'\n\n return {\n ...baseContext,\n isFromNativeToken,\n disableMessageSigning,\n ethereumClient: this.client,\n checkClient: this.checkClient,\n getStorage: this.getStorage,\n // Signed typed data for native permits and other messages\n signedTypedData: [],\n // Calls for atomic batch transactions (EIP-5792)\n calls: [],\n }\n }\n\n override createPipeline = (\n context: EthereumStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution, isFromNativeToken } = context\n\n const tasks = [\n new EthereumCheckPermitsTask(),\n new EthereumCheckAllowanceTask(),\n new EthereumNativePermitTask(),\n new EthereumResetAllowanceTask(),\n new EthereumSetAllowanceTask(),\n new EthereumCheckBalanceTask(),\n new EthereumPermit2AllowanceTask(),\n new EthereumPrepareTransactionTask(),\n new EthereumSignAndExecuteTask(),\n new EthereumWaitForTransactionTask(),\n new EthereumWaitForTransactionStatusTask(),\n ]\n\n const doCheckAllowance = shouldCheckForAllowance(\n step,\n isBridgeExecution,\n isFromNativeToken,\n this.statusManager\n )\n\n let firstTask:\n | typeof EthereumCheckPermitsTask\n | typeof EthereumCheckBalanceTask\n | typeof EthereumWaitForTransactionTask\n | typeof EthereumWaitForTransactionStatusTask\n if (doCheckAllowance) {\n firstTask = EthereumCheckPermitsTask\n } else {\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n // Same predicate as the pre-sign guard: an open transaction is waited\n // for, a FAILED action with a final outcome signs again.\n firstTask = hasOpenTransaction(swapOrBridgeAction)\n ? swapOrBridgeAction?.status === 'DONE'\n ? EthereumWaitForTransactionStatusTask\n : EthereumWaitForTransactionTask\n : EthereumCheckBalanceTask\n }\n\n // Compare classes, not names: a minifier can give two task classes the\n // same name.\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor === firstTask\n )\n if (firstTaskIndex === -1) {\n throw new TransactionError(\n LiFiErrorCode.InternalError,\n 'EthereumStepExecutor.createPipeline: first task not found'\n )\n }\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2CA,IAAa,uBAAb,cAA0C,iBAAiB;CACzD;CACA;CACA;CACA;CAEA,YAAY,SAAsC;EAChD,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;EACtB,KAAK,cAAc,QAAQ;EAC3B,KAAK,wBAAwB,QAAQ;CACvC;CAEA,cAAsB,WAAkC;EACtD,IAAI,CAAC,KAAK,SACR,KAAK,UAAU,OAAO,OAAO,WAAW,qBAAqB;EAE/D,OAAO,KAAK;CACd;CAEA,eACE,OACA,MACA,QACA,gBAEA,oBAAoB,OAAO,MAAM,QAAQ,WAAW;CAGtD,cAAc,OACZ,MACA,kBACgC;EAChC,MAAM,gBAAgB,MAAM,YAC1B,KAAK,QACL,iBAAiB,KAAK,OAAO,aAC7B,KAAK,sBACL,KAAK,WACP;EACA,IAAI,eACF,KAAK,SAAS;EAIhB,IAAI,iBAAiB,KAAK,OAAO,SAAS;EAC1C,IAAI,CAAC,gBAMH,kBAAiB,MALe,UAC9B,KAAK,QACL,cACA,cACF,CAAC,CAAC,KAAA,CAAS,EAAA,GACyB;EAEtC,IACE,gBAAgB,YAAY,MAAM,KAAK,OAAO,aAAa,YAAY,GAEvE,MAAM,IAAI,iBACR,cAAc,8BACd,mHACF;EAEF,OAAO;CACT;CAEA,gBAAyB,OACvB,gBACyC;EACzC,MAAM,EAAE,MAAM,cAAc;EAE5B,MAAM,oBACJ,UAAU,YAAY,YAAY,KAAK,OAAO,UAAU,WACxD,cAAc,KAAK,OAAO,UAAU,OAAO;EAI7C,MAAM,wBACJ,CAAC,CAAC,KAAK,yBAAyB,KAAK,SAAS;EAEhD,OAAO;GACL,GAAG;GACH;GACA;GACA,gBAAgB,KAAK;GACrB,aAAa,KAAK;GAClB,YAAY,KAAK;GAEjB,iBAAiB,CAAC;GAElB,OAAO,CAAC;EACV;CACF;CAEA,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,mBAAmB,sBAAsB;EAEvD,MAAM,QAAQ;GACZ,IAAI,yBAAyB;GAC7B,IAAI,2BAA2B;GAC/B,IAAI,yBAAyB;GAC7B,IAAI,2BAA2B;GAC/B,IAAI,yBAAyB;GAC7B,IAAI,yBAAyB;GAC7B,IAAI,6BAA6B;GACjC,IAAI,+BAA+B;GACnC,IAAI,2BAA2B;GAC/B,IAAI,+BAA+B;GACnC,IAAI,qCAAqC;EAC3C;EAEA,MAAM,mBAAmB,wBACvB,MACA,mBACA,mBACA,KAAK,aACP;EAEA,IAAI;EAKJ,IAAI,kBACF,YAAY;OACP;GACL,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;GAGA,YAAY,mBAAmB,kBAAkB,IAC7C,oBAAoB,WAAW,SAC7B,uCACA,iCACF;EACN;EAIA,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,gBAAgB,SACjC;EACA,IAAI,mBAAmB,IACrB,MAAM,IAAI,iBACR,cAAc,eACd,2DACF;EAGF,MAAM,aAAa,MAAM,MAAM,cAAc;EAE7C,OAAO,IAAI,aAAa,UAAU;CACpC;AACF"}
1
+ {"version":3,"file":"EthereumStepExecutor.js","names":[],"sources":["../../../src/core/EthereumStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n createDefaultStorage,\n type ExecuteStepRetryError,\n type ExecuteStepRetryParams,\n type ExecutionAction,\n hasOpenTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n type SDKClient,\n type SDKError,\n type SDKStorage,\n type StepExecutorBaseContext,\n type StepExecutorOptions,\n TaskPipeline,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Client, GetAddressesReturnType } from 'viem'\nimport { getAddresses } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { parseEthereumErrors } from '../errors/parseEthereumErrors.js'\nimport type { EthereumStepExecutorContext } from '../types.js'\nimport { isZeroAddress } from '../utils/isZeroAddress.js'\nimport { EthereumCheckAllowanceAfterPrepareTask } from './tasks/EthereumCheckAllowanceAfterPrepareTask.js'\nimport { EthereumCheckAllowanceTask } from './tasks/EthereumCheckAllowanceTask.js'\nimport { EthereumCheckBalanceTask } from './tasks/EthereumCheckBalanceTask.js'\nimport { EthereumCheckPermitsTask } from './tasks/EthereumCheckPermitsTask.js'\nimport { EthereumNativePermitTask } from './tasks/EthereumNativePermitTask.js'\nimport { EthereumPermit2AllowanceTask } from './tasks/EthereumPermit2AllowanceTask.js'\nimport { EthereumPrepareTransactionTask } from './tasks/EthereumPrepareTransactionTask.js'\nimport { EthereumResetAllowanceTask } from './tasks/EthereumResetAllowanceTask.js'\nimport { EthereumSetAllowanceTask } from './tasks/EthereumSetAllowanceTask.js'\nimport { EthereumSignAndExecuteTask } from './tasks/EthereumSignAndExecuteTask.js'\nimport { EthereumWaitForTransactionStatusTask } from './tasks/EthereumWaitForTransactionStatusTask.js'\nimport { EthereumWaitForTransactionTask } from './tasks/EthereumWaitForTransactionTask.js'\nimport { shouldCheckForAllowance } from './tasks/helpers/shouldCheckForAllowance.js'\nimport { switchChain } from './tasks/helpers/switchChain.js'\n\ninterface EthereumStepExecutorOptions extends StepExecutorOptions {\n client: Client\n switchChain?: (chainId: number) => Promise<Client | undefined>\n disableMessageSigning?: boolean\n}\n\nexport class EthereumStepExecutor extends BaseStepExecutor {\n private client: Client\n private switchChain?: (chainId: number) => Promise<Client | undefined>\n private storage?: SDKStorage\n private disableMessageSigning?: boolean\n\n constructor(options: EthereumStepExecutorOptions) {\n super(options)\n this.client = options.client\n this.switchChain = options.switchChain\n this.disableMessageSigning = options.disableMessageSigning\n }\n\n private getStorage = (client: SDKClient): SDKStorage => {\n if (!this.storage) {\n this.storage = client.config.storage ?? createDefaultStorage()\n }\n return this.storage\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction,\n retryParams?: ExecuteStepRetryParams\n ): Promise<SDKError | ExecuteStepRetryError> =>\n parseEthereumErrors(error, step, action, retryParams)\n\n // Ensure that we are using the right chain and wallet when executing transactions.\n checkClient = async (\n step: LiFiStepExtended,\n targetChainId?: number\n ): Promise<Client | undefined> => {\n const updatedClient = await switchChain(\n this.client,\n targetChainId ?? step.action.fromChainId,\n this.allowUserInteraction,\n this.switchChain\n )\n if (updatedClient) {\n this.client = updatedClient\n }\n\n // Prevent execution of the quote by wallet different from the one which requested the quote\n let accountAddress = this.client.account?.address\n if (!accountAddress) {\n const accountAddresses = (await getAction(\n this.client,\n getAddresses,\n 'getAddresses'\n )(undefined)) as GetAddressesReturnType\n accountAddress = accountAddresses?.[0]\n }\n if (\n accountAddress?.toLowerCase() !== step.action.fromAddress?.toLowerCase()\n ) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n return updatedClient\n }\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<EthereumStepExecutorContext> => {\n const { step, fromChain } = baseContext\n\n const isFromNativeToken =\n fromChain.nativeToken.address === step.action.fromToken.address &&\n isZeroAddress(step.action.fromToken.address)\n\n // Check if message signing is disabled - useful for smart contract wallets\n // We also disable message signing for custom steps\n const disableMessageSigning =\n !!this.disableMessageSigning || step.type !== 'lifi'\n\n return {\n ...baseContext,\n isFromNativeToken,\n disableMessageSigning,\n ethereumClient: this.client,\n checkClient: this.checkClient,\n getStorage: this.getStorage,\n // Signed typed data for native permits and other messages\n signedTypedData: [],\n // Calls for atomic batch transactions (EIP-5792)\n calls: [],\n }\n }\n\n override createPipeline = (\n context: EthereumStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution, isFromNativeToken } = context\n\n const tasks = [\n new EthereumCheckPermitsTask(),\n new EthereumCheckAllowanceTask(),\n new EthereumNativePermitTask(),\n new EthereumResetAllowanceTask(),\n new EthereumSetAllowanceTask(),\n new EthereumCheckBalanceTask(),\n new EthereumPermit2AllowanceTask(),\n new EthereumPrepareTransactionTask(),\n new EthereumCheckAllowanceAfterPrepareTask(),\n new EthereumSignAndExecuteTask(),\n new EthereumWaitForTransactionTask(),\n new EthereumWaitForTransactionStatusTask(),\n ]\n\n const doCheckAllowance = shouldCheckForAllowance(\n step,\n isBridgeExecution,\n isFromNativeToken,\n this.statusManager\n )\n\n let firstTask:\n | typeof EthereumCheckPermitsTask\n | typeof EthereumCheckBalanceTask\n | typeof EthereumWaitForTransactionTask\n | typeof EthereumWaitForTransactionStatusTask\n if (doCheckAllowance) {\n firstTask = EthereumCheckPermitsTask\n } else {\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n // Same predicate as the pre-sign guard: an open transaction is waited\n // for, a FAILED action with a final outcome signs again.\n firstTask = hasOpenTransaction(swapOrBridgeAction)\n ? swapOrBridgeAction?.status === 'DONE'\n ? EthereumWaitForTransactionStatusTask\n : EthereumWaitForTransactionTask\n : EthereumCheckBalanceTask\n }\n\n // Compare classes, not names: a minifier can give two task classes the\n // same name.\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor === firstTask\n )\n if (firstTaskIndex === -1) {\n throw new TransactionError(\n LiFiErrorCode.InternalError,\n 'EthereumStepExecutor.createPipeline: first task not found'\n )\n }\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4CA,IAAa,uBAAb,cAA0C,iBAAiB;CACzD;CACA;CACA;CACA;CAEA,YAAY,SAAsC;EAChD,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;EACtB,KAAK,cAAc,QAAQ;EAC3B,KAAK,wBAAwB,QAAQ;CACvC;CAEA,cAAsB,WAAkC;EACtD,IAAI,CAAC,KAAK,SACR,KAAK,UAAU,OAAO,OAAO,WAAW,qBAAqB;EAE/D,OAAO,KAAK;CACd;CAEA,eACE,OACA,MACA,QACA,gBAEA,oBAAoB,OAAO,MAAM,QAAQ,WAAW;CAGtD,cAAc,OACZ,MACA,kBACgC;EAChC,MAAM,gBAAgB,MAAM,YAC1B,KAAK,QACL,iBAAiB,KAAK,OAAO,aAC7B,KAAK,sBACL,KAAK,WACP;EACA,IAAI,eACF,KAAK,SAAS;EAIhB,IAAI,iBAAiB,KAAK,OAAO,SAAS;EAC1C,IAAI,CAAC,gBAMH,kBAAiB,MALe,UAC9B,KAAK,QACL,cACA,cACF,CAAC,CAAC,KAAA,CAAS,EAAA,GACyB;EAEtC,IACE,gBAAgB,YAAY,MAAM,KAAK,OAAO,aAAa,YAAY,GAEvE,MAAM,IAAI,iBACR,cAAc,8BACd,mHACF;EAEF,OAAO;CACT;CAEA,gBAAyB,OACvB,gBACyC;EACzC,MAAM,EAAE,MAAM,cAAc;EAE5B,MAAM,oBACJ,UAAU,YAAY,YAAY,KAAK,OAAO,UAAU,WACxD,cAAc,KAAK,OAAO,UAAU,OAAO;EAI7C,MAAM,wBACJ,CAAC,CAAC,KAAK,yBAAyB,KAAK,SAAS;EAEhD,OAAO;GACL,GAAG;GACH;GACA;GACA,gBAAgB,KAAK;GACrB,aAAa,KAAK;GAClB,YAAY,KAAK;GAEjB,iBAAiB,CAAC;GAElB,OAAO,CAAC;EACV;CACF;CAEA,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,mBAAmB,sBAAsB;EAEvD,MAAM,QAAQ;GACZ,IAAI,yBAAyB;GAC7B,IAAI,2BAA2B;GAC/B,IAAI,yBAAyB;GAC7B,IAAI,2BAA2B;GAC/B,IAAI,yBAAyB;GAC7B,IAAI,yBAAyB;GAC7B,IAAI,6BAA6B;GACjC,IAAI,+BAA+B;GACnC,IAAI,uCAAuC;GAC3C,IAAI,2BAA2B;GAC/B,IAAI,+BAA+B;GACnC,IAAI,qCAAqC;EAC3C;EAEA,MAAM,mBAAmB,wBACvB,MACA,mBACA,mBACA,KAAK,aACP;EAEA,IAAI;EAKJ,IAAI,kBACF,YAAY;OACP;GACL,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;GAGA,YAAY,mBAAmB,kBAAkB,IAC7C,oBAAoB,WAAW,SAC7B,uCACA,iCACF;EACN;EAIA,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,gBAAgB,SACjC;EACA,IAAI,mBAAmB,IACrB,MAAM,IAAI,iBACR,cAAc,eACd,2DACF;EAGF,MAAM,aAAa,MAAM,MAAM,cAAc;EAE7C,OAAO,IAAI,aAAa,UAAU;CACpC;AACF"}
@@ -0,0 +1,20 @@
1
+ import { EthereumStepExecutorContext } from "../../types.js";
2
+ import { BaseStepExecutionTask, TaskResult } from "@lifi/sdk";
3
+ //#region src/core/tasks/EthereumCheckAllowanceAfterPrepareTask.d.ts
4
+ /**
5
+ * Runs after PrepareTransaction. Some providers only know the spender once
6
+ * `/stepTransaction` builds the executable transaction, so the routing-time
7
+ * step carries no `estimate.approvalAddress` and the allowance tasks before
8
+ * prepare do not run. When the re-quote brings one, the allowance is read for
9
+ * it, and reset and set only if it falls short, before the transaction is
10
+ * signed.
11
+ *
12
+ * A spender that was already set before prepare is not checked again here.
13
+ */
14
+ export declare class EthereumCheckAllowanceAfterPrepareTask extends BaseStepExecutionTask {
15
+ private readonly allowancePipeline;
16
+ override shouldRun(context: EthereumStepExecutorContext): Promise<boolean>;
17
+ run(context: EthereumStepExecutorContext): Promise<TaskResult>;
18
+ }
19
+ //#endregion
20
+ //# sourceMappingURL=EthereumCheckAllowanceAfterPrepareTask.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EthereumCheckAllowanceAfterPrepareTask.d.ts","names":[],"sources":["../../../../src/core/tasks/EthereumCheckAllowanceAfterPrepareTask.ts"],"mappings":";;;;;;;;;;;;;qBAiBa,+CAA+C;mBACzC;WAMF,UACb,SAAS,8BACR;EAIH,IAAU,SAAS,8BAA8B,QAAQ"}
@@ -0,0 +1,33 @@
1
+ import { EthereumCheckAllowanceTask } from "./EthereumCheckAllowanceTask.js";
2
+ import { EthereumResetAllowanceTask } from "./EthereumResetAllowanceTask.js";
3
+ import { EthereumSetAllowanceTask } from "./EthereumSetAllowanceTask.js";
4
+ import { hasApprovalAddressAppearedAtPrepare } from "./helpers/hasApprovalAddressAppearedAtPrepare.js";
5
+ import { BaseStepExecutionTask, TaskPipeline } from "@lifi/sdk";
6
+ //#region src/core/tasks/EthereumCheckAllowanceAfterPrepareTask.ts
7
+ /**
8
+ * Runs after PrepareTransaction. Some providers only know the spender once
9
+ * `/stepTransaction` builds the executable transaction, so the routing-time
10
+ * step carries no `estimate.approvalAddress` and the allowance tasks before
11
+ * prepare do not run. When the re-quote brings one, the allowance is read for
12
+ * it, and reset and set only if it falls short, before the transaction is
13
+ * signed.
14
+ *
15
+ * A spender that was already set before prepare is not checked again here.
16
+ */
17
+ var EthereumCheckAllowanceAfterPrepareTask = class extends BaseStepExecutionTask {
18
+ allowancePipeline = new TaskPipeline([
19
+ new EthereumCheckAllowanceTask(),
20
+ new EthereumResetAllowanceTask(),
21
+ new EthereumSetAllowanceTask()
22
+ ]);
23
+ async shouldRun(context) {
24
+ return hasApprovalAddressAppearedAtPrepare(context);
25
+ }
26
+ async run(context) {
27
+ return this.allowancePipeline.run(context);
28
+ }
29
+ };
30
+ //#endregion
31
+ export { EthereumCheckAllowanceAfterPrepareTask };
32
+
33
+ //# sourceMappingURL=EthereumCheckAllowanceAfterPrepareTask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EthereumCheckAllowanceAfterPrepareTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumCheckAllowanceAfterPrepareTask.ts"],"sourcesContent":["import { BaseStepExecutionTask, TaskPipeline, type TaskResult } from '@lifi/sdk'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { EthereumCheckAllowanceTask } from './EthereumCheckAllowanceTask.js'\nimport { EthereumResetAllowanceTask } from './EthereumResetAllowanceTask.js'\nimport { EthereumSetAllowanceTask } from './EthereumSetAllowanceTask.js'\nimport { hasApprovalAddressAppearedAtPrepare } from './helpers/hasApprovalAddressAppearedAtPrepare.js'\n\n/**\n * Runs after PrepareTransaction. Some providers only know the spender once\n * `/stepTransaction` builds the executable transaction, so the routing-time\n * step carries no `estimate.approvalAddress` and the allowance tasks before\n * prepare do not run. When the re-quote brings one, the allowance is read for\n * it, and reset and set only if it falls short, before the transaction is\n * signed.\n *\n * A spender that was already set before prepare is not checked again here.\n */\nexport class EthereumCheckAllowanceAfterPrepareTask extends BaseStepExecutionTask {\n private readonly allowancePipeline = new TaskPipeline([\n new EthereumCheckAllowanceTask(),\n new EthereumResetAllowanceTask(),\n new EthereumSetAllowanceTask(),\n ])\n\n override async shouldRun(\n context: EthereumStepExecutorContext\n ): Promise<boolean> {\n return hasApprovalAddressAppearedAtPrepare(context)\n }\n\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n return this.allowancePipeline.run(context)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,IAAa,yCAAb,cAA4D,sBAAsB;CAChF,oBAAqC,IAAI,aAAa;EACpD,IAAI,2BAA2B;EAC/B,IAAI,2BAA2B;EAC/B,IAAI,yBAAyB;CAC/B,CAAC;CAED,MAAe,UACb,SACkB;EAClB,OAAO,oCAAoC,OAAO;CACpD;CAEA,MAAM,IAAI,SAA2D;EACnE,OAAO,KAAK,kBAAkB,IAAI,OAAO;CAC3C;AACF"}
@@ -0,0 +1,11 @@
1
+ import { EthereumStepExecutorContext } from "../../../types.js";
2
+ //#region src/core/tasks/helpers/hasApprovalAddressAppearedAtPrepare.d.ts
3
+ /**
4
+ * Whether the step had no `estimate.approvalAddress` before prepare and the
5
+ * re-quote brought one. No allowance was checked then (`allowanceSpender` is
6
+ * unset), and the step now needs it checked. The allowance tasks resolve the
7
+ * spender themselves, so on a Permit2 chain they approve `fromChain.permit2`.
8
+ */
9
+ export declare const hasApprovalAddressAppearedAtPrepare: (context: EthereumStepExecutorContext) => boolean;
10
+ //#endregion
11
+ //# sourceMappingURL=hasApprovalAddressAppearedAtPrepare.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasApprovalAddressAppearedAtPrepare.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/hasApprovalAddressAppearedAtPrepare.ts"],"mappings":";;;;;;;;qBASa,sCACX,SAAS"}
@@ -0,0 +1,16 @@
1
+ import { shouldCheckForAllowance } from "./shouldCheckForAllowance.js";
2
+ //#region src/core/tasks/helpers/hasApprovalAddressAppearedAtPrepare.ts
3
+ /**
4
+ * Whether the step had no `estimate.approvalAddress` before prepare and the
5
+ * re-quote brought one. No allowance was checked then (`allowanceSpender` is
6
+ * unset), and the step now needs it checked. The allowance tasks resolve the
7
+ * spender themselves, so on a Permit2 chain they approve `fromChain.permit2`.
8
+ */
9
+ const hasApprovalAddressAppearedAtPrepare = (context) => {
10
+ const { step, allowanceSpender, isBridgeExecution, isFromNativeToken, statusManager } = context;
11
+ return !allowanceSpender && shouldCheckForAllowance(step, isBridgeExecution, isFromNativeToken, statusManager);
12
+ };
13
+ //#endregion
14
+ export { hasApprovalAddressAppearedAtPrepare };
15
+
16
+ //# sourceMappingURL=hasApprovalAddressAppearedAtPrepare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasApprovalAddressAppearedAtPrepare.js","names":[],"sources":["../../../../../src/core/tasks/helpers/hasApprovalAddressAppearedAtPrepare.ts"],"sourcesContent":["import type { EthereumStepExecutorContext } from '../../../types.js'\nimport { shouldCheckForAllowance } from './shouldCheckForAllowance.js'\n\n/**\n * Whether the step had no `estimate.approvalAddress` before prepare and the\n * re-quote brought one. No allowance was checked then (`allowanceSpender` is\n * unset), and the step now needs it checked. The allowance tasks resolve the\n * spender themselves, so on a Permit2 chain they approve `fromChain.permit2`.\n */\nexport const hasApprovalAddressAppearedAtPrepare = (\n context: EthereumStepExecutorContext\n): boolean => {\n const {\n step,\n allowanceSpender,\n isBridgeExecution,\n isFromNativeToken,\n statusManager,\n } = context\n return (\n !allowanceSpender &&\n shouldCheckForAllowance(\n step,\n isBridgeExecution,\n isFromNativeToken,\n statusManager\n )\n )\n}\n"],"mappings":";;;;;;;;AASA,MAAa,uCACX,YACY;CACZ,MAAM,EACJ,MACA,kBACA,mBACA,mBACA,kBACE;CACJ,OACE,CAAC,oBACD,wBACE,MACA,mBACA,mBACA,aACF;AAEJ"}
package/dist/esm/index.js CHANGED
@@ -2,12 +2,12 @@ import { isZeroAddress } from "./utils/isZeroAddress.js";
2
2
  import { getTokenAllowance, getTokenAllowanceMulticall } from "./actions/getAllowance.js";
3
3
  import { isBatchingSupported } from "./actions/isBatchingSupported.js";
4
4
  import { isGaslessStep } from "./utils/isGaslessStep.js";
5
+ import { isEthereumProvider } from "./types.js";
5
6
  import { isDelegationDesignatorCode } from "./permits/isDelegationDesignatorCode.js";
7
+ import { revokeTokenApproval, setAllowance, setTokenAllowance } from "./actions/setAllowance.js";
6
8
  import { PatcherMagicNumber } from "./permits/constants.js";
7
9
  import { getNativePermit } from "./permits/getNativePermit.js";
8
10
  import { isContractCallStep } from "./utils/isContractCallStep.js";
9
- import { isEthereumProvider } from "./types.js";
10
- import { revokeTokenApproval, setAllowance, setTokenAllowance } from "./actions/setAllowance.js";
11
11
  import { isHyperliquidAgentStep, isHyperliquidOrderMessage } from "./hyperliquid/isHyperliquidAgentStep.js";
12
12
  import { convertExtendedChain } from "./utils/convertExtendedChain.js";
13
13
  import { EthereumProvider } from "./EthereumProvider.js";
@@ -1,8 +1,8 @@
1
1
  import { eip2612Abi } from "../utils/abi.js";
2
2
  import { getMulticallAddress } from "../actions/getMulticallAddress.js";
3
3
  import { getActionWithFallback } from "../utils/getActionWithFallback.js";
4
- import { canAccountUseNativePermits } from "./canAccountUseNativePermits.js";
5
4
  import { EIP712_DOMAIN_TYPEHASH, EIP712_DOMAIN_TYPEHASH_WITH_SALT, eip2612Types } from "./constants.js";
5
+ import { canAccountUseNativePermits } from "./canAccountUseNativePermits.js";
6
6
  import { encodeAbiParameters, keccak256, pad, parseAbiParameters, toBytes, toHex, zeroHash } from "viem";
7
7
  import { multicall, readContract } from "viem/actions";
8
8
  //#region src/permits/getNativePermit.ts
@@ -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.10";
3
+ export declare const version = "4.2.12";
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.10";
3
+ const version = "4.2.12";
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.10'\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.12'\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.10",
3
+ "version": "4.2.12",
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": {
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@lifi/sdk": "4.12.1",
32
- "viem": "^2.57.4"
32
+ "viem": "^2.57.7"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"
@@ -7,6 +7,25 @@ import type { WalletCallReceipt } from '../types.js'
7
7
  // Some wallets answer from a remote service that can forget an old bundle.
8
8
  const DROPPED_BUNDLE_MAX_AGE_MS = 10 * 60_000
9
9
 
10
+ type BundleWait = {
11
+ /** The one `status` predicate that every wait for the bundle passes. */
12
+ status: (result: { statusCode: number }) => boolean
13
+ /** True after the wallet answered for the bundle in the shared poll. */
14
+ answered: boolean
15
+ /** The waits that did not finish yet. */
16
+ waiters: number
17
+ }
18
+
19
+ /**
20
+ * viem shares one poll between the waits for the same client and id, and
21
+ * calls only the predicate of the wait that started it. Since viem 2.57.5 the
22
+ * shared poll also needs the same `status` function (compared by identity).
23
+ * All waits for one bundle thus pass the same predicate from this map. Then
24
+ * they share one poll in every viem version, and only the first wait of the
25
+ * bundle can see the wallet's answers.
26
+ */
27
+ const bundleWaits = new Map<string, BundleWait>()
28
+
10
29
  const isUnknownBundleIdError = (error: any): boolean =>
11
30
  error?.name === 'UnknownBundleIdError' ||
12
31
  error?.cause?.name === 'UnknownBundleIdError' ||
@@ -58,7 +77,27 @@ export const waitForBatchTransactionReceipt = async (
58
77
  callCount?: number
59
78
  } = {}
60
79
  ): Promise<WalletCallReceipt> => {
61
- let known = false
80
+ const waitKey = `${client.uid}:${batchHash}`
81
+ let bundleWait = bundleWaits.get(waitKey)
82
+ // The first wait of a bundle starts the poll. A wait that joins it does not
83
+ // see the wallet's answers, so it never has a record of them.
84
+ const startedPoll = !bundleWait
85
+ if (!bundleWait) {
86
+ const created: BundleWait = {
87
+ // viem's default, and a record that the wallet answered for this id.
88
+ status: ({ statusCode }) => {
89
+ created.answered = true
90
+ return statusCode === 200 || statusCode >= 300
91
+ },
92
+ answered: false,
93
+ waiters: 0,
94
+ }
95
+ bundleWait = created
96
+ bundleWaits.set(waitKey, created)
97
+ }
98
+ const sharedWait = bundleWait
99
+ sharedWait.waiters += 1
100
+
62
101
  let result: GetCallsStatusReturnType
63
102
  try {
64
103
  result = await getAction(
@@ -68,15 +107,10 @@ export const waitForBatchTransactionReceipt = async (
68
107
  )({
69
108
  id: batchHash,
70
109
  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
- },
110
+ status: sharedWait.status,
78
111
  })
79
112
  } catch (error) {
113
+ const known = startedPoll && sharedWait.answered
80
114
  if (!isUnknownBundleIdError(error)) {
81
115
  throw error
82
116
  }
@@ -100,6 +134,13 @@ export const waitForBatchTransactionReceipt = async (
100
134
  'The wallet has no record of the call bundle.',
101
135
  error as Error
102
136
  )
137
+ } finally {
138
+ // The last wait of the bundle removes the shared predicate. A later wait
139
+ // then starts a new poll and sees the wallet's answers again.
140
+ sharedWait.waiters -= 1
141
+ if (sharedWait.waiters === 0 && bundleWaits.get(waitKey) === sharedWait) {
142
+ bundleWaits.delete(waitKey)
143
+ }
103
144
  }
104
145
 
105
146
  if (result.status === 'success') {
@@ -21,6 +21,7 @@ import { getAction } from 'viem/utils'
21
21
  import { parseEthereumErrors } from '../errors/parseEthereumErrors.js'
22
22
  import type { EthereumStepExecutorContext } from '../types.js'
23
23
  import { isZeroAddress } from '../utils/isZeroAddress.js'
24
+ import { EthereumCheckAllowanceAfterPrepareTask } from './tasks/EthereumCheckAllowanceAfterPrepareTask.js'
24
25
  import { EthereumCheckAllowanceTask } from './tasks/EthereumCheckAllowanceTask.js'
25
26
  import { EthereumCheckBalanceTask } from './tasks/EthereumCheckBalanceTask.js'
26
27
  import { EthereumCheckPermitsTask } from './tasks/EthereumCheckPermitsTask.js'
@@ -147,6 +148,7 @@ export class EthereumStepExecutor extends BaseStepExecutor {
147
148
  new EthereumCheckBalanceTask(),
148
149
  new EthereumPermit2AllowanceTask(),
149
150
  new EthereumPrepareTransactionTask(),
151
+ new EthereumCheckAllowanceAfterPrepareTask(),
150
152
  new EthereumSignAndExecuteTask(),
151
153
  new EthereumWaitForTransactionTask(),
152
154
  new EthereumWaitForTransactionStatusTask(),
@@ -0,0 +1,34 @@
1
+ import { BaseStepExecutionTask, TaskPipeline, type TaskResult } from '@lifi/sdk'
2
+ import type { EthereumStepExecutorContext } from '../../types.js'
3
+ import { EthereumCheckAllowanceTask } from './EthereumCheckAllowanceTask.js'
4
+ import { EthereumResetAllowanceTask } from './EthereumResetAllowanceTask.js'
5
+ import { EthereumSetAllowanceTask } from './EthereumSetAllowanceTask.js'
6
+ import { hasApprovalAddressAppearedAtPrepare } from './helpers/hasApprovalAddressAppearedAtPrepare.js'
7
+
8
+ /**
9
+ * Runs after PrepareTransaction. Some providers only know the spender once
10
+ * `/stepTransaction` builds the executable transaction, so the routing-time
11
+ * step carries no `estimate.approvalAddress` and the allowance tasks before
12
+ * prepare do not run. When the re-quote brings one, the allowance is read for
13
+ * it, and reset and set only if it falls short, before the transaction is
14
+ * signed.
15
+ *
16
+ * A spender that was already set before prepare is not checked again here.
17
+ */
18
+ export class EthereumCheckAllowanceAfterPrepareTask extends BaseStepExecutionTask {
19
+ private readonly allowancePipeline = new TaskPipeline([
20
+ new EthereumCheckAllowanceTask(),
21
+ new EthereumResetAllowanceTask(),
22
+ new EthereumSetAllowanceTask(),
23
+ ])
24
+
25
+ override async shouldRun(
26
+ context: EthereumStepExecutorContext
27
+ ): Promise<boolean> {
28
+ return hasApprovalAddressAppearedAtPrepare(context)
29
+ }
30
+
31
+ async run(context: EthereumStepExecutorContext): Promise<TaskResult> {
32
+ return this.allowancePipeline.run(context)
33
+ }
34
+ }
@@ -0,0 +1,29 @@
1
+ import type { EthereumStepExecutorContext } from '../../../types.js'
2
+ import { shouldCheckForAllowance } from './shouldCheckForAllowance.js'
3
+
4
+ /**
5
+ * Whether the step had no `estimate.approvalAddress` before prepare and the
6
+ * re-quote brought one. No allowance was checked then (`allowanceSpender` is
7
+ * unset), and the step now needs it checked. The allowance tasks resolve the
8
+ * spender themselves, so on a Permit2 chain they approve `fromChain.permit2`.
9
+ */
10
+ export const hasApprovalAddressAppearedAtPrepare = (
11
+ context: EthereumStepExecutorContext
12
+ ): boolean => {
13
+ const {
14
+ step,
15
+ allowanceSpender,
16
+ isBridgeExecution,
17
+ isFromNativeToken,
18
+ statusManager,
19
+ } = context
20
+ return (
21
+ !allowanceSpender &&
22
+ shouldCheckForAllowance(
23
+ step,
24
+ isBridgeExecution,
25
+ isFromNativeToken,
26
+ statusManager
27
+ )
28
+ )
29
+ }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk-provider-ethereum'
2
- export const version = '4.2.10'
2
+ export const version = '4.2.12'