@lifi/sdk-provider-ethereum 4.2.9 → 4.2.11

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 (30) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/actions/checkPermitSupport.d.ts +1 -0
  3. package/dist/cjs/actions/getAccountCode.d.ts +1 -0
  4. package/dist/cjs/actions/isSafeWallet.d.ts +1 -0
  5. package/dist/cjs/actions/isSafeWallet.js.map +1 -1
  6. package/dist/cjs/actions/waitForBatchTransactionReceipt.js +31 -5
  7. package/dist/cjs/actions/waitForBatchTransactionReceipt.js.map +1 -1
  8. package/dist/cjs/actions/waitForTransactionReceipt.d.ts +1 -0
  9. package/dist/cjs/core/EthereumStepExecutor.d.ts +1 -0
  10. package/dist/cjs/permits/getNativePermit.d.ts +1 -0
  11. package/dist/cjs/permits/signPermit2Message.d.ts +1 -0
  12. package/dist/cjs/version.d.ts +1 -1
  13. package/dist/cjs/version.js +1 -1
  14. package/dist/cjs/version.js.map +1 -1
  15. package/dist/esm/actions/checkPermitSupport.d.ts +1 -0
  16. package/dist/esm/actions/getAccountCode.d.ts +1 -0
  17. package/dist/esm/actions/isSafeWallet.d.ts +1 -0
  18. package/dist/esm/actions/waitForBatchTransactionReceipt.d.ts.map +1 -1
  19. package/dist/esm/actions/waitForBatchTransactionReceipt.js +31 -5
  20. package/dist/esm/actions/waitForBatchTransactionReceipt.js.map +1 -1
  21. package/dist/esm/actions/waitForTransactionReceipt.d.ts +1 -0
  22. package/dist/esm/core/EthereumStepExecutor.d.ts +1 -0
  23. package/dist/esm/permits/getNativePermit.d.ts +1 -0
  24. package/dist/esm/permits/signPermit2Message.d.ts +1 -0
  25. package/dist/esm/version.d.ts +1 -1
  26. package/dist/esm/version.js +1 -1
  27. package/dist/esm/version.js.map +1 -1
  28. package/package.json +2 -2
  29. package/src/actions/waitForBatchTransactionReceipt.ts +49 -8
  30. package/src/version.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @lifi/sdk-provider-ethereum
2
2
 
3
+ ## 4.2.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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.
8
+
9
+ - [#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`.
10
+
11
+ ## 4.2.10
12
+
13
+ ### Patch Changes
14
+
15
+ - [#519](https://github.com/lifinance/sdk/pull/519) [`950bdbd`](https://github.com/lifinance/sdk/commit/950bdbd6c0415b950f3f5cf896a100c67ad5902f) Thanks [@chybisov](https://github.com/chybisov)! - Bump the runtime dependency viem to 2.57.4.
16
+
3
17
  ## 4.2.9
4
18
 
5
19
  ### Patch Changes
@@ -28,4 +28,5 @@ export declare const checkPermitSupport: (client: SDKClient, { chain, tokenAddre
28
28
  amount: bigint;
29
29
  }) => Promise<PermitSupport>;
30
30
  //#endregion
31
+ export {};
31
32
  //# sourceMappingURL=checkPermitSupport.d.ts.map
@@ -26,4 +26,5 @@ type GetAccountCodeParams = {
26
26
  */
27
27
  export declare const getAccountCode: ({ client, chainId, address }: GetAccountCodeParams) => Promise<Hex | undefined>;
28
28
  //#endregion
29
+ export {};
29
30
  //# sourceMappingURL=getAccountCode.d.ts.map
@@ -13,4 +13,5 @@ type IsSafeWalletParams = {
13
13
  */
14
14
  export declare function isSafeWallet({ client, chainId, address, safeApiKey }: IsSafeWalletParams): Promise<boolean>;
15
15
  //#endregion
16
+ export {};
16
17
  //# sourceMappingURL=isSafeWallet.d.ts.map
@@ -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"}
@@ -9,4 +9,5 @@ interface WaitForTransactionReceiptProps {
9
9
  }
10
10
  export declare function waitForTransactionReceipt(client: SDKClient, { client: viemClient, chainId, txHash, onReplaced }: WaitForTransactionReceiptProps): Promise<TransactionReceipt | undefined>;
11
11
  //#endregion
12
+ export {};
12
13
  //# sourceMappingURL=waitForTransactionReceipt.d.ts.map
@@ -20,4 +20,5 @@ export declare class EthereumStepExecutor extends BaseStepExecutor {
20
20
  override createPipeline: (context: EthereumStepExecutorContext) => TaskPipeline;
21
21
  }
22
22
  //#endregion
23
+ export {};
23
24
  //# sourceMappingURL=EthereumStepExecutor.d.ts.map
@@ -27,4 +27,5 @@ type GetNativePermitParams = {
27
27
  */
28
28
  export declare const getNativePermit: (viemClient: Client, { client, chainId, tokenAddress, spenderAddress, amount, ownerAddress }: GetNativePermitParams) => Promise<NativePermitData | undefined>;
29
29
  //#endregion
30
+ export {};
30
31
  //# sourceMappingURL=getNativePermit.d.ts.map
@@ -11,4 +11,5 @@ interface SignPermit2MessageParams {
11
11
  }
12
12
  export declare function signPermit2Message(client: SDKClient, params: SignPermit2MessageParams): Promise<SignedTypedData>;
13
13
  //#endregion
14
+ export {};
14
15
  //# sourceMappingURL=signPermit2Message.d.ts.map
@@ -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.9";
3
+ export declare const version = "4.2.11";
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.9";
4
+ const version = "4.2.11";
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.9'\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.11'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
@@ -28,4 +28,5 @@ export declare const checkPermitSupport: (client: SDKClient, { chain, tokenAddre
28
28
  amount: bigint;
29
29
  }) => Promise<PermitSupport>;
30
30
  //#endregion
31
+ export {};
31
32
  //# sourceMappingURL=checkPermitSupport.d.ts.map
@@ -26,4 +26,5 @@ type GetAccountCodeParams = {
26
26
  */
27
27
  export declare const getAccountCode: ({ client, chainId, address }: GetAccountCodeParams) => Promise<Hex | undefined>;
28
28
  //#endregion
29
+ export {};
29
30
  //# sourceMappingURL=getAccountCode.d.ts.map
@@ -13,4 +13,5 @@ type IsSafeWalletParams = {
13
13
  */
14
14
  export declare function isSafeWallet({ client, chainId, address, safeApiKey }: IsSafeWalletParams): Promise<boolean>;
15
15
  //#endregion
16
+ export {};
16
17
  //# sourceMappingURL=isSafeWallet.d.ts.map
@@ -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"}
@@ -9,4 +9,5 @@ interface WaitForTransactionReceiptProps {
9
9
  }
10
10
  export declare function waitForTransactionReceipt(client: SDKClient, { client: viemClient, chainId, txHash, onReplaced }: WaitForTransactionReceiptProps): Promise<TransactionReceipt | undefined>;
11
11
  //#endregion
12
+ export {};
12
13
  //# sourceMappingURL=waitForTransactionReceipt.d.ts.map
@@ -20,4 +20,5 @@ export declare class EthereumStepExecutor extends BaseStepExecutor {
20
20
  override createPipeline: (context: EthereumStepExecutorContext) => TaskPipeline;
21
21
  }
22
22
  //#endregion
23
+ export {};
23
24
  //# sourceMappingURL=EthereumStepExecutor.d.ts.map
@@ -27,4 +27,5 @@ type GetNativePermitParams = {
27
27
  */
28
28
  export declare const getNativePermit: (viemClient: Client, { client, chainId, tokenAddress, spenderAddress, amount, ownerAddress }: GetNativePermitParams) => Promise<NativePermitData | undefined>;
29
29
  //#endregion
30
+ export {};
30
31
  //# sourceMappingURL=getNativePermit.d.ts.map
@@ -11,4 +11,5 @@ interface SignPermit2MessageParams {
11
11
  }
12
12
  export declare function signPermit2Message(client: SDKClient, params: SignPermit2MessageParams): Promise<SignedTypedData>;
13
13
  //#endregion
14
+ export {};
14
15
  //# sourceMappingURL=signPermit2Message.d.ts.map
@@ -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.9";
3
+ export declare const version = "4.2.11";
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.9";
3
+ const version = "4.2.11";
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.9'\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.11'\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.9",
3
+ "version": "4.2.11",
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.3"
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') {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk-provider-ethereum'
2
- export const version = '4.2.9'
2
+ export const version = '4.2.11'