@lifi/sdk 4.10.0 → 4.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/README.md +9 -0
- package/dist/cjs/client/createClient.js +6 -4
- package/dist/cjs/client/createClient.js.map +1 -1
- package/dist/cjs/client/findProvider.d.ts +10 -0
- package/dist/cjs/client/findProvider.js +11 -0
- package/dist/cjs/client/findProvider.js.map +1 -0
- package/dist/cjs/core/BaseStepExecutor.d.ts +1 -1
- package/dist/cjs/core/BaseStepExecutor.js +21 -9
- package/dist/cjs/core/BaseStepExecutor.js.map +1 -1
- package/dist/cjs/core/StatusManager.d.ts +10 -0
- package/dist/cjs/core/StatusManager.js +105 -3
- package/dist/cjs/core/StatusManager.js.map +1 -1
- package/dist/cjs/core/execution.js +30 -14
- package/dist/cjs/core/execution.js.map +1 -1
- package/dist/cjs/core/executionState.d.ts +34 -2
- package/dist/cjs/core/executionState.js +44 -1
- package/dist/cjs/core/executionState.js.map +1 -1
- package/dist/cjs/core/prepareRestart.js +14 -6
- package/dist/cjs/core/prepareRestart.js.map +1 -1
- package/dist/cjs/core/tasks/WaitForTransactionStatusTask.js +4 -2
- package/dist/cjs/core/tasks/WaitForTransactionStatusTask.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/getStepStatusRequest.d.ts +10 -0
- package/dist/cjs/core/tasks/helpers/getStepStatusRequest.js +20 -0
- package/dist/cjs/core/tasks/helpers/getStepStatusRequest.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/isKnownToStatusApi.d.ts +21 -0
- package/dist/cjs/core/tasks/helpers/isKnownToStatusApi.js +44 -0
- package/dist/cjs/core/tasks/helpers/isKnownToStatusApi.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.d.ts +22 -1
- package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.js +76 -17
- package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.js.map +1 -1
- package/dist/cjs/core/transactionState.d.ts +121 -0
- package/dist/cjs/core/transactionState.js +164 -0
- package/dist/cjs/core/transactionState.js.map +1 -0
- package/dist/cjs/errors/errors.d.ts +13 -2
- package/dist/cjs/errors/errors.js +5 -2
- package/dist/cjs/errors/errors.js.map +1 -1
- package/dist/cjs/index.d.ts +5 -2
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/types/core.d.ts +49 -3
- package/dist/cjs/types/execution.d.ts +8 -0
- package/dist/cjs/utils/checkPackageUpdates.js +1 -1
- package/dist/cjs/utils/waitForResult.d.ts +3 -1
- package/dist/cjs/utils/waitForResult.js +15 -10
- package/dist/cjs/utils/waitForResult.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/getRoutes.d.ts.map +1 -1
- package/dist/esm/actions/index.d.ts.map +1 -1
- package/dist/esm/client/createClient.d.ts.map +1 -1
- package/dist/esm/client/createClient.js +6 -4
- package/dist/esm/client/createClient.js.map +1 -1
- package/dist/esm/client/findProvider.d.ts +10 -0
- package/dist/esm/client/findProvider.d.ts.map +1 -0
- package/dist/esm/client/findProvider.js +10 -0
- package/dist/esm/client/findProvider.js.map +1 -0
- package/dist/esm/core/BaseStepExecutor.d.ts +1 -1
- package/dist/esm/core/BaseStepExecutor.d.ts.map +1 -1
- package/dist/esm/core/BaseStepExecutor.js +22 -10
- package/dist/esm/core/BaseStepExecutor.js.map +1 -1
- package/dist/esm/core/StatusManager.d.ts +10 -0
- package/dist/esm/core/StatusManager.d.ts.map +1 -1
- package/dist/esm/core/StatusManager.js +105 -3
- package/dist/esm/core/StatusManager.js.map +1 -1
- package/dist/esm/core/execution.d.ts.map +1 -1
- package/dist/esm/core/execution.js +30 -14
- package/dist/esm/core/execution.js.map +1 -1
- package/dist/esm/core/executionState.d.ts +34 -2
- package/dist/esm/core/executionState.d.ts.map +1 -1
- package/dist/esm/core/executionState.js +44 -1
- package/dist/esm/core/executionState.js.map +1 -1
- package/dist/esm/core/prepareRestart.d.ts.map +1 -1
- package/dist/esm/core/prepareRestart.js +14 -6
- package/dist/esm/core/prepareRestart.js.map +1 -1
- package/dist/esm/core/tasks/WaitForTransactionStatusTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/WaitForTransactionStatusTask.js +4 -2
- package/dist/esm/core/tasks/WaitForTransactionStatusTask.js.map +1 -1
- package/dist/esm/core/tasks/helpers/getStepStatusRequest.d.ts +10 -0
- package/dist/esm/core/tasks/helpers/getStepStatusRequest.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/getStepStatusRequest.js +19 -0
- package/dist/esm/core/tasks/helpers/getStepStatusRequest.js.map +1 -0
- package/dist/esm/core/tasks/helpers/isKnownToStatusApi.d.ts +21 -0
- package/dist/esm/core/tasks/helpers/isKnownToStatusApi.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/isKnownToStatusApi.js +43 -0
- package/dist/esm/core/tasks/helpers/isKnownToStatusApi.js.map +1 -0
- package/dist/esm/core/tasks/helpers/waitForTransactionStatus.d.ts +22 -1
- package/dist/esm/core/tasks/helpers/waitForTransactionStatus.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/waitForTransactionStatus.js +76 -18
- package/dist/esm/core/tasks/helpers/waitForTransactionStatus.js.map +1 -1
- package/dist/esm/core/transactionState.d.ts +121 -0
- package/dist/esm/core/transactionState.d.ts.map +1 -0
- package/dist/esm/core/transactionState.js +152 -0
- package/dist/esm/core/transactionState.js.map +1 -0
- package/dist/esm/errors/errors.d.ts +13 -2
- package/dist/esm/errors/errors.d.ts.map +1 -1
- package/dist/esm/errors/errors.js +5 -2
- package/dist/esm/errors/errors.js.map +1 -1
- package/dist/esm/index.d.ts +5 -2
- package/dist/esm/index.js +4 -1
- package/dist/esm/types/actions.d.ts.map +1 -1
- package/dist/esm/types/core.d.ts +49 -3
- package/dist/esm/types/core.d.ts.map +1 -1
- package/dist/esm/types/execution.d.ts +8 -0
- package/dist/esm/types/execution.d.ts.map +1 -1
- package/dist/esm/utils/checkPackageUpdates.js +1 -1
- package/dist/esm/utils/waitForResult.d.ts +3 -1
- package/dist/esm/utils/waitForResult.d.ts.map +1 -1
- package/dist/esm/utils/waitForResult.js +15 -10
- package/dist/esm/utils/waitForResult.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/client/createClient.ts +12 -4
- package/src/client/findProvider.ts +21 -0
- package/src/core/BaseStepExecutor.ts +40 -6
- package/src/core/StatusManager.ts +211 -2
- package/src/core/execution.ts +69 -20
- package/src/core/executionState.ts +84 -1
- package/src/core/prepareRestart.ts +29 -13
- package/src/core/tasks/WaitForTransactionStatusTask.ts +10 -1
- package/src/core/tasks/helpers/getStepStatusRequest.ts +20 -0
- package/src/core/tasks/helpers/isKnownToStatusApi.ts +57 -0
- package/src/core/tasks/helpers/waitForTransactionStatus.ts +128 -17
- package/src/core/transactionState.ts +194 -0
- package/src/errors/errors.ts +21 -2
- package/src/index.ts +14 -0
- package/src/types/core.ts +50 -3
- package/src/types/execution.ts +8 -0
- package/src/utils/waitForResult.ts +16 -6
- package/src/version.ts +1 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { ExecutionAction, ExecutionActionType, LiFiStepExtended } from "../types/core.js";
|
|
2
|
+
import { TransactionError } from "../errors/errors.js";
|
|
3
|
+
//#region src/core/transactionState.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Action types that carry the step's own transaction.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare const TRANSACTION_ACTION_TYPES: readonly ExecutionActionType[];
|
|
10
|
+
/**
|
|
11
|
+
* Stored bytes on a chain without its own expiry (Sui, Solana with a durable
|
|
12
|
+
* nonce, Bitcoin) are resent only this long after signing. Past it, a page
|
|
13
|
+
* load could otherwise execute a swap on a quote the user no longer expects.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare const MAX_RESEND_AGE_MS = 12e4;
|
|
18
|
+
/**
|
|
19
|
+
* Without an expiry verdict, a signature younger than this is never declared
|
|
20
|
+
* dropped. Solana blockhashes and Tron transactions expire well before it.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare const DROPPED_FALLBACK_AGE_MS = 3e5;
|
|
25
|
+
/**
|
|
26
|
+
* Subtracted from `execution.signedAt` (the device clock) when it anchors a
|
|
27
|
+
* history-coverage check, so a device clock that runs fast cannot make a node
|
|
28
|
+
* look like it covers the signing time when it does not.
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export declare const CLOCK_SKEW_MARGIN_MS = 6e5;
|
|
33
|
+
/**
|
|
34
|
+
* Fields a sign task clears before it writes a new transaction's data, and
|
|
35
|
+
* that re-initializing a final-failed action clears. `taskId` is included: a
|
|
36
|
+
* stale relayed or batched task id would otherwise keep the action open.
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export declare const CLEARED_TRANSACTION_FIELDS: Readonly<Pick<ExecutionAction, "txHash" | "txLink" | "txHex" | "txFinal" | "taskId">>;
|
|
41
|
+
/**
|
|
42
|
+
* True when the action has a transaction to follow, landed or not: a hash, a
|
|
43
|
+
* task id or stored signed bytes, unless the action FAILED with a final
|
|
44
|
+
* outcome. Every resume decision uses this one predicate, so the pipeline
|
|
45
|
+
* selector and the pre-sign guard can never disagree.
|
|
46
|
+
*
|
|
47
|
+
* Resume rules for providers. A step never signs or sends a second
|
|
48
|
+
* transaction while an earlier one can still land:
|
|
49
|
+
* 1. Pick the first task with this predicate: open and DONE, the status
|
|
50
|
+
* wait; open, the provider's wait task; otherwise the first task.
|
|
51
|
+
* 2. In the sign task, call `assertNoOpenTransaction` at the start, right
|
|
52
|
+
* before each wallet call and, where the SDK sends, right after the
|
|
53
|
+
* wallet returns. Write the new data with `CLEARED_TRANSACTION_FIELDS`
|
|
54
|
+
* and `signedAt`.
|
|
55
|
+
* 3. From the last check, nothing awaits until the send or, where the SDK
|
|
56
|
+
* sends signed bytes, until they are stored as `txHex`, before the first
|
|
57
|
+
* send. Clear `txHex` only when the outcome is known, no node can still
|
|
58
|
+
* hold the bytes, or they no longer decode.
|
|
59
|
+
* 4. A resume never signs. It looks the transaction up and resends the
|
|
60
|
+
* stored bytes only while `isResendAllowed` (or the chain's own expiry)
|
|
61
|
+
* allows it; otherwise it only waits.
|
|
62
|
+
* 5. Mark an error final only on a verdict about the transaction: failed
|
|
63
|
+
* or reverted (on chain or at the relayer), cancelled, replaced, or
|
|
64
|
+
* dropped with proof. Dropped needs all three: the transaction can no
|
|
65
|
+
* longer land, a node that covers its window reports it absent (in the
|
|
66
|
+
* same response where the chain allows it), and `isKnownToStatusApi` is
|
|
67
|
+
* false. In doubt, throw without the marker and keep the fields.
|
|
68
|
+
* 6. Give `context.signal` only to waits that start after the broadcast. On
|
|
69
|
+
* abort, return `PAUSED` and write nothing.
|
|
70
|
+
*/
|
|
71
|
+
export declare function hasOpenTransaction(action?: ExecutionAction): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* True when any SWAP / CROSS_CHAIN action of the step has an open transaction.
|
|
74
|
+
*
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
export declare function hasStepOpenTransaction(step: LiFiStepExtended): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Walks the error and its `cause` chain. Parsers may rebuild errors, so the
|
|
80
|
+
* marker is read from the original error. A property check instead of
|
|
81
|
+
* `instanceof` keeps it working across duplicated installs.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
export declare function isFinalTransactionError(error: unknown): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* The error of a step that would sign a second transaction while its first
|
|
88
|
+
* one may still land.
|
|
89
|
+
*
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
export declare function transactionConflictError(): TransactionError;
|
|
93
|
+
/**
|
|
94
|
+
* Called first in every sign task. With correct pipeline selectors it never
|
|
95
|
+
* throws; it stops a second signature if a selector ever routes an open
|
|
96
|
+
* transaction back to signing. Every sign task calls it again on the freshly
|
|
97
|
+
* found action right before its wallet call: a late write of an older run can
|
|
98
|
+
* merge a transaction into the action during the awaits in between. A sign
|
|
99
|
+
* task that sends the transaction itself calls it once more after the wallet
|
|
100
|
+
* returns, before it writes or sends anything: the merge can also land while
|
|
101
|
+
* the prompt is open.
|
|
102
|
+
*
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
export declare function assertNoOpenTransaction(action?: ExecutionAction): void;
|
|
106
|
+
/**
|
|
107
|
+
* Unknown signing time never allows a resend. Nor does a signing time in the
|
|
108
|
+
* future: a device clock that ran ahead at signing and was corrected later
|
|
109
|
+
* would otherwise stretch the cap by the clock error.
|
|
110
|
+
*
|
|
111
|
+
* @internal
|
|
112
|
+
*/
|
|
113
|
+
export declare function isResendAllowed(signedAt: number | undefined, now?: number): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Unknown signing time never allows a drop.
|
|
116
|
+
*
|
|
117
|
+
* @internal
|
|
118
|
+
*/
|
|
119
|
+
export declare function isOldEnoughToDrop(signedAt: number | undefined, now?: number): boolean;
|
|
120
|
+
//#endregion
|
|
121
|
+
//# sourceMappingURL=transactionState.d.ts.map
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../errors/constants.js");
|
|
3
|
+
const require_errors_errors = require("../errors/errors.js");
|
|
4
|
+
//#region src/core/transactionState.ts
|
|
5
|
+
/**
|
|
6
|
+
* Action types that carry the step's own transaction.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
const TRANSACTION_ACTION_TYPES = ["SWAP", "CROSS_CHAIN"];
|
|
11
|
+
/**
|
|
12
|
+
* Stored bytes on a chain without its own expiry (Sui, Solana with a durable
|
|
13
|
+
* nonce, Bitcoin) are resent only this long after signing. Past it, a page
|
|
14
|
+
* load could otherwise execute a swap on a quote the user no longer expects.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
const MAX_RESEND_AGE_MS = 12e4;
|
|
19
|
+
/**
|
|
20
|
+
* Without an expiry verdict, a signature younger than this is never declared
|
|
21
|
+
* dropped. Solana blockhashes and Tron transactions expire well before it.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
const DROPPED_FALLBACK_AGE_MS = 3e5;
|
|
26
|
+
/**
|
|
27
|
+
* Subtracted from `execution.signedAt` (the device clock) when it anchors a
|
|
28
|
+
* history-coverage check, so a device clock that runs fast cannot make a node
|
|
29
|
+
* look like it covers the signing time when it does not.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
const CLOCK_SKEW_MARGIN_MS = 6e5;
|
|
34
|
+
/**
|
|
35
|
+
* Fields a sign task clears before it writes a new transaction's data, and
|
|
36
|
+
* that re-initializing a final-failed action clears. `taskId` is included: a
|
|
37
|
+
* stale relayed or batched task id would otherwise keep the action open.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
const CLEARED_TRANSACTION_FIELDS = Object.freeze({
|
|
42
|
+
txHash: void 0,
|
|
43
|
+
txLink: void 0,
|
|
44
|
+
txHex: void 0,
|
|
45
|
+
txFinal: void 0,
|
|
46
|
+
taskId: void 0
|
|
47
|
+
});
|
|
48
|
+
/**
|
|
49
|
+
* True when the action has a transaction to follow, landed or not: a hash, a
|
|
50
|
+
* task id or stored signed bytes, unless the action FAILED with a final
|
|
51
|
+
* outcome. Every resume decision uses this one predicate, so the pipeline
|
|
52
|
+
* selector and the pre-sign guard can never disagree.
|
|
53
|
+
*
|
|
54
|
+
* Resume rules for providers. A step never signs or sends a second
|
|
55
|
+
* transaction while an earlier one can still land:
|
|
56
|
+
* 1. Pick the first task with this predicate: open and DONE, the status
|
|
57
|
+
* wait; open, the provider's wait task; otherwise the first task.
|
|
58
|
+
* 2. In the sign task, call `assertNoOpenTransaction` at the start, right
|
|
59
|
+
* before each wallet call and, where the SDK sends, right after the
|
|
60
|
+
* wallet returns. Write the new data with `CLEARED_TRANSACTION_FIELDS`
|
|
61
|
+
* and `signedAt`.
|
|
62
|
+
* 3. From the last check, nothing awaits until the send or, where the SDK
|
|
63
|
+
* sends signed bytes, until they are stored as `txHex`, before the first
|
|
64
|
+
* send. Clear `txHex` only when the outcome is known, no node can still
|
|
65
|
+
* hold the bytes, or they no longer decode.
|
|
66
|
+
* 4. A resume never signs. It looks the transaction up and resends the
|
|
67
|
+
* stored bytes only while `isResendAllowed` (or the chain's own expiry)
|
|
68
|
+
* allows it; otherwise it only waits.
|
|
69
|
+
* 5. Mark an error final only on a verdict about the transaction: failed
|
|
70
|
+
* or reverted (on chain or at the relayer), cancelled, replaced, or
|
|
71
|
+
* dropped with proof. Dropped needs all three: the transaction can no
|
|
72
|
+
* longer land, a node that covers its window reports it absent (in the
|
|
73
|
+
* same response where the chain allows it), and `isKnownToStatusApi` is
|
|
74
|
+
* false. In doubt, throw without the marker and keep the fields.
|
|
75
|
+
* 6. Give `context.signal` only to waits that start after the broadcast. On
|
|
76
|
+
* abort, return `PAUSED` and write nothing.
|
|
77
|
+
*/
|
|
78
|
+
function hasOpenTransaction(action) {
|
|
79
|
+
if (!action) return false;
|
|
80
|
+
if (!(action.txHash || action.taskId || action.txHex)) return false;
|
|
81
|
+
return !(action.status === "FAILED" && action.txFinal === true);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* True when any SWAP / CROSS_CHAIN action of the step has an open transaction.
|
|
85
|
+
*
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
function hasStepOpenTransaction(step) {
|
|
89
|
+
return !!step.execution?.actions?.some((action) => TRANSACTION_ACTION_TYPES.includes(action.type) && hasOpenTransaction(action));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Walks the error and its `cause` chain. Parsers may rebuild errors, so the
|
|
93
|
+
* marker is read from the original error. A property check instead of
|
|
94
|
+
* `instanceof` keeps it working across duplicated installs.
|
|
95
|
+
*
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
98
|
+
function isFinalTransactionError(error) {
|
|
99
|
+
const seen = /* @__PURE__ */ new Set();
|
|
100
|
+
let current = error;
|
|
101
|
+
while (current && typeof current === "object" && !seen.has(current)) {
|
|
102
|
+
seen.add(current);
|
|
103
|
+
if (current.final === true) return true;
|
|
104
|
+
current = current.cause;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The error of a step that would sign a second transaction while its first
|
|
110
|
+
* one may still land.
|
|
111
|
+
*
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
114
|
+
function transactionConflictError() {
|
|
115
|
+
return new require_errors_errors.TransactionError(1020, "A transaction for this step was already signed and may still land. Resume the route to wait for it instead of signing a new one.");
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Called first in every sign task. With correct pipeline selectors it never
|
|
119
|
+
* throws; it stops a second signature if a selector ever routes an open
|
|
120
|
+
* transaction back to signing. Every sign task calls it again on the freshly
|
|
121
|
+
* found action right before its wallet call: a late write of an older run can
|
|
122
|
+
* merge a transaction into the action during the awaits in between. A sign
|
|
123
|
+
* task that sends the transaction itself calls it once more after the wallet
|
|
124
|
+
* returns, before it writes or sends anything: the merge can also land while
|
|
125
|
+
* the prompt is open.
|
|
126
|
+
*
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
function assertNoOpenTransaction(action) {
|
|
130
|
+
if (hasOpenTransaction(action)) throw transactionConflictError();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Unknown signing time never allows a resend. Nor does a signing time in the
|
|
134
|
+
* future: a device clock that ran ahead at signing and was corrected later
|
|
135
|
+
* would otherwise stretch the cap by the clock error.
|
|
136
|
+
*
|
|
137
|
+
* @internal
|
|
138
|
+
*/
|
|
139
|
+
function isResendAllowed(signedAt, now = Date.now()) {
|
|
140
|
+
return signedAt !== void 0 && now >= signedAt && now - signedAt < 12e4;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Unknown signing time never allows a drop.
|
|
144
|
+
*
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
147
|
+
function isOldEnoughToDrop(signedAt, now = Date.now()) {
|
|
148
|
+
return signedAt !== void 0 && now - signedAt > 3e5;
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
exports.CLEARED_TRANSACTION_FIELDS = CLEARED_TRANSACTION_FIELDS;
|
|
152
|
+
exports.CLOCK_SKEW_MARGIN_MS = CLOCK_SKEW_MARGIN_MS;
|
|
153
|
+
exports.DROPPED_FALLBACK_AGE_MS = DROPPED_FALLBACK_AGE_MS;
|
|
154
|
+
exports.MAX_RESEND_AGE_MS = MAX_RESEND_AGE_MS;
|
|
155
|
+
exports.TRANSACTION_ACTION_TYPES = TRANSACTION_ACTION_TYPES;
|
|
156
|
+
exports.assertNoOpenTransaction = assertNoOpenTransaction;
|
|
157
|
+
exports.hasOpenTransaction = hasOpenTransaction;
|
|
158
|
+
exports.hasStepOpenTransaction = hasStepOpenTransaction;
|
|
159
|
+
exports.isFinalTransactionError = isFinalTransactionError;
|
|
160
|
+
exports.isOldEnoughToDrop = isOldEnoughToDrop;
|
|
161
|
+
exports.isResendAllowed = isResendAllowed;
|
|
162
|
+
exports.transactionConflictError = transactionConflictError;
|
|
163
|
+
|
|
164
|
+
//# sourceMappingURL=transactionState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactionState.js","names":["TransactionError"],"sources":["../../../src/core/transactionState.ts"],"sourcesContent":["import { LiFiErrorCode } from '../errors/constants.js'\nimport { TransactionError } from '../errors/errors.js'\nimport type {\n ExecutionAction,\n ExecutionActionType,\n LiFiStepExtended,\n} from '../types/core.js'\n\n/**\n * Action types that carry the step's own transaction.\n *\n * @internal\n */\nexport const TRANSACTION_ACTION_TYPES: readonly ExecutionActionType[] = [\n 'SWAP',\n 'CROSS_CHAIN',\n]\n\n/**\n * Stored bytes on a chain without its own expiry (Sui, Solana with a durable\n * nonce, Bitcoin) are resent only this long after signing. Past it, a page\n * load could otherwise execute a swap on a quote the user no longer expects.\n *\n * @internal\n */\nexport const MAX_RESEND_AGE_MS = 120_000\n\n/**\n * Without an expiry verdict, a signature younger than this is never declared\n * dropped. Solana blockhashes and Tron transactions expire well before it.\n *\n * @internal\n */\nexport const DROPPED_FALLBACK_AGE_MS = 300_000\n\n/**\n * Subtracted from `execution.signedAt` (the device clock) when it anchors a\n * history-coverage check, so a device clock that runs fast cannot make a node\n * look like it covers the signing time when it does not.\n *\n * @internal\n */\nexport const CLOCK_SKEW_MARGIN_MS = 600_000\n\n/**\n * Fields a sign task clears before it writes a new transaction's data, and\n * that re-initializing a final-failed action clears. `taskId` is included: a\n * stale relayed or batched task id would otherwise keep the action open.\n *\n * @internal\n */\nexport const CLEARED_TRANSACTION_FIELDS: Readonly<\n Pick<ExecutionAction, 'txHash' | 'txLink' | 'txHex' | 'txFinal' | 'taskId'>\n> = Object.freeze({\n txHash: undefined,\n txLink: undefined,\n txHex: undefined,\n txFinal: undefined,\n taskId: undefined,\n})\n\n/**\n * True when the action has a transaction to follow, landed or not: a hash, a\n * task id or stored signed bytes, unless the action FAILED with a final\n * outcome. Every resume decision uses this one predicate, so the pipeline\n * selector and the pre-sign guard can never disagree.\n *\n * Resume rules for providers. A step never signs or sends a second\n * transaction while an earlier one can still land:\n * 1. Pick the first task with this predicate: open and DONE, the status\n * wait; open, the provider's wait task; otherwise the first task.\n * 2. In the sign task, call `assertNoOpenTransaction` at the start, right\n * before each wallet call and, where the SDK sends, right after the\n * wallet returns. Write the new data with `CLEARED_TRANSACTION_FIELDS`\n * and `signedAt`.\n * 3. From the last check, nothing awaits until the send or, where the SDK\n * sends signed bytes, until they are stored as `txHex`, before the first\n * send. Clear `txHex` only when the outcome is known, no node can still\n * hold the bytes, or they no longer decode.\n * 4. A resume never signs. It looks the transaction up and resends the\n * stored bytes only while `isResendAllowed` (or the chain's own expiry)\n * allows it; otherwise it only waits.\n * 5. Mark an error final only on a verdict about the transaction: failed\n * or reverted (on chain or at the relayer), cancelled, replaced, or\n * dropped with proof. Dropped needs all three: the transaction can no\n * longer land, a node that covers its window reports it absent (in the\n * same response where the chain allows it), and `isKnownToStatusApi` is\n * false. In doubt, throw without the marker and keep the fields.\n * 6. Give `context.signal` only to waits that start after the broadcast. On\n * abort, return `PAUSED` and write nothing.\n */\nexport function hasOpenTransaction(action?: ExecutionAction): boolean {\n if (!action) {\n return false\n }\n if (!(action.txHash || action.taskId || action.txHex)) {\n return false\n }\n return !(action.status === 'FAILED' && action.txFinal === true)\n}\n\n/**\n * True when any SWAP / CROSS_CHAIN action of the step has an open transaction.\n *\n * @internal\n */\nexport function hasStepOpenTransaction(step: LiFiStepExtended): boolean {\n return !!step.execution?.actions?.some(\n (action) =>\n TRANSACTION_ACTION_TYPES.includes(action.type) &&\n hasOpenTransaction(action)\n )\n}\n\n/**\n * Walks the error and its `cause` chain. Parsers may rebuild errors, so the\n * marker is read from the original error. A property check instead of\n * `instanceof` keeps it working across duplicated installs.\n *\n * @internal\n */\nexport function isFinalTransactionError(error: unknown): boolean {\n const seen = new Set<unknown>()\n let current: unknown = error\n while (current && typeof current === 'object' && !seen.has(current)) {\n seen.add(current)\n if ((current as { final?: unknown }).final === true) {\n return true\n }\n current = (current as { cause?: unknown }).cause\n }\n return false\n}\n\n/**\n * The error of a step that would sign a second transaction while its first\n * one may still land.\n *\n * @internal\n */\nexport function transactionConflictError(): TransactionError {\n return new TransactionError(\n LiFiErrorCode.TransactionConflict,\n 'A transaction for this step was already signed and may still land. Resume the route to wait for it instead of signing a new one.'\n )\n}\n\n/**\n * Called first in every sign task. With correct pipeline selectors it never\n * throws; it stops a second signature if a selector ever routes an open\n * transaction back to signing. Every sign task calls it again on the freshly\n * found action right before its wallet call: a late write of an older run can\n * merge a transaction into the action during the awaits in between. A sign\n * task that sends the transaction itself calls it once more after the wallet\n * returns, before it writes or sends anything: the merge can also land while\n * the prompt is open.\n *\n * @internal\n */\nexport function assertNoOpenTransaction(action?: ExecutionAction): void {\n if (hasOpenTransaction(action)) {\n throw transactionConflictError()\n }\n}\n\n/**\n * Unknown signing time never allows a resend. Nor does a signing time in the\n * future: a device clock that ran ahead at signing and was corrected later\n * would otherwise stretch the cap by the clock error.\n *\n * @internal\n */\nexport function isResendAllowed(\n signedAt: number | undefined,\n now: number = Date.now()\n): boolean {\n return (\n signedAt !== undefined &&\n now >= signedAt &&\n now - signedAt < MAX_RESEND_AGE_MS\n )\n}\n\n/**\n * Unknown signing time never allows a drop.\n *\n * @internal\n */\nexport function isOldEnoughToDrop(\n signedAt: number | undefined,\n now: number = Date.now()\n): boolean {\n return signedAt !== undefined && now - signedAt > DROPPED_FALLBACK_AGE_MS\n}\n"],"mappings":";;;;;;;;;AAaA,MAAa,2BAA2D,CACtE,QACA,aACF;;;;;;;;AASA,MAAa,oBAAoB;;;;;;;AAQjC,MAAa,0BAA0B;;;;;;;;AASvC,MAAa,uBAAuB;;;;;;;;AASpC,MAAa,6BAET,OAAO,OAAO;CAChB,QAAQ,KAAA;CACR,QAAQ,KAAA;CACR,OAAO,KAAA;CACP,SAAS,KAAA;CACT,QAAQ,KAAA;AACV,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCD,SAAgB,mBAAmB,QAAmC;CACpE,IAAI,CAAC,QACH,OAAO;CAET,IAAI,EAAE,OAAO,UAAU,OAAO,UAAU,OAAO,QAC7C,OAAO;CAET,OAAO,EAAE,OAAO,WAAW,YAAY,OAAO,YAAY;AAC5D;;;;;;AAOA,SAAgB,uBAAuB,MAAiC;CACtE,OAAO,CAAC,CAAC,KAAK,WAAW,SAAS,MAC/B,WACC,yBAAyB,SAAS,OAAO,IAAI,KAC7C,mBAAmB,MAAM,CAC7B;AACF;;;;;;;;AASA,SAAgB,wBAAwB,OAAyB;CAC/D,MAAM,uBAAO,IAAI,IAAa;CAC9B,IAAI,UAAmB;CACvB,OAAO,WAAW,OAAO,YAAY,YAAY,CAAC,KAAK,IAAI,OAAO,GAAG;EACnE,KAAK,IAAI,OAAO;EAChB,IAAK,QAAgC,UAAU,MAC7C,OAAO;EAET,UAAW,QAAgC;CAC7C;CACA,OAAO;AACT;;;;;;;AAQA,SAAgB,2BAA6C;CAC3D,OAAO,IAAIA,sBAAAA,iBAAAA,MAET,kIACF;AACF;;;;;;;;;;;;;AAcA,SAAgB,wBAAwB,QAAgC;CACtE,IAAI,mBAAmB,MAAM,GAC3B,MAAM,yBAAyB;AAEnC;;;;;;;;AASA,SAAgB,gBACd,UACA,MAAc,KAAK,IAAI,GACd;CACT,OACE,aAAa,KAAA,KACb,OAAO,YACP,MAAM,WAAA;AAEV;;;;;;AAOA,SAAgB,kBACd,UACA,MAAc,KAAK,IAAI,GACd;CACT,OAAO,aAAa,KAAA,KAAa,MAAM,WAAA;AACzC"}
|
|
@@ -8,8 +8,18 @@ export declare class RPCError extends BaseError {
|
|
|
8
8
|
export declare class ProviderError extends BaseError {
|
|
9
9
|
constructor(code: LiFiErrorCode, message: string, cause?: Error);
|
|
10
10
|
}
|
|
11
|
+
export interface TransactionErrorOptions {
|
|
12
|
+
/**
|
|
13
|
+
* A definite verdict about the transaction (failed or reverted on chain or
|
|
14
|
+
* at the relayer, cancelled, replaced, or dropped with proof). The step
|
|
15
|
+
* executor then flags the failed action with `txFinal`, so a restart signs
|
|
16
|
+
* a new transaction.
|
|
17
|
+
*/
|
|
18
|
+
final?: boolean;
|
|
19
|
+
}
|
|
11
20
|
export declare class TransactionError extends BaseError {
|
|
12
|
-
|
|
21
|
+
readonly final: boolean;
|
|
22
|
+
constructor(code: LiFiErrorCode, message: string, cause?: Error, options?: TransactionErrorOptions);
|
|
13
23
|
}
|
|
14
24
|
export declare class UnknownError extends BaseError {
|
|
15
25
|
constructor(message: string, cause?: Error);
|
|
@@ -26,7 +36,8 @@ export declare class ValidationError extends BaseError {
|
|
|
26
36
|
/**
|
|
27
37
|
* Thrown by a step executor when executeStep should be retried with the given params
|
|
28
38
|
* (e.g. wallet rejected 7702 upgrade → retry with atomicityNotReady).
|
|
29
|
-
* The execution layer catches this and retries executeStep(client, step, retryParams)
|
|
39
|
+
* The execution layer catches this and retries executeStep(client, step, retryParams),
|
|
40
|
+
* unless the route was stopped or the step has an open transaction.
|
|
30
41
|
*/
|
|
31
42
|
export declare class ExecuteStepRetryError extends BaseError {
|
|
32
43
|
readonly retryParams: ExecuteStepRetryParams;
|
|
@@ -13,8 +13,10 @@ var ProviderError = class extends require_errors_baseError.BaseError {
|
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
var TransactionError = class extends require_errors_baseError.BaseError {
|
|
16
|
-
|
|
16
|
+
final;
|
|
17
|
+
constructor(code, message, cause, options) {
|
|
17
18
|
super("TransactionError", code, message, cause);
|
|
19
|
+
this.final = options?.final ?? false;
|
|
18
20
|
}
|
|
19
21
|
};
|
|
20
22
|
var UnknownError = class extends require_errors_baseError.BaseError {
|
|
@@ -40,7 +42,8 @@ var ValidationError = class extends require_errors_baseError.BaseError {
|
|
|
40
42
|
/**
|
|
41
43
|
* Thrown by a step executor when executeStep should be retried with the given params
|
|
42
44
|
* (e.g. wallet rejected 7702 upgrade → retry with atomicityNotReady).
|
|
43
|
-
* The execution layer catches this and retries executeStep(client, step, retryParams)
|
|
45
|
+
* The execution layer catches this and retries executeStep(client, step, retryParams),
|
|
46
|
+
* unless the route was stopped or the step has an open transaction.
|
|
44
47
|
*/
|
|
45
48
|
var ExecuteStepRetryError = class extends require_errors_baseError.BaseError {
|
|
46
49
|
retryParams;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":["BaseError"],"sources":["../../../src/errors/errors.ts"],"sourcesContent":["import type { ExecuteStepRetryParams } from '../types/core.js'\nimport { BaseError } from './baseError.js'\nimport { ErrorName, LiFiErrorCode } from './constants.js'\n\nexport class RPCError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.RPCError, code, message, cause)\n }\n}\n\nexport class ProviderError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.ProviderError, code, message, cause)\n }\n}\n\nexport class TransactionError extends BaseError {\n constructor(code: LiFiErrorCode
|
|
1
|
+
{"version":3,"file":"errors.js","names":["BaseError"],"sources":["../../../src/errors/errors.ts"],"sourcesContent":["import type { ExecuteStepRetryParams } from '../types/core.js'\nimport { BaseError } from './baseError.js'\nimport { ErrorName, LiFiErrorCode } from './constants.js'\n\nexport class RPCError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.RPCError, code, message, cause)\n }\n}\n\nexport class ProviderError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.ProviderError, code, message, cause)\n }\n}\n\nexport interface TransactionErrorOptions {\n /**\n * A definite verdict about the transaction (failed or reverted on chain or\n * at the relayer, cancelled, replaced, or dropped with proof). The step\n * executor then flags the failed action with `txFinal`, so a restart signs\n * a new transaction.\n */\n final?: boolean\n}\n\nexport class TransactionError extends BaseError {\n readonly final: boolean\n\n constructor(\n code: LiFiErrorCode,\n message: string,\n cause?: Error,\n options?: TransactionErrorOptions\n ) {\n super(ErrorName.TransactionError, code, message, cause)\n this.final = options?.final ?? false\n }\n}\n\nexport class UnknownError extends BaseError {\n constructor(message: string, cause?: Error) {\n super(ErrorName.UnknownError, LiFiErrorCode.InternalError, message, cause)\n }\n}\n\nexport class BalanceError extends BaseError {\n constructor(message: string, cause?: Error) {\n super(ErrorName.BalanceError, LiFiErrorCode.BalanceError, message, cause)\n }\n}\n\nexport class ServerError extends BaseError {\n constructor(message: string) {\n super(ErrorName.ServerError, LiFiErrorCode.InternalError, message)\n }\n}\n\nexport class ValidationError extends BaseError {\n constructor(message: string) {\n super(ErrorName.ValidationError, LiFiErrorCode.ValidationError, message)\n }\n}\n\n/**\n * Thrown by a step executor when executeStep should be retried with the given params\n * (e.g. wallet rejected 7702 upgrade → retry with atomicityNotReady).\n * The execution layer catches this and retries executeStep(client, step, retryParams),\n * unless the route was stopped or the step has an open transaction.\n */\nexport class ExecuteStepRetryError extends BaseError {\n readonly retryParams: ExecuteStepRetryParams\n\n constructor(\n message: string,\n retryParams: ExecuteStepRetryParams,\n cause?: Error\n ) {\n super(\n ErrorName.ExecuteStepRetryError,\n LiFiErrorCode.InternalError,\n message,\n cause\n )\n this.retryParams = retryParams\n }\n}\n"],"mappings":";;;;AAIA,IAAa,WAAb,cAA8BA,yBAAAA,UAAU;CACtC,YAAY,MAAqB,SAAiB,OAAe;EAC/D,MAAA,YAA0B,MAAM,SAAS,KAAK;CAChD;AACF;AAEA,IAAa,gBAAb,cAAmCA,yBAAAA,UAAU;CAC3C,YAAY,MAAqB,SAAiB,OAAe;EAC/D,MAAA,iBAA+B,MAAM,SAAS,KAAK;CACrD;AACF;AAYA,IAAa,mBAAb,cAAsCA,yBAAAA,UAAU;CAC9C;CAEA,YACE,MACA,SACA,OACA,SACA;EACA,MAAA,oBAAkC,MAAM,SAAS,KAAK;EACtD,KAAK,QAAQ,SAAS,SAAS;CACjC;AACF;AAEA,IAAa,eAAb,cAAkCA,yBAAAA,UAAU;CAC1C,YAAY,SAAiB,OAAe;EAC1C,MAAA,gBAAA,KAA2D,SAAS,KAAK;CAC3E;AACF;AAEA,IAAa,eAAb,cAAkCA,yBAAAA,UAAU;CAC1C,YAAY,SAAiB,OAAe;EAC1C,MAAA,gBAAA,MAA0D,SAAS,KAAK;CAC1E;AACF;AAEA,IAAa,cAAb,cAAiCA,yBAAAA,UAAU;CACzC,YAAY,SAAiB;EAC3B,MAAA,eAAA,KAA0D,OAAO;CACnE;AACF;AAEA,IAAa,kBAAb,cAAqCA,yBAAAA,UAAU;CAC7C,YAAY,SAAiB;EAC3B,MAAA,mBAAA,MAAgE,OAAO;CACzE;AACF;;;;;;;AAQA,IAAa,wBAAb,cAA2CA,yBAAAA,UAAU;CACnD;CAEA,YACE,SACA,aACA,OACA;EACA,MAAA,yBAAA,KAGE,SACA,KACF;EACA,KAAK,cAAc;CACrB;AACF"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -23,12 +23,13 @@ import { patchContractCalls } from "./actions/patchContractCalls.js";
|
|
|
23
23
|
import { actions } from "./actions/index.js";
|
|
24
24
|
import { relayTransaction } from "./actions/relayTransaction.js";
|
|
25
25
|
import { createClient } from "./client/createClient.js";
|
|
26
|
+
import { findProvider } from "./client/findProvider.js";
|
|
26
27
|
import { StatusManager } from "./core/StatusManager.js";
|
|
27
28
|
import { StepExecutorBaseContext, StepExecutorContext, TaskResult, TaskStatus } from "./types/execution.js";
|
|
28
29
|
import { BaseStepExecutionTask } from "./core/BaseStepExecutionTask.js";
|
|
29
30
|
import { ErrorCode, ErrorMessage, ErrorName, LiFiErrorCode } from "./errors/constants.js";
|
|
30
31
|
import { BaseError } from "./errors/baseError.js";
|
|
31
|
-
import { BalanceError, ExecuteStepRetryError, ProviderError, RPCError, ServerError, TransactionError, UnknownError, ValidationError } from "./errors/errors.js";
|
|
32
|
+
import { BalanceError, ExecuteStepRetryError, ProviderError, RPCError, ServerError, TransactionError, TransactionErrorOptions, UnknownError, ValidationError } from "./errors/errors.js";
|
|
32
33
|
import { SDKError } from "./errors/SDKError.js";
|
|
33
34
|
import { TaskPipeline } from "./core/TaskPipeline.js";
|
|
34
35
|
import { BaseStepExecutor } from "./core/BaseStepExecutor.js";
|
|
@@ -39,7 +40,9 @@ import { CheckBalanceTask } from "./core/tasks/CheckBalanceTask.js";
|
|
|
39
40
|
import { PrepareTransactionTask } from "./core/tasks/PrepareTransactionTask.js";
|
|
40
41
|
import { WaitForTransactionStatusTask } from "./core/tasks/WaitForTransactionStatusTask.js";
|
|
41
42
|
import { getTransactionRequestData } from "./core/tasks/helpers/getTransactionRequestData.js";
|
|
43
|
+
import { isKnownToStatusApi } from "./core/tasks/helpers/isKnownToStatusApi.js";
|
|
42
44
|
import { stepComparison } from "./core/tasks/helpers/stepComparison.js";
|
|
45
|
+
import { CLEARED_TRANSACTION_FIELDS, CLOCK_SKEW_MARGIN_MS, DROPPED_FALLBACK_AGE_MS, MAX_RESEND_AGE_MS, assertNoOpenTransaction, hasOpenTransaction, isFinalTransactionError, isOldEnoughToDrop, isResendAllowed } from "./core/transactionState.js";
|
|
43
46
|
import { HTTPError } from "./errors/httpError.js";
|
|
44
47
|
import { checkPackageUpdates } from "./utils/checkPackageUpdates.js";
|
|
45
48
|
import { convertQuoteToRoute } from "./utils/convertQuoteToRoute.js";
|
|
@@ -54,4 +57,4 @@ import { withDedupe } from "./utils/withDedupe.js";
|
|
|
54
57
|
import { withTimeout } from "./utils/withTimeout.js";
|
|
55
58
|
import { name, version } from "./version.js";
|
|
56
59
|
export * from "@lifi/types";
|
|
57
|
-
export { type AcceptExchangeRateUpdateHook, type AcceptSlippageUpdateHook, type AcceptSlippageUpdateHookParams, BalanceError, BaseError, BaseStepExecutionTask, BaseStepExecutor, type CheckBalanceOptions, CheckBalanceTask, type ContractCallParams, type ContractTool, type ErrorCode, ErrorMessage, ErrorName, type ExchangeRateUpdateParams, ExecuteStepRetryError, type ExecuteStepRetryParams, type Execution, type ExecutionAction, type ExecutionActionStatus, type ExecutionActionType, type ExecutionOptions, type ExecutionStatus, type GetContractCallsHook, type GetContractCallsResult, type GetStatusRequestExtended, HTTPError, InMemoryStorage, type InteractionSettings, LiFiErrorCode, type LiFiStepExtended, type LiFiStepRequest, LocalStorageAdapter, LruMap, PrepareTransactionTask, ProviderError, type QuoteRequest, type QuoteRequestFromAmount, type QuoteRequestToAmount, RPCError, type RPCUrls, type RPCUrlsByRole, type RPCUrlsConfig, type RequestInterceptor, type RouteExecutionData, type RouteExecutionDataDictionary, type RouteExecutionDictionary, type RouteExtended, type SDKBaseConfig, type SDKClient, type SDKConfig, SDKError, type SDKProvider, type SDKStorage, ServerError, StatusManager, type StepExecutor, type StepExecutorBaseContext, type StepExecutorContext, type StepExecutorOptions, type StepExtended, TaskPipeline, type TaskResult, type TaskStatus, TransactionError, type TransactionMethodType, type TransactionParameters, type TransactionRequestParameters, type TransactionRequestUpdateHook, UnknownError, type UpdateRouteHook, ValidationError, WaitForTransactionStatusTask, actions, checkBalance, checkPackageUpdates, convertQuoteToRoute, createClient, createDefaultStorage, executeRoute, fetchTxErrorDetails, formatUnits, getActionMessage, getActiveRoute, getActiveRoutes, getChains, getConnections, getContractCallsQuote, getGasRecommendation, getNameServiceAddress, getQuote, getRelayedTransactionStatus, getRelayerQuote, getRoutes, getStatus, getStepTransaction, getSubstatusMessage, getToken, getTokenBalance, getTokenBalances, getTokenBalancesByChain, getTokens, getTools, getTransactionHistory, getTransactionRequestData, isHex, name, parseUnits, patchContractCalls, relayTransaction, resumeRoute, sleep, stepComparison, stopRouteExecution, updateRouteExecution, version, waitForResult, withDedupe, withTimeout };
|
|
60
|
+
export { type AcceptExchangeRateUpdateHook, type AcceptSlippageUpdateHook, type AcceptSlippageUpdateHookParams, BalanceError, BaseError, BaseStepExecutionTask, BaseStepExecutor, CLEARED_TRANSACTION_FIELDS, CLOCK_SKEW_MARGIN_MS, type CheckBalanceOptions, CheckBalanceTask, type ContractCallParams, type ContractTool, DROPPED_FALLBACK_AGE_MS, type ErrorCode, ErrorMessage, ErrorName, type ExchangeRateUpdateParams, ExecuteStepRetryError, type ExecuteStepRetryParams, type Execution, type ExecutionAction, type ExecutionActionStatus, type ExecutionActionType, type ExecutionOptions, type ExecutionStatus, type GetContractCallsHook, type GetContractCallsResult, type GetStatusRequestExtended, HTTPError, InMemoryStorage, type InteractionSettings, LiFiErrorCode, type LiFiStepExtended, type LiFiStepRequest, LocalStorageAdapter, LruMap, MAX_RESEND_AGE_MS, PrepareTransactionTask, ProviderError, type QuoteRequest, type QuoteRequestFromAmount, type QuoteRequestToAmount, RPCError, type RPCUrls, type RPCUrlsByRole, type RPCUrlsConfig, type RequestInterceptor, type RouteExecutionData, type RouteExecutionDataDictionary, type RouteExecutionDictionary, type RouteExtended, type SDKBaseConfig, type SDKClient, type SDKConfig, SDKError, type SDKProvider, type SDKStorage, ServerError, StatusManager, type StepExecutor, type StepExecutorBaseContext, type StepExecutorContext, type StepExecutorOptions, type StepExtended, TaskPipeline, type TaskResult, type TaskStatus, TransactionError, type TransactionErrorOptions, type TransactionMethodType, type TransactionParameters, type TransactionRequestParameters, type TransactionRequestUpdateHook, UnknownError, type UpdateRouteHook, ValidationError, WaitForTransactionStatusTask, actions, assertNoOpenTransaction, checkBalance, checkPackageUpdates, convertQuoteToRoute, createClient, createDefaultStorage, executeRoute, fetchTxErrorDetails, findProvider, formatUnits, getActionMessage, getActiveRoute, getActiveRoutes, getChains, getConnections, getContractCallsQuote, getGasRecommendation, getNameServiceAddress, getQuote, getRelayedTransactionStatus, getRelayerQuote, getRoutes, getStatus, getStepTransaction, getSubstatusMessage, getToken, getTokenBalance, getTokenBalances, getTokenBalancesByChain, getTokens, getTools, getTransactionHistory, getTransactionRequestData, hasOpenTransaction, isFinalTransactionError, isHex, isKnownToStatusApi, isOldEnoughToDrop, isResendAllowed, name, parseUnits, patchContractCalls, relayTransaction, resumeRoute, sleep, stepComparison, stopRouteExecution, updateRouteExecution, version, waitForResult, withDedupe, withTimeout };
|
package/dist/cjs/index.js
CHANGED
|
@@ -30,9 +30,11 @@ const require_actions_patchContractCalls = require("./actions/patchContractCalls
|
|
|
30
30
|
const require_actions_relayTransaction = require("./actions/relayTransaction.js");
|
|
31
31
|
const require_actions_index = require("./actions/index.js");
|
|
32
32
|
const require_utils_checkPackageUpdates = require("./utils/checkPackageUpdates.js");
|
|
33
|
+
const require_client_findProvider = require("./client/findProvider.js");
|
|
33
34
|
const require_client_createClient = require("./client/createClient.js");
|
|
34
35
|
const require_core_actionMessages = require("./core/actionMessages.js");
|
|
35
36
|
const require_core_BaseStepExecutionTask = require("./core/BaseStepExecutionTask.js");
|
|
37
|
+
const require_core_transactionState = require("./core/transactionState.js");
|
|
36
38
|
const require_core_StatusManager = require("./core/StatusManager.js");
|
|
37
39
|
const require_core_BaseStepExecutor = require("./core/BaseStepExecutor.js");
|
|
38
40
|
const require_core_execution = require("./core/execution.js");
|
|
@@ -43,6 +45,7 @@ const require_utils_withTimeout = require("./utils/withTimeout.js");
|
|
|
43
45
|
const require_core_tasks_helpers_checkBalance = require("./core/tasks/helpers/checkBalance.js");
|
|
44
46
|
const require_core_tasks_CheckBalanceTask = require("./core/tasks/CheckBalanceTask.js");
|
|
45
47
|
const require_core_tasks_helpers_getTransactionRequestData = require("./core/tasks/helpers/getTransactionRequestData.js");
|
|
48
|
+
const require_core_tasks_helpers_isKnownToStatusApi = require("./core/tasks/helpers/isKnownToStatusApi.js");
|
|
46
49
|
const require_core_tasks_helpers_stepComparison = require("./core/tasks/helpers/stepComparison.js");
|
|
47
50
|
const require_core_tasks_PrepareTransactionTask = require("./core/tasks/PrepareTransactionTask.js");
|
|
48
51
|
const require_utils_waitForResult = require("./utils/waitForResult.js");
|
|
@@ -55,7 +58,10 @@ exports.BalanceError = require_errors_errors.BalanceError;
|
|
|
55
58
|
exports.BaseError = require_errors_baseError.BaseError;
|
|
56
59
|
exports.BaseStepExecutionTask = require_core_BaseStepExecutionTask.BaseStepExecutionTask;
|
|
57
60
|
exports.BaseStepExecutor = require_core_BaseStepExecutor.BaseStepExecutor;
|
|
61
|
+
exports.CLEARED_TRANSACTION_FIELDS = require_core_transactionState.CLEARED_TRANSACTION_FIELDS;
|
|
62
|
+
exports.CLOCK_SKEW_MARGIN_MS = require_core_transactionState.CLOCK_SKEW_MARGIN_MS;
|
|
58
63
|
exports.CheckBalanceTask = require_core_tasks_CheckBalanceTask.CheckBalanceTask;
|
|
64
|
+
exports.DROPPED_FALLBACK_AGE_MS = require_core_transactionState.DROPPED_FALLBACK_AGE_MS;
|
|
59
65
|
exports.ErrorMessage = require_errors_constants.ErrorMessage;
|
|
60
66
|
exports.ErrorName = require_errors_constants.ErrorName;
|
|
61
67
|
exports.ExecuteStepRetryError = require_errors_errors.ExecuteStepRetryError;
|
|
@@ -64,6 +70,7 @@ exports.InMemoryStorage = require_core_storage.InMemoryStorage;
|
|
|
64
70
|
exports.LiFiErrorCode = require_errors_constants.LiFiErrorCode;
|
|
65
71
|
exports.LocalStorageAdapter = require_core_storage.LocalStorageAdapter;
|
|
66
72
|
exports.LruMap = require_utils_lru.LruMap;
|
|
73
|
+
exports.MAX_RESEND_AGE_MS = require_core_transactionState.MAX_RESEND_AGE_MS;
|
|
67
74
|
exports.PrepareTransactionTask = require_core_tasks_PrepareTransactionTask.PrepareTransactionTask;
|
|
68
75
|
exports.ProviderError = require_errors_errors.ProviderError;
|
|
69
76
|
exports.RPCError = require_errors_errors.RPCError;
|
|
@@ -76,6 +83,7 @@ exports.UnknownError = require_errors_errors.UnknownError;
|
|
|
76
83
|
exports.ValidationError = require_errors_errors.ValidationError;
|
|
77
84
|
exports.WaitForTransactionStatusTask = require_core_tasks_WaitForTransactionStatusTask.WaitForTransactionStatusTask;
|
|
78
85
|
exports.actions = require_actions_index.actions;
|
|
86
|
+
exports.assertNoOpenTransaction = require_core_transactionState.assertNoOpenTransaction;
|
|
79
87
|
exports.checkBalance = require_core_tasks_helpers_checkBalance.checkBalance;
|
|
80
88
|
exports.checkPackageUpdates = require_utils_checkPackageUpdates.checkPackageUpdates;
|
|
81
89
|
exports.convertQuoteToRoute = require_utils_convertQuoteToRoute.convertQuoteToRoute;
|
|
@@ -83,6 +91,7 @@ exports.createClient = require_client_createClient.createClient;
|
|
|
83
91
|
exports.createDefaultStorage = require_core_storage.createDefaultStorage;
|
|
84
92
|
exports.executeRoute = require_core_execution.executeRoute;
|
|
85
93
|
exports.fetchTxErrorDetails = require_utils_fetchTxErrorDetails.fetchTxErrorDetails;
|
|
94
|
+
exports.findProvider = require_client_findProvider.findProvider;
|
|
86
95
|
exports.formatUnits = require_utils_formatUnits.formatUnits;
|
|
87
96
|
exports.getActionMessage = require_core_actionMessages.getActionMessage;
|
|
88
97
|
exports.getActiveRoute = require_core_execution.getActiveRoute;
|
|
@@ -107,7 +116,12 @@ exports.getTokens = require_actions_getTokens.getTokens;
|
|
|
107
116
|
exports.getTools = require_actions_getTools.getTools;
|
|
108
117
|
exports.getTransactionHistory = require_actions_getTransactionHistory.getTransactionHistory;
|
|
109
118
|
exports.getTransactionRequestData = require_core_tasks_helpers_getTransactionRequestData.getTransactionRequestData;
|
|
119
|
+
exports.hasOpenTransaction = require_core_transactionState.hasOpenTransaction;
|
|
120
|
+
exports.isFinalTransactionError = require_core_transactionState.isFinalTransactionError;
|
|
110
121
|
exports.isHex = require_utils_isHex.isHex;
|
|
122
|
+
exports.isKnownToStatusApi = require_core_tasks_helpers_isKnownToStatusApi.isKnownToStatusApi;
|
|
123
|
+
exports.isOldEnoughToDrop = require_core_transactionState.isOldEnoughToDrop;
|
|
124
|
+
exports.isResendAllowed = require_core_transactionState.isResendAllowed;
|
|
111
125
|
exports.name = require_version.name;
|
|
112
126
|
exports.parseUnits = require_utils_parseUnits.parseUnits;
|
|
113
127
|
exports.patchContractCalls = require_actions_patchContractCalls.patchContractCalls;
|
package/dist/cjs/types/core.d.ts
CHANGED
|
@@ -67,7 +67,18 @@ export type RPCUrlsConfig = Partial<Record<ChainId, string[] | RPCUrlsByRole>>;
|
|
|
67
67
|
export type RPCUrls = Partial<Record<ChainId, string[]>>;
|
|
68
68
|
export interface SDKProvider {
|
|
69
69
|
readonly type: ChainType;
|
|
70
|
-
|
|
70
|
+
/**
|
|
71
|
+
* The chains this provider serves. Omit it to serve every chain of `type`
|
|
72
|
+
* that no other provider lists.
|
|
73
|
+
*/
|
|
74
|
+
readonly chainIds?: readonly ChainId[];
|
|
75
|
+
/**
|
|
76
|
+
* Validates a wallet address. With `chainId`, a provider whose chains use
|
|
77
|
+
* different address formats accepts only that chain's format and refuses a
|
|
78
|
+
* chain it does not know. Never forward `chainId` to a library function whose
|
|
79
|
+
* second parameter means something else.
|
|
80
|
+
*/
|
|
81
|
+
isAddress(address: string, chainId?: ChainId): boolean;
|
|
71
82
|
/**
|
|
72
83
|
* Validates a token identifier, which several ecosystems shape unlike a
|
|
73
84
|
* wallet address. A provider that omits the method has no token address
|
|
@@ -81,7 +92,7 @@ export interface SDKProvider {
|
|
|
81
92
|
export interface SDKClient {
|
|
82
93
|
config: SDKBaseConfig;
|
|
83
94
|
providers: SDKProvider[];
|
|
84
|
-
getProvider(type: ChainType): SDKProvider | undefined;
|
|
95
|
+
getProvider(type: ChainType, chainId?: ChainId): SDKProvider | undefined;
|
|
85
96
|
setProviders(providers: SDKProvider[]): void;
|
|
86
97
|
setChains(chains: ExtendedChain[]): void;
|
|
87
98
|
getChains(): Promise<ExtendedChain[]>;
|
|
@@ -121,7 +132,11 @@ export interface StepExecutor {
|
|
|
121
132
|
allowUserInteraction: boolean;
|
|
122
133
|
allowExecution: boolean;
|
|
123
134
|
setInteraction(settings?: InteractionSettings): void;
|
|
124
|
-
|
|
135
|
+
/**
|
|
136
|
+
* @param signal Aborts when the execution stops. Only waits that start
|
|
137
|
+
* after the broadcast may use it (`StepExecutorBaseContext.signal`).
|
|
138
|
+
*/
|
|
139
|
+
executeStep(client: SDKClient, step: LiFiStepExtended, retryParams?: ExecuteStepRetryParams, signal?: AbortSignal): Promise<LiFiStepExtended>;
|
|
125
140
|
}
|
|
126
141
|
export interface RouteExecutionData {
|
|
127
142
|
route: Route;
|
|
@@ -151,6 +166,18 @@ export type TransactionParameters = {
|
|
|
151
166
|
maxPriorityFeePerGas?: bigint;
|
|
152
167
|
};
|
|
153
168
|
export type RouteExecutionDictionary = Partial<Record<string, Promise<Route>>>;
|
|
169
|
+
/**
|
|
170
|
+
* Called on every update of the route. It receives the SDK's working copy of
|
|
171
|
+
* the route: the same object on every call of one execution, which the SDK
|
|
172
|
+
* keeps changing after the hook returns. Copy or serialize it before you
|
|
173
|
+
* store it.
|
|
174
|
+
*
|
|
175
|
+
* After `stopRouteExecution` it can still be called, but only to deliver the
|
|
176
|
+
* transaction data (`txHash`, `txHex`, `taskId`, `txFinal`) of a task that
|
|
177
|
+
* was still running at the stop, for example in an open wallet prompt. Store
|
|
178
|
+
* that data, so a resume waits for that transaction instead of signing
|
|
179
|
+
* again. If you deleted the route, ignore the call.
|
|
180
|
+
*/
|
|
154
181
|
export type UpdateRouteHook = (updatedRoute: RouteExtended) => void;
|
|
155
182
|
export interface TransactionRequestParameters extends TransactionParameters {
|
|
156
183
|
requestType: "approve" | "transaction";
|
|
@@ -193,6 +220,11 @@ export interface GetContractCallsResult {
|
|
|
193
220
|
export type GetContractCallsHook = (params: ContractCallParams) => Promise<GetContractCallsResult>;
|
|
194
221
|
export interface ExecutionOptions {
|
|
195
222
|
acceptExchangeRateUpdateHook?: AcceptExchangeRateUpdateHook;
|
|
223
|
+
/**
|
|
224
|
+
* Receives the route on every update, and after `stopRouteExecution` the
|
|
225
|
+
* late transaction data of a task that was still running. See
|
|
226
|
+
* {@link UpdateRouteHook}.
|
|
227
|
+
*/
|
|
196
228
|
updateRouteHook?: UpdateRouteHook;
|
|
197
229
|
updateTransactionRequestHook?: TransactionRequestUpdateHook;
|
|
198
230
|
getContractCalls?: GetContractCallsHook;
|
|
@@ -213,7 +245,21 @@ export type ExecutionAction = {
|
|
|
213
245
|
txLink?: string;
|
|
214
246
|
taskId?: string;
|
|
215
247
|
txType?: TransactionMethodType;
|
|
248
|
+
/**
|
|
249
|
+
* Provider-specific serialized signed transaction (hex, XDR, base64 or JSON).
|
|
250
|
+
* Present while the transaction may still need to be (re)sent or looked up.
|
|
251
|
+
* Stellar keeps it, and Bitcoin keeps it unless every node refuses its first
|
|
252
|
+
* send; Solana, Tron and Sui clear it when no longer needed.
|
|
253
|
+
*/
|
|
216
254
|
txHex?: string;
|
|
255
|
+
/**
|
|
256
|
+
* Set together with status `FAILED` when the outcome of this action's
|
|
257
|
+
* transaction is known and final (failed or reverted on chain or at the
|
|
258
|
+
* relayer, cancelled, replaced, or dropped with proof).
|
|
259
|
+
* A FAILED action without this flag has an unknown outcome and is re-checked
|
|
260
|
+
* on resume instead of being signed again.
|
|
261
|
+
*/
|
|
262
|
+
txFinal?: boolean;
|
|
217
263
|
error?: {
|
|
218
264
|
code: string | number;
|
|
219
265
|
message: string;
|
|
@@ -12,6 +12,14 @@ export interface StepExecutorBaseContext {
|
|
|
12
12
|
step: LiFiStepExtended;
|
|
13
13
|
allowUserInteraction: boolean;
|
|
14
14
|
retryParams?: ExecuteStepRetryParams;
|
|
15
|
+
/**
|
|
16
|
+
* Aborts when `stopRouteExecution` stops the execution. Give it only to a
|
|
17
|
+
* wait that starts after the transaction is broadcast, such as the
|
|
18
|
+
* `/status` poll. Never give it to a sign, send or wallet call: a stopped
|
|
19
|
+
* run must finish those, so its late transaction data still reaches the
|
|
20
|
+
* stored route and a resume does not sign again.
|
|
21
|
+
*/
|
|
22
|
+
signal?: AbortSignal;
|
|
15
23
|
}
|
|
16
24
|
export interface StepExecutorContext extends StepExecutorBaseContext {
|
|
17
25
|
pollingIntervalMs?: number;
|
|
@@ -5,7 +5,7 @@ const checkPackageUpdates = async (packageName, packageVersion) => {
|
|
|
5
5
|
try {
|
|
6
6
|
const pkgName = packageName ?? "@lifi/sdk";
|
|
7
7
|
const latestVersion = (await (await fetch(`https://registry.npmjs.org/${pkgName}/latest`)).json()).version;
|
|
8
|
-
const currentVersion = packageVersion ?? "4.
|
|
8
|
+
const currentVersion = packageVersion ?? "4.11.0";
|
|
9
9
|
if (latestVersion > currentVersion) console.warn(`${pkgName}: new package version is available. Please update as soon as possible to enjoy the newest features. Current version: ${currentVersion}. Latest version: ${latestVersion}.`);
|
|
10
10
|
} catch (_error) {}
|
|
11
11
|
};
|
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* @param interval The timeout in milliseconds between retries, or a function that receives the current poll count and returns the interval. Defaults to 5000
|
|
6
6
|
* @param maxRetries Maximum number of calls that throw before the error is rethrown, defaults to 3
|
|
7
7
|
* @param shouldRetry Optional predicate to determine if an error should trigger a retry
|
|
8
|
+
* @param signal Optional signal that ends the wait: no call starts after it aborts, and the sleep between calls ends at once
|
|
8
9
|
* @returns The result of the fn function
|
|
9
10
|
* @throws The error of fn if maximum retries is reached, or if shouldRetry returns false
|
|
11
|
+
* @throws The abort reason of `signal` once it aborts
|
|
10
12
|
*/
|
|
11
|
-
export declare const waitForResult: <T>(fn: () => Promise<T | undefined>, interval?: number | ((poll: number) => number), maxRetries?: number, shouldRetry?: (count: number, error: unknown) => boolean) => Promise<T>;
|
|
13
|
+
export declare const waitForResult: <T>(fn: () => Promise<T | undefined>, interval?: number | ((poll: number) => number), maxRetries?: number, shouldRetry?: (count: number, error: unknown) => boolean, signal?: AbortSignal) => Promise<T>;
|
|
12
14
|
//#endregion
|
|
13
15
|
//# sourceMappingURL=waitForResult.d.ts.map
|