@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
package/dist/esm/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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","names":[],"sources":["../../../src/types/core.ts"],"mappings":";;;;YAmBY,sBACV,SAAS,wBACN,sBAAsB,QAAQ;iBAElB;EACf;EACA;EACA;EACA;EACA,eAAe;EACf,mBAAmB;EACnB,SAAS;EACT;EACA;EACA;EACA;EACA;EACA,qBAAqB;EACrB,UAAU;;iBAGK,kBACP,QAAQ,KAAK;EACrB;;;;;;EAMA,UAAU;EACV,YAAY;;;;;iBAMG;;;;;EAKf;;;;;;;;;;EAUA;;;;;;;;;EASA;;;;;;YAOU,gBAAgB,QAAQ,OAAO,oBAAoB;;YAGnD,UAAU,QAAQ,OAAO;iBAEpB;WACN,MAAM
|
|
1
|
+
{"version":3,"file":"core.d.ts","names":[],"sources":["../../../src/types/core.ts"],"mappings":";;;;YAmBY,sBACV,SAAS,wBACN,sBAAsB,QAAQ;iBAElB;EACf;EACA;EACA;EACA;EACA,eAAe;EACf,mBAAmB;EACnB,SAAS;EACT;EACA;EACA;EACA;EACA;EACA,qBAAqB;EACrB,UAAU;;iBAGK,kBACP,QAAQ,KAAK;EACrB;;;;;;EAMA,UAAU;EACV,YAAY;;;;;iBAMG;;;;;EAKf;;;;;;;;;;EAUA;;;;;;;;;EASA;;;;;;YAOU,gBAAgB,QAAQ,OAAO,oBAAoB;;YAGnD,UAAU,QAAQ,OAAO;iBAEpB;WACN,MAAM;;;;;WAKN,oBAAoB;;;;;;;EAO7B,UAAU,iBAAiB,UAAU;;;;;;EAMrC,gBAAgB;EAChB,eACE,cACA,QAAQ,WACR,UAAU,SACV,QAAQ,UACP;EACH,gBAAgB,SAAS,sBAAsB,QAAQ;EACvD,WACE,QAAQ,WACR,uBACA,QAAQ,UACP,QAAQ;;iBAGI;EACf,QAAQ;EACR,WAAW;EACX,YAAY,MAAM,WAAW,UAAU,UAAU;EACjD,aAAa,WAAW;EACxB,UAAU,QAAQ;EAClB,aAAa,QAAQ;EACrB,aAAa,SAAS,UAAU,QAAQ;EACxC,cAAc,QAAQ;EACtB,oBAAoB,SAAS,UAAU;;;;;;;;EAQvC,0BAA0B,SAAS,UAAU;;;;;;EAM7C,2BAA2B,SAAS,UAAU;;iBAG/B;EACf;EACA,mBAAmB;;iBAGJ;EACf;EACA;EACA;;;;;;YAOU,yBAAyB;iBAEpB;EACf;EACA;EACA,eAAe,WAAW;;;;;EAK1B,YACE,QAAQ,WACR,MAAM,kBACN,cAAc,wBACd,SAAS,cACR,QAAQ;;iBAGI;EACf,OAAO;EACP,WAAW;EACX,mBAAmB;;YAGT,+BAA+B,QACzC,eAAe;iBAGA,sBAAsB,KAAK;EAC1C,OAAO;;iBAGQ,yBAAyB;EACxC,YAAY;;YAGF,eAAe;EACzB,YAAY;;YAGF;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;YAGU,2BAA2B,QAAQ,eAAe,QAAQ;;;;;;;;;;;;;YAc1D,mBAAmB,cAAc;iBAE5B,qCAAqC;EACpD;;YAGU,gCACV,kBAAkB,iCACf,QAAQ;iBAEI;EACf,SAAS;EACT;EACA;EACA;EACA;;YAGU,4BACV,QAAQ,mCACL;iBAEY;EACf,SAAS;EACT;EACA;;YAGU,gCACV,QAAQ,6BACL;iBAEY;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe;EACf;EACA;;iBAGe;EACf,eAAe;EACf;EACA,eAAe;;YAGL,wBACV,QAAQ,uBACL,QAAQ;iBAEI;EACf,+BAA+B;;;;;;EAM/B,kBAAkB;EAClB,+BAA+B;EAC/B,mBAAmB;EACnB;EACA;;YAGU;YAEA;YAUA;YAUA;EACV,MAAM;EACN,QAAQ;EACR;EACA,YAAY;EACZ;EACA;EACA;EACA;EACA;EACA,SAAS;;;;;;;EAOT;;;;;;;;EAQA;EAEA;IAAU;IAAuB;IAAiB;;;iBAGnC;EACf;EACA;EACA,QAAQ;EACR,SAAS,MAAM;EACf;EACA;EACA,UAAU;EACV,WAAW;EACX,WAAW;EACX;EACA;EAEA;IAAU;IAAuB;IAAiB;;;YAGxC"}
|
|
@@ -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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution.d.ts","names":[],"sources":["../../../src/types/execution.ts"],"mappings":";;;;iBASiB;EACf,eAAe;EACf,mBAAmB;EACnB,WAAW;EACX,SAAS;EACT;EACA,QAAQ;EACR,MAAM;EACN;EACA,cAAc;;
|
|
1
|
+
{"version":3,"file":"execution.d.ts","names":[],"sources":["../../../src/types/execution.ts"],"mappings":";;;;iBASiB;EACf,eAAe;EACf,mBAAmB;EACnB,WAAW;EACX,SAAS;EACT;EACA,QAAQ;EACR,MAAM;EACN;EACA,cAAc;;;;;;;;EAQd,SAAS;;iBAGM,4BAA4B;EAC3C;;iBAGe,WAAW,WAAW;EACrC,QAAQ;;EAER,UAAU;;YAGA"}
|
|
@@ -4,7 +4,7 @@ const checkPackageUpdates = async (packageName, packageVersion) => {
|
|
|
4
4
|
try {
|
|
5
5
|
const pkgName = packageName ?? "@lifi/sdk";
|
|
6
6
|
const latestVersion = (await (await fetch(`https://registry.npmjs.org/${pkgName}/latest`)).json()).version;
|
|
7
|
-
const currentVersion = packageVersion ?? "4.
|
|
7
|
+
const currentVersion = packageVersion ?? "4.11.0";
|
|
8
8
|
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}.`);
|
|
9
9
|
} catch (_error) {}
|
|
10
10
|
};
|
|
@@ -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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForResult.d.ts","names":[],"sources":["../../../src/utils/waitForResult.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"waitForResult.d.ts","names":[],"sources":["../../../src/utils/waitForResult.ts"],"mappings":";;;;;;;;;;;;qBAca,gBAAuB,GAClC,UAAU,QAAQ,gBAClB,sBAAqB,0BACrB,qBACA,eAAc,eAAe,4BAC7B,SAAS,gBACR,QAAQ"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getAbortError } from "./abort.js";
|
|
1
2
|
import { sleep } from "./sleep.js";
|
|
2
3
|
//#region src/utils/waitForResult.ts
|
|
3
4
|
/**
|
|
@@ -6,26 +7,30 @@ import { sleep } from "./sleep.js";
|
|
|
6
7
|
* @param interval The timeout in milliseconds between retries, or a function that receives the current poll count and returns the interval. Defaults to 5000
|
|
7
8
|
* @param maxRetries Maximum number of calls that throw before the error is rethrown, defaults to 3
|
|
8
9
|
* @param shouldRetry Optional predicate to determine if an error should trigger a retry
|
|
10
|
+
* @param signal Optional signal that ends the wait: no call starts after it aborts, and the sleep between calls ends at once
|
|
9
11
|
* @returns The result of the fn function
|
|
10
12
|
* @throws The error of fn if maximum retries is reached, or if shouldRetry returns false
|
|
13
|
+
* @throws The abort reason of `signal` once it aborts
|
|
11
14
|
*/
|
|
12
|
-
const waitForResult = async (fn, interval = 5e3, maxRetries = 3, shouldRetry = () => true) => {
|
|
15
|
+
const waitForResult = async (fn, interval = 5e3, maxRetries = 3, shouldRetry = () => true, signal) => {
|
|
13
16
|
let result;
|
|
14
17
|
let attempts = 0;
|
|
15
18
|
let polls = 0;
|
|
16
19
|
const getInterval = typeof interval === "function" ? interval : () => interval;
|
|
17
|
-
while (!result)
|
|
18
|
-
|
|
20
|
+
while (!result) {
|
|
21
|
+
if (signal?.aborted) throw getAbortError(signal);
|
|
22
|
+
try {
|
|
23
|
+
result = await fn();
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if (signal?.aborted) throw getAbortError(signal);
|
|
26
|
+
if (!shouldRetry(attempts, error)) throw error;
|
|
27
|
+
attempts++;
|
|
28
|
+
if (attempts === maxRetries) throw error;
|
|
29
|
+
}
|
|
19
30
|
if (!result) {
|
|
20
|
-
await sleep(getInterval(polls));
|
|
31
|
+
await sleep(getInterval(polls), { signal });
|
|
21
32
|
polls++;
|
|
22
33
|
}
|
|
23
|
-
} catch (error) {
|
|
24
|
-
if (!shouldRetry(attempts, error)) throw error;
|
|
25
|
-
attempts++;
|
|
26
|
-
if (attempts === maxRetries) throw error;
|
|
27
|
-
await sleep(getInterval(polls));
|
|
28
|
-
polls++;
|
|
29
34
|
}
|
|
30
35
|
return result;
|
|
31
36
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForResult.js","names":[],"sources":["../../../src/utils/waitForResult.ts"],"sourcesContent":["import { sleep } from './sleep.js'\n\n/**\n * Repeatedly calls a given asynchronous function until it resolves with a truthy value\n * @param fn The function that should be repeated. A falsy result means \"no result yet\" and polls again, with no limit on the number of polls\n * @param interval The timeout in milliseconds between retries, or a function that receives the current poll count and returns the interval. Defaults to 5000\n * @param maxRetries Maximum number of calls that throw before the error is rethrown, defaults to 3\n * @param shouldRetry Optional predicate to determine if an error should trigger a retry\n * @returns The result of the fn function\n * @throws The error of fn if maximum retries is reached, or if shouldRetry returns false\n */\nexport const waitForResult = async <T>(\n fn: () => Promise<T | undefined>,\n interval: number | ((poll: number) => number) = 5000,\n maxRetries = 3,\n shouldRetry: (count: number, error: unknown) => boolean = () => true\n): Promise<T> => {\n let result: T | undefined\n let attempts = 0\n let polls = 0\n\n const getInterval = typeof interval === 'function' ? interval : () => interval\n\n while (!result) {\n try {\n result = await fn()\n if (
|
|
1
|
+
{"version":3,"file":"waitForResult.js","names":[],"sources":["../../../src/utils/waitForResult.ts"],"sourcesContent":["import { getAbortError } from './abort.js'\nimport { sleep } from './sleep.js'\n\n/**\n * Repeatedly calls a given asynchronous function until it resolves with a truthy value\n * @param fn The function that should be repeated. A falsy result means \"no result yet\" and polls again, with no limit on the number of polls\n * @param interval The timeout in milliseconds between retries, or a function that receives the current poll count and returns the interval. Defaults to 5000\n * @param maxRetries Maximum number of calls that throw before the error is rethrown, defaults to 3\n * @param shouldRetry Optional predicate to determine if an error should trigger a retry\n * @param signal Optional signal that ends the wait: no call starts after it aborts, and the sleep between calls ends at once\n * @returns The result of the fn function\n * @throws The error of fn if maximum retries is reached, or if shouldRetry returns false\n * @throws The abort reason of `signal` once it aborts\n */\nexport const waitForResult = async <T>(\n fn: () => Promise<T | undefined>,\n interval: number | ((poll: number) => number) = 5000,\n maxRetries = 3,\n shouldRetry: (count: number, error: unknown) => boolean = () => true,\n signal?: AbortSignal\n): Promise<T> => {\n let result: T | undefined\n let attempts = 0\n let polls = 0\n\n const getInterval = typeof interval === 'function' ? interval : () => interval\n\n while (!result) {\n if (signal?.aborted) {\n throw getAbortError(signal)\n }\n try {\n result = await fn()\n } catch (error) {\n // An error of a call that the abort cut short is not a reason to retry.\n if (signal?.aborted) {\n throw getAbortError(signal)\n }\n if (!shouldRetry(attempts, error)) {\n throw error\n }\n attempts++\n if (attempts === maxRetries) {\n throw error\n }\n }\n if (!result) {\n // Rejects at once, also when the signal aborted during the call.\n await sleep(getInterval(polls), { signal })\n polls++\n }\n }\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,gBAAgB,OAC3B,IACA,WAAgD,KAChD,aAAa,GACb,oBAAgE,MAChE,WACe;CACf,IAAI;CACJ,IAAI,WAAW;CACf,IAAI,QAAQ;CAEZ,MAAM,cAAc,OAAO,aAAa,aAAa,iBAAiB;CAEtE,OAAO,CAAC,QAAQ;EACd,IAAI,QAAQ,SACV,MAAM,cAAc,MAAM;EAE5B,IAAI;GACF,SAAS,MAAM,GAAG;EACpB,SAAS,OAAO;GAEd,IAAI,QAAQ,SACV,MAAM,cAAc,MAAM;GAE5B,IAAI,CAAC,YAAY,UAAU,KAAK,GAC9B,MAAM;GAER;GACA,IAAI,aAAa,YACf,MAAM;EAEV;EACA,IAAI,CAAC,QAAQ;GAEX,MAAM,MAAM,YAAY,KAAK,GAAG,EAAE,OAAO,CAAC;GAC1C;EACF;CACF;CAEA,OAAO;AACT"}
|
package/dist/esm/version.d.ts
CHANGED
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk'\nexport const version = '4.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk'\nexport const version = '4.11.0'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.11.0",
|
|
4
4
|
"description": "LI.FI SDK for Any-to-Any Cross-Chain-Swap",
|
|
5
5
|
"homepage": "https://github.com/lifinance/sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@lifi/types": "^18.
|
|
31
|
+
"@lifi/types": "^18.13.0"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
@@ -8,8 +8,16 @@ import type {
|
|
|
8
8
|
} from '../types/core.js'
|
|
9
9
|
import { checkPackageUpdates } from '../utils/checkPackageUpdates.js'
|
|
10
10
|
import { name, version } from '../version.js'
|
|
11
|
+
import { findProvider } from './findProvider.js'
|
|
11
12
|
import { getClientStorage } from './getClientStorage.js'
|
|
12
13
|
|
|
14
|
+
// A provider replaces only one that serves the same chains. A provider that
|
|
15
|
+
// lists no chains keeps the bare type, so even an empty list stays apart.
|
|
16
|
+
const providerScope = (provider: SDKProvider): string =>
|
|
17
|
+
provider.chainIds
|
|
18
|
+
? `${provider.type}:${[...provider.chainIds].sort().join(',')}`
|
|
19
|
+
: provider.type
|
|
20
|
+
|
|
13
21
|
export function createClient(options: SDKConfig): SDKClient {
|
|
14
22
|
if (!options.integrator) {
|
|
15
23
|
throw new Error(
|
|
@@ -68,15 +76,15 @@ export function createClient(options: SDKConfig): SDKClient {
|
|
|
68
76
|
get providers() {
|
|
69
77
|
return _providers
|
|
70
78
|
},
|
|
71
|
-
getProvider(type: ChainType) {
|
|
72
|
-
return this.providers
|
|
79
|
+
getProvider(type: ChainType, chainId?: ChainId) {
|
|
80
|
+
return findProvider(this.providers, type, chainId)
|
|
73
81
|
},
|
|
74
82
|
setProviders(newProviders: SDKProvider[]) {
|
|
75
83
|
const providerMap = new Map(
|
|
76
|
-
this.providers.map((provider) => [provider
|
|
84
|
+
this.providers.map((provider) => [providerScope(provider), provider])
|
|
77
85
|
)
|
|
78
86
|
for (const provider of newProviders) {
|
|
79
|
-
providerMap.set(provider
|
|
87
|
+
providerMap.set(providerScope(provider), provider)
|
|
80
88
|
}
|
|
81
89
|
_providers = Array.from(providerMap.values())
|
|
82
90
|
},
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ChainId, ChainType } from '@lifi/types'
|
|
2
|
+
import type { SDKProvider } from '../types/core.js'
|
|
3
|
+
|
|
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 const findProvider = <T extends Pick<SDKProvider, 'type' | 'chainIds'>>(
|
|
9
|
+
providers: readonly T[],
|
|
10
|
+
chainType: ChainType,
|
|
11
|
+
chainId?: ChainId
|
|
12
|
+
): T | undefined =>
|
|
13
|
+
(chainId === undefined
|
|
14
|
+
? undefined
|
|
15
|
+
: providers.find(
|
|
16
|
+
(provider) =>
|
|
17
|
+
provider.type === chainType && provider.chainIds?.includes(chainId)
|
|
18
|
+
)) ??
|
|
19
|
+
providers.find(
|
|
20
|
+
(provider) => provider.type === chainType && !provider.chainIds
|
|
21
|
+
)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { BaseError } from '../errors/baseError.js'
|
|
2
|
+
import { ExecuteStepRetryError, UnknownError } from '../errors/errors.js'
|
|
3
|
+
import { SDKError } from '../errors/SDKError.js'
|
|
3
4
|
import type {
|
|
4
5
|
ExecuteStepRetryParams,
|
|
5
6
|
ExecutionAction,
|
|
@@ -16,6 +17,11 @@ import type {
|
|
|
16
17
|
} from '../types/execution.js'
|
|
17
18
|
import { StatusManager } from './StatusManager.js'
|
|
18
19
|
import type { TaskPipeline } from './TaskPipeline.js'
|
|
20
|
+
import {
|
|
21
|
+
hasStepOpenTransaction,
|
|
22
|
+
isFinalTransactionError,
|
|
23
|
+
transactionConflictError,
|
|
24
|
+
} from './transactionState.js'
|
|
19
25
|
|
|
20
26
|
// Please be careful when changing the defaults as it may break the behavior (e.g., background execution)
|
|
21
27
|
const defaultInteractionSettings = {
|
|
@@ -49,7 +55,8 @@ export abstract class BaseStepExecutor implements StepExecutor {
|
|
|
49
55
|
private createBaseContext = async (
|
|
50
56
|
client: SDKClient,
|
|
51
57
|
step: LiFiStepExtended,
|
|
52
|
-
retryParams?: ExecuteStepRetryParams
|
|
58
|
+
retryParams?: ExecuteStepRetryParams,
|
|
59
|
+
signal?: AbortSignal
|
|
53
60
|
): Promise<StepExecutorBaseContext> => {
|
|
54
61
|
const fromChain = await client.getChainById(step.action.fromChainId)
|
|
55
62
|
const toChain = await client.getChainById(step.action.toChainId)
|
|
@@ -66,6 +73,7 @@ export abstract class BaseStepExecutor implements StepExecutor {
|
|
|
66
73
|
statusManager: this.statusManager,
|
|
67
74
|
executionOptions: this.executionOptions,
|
|
68
75
|
allowUserInteraction: this.allowUserInteraction,
|
|
76
|
+
signal,
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
79
|
|
|
@@ -85,7 +93,8 @@ export abstract class BaseStepExecutor implements StepExecutor {
|
|
|
85
93
|
executeStep = async (
|
|
86
94
|
client: SDKClient,
|
|
87
95
|
step: LiFiStepExtended,
|
|
88
|
-
retryParams?: ExecuteStepRetryParams
|
|
96
|
+
retryParams?: ExecuteStepRetryParams,
|
|
97
|
+
signal?: AbortSignal
|
|
89
98
|
): Promise<LiFiStepExtended> => {
|
|
90
99
|
try {
|
|
91
100
|
step.execution = this.statusManager.initializeExecution(step)
|
|
@@ -93,7 +102,8 @@ export abstract class BaseStepExecutor implements StepExecutor {
|
|
|
93
102
|
const baseContext = await this.createBaseContext(
|
|
94
103
|
client,
|
|
95
104
|
step,
|
|
96
|
-
retryParams
|
|
105
|
+
retryParams,
|
|
106
|
+
signal
|
|
97
107
|
)
|
|
98
108
|
const context = await this.createContext(baseContext)
|
|
99
109
|
const pipeline = this.createPipeline(context)
|
|
@@ -104,7 +114,30 @@ export abstract class BaseStepExecutor implements StepExecutor {
|
|
|
104
114
|
} catch (error: any) {
|
|
105
115
|
// Derive failing action from last in execution.actions
|
|
106
116
|
const action = step.execution?.actions?.at(-1)
|
|
107
|
-
|
|
117
|
+
// Read before parsing: parsers may rebuild the error and drop the marker.
|
|
118
|
+
let isFinal = isFinalTransactionError(error)
|
|
119
|
+
let parsed = await this.parseErrors(error, step, action, retryParams)
|
|
120
|
+
if (
|
|
121
|
+
parsed instanceof ExecuteStepRetryError &&
|
|
122
|
+
hasStepOpenTransaction(step)
|
|
123
|
+
) {
|
|
124
|
+
// A retry runs the step again on an empty execution, which would erase
|
|
125
|
+
// the hash of a transaction that may still land. Fail with the original
|
|
126
|
+
// error instead, and keep the outcome unknown so a resume re-checks it.
|
|
127
|
+
// A BaseError keeps its code, so the widget shows its text. A replay
|
|
128
|
+
// that a task asked for has no error of its own: it fails as a sign
|
|
129
|
+
// task fails for the same state (`TransactionConflict`).
|
|
130
|
+
parsed = new SDKError(
|
|
131
|
+
error instanceof ExecuteStepRetryError
|
|
132
|
+
? transactionConflictError()
|
|
133
|
+
: error instanceof BaseError
|
|
134
|
+
? error
|
|
135
|
+
: new UnknownError(error?.message || parsed.message, error),
|
|
136
|
+
step,
|
|
137
|
+
action
|
|
138
|
+
)
|
|
139
|
+
isFinal = false
|
|
140
|
+
}
|
|
108
141
|
if (!(parsed instanceof ExecuteStepRetryError)) {
|
|
109
142
|
if (action) {
|
|
110
143
|
this.statusManager.updateAction(step, action.type, 'FAILED', {
|
|
@@ -112,6 +145,7 @@ export abstract class BaseStepExecutor implements StepExecutor {
|
|
|
112
145
|
message: parsed.cause?.message,
|
|
113
146
|
code: parsed.code,
|
|
114
147
|
},
|
|
148
|
+
...(isFinal && { txFinal: true }),
|
|
115
149
|
})
|
|
116
150
|
} else {
|
|
117
151
|
this.statusManager.updateExecution(step, {
|