@lifi/sdk 4.9.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 +50 -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/checkBalance.js +6 -3
- package/dist/cjs/core/tasks/helpers/checkBalance.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 +7 -3
- package/dist/cjs/index.js +16 -1
- package/dist/cjs/types/core.d.ts +49 -3
- package/dist/cjs/types/execution.d.ts +8 -0
- package/dist/cjs/utils/abort.d.ts +6 -0
- package/dist/cjs/utils/abort.js +10 -0
- package/dist/cjs/utils/abort.js.map +1 -0
- package/dist/cjs/utils/checkPackageUpdates.js +1 -1
- package/dist/cjs/utils/formatUnits.js +1 -0
- package/dist/cjs/utils/formatUnits.js.map +1 -1
- package/dist/cjs/utils/lru.d.ts +14 -0
- package/dist/cjs/utils/lru.js +35 -0
- package/dist/cjs/utils/lru.js.map +1 -0
- package/dist/cjs/utils/parseUnits.js +30 -16
- package/dist/cjs/utils/parseUnits.js.map +1 -1
- package/dist/cjs/utils/sleep.d.ts +7 -1
- package/dist/cjs/utils/sleep.js +22 -3
- package/dist/cjs/utils/sleep.js.map +1 -1
- package/dist/cjs/utils/waitForResult.d.ts +7 -5
- package/dist/cjs/utils/waitForResult.js +19 -14
- package/dist/cjs/utils/waitForResult.js.map +1 -1
- package/dist/cjs/utils/withDedupe.d.ts +0 -10
- package/dist/cjs/utils/withDedupe.js +4 -23
- package/dist/cjs/utils/withDedupe.js.map +1 -1
- package/dist/cjs/utils/withTimeout.js +6 -2
- package/dist/cjs/utils/withTimeout.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/checkBalance.js +6 -3
- package/dist/esm/core/tasks/helpers/checkBalance.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 +7 -3
- package/dist/esm/index.js +6 -2
- 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/abort.d.ts +6 -0
- package/dist/esm/utils/abort.d.ts.map +1 -0
- package/dist/esm/utils/abort.js +8 -0
- package/dist/esm/utils/abort.js.map +1 -0
- package/dist/esm/utils/checkPackageUpdates.js +1 -1
- package/dist/esm/utils/formatUnits.js +1 -0
- package/dist/esm/utils/formatUnits.js.map +1 -1
- package/dist/esm/utils/lru.d.ts +14 -0
- package/dist/esm/utils/lru.d.ts.map +1 -0
- package/dist/esm/utils/lru.js +34 -0
- package/dist/esm/utils/lru.js.map +1 -0
- package/dist/esm/utils/parseUnits.js +30 -16
- package/dist/esm/utils/parseUnits.js.map +1 -1
- package/dist/esm/utils/sleep.d.ts +7 -1
- package/dist/esm/utils/sleep.d.ts.map +1 -1
- package/dist/esm/utils/sleep.js +22 -3
- package/dist/esm/utils/sleep.js.map +1 -1
- package/dist/esm/utils/waitForResult.d.ts +7 -5
- package/dist/esm/utils/waitForResult.d.ts.map +1 -1
- package/dist/esm/utils/waitForResult.js +19 -14
- package/dist/esm/utils/waitForResult.js.map +1 -1
- package/dist/esm/utils/withDedupe.d.ts +0 -10
- package/dist/esm/utils/withDedupe.d.ts.map +1 -1
- package/dist/esm/utils/withDedupe.js +5 -22
- package/dist/esm/utils/withDedupe.js.map +1 -1
- package/dist/esm/utils/withTimeout.d.ts.map +1 -1
- package/dist/esm/utils/withTimeout.js +6 -2
- package/dist/esm/utils/withTimeout.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/checkBalance.ts +11 -3
- 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 +16 -1
- package/src/types/core.ts +50 -3
- package/src/types/execution.ts +8 -0
- package/src/utils/abort.ts +10 -0
- package/src/utils/formatUnits.ts +6 -0
- package/src/utils/lru.ts +38 -0
- package/src/utils/parseUnits.ts +53 -20
- package/src/utils/sleep.ts +27 -3
- package/src/utils/waitForResult.ts +20 -10
- package/src/utils/withDedupe.ts +4 -28
- package/src/utils/withTimeout.ts +7 -2
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# @lifi/sdk
|
|
2
2
|
|
|
3
|
+
## 4.11.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#492](https://github.com/lifinance/sdk/pull/492) [`48af3ae`](https://github.com/lifinance/sdk/commit/48af3aeb250299ef9d2ff9eb79a38a6b8f52d409) Thanks [@chybisov](https://github.com/chybisov)! - `SDKProvider.isAddress` accepts an optional `chainId`. Without it, a provider answers as before. With it, a provider whose chains use different address formats accepts only that chain's format and refuses a chain it does not know. A provider must never forward the chain ID to a library function whose second parameter means something else. A custom provider that assigns such a function directly as `isAddress`, for example viem's `isAddress` or bigmi's `isUTXOAddress`, no longer type-checks; wrap it in a one-argument function, as `EthereumProvider` and `BitcoinProvider` do.
|
|
8
|
+
|
|
9
|
+
A provider can declare the `chainIds` it serves, so a chain-specific provider can sit beside the generic provider of the same chain type. `client.getProvider(type, chainId?)` returns the provider that lists the chain, otherwise the provider of that type that lists no chains; `getProvider(type)` answers as before. The new `findProvider(providers, chainType, chainId?)` applies the same rule to any provider list. `setProviders` replaces only a provider with the same type and the same `chainIds`.
|
|
10
|
+
|
|
11
|
+
- [#507](https://github.com/lifinance/sdk/pull/507) [`14f4ecc`](https://github.com/lifinance/sdk/commit/14f4ecc2714799449d57b61ff06b040df505184e) Thanks [@chybisov](https://github.com/chybisov)! - Never sign a second transaction on resume while the first one may still land.
|
|
12
|
+
|
|
13
|
+
- `prepareRestart` keeps a FAILED action with an unknown outcome and re-checks it on chain. Only a final outcome is dropped, so "Try again" signs anew.
|
|
14
|
+
- After `stopRouteExecution`, `updateRouteHook` can still be called for a route whose task was running, but only for a write that changes `txHash`, `txHex`, `taskId` or `txFinal`. An integrator that deleted the route should ignore that call. An error the hook throws in such a late call does not reach the run; in development it is logged with `console.debug`. If a new execution of the same route is running, a late transaction that may still land is merged into its action instead, so it does not sign again unless its wallet call has already started. If a newer execution already ended, the late transaction is merged into the route of the last ended execution, and that execution's `updateRouteHook` is called.
|
|
15
|
+
- The new `ExecutionAction.txFinal` flags a final outcome.
|
|
16
|
+
- `TransactionError` takes a new `final` option. Every `TransactionError` now has an own `final` property (`false` unless set), which changes its JSON shape.
|
|
17
|
+
- `resumeRoute` no longer mutates the route it is given. A restart keeps `execution.signedAt` while a transaction is open.
|
|
18
|
+
- In the EVM relayed lane and in the Solana, Sui, Tron, Bitcoin and Stellar providers, the SDK sends the transaction and checks the action again after the wallet returns. A prompt that was already open can still be signed, but when the late transaction merged first, those bytes are never sent or stored. A caught merge makes the newer run fail with `TransactionConflict`, and "Try again" then resumes and waits for the transaction. A step that asks for a replay (`ExecuteStepRetryError`) after such a merge also fails with `TransactionConflict`.
|
|
19
|
+
- An older run no longer stops or ends a newer execution of the same route.
|
|
20
|
+
- After `stopRouteExecution`, a run that waits for `/status` stops polling. Before, it polled every few seconds until the API answered DONE, and forever on FAILED, INVALID, NOT_FOUND or HTTP/network errors. The wait ends at once without a write to the route, so the step stays PENDING, and the run's `executeRoute` promise resolves with the route. A resume waits for the outcome of the same transaction.
|
|
21
|
+
- A stop during the first attempt of a step that then asks for a replay (`ExecuteStepRetryError`) also ends the run. The step does not run again, so the replay's re-quote, chain reads and integrator callbacks do not run after the stop, and `executeRoute` resolves with the route.
|
|
22
|
+
- `waitForResult` and `StepExecutor.executeStep` take an optional `signal`. Provider authors get it as `StepExecutorBaseContext.signal`, which aborts on `stopRouteExecution`. Give it only to a wait that starts after the transaction is broadcast, never to a sign, send or wallet call.
|
|
23
|
+
- New `hasOpenTransaction`. `assertNoOpenTransaction`, `isKnownToStatusApi`, `isFinalTransactionError`, `isResendAllowed`, `isOldEnoughToDrop`, `CLEARED_TRANSACTION_FIELDS`, `MAX_RESEND_AGE_MS`, `DROPPED_FALLBACK_AGE_MS` and `CLOCK_SKEW_MARGIN_MS` are exported for provider packages; they are not part of the integrator API (`@internal`).
|
|
24
|
+
- Remaining limits:
|
|
25
|
+
- In the lanes where the SDK sends, if the newer prompt is approved before the older run stores its transaction (in the EVM relayed lane, before the older run's relay request returns), nothing is merged yet, and both transactions can be sent.
|
|
26
|
+
- In the EVM standard and batched lanes the wallet sends, so a wallet call that has already started can still send a second transaction.
|
|
27
|
+
- A FAILED route from before the upgrade, or one resumed after node history no longer covers its signing time, can stay unknown. The exit is to delete the route.
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- [#510](https://github.com/lifinance/sdk/pull/510) [`bb964c0`](https://github.com/lifinance/sdk/commit/bb964c03d8ea1770303ab1bba803373a80e6388f) Thanks [@chybisov](https://github.com/chybisov)! - Bump runtime dependencies: viem to 2.57.3, @stellar/stellar-sdk to 17.2.1,
|
|
32
|
+
@mysten/sui to 2.35.0, @lifi/types to 18.13.0 and @bigmi/core to 0.9.3.
|
|
33
|
+
|
|
34
|
+
## 4.10.0
|
|
35
|
+
|
|
36
|
+
### Minor Changes
|
|
37
|
+
|
|
38
|
+
- [#499](https://github.com/lifinance/sdk/pull/499) [`2d60ab4`](https://github.com/lifinance/sdk/commit/2d60ab43af2ecd1c17a3bbb126de408952a46d80) Thanks [@chybisov](https://github.com/chybisov)! - `sleep` takes an optional `{ signal }`. It rejects with the abort reason as soon as the signal aborts.
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- [#496](https://github.com/lifinance/sdk/pull/496) [`dcbbdcc`](https://github.com/lifinance/sdk/commit/dcbbdccc2684c4549cbfe06444698f11347206af) Thanks [@chybisov](https://github.com/chybisov)! - Bump the `@lifi/types` pin to `^18.12.1`, which adds `slippageScope` and the route-wide
|
|
43
|
+
slippage commitment types.
|
|
44
|
+
|
|
45
|
+
- [#499](https://github.com/lifinance/sdk/pull/499) [`2d60ab4`](https://github.com/lifinance/sdk/commit/2d60ab43af2ecd1c17a3bbb126de408952a46d80) Thanks [@chybisov](https://github.com/chybisov)! - Stop the balance check's retry loop once its 10 s timeout rejects, so a late balance read can no longer change `step.action.fromAmount`.
|
|
46
|
+
|
|
47
|
+
- [#499](https://github.com/lifinance/sdk/pull/499) [`2d60ab4`](https://github.com/lifinance/sdk/commit/2d60ab43af2ecd1c17a3bbb126de408952a46d80) Thanks [@chybisov](https://github.com/chybisov)! - `LruMap` now evicts the least recently used entry instead of the oldest one, and no longer grows past its size on iOS 18.
|
|
48
|
+
|
|
49
|
+
- [#499](https://github.com/lifinance/sdk/pull/499) [`2d60ab4`](https://github.com/lifinance/sdk/commit/2d60ab43af2ecd1c17a3bbb126de408952a46d80) Thanks [@chybisov](https://github.com/chybisov)! - `parseUnits` rounds long fractions exactly, and `parseUnits` and `formatUnits` throw on a negative or fractional `decimals` instead of giving a wrong amount. An input with no digit, such as `''`, still parses as `0n`.
|
|
50
|
+
|
|
51
|
+
- [#499](https://github.com/lifinance/sdk/pull/499) [`2d60ab4`](https://github.com/lifinance/sdk/commit/2d60ab43af2ecd1c17a3bbb126de408952a46d80) Thanks [@chybisov](https://github.com/chybisov)! - `withTimeout` now rejects with its timeout error only when its own timeout fires. Any other `AbortError` from the wrapped function passes through, so a wallet `AbortError` in the Bitcoin and Solana signing steps is no longer reported as `TransactionExpired`.
|
|
52
|
+
|
|
3
53
|
## 4.9.0
|
|
4
54
|
|
|
5
55
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -83,6 +83,13 @@ needs no ecosystem library. To discover and connect browser wallets such as Frei
|
|
|
83
83
|
xBull, or Lobstr, we recommend
|
|
84
84
|
[Stellar Wallets Kit](https://github.com/Creit-Tech/Stellar-Wallets-Kit).
|
|
85
85
|
|
|
86
|
+
**Zcash**
|
|
87
|
+
```bash
|
|
88
|
+
pnpm add @lifi/sdk-provider-zcash
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
ZEC is a destination-only chain: `ZcashProvider` validates transparent `t1` and `t3` receivers, and unified `u1` receivers that carry an Orchard receiver, and needs no wallet. Register it after `BitcoinProvider`; it serves ZEC only.
|
|
92
|
+
|
|
86
93
|
## Architecture
|
|
87
94
|
|
|
88
95
|
The LI.FI SDK uses a modular provider architecture:
|
|
@@ -134,6 +141,7 @@ import { BitcoinProvider } from '@lifi/sdk-provider-bitcoin'
|
|
|
134
141
|
import { SuiProvider } from '@lifi/sdk-provider-sui'
|
|
135
142
|
import { TronProvider } from '@lifi/sdk-provider-tron'
|
|
136
143
|
import { StellarProvider } from '@lifi/sdk-provider-stellar'
|
|
144
|
+
import { ZcashProvider } from '@lifi/sdk-provider-zcash'
|
|
137
145
|
|
|
138
146
|
const client = createClient({
|
|
139
147
|
integrator: 'Your dApp/company name',
|
|
@@ -144,6 +152,7 @@ const client = createClient({
|
|
|
144
152
|
SuiProvider({ /* options */ }),
|
|
145
153
|
TronProvider({ /* options */ }),
|
|
146
154
|
StellarProvider({ /* options */ }),
|
|
155
|
+
ZcashProvider(),
|
|
147
156
|
],
|
|
148
157
|
})
|
|
149
158
|
```
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_version = require("../version.js");
|
|
3
3
|
const require_utils_checkPackageUpdates = require("../utils/checkPackageUpdates.js");
|
|
4
|
+
const require_client_findProvider = require("./findProvider.js");
|
|
4
5
|
const require_client_getClientStorage = require("./getClientStorage.js");
|
|
5
6
|
//#region src/client/createClient.ts
|
|
7
|
+
const providerScope = (provider) => provider.chainIds ? `${provider.type}:${[...provider.chainIds].sort().join(",")}` : provider.type;
|
|
6
8
|
function createClient(options) {
|
|
7
9
|
if (!options.integrator) throw new Error("Integrator not found. Please see documentation https://docs.li.fi/integrate-li.fi-js-sdk/set-up-the-sdk");
|
|
8
10
|
if (!options.disableVersionCheck && process.env.NODE_ENV === "development") require_utils_checkPackageUpdates.checkPackageUpdates(require_version.name, require_version.version);
|
|
@@ -39,12 +41,12 @@ function createClient(options) {
|
|
|
39
41
|
get providers() {
|
|
40
42
|
return _providers;
|
|
41
43
|
},
|
|
42
|
-
getProvider(type) {
|
|
43
|
-
return this.providers
|
|
44
|
+
getProvider(type, chainId) {
|
|
45
|
+
return require_client_findProvider.findProvider(this.providers, type, chainId);
|
|
44
46
|
},
|
|
45
47
|
setProviders(newProviders) {
|
|
46
|
-
const providerMap = new Map(this.providers.map((provider) => [provider
|
|
47
|
-
for (const provider of newProviders) providerMap.set(provider
|
|
48
|
+
const providerMap = new Map(this.providers.map((provider) => [providerScope(provider), provider]));
|
|
49
|
+
for (const provider of newProviders) providerMap.set(providerScope(provider), provider);
|
|
48
50
|
_providers = Array.from(providerMap.values());
|
|
49
51
|
},
|
|
50
52
|
setChains(chains) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createClient.js","names":["name","version","getClientStorage"],"sources":["../../../src/client/createClient.ts"],"sourcesContent":["import type { ChainId, ChainType, ExtendedChain } from '@lifi/types'\nimport type {\n RPCUrls,\n SDKBaseConfig,\n SDKClient,\n SDKConfig,\n SDKProvider,\n} from '../types/core.js'\nimport { checkPackageUpdates } from '../utils/checkPackageUpdates.js'\nimport { name, version } from '../version.js'\nimport { getClientStorage } from './getClientStorage.js'\n\nexport function createClient(options: SDKConfig): SDKClient {\n if (!options.integrator) {\n throw new Error(\n 'Integrator not found. Please see documentation https://docs.li.fi/integrate-li.fi-js-sdk/set-up-the-sdk'\n )\n }\n\n if (!options.disableVersionCheck && process.env.NODE_ENV === 'development') {\n checkPackageUpdates(name, version)\n }\n\n const { providers, rpcUrls, ...configOptions } = options\n\n // Role entries split once, here: the config keeps plain read lists, so\n // everything that reads `config.rpcUrls` sees `string[]` as before.\n const readRpcUrls: RPCUrls = {}\n const writeRpcUrls: RPCUrls = {}\n const bundleRpcUrls: RPCUrls = {}\n let hasRoles = false\n for (const key in rpcUrls) {\n const chainId = Number(key) as ChainId\n const entry = rpcUrls[chainId]\n if (Array.isArray(entry)) {\n readRpcUrls[chainId] = entry\n } else if (entry) {\n hasRoles = true\n if (entry.read) {\n readRpcUrls[chainId] = entry.read\n }\n if (entry.write?.length) {\n writeRpcUrls[chainId] = entry.write\n }\n if (entry.bundle?.length) {\n bundleRpcUrls[chainId] = entry.bundle\n }\n }\n }\n\n const _config: SDKBaseConfig = {\n ...configOptions,\n apiUrl: configOptions?.apiUrl ?? 'https://li.quest/v1',\n // Plain lists only: the caller's own object, exactly as before.\n rpcUrls: hasRoles ? readRpcUrls : ((rpcUrls ?? {}) as RPCUrls),\n debug: configOptions?.debug ?? false,\n preloadChains: configOptions?.preloadChains ?? true,\n integrator: configOptions?.integrator ?? 'lifi-sdk',\n }\n\n let _providers: SDKProvider[] = providers ?? []\n const _storage = getClientStorage(_config)\n\n const client: SDKClient = {\n get config() {\n return _config\n },\n get providers() {\n return _providers\n },\n getProvider(type: ChainType) {\n return this.providers
|
|
1
|
+
{"version":3,"file":"createClient.js","names":["name","version","getClientStorage","findProvider"],"sources":["../../../src/client/createClient.ts"],"sourcesContent":["import type { ChainId, ChainType, ExtendedChain } from '@lifi/types'\nimport type {\n RPCUrls,\n SDKBaseConfig,\n SDKClient,\n SDKConfig,\n SDKProvider,\n} from '../types/core.js'\nimport { checkPackageUpdates } from '../utils/checkPackageUpdates.js'\nimport { name, version } from '../version.js'\nimport { findProvider } from './findProvider.js'\nimport { getClientStorage } from './getClientStorage.js'\n\n// A provider replaces only one that serves the same chains. A provider that\n// lists no chains keeps the bare type, so even an empty list stays apart.\nconst providerScope = (provider: SDKProvider): string =>\n provider.chainIds\n ? `${provider.type}:${[...provider.chainIds].sort().join(',')}`\n : provider.type\n\nexport function createClient(options: SDKConfig): SDKClient {\n if (!options.integrator) {\n throw new Error(\n 'Integrator not found. Please see documentation https://docs.li.fi/integrate-li.fi-js-sdk/set-up-the-sdk'\n )\n }\n\n if (!options.disableVersionCheck && process.env.NODE_ENV === 'development') {\n checkPackageUpdates(name, version)\n }\n\n const { providers, rpcUrls, ...configOptions } = options\n\n // Role entries split once, here: the config keeps plain read lists, so\n // everything that reads `config.rpcUrls` sees `string[]` as before.\n const readRpcUrls: RPCUrls = {}\n const writeRpcUrls: RPCUrls = {}\n const bundleRpcUrls: RPCUrls = {}\n let hasRoles = false\n for (const key in rpcUrls) {\n const chainId = Number(key) as ChainId\n const entry = rpcUrls[chainId]\n if (Array.isArray(entry)) {\n readRpcUrls[chainId] = entry\n } else if (entry) {\n hasRoles = true\n if (entry.read) {\n readRpcUrls[chainId] = entry.read\n }\n if (entry.write?.length) {\n writeRpcUrls[chainId] = entry.write\n }\n if (entry.bundle?.length) {\n bundleRpcUrls[chainId] = entry.bundle\n }\n }\n }\n\n const _config: SDKBaseConfig = {\n ...configOptions,\n apiUrl: configOptions?.apiUrl ?? 'https://li.quest/v1',\n // Plain lists only: the caller's own object, exactly as before.\n rpcUrls: hasRoles ? readRpcUrls : ((rpcUrls ?? {}) as RPCUrls),\n debug: configOptions?.debug ?? false,\n preloadChains: configOptions?.preloadChains ?? true,\n integrator: configOptions?.integrator ?? 'lifi-sdk',\n }\n\n let _providers: SDKProvider[] = providers ?? []\n const _storage = getClientStorage(_config)\n\n const client: SDKClient = {\n get config() {\n return _config\n },\n get providers() {\n return _providers\n },\n getProvider(type: ChainType, chainId?: ChainId) {\n return findProvider(this.providers, type, chainId)\n },\n setProviders(newProviders: SDKProvider[]) {\n const providerMap = new Map(\n this.providers.map((provider) => [providerScope(provider), provider])\n )\n for (const provider of newProviders) {\n providerMap.set(providerScope(provider), provider)\n }\n _providers = Array.from(providerMap.values())\n },\n setChains(chains: ExtendedChain[]) {\n _storage.setChains(chains)\n },\n async getChains() {\n return await _storage.getChains()\n },\n async getChainById(chainId: ChainId) {\n const chains = await this.getChains()\n const chain = chains?.find((chain) => chain.id === chainId)\n if (!chain) {\n throw new Error(`ChainId ${chainId} not found`)\n }\n return chain\n },\n async getRpcUrls() {\n return await _storage.getRpcUrls()\n },\n async getRpcUrlsByChainId(chainId: ChainId) {\n const rpcUrls = await this.getRpcUrls()\n const chainRpcUrls = rpcUrls[chainId]\n if (!chainRpcUrls?.length) {\n throw new Error(`RPC URL not found for chainId: ${chainId}`)\n }\n return chainRpcUrls\n },\n async getWriteRpcUrlsByChainId(chainId: ChainId) {\n return writeRpcUrls[chainId] ?? []\n },\n async getBundleRpcUrlsByChainId(chainId: ChainId) {\n return bundleRpcUrls[chainId] ?? []\n },\n }\n\n function extend<TClient extends SDKClient>(\n base: TClient\n ): <TExtensions extends Record<string, any>>(\n extendFn: (client: TClient) => TExtensions\n ) => TClient & TExtensions {\n return (extendFn) => {\n const extensions = extendFn(base)\n // Copy descriptors rather than spreading. `config` and `providers` are\n // accessors over closure variables, and `setProviders` reassigns\n // `_providers` — so a spread would freeze the extension on the values\n // those getters happened to return at extend time, leaving it with a\n // provider list that never updates.\n const extended = Object.defineProperties(\n {},\n {\n ...Object.getOwnPropertyDescriptors(base),\n ...Object.getOwnPropertyDescriptors(extensions),\n }\n ) as TClient & typeof extensions\n\n // Preserve the extend function for further extensions\n return Object.assign(extended, {\n extend: extend(extended),\n })\n }\n }\n\n return Object.assign(client, { extend: extend(client) })\n}\n"],"mappings":";;;;;;AAeA,MAAM,iBAAiB,aACrB,SAAS,WACL,GAAG,SAAS,KAAK,GAAG,CAAC,GAAG,SAAS,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,MAC1D,SAAS;AAEf,SAAgB,aAAa,SAA+B;CAC1D,IAAI,CAAC,QAAQ,YACX,MAAM,IAAI,MACR,yGACF;CAGF,IAAI,CAAC,QAAQ,uBAAuB,QAAQ,IAAI,aAAa,eAC3D,kCAAA,oBAAoBA,gBAAAA,MAAMC,gBAAAA,OAAO;CAGnC,MAAM,EAAE,WAAW,SAAS,GAAG,kBAAkB;CAIjD,MAAM,cAAuB,CAAC;CAC9B,MAAM,eAAwB,CAAC;CAC/B,MAAM,gBAAyB,CAAC;CAChC,IAAI,WAAW;CACf,KAAK,MAAM,OAAO,SAAS;EACzB,MAAM,UAAU,OAAO,GAAG;EAC1B,MAAM,QAAQ,QAAQ;EACtB,IAAI,MAAM,QAAQ,KAAK,GACrB,YAAY,WAAW;OAClB,IAAI,OAAO;GAChB,WAAW;GACX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AAC,cAAc,QACjB,MAAM,IAAI,MAAM,kCAAkC,SAAS;GAE7D,OAAO;EACT;EACA,MAAM,yBAAyB,SAAkB;GAC/C,OAAO,aAAa,YAAY,CAAC;EACnC;EACA,MAAM,0BAA0B,SAAkB;GAChD,OAAO,cAAc,YAAY,CAAC;EACpC;CACF;CAEA,SAAS,OACP,MAGyB;EACzB,QAAQ,aAAa;GACnB,MAAM,aAAa,SAAS,IAAI;GAMhC,MAAM,WAAW,OAAO,iBACtB,CAAC,GACD;IACE,GAAG,OAAO,0BAA0B,IAAI;IACxC,GAAG,OAAO,0BAA0B,UAAU;GAChD,CACF;GAGA,OAAO,OAAO,OAAO,UAAU,EAC7B,QAAQ,OAAO,QAAQ,EACzB,CAAC;EACH;CACF;CAEA,OAAO,OAAO,OAAO,QAAQ,EAAE,QAAQ,OAAO,MAAM,EAAE,CAAC;AACzD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SDKProvider } from "../types/core.js";
|
|
2
|
+
import { ChainId, ChainType } from "@lifi/types";
|
|
3
|
+
//#region src/client/findProvider.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The provider that serves a chain: the one that lists `chainId` in its
|
|
6
|
+
* `chainIds`, otherwise the provider of `chainType` that lists no chains.
|
|
7
|
+
*/
|
|
8
|
+
export declare const findProvider: <T extends Pick<SDKProvider, "type" | "chainIds">>(providers: readonly T[], chainType: ChainType, chainId?: ChainId) => T | undefined;
|
|
9
|
+
//#endregion
|
|
10
|
+
//# sourceMappingURL=findProvider.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/client/findProvider.ts
|
|
3
|
+
/**
|
|
4
|
+
* The provider that serves a chain: the one that lists `chainId` in its
|
|
5
|
+
* `chainIds`, otherwise the provider of `chainType` that lists no chains.
|
|
6
|
+
*/
|
|
7
|
+
const findProvider = (providers, chainType, chainId) => (chainId === void 0 ? void 0 : providers.find((provider) => provider.type === chainType && provider.chainIds?.includes(chainId))) ?? providers.find((provider) => provider.type === chainType && !provider.chainIds);
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.findProvider = findProvider;
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=findProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findProvider.js","names":[],"sources":["../../../src/client/findProvider.ts"],"sourcesContent":["import type { ChainId, ChainType } from '@lifi/types'\nimport type { SDKProvider } from '../types/core.js'\n\n/**\n * The provider that serves a chain: the one that lists `chainId` in its\n * `chainIds`, otherwise the provider of `chainType` that lists no chains.\n */\nexport const findProvider = <T extends Pick<SDKProvider, 'type' | 'chainIds'>>(\n providers: readonly T[],\n chainType: ChainType,\n chainId?: ChainId\n): T | undefined =>\n (chainId === undefined\n ? undefined\n : providers.find(\n (provider) =>\n provider.type === chainType && provider.chainIds?.includes(chainId)\n )) ??\n providers.find(\n (provider) => provider.type === chainType && !provider.chainIds\n )\n"],"mappings":";;;;;;AAOA,MAAa,gBACX,WACA,WACA,aAEC,YAAY,KAAA,IACT,KAAA,IACA,UAAU,MACP,aACC,SAAS,SAAS,aAAa,SAAS,UAAU,SAAS,OAAO,CACtE,MACJ,UAAU,MACP,aAAa,SAAS,SAAS,aAAa,CAAC,SAAS,QACzD"}
|
|
@@ -16,7 +16,7 @@ export declare abstract class BaseStepExecutor implements StepExecutor {
|
|
|
16
16
|
abstract createContext(baseContext: StepExecutorBaseContext): Promise<StepExecutorContext>;
|
|
17
17
|
abstract createPipeline(context: StepExecutorContext): TaskPipeline;
|
|
18
18
|
abstract parseErrors(error: Error, step?: LiFiStepExtended, action?: ExecutionAction, retryParams?: ExecuteStepRetryParams): Promise<SDKError | ExecuteStepRetryError>;
|
|
19
|
-
executeStep: (client: SDKClient, step: LiFiStepExtended, retryParams?: ExecuteStepRetryParams) => Promise<LiFiStepExtended>;
|
|
19
|
+
executeStep: (client: SDKClient, step: LiFiStepExtended, retryParams?: ExecuteStepRetryParams, signal?: AbortSignal) => Promise<LiFiStepExtended>;
|
|
20
20
|
}
|
|
21
21
|
//#endregion
|
|
22
22
|
//# sourceMappingURL=BaseStepExecutor.d.ts.map
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_errors_SDKError = require("../errors/SDKError.js");
|
|
3
|
+
const require_errors_baseError = require("../errors/baseError.js");
|
|
2
4
|
const require_errors_errors = require("../errors/errors.js");
|
|
5
|
+
const require_core_transactionState = require("./transactionState.js");
|
|
3
6
|
const require_core_StatusManager = require("./StatusManager.js");
|
|
4
7
|
//#region src/core/BaseStepExecutor.ts
|
|
5
8
|
const defaultInteractionSettings = {
|
|
@@ -25,7 +28,7 @@ var BaseStepExecutor = class {
|
|
|
25
28
|
this.statusManager.allowUpdates(interactionSettings.allowUpdates);
|
|
26
29
|
this.allowExecution = interactionSettings.allowExecution;
|
|
27
30
|
};
|
|
28
|
-
createBaseContext = async (client, step, retryParams) => {
|
|
31
|
+
createBaseContext = async (client, step, retryParams, signal) => {
|
|
29
32
|
const fromChain = await client.getChainById(step.action.fromChainId);
|
|
30
33
|
const toChain = await client.getChainById(step.action.toChainId);
|
|
31
34
|
return {
|
|
@@ -37,24 +40,33 @@ var BaseStepExecutor = class {
|
|
|
37
40
|
retryParams,
|
|
38
41
|
statusManager: this.statusManager,
|
|
39
42
|
executionOptions: this.executionOptions,
|
|
40
|
-
allowUserInteraction: this.allowUserInteraction
|
|
43
|
+
allowUserInteraction: this.allowUserInteraction,
|
|
44
|
+
signal
|
|
41
45
|
};
|
|
42
46
|
};
|
|
43
|
-
executeStep = async (client, step, retryParams) => {
|
|
47
|
+
executeStep = async (client, step, retryParams, signal) => {
|
|
44
48
|
try {
|
|
45
49
|
step.execution = this.statusManager.initializeExecution(step);
|
|
46
|
-
const baseContext = await this.createBaseContext(client, step, retryParams);
|
|
50
|
+
const baseContext = await this.createBaseContext(client, step, retryParams, signal);
|
|
47
51
|
const context = await this.createContext(baseContext);
|
|
48
52
|
await this.createPipeline(context).run(context);
|
|
49
53
|
return step;
|
|
50
54
|
} catch (error) {
|
|
51
55
|
const action = step.execution?.actions?.at(-1);
|
|
52
|
-
|
|
56
|
+
let isFinal = require_core_transactionState.isFinalTransactionError(error);
|
|
57
|
+
let parsed = await this.parseErrors(error, step, action, retryParams);
|
|
58
|
+
if (parsed instanceof require_errors_errors.ExecuteStepRetryError && require_core_transactionState.hasStepOpenTransaction(step)) {
|
|
59
|
+
parsed = new require_errors_SDKError.SDKError(error instanceof require_errors_errors.ExecuteStepRetryError ? require_core_transactionState.transactionConflictError() : error instanceof require_errors_baseError.BaseError ? error : new require_errors_errors.UnknownError(error?.message || parsed.message, error), step, action);
|
|
60
|
+
isFinal = false;
|
|
61
|
+
}
|
|
53
62
|
if (!(parsed instanceof require_errors_errors.ExecuteStepRetryError)) {
|
|
54
|
-
if (action) this.statusManager.updateAction(step, action.type, "FAILED", {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
if (action) this.statusManager.updateAction(step, action.type, "FAILED", {
|
|
64
|
+
error: {
|
|
65
|
+
message: parsed.cause?.message,
|
|
66
|
+
code: parsed.code
|
|
67
|
+
},
|
|
68
|
+
...isFinal && { txFinal: true }
|
|
69
|
+
});
|
|
58
70
|
else this.statusManager.updateExecution(step, {
|
|
59
71
|
status: "FAILED",
|
|
60
72
|
error: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseStepExecutor.js","names":["StatusManager","ExecuteStepRetryError"],"sources":["../../../src/core/BaseStepExecutor.ts"],"sourcesContent":["import { ExecuteStepRetryError } from '../errors/errors.js'\nimport
|
|
1
|
+
{"version":3,"file":"BaseStepExecutor.js","names":["StatusManager","isFinalTransactionError","ExecuteStepRetryError","hasStepOpenTransaction","SDKError","transactionConflictError","BaseError","UnknownError"],"sources":["../../../src/core/BaseStepExecutor.ts"],"sourcesContent":["import { BaseError } from '../errors/baseError.js'\nimport { ExecuteStepRetryError, UnknownError } from '../errors/errors.js'\nimport { SDKError } from '../errors/SDKError.js'\nimport type {\n ExecuteStepRetryParams,\n ExecutionAction,\n ExecutionOptions,\n InteractionSettings,\n LiFiStepExtended,\n SDKClient,\n StepExecutor,\n StepExecutorOptions,\n} from '../types/core.js'\nimport type {\n StepExecutorBaseContext,\n StepExecutorContext,\n} from '../types/execution.js'\nimport { StatusManager } from './StatusManager.js'\nimport type { TaskPipeline } from './TaskPipeline.js'\nimport {\n hasStepOpenTransaction,\n isFinalTransactionError,\n transactionConflictError,\n} from './transactionState.js'\n\n// Please be careful when changing the defaults as it may break the behavior (e.g., background execution)\nconst defaultInteractionSettings = {\n allowInteraction: true,\n allowUpdates: true,\n allowExecution: true,\n}\n\nexport abstract class BaseStepExecutor implements StepExecutor {\n protected executionOptions?: ExecutionOptions\n protected statusManager: StatusManager\n\n public allowUserInteraction = true\n public allowExecution = true\n\n constructor(options: StepExecutorOptions) {\n this.statusManager = new StatusManager(options.routeId)\n this.executionOptions = options.executionOptions\n }\n\n setInteraction = (settings?: InteractionSettings): void => {\n const interactionSettings = {\n ...defaultInteractionSettings,\n ...settings,\n }\n this.allowUserInteraction = interactionSettings.allowInteraction\n this.statusManager.allowUpdates(interactionSettings.allowUpdates)\n this.allowExecution = interactionSettings.allowExecution\n }\n\n private createBaseContext = async (\n client: SDKClient,\n step: LiFiStepExtended,\n retryParams?: ExecuteStepRetryParams,\n signal?: AbortSignal\n ): Promise<StepExecutorBaseContext> => {\n const fromChain = await client.getChainById(step.action.fromChainId)\n const toChain = await client.getChainById(step.action.toChainId)\n\n const isBridgeExecution = fromChain.id !== toChain.id\n\n return {\n client,\n step,\n fromChain,\n toChain,\n isBridgeExecution,\n retryParams,\n statusManager: this.statusManager,\n executionOptions: this.executionOptions,\n allowUserInteraction: this.allowUserInteraction,\n signal,\n }\n }\n\n abstract createContext(\n baseContext: StepExecutorBaseContext\n ): Promise<StepExecutorContext>\n\n abstract createPipeline(context: StepExecutorContext): TaskPipeline\n\n abstract parseErrors(\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction,\n retryParams?: ExecuteStepRetryParams\n ): Promise<SDKError | ExecuteStepRetryError>\n\n executeStep = async (\n client: SDKClient,\n step: LiFiStepExtended,\n retryParams?: ExecuteStepRetryParams,\n signal?: AbortSignal\n ): Promise<LiFiStepExtended> => {\n try {\n step.execution = this.statusManager.initializeExecution(step)\n\n const baseContext = await this.createBaseContext(\n client,\n step,\n retryParams,\n signal\n )\n const context = await this.createContext(baseContext)\n const pipeline = this.createPipeline(context)\n\n await pipeline.run(context)\n\n return step\n } catch (error: any) {\n // Derive failing action from last in execution.actions\n const action = step.execution?.actions?.at(-1)\n // Read before parsing: parsers may rebuild the error and drop the marker.\n let isFinal = isFinalTransactionError(error)\n let parsed = await this.parseErrors(error, step, action, retryParams)\n if (\n parsed instanceof ExecuteStepRetryError &&\n hasStepOpenTransaction(step)\n ) {\n // A retry runs the step again on an empty execution, which would erase\n // the hash of a transaction that may still land. Fail with the original\n // error instead, and keep the outcome unknown so a resume re-checks it.\n // A BaseError keeps its code, so the widget shows its text. A replay\n // that a task asked for has no error of its own: it fails as a sign\n // task fails for the same state (`TransactionConflict`).\n parsed = new SDKError(\n error instanceof ExecuteStepRetryError\n ? transactionConflictError()\n : error instanceof BaseError\n ? error\n : new UnknownError(error?.message || parsed.message, error),\n step,\n action\n )\n isFinal = false\n }\n if (!(parsed instanceof ExecuteStepRetryError)) {\n if (action) {\n this.statusManager.updateAction(step, action.type, 'FAILED', {\n error: {\n message: parsed.cause?.message,\n code: parsed.code,\n },\n ...(isFinal && { txFinal: true }),\n })\n } else {\n this.statusManager.updateExecution(step, {\n status: 'FAILED',\n error: {\n message: parsed.cause?.message,\n code: parsed.code,\n },\n })\n }\n }\n throw parsed\n }\n }\n}\n"],"mappings":";;;;;;;AA0BA,MAAM,6BAA6B;CACjC,kBAAkB;CAClB,cAAc;CACd,gBA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yBAAyB,IACzB,iBAAiBC,yBAAAA,YACf,QACA,IAAIC,sBAAAA,aAAa,OAAO,WAAW,OAAO,SAAS,KAAK,GAC9D,MACA,MACF;IACA,UAAU;GACZ;GACA,IAAI,EAAE,kBAAkBL,sBAAAA,wBAAwB;IAC9C,IAAI,QACF,KAAK,cAAc,aAAa,MAAM,OAAO,MAAM,UAAU;KAC3D,OAAO;MACL,SAAS,OAAO,OAAO;MACvB,MAAM,OAAO;KACf;KACA,GAAI,WAAW,EAAE,SAAS,KAAK;IACjC,CAAC;SAED,KAAK,cAAc,gBAAgB,MAAM;KACvC,QAAQ;KACR,OAAO;MACL,SAAS,OAAO,OAAO;MACvB,MAAM,OAAO;KACf;IACF,CAAC;GAEL;GACA,MAAM;EACR;CACF;AACF"}
|
|
@@ -13,6 +13,7 @@ type ActionProps = {
|
|
|
13
13
|
export declare class StatusManager {
|
|
14
14
|
private readonly routeId;
|
|
15
15
|
private shouldUpdate;
|
|
16
|
+
private stoppedExecution?;
|
|
16
17
|
constructor(routeId: string);
|
|
17
18
|
/**
|
|
18
19
|
* Initializes the execution object of a Step.
|
|
@@ -66,6 +67,15 @@ export declare class StatusManager {
|
|
|
66
67
|
}>) => ExecutionAction;
|
|
67
68
|
updateStepInRoute: (step: LiFiStep) => LiFiStep;
|
|
68
69
|
allowUpdates(value: boolean): void;
|
|
70
|
+
/**
|
|
71
|
+
* A write of transaction data after `stopRouteExecution`. With a newer
|
|
72
|
+
* execution of the same route id running, the transaction is merged into
|
|
73
|
+
* it. If no execution of the route started since the stop, the kept route
|
|
74
|
+
* is updated and the kept hook is called. If a newer execution started and
|
|
75
|
+
* ended since the stop, the transaction is merged into the route of the
|
|
76
|
+
* last ended execution, and its hook is called.
|
|
77
|
+
*/
|
|
78
|
+
private deliverLateTransactionData;
|
|
69
79
|
}
|
|
70
80
|
//#endregion
|
|
71
81
|
//# sourceMappingURL=StatusManager.d.ts.map
|
|
@@ -1,13 +1,66 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_core_actionMessages = require("./actionMessages.js");
|
|
3
3
|
const require_core_executionState = require("./executionState.js");
|
|
4
|
+
const require_core_transactionState = require("./transactionState.js");
|
|
4
5
|
//#region src/core/StatusManager.ts
|
|
5
6
|
/**
|
|
7
|
+
* A write is transaction data when it changes one of these fields. `txLink`
|
|
8
|
+
* and `signedAt` travel with such a write but never trigger one: the status
|
|
9
|
+
* poll rewrites `txLink` every few seconds.
|
|
10
|
+
*/
|
|
11
|
+
const TRANSACTION_KEYS = [
|
|
12
|
+
"txHash",
|
|
13
|
+
"txHex",
|
|
14
|
+
"taskId",
|
|
15
|
+
"txFinal"
|
|
16
|
+
];
|
|
17
|
+
const readTransaction = (action) => ({
|
|
18
|
+
txHash: action.txHash,
|
|
19
|
+
txHex: action.txHex,
|
|
20
|
+
taskId: action.taskId,
|
|
21
|
+
txFinal: action.txFinal
|
|
22
|
+
});
|
|
23
|
+
/** True when the write changed a transaction field, also to `undefined`. */
|
|
24
|
+
const changesTransaction = (before, action) => TRANSACTION_KEYS.some((key) => action[key] !== before[key]);
|
|
25
|
+
/**
|
|
26
|
+
* Copies a late transaction into the route of a newer execution of the same
|
|
27
|
+
* route id, running or ended. The step's objects are changed in place: a
|
|
28
|
+
* running executor holds them, so its selector and its pre-sign guard see
|
|
29
|
+
* the transaction. Returns true when something changed.
|
|
30
|
+
*/
|
|
31
|
+
const mergeLateTransaction = (liveRoute, lateStep, lateAction) => {
|
|
32
|
+
if (!require_core_transactionState.hasOpenTransaction(lateAction)) return false;
|
|
33
|
+
const liveStep = liveRoute.steps.find((routeStep) => routeStep.id === lateStep.id);
|
|
34
|
+
if (!liveStep) return false;
|
|
35
|
+
if (!liveStep.execution) liveStep.execution = {
|
|
36
|
+
startedAt: Date.now(),
|
|
37
|
+
status: "PENDING",
|
|
38
|
+
actions: [structuredClone(lateAction)]
|
|
39
|
+
};
|
|
40
|
+
else {
|
|
41
|
+
const liveAction = liveStep.execution.actions.find((action) => action.type === lateAction.type);
|
|
42
|
+
if (!liveAction) liveStep.execution.actions.push(structuredClone(lateAction));
|
|
43
|
+
else if (require_core_transactionState.hasOpenTransaction(liveAction)) return false;
|
|
44
|
+
else Object.assign(liveAction, {
|
|
45
|
+
txHash: lateAction.txHash,
|
|
46
|
+
txLink: lateAction.txLink,
|
|
47
|
+
txHex: lateAction.txHex,
|
|
48
|
+
txFinal: lateAction.txFinal,
|
|
49
|
+
taskId: lateAction.taskId,
|
|
50
|
+
txType: lateAction.txType
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const signedAt = lateStep.execution?.signedAt;
|
|
54
|
+
if (require_core_transactionState.TRANSACTION_ACTION_TYPES.includes(lateAction.type) && signedAt !== void 0) liveStep.execution.signedAt = signedAt;
|
|
55
|
+
return true;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
6
58
|
* Manages status updates of a route and provides various functions for tracking actions.
|
|
7
59
|
*/
|
|
8
60
|
var StatusManager = class {
|
|
9
61
|
routeId;
|
|
10
62
|
shouldUpdate = true;
|
|
63
|
+
stoppedExecution;
|
|
11
64
|
constructor(routeId) {
|
|
12
65
|
this.routeId = routeId;
|
|
13
66
|
}
|
|
@@ -28,7 +81,7 @@ var StatusManager = class {
|
|
|
28
81
|
if (step.execution.status === "FAILED") {
|
|
29
82
|
step.execution.startedAt = Date.now();
|
|
30
83
|
step.execution.status = "PENDING";
|
|
31
|
-
step.execution.signedAt = void 0;
|
|
84
|
+
if (!require_core_transactionState.hasStepOpenTransaction(step)) step.execution.signedAt = void 0;
|
|
32
85
|
step.execution.error = void 0;
|
|
33
86
|
this.updateStepInRoute(step);
|
|
34
87
|
}
|
|
@@ -89,7 +142,11 @@ var StatusManager = class {
|
|
|
89
142
|
* @returns The updated or newly created action.
|
|
90
143
|
*/
|
|
91
144
|
initializeAction = ({ step, type, chainId, status }) => {
|
|
92
|
-
|
|
145
|
+
const action = this.findAction(step, type);
|
|
146
|
+
if (action) return this.updateAction(step, type, status, {
|
|
147
|
+
error: void 0,
|
|
148
|
+
...action.status === "FAILED" && action.txFinal === true && require_core_transactionState.CLEARED_TRANSACTION_FIELDS
|
|
149
|
+
});
|
|
93
150
|
return this.createAction({
|
|
94
151
|
step,
|
|
95
152
|
type,
|
|
@@ -109,6 +166,7 @@ var StatusManager = class {
|
|
|
109
166
|
if (!step.execution) throw new Error("Can't update an empty step execution.");
|
|
110
167
|
const currentAction = this.findAction(step, type);
|
|
111
168
|
if (!currentAction) throw new Error("Can't find an action for the given type.");
|
|
169
|
+
const transactionBefore = this.shouldUpdate ? void 0 : readTransaction(currentAction);
|
|
112
170
|
switch (status) {
|
|
113
171
|
case "CANCELLED": break;
|
|
114
172
|
case "FAILED":
|
|
@@ -131,7 +189,8 @@ var StatusManager = class {
|
|
|
131
189
|
Object.assign(currentAction, rest);
|
|
132
190
|
}
|
|
133
191
|
step.execution.actions = [...step.execution.actions.filter((action) => action.status === "DONE"), ...step.execution.actions.filter((action) => action.status !== "DONE")];
|
|
134
|
-
this.
|
|
192
|
+
if (transactionBefore && changesTransaction(transactionBefore, currentAction)) this.deliverLateTransactionData(step, currentAction);
|
|
193
|
+
else this.updateStepInRoute(step);
|
|
135
194
|
return currentAction;
|
|
136
195
|
};
|
|
137
196
|
updateStepInRoute = (step) => {
|
|
@@ -149,6 +208,49 @@ var StatusManager = class {
|
|
|
149
208
|
};
|
|
150
209
|
allowUpdates(value) {
|
|
151
210
|
this.shouldUpdate = value;
|
|
211
|
+
if (value) {
|
|
212
|
+
this.stoppedExecution = void 0;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const data = require_core_executionState.executionState.get(this.routeId);
|
|
216
|
+
if (data) this.stoppedExecution = {
|
|
217
|
+
route: data.route,
|
|
218
|
+
updateRouteHook: data.executionOptions?.updateRouteHook,
|
|
219
|
+
startCount: require_core_executionState.executionState.startCount(this.routeId)
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* A write of transaction data after `stopRouteExecution`. With a newer
|
|
224
|
+
* execution of the same route id running, the transaction is merged into
|
|
225
|
+
* it. If no execution of the route started since the stop, the kept route
|
|
226
|
+
* is updated and the kept hook is called. If a newer execution started and
|
|
227
|
+
* ended since the stop, the transaction is merged into the route of the
|
|
228
|
+
* last ended execution, and its hook is called.
|
|
229
|
+
*/
|
|
230
|
+
deliverLateTransactionData(step, lateAction) {
|
|
231
|
+
const stopped = this.stoppedExecution;
|
|
232
|
+
if (!stopped) return;
|
|
233
|
+
try {
|
|
234
|
+
const live = require_core_executionState.executionState.get(this.routeId);
|
|
235
|
+
if (live) {
|
|
236
|
+
if (mergeLateTransaction(live.route, step, lateAction)) live.executionOptions?.updateRouteHook?.(live.route);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (require_core_executionState.executionState.startCount(this.routeId) !== stopped.startCount) {
|
|
240
|
+
const ended = require_core_executionState.executionState.lastEnded(this.routeId);
|
|
241
|
+
if (ended && mergeLateTransaction(ended.route, step, lateAction)) ended.updateRouteHook?.(ended.route);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const stepIndex = stopped.route.steps.findIndex((routeStep) => routeStep.id === step.id);
|
|
245
|
+
if (stepIndex === -1) return;
|
|
246
|
+
stopped.route.steps[stepIndex] = {
|
|
247
|
+
...stopped.route.steps[stepIndex],
|
|
248
|
+
...step
|
|
249
|
+
};
|
|
250
|
+
stopped.updateRouteHook?.(stopped.route);
|
|
251
|
+
} catch (error) {
|
|
252
|
+
if (process.env.NODE_ENV === "development") console.debug("Delivering late transaction data failed.", error);
|
|
253
|
+
}
|
|
152
254
|
}
|
|
153
255
|
};
|
|
154
256
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatusManager.js","names":["getActionMessage","executionState"],"sources":["../../../src/core/StatusManager.ts"],"sourcesContent":["import type { ChainId, LiFiStep } from '@lifi/types'\nimport type {\n Execution,\n ExecutionAction,\n ExecutionActionStatus,\n ExecutionActionType,\n LiFiStepExtended,\n} from '../types/core.js'\nimport { getActionMessage } from './actionMessages.js'\nimport { executionState } from './executionState.js'\n\ntype ActionProps = {\n step: LiFiStepExtended\n type: ExecutionActionType\n chainId: ChainId\n status: ExecutionActionStatus\n}\n\n/**\n * Manages status updates of a route and provides various functions for tracking actions.\n */\nexport class StatusManager {\n private readonly routeId: string\n private shouldUpdate = true\n\n constructor(routeId: string) {\n this.routeId = routeId\n }\n\n /**\n * Initializes the execution object of a Step.\n * @param step The current step in execution\n * @returns The initialized execution object for this step\n */\n initializeExecution = (step: LiFiStepExtended): Execution => {\n if (!step.execution) {\n step.execution = {\n startedAt: Date.now(),\n status: 'PENDING',\n actions: [],\n }\n this.updateStepInRoute(step)\n }\n\n // Change status to PENDING after resuming from FAILED\n if (step.execution.status === 'FAILED') {\n step.execution.startedAt = Date.now()\n step.execution.status = 'PENDING'\n step.execution.signedAt = undefined\n step.execution.error = undefined\n this.updateStepInRoute(step)\n }\n\n return step.execution\n }\n\n /**\n * Updates the execution object of a Step.\n * @param step The current step in execution\n * @param execution Partial execution data to merge\n * @returns The step with the updated execution object\n */\n updateExecution(\n step: LiFiStepExtended,\n execution: Partial<Execution>\n ): LiFiStep {\n if (!step.execution) {\n throw Error(\"Can't update empty execution.\")\n }\n step.execution = {\n ...step.execution,\n ...execution,\n }\n this.updateStepInRoute(step)\n return step\n }\n\n /**\n * Finds an action of the specified type in the step's execution\n * @param step The step to search in\n * @param type The action type to find\n * @returns The found action or undefined if not found\n */\n findAction(\n step: LiFiStepExtended,\n type: ExecutionActionType\n ): ExecutionAction | undefined {\n if (!step.execution?.actions) {\n throw new Error(\"Execution hasn't been initialized.\")\n }\n\n const action = step.execution.actions.find((p) => p.type === type)\n\n return action\n }\n\n /**\n * Create and push a new action into the execution.\n * Caller is responsible for ensuring an action of this type does not already exist.\n * @param step The step that should contain the new action.\n * @param type Type of the action.\n * @param chainId Chain Id of the action.\n * @param status The initial status for the new action.\n * @returns The created action.\n */\n createAction = ({\n step,\n type,\n chainId,\n status,\n }: ActionProps): ExecutionAction => {\n if (!step.execution) {\n throw new Error(\"Execution hasn't been initialized.\")\n }\n\n const newAction: ExecutionAction = {\n type,\n message: getActionMessage(type, status),\n status,\n chainId,\n }\n\n step.execution.actions.push(newAction)\n this.updateStepInRoute(step)\n return newAction\n }\n\n /**\n * Find an existing action by type and update it, or create a new one if none exists.\n * @param step The step that should contain the action.\n * @param type Type of the action. Used to identify already existing actions.\n * @param chainId Chain Id of the action (used when creating).\n * @param status The status to set on the found or newly created action.\n * @returns The updated or newly created action.\n */\n initializeAction = ({\n step,\n type,\n chainId,\n status,\n }: ActionProps): ExecutionAction => {\n const action = this.findAction(step, type)\n\n if (action) {\n return this.updateAction(step, type, status, {\n error: undefined,\n })\n }\n\n return this.createAction({ step, type, chainId, status })\n }\n\n /**\n * Update an action object.\n * @param step The step where the action should be updated\n * @param type The action type to update\n * @param status The status the action gets.\n * @param [params] Additional parameters to append to the action.\n * @returns The updated action\n */\n updateAction = (\n step: LiFiStepExtended,\n type: ExecutionActionType,\n status: ExecutionActionStatus,\n params?: Partial<ExecutionAction & { signedAt?: number }>\n ): ExecutionAction => {\n if (!step.execution) {\n throw new Error(\"Can't update an empty step execution.\")\n }\n const currentAction = this.findAction(step, type)\n\n if (!currentAction) {\n throw new Error(\"Can't find an action for the given type.\")\n }\n\n switch (status) {\n case 'CANCELLED':\n break\n case 'FAILED':\n step.execution.status = 'FAILED'\n if (params?.error) {\n step.execution.error = params.error\n }\n break\n case 'DONE':\n break\n case 'PENDING':\n step.execution.status = 'PENDING'\n if (params?.signedAt) {\n step.execution.signedAt = params.signedAt\n }\n break\n case 'RESET_REQUIRED':\n case 'MESSAGE_REQUIRED':\n case 'ACTION_REQUIRED':\n step.execution.status = 'ACTION_REQUIRED'\n break\n default:\n break\n }\n\n currentAction.status = status\n currentAction.message = getActionMessage(type, status)\n // set extra parameters or overwrite the standard params set in the switch statement\n if (params) {\n const { signedAt: _signedAt, ...rest } = params\n Object.assign(currentAction, rest)\n }\n // Sort actions, the ones with DONE status go first\n step.execution.actions = [\n ...step.execution.actions.filter((action) => action.status === 'DONE'),\n ...step.execution.actions.filter((action) => action.status !== 'DONE'),\n ]\n this.updateStepInRoute(step) // updates the step in the route\n return currentAction\n }\n\n updateStepInRoute = (step: LiFiStep): LiFiStep => {\n if (!this.shouldUpdate) {\n return step\n }\n const data = executionState.get(this.routeId)\n\n if (!data) {\n throw new Error('Execution data not found.')\n }\n\n const stepIndex = data.route.steps.findIndex(\n (routeStep) => routeStep.id === step.id\n )\n\n if (stepIndex === -1) {\n throw new Error(\"Couldn't find a step to update.\")\n }\n\n data.route.steps[stepIndex] = { ...data.route.steps[stepIndex], ...step }\n\n data.executionOptions?.updateRouteHook?.(data.route)\n return data.route.steps[stepIndex]\n }\n\n allowUpdates(value: boolean): void {\n this.shouldUpdate = value\n }\n}\n"],"mappings":";;;;;;;AAqBA,IAAa,gBAAb,MAA2B;CACzB;CACA,eAAuB;CAEvB,YAAY,SAAiB;EAC3B,KAAK,UAAU;CACjB;;;;;;CAOA,uBAAuB,SAAsC;EAC3D,IAAI,CAAC,KAAK,WAAW;GACnB,KAAK,YAAY;IACf,WAAW,KAAK,IAAI;IACpB,QAAQ;IACR,SAAS,CAAC;GACZ;GACA,KAAK,kBAAkB,IAAI;EAC7B;EAGA,IAAI,KAAK,UAAU,WAAW,UAAU;GACtC,KAAK,UAAU,YAAY,KAAK,IAAI;GACpC,KAAK,UAAU,SAAS;GACxB,KAAK,UAAU,WAAW,KAAA;GAC1B,KAAK,UAAU,QAAQ,KAAA;GACvB,KAAK,kBAAkB,IAAI;EAC7B;EAEA,OAAO,KAAK;CACd;;;;;;;CAQA,gBACE,MACA,WACU;EACV,IAAI,CAAC,KAAK,WACR,MAAM,MAAM,+BAA+B;EAE7C,KAAK,YAAY;GACf,GAAG,KAAK;GACR,GAAG;EACL;EACA,KAAK,kBAAkB,IAAI;EAC3B,OAAO;CACT;;;;;;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,MAAM,EAAE,UAAU,WAAW,GAAG,SAAS;GACzC,OAAO,OAAO,eAAe,IAAI;EACnC;EAEA,KAAK,UAAU,UAAU,CACvB,GAAG,KAAK,UAAU,QAAQ,QAAQ,WAAW,OAAO,WAAW,MAAM,GACrE,GAAG,KAAK,UAAU,QAAQ,QAAQ,WAAW,OAAO,WAAW,MAAM,CACvE;EACA,KAAK,kBAAkB,IAAI;EAC3B,OAAO;CACT;CAEA,qBAAqB,SAA6B;EAChD,IAAI,CAAC,KAAK,cACR,OAAO;EAET,MAAM,OAAOC,4BAAAA,eAAe,IAAI,KAAK,OAAO;EAE5C,IAAI,CAAC,MACH,MAAM,IAAI,MAAM,2BAA2B;EAG7C,MAAM,YAAY,KAAK,MAAM,MAAM,WAChC,cAAc,UAAU,OAAO,KAAK,EACvC;EAEA,IAAI,cAAc,IAChB,MAAM,IAAI,MAAM,iCAAiC;EAGnD,KAAK,MAAM,MAAM,aAAa;GAAE,GAAG,KAAK,MAAM,MAAM;GAAY,GAAG;EAAK;EAExE,KAAK,kBAAkB,kBAAkB,KAAK,KAAK;EACnD,OAAO,KAAK,MAAM,MAAM;CAC1B;CAEA,aAAa,OAAsB;EACjC,KAAK,eAAe;CACtB;AACF"}
|
|
1
|
+
{"version":3,"file":"StatusManager.js","names":["hasOpenTransaction","TRANSACTION_ACTION_TYPES","hasStepOpenTransaction","getActionMessage","CLEARED_TRANSACTION_FIELDS","executionState"],"sources":["../../../src/core/StatusManager.ts"],"sourcesContent":["import type { ChainId, LiFiStep } from '@lifi/types'\nimport type {\n Execution,\n ExecutionAction,\n ExecutionActionStatus,\n ExecutionActionType,\n LiFiStepExtended,\n RouteExtended,\n UpdateRouteHook,\n} from '../types/core.js'\nimport { getActionMessage } from './actionMessages.js'\nimport { executionState } from './executionState.js'\nimport {\n CLEARED_TRANSACTION_FIELDS,\n hasOpenTransaction,\n hasStepOpenTransaction,\n TRANSACTION_ACTION_TYPES,\n} from './transactionState.js'\n\ntype ActionProps = {\n step: LiFiStepExtended\n type: ExecutionActionType\n chainId: ChainId\n status: ExecutionActionStatus\n}\n\n/**\n * The route and hook of an execution that `stopRouteExecution` ended. A task\n * that was still running (e.g. waiting in the wallet prompt) writes its\n * transaction data later; without these the write would never reach the\n * integrator, and a resume of the stored route would sign again.\n * `startCount` is `executionState.startCount` at the stop.\n */\ntype StoppedExecution = {\n route: RouteExtended\n updateRouteHook?: UpdateRouteHook\n startCount: number\n}\n\n/**\n * A write is transaction data when it changes one of these fields. `txLink`\n * and `signedAt` travel with such a write but never trigger one: the status\n * poll rewrites `txLink` every few seconds.\n */\nconst TRANSACTION_KEYS = ['txHash', 'txHex', 'taskId', 'txFinal'] as const\n\ntype TransactionFields = Pick<\n ExecutionAction,\n (typeof TRANSACTION_KEYS)[number]\n>\n\nconst readTransaction = (action: ExecutionAction): TransactionFields => ({\n txHash: action.txHash,\n txHex: action.txHex,\n taskId: action.taskId,\n txFinal: action.txFinal,\n})\n\n/** True when the write changed a transaction field, also to `undefined`. */\nconst changesTransaction = (\n before: TransactionFields,\n action: ExecutionAction\n): boolean => TRANSACTION_KEYS.some((key) => action[key] !== before[key])\n\n/**\n * Copies a late transaction into the route of a newer execution of the same\n * route id, running or ended. The step's objects are changed in place: a\n * running executor holds them, so its selector and its pre-sign guard see\n * the transaction. Returns true when something changed.\n */\nconst mergeLateTransaction = (\n liveRoute: RouteExtended,\n lateStep: LiFiStepExtended,\n lateAction: ExecutionAction\n): boolean => {\n // Cleared or final: the newer execution needs nothing from it.\n if (!hasOpenTransaction(lateAction)) {\n return false\n }\n const liveStep = liveRoute.steps.find(\n (routeStep) => routeStep.id === lateStep.id\n )\n if (!liveStep) {\n return false\n }\n if (!liveStep.execution) {\n liveStep.execution = {\n startedAt: Date.now(),\n status: 'PENDING',\n actions: [structuredClone(lateAction)],\n }\n } else {\n const liveAction = liveStep.execution.actions.find(\n (action) => action.type === lateAction.type\n )\n if (!liveAction) {\n liveStep.execution.actions.push(structuredClone(lateAction))\n } else if (hasOpenTransaction(liveAction)) {\n // The live action already has an open transaction (its own, or one\n // merged earlier); it is kept.\n return false\n } else {\n // All five fields, so a stale `txFinal` goes and the action is open.\n // `txType` goes with them: the live one described no open transaction.\n Object.assign(liveAction, {\n txHash: lateAction.txHash,\n txLink: lateAction.txLink,\n txHex: lateAction.txHex,\n txFinal: lateAction.txFinal,\n taskId: lateAction.taskId,\n txType: lateAction.txType,\n })\n }\n }\n // `signedAt` is the signing time of the step's own transaction: an\n // allowance does not set it, and a write without one keeps the live time.\n const signedAt = lateStep.execution?.signedAt\n if (\n TRANSACTION_ACTION_TYPES.includes(lateAction.type) &&\n signedAt !== undefined\n ) {\n liveStep.execution.signedAt = signedAt\n }\n return true\n}\n\n/**\n * Manages status updates of a route and provides various functions for tracking actions.\n */\nexport class StatusManager {\n private readonly routeId: string\n private shouldUpdate = true\n private stoppedExecution?: StoppedExecution\n\n constructor(routeId: string) {\n this.routeId = routeId\n }\n\n /**\n * Initializes the execution object of a Step.\n * @param step The current step in execution\n * @returns The initialized execution object for this step\n */\n initializeExecution = (step: LiFiStepExtended): Execution => {\n if (!step.execution) {\n step.execution = {\n startedAt: Date.now(),\n status: 'PENDING',\n actions: [],\n }\n this.updateStepInRoute(step)\n }\n\n // Change status to PENDING after resuming from FAILED\n if (step.execution.status === 'FAILED') {\n step.execution.startedAt = Date.now()\n step.execution.status = 'PENDING'\n // Keep the signing time while a signed transaction may still land: the\n // resume path uses it to decide when stored bytes are too old to resend\n // or old enough to be declared dropped.\n if (!hasStepOpenTransaction(step)) {\n step.execution.signedAt = undefined\n }\n step.execution.error = undefined\n this.updateStepInRoute(step)\n }\n\n return step.execution\n }\n\n /**\n * Updates the execution object of a Step.\n * @param step The current step in execution\n * @param execution Partial execution data to merge\n * @returns The step with the updated execution object\n */\n updateExecution(\n step: LiFiStepExtended,\n execution: Partial<Execution>\n ): LiFiStep {\n if (!step.execution) {\n throw Error(\"Can't update empty execution.\")\n }\n step.execution = {\n ...step.execution,\n ...execution,\n }\n this.updateStepInRoute(step)\n return step\n }\n\n /**\n * Finds an action of the specified type in the step's execution\n * @param step The step to search in\n * @param type The action type to find\n * @returns The found action or undefined if not found\n */\n findAction(\n step: LiFiStepExtended,\n type: ExecutionActionType\n ): ExecutionAction | undefined {\n if (!step.execution?.actions) {\n throw new Error(\"Execution hasn't been initialized.\")\n }\n\n const action = step.execution.actions.find((p) => p.type === type)\n\n return action\n }\n\n /**\n * Create and push a new action into the execution.\n * Caller is responsible for ensuring an action of this type does not already exist.\n * @param step The step that should contain the new action.\n * @param type Type of the action.\n * @param chainId Chain Id of the action.\n * @param status The initial status for the new action.\n * @returns The created action.\n */\n createAction = ({\n step,\n type,\n chainId,\n status,\n }: ActionProps): ExecutionAction => {\n if (!step.execution) {\n throw new Error(\"Execution hasn't been initialized.\")\n }\n\n const newAction: ExecutionAction = {\n type,\n message: getActionMessage(type, status),\n status,\n chainId,\n }\n\n step.execution.actions.push(newAction)\n this.updateStepInRoute(step)\n return newAction\n }\n\n /**\n * Find an existing action by type and update it, or create a new one if none exists.\n * @param step The step that should contain the action.\n * @param type Type of the action. Used to identify already existing actions.\n * @param chainId Chain Id of the action (used when creating).\n * @param status The status to set on the found or newly created action.\n * @returns The updated or newly created action.\n */\n initializeAction = ({\n step,\n type,\n chainId,\n status,\n }: ActionProps): ExecutionAction => {\n const action = this.findAction(step, type)\n\n if (action) {\n return this.updateAction(step, type, status, {\n error: undefined,\n // A final outcome is dead. A new attempt starts without its data, so\n // the pre-sign guard does not mistake it for an open transaction (the\n // route was run again without `prepareRestart`, e.g. `executeRoute`).\n ...(action.status === 'FAILED' &&\n action.txFinal === true &&\n CLEARED_TRANSACTION_FIELDS),\n })\n }\n\n return this.createAction({ step, type, chainId, status })\n }\n\n /**\n * Update an action object.\n * @param step The step where the action should be updated\n * @param type The action type to update\n * @param status The status the action gets.\n * @param [params] Additional parameters to append to the action.\n * @returns The updated action\n */\n updateAction = (\n step: LiFiStepExtended,\n type: ExecutionActionType,\n status: ExecutionActionStatus,\n params?: Partial<ExecutionAction & { signedAt?: number }>\n ): ExecutionAction => {\n if (!step.execution) {\n throw new Error(\"Can't update an empty step execution.\")\n }\n const currentAction = this.findAction(step, type)\n\n if (!currentAction) {\n throw new Error(\"Can't find an action for the given type.\")\n }\n // Read before the write: after a stop, only a write that changes the\n // transaction reaches the integrator.\n const transactionBefore = this.shouldUpdate\n ? undefined\n : readTransaction(currentAction)\n\n switch (status) {\n case 'CANCELLED':\n break\n case 'FAILED':\n step.execution.status = 'FAILED'\n if (params?.error) {\n step.execution.error = params.error\n }\n break\n case 'DONE':\n break\n case 'PENDING':\n step.execution.status = 'PENDING'\n if (params?.signedAt) {\n step.execution.signedAt = params.signedAt\n }\n break\n case 'RESET_REQUIRED':\n case 'MESSAGE_REQUIRED':\n case 'ACTION_REQUIRED':\n step.execution.status = 'ACTION_REQUIRED'\n break\n default:\n break\n }\n\n currentAction.status = status\n currentAction.message = getActionMessage(type, status)\n // set extra parameters or overwrite the standard params set in the switch statement\n if (params) {\n const { signedAt: _signedAt, ...rest } = params\n Object.assign(currentAction, rest)\n }\n // Sort actions, the ones with DONE status go first\n step.execution.actions = [\n ...step.execution.actions.filter((action) => action.status === 'DONE'),\n ...step.execution.actions.filter((action) => action.status !== 'DONE'),\n ]\n if (\n transactionBefore &&\n changesTransaction(transactionBefore, currentAction)\n ) {\n this.deliverLateTransactionData(step, currentAction)\n } else {\n this.updateStepInRoute(step) // updates the step in the route\n }\n return currentAction\n }\n\n updateStepInRoute = (step: LiFiStep): LiFiStep => {\n if (!this.shouldUpdate) {\n return step\n }\n const data = executionState.get(this.routeId)\n\n if (!data) {\n throw new Error('Execution data not found.')\n }\n\n const stepIndex = data.route.steps.findIndex(\n (routeStep) => routeStep.id === step.id\n )\n\n if (stepIndex === -1) {\n throw new Error(\"Couldn't find a step to update.\")\n }\n\n // A shallow copy on purpose: the route's step must keep sharing the\n // step's `execution` object. `mergeLateTransaction` changes the live\n // route in place, and the running sign task's check after the wallet\n // must see the merge (pinned by the stop-and-resume race test in\n // `sdk-provider-ethereum/src/core/flows/reload.unit.spec.ts`).\n data.route.steps[stepIndex] = { ...data.route.steps[stepIndex], ...step }\n\n data.executionOptions?.updateRouteHook?.(data.route)\n return data.route.steps[stepIndex]\n }\n\n allowUpdates(value: boolean): void {\n this.shouldUpdate = value\n if (value) {\n this.stoppedExecution = undefined\n return\n }\n // `stopRouteExecution` turns updates off right before it deletes the\n // execution state, so the state is still here to keep.\n const data = executionState.get(this.routeId)\n if (data) {\n this.stoppedExecution = {\n route: data.route,\n updateRouteHook: data.executionOptions?.updateRouteHook,\n startCount: executionState.startCount(this.routeId),\n }\n }\n }\n\n /**\n * A write of transaction data after `stopRouteExecution`. With a newer\n * execution of the same route id running, the transaction is merged into\n * it. If no execution of the route started since the stop, the kept route\n * is updated and the kept hook is called. If a newer execution started and\n * ended since the stop, the transaction is merged into the route of the\n * last ended execution, and its hook is called.\n */\n private deliverLateTransactionData(\n step: LiFiStepExtended,\n lateAction: ExecutionAction\n ): void {\n const stopped = this.stoppedExecution\n if (!stopped) {\n return\n }\n // A late write must never fail the task that made it: its catch block\n // would mark the action FAILED while the transaction may still land.\n try {\n // Always a newer execution: `stopRouteExecution` deleted this one.\n const live = executionState.get(this.routeId)\n if (live) {\n if (mergeLateTransaction(live.route, step, lateAction)) {\n live.executionOptions?.updateRouteHook?.(live.route)\n }\n return\n }\n // A newer execution started and ended since the stop: the integrator\n // stored its route, which the kept one would roll back. The late\n // transaction goes into that route instead. With the records of the\n // route freed (no run in flight, `startCount` 0) the write is dropped.\n if (executionState.startCount(this.routeId) !== stopped.startCount) {\n const ended = executionState.lastEnded(this.routeId)\n if (ended && mergeLateTransaction(ended.route, step, lateAction)) {\n ended.updateRouteHook?.(ended.route)\n }\n return\n }\n const stepIndex = stopped.route.steps.findIndex(\n (routeStep) => routeStep.id === step.id\n )\n if (stepIndex === -1) {\n return\n }\n stopped.route.steps[stepIndex] = {\n ...stopped.route.steps[stepIndex],\n ...step,\n }\n stopped.updateRouteHook?.(stopped.route)\n } catch (error) {\n // Not rethrown, see above. The integrator's hook can throw here, so\n // the error is reported in development, as other swallowed errors are.\n if (process.env.NODE_ENV === 'development') {\n console.debug('Delivering late transaction data failed.', error)\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;AA4CA,MAAM,mBAAmB;CAAC;CAAU;CAAS;CAAU;AAAS;AAOhE,MAAM,mBAAmB,YAAgD;CACvE,QAAQ,OAAO;CACf,OAAO,OAAO;CACd,QAAQ,OAAO;CACf,SAAS,OAAO;AAClB;;AAGA,MAAM,sBACJ,QACA,WACY,iBAAiB,MAAM,QAAQ,OAAO,SAAS,OAAO,IAAI;;;;;;;AAQxE,MAAM,wBACJ,WACA,UACA,eACY;CAEZ,IAAI,CAACA,8BAAAA,mBAAmB,UAAU,GAChC,OAAO;CAET,MAAM,WAAW,UAAU,MAAM,MAC9B,cAAc,UAAU,OAAO,SAAS,EAC3C;CACA,IAAI,CAAC,UACH,OAAO;CAET,IAAI,CAAC,SAAS,WACZ,SAAS,YAAY;EACnB,WAAW,KAAK,IAAI;EACpB,QAAQ;EACR,SAAS,CAAC,gBAAgB,UAAU,CAAC;CACvC;MACK;EACL,MAAM,aAAa,SAAS,UAAU,QAAQ,MAC3C,WAAW,OAAO,SAAS,WAAW,IACzC;EACA,IAAI,CAAC,YACH,SAAS,UAAU,QAAQ,KAAK,gBAAgB,UAAU,CAAC;OACtD,IAAIA,8BAAAA,mBAAmB,UAAU,GAGtC,OAAO;OAIP,OAAO,OAAO,YAAY;GACxB,QAAQ,WAAW;GACnB,QAAQ,WAAW;GACnB,OAAO,WAAW;GAClB,SAAS,WAAW;GACpB,QAAQ,WAAW;GACnB,QAAQ,WAAW;EACrB,CAAC;CAEL;CAGA,MAAM,WAAW,SAAS,WAAW;CACrC,IACEC,8BAAAA,yBAAyB,SAAS,WAAW,IAAI,KACjD,aAAa,KAAA,GAEb,SAAS,UAAU,WAAW;CAEhC,OAAO;AACT;;;;AAKA,IAAa,g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,MAAM,MAAM,aAAa;IAC/B,GAAG,QAAQ,MAAM,MAAM;IACvB,GAAG;GACL;GACA,QAAQ,kBAAkB,QAAQ,KAAK;EACzC,SAAS,OAAO;GAGd,IAAI,QAAQ,IAAI,aAAa,eAC3B,QAAQ,MAAM,4CAA4C,KAAK;EAEnE;CACF;AACF"}
|
|
@@ -44,13 +44,20 @@ const resumeRoute = async (client, route, executionOptions) => {
|
|
|
44
44
|
return execution.promise;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
const restartRoute = structuredClone(route);
|
|
48
|
+
require_core_prepareRestart.prepareRestart(restartRoute);
|
|
49
|
+
return executeRoute(client, restartRoute, executionOptions);
|
|
49
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* True while `route` is the execution registered for its id. A stopped run
|
|
53
|
+
* keeps going until its step ends; it must not stop or delete a newer
|
|
54
|
+
* execution of the same route.
|
|
55
|
+
*/
|
|
56
|
+
const ownsExecution = (route) => require_core_executionState.executionState.get(route.id)?.route === route;
|
|
50
57
|
const executeSteps = async (client, route) => {
|
|
51
58
|
for (let index = 0; index < route.steps.length; index++) {
|
|
52
59
|
const execution = require_core_executionState.executionState.get(route.id);
|
|
53
|
-
if (!execution) break;
|
|
60
|
+
if (!execution || execution.route !== route) break;
|
|
54
61
|
const step = route.steps[index];
|
|
55
62
|
const previousStep = route.steps[index - 1];
|
|
56
63
|
if (step.execution?.status === "DONE") continue;
|
|
@@ -67,25 +74,33 @@ const executeSteps = async (client, route) => {
|
|
|
67
74
|
routeId: route.id,
|
|
68
75
|
executionOptions: execution.executionOptions
|
|
69
76
|
});
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
if (!ownsExecution(route)) return route;
|
|
78
|
+
require_core_executionState.executionState.retain(route.id);
|
|
79
|
+
const { signal } = execution.abortController;
|
|
72
80
|
let executedStep;
|
|
73
81
|
try {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
execution.executors.push(stepExecutor);
|
|
83
|
+
if (execution.executionOptions) updateRouteExecution(route, execution.executionOptions);
|
|
84
|
+
try {
|
|
85
|
+
executedStep = await stepExecutor.executeStep(client, step, void 0, signal);
|
|
86
|
+
} catch (e) {
|
|
87
|
+
if (e instanceof require_errors_errors.ExecuteStepRetryError) {
|
|
88
|
+
if (!stepExecutor.allowExecution) return route;
|
|
89
|
+
step.execution = void 0;
|
|
90
|
+
executedStep = await stepExecutor.executeStep(client, step, e.retryParams, signal);
|
|
91
|
+
} else throw e;
|
|
92
|
+
}
|
|
93
|
+
} finally {
|
|
94
|
+
require_core_executionState.executionState.release(route.id);
|
|
80
95
|
}
|
|
81
|
-
if (executedStep.execution?.status !== "DONE") stopRouteExecution(route);
|
|
96
|
+
if (executedStep.execution?.status !== "DONE" && ownsExecution(route)) stopRouteExecution(route);
|
|
82
97
|
if (!stepExecutor.allowExecution) return route;
|
|
83
98
|
} catch (e) {
|
|
84
|
-
stopRouteExecution(route);
|
|
99
|
+
if (ownsExecution(route)) stopRouteExecution(route);
|
|
85
100
|
throw e;
|
|
86
101
|
}
|
|
87
102
|
}
|
|
88
|
-
require_core_executionState.executionState.delete(route.id);
|
|
103
|
+
if (ownsExecution(route)) require_core_executionState.executionState.delete(route.id);
|
|
89
104
|
return route;
|
|
90
105
|
};
|
|
91
106
|
/**
|
|
@@ -119,6 +134,7 @@ const stopRouteExecution = (route) => {
|
|
|
119
134
|
allowExecution: false
|
|
120
135
|
});
|
|
121
136
|
require_core_executionState.executionState.delete(route.id);
|
|
137
|
+
execution.abortController.abort();
|
|
122
138
|
return execution.route;
|
|
123
139
|
};
|
|
124
140
|
/**
|