@lifi/sdk-provider-ethereum 4.2.7 → 4.2.9
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.
- package/CHANGELOG.md +25 -0
- package/dist/cjs/actions/waitForBatchTransactionReceipt.d.ts +25 -1
- package/dist/cjs/actions/waitForBatchTransactionReceipt.js +48 -5
- package/dist/cjs/actions/waitForBatchTransactionReceipt.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumBatchedSignAndExecuteTask.js +1 -0
- package/dist/cjs/core/tasks/EthereumBatchedSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumBatchedWaitForTransactionTask.js +7 -3
- package/dist/cjs/core/tasks/EthereumBatchedWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/errors/parseEthereumErrors.js +8 -1
- package/dist/cjs/errors/parseEthereumErrors.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/actions/waitForBatchTransactionReceipt.d.ts +25 -1
- package/dist/esm/actions/waitForBatchTransactionReceipt.d.ts.map +1 -1
- package/dist/esm/actions/waitForBatchTransactionReceipt.js +48 -5
- package/dist/esm/actions/waitForBatchTransactionReceipt.js.map +1 -1
- package/dist/esm/core/tasks/EthereumBatchedSignAndExecuteTask.js +1 -0
- package/dist/esm/core/tasks/EthereumBatchedSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumBatchedWaitForTransactionTask.js +7 -3
- package/dist/esm/core/tasks/EthereumBatchedWaitForTransactionTask.js.map +1 -1
- package/dist/esm/errors/parseEthereumErrors.d.ts.map +1 -1
- package/dist/esm/errors/parseEthereumErrors.js +8 -1
- package/dist/esm/errors/parseEthereumErrors.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +2 -2
- package/src/actions/waitForBatchTransactionReceipt.ts +94 -10
- package/src/core/tasks/EthereumBatchedSignAndExecuteTask.ts +1 -0
- package/src/core/tasks/EthereumBatchedWaitForTransactionTask.ts +17 -13
- package/src/errors/parseEthereumErrors.ts +10 -6
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @lifi/sdk-provider-ethereum
|
|
2
2
|
|
|
3
|
+
## 4.2.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`07cc186`](https://github.com/lifinance/sdk/commit/07cc1869a6966980ce2226036f8b441ce68f0a36)]:
|
|
8
|
+
- @lifi/sdk@4.12.1
|
|
9
|
+
|
|
10
|
+
## 4.2.8
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [#514](https://github.com/lifinance/sdk/pull/514) [`5dc9cc5`](https://github.com/lifinance/sdk/commit/5dc9cc5f52b0308962b822cfacd766dbf27bab3c) Thanks [@chybisov](https://github.com/chybisov)! - After a user rejected a single-call EIP-5792 bundle in MetaMask, every "Try again" failed with "This bundle id is unknown". The wallet showed no new prompt. MetaMask returns the bundle id before the user approves the bundle. When the user rejects the bundle, MetaMask removes it.
|
|
15
|
+
|
|
16
|
+
Now the SDK uses a new rule for a bundle with one call. If the wallet reports the bundle and then has no record of it in the same wait, the SDK treats the bundle as never sent. The step fails with a final `SignatureRejected`. The action keeps the bundle id with `txFinal: true`, so the action is closed, and "Try again" signs a new bundle. The SDK uses this rule only for 10 minutes after signing. Some wallets get the bundle status from a remote service, and that service can forget an old bundle.
|
|
17
|
+
|
|
18
|
+
This rule applies only to a bundle with one call. MetaMask returns the id of a bundle with two or more calls only after it sent the bundle. The action stores the number of calls in `callCount`, so the rule also works after a page reload. A bundle that the SDK stored before this release has no `callCount`, and the rule does not apply to it.
|
|
19
|
+
|
|
20
|
+
One limit stays for a bundle with one call. If the wallet sends it and then loses its record of it within 10 minutes of signing, "Try again" can sign a second bundle. Examples are "Delete activity and nonce data" or "Reset account" in MetaMask, or a remote status service that forgets the bundle.
|
|
21
|
+
|
|
22
|
+
When the wallet has no record of the bundle at its first answer, the step fails with the new code `LiFiErrorCode.CallBundleNotFound`. A page reload after the reject is an example. The step also fails with this code when the rule does not apply. An example is a wallet that loses the bundle 10 minutes or more after signing. The SDK cannot know if the wallet sent this bundle. Thus the action keeps the bundle id, and "Try again" waits for the bundle again and does not sign. A route that is stuck after a reject on `@lifi/sdk` 4.11.0 fails with `CallBundleNotFound` on its next "Try again".
|
|
23
|
+
|
|
24
|
+
If an "unknown bundle id" error (5730) reaches the error parser from another call, the step also fails with `CallBundleNotFound`, not with `SignatureRejected`.
|
|
25
|
+
- Updated dependencies [[`5dc9cc5`](https://github.com/lifinance/sdk/commit/5dc9cc5f52b0308962b822cfacd766dbf27bab3c)]:
|
|
26
|
+
- @lifi/sdk@4.12.0
|
|
27
|
+
|
|
3
28
|
## 4.2.7
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
|
@@ -2,6 +2,30 @@ import { WalletCallReceipt as WalletCallReceipt$1 } from "../types.js";
|
|
|
2
2
|
import { Client, Hash } from "viem";
|
|
3
3
|
import { GetCallsStatusReturnType } from "viem/actions";
|
|
4
4
|
//#region src/actions/waitForBatchTransactionReceipt.d.ts
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Waits until the wallet reports the EIP-5792 call bundle as done or failed.
|
|
7
|
+
*
|
|
8
|
+
* MetaMask returns the id of a single-call bundle before the user approves
|
|
9
|
+
* it, and removes the bundle on a reject: `wallet_getCallsStatus` then fails
|
|
10
|
+
* with 5730 (`UnknownBundleIdError`). It returns the id of a bundle of two or
|
|
11
|
+
* more calls only after it sent the bundle. Thus the SDK treats a bundle as
|
|
12
|
+
* never sent only when all of these are true: its stored `callCount` is 1,
|
|
13
|
+
* the wallet answered for it in this wait and then has no record of it, and
|
|
14
|
+
* this happens within `DROPPED_BUNDLE_MAX_AGE_MS` of signing.
|
|
15
|
+
*
|
|
16
|
+
* @param client - The wallet client that sent the bundle.
|
|
17
|
+
* @param batchHash - The bundle id that `wallet_sendCalls` returned.
|
|
18
|
+
* @param options.onFailed - Gets the wallet's answer for a failed bundle, before the error is thrown.
|
|
19
|
+
* @param options.signedAt - The signing time of the step (`execution.signedAt`).
|
|
20
|
+
* @param options.callCount - The stored number of calls of the bundle (`action.callCount`).
|
|
21
|
+
* @returns The receipt of the last call of the bundle.
|
|
22
|
+
* @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.
|
|
23
|
+
* @throws Any other error of the wallet, unchanged.
|
|
24
|
+
*/
|
|
25
|
+
export declare const waitForBatchTransactionReceipt: (client: Client, batchHash: Hash, { onFailed, signedAt, callCount }?: {
|
|
26
|
+
onFailed?: (result: GetCallsStatusReturnType) => void;
|
|
27
|
+
signedAt?: number;
|
|
28
|
+
callCount?: number;
|
|
29
|
+
}) => Promise<WalletCallReceipt$1>;
|
|
6
30
|
//#endregion
|
|
7
31
|
//# sourceMappingURL=waitForBatchTransactionReceipt.d.ts.map
|
|
@@ -1,13 +1,56 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _lifi_sdk = require("@lifi/sdk");
|
|
3
|
+
let viem = require("viem");
|
|
3
4
|
let viem_actions = require("viem/actions");
|
|
4
5
|
let viem_utils = require("viem/utils");
|
|
5
6
|
//#region src/actions/waitForBatchTransactionReceipt.ts
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const DROPPED_BUNDLE_MAX_AGE_MS = 6e5;
|
|
8
|
+
const isUnknownBundleIdError = (error) => error?.name === "UnknownBundleIdError" || error?.cause?.name === "UnknownBundleIdError" || error?.code === viem.UnknownBundleIdError.code;
|
|
9
|
+
/**
|
|
10
|
+
* Unknown signing time is never in the window. Nor is a signing time in the
|
|
11
|
+
* future, as in `isResendAllowed`.
|
|
12
|
+
*/
|
|
13
|
+
const isWithinDropWindow = (signedAt) => {
|
|
14
|
+
const now = Date.now();
|
|
15
|
+
return signedAt !== void 0 && now >= signedAt && now - signedAt < DROPPED_BUNDLE_MAX_AGE_MS;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Waits until the wallet reports the EIP-5792 call bundle as done or failed.
|
|
19
|
+
*
|
|
20
|
+
* MetaMask returns the id of a single-call bundle before the user approves
|
|
21
|
+
* it, and removes the bundle on a reject: `wallet_getCallsStatus` then fails
|
|
22
|
+
* with 5730 (`UnknownBundleIdError`). It returns the id of a bundle of two or
|
|
23
|
+
* more calls only after it sent the bundle. Thus the SDK treats a bundle as
|
|
24
|
+
* never sent only when all of these are true: its stored `callCount` is 1,
|
|
25
|
+
* the wallet answered for it in this wait and then has no record of it, and
|
|
26
|
+
* this happens within `DROPPED_BUNDLE_MAX_AGE_MS` of signing.
|
|
27
|
+
*
|
|
28
|
+
* @param client - The wallet client that sent the bundle.
|
|
29
|
+
* @param batchHash - The bundle id that `wallet_sendCalls` returned.
|
|
30
|
+
* @param options.onFailed - Gets the wallet's answer for a failed bundle, before the error is thrown.
|
|
31
|
+
* @param options.signedAt - The signing time of the step (`execution.signedAt`).
|
|
32
|
+
* @param options.callCount - The stored number of calls of the bundle (`action.callCount`).
|
|
33
|
+
* @returns The receipt of the last call of the bundle.
|
|
34
|
+
* @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.
|
|
35
|
+
* @throws Any other error of the wallet, unchanged.
|
|
36
|
+
*/
|
|
37
|
+
const waitForBatchTransactionReceipt = async (client, batchHash, { onFailed, signedAt, callCount } = {}) => {
|
|
38
|
+
let known = false;
|
|
39
|
+
let result;
|
|
40
|
+
try {
|
|
41
|
+
result = await (0, viem_utils.getAction)(client, viem_actions.waitForCallsStatus, "waitForCallsStatus")({
|
|
42
|
+
id: batchHash,
|
|
43
|
+
timeout: 864e5,
|
|
44
|
+
status: ({ statusCode }) => {
|
|
45
|
+
known = true;
|
|
46
|
+
return statusCode === 200 || statusCode >= 300;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (!isUnknownBundleIdError(error)) throw error;
|
|
51
|
+
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
|
+
throw new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.CallBundleNotFound, "The wallet has no record of the call bundle.", error);
|
|
53
|
+
}
|
|
11
54
|
if (result.status === "success") {
|
|
12
55
|
if (result.receipts?.some((receipt) => receipt.status === "reverted")) {
|
|
13
56
|
onFailed?.(result);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForBatchTransactionReceipt.js","names":["getAction","waitForCallsStatus","TransactionError","LiFiErrorCode"],"sources":["../../../src/actions/waitForBatchTransactionReceipt.ts"],"sourcesContent":["import { LiFiErrorCode, TransactionError } from '@lifi/sdk'\nimport type
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumBatchedSignAndExecuteTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","getAction","sendCalls","CLEARED_TRANSACTION_FIELDS"],"sources":["../../../../src/core/tasks/EthereumBatchedSignAndExecuteTask.ts"],"sourcesContent":["import {\n assertNoOpenTransaction,\n BaseStepExecutionTask,\n CLEARED_TRANSACTION_FIELDS,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Address, Hash, Hex } from 'viem'\nimport { sendCalls } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { Call, EthereumStepExecutorContext } from '../../types.js'\n\nexport class EthereumBatchedSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n fromChain,\n statusManager,\n checkClient,\n transactionRequest,\n calls: currentCalls,\n isBridgeExecution,\n } = context\n\n const calls = [...currentCalls]\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Make sure that the chain is still correct\n const updatedClient = await checkClient(step)\n if (!updatedClient) {\n return { status: 'PAUSED' }\n }\n\n if (!transactionRequest) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction request is not found.'\n )\n }\n\n const transferCall: Call = {\n chainId: fromChain.id,\n data: transactionRequest.data as Hex,\n to: transactionRequest.to as Address,\n value: transactionRequest.value,\n }\n\n calls.push(transferCall)\n\n // Checked again right before the wallet: a late write of an older run\n // can merge its transaction into this action during the awaits above\n // (strategy, chain switch).\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n const { id } = await getAction(\n updatedClient,\n sendCalls,\n 'sendCalls'\n )({\n account: updatedClient.account!,\n calls,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n // A new transaction: nothing of the previous one may survive, least of\n // all its `txFinal` verdict.\n ...CLEARED_TRANSACTION_FIELDS,\n taskId: id as Hash,\n txType: 'batched',\n signedAt: Date.now(),\n })\n\n return { status: 'COMPLETED', context: { calls } }\n }\n}\n"],"mappings":";;;;;AAaA,IAAa,oCAAb,cAAuDA,UAAAA,sBAAsB;CAC3E,MAAM,IAAI,SAA2D;EACnE,MAAM,EACJ,MACA,WACA,eACA,aACA,oBACA,OAAO,cACP,sBACE;EAEJ,MAAM,QAAQ,CAAC,GAAG,YAAY;EAE9B,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,kDACF;EAIF,MAAM,gBAAgB,MAAM,YAAY,IAAI;EAC5C,IAAI,CAAC,eACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,IAAI,CAAC,oBACH,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,uBACd,kEACF;EAGF,MAAM,eAAqB;GACzB,SAAS,UAAU;GACnB,MAAM,mBAAmB;GACzB,IAAI,mBAAmB;GACvB,OAAO,mBAAmB;EAC5B;EAEA,MAAM,KAAK,YAAY;EAKvB,CAAA,GAAA,UAAA,wBAAA,CAAwB,cAAc,WAAW,MAAM,OAAO,IAAI,CAAC;EAEnE,MAAM,EAAE,OAAO,OAAA,GAAMC,WAAAA,UAAAA,CACnB,eACAC,aAAAA,WACA,WACF,CAAC,CAAC;GACA,SAAS,cAAc;GACvB;EACF,CAAC;EAED,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GAGvD,GAAGC,UAAAA;GACH,QAAQ;GACR,QAAQ;GACR,UAAU,KAAK,IAAI;EACrB,CAAC;EAED,OAAO;GAAE,QAAQ;GAAa,SAAS,EAAE,MAAM;EAAE;CACnD;AACF"}
|
|
1
|
+
{"version":3,"file":"EthereumBatchedSignAndExecuteTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","getAction","sendCalls","CLEARED_TRANSACTION_FIELDS"],"sources":["../../../../src/core/tasks/EthereumBatchedSignAndExecuteTask.ts"],"sourcesContent":["import {\n assertNoOpenTransaction,\n BaseStepExecutionTask,\n CLEARED_TRANSACTION_FIELDS,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Address, Hash, Hex } from 'viem'\nimport { sendCalls } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { Call, EthereumStepExecutorContext } from '../../types.js'\n\nexport class EthereumBatchedSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n fromChain,\n statusManager,\n checkClient,\n transactionRequest,\n calls: currentCalls,\n isBridgeExecution,\n } = context\n\n const calls = [...currentCalls]\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Make sure that the chain is still correct\n const updatedClient = await checkClient(step)\n if (!updatedClient) {\n return { status: 'PAUSED' }\n }\n\n if (!transactionRequest) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction request is not found.'\n )\n }\n\n const transferCall: Call = {\n chainId: fromChain.id,\n data: transactionRequest.data as Hex,\n to: transactionRequest.to as Address,\n value: transactionRequest.value,\n }\n\n calls.push(transferCall)\n\n // Checked again right before the wallet: a late write of an older run\n // can merge its transaction into this action during the awaits above\n // (strategy, chain switch).\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n const { id } = await getAction(\n updatedClient,\n sendCalls,\n 'sendCalls'\n )({\n account: updatedClient.account!,\n calls,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n // A new transaction: nothing of the previous one may survive, least of\n // all its `txFinal` verdict.\n ...CLEARED_TRANSACTION_FIELDS,\n taskId: id as Hash,\n txType: 'batched',\n callCount: calls.length,\n signedAt: Date.now(),\n })\n\n return { status: 'COMPLETED', context: { calls } }\n }\n}\n"],"mappings":";;;;;AAaA,IAAa,oCAAb,cAAuDA,UAAAA,sBAAsB;CAC3E,MAAM,IAAI,SAA2D;EACnE,MAAM,EACJ,MACA,WACA,eACA,aACA,oBACA,OAAO,cACP,sBACE;EAEJ,MAAM,QAAQ,CAAC,GAAG,YAAY;EAE9B,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,kDACF;EAIF,MAAM,gBAAgB,MAAM,YAAY,IAAI;EAC5C,IAAI,CAAC,eACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,IAAI,CAAC,oBACH,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,uBACd,kEACF;EAGF,MAAM,eAAqB;GACzB,SAAS,UAAU;GACnB,MAAM,mBAAmB;GACzB,IAAI,mBAAmB;GACvB,OAAO,mBAAmB;EAC5B;EAEA,MAAM,KAAK,YAAY;EAKvB,CAAA,GAAA,UAAA,wBAAA,CAAwB,cAAc,WAAW,MAAM,OAAO,IAAI,CAAC;EAEnE,MAAM,EAAE,OAAO,OAAA,GAAMC,WAAAA,UAAAA,CACnB,eACAC,aAAAA,WACA,WACF,CAAC,CAAC;GACA,SAAS,cAAc;GACvB;EACF,CAAC;EAED,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GAGvD,GAAGC,UAAAA;GACH,QAAQ;GACR,QAAQ;GACR,WAAW,MAAM;GACjB,UAAU,KAAK,IAAI;EACrB,CAAC;EAED,OAAO;GAAE,QAAQ;GAAa,SAAS,EAAE,MAAM;EAAE;CACnD;AACF"}
|
|
@@ -10,9 +10,13 @@ var EthereumBatchedWaitForTransactionTask = class extends _lifi_sdk.BaseStepExec
|
|
|
10
10
|
if (!action) throw new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Action not found.");
|
|
11
11
|
const updatedClient = await checkClient(step);
|
|
12
12
|
if (!updatedClient) return { status: "PAUSED" };
|
|
13
|
-
const transactionReceipt = await require_actions_waitForBatchTransactionReceipt.waitForBatchTransactionReceipt(updatedClient, action.taskId,
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const transactionReceipt = await require_actions_waitForBatchTransactionReceipt.waitForBatchTransactionReceipt(updatedClient, action.taskId, {
|
|
14
|
+
onFailed: (result) => {
|
|
15
|
+
const receipt = result.receipts?.find((r) => r.status === "reverted");
|
|
16
|
+
if (receipt) require_core_tasks_helpers_updateActionWithReceipt.updateActionWithReceipt(statusManager, step, fromChain, receipt, action);
|
|
17
|
+
},
|
|
18
|
+
signedAt: step.execution?.signedAt,
|
|
19
|
+
callCount: action.callCount
|
|
16
20
|
});
|
|
17
21
|
require_core_tasks_helpers_updateActionWithReceipt.updateActionWithReceipt(statusManager, step, fromChain, transactionReceipt, action);
|
|
18
22
|
if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumBatchedWaitForTransactionTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","waitForBatchTransactionReceipt"],"sources":["../../../../src/core/tasks/EthereumBatchedWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Hash } from 'viem'\nimport { waitForBatchTransactionReceipt } from '../../actions/waitForBatchTransactionReceipt.js'\nimport type {\n EthereumStepExecutorContext,\n WalletCallReceipt,\n} from '../../types.js'\nimport { updateActionWithReceipt } from './helpers/updateActionWithReceipt.js'\n\nexport class EthereumBatchedWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const { step, statusManager, fromChain, isBridgeExecution, checkClient } =\n context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const updatedClient = await checkClient(step)\n if (!updatedClient) {\n return { status: 'PAUSED' }\n }\n\n const transactionReceipt = await waitForBatchTransactionReceipt(\n updatedClient,\n action.taskId as Hash,\n (result) => {\n
|
|
1
|
+
{"version":3,"file":"EthereumBatchedWaitForTransactionTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","waitForBatchTransactionReceipt"],"sources":["../../../../src/core/tasks/EthereumBatchedWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Hash } from 'viem'\nimport { waitForBatchTransactionReceipt } from '../../actions/waitForBatchTransactionReceipt.js'\nimport type {\n EthereumStepExecutorContext,\n WalletCallReceipt,\n} from '../../types.js'\nimport { updateActionWithReceipt } from './helpers/updateActionWithReceipt.js'\n\nexport class EthereumBatchedWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const { step, statusManager, fromChain, isBridgeExecution, checkClient } =\n context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const updatedClient = await checkClient(step)\n if (!updatedClient) {\n return { status: 'PAUSED' }\n }\n\n const transactionReceipt = await waitForBatchTransactionReceipt(\n updatedClient,\n action.taskId as Hash,\n {\n onFailed: (result) => {\n const receipt = result.receipts?.find(\n (r) => r.status === 'reverted'\n ) as WalletCallReceipt | undefined\n if (receipt) {\n updateActionWithReceipt(\n statusManager,\n step,\n fromChain,\n receipt,\n action\n )\n }\n },\n signedAt: step.execution?.signedAt,\n callCount: action.callCount,\n }\n )\n\n updateActionWithReceipt(\n statusManager,\n step,\n fromChain,\n transactionReceipt,\n action\n )\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;;;AAcA,IAAa,wCAAb,cAA2DA,UAAAA,sBAAsB;CAC/E,MAAM,IAAI,SAA2D;EACnE,MAAM,EAAE,MAAM,eAAe,WAAW,mBAAmB,gBACzD;EAEF,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAEA,IAAI,CAAC,QACH,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,kDACF;EAGF,MAAM,gBAAgB,MAAM,YAAY,IAAI;EAC5C,IAAI,CAAC,eACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,MAAM,qBAAqB,MAAMC,+CAAAA,+BAC/B,eACA,OAAO,QACP;GACE,WAAW,WAAW;IACpB,MAAM,UAAU,OAAO,UAAU,MAC9B,MAAM,EAAE,WAAW,UACtB;IACA,IAAI,SACF,mDAAA,wBACE,eACA,MACA,WACA,SACA,MACF;GAEJ;GACA,UAAU,KAAK,WAAW;GAC1B,WAAW,OAAO;EACpB,CACF;EAEA,mDAAA,wBACE,eACA,MACA,WACA,oBACA,MACF;EAEA,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAGtD,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF"}
|
|
@@ -14,7 +14,14 @@ const parseEthereumErrors = async (e, step, action, retryParams) => {
|
|
|
14
14
|
return new _lifi_sdk.SDKError(baseError, step, action);
|
|
15
15
|
};
|
|
16
16
|
const handleSpecificErrors = async (e, step, action) => {
|
|
17
|
-
if (e.name === "UserRejectedRequestError" || e.cause?.name === "UserRejectedRequestError"
|
|
17
|
+
if (e.name === "UserRejectedRequestError" || e.cause?.name === "UserRejectedRequestError") return new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.SignatureRejected, e.message, e);
|
|
18
|
+
/**
|
|
19
|
+
* The wallet has no record of an EIP-5792 bundle (5730), so the outcome is unknown: the bundle may still land.
|
|
20
|
+
* No call reaches this branch today, because `waitForBatchTransactionReceipt` handles 5730 first. A later call that reaches it gets the unknown outcome.
|
|
21
|
+
* Only the error itself matches: an error of the batched wait carries it as a cause and keeps its own code.
|
|
22
|
+
* @see https://github.com/MetaMask/core/blob/main/packages/eip-5792-middleware/src/hooks/getCallsStatus.ts
|
|
23
|
+
*/
|
|
24
|
+
if (e.name === "UnknownBundleIdError") return new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.CallBundleNotFound, e.message, e);
|
|
18
25
|
/**
|
|
19
26
|
* Safe Wallet via WalletConnect returns -32000 code when user rejects the signature
|
|
20
27
|
* {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseEthereumErrors.js","names":["ExecuteStepRetryError","SDKError","TransactionError","LiFiErrorCode","ErrorMessage","fetchTxErrorDetails","BaseError","UnknownError","AtomicReadyWalletRejectedUpgradeError"],"sources":["../../../src/errors/parseEthereumErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n ExecuteStepRetryError,\n type ExecuteStepRetryParams,\n type ExecutionAction,\n fetchTxErrorDetails,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\nimport { AtomicReadyWalletRejectedUpgradeError } from 'viem'\n\nexport const parseEthereumErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction,\n retryParams?: ExecuteStepRetryParams\n): Promise<SDKError | ExecuteStepRetryError> => {\n // A task raised it to request a replay; it is not an error to classify.\n if (e instanceof ExecuteStepRetryError) {\n return e\n }\n\n // `executeRoute` replays a step only once, so only the first attempt asks for\n // this retry.\n if (isAtomicReadyWalletRejectedUpgradeError(e) && !retryParams) {\n return new ExecuteStepRetryError(\n 'Wallet rejected 7702 upgrade based on the EIP-5792 capabilities; retry with atomicityNotReady',\n { atomicityNotReady: true },\n e\n )\n }\n\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = await handleSpecificErrors(e, step, action)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = async (\n e: any,\n step?: LiFiStep,\n action?: ExecutionAction\n) => {\n if (\n e.name === 'UserRejectedRequestError' ||\n e.cause?.name === 'UserRejectedRequestError'
|
|
1
|
+
{"version":3,"file":"parseEthereumErrors.js","names":["ExecuteStepRetryError","SDKError","TransactionError","LiFiErrorCode","ErrorMessage","fetchTxErrorDetails","BaseError","UnknownError","AtomicReadyWalletRejectedUpgradeError"],"sources":["../../../src/errors/parseEthereumErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n ExecuteStepRetryError,\n type ExecuteStepRetryParams,\n type ExecutionAction,\n fetchTxErrorDetails,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\nimport { AtomicReadyWalletRejectedUpgradeError } from 'viem'\n\nexport const parseEthereumErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction,\n retryParams?: ExecuteStepRetryParams\n): Promise<SDKError | ExecuteStepRetryError> => {\n // A task raised it to request a replay; it is not an error to classify.\n if (e instanceof ExecuteStepRetryError) {\n return e\n }\n\n // `executeRoute` replays a step only once, so only the first attempt asks for\n // this retry.\n if (isAtomicReadyWalletRejectedUpgradeError(e) && !retryParams) {\n return new ExecuteStepRetryError(\n 'Wallet rejected 7702 upgrade based on the EIP-5792 capabilities; retry with atomicityNotReady',\n { atomicityNotReady: true },\n e\n )\n }\n\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = await handleSpecificErrors(e, step, action)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = async (\n e: any,\n step?: LiFiStep,\n action?: ExecutionAction\n) => {\n if (\n e.name === 'UserRejectedRequestError' ||\n e.cause?.name === 'UserRejectedRequestError'\n ) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n /**\n * The wallet has no record of an EIP-5792 bundle (5730), so the outcome is unknown: the bundle may still land.\n * No call reaches this branch today, because `waitForBatchTransactionReceipt` handles 5730 first. A later call that reaches it gets the unknown outcome.\n * Only the error itself matches: an error of the batched wait carries it as a cause and keeps its own code.\n * @see https://github.com/MetaMask/core/blob/main/packages/eip-5792-middleware/src/hooks/getCallsStatus.ts\n */\n if (e.name === 'UnknownBundleIdError') {\n return new TransactionError(LiFiErrorCode.CallBundleNotFound, e.message, e)\n }\n /**\n * Safe Wallet via WalletConnect returns -32000 code when user rejects the signature\n * {\n * code: -32000,\n * message: 'User rejected transaction',\n * }\n */\n if (\n e.cause?.code === -32000 ||\n // Safe doesn't return proper code, but the error details includes 'rejected'\n (e.name === 'TransactionExecutionError' &&\n e.cause?.details?.includes('rejected'))\n ) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n /**\n * Some wallets reject transactions sometimes with this code because of internal and JSON-RPC errors, e.g.:\n * {\n * \"code\": -32603,\n * \"message\": \"Pop up window failed to open\",\n * \"docUrl\": \"https://docs.cloud.coinbase.com/wallet-sdk/docs/errors\"\n * }\n */\n if (e.cause?.code === -32603) {\n return new TransactionError(LiFiErrorCode.TransactionRejected, e.message, e)\n }\n\n /**\n * This error is specific to Smart Accounts and thrown when the user doesn't have enough gas to pay for the transaction.\n */\n if (\n e.name === 'InsufficientPrefundError' ||\n e.cause?.name === 'InsufficientPrefundError' ||\n e.cause?.cause?.name === 'InsufficientPrefundError'\n ) {\n return new TransactionError(LiFiErrorCode.InsufficientGas, e.message, e)\n }\n\n if (\n step &&\n action?.txHash &&\n e.code === LiFiErrorCode.TransactionFailed &&\n e.message === ErrorMessage.TransactionReverted\n ) {\n const response = await fetchTxErrorDetails(\n action.txHash,\n step.action.fromChainId\n )\n\n const errorMessage = (response as Record<string, string>)?.error_message\n\n if (errorMessage?.toLowerCase().includes('out of gas')) {\n return new TransactionError(\n LiFiErrorCode.GasLimitError,\n ErrorMessage.GasLimitLow,\n e\n )\n }\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n\nexport const isAtomicReadyWalletRejectedUpgradeError = (e: any): boolean => {\n if (e.cause?.code === AtomicReadyWalletRejectedUpgradeError.code) {\n return true\n }\n\n const details = e.cause?.details?.toLowerCase()\n const isTransactionError =\n e.name === 'TransactionExecutionError' ||\n e.cause?.name === 'TransactionExecutionError'\n const hasRejectedUpgrade =\n details?.includes('rejected') && details?.includes('upgrade')\n const has7702ErrorCode = details?.includes('7702')\n\n return isTransactionError && (hasRejectedUpgrade || has7702ErrorCode)\n}\n"],"mappings":";;;;AAeA,MAAa,sBAAsB,OACjC,GACA,MACA,QACA,gBAC8C;CAE9C,IAAI,aAAaA,UAAAA,uBACf,OAAO;CAKT,IAAI,wCAAwC,CAAC,KAAK,CAAC,aACjD,OAAO,IAAIA,UAAAA,sBACT,iGACA,EAAE,mBAAmB,KAAK,GAC1B,CACF;CAGF,IAAI,aAAaC,UAAAA,UAAU;EACzB,EAAE,OAAO,EAAE,QAAQ;EACnB,EAAE,SAAS,EAAE,UAAU;EACvB,OAAO;CACT;CAEA,MAAM,YAAY,MAAM,qBAAqB,GAAG,MAAM,MAAM;CAE5D,OAAO,IAAIA,UAAAA,SAAS,WAAW,MAAM,MAAM;AAC7C;AAEA,MAAM,uBAAuB,OAC3B,GACA,MACA,WACG;CACH,IACE,EAAE,SAAS,8BACX,EAAE,OAAO,SAAS,4BAElB,OAAO,IAAIC,UAAAA,iBAAiBC,UAAAA,cAAc,mBAAmB,EAAE,SAAS,CAAC;;;;;;;CAQ3E,IAAI,EAAE,SAAS,wBACb,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,oBAAoB,EAAE,SAAS,CAAC;;;;;;;;CAS5E,IACE,EAAE,OAAO,SAAS,SAEjB,EAAE,SAAS,+BACV,EAAE,OAAO,SAAS,SAAS,UAAU,GAEvC,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,mBAAmB,EAAE,SAAS,CAAC;;;;;;;;;CAU3E,IAAI,EAAE,OAAO,SAAS,QACpB,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,qBAAqB,EAAE,SAAS,CAAC;;;;CAM7E,IACE,EAAE,SAAS,8BACX,EAAE,OAAO,SAAS,8BAClB,EAAE,OAAO,OAAO,SAAS,4BAEzB,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,iBAAiB,EAAE,SAAS,CAAC;CAGzE,IACE,QACA,QAAQ,UACR,EAAE,SAASA,UAAAA,cAAc,qBACzB,EAAE,YAAYC,UAAAA,aAAa,qBAOL;QAAA,OAAA,GALCC,UAAAA,oBAAAA,CACrB,OAAO,QACP,KAAK,OAAO,WACd,EAAA,EAE2D,cAAA,EAEzC,YAAY,CAAC,CAAC,SAAS,YAAY,GACnD,OAAO,IAAIH,UAAAA,iBACTC,UAAAA,cAAc,eACdC,UAAAA,aAAa,aACb,CACF;CAAA;CAIJ,IAAI,aAAaE,UAAAA,WACf,OAAO;CAGT,OAAO,IAAIC,UAAAA,aAAa,EAAE,WAAWH,UAAAA,aAAa,cAAc,CAAC;AACnE;AAEA,MAAa,2CAA2C,MAAoB;CAC1E,IAAI,EAAE,OAAO,SAASI,KAAAA,sCAAsC,MAC1D,OAAO;CAGT,MAAM,UAAU,EAAE,OAAO,SAAS,YAAY;CAC9C,MAAM,qBACJ,EAAE,SAAS,+BACX,EAAE,OAAO,SAAS;CACpB,MAAM,qBACJ,SAAS,SAAS,UAAU,KAAK,SAAS,SAAS,SAAS;CAC9D,MAAM,mBAAmB,SAAS,SAAS,MAAM;CAEjD,OAAO,uBAAuB,sBAAsB;AACtD"}
|
package/dist/cjs/version.d.ts
CHANGED
package/dist/cjs/version.js
CHANGED
|
@@ -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.
|
|
4
|
+
const version = "4.2.9";
|
|
5
5
|
//#endregion
|
|
6
6
|
exports.name = name;
|
|
7
7
|
exports.version = version;
|
package/dist/cjs/version.js.map
CHANGED
|
@@ -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.
|
|
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"}
|
|
@@ -2,6 +2,30 @@ import { WalletCallReceipt as WalletCallReceipt$1 } from "../types.js";
|
|
|
2
2
|
import { Client, Hash } from "viem";
|
|
3
3
|
import { GetCallsStatusReturnType } from "viem/actions";
|
|
4
4
|
//#region src/actions/waitForBatchTransactionReceipt.d.ts
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Waits until the wallet reports the EIP-5792 call bundle as done or failed.
|
|
7
|
+
*
|
|
8
|
+
* MetaMask returns the id of a single-call bundle before the user approves
|
|
9
|
+
* it, and removes the bundle on a reject: `wallet_getCallsStatus` then fails
|
|
10
|
+
* with 5730 (`UnknownBundleIdError`). It returns the id of a bundle of two or
|
|
11
|
+
* more calls only after it sent the bundle. Thus the SDK treats a bundle as
|
|
12
|
+
* never sent only when all of these are true: its stored `callCount` is 1,
|
|
13
|
+
* the wallet answered for it in this wait and then has no record of it, and
|
|
14
|
+
* this happens within `DROPPED_BUNDLE_MAX_AGE_MS` of signing.
|
|
15
|
+
*
|
|
16
|
+
* @param client - The wallet client that sent the bundle.
|
|
17
|
+
* @param batchHash - The bundle id that `wallet_sendCalls` returned.
|
|
18
|
+
* @param options.onFailed - Gets the wallet's answer for a failed bundle, before the error is thrown.
|
|
19
|
+
* @param options.signedAt - The signing time of the step (`execution.signedAt`).
|
|
20
|
+
* @param options.callCount - The stored number of calls of the bundle (`action.callCount`).
|
|
21
|
+
* @returns The receipt of the last call of the bundle.
|
|
22
|
+
* @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.
|
|
23
|
+
* @throws Any other error of the wallet, unchanged.
|
|
24
|
+
*/
|
|
25
|
+
export declare const waitForBatchTransactionReceipt: (client: Client, batchHash: Hash, { onFailed, signedAt, callCount }?: {
|
|
26
|
+
onFailed?: (result: GetCallsStatusReturnType) => void;
|
|
27
|
+
signedAt?: number;
|
|
28
|
+
callCount?: number;
|
|
29
|
+
}) => Promise<WalletCallReceipt$1>;
|
|
6
30
|
//#endregion
|
|
7
31
|
//# sourceMappingURL=waitForBatchTransactionReceipt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForBatchTransactionReceipt.d.ts","names":["WalletCallReceipt"],"sources":["../../../src/actions/waitForBatchTransactionReceipt.ts"],"mappings":"
|
|
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,12 +1,55 @@
|
|
|
1
1
|
import { LiFiErrorCode, TransactionError } from "@lifi/sdk";
|
|
2
|
+
import { UnknownBundleIdError } from "viem";
|
|
2
3
|
import { waitForCallsStatus } from "viem/actions";
|
|
3
4
|
import { getAction } from "viem/utils";
|
|
4
5
|
//#region src/actions/waitForBatchTransactionReceipt.ts
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const DROPPED_BUNDLE_MAX_AGE_MS = 6e5;
|
|
7
|
+
const isUnknownBundleIdError = (error) => error?.name === "UnknownBundleIdError" || error?.cause?.name === "UnknownBundleIdError" || error?.code === UnknownBundleIdError.code;
|
|
8
|
+
/**
|
|
9
|
+
* Unknown signing time is never in the window. Nor is a signing time in the
|
|
10
|
+
* future, as in `isResendAllowed`.
|
|
11
|
+
*/
|
|
12
|
+
const isWithinDropWindow = (signedAt) => {
|
|
13
|
+
const now = Date.now();
|
|
14
|
+
return signedAt !== void 0 && now >= signedAt && now - signedAt < DROPPED_BUNDLE_MAX_AGE_MS;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Waits until the wallet reports the EIP-5792 call bundle as done or failed.
|
|
18
|
+
*
|
|
19
|
+
* MetaMask returns the id of a single-call bundle before the user approves
|
|
20
|
+
* it, and removes the bundle on a reject: `wallet_getCallsStatus` then fails
|
|
21
|
+
* with 5730 (`UnknownBundleIdError`). It returns the id of a bundle of two or
|
|
22
|
+
* more calls only after it sent the bundle. Thus the SDK treats a bundle as
|
|
23
|
+
* never sent only when all of these are true: its stored `callCount` is 1,
|
|
24
|
+
* the wallet answered for it in this wait and then has no record of it, and
|
|
25
|
+
* this happens within `DROPPED_BUNDLE_MAX_AGE_MS` of signing.
|
|
26
|
+
*
|
|
27
|
+
* @param client - The wallet client that sent the bundle.
|
|
28
|
+
* @param batchHash - The bundle id that `wallet_sendCalls` returned.
|
|
29
|
+
* @param options.onFailed - Gets the wallet's answer for a failed bundle, before the error is thrown.
|
|
30
|
+
* @param options.signedAt - The signing time of the step (`execution.signedAt`).
|
|
31
|
+
* @param options.callCount - The stored number of calls of the bundle (`action.callCount`).
|
|
32
|
+
* @returns The receipt of the last call of the bundle.
|
|
33
|
+
* @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.
|
|
34
|
+
* @throws Any other error of the wallet, unchanged.
|
|
35
|
+
*/
|
|
36
|
+
const waitForBatchTransactionReceipt = async (client, batchHash, { onFailed, signedAt, callCount } = {}) => {
|
|
37
|
+
let known = false;
|
|
38
|
+
let result;
|
|
39
|
+
try {
|
|
40
|
+
result = await getAction(client, waitForCallsStatus, "waitForCallsStatus")({
|
|
41
|
+
id: batchHash,
|
|
42
|
+
timeout: 864e5,
|
|
43
|
+
status: ({ statusCode }) => {
|
|
44
|
+
known = true;
|
|
45
|
+
return statusCode === 200 || statusCode >= 300;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (!isUnknownBundleIdError(error)) throw error;
|
|
50
|
+
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
|
+
throw new TransactionError(LiFiErrorCode.CallBundleNotFound, "The wallet has no record of the call bundle.", error);
|
|
52
|
+
}
|
|
10
53
|
if (result.status === "success") {
|
|
11
54
|
if (result.receipts?.some((receipt) => receipt.status === "reverted")) {
|
|
12
55
|
onFailed?.(result);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForBatchTransactionReceipt.js","names":[],"sources":["../../../src/actions/waitForBatchTransactionReceipt.ts"],"sourcesContent":["import { LiFiErrorCode, TransactionError } from '@lifi/sdk'\nimport type
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumBatchedSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumBatchedSignAndExecuteTask.ts"],"sourcesContent":["import {\n assertNoOpenTransaction,\n BaseStepExecutionTask,\n CLEARED_TRANSACTION_FIELDS,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Address, Hash, Hex } from 'viem'\nimport { sendCalls } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { Call, EthereumStepExecutorContext } from '../../types.js'\n\nexport class EthereumBatchedSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n fromChain,\n statusManager,\n checkClient,\n transactionRequest,\n calls: currentCalls,\n isBridgeExecution,\n } = context\n\n const calls = [...currentCalls]\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Make sure that the chain is still correct\n const updatedClient = await checkClient(step)\n if (!updatedClient) {\n return { status: 'PAUSED' }\n }\n\n if (!transactionRequest) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction request is not found.'\n )\n }\n\n const transferCall: Call = {\n chainId: fromChain.id,\n data: transactionRequest.data as Hex,\n to: transactionRequest.to as Address,\n value: transactionRequest.value,\n }\n\n calls.push(transferCall)\n\n // Checked again right before the wallet: a late write of an older run\n // can merge its transaction into this action during the awaits above\n // (strategy, chain switch).\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n const { id } = await getAction(\n updatedClient,\n sendCalls,\n 'sendCalls'\n )({\n account: updatedClient.account!,\n calls,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n // A new transaction: nothing of the previous one may survive, least of\n // all its `txFinal` verdict.\n ...CLEARED_TRANSACTION_FIELDS,\n taskId: id as Hash,\n txType: 'batched',\n signedAt: Date.now(),\n })\n\n return { status: 'COMPLETED', context: { calls } }\n }\n}\n"],"mappings":";;;;AAaA,IAAa,oCAAb,cAAuD,sBAAsB;CAC3E,MAAM,IAAI,SAA2D;EACnE,MAAM,EACJ,MACA,WACA,eACA,aACA,oBACA,OAAO,cACP,sBACE;EAEJ,MAAM,QAAQ,CAAC,GAAG,YAAY;EAE9B,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAIF,MAAM,gBAAgB,MAAM,YAAY,IAAI;EAC5C,IAAI,CAAC,eACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,IAAI,CAAC,oBACH,MAAM,IAAI,iBACR,cAAc,uBACd,kEACF;EAGF,MAAM,eAAqB;GACzB,SAAS,UAAU;GACnB,MAAM,mBAAmB;GACzB,IAAI,mBAAmB;GACvB,OAAO,mBAAmB;EAC5B;EAEA,MAAM,KAAK,YAAY;EAKvB,wBAAwB,cAAc,WAAW,MAAM,OAAO,IAAI,CAAC;EAEnE,MAAM,EAAE,OAAO,MAAM,UACnB,eACA,WACA,WACF,CAAC,CAAC;GACA,SAAS,cAAc;GACvB;EACF,CAAC;EAED,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GAGvD,GAAG;GACH,QAAQ;GACR,QAAQ;GACR,UAAU,KAAK,IAAI;EACrB,CAAC;EAED,OAAO;GAAE,QAAQ;GAAa,SAAS,EAAE,MAAM;EAAE;CACnD;AACF"}
|
|
1
|
+
{"version":3,"file":"EthereumBatchedSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumBatchedSignAndExecuteTask.ts"],"sourcesContent":["import {\n assertNoOpenTransaction,\n BaseStepExecutionTask,\n CLEARED_TRANSACTION_FIELDS,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Address, Hash, Hex } from 'viem'\nimport { sendCalls } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { Call, EthereumStepExecutorContext } from '../../types.js'\n\nexport class EthereumBatchedSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n fromChain,\n statusManager,\n checkClient,\n transactionRequest,\n calls: currentCalls,\n isBridgeExecution,\n } = context\n\n const calls = [...currentCalls]\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Make sure that the chain is still correct\n const updatedClient = await checkClient(step)\n if (!updatedClient) {\n return { status: 'PAUSED' }\n }\n\n if (!transactionRequest) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction request is not found.'\n )\n }\n\n const transferCall: Call = {\n chainId: fromChain.id,\n data: transactionRequest.data as Hex,\n to: transactionRequest.to as Address,\n value: transactionRequest.value,\n }\n\n calls.push(transferCall)\n\n // Checked again right before the wallet: a late write of an older run\n // can merge its transaction into this action during the awaits above\n // (strategy, chain switch).\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n const { id } = await getAction(\n updatedClient,\n sendCalls,\n 'sendCalls'\n )({\n account: updatedClient.account!,\n calls,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n // A new transaction: nothing of the previous one may survive, least of\n // all its `txFinal` verdict.\n ...CLEARED_TRANSACTION_FIELDS,\n taskId: id as Hash,\n txType: 'batched',\n callCount: calls.length,\n signedAt: Date.now(),\n })\n\n return { status: 'COMPLETED', context: { calls } }\n }\n}\n"],"mappings":";;;;AAaA,IAAa,oCAAb,cAAuD,sBAAsB;CAC3E,MAAM,IAAI,SAA2D;EACnE,MAAM,EACJ,MACA,WACA,eACA,aACA,oBACA,OAAO,cACP,sBACE;EAEJ,MAAM,QAAQ,CAAC,GAAG,YAAY;EAE9B,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAIF,MAAM,gBAAgB,MAAM,YAAY,IAAI;EAC5C,IAAI,CAAC,eACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,IAAI,CAAC,oBACH,MAAM,IAAI,iBACR,cAAc,uBACd,kEACF;EAGF,MAAM,eAAqB;GACzB,SAAS,UAAU;GACnB,MAAM,mBAAmB;GACzB,IAAI,mBAAmB;GACvB,OAAO,mBAAmB;EAC5B;EAEA,MAAM,KAAK,YAAY;EAKvB,wBAAwB,cAAc,WAAW,MAAM,OAAO,IAAI,CAAC;EAEnE,MAAM,EAAE,OAAO,MAAM,UACnB,eACA,WACA,WACF,CAAC,CAAC;GACA,SAAS,cAAc;GACvB;EACF,CAAC;EAED,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GAGvD,GAAG;GACH,QAAQ;GACR,QAAQ;GACR,WAAW,MAAM;GACjB,UAAU,KAAK,IAAI;EACrB,CAAC;EAED,OAAO;GAAE,QAAQ;GAAa,SAAS,EAAE,MAAM;EAAE;CACnD;AACF"}
|
|
@@ -9,9 +9,13 @@ var EthereumBatchedWaitForTransactionTask = class extends BaseStepExecutionTask
|
|
|
9
9
|
if (!action) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Action not found.");
|
|
10
10
|
const updatedClient = await checkClient(step);
|
|
11
11
|
if (!updatedClient) return { status: "PAUSED" };
|
|
12
|
-
const transactionReceipt = await waitForBatchTransactionReceipt(updatedClient, action.taskId,
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const transactionReceipt = await waitForBatchTransactionReceipt(updatedClient, action.taskId, {
|
|
13
|
+
onFailed: (result) => {
|
|
14
|
+
const receipt = result.receipts?.find((r) => r.status === "reverted");
|
|
15
|
+
if (receipt) updateActionWithReceipt(statusManager, step, fromChain, receipt, action);
|
|
16
|
+
},
|
|
17
|
+
signedAt: step.execution?.signedAt,
|
|
18
|
+
callCount: action.callCount
|
|
15
19
|
});
|
|
16
20
|
updateActionWithReceipt(statusManager, step, fromChain, transactionReceipt, action);
|
|
17
21
|
if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumBatchedWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumBatchedWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Hash } from 'viem'\nimport { waitForBatchTransactionReceipt } from '../../actions/waitForBatchTransactionReceipt.js'\nimport type {\n EthereumStepExecutorContext,\n WalletCallReceipt,\n} from '../../types.js'\nimport { updateActionWithReceipt } from './helpers/updateActionWithReceipt.js'\n\nexport class EthereumBatchedWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const { step, statusManager, fromChain, isBridgeExecution, checkClient } =\n context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const updatedClient = await checkClient(step)\n if (!updatedClient) {\n return { status: 'PAUSED' }\n }\n\n const transactionReceipt = await waitForBatchTransactionReceipt(\n updatedClient,\n action.taskId as Hash,\n (result) => {\n
|
|
1
|
+
{"version":3,"file":"EthereumBatchedWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumBatchedWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Hash } from 'viem'\nimport { waitForBatchTransactionReceipt } from '../../actions/waitForBatchTransactionReceipt.js'\nimport type {\n EthereumStepExecutorContext,\n WalletCallReceipt,\n} from '../../types.js'\nimport { updateActionWithReceipt } from './helpers/updateActionWithReceipt.js'\n\nexport class EthereumBatchedWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const { step, statusManager, fromChain, isBridgeExecution, checkClient } =\n context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const updatedClient = await checkClient(step)\n if (!updatedClient) {\n return { status: 'PAUSED' }\n }\n\n const transactionReceipt = await waitForBatchTransactionReceipt(\n updatedClient,\n action.taskId as Hash,\n {\n onFailed: (result) => {\n const receipt = result.receipts?.find(\n (r) => r.status === 'reverted'\n ) as WalletCallReceipt | undefined\n if (receipt) {\n updateActionWithReceipt(\n statusManager,\n step,\n fromChain,\n receipt,\n action\n )\n }\n },\n signedAt: step.execution?.signedAt,\n callCount: action.callCount,\n }\n )\n\n updateActionWithReceipt(\n statusManager,\n step,\n fromChain,\n transactionReceipt,\n action\n )\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;;AAcA,IAAa,wCAAb,cAA2D,sBAAsB;CAC/E,MAAM,IAAI,SAA2D;EACnE,MAAM,EAAE,MAAM,eAAe,WAAW,mBAAmB,gBACzD;EAEF,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAEA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAGF,MAAM,gBAAgB,MAAM,YAAY,IAAI;EAC5C,IAAI,CAAC,eACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,MAAM,qBAAqB,MAAM,+BAC/B,eACA,OAAO,QACP;GACE,WAAW,WAAW;IACpB,MAAM,UAAU,OAAO,UAAU,MAC9B,MAAM,EAAE,WAAW,UACtB;IACA,IAAI,SACF,wBACE,eACA,MACA,WACA,SACA,MACF;GAEJ;GACA,UAAU,KAAK,WAAW;GAC1B,WAAW,OAAO;EACpB,CACF;EAEA,wBACE,eACA,MACA,WACA,oBACA,MACF;EAEA,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAGtD,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseEthereumErrors.d.ts","names":[],"sources":["../../../src/errors/parseEthereumErrors.ts"],"mappings":";;qBAea,sBACX,GAAG,OACH,OAAO,UACP,SAAS,iBACT,cAAc,2BACb,QAAQ,WAAW;
|
|
1
|
+
{"version":3,"file":"parseEthereumErrors.d.ts","names":[],"sources":["../../../src/errors/parseEthereumErrors.ts"],"mappings":";;qBAea,sBACX,GAAG,OACH,OAAO,UACP,SAAS,iBACT,cAAc,2BACb,QAAQ,WAAW;qBAkHT,0CAA2C"}
|
|
@@ -13,7 +13,14 @@ const parseEthereumErrors = async (e, step, action, retryParams) => {
|
|
|
13
13
|
return new SDKError(baseError, step, action);
|
|
14
14
|
};
|
|
15
15
|
const handleSpecificErrors = async (e, step, action) => {
|
|
16
|
-
if (e.name === "UserRejectedRequestError" || e.cause?.name === "UserRejectedRequestError"
|
|
16
|
+
if (e.name === "UserRejectedRequestError" || e.cause?.name === "UserRejectedRequestError") return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e);
|
|
17
|
+
/**
|
|
18
|
+
* The wallet has no record of an EIP-5792 bundle (5730), so the outcome is unknown: the bundle may still land.
|
|
19
|
+
* No call reaches this branch today, because `waitForBatchTransactionReceipt` handles 5730 first. A later call that reaches it gets the unknown outcome.
|
|
20
|
+
* Only the error itself matches: an error of the batched wait carries it as a cause and keeps its own code.
|
|
21
|
+
* @see https://github.com/MetaMask/core/blob/main/packages/eip-5792-middleware/src/hooks/getCallsStatus.ts
|
|
22
|
+
*/
|
|
23
|
+
if (e.name === "UnknownBundleIdError") return new TransactionError(LiFiErrorCode.CallBundleNotFound, e.message, e);
|
|
17
24
|
/**
|
|
18
25
|
* Safe Wallet via WalletConnect returns -32000 code when user rejects the signature
|
|
19
26
|
* {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseEthereumErrors.js","names":[],"sources":["../../../src/errors/parseEthereumErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n ExecuteStepRetryError,\n type ExecuteStepRetryParams,\n type ExecutionAction,\n fetchTxErrorDetails,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\nimport { AtomicReadyWalletRejectedUpgradeError } from 'viem'\n\nexport const parseEthereumErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction,\n retryParams?: ExecuteStepRetryParams\n): Promise<SDKError | ExecuteStepRetryError> => {\n // A task raised it to request a replay; it is not an error to classify.\n if (e instanceof ExecuteStepRetryError) {\n return e\n }\n\n // `executeRoute` replays a step only once, so only the first attempt asks for\n // this retry.\n if (isAtomicReadyWalletRejectedUpgradeError(e) && !retryParams) {\n return new ExecuteStepRetryError(\n 'Wallet rejected 7702 upgrade based on the EIP-5792 capabilities; retry with atomicityNotReady',\n { atomicityNotReady: true },\n e\n )\n }\n\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = await handleSpecificErrors(e, step, action)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = async (\n e: any,\n step?: LiFiStep,\n action?: ExecutionAction\n) => {\n if (\n e.name === 'UserRejectedRequestError' ||\n e.cause?.name === 'UserRejectedRequestError'
|
|
1
|
+
{"version":3,"file":"parseEthereumErrors.js","names":[],"sources":["../../../src/errors/parseEthereumErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n ExecuteStepRetryError,\n type ExecuteStepRetryParams,\n type ExecutionAction,\n fetchTxErrorDetails,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\nimport { AtomicReadyWalletRejectedUpgradeError } from 'viem'\n\nexport const parseEthereumErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction,\n retryParams?: ExecuteStepRetryParams\n): Promise<SDKError | ExecuteStepRetryError> => {\n // A task raised it to request a replay; it is not an error to classify.\n if (e instanceof ExecuteStepRetryError) {\n return e\n }\n\n // `executeRoute` replays a step only once, so only the first attempt asks for\n // this retry.\n if (isAtomicReadyWalletRejectedUpgradeError(e) && !retryParams) {\n return new ExecuteStepRetryError(\n 'Wallet rejected 7702 upgrade based on the EIP-5792 capabilities; retry with atomicityNotReady',\n { atomicityNotReady: true },\n e\n )\n }\n\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = await handleSpecificErrors(e, step, action)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = async (\n e: any,\n step?: LiFiStep,\n action?: ExecutionAction\n) => {\n if (\n e.name === 'UserRejectedRequestError' ||\n e.cause?.name === 'UserRejectedRequestError'\n ) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n /**\n * The wallet has no record of an EIP-5792 bundle (5730), so the outcome is unknown: the bundle may still land.\n * No call reaches this branch today, because `waitForBatchTransactionReceipt` handles 5730 first. A later call that reaches it gets the unknown outcome.\n * Only the error itself matches: an error of the batched wait carries it as a cause and keeps its own code.\n * @see https://github.com/MetaMask/core/blob/main/packages/eip-5792-middleware/src/hooks/getCallsStatus.ts\n */\n if (e.name === 'UnknownBundleIdError') {\n return new TransactionError(LiFiErrorCode.CallBundleNotFound, e.message, e)\n }\n /**\n * Safe Wallet via WalletConnect returns -32000 code when user rejects the signature\n * {\n * code: -32000,\n * message: 'User rejected transaction',\n * }\n */\n if (\n e.cause?.code === -32000 ||\n // Safe doesn't return proper code, but the error details includes 'rejected'\n (e.name === 'TransactionExecutionError' &&\n e.cause?.details?.includes('rejected'))\n ) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n /**\n * Some wallets reject transactions sometimes with this code because of internal and JSON-RPC errors, e.g.:\n * {\n * \"code\": -32603,\n * \"message\": \"Pop up window failed to open\",\n * \"docUrl\": \"https://docs.cloud.coinbase.com/wallet-sdk/docs/errors\"\n * }\n */\n if (e.cause?.code === -32603) {\n return new TransactionError(LiFiErrorCode.TransactionRejected, e.message, e)\n }\n\n /**\n * This error is specific to Smart Accounts and thrown when the user doesn't have enough gas to pay for the transaction.\n */\n if (\n e.name === 'InsufficientPrefundError' ||\n e.cause?.name === 'InsufficientPrefundError' ||\n e.cause?.cause?.name === 'InsufficientPrefundError'\n ) {\n return new TransactionError(LiFiErrorCode.InsufficientGas, e.message, e)\n }\n\n if (\n step &&\n action?.txHash &&\n e.code === LiFiErrorCode.TransactionFailed &&\n e.message === ErrorMessage.TransactionReverted\n ) {\n const response = await fetchTxErrorDetails(\n action.txHash,\n step.action.fromChainId\n )\n\n const errorMessage = (response as Record<string, string>)?.error_message\n\n if (errorMessage?.toLowerCase().includes('out of gas')) {\n return new TransactionError(\n LiFiErrorCode.GasLimitError,\n ErrorMessage.GasLimitLow,\n e\n )\n }\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n\nexport const isAtomicReadyWalletRejectedUpgradeError = (e: any): boolean => {\n if (e.cause?.code === AtomicReadyWalletRejectedUpgradeError.code) {\n return true\n }\n\n const details = e.cause?.details?.toLowerCase()\n const isTransactionError =\n e.name === 'TransactionExecutionError' ||\n e.cause?.name === 'TransactionExecutionError'\n const hasRejectedUpgrade =\n details?.includes('rejected') && details?.includes('upgrade')\n const has7702ErrorCode = details?.includes('7702')\n\n return isTransactionError && (hasRejectedUpgrade || has7702ErrorCode)\n}\n"],"mappings":";;;AAeA,MAAa,sBAAsB,OACjC,GACA,MACA,QACA,gBAC8C;CAE9C,IAAI,aAAa,uBACf,OAAO;CAKT,IAAI,wCAAwC,CAAC,KAAK,CAAC,aACjD,OAAO,IAAI,sBACT,iGACA,EAAE,mBAAmB,KAAK,GAC1B,CACF;CAGF,IAAI,aAAa,UAAU;EACzB,EAAE,OAAO,EAAE,QAAQ;EACnB,EAAE,SAAS,EAAE,UAAU;EACvB,OAAO;CACT;CAEA,MAAM,YAAY,MAAM,qBAAqB,GAAG,MAAM,MAAM;CAE5D,OAAO,IAAI,SAAS,WAAW,MAAM,MAAM;AAC7C;AAEA,MAAM,uBAAuB,OAC3B,GACA,MACA,WACG;CACH,IACE,EAAE,SAAS,8BACX,EAAE,OAAO,SAAS,4BAElB,OAAO,IAAI,iBAAiB,cAAc,mBAAmB,EAAE,SAAS,CAAC;;;;;;;CAQ3E,IAAI,EAAE,SAAS,wBACb,OAAO,IAAI,iBAAiB,cAAc,oBAAoB,EAAE,SAAS,CAAC;;;;;;;;CAS5E,IACE,EAAE,OAAO,SAAS,SAEjB,EAAE,SAAS,+BACV,EAAE,OAAO,SAAS,SAAS,UAAU,GAEvC,OAAO,IAAI,iBAAiB,cAAc,mBAAmB,EAAE,SAAS,CAAC;;;;;;;;;CAU3E,IAAI,EAAE,OAAO,SAAS,QACpB,OAAO,IAAI,iBAAiB,cAAc,qBAAqB,EAAE,SAAS,CAAC;;;;CAM7E,IACE,EAAE,SAAS,8BACX,EAAE,OAAO,SAAS,8BAClB,EAAE,OAAO,OAAO,SAAS,4BAEzB,OAAO,IAAI,iBAAiB,cAAc,iBAAiB,EAAE,SAAS,CAAC;CAGzE,IACE,QACA,QAAQ,UACR,EAAE,SAAS,cAAc,qBACzB,EAAE,YAAY,aAAa,qBAOL;QAAA,MALC,oBACrB,OAAO,QACP,KAAK,OAAO,WACd,EAAA,EAE2D,cAAA,EAEzC,YAAY,CAAC,CAAC,SAAS,YAAY,GACnD,OAAO,IAAI,iBACT,cAAc,eACd,aAAa,aACb,CACF;CAAA;CAIJ,IAAI,aAAa,WACf,OAAO;CAGT,OAAO,IAAI,aAAa,EAAE,WAAW,aAAa,cAAc,CAAC;AACnE;AAEA,MAAa,2CAA2C,MAAoB;CAC1E,IAAI,EAAE,OAAO,SAAS,sCAAsC,MAC1D,OAAO;CAGT,MAAM,UAAU,EAAE,OAAO,SAAS,YAAY;CAC9C,MAAM,qBACJ,EAAE,SAAS,+BACX,EAAE,OAAO,SAAS;CACpB,MAAM,qBACJ,SAAS,SAAS,UAAU,KAAK,SAAS,SAAS,SAAS;CAC9D,MAAM,mBAAmB,SAAS,SAAS,MAAM;CAEjD,OAAO,uBAAuB,sBAAsB;AACtD"}
|
package/dist/esm/version.d.ts
CHANGED
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -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.
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk-provider-ethereum",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.9",
|
|
4
4
|
"description": "LI.FI Ethereum SDK Provider for Any-to-Any Cross-Chain-Swap",
|
|
5
5
|
"homepage": "https://github.com/lifinance/sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@lifi/sdk": "4.
|
|
31
|
+
"@lifi/sdk": "4.12.1",
|
|
32
32
|
"viem": "^2.57.3"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
@@ -1,22 +1,106 @@
|
|
|
1
1
|
import { LiFiErrorCode, TransactionError } from '@lifi/sdk'
|
|
2
|
-
import type
|
|
2
|
+
import { type Client, type Hash, UnknownBundleIdError } from 'viem'
|
|
3
3
|
import { type GetCallsStatusReturnType, waitForCallsStatus } from 'viem/actions'
|
|
4
4
|
import { getAction } from 'viem/utils'
|
|
5
5
|
import type { WalletCallReceipt } from '../types.js'
|
|
6
6
|
|
|
7
|
+
// Some wallets answer from a remote service that can forget an old bundle.
|
|
8
|
+
const DROPPED_BUNDLE_MAX_AGE_MS = 10 * 60_000
|
|
9
|
+
|
|
10
|
+
const isUnknownBundleIdError = (error: any): boolean =>
|
|
11
|
+
error?.name === 'UnknownBundleIdError' ||
|
|
12
|
+
error?.cause?.name === 'UnknownBundleIdError' ||
|
|
13
|
+
error?.code === UnknownBundleIdError.code
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Unknown signing time is never in the window. Nor is a signing time in the
|
|
17
|
+
* future, as in `isResendAllowed`.
|
|
18
|
+
*/
|
|
19
|
+
const isWithinDropWindow = (signedAt: number | undefined): boolean => {
|
|
20
|
+
const now = Date.now()
|
|
21
|
+
return (
|
|
22
|
+
signedAt !== undefined &&
|
|
23
|
+
now >= signedAt &&
|
|
24
|
+
now - signedAt < DROPPED_BUNDLE_MAX_AGE_MS
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Waits until the wallet reports the EIP-5792 call bundle as done or failed.
|
|
30
|
+
*
|
|
31
|
+
* MetaMask returns the id of a single-call bundle before the user approves
|
|
32
|
+
* it, and removes the bundle on a reject: `wallet_getCallsStatus` then fails
|
|
33
|
+
* with 5730 (`UnknownBundleIdError`). It returns the id of a bundle of two or
|
|
34
|
+
* more calls only after it sent the bundle. Thus the SDK treats a bundle as
|
|
35
|
+
* never sent only when all of these are true: its stored `callCount` is 1,
|
|
36
|
+
* the wallet answered for it in this wait and then has no record of it, and
|
|
37
|
+
* this happens within `DROPPED_BUNDLE_MAX_AGE_MS` of signing.
|
|
38
|
+
*
|
|
39
|
+
* @param client - The wallet client that sent the bundle.
|
|
40
|
+
* @param batchHash - The bundle id that `wallet_sendCalls` returned.
|
|
41
|
+
* @param options.onFailed - Gets the wallet's answer for a failed bundle, before the error is thrown.
|
|
42
|
+
* @param options.signedAt - The signing time of the step (`execution.signedAt`).
|
|
43
|
+
* @param options.callCount - The stored number of calls of the bundle (`action.callCount`).
|
|
44
|
+
* @returns The receipt of the last call of the bundle.
|
|
45
|
+
* @throws {TransactionError} If the bundle failed, was canceled, or the wallet has no record of it. A bundle that the SDK treats as never sent is a final `SignatureRejected`. Any other bundle without a record is `CallBundleNotFound`, which is not final.
|
|
46
|
+
* @throws Any other error of the wallet, unchanged.
|
|
47
|
+
*/
|
|
7
48
|
export const waitForBatchTransactionReceipt = async (
|
|
8
49
|
client: Client,
|
|
9
50
|
batchHash: Hash,
|
|
10
|
-
|
|
51
|
+
{
|
|
52
|
+
onFailed,
|
|
53
|
+
signedAt,
|
|
54
|
+
callCount,
|
|
55
|
+
}: {
|
|
56
|
+
onFailed?: (result: GetCallsStatusReturnType) => void
|
|
57
|
+
signedAt?: number
|
|
58
|
+
callCount?: number
|
|
59
|
+
} = {}
|
|
11
60
|
): Promise<WalletCallReceipt> => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
61
|
+
let known = false
|
|
62
|
+
let result: GetCallsStatusReturnType
|
|
63
|
+
try {
|
|
64
|
+
result = await getAction(
|
|
65
|
+
client,
|
|
66
|
+
waitForCallsStatus,
|
|
67
|
+
'waitForCallsStatus'
|
|
68
|
+
)({
|
|
69
|
+
id: batchHash,
|
|
70
|
+
timeout: 3_600_000 * 24,
|
|
71
|
+
// viem's default, and a record that the wallet answered for this id.
|
|
72
|
+
// viem shares one poll between waits for the same client and id, and
|
|
73
|
+
// calls only the predicate of the wait that started it.
|
|
74
|
+
status: ({ statusCode }) => {
|
|
75
|
+
known = true
|
|
76
|
+
return statusCode === 200 || statusCode >= 300
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (!isUnknownBundleIdError(error)) {
|
|
81
|
+
throw error
|
|
82
|
+
}
|
|
83
|
+
// MetaMask removes a single-call bundle in this way only before it sends
|
|
84
|
+
// it. The SDK treats the bundle as never sent: a final rejection, so
|
|
85
|
+
// "Try again" signs anew.
|
|
86
|
+
if (known && callCount === 1 && isWithinDropWindow(signedAt)) {
|
|
87
|
+
throw new TransactionError(
|
|
88
|
+
LiFiErrorCode.SignatureRejected,
|
|
89
|
+
'The wallet has no record of the call bundle. The SDK treats it as never sent.',
|
|
90
|
+
error as Error,
|
|
91
|
+
{ final: true }
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
// Unknown from the first answer (a reload after the reject, another
|
|
95
|
+
// wallet), too long after signing, or no stored count of one call (two
|
|
96
|
+
// or more calls, or a route stored without the count): the bundle may
|
|
97
|
+
// still land.
|
|
98
|
+
throw new TransactionError(
|
|
99
|
+
LiFiErrorCode.CallBundleNotFound,
|
|
100
|
+
'The wallet has no record of the call bundle.',
|
|
101
|
+
error as Error
|
|
102
|
+
)
|
|
103
|
+
}
|
|
20
104
|
|
|
21
105
|
if (result.status === 'success') {
|
|
22
106
|
if (result.receipts?.some((receipt) => receipt.status === 'reverted')) {
|
|
@@ -37,19 +37,23 @@ export class EthereumBatchedWaitForTransactionTask extends BaseStepExecutionTask
|
|
|
37
37
|
const transactionReceipt = await waitForBatchTransactionReceipt(
|
|
38
38
|
updatedClient,
|
|
39
39
|
action.taskId as Hash,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
{
|
|
41
|
+
onFailed: (result) => {
|
|
42
|
+
const receipt = result.receipts?.find(
|
|
43
|
+
(r) => r.status === 'reverted'
|
|
44
|
+
) as WalletCallReceipt | undefined
|
|
45
|
+
if (receipt) {
|
|
46
|
+
updateActionWithReceipt(
|
|
47
|
+
statusManager,
|
|
48
|
+
step,
|
|
49
|
+
fromChain,
|
|
50
|
+
receipt,
|
|
51
|
+
action
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
signedAt: step.execution?.signedAt,
|
|
56
|
+
callCount: action.callCount,
|
|
53
57
|
}
|
|
54
58
|
)
|
|
55
59
|
|
|
@@ -52,15 +52,19 @@ const handleSpecificErrors = async (
|
|
|
52
52
|
) => {
|
|
53
53
|
if (
|
|
54
54
|
e.name === 'UserRejectedRequestError' ||
|
|
55
|
-
e.cause?.name === 'UserRejectedRequestError'
|
|
56
|
-
/**
|
|
57
|
-
* This error is specific to MetaMask and thrown when the user rejects the signature of the native token transfer, at that point, the bundle id is unknown.
|
|
58
|
-
* @see https://github.com/MetaMask/metamask-extension/blob/main/app/scripts/lib/transaction/eip5792.ts#L141-L146
|
|
59
|
-
*/
|
|
60
|
-
e.name === 'UnknownBundleIdError'
|
|
55
|
+
e.cause?.name === 'UserRejectedRequestError'
|
|
61
56
|
) {
|
|
62
57
|
return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)
|
|
63
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* The wallet has no record of an EIP-5792 bundle (5730), so the outcome is unknown: the bundle may still land.
|
|
61
|
+
* No call reaches this branch today, because `waitForBatchTransactionReceipt` handles 5730 first. A later call that reaches it gets the unknown outcome.
|
|
62
|
+
* Only the error itself matches: an error of the batched wait carries it as a cause and keeps its own code.
|
|
63
|
+
* @see https://github.com/MetaMask/core/blob/main/packages/eip-5792-middleware/src/hooks/getCallsStatus.ts
|
|
64
|
+
*/
|
|
65
|
+
if (e.name === 'UnknownBundleIdError') {
|
|
66
|
+
return new TransactionError(LiFiErrorCode.CallBundleNotFound, e.message, e)
|
|
67
|
+
}
|
|
64
68
|
/**
|
|
65
69
|
* Safe Wallet via WalletConnect returns -32000 code when user rejects the signature
|
|
66
70
|
* {
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk-provider-ethereum'
|
|
2
|
-
export const version = '4.2.
|
|
2
|
+
export const version = '4.2.9'
|