@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/dist/esm/index.js
CHANGED
|
@@ -5,7 +5,8 @@ import { ErrorMessage, ErrorName, LiFiErrorCode } from "./errors/constants.js";
|
|
|
5
5
|
import { BalanceError, ExecuteStepRetryError, ProviderError, RPCError, ServerError, TransactionError, UnknownError, ValidationError } from "./errors/errors.js";
|
|
6
6
|
import { HTTPError } from "./errors/httpError.js";
|
|
7
7
|
import { sleep } from "./utils/sleep.js";
|
|
8
|
-
import { LruMap
|
|
8
|
+
import { LruMap } from "./utils/lru.js";
|
|
9
|
+
import { withDedupe } from "./utils/withDedupe.js";
|
|
9
10
|
import { getChains } from "./actions/getChains.js";
|
|
10
11
|
import { getConnections } from "./actions/getConnections.js";
|
|
11
12
|
import { getContractCallsQuote } from "./actions/getContractCallsQuote.js";
|
|
@@ -28,9 +29,11 @@ import { patchContractCalls } from "./actions/patchContractCalls.js";
|
|
|
28
29
|
import { relayTransaction } from "./actions/relayTransaction.js";
|
|
29
30
|
import { actions } from "./actions/index.js";
|
|
30
31
|
import { checkPackageUpdates } from "./utils/checkPackageUpdates.js";
|
|
32
|
+
import { findProvider } from "./client/findProvider.js";
|
|
31
33
|
import { createClient } from "./client/createClient.js";
|
|
32
34
|
import { getActionMessage, getSubstatusMessage } from "./core/actionMessages.js";
|
|
33
35
|
import { BaseStepExecutionTask } from "./core/BaseStepExecutionTask.js";
|
|
36
|
+
import { CLEARED_TRANSACTION_FIELDS, CLOCK_SKEW_MARGIN_MS, DROPPED_FALLBACK_AGE_MS, MAX_RESEND_AGE_MS, assertNoOpenTransaction, hasOpenTransaction, isFinalTransactionError, isOldEnoughToDrop, isResendAllowed } from "./core/transactionState.js";
|
|
34
37
|
import { StatusManager } from "./core/StatusManager.js";
|
|
35
38
|
import { BaseStepExecutor } from "./core/BaseStepExecutor.js";
|
|
36
39
|
import { executeRoute, getActiveRoute, getActiveRoutes, resumeRoute, stopRouteExecution, updateRouteExecution } from "./core/execution.js";
|
|
@@ -41,6 +44,7 @@ import { withTimeout } from "./utils/withTimeout.js";
|
|
|
41
44
|
import { checkBalance } from "./core/tasks/helpers/checkBalance.js";
|
|
42
45
|
import { CheckBalanceTask } from "./core/tasks/CheckBalanceTask.js";
|
|
43
46
|
import { getTransactionRequestData } from "./core/tasks/helpers/getTransactionRequestData.js";
|
|
47
|
+
import { isKnownToStatusApi } from "./core/tasks/helpers/isKnownToStatusApi.js";
|
|
44
48
|
import { stepComparison } from "./core/tasks/helpers/stepComparison.js";
|
|
45
49
|
import { PrepareTransactionTask } from "./core/tasks/PrepareTransactionTask.js";
|
|
46
50
|
import { waitForResult } from "./utils/waitForResult.js";
|
|
@@ -50,4 +54,4 @@ import { fetchTxErrorDetails } from "./utils/fetchTxErrorDetails.js";
|
|
|
50
54
|
import { isHex } from "./utils/isHex.js";
|
|
51
55
|
import { parseUnits } from "./utils/parseUnits.js";
|
|
52
56
|
export * from "@lifi/types";
|
|
53
|
-
export { BalanceError, BaseError, BaseStepExecutionTask, BaseStepExecutor, CheckBalanceTask, ErrorMessage, ErrorName, ExecuteStepRetryError, HTTPError, InMemoryStorage, LiFiErrorCode, LocalStorageAdapter, LruMap, PrepareTransactionTask, ProviderError, RPCError, SDKError, ServerError, StatusManager, TaskPipeline, TransactionError, UnknownError, ValidationError, WaitForTransactionStatusTask, actions, checkBalance, checkPackageUpdates, convertQuoteToRoute, createClient, createDefaultStorage, executeRoute, fetchTxErrorDetails, formatUnits, getActionMessage, getActiveRoute, getActiveRoutes, getChains, getConnections, getContractCallsQuote, getGasRecommendation, getNameServiceAddress, getQuote, getRelayedTransactionStatus, getRelayerQuote, getRoutes, getStatus, getStepTransaction, getSubstatusMessage, getToken, getTokenBalance, getTokenBalances, getTokenBalancesByChain, getTokens, getTools, getTransactionHistory, getTransactionRequestData, isHex, name, parseUnits, patchContractCalls, relayTransaction, resumeRoute, sleep, stepComparison, stopRouteExecution, updateRouteExecution, version, waitForResult, withDedupe, withTimeout };
|
|
57
|
+
export { BalanceError, BaseError, BaseStepExecutionTask, BaseStepExecutor, CLEARED_TRANSACTION_FIELDS, CLOCK_SKEW_MARGIN_MS, CheckBalanceTask, DROPPED_FALLBACK_AGE_MS, ErrorMessage, ErrorName, ExecuteStepRetryError, HTTPError, InMemoryStorage, LiFiErrorCode, LocalStorageAdapter, LruMap, MAX_RESEND_AGE_MS, PrepareTransactionTask, ProviderError, RPCError, SDKError, ServerError, StatusManager, TaskPipeline, TransactionError, UnknownError, ValidationError, WaitForTransactionStatusTask, actions, assertNoOpenTransaction, checkBalance, checkPackageUpdates, convertQuoteToRoute, createClient, createDefaultStorage, executeRoute, fetchTxErrorDetails, findProvider, formatUnits, getActionMessage, getActiveRoute, getActiveRoutes, getChains, getConnections, getContractCallsQuote, getGasRecommendation, getNameServiceAddress, getQuote, getRelayedTransactionStatus, getRelayerQuote, getRoutes, getStatus, getStepTransaction, getSubstatusMessage, getToken, getTokenBalance, getTokenBalances, getTokenBalancesByChain, getTokens, getTools, getTransactionHistory, getTransactionRequestData, hasOpenTransaction, isFinalTransactionError, isHex, isKnownToStatusApi, isOldEnoughToDrop, isResendAllowed, name, parseUnits, patchContractCalls, relayTransaction, resumeRoute, sleep, stepComparison, stopRouteExecution, updateRouteExecution, version, waitForResult, withDedupe, withTimeout };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","names":[],"sources":["../../../src/types/actions.ts"],"mappings":";;YASY,2BAA2B;EACrC;;;;;;KAOG;EACH;EACA;EACA;;YAGU,gBAAgB,
|
|
1
|
+
{"version":3,"file":"actions.d.ts","names":["RoutesRequestBase","QuoteRequestBase"],"sources":["../../../src/types/actions.ts"],"mappings":";;YASY,2BAA2B;EACrC;;;;;;KAOG;EACH;EACA;EACA;;YAGU,gBAAgB,KAAKA,8BAC/B;EACE,UAAUA;;IAER;;;;;;YAOM,mBAAmB,WAAW;EACxC,QAAQ,SAAS;;YAGP,yBAAyBC;YAEzB,uBAAuB,KAAKA;EACtC;;YAGU,eAAe,yBAAyB"}
|
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"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/utils/abort.d.ts
|
|
2
|
+
/** Older runtimes and polyfills can abort a signal without a `reason`. */
|
|
3
|
+
export declare const getAbortError: (signal: AbortSignal) => unknown;
|
|
4
|
+
export declare const isAbortError: (error: unknown) => boolean;
|
|
5
|
+
//#endregion
|
|
6
|
+
//# sourceMappingURL=abort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abort.d.ts","names":[],"sources":["../../../src/utils/abort.ts"],"mappings":";;qBACa,gBAAiB,QAAQ;qBAIzB,eAAgB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/utils/abort.ts
|
|
2
|
+
/** Older runtimes and polyfills can abort a signal without a `reason`. */
|
|
3
|
+
const getAbortError = (signal) => signal.reason ?? Object.assign(/* @__PURE__ */ new Error("This operation was aborted"), { name: "AbortError" });
|
|
4
|
+
const isAbortError = (error) => typeof error === "object" && error !== null && "name" in error && error.name === "AbortError";
|
|
5
|
+
//#endregion
|
|
6
|
+
export { getAbortError, isAbortError };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=abort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abort.js","names":[],"sources":["../../../src/utils/abort.ts"],"sourcesContent":["/** Older runtimes and polyfills can abort a signal without a `reason`. */\nexport const getAbortError = (signal: AbortSignal): unknown =>\n signal.reason ??\n Object.assign(new Error('This operation was aborted'), { name: 'AbortError' })\n\nexport const isAbortError = (error: unknown): boolean =>\n typeof error === 'object' &&\n error !== null &&\n 'name' in error &&\n error.name === 'AbortError'\n"],"mappings":";;AACA,MAAa,iBAAiB,WAC5B,OAAO,UACP,OAAO,uBAAO,IAAI,MAAM,4BAA4B,GAAG,EAAE,MAAM,aAAa,CAAC;AAE/E,MAAa,gBAAgB,UAC3B,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS"}
|
|
@@ -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
|
};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Divides a number by a given exponent of base 10 (10exponent), and formats it into a string representation of the number.
|
|
4
4
|
*/
|
|
5
5
|
function formatUnits(value, decimals) {
|
|
6
|
+
if (!Number.isInteger(decimals) || decimals < 0) throw new Error(`\`decimals\` must be a non-negative integer. Got \`${decimals}\`.`);
|
|
6
7
|
let display = value.toString();
|
|
7
8
|
const negative = display.startsWith("-");
|
|
8
9
|
if (negative) display = display.slice(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatUnits.js","names":[],"sources":["../../../src/utils/formatUnits.ts"],"sourcesContent":["/**\n * Divides a number by a given exponent of base 10 (10exponent), and formats it into a string representation of the number.\n */\nexport function formatUnits(value: bigint, decimals: number): string {\n let display = value.toString()\n\n const negative = display.startsWith('-')\n if (negative) {\n display = display.slice(1)\n }\n\n display = display.padStart(decimals, '0')\n\n let [integer, fraction] = [\n display.slice(0, display.length - decimals),\n display.slice(display.length - decimals),\n ]\n fraction = fraction.replace(/(0+)$/, '')\n return `${negative ? '-' : ''}${integer || '0'}${\n fraction ? `.${fraction}` : ''\n }`\n}\n"],"mappings":";;;;AAGA,SAAgB,YAAY,OAAe,UAA0B;CACnE,IAAI,UAAU,MAAM,SAAS;CAE7B,MAAM,WAAW,QAAQ,WAAW,GAAG;CACvC,IAAI,UACF,UAAU,QAAQ,MAAM,CAAC;CAG3B,UAAU,QAAQ,SAAS,UAAU,GAAG;CAExC,IAAI,CAAC,SAAS,YAAY,CACxB,QAAQ,MAAM,GAAG,QAAQ,SAAS,QAAQ,GAC1C,QAAQ,MAAM,QAAQ,SAAS,QAAQ,CACzC;CACA,WAAW,SAAS,QAAQ,SAAS,EAAE;CACvC,OAAO,GAAG,WAAW,MAAM,KAAK,WAAW,MACzC,WAAW,IAAI,aAAa;AAEhC"}
|
|
1
|
+
{"version":3,"file":"formatUnits.js","names":[],"sources":["../../../src/utils/formatUnits.ts"],"sourcesContent":["/**\n * Divides a number by a given exponent of base 10 (10exponent), and formats it into a string representation of the number.\n */\nexport function formatUnits(value: bigint, decimals: number): string {\n if (!Number.isInteger(decimals) || decimals < 0) {\n throw new Error(\n `\\`decimals\\` must be a non-negative integer. Got \\`${decimals}\\`.`\n )\n }\n\n let display = value.toString()\n\n const negative = display.startsWith('-')\n if (negative) {\n display = display.slice(1)\n }\n\n display = display.padStart(decimals, '0')\n\n let [integer, fraction] = [\n display.slice(0, display.length - decimals),\n display.slice(display.length - decimals),\n ]\n fraction = fraction.replace(/(0+)$/, '')\n return `${negative ? '-' : ''}${integer || '0'}${\n fraction ? `.${fraction}` : ''\n }`\n}\n"],"mappings":";;;;AAGA,SAAgB,YAAY,OAAe,UAA0B;CACnE,IAAI,CAAC,OAAO,UAAU,QAAQ,KAAK,WAAW,GAC5C,MAAM,IAAI,MACR,sDAAsD,SAAS,IACjE;CAGF,IAAI,UAAU,MAAM,SAAS;CAE7B,MAAM,WAAW,QAAQ,WAAW,GAAG;CACvC,IAAI,UACF,UAAU,QAAQ,MAAM,CAAC;CAG3B,UAAU,QAAQ,SAAS,UAAU,GAAG;CAExC,IAAI,CAAC,SAAS,YAAY,CACxB,QAAQ,MAAM,GAAG,QAAQ,SAAS,QAAQ,GAC1C,QAAQ,MAAM,QAAQ,SAAS,QAAQ,CACzC;CACA,WAAW,SAAS,QAAQ,SAAS,EAAE;CACvC,OAAO,GAAG,WAAW,MAAM,KAAK,WAAW,MACzC,WAAW,IAAI,aAAa;AAEhC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/utils/lru.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Map with a LRU (Least recently used) policy.
|
|
4
|
+
*
|
|
5
|
+
* https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU
|
|
6
|
+
*/
|
|
7
|
+
export declare class LruMap<value = unknown> extends Map<string, value> {
|
|
8
|
+
maxSize: number;
|
|
9
|
+
constructor(size: number);
|
|
10
|
+
override get(key: string): value | undefined;
|
|
11
|
+
override set(key: string, value: value): this;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//# sourceMappingURL=lru.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lru.d.ts","names":[],"sources":["../../../src/utils/lru.ts"],"mappings":";;;;;;qBAKa,OAAO,yBAAyB,YAAY;EACvD;EAEA,YAAY;WAKH,IAAI,cAAc;WASlB,IAAI,aAAa,OAAO"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/utils/lru.ts
|
|
2
|
+
/**
|
|
3
|
+
* Map with a LRU (Least recently used) policy.
|
|
4
|
+
*
|
|
5
|
+
* https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU
|
|
6
|
+
*/
|
|
7
|
+
var LruMap = class extends Map {
|
|
8
|
+
maxSize;
|
|
9
|
+
constructor(size) {
|
|
10
|
+
super();
|
|
11
|
+
this.maxSize = size;
|
|
12
|
+
}
|
|
13
|
+
get(key) {
|
|
14
|
+
const value = super.get(key);
|
|
15
|
+
if (super.has(key)) {
|
|
16
|
+
super.delete(key);
|
|
17
|
+
super.set(key, value);
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
set(key, value) {
|
|
22
|
+
if (super.has(key)) super.delete(key);
|
|
23
|
+
super.set(key, value);
|
|
24
|
+
if (this.maxSize && this.size > this.maxSize) {
|
|
25
|
+
const firstKey = super.keys().next().value;
|
|
26
|
+
if (firstKey !== void 0) super.delete(firstKey);
|
|
27
|
+
}
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { LruMap };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=lru.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lru.js","names":[],"sources":["../../../src/utils/lru.ts"],"sourcesContent":["/**\n * Map with a LRU (Least recently used) policy.\n *\n * https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU\n */\nexport class LruMap<value = unknown> extends Map<string, value> {\n maxSize: number\n\n constructor(size: number) {\n super()\n this.maxSize = size\n }\n\n override get(key: string): value | undefined {\n const value = super.get(key)\n if (super.has(key)) {\n super.delete(key)\n super.set(key, value as value)\n }\n return value\n }\n\n override set(key: string, value: value): this {\n if (super.has(key)) {\n super.delete(key)\n }\n super.set(key, value)\n if (this.maxSize && this.size > this.maxSize) {\n // `super.keys()`, not `this.keys()`: on iOS 18 the subclass iterator\n // can yield `undefined`, and the map then grows without limit.\n const firstKey = super.keys().next().value\n if (firstKey !== undefined) {\n super.delete(firstKey)\n }\n }\n return this\n }\n}\n"],"mappings":";;;;;;AAKA,IAAa,SAAb,cAA6C,IAAmB;CAC9D;CAEA,YAAY,MAAc;EACxB,MAAM;EACN,KAAK,UAAU;CACjB;CAEA,IAAa,KAAgC;EAC3C,MAAM,QAAQ,MAAM,IAAI,GAAG;EAC3B,IAAI,MAAM,IAAI,GAAG,GAAG;GAClB,MAAM,OAAO,GAAG;GAChB,MAAM,IAAI,KAAK,KAAc;EAC/B;EACA,OAAO;CACT;CAEA,IAAa,KAAa,OAAoB;EAC5C,IAAI,MAAM,IAAI,GAAG,GACf,MAAM,OAAO,GAAG;EAElB,MAAM,IAAI,KAAK,KAAK;EACpB,IAAI,KAAK,WAAW,KAAK,OAAO,KAAK,SAAS;GAG5C,MAAM,WAAW,MAAM,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;GACrC,IAAI,aAAa,KAAA,GACf,MAAM,OAAO,QAAQ;EAEzB;EACA,OAAO;CACT;AACF"}
|
|
@@ -3,31 +3,45 @@
|
|
|
3
3
|
* Multiplies a string representation of a number by a given exponent of base 10 (10exponent).
|
|
4
4
|
*/
|
|
5
5
|
function parseUnits(value, decimals) {
|
|
6
|
-
if (
|
|
7
|
-
|
|
6
|
+
if (!Number.isInteger(decimals) || decimals < 0) throw new Error(`\`decimals\` must be a non-negative integer. Got \`${decimals}\`.`);
|
|
7
|
+
if (/^-?\.?$/.test(value)) return 0n;
|
|
8
|
+
if (!/^-?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)$/.test(value)) throw new Error(`Number \`${value}\` is not a valid decimal number.`);
|
|
9
|
+
let [integer = "", fraction = "0"] = value.split(".");
|
|
8
10
|
const negative = integer.startsWith("-");
|
|
9
11
|
if (negative) integer = integer.slice(1);
|
|
12
|
+
if (integer === "") integer = "0";
|
|
10
13
|
fraction = fraction.replace(/(0+)$/, "");
|
|
11
14
|
if (decimals === 0) {
|
|
12
|
-
if (
|
|
15
|
+
if (fraction.length > 0 && Number.parseInt(fraction[0], 10) >= 5) integer = `${BigInt(integer) + 1n}`;
|
|
13
16
|
fraction = "";
|
|
14
17
|
} else if (fraction.length > decimals) {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
else fraction =
|
|
23
|
-
if (fraction.length > decimals) {
|
|
24
|
-
fraction = fraction.slice(1);
|
|
25
|
-
integer = `${BigInt(integer) + 1n}`;
|
|
26
|
-
}
|
|
27
|
-
fraction = fraction.slice(0, decimals);
|
|
18
|
+
const left = fraction.slice(0, decimals);
|
|
19
|
+
if (Number.parseInt(fraction.slice(decimals, decimals + 1), 10) >= 5) {
|
|
20
|
+
const carried = carry(left);
|
|
21
|
+
if (carried.length > decimals) {
|
|
22
|
+
fraction = carried.slice(1);
|
|
23
|
+
integer = `${BigInt(integer) + 1n}`;
|
|
24
|
+
} else fraction = carried;
|
|
25
|
+
} else fraction = left;
|
|
28
26
|
} else fraction = fraction.padEnd(decimals, "0");
|
|
29
27
|
return BigInt(`${negative ? "-" : ""}${integer}${fraction}`);
|
|
30
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Adds 1 to a digit string. The result has the same length, unless the carry
|
|
31
|
+
* passes the most significant digit: then it is one digit longer.
|
|
32
|
+
*/
|
|
33
|
+
function carry(digits) {
|
|
34
|
+
const out = digits.split("");
|
|
35
|
+
for (let i = out.length - 1; i >= 0; i--) {
|
|
36
|
+
const digit = Number.parseInt(out[i], 10) + 1;
|
|
37
|
+
if (digit < 10) {
|
|
38
|
+
out[i] = String(digit);
|
|
39
|
+
return out.join("");
|
|
40
|
+
}
|
|
41
|
+
out[i] = "0";
|
|
42
|
+
}
|
|
43
|
+
return `1${out.join("")}`;
|
|
44
|
+
}
|
|
31
45
|
//#endregion
|
|
32
46
|
export { parseUnits };
|
|
33
47
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseUnits.js","names":[],"sources":["../../../src/utils/parseUnits.ts"],"sourcesContent":["/**\n * Multiplies a string representation of a number by a given exponent of base 10 (10exponent).\n */\nexport function parseUnits(value: string, decimals: number): bigint {\n if (
|
|
1
|
+
{"version":3,"file":"parseUnits.js","names":[],"sources":["../../../src/utils/parseUnits.ts"],"sourcesContent":["/**\n * Multiplies a string representation of a number by a given exponent of base 10 (10exponent).\n */\nexport function parseUnits(value: string, decimals: number): bigint {\n if (!Number.isInteger(decimals) || decimals < 0) {\n throw new Error(\n `\\`decimals\\` must be a non-negative integer. Got \\`${decimals}\\`.`\n )\n }\n\n // An input with no digit is 0n: the widget parses an empty amount field.\n if (/^-?\\.?$/.test(value)) {\n return 0n\n }\n\n if (!/^-?(?:[0-9]+(?:\\.[0-9]*)?|\\.[0-9]+)$/.test(value)) {\n throw new Error(`Number \\`${value}\\` is not a valid decimal number.`)\n }\n\n let [integer = '', fraction = '0'] = value.split('.')\n\n const negative = integer.startsWith('-')\n if (negative) {\n integer = integer.slice(1)\n }\n if (integer === '') {\n integer = '0'\n }\n\n // trim trailing zeros.\n fraction = fraction.replace(/(0+)$/, '')\n\n // round off if the fraction is larger than the number of decimals.\n if (decimals === 0) {\n // Round half away from zero by the first fractional digit.\n if (fraction.length > 0 && Number.parseInt(fraction[0], 10) >= 5) {\n integer = `${BigInt(integer) + 1n}`\n }\n fraction = ''\n } else if (fraction.length > decimals) {\n const left = fraction.slice(0, decimals)\n const roundDigit = Number.parseInt(\n fraction.slice(decimals, decimals + 1),\n 10\n )\n\n if (roundDigit >= 5) {\n // Carry in decimal space, not through a JS number: a float loses\n // precision on long fractions and can round the wrong way.\n const carried = carry(left)\n if (carried.length > decimals) {\n // The carry overflowed into the integer part.\n fraction = carried.slice(1)\n integer = `${BigInt(integer) + 1n}`\n } else {\n fraction = carried\n }\n } else {\n fraction = left\n }\n } else {\n fraction = fraction.padEnd(decimals, '0')\n }\n\n return BigInt(`${negative ? '-' : ''}${integer}${fraction}`)\n}\n\n/**\n * Adds 1 to a digit string. The result has the same length, unless the carry\n * passes the most significant digit: then it is one digit longer.\n */\nfunction carry(digits: string): string {\n const out = digits.split('')\n for (let i = out.length - 1; i >= 0; i--) {\n const digit = Number.parseInt(out[i], 10) + 1\n if (digit < 10) {\n out[i] = String(digit)\n return out.join('')\n }\n out[i] = '0'\n }\n return `1${out.join('')}`\n}\n"],"mappings":";;;;AAGA,SAAgB,WAAW,OAAe,UAA0B;CAClE,IAAI,CAAC,OAAO,UAAU,QAAQ,KAAK,WAAW,GAC5C,MAAM,IAAI,MACR,sDAAsD,SAAS,IACjE;CAIF,IAAI,UAAU,KAAK,KAAK,GACtB,OAAO;CAGT,IAAI,CAAC,uCAAuC,KAAK,KAAK,GACpD,MAAM,IAAI,MAAM,YAAY,MAAM,kCAAkC;CAGtE,IAAI,CAAC,UAAU,IAAI,WAAW,OAAO,MAAM,MAAM,GAAG;CAEpD,MAAM,WAAW,QAAQ,WAAW,GAAG;CACvC,IAAI,UACF,UAAU,QAAQ,MAAM,CAAC;CAE3B,IAAI,YAAY,IACd,UAAU;CAIZ,WAAW,SAAS,QAAQ,SAAS,EAAE;CAGvC,IAAI,aAAa,GAAG;EAElB,IAAI,SAAS,SAAS,KAAK,OAAO,SAAS,SAAS,IAAI,EAAE,KAAK,GAC7D,UAAU,GAAG,OAAO,OAAO,IAAI;EAEjC,WAAW;CACb,OAAO,IAAI,SAAS,SAAS,UAAU;EACrC,MAAM,OAAO,SAAS,MAAM,GAAG,QAAQ;EAMvC,IALmB,OAAO,SACxB,SAAS,MAAM,UAAU,WAAW,CAAC,GACrC,EAGW,KAAK,GAAG;GAGnB,MAAM,UAAU,MAAM,IAAI;GAC1B,IAAI,QAAQ,SAAS,UAAU;IAE7B,WAAW,QAAQ,MAAM,CAAC;IAC1B,UAAU,GAAG,OAAO,OAAO,IAAI;GACjC,OACE,WAAW;EAEf,OACE,WAAW;CAEf,OACE,WAAW,SAAS,OAAO,UAAU,GAAG;CAG1C,OAAO,OAAO,GAAG,WAAW,MAAM,KAAK,UAAU,UAAU;AAC7D;;;;;AAMA,SAAS,MAAM,QAAwB;CACrC,MAAM,MAAM,OAAO,MAAM,EAAE;CAC3B,KAAK,IAAI,IAAI,IAAI,SAAS,GAAG,KAAK,GAAG,KAAK;EACxC,MAAM,QAAQ,OAAO,SAAS,IAAI,IAAI,EAAE,IAAI;EAC5C,IAAI,QAAQ,IAAI;GACd,IAAI,KAAK,OAAO,KAAK;GACrB,OAAO,IAAI,KAAK,EAAE;EACpB;EACA,IAAI,KAAK;CACX;CACA,OAAO,IAAI,IAAI,KAAK,EAAE;AACxB"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
//#region src/utils/sleep.d.ts
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Resolves with `null` after `ms`. With a `signal`, it rejects with the abort
|
|
4
|
+
* reason as soon as the signal aborts, and clears its timer.
|
|
5
|
+
*/
|
|
6
|
+
export declare function sleep(ms: number, { signal }?: {
|
|
7
|
+
signal?: AbortSignal | undefined;
|
|
8
|
+
}): Promise<null>;
|
|
3
9
|
//#endregion
|
|
4
10
|
//# sourceMappingURL=sleep.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sleep.d.ts","names":[],"sources":["../../../src/utils/sleep.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"sleep.d.ts","names":[],"sources":["../../../src/utils/sleep.ts"],"mappings":";;;;;wBAMgB,MACd,cACE;EAAY,SAAS;IACtB"}
|
package/dist/esm/utils/sleep.js
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
1
|
+
import { getAbortError } from "./abort.js";
|
|
1
2
|
//#region src/utils/sleep.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Resolves with `null` after `ms`. With a `signal`, it rejects with the abort
|
|
5
|
+
* reason as soon as the signal aborts, and clears its timer.
|
|
6
|
+
*/
|
|
7
|
+
function sleep(ms, { signal } = {}) {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
if (signal?.aborted) {
|
|
10
|
+
reject(getAbortError(signal));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const cleanup = () => signal?.removeEventListener("abort", onAbort);
|
|
14
|
+
const timer = setTimeout(() => {
|
|
15
|
+
cleanup();
|
|
16
|
+
resolve(null);
|
|
17
|
+
}, ms);
|
|
18
|
+
const onAbort = () => {
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
cleanup();
|
|
21
|
+
reject(getAbortError(signal));
|
|
22
|
+
};
|
|
23
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
5
24
|
});
|
|
6
25
|
}
|
|
7
26
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sleep.js","names":[],"sources":["../../../src/utils/sleep.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"sleep.js","names":[],"sources":["../../../src/utils/sleep.ts"],"sourcesContent":["import { getAbortError } from './abort.js'\n\n/**\n * Resolves with `null` after `ms`. With a `signal`, it rejects with the abort\n * reason as soon as the signal aborts, and clears its timer.\n */\nexport function sleep(\n ms: number,\n { signal }: { signal?: AbortSignal | undefined } = {}\n): Promise<null> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(getAbortError(signal))\n return\n }\n\n const cleanup = (): void => signal?.removeEventListener('abort', onAbort)\n const timer = setTimeout(() => {\n cleanup()\n resolve(null)\n }, ms)\n const onAbort = (): void => {\n clearTimeout(timer)\n cleanup()\n reject(getAbortError(signal!))\n }\n signal?.addEventListener('abort', onAbort, { once: true })\n })\n}\n"],"mappings":";;;;;;AAMA,SAAgB,MACd,IACA,EAAE,WAAiD,CAAC,GACrC;CACf,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,IAAI,QAAQ,SAAS;GACnB,OAAO,cAAc,MAAM,CAAC;GAC5B;EACF;EAEA,MAAM,gBAAsB,QAAQ,oBAAoB,SAAS,OAAO;EACxE,MAAM,QAAQ,iBAAiB;GAC7B,QAAQ;GACR,QAAQ,IAAI;EACd,GAAG,EAAE;EACL,MAAM,gBAAsB;GAC1B,aAAa,KAAK;GAClB,QAAQ;GACR,OAAO,cAAc,MAAO,CAAC;EAC/B;EACA,QAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;CAC3D,CAAC;AACH"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
//#region src/utils/waitForResult.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* Repeatedly calls a given asynchronous function until it resolves with a value
|
|
4
|
-
* @param fn The function that should be repeated
|
|
3
|
+
* Repeatedly calls a given asynchronous function until it resolves with a truthy value
|
|
4
|
+
* @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
|
|
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
|
-
* @param maxRetries Maximum number of
|
|
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
|
-
* @throws
|
|
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,31 +1,36 @@
|
|
|
1
|
+
import { getAbortError } from "./abort.js";
|
|
1
2
|
import { sleep } from "./sleep.js";
|
|
2
3
|
//#region src/utils/waitForResult.ts
|
|
3
4
|
/**
|
|
4
|
-
* Repeatedly calls a given asynchronous function until it resolves with a value
|
|
5
|
-
* @param fn The function that should be repeated
|
|
5
|
+
* Repeatedly calls a given asynchronous function until it resolves with a truthy value
|
|
6
|
+
* @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
|
|
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
|
-
* @param maxRetries Maximum number of
|
|
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
|
-
* @throws
|
|
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 value\n * @param fn The function that should be repeated\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
|
|
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"}
|
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
//#region src/utils/withDedupe.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Map with a LRU (Least recently used) policy.
|
|
4
|
-
*
|
|
5
|
-
* https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU
|
|
6
|
-
*/
|
|
7
|
-
export declare class LruMap<value = unknown> extends Map<string, value> {
|
|
8
|
-
maxSize: number;
|
|
9
|
-
constructor(size: number);
|
|
10
|
-
override set(key: string, value: value): this;
|
|
11
|
-
}
|
|
12
2
|
type WithDedupeOptions = {
|
|
13
3
|
enabled?: boolean | undefined;
|
|
14
4
|
id?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withDedupe.d.ts","names":[],"sources":["../../../src/utils/withDedupe.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"withDedupe.d.ts","names":[],"sources":["../../../src/utils/withDedupe.ts"],"mappings":";KAqBK;EACH;EACA;;EAEA,SAAS;;;;;;;;;;;wBAYK,WAAW,GACzB,KAAK,SAAS,gBAAgB,QAAQ,IACtC,SAAS,oBACR,QAAQ;wBACK,WAAW,GACzB,UAAU,QAAQ,IAClB,SAAS;EAAsB;IAC9B,QAAQ"}
|
|
@@ -1,26 +1,11 @@
|
|
|
1
|
+
import { getAbortError } from "./abort.js";
|
|
2
|
+
import { LruMap } from "./lru.js";
|
|
1
3
|
//#region src/utils/withDedupe.ts
|
|
2
|
-
/**
|
|
3
|
-
* Map with a LRU (Least recently used) policy.
|
|
4
|
-
*
|
|
5
|
-
* https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU
|
|
6
|
-
*/
|
|
7
|
-
var LruMap = class extends Map {
|
|
8
|
-
maxSize;
|
|
9
|
-
constructor(size) {
|
|
10
|
-
super();
|
|
11
|
-
this.maxSize = size;
|
|
12
|
-
}
|
|
13
|
-
set(key, value) {
|
|
14
|
-
super.set(key, value);
|
|
15
|
-
if (this.maxSize && this.size > this.maxSize) this.delete(this.keys().next().value);
|
|
16
|
-
return this;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
4
|
/** @internal */
|
|
20
5
|
const promiseCache = /*#__PURE__*/ new LruMap(8192);
|
|
21
6
|
function withDedupe(fn, { enabled = true, id, signal }) {
|
|
22
7
|
if (!enabled || !id) return fn(signal);
|
|
23
|
-
if (signal?.aborted) return Promise.reject(
|
|
8
|
+
if (signal?.aborted) return Promise.reject(getAbortError(signal));
|
|
24
9
|
let inFlight = promiseCache.get(id);
|
|
25
10
|
if (!inFlight) {
|
|
26
11
|
const controller = signal ? new AbortController() : void 0;
|
|
@@ -54,7 +39,7 @@ function join(id, inFlight, signal) {
|
|
|
54
39
|
const leave = () => {
|
|
55
40
|
signal.removeEventListener("abort", leave);
|
|
56
41
|
callers.delete(caller);
|
|
57
|
-
const reason =
|
|
42
|
+
const reason = getAbortError(signal);
|
|
58
43
|
reject(reason);
|
|
59
44
|
if (!inFlight.pinned && callers.size === 0) {
|
|
60
45
|
evict(id, inFlight.promise);
|
|
@@ -87,9 +72,7 @@ function subscribe(inFlight) {
|
|
|
87
72
|
function evict(id, promise) {
|
|
88
73
|
if (promiseCache.get(id)?.promise === promise) promiseCache.delete(id);
|
|
89
74
|
}
|
|
90
|
-
/** Older runtimes and polyfills can abort a signal without a `reason`. */
|
|
91
|
-
const abortReason = (signal) => signal.reason ?? Object.assign(/* @__PURE__ */ new Error("This operation was aborted"), { name: "AbortError" });
|
|
92
75
|
//#endregion
|
|
93
|
-
export {
|
|
76
|
+
export { withDedupe };
|
|
94
77
|
|
|
95
78
|
//# sourceMappingURL=withDedupe.js.map
|