@across-protocol/sdk 4.3.145-alpha.1 → 4.3.145-alpha.4
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/dist/cjs/src/caching/Arweave/ArweaveClient.d.ts +2 -0
- package/dist/cjs/src/caching/Arweave/ArweaveClient.js +116 -40
- package/dist/cjs/src/caching/Arweave/ArweaveClient.js.map +1 -1
- package/dist/cjs/src/clients/BundleDataClient/BundleDataClient.d.ts +5 -2
- package/dist/cjs/src/clients/BundleDataClient/BundleDataClient.js +74 -10
- package/dist/cjs/src/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/src/coingecko/Coingecko.js +2 -9
- package/dist/cjs/src/coingecko/Coingecko.js.map +1 -1
- package/dist/cjs/src/utils/CachingUtils.d.ts +1 -0
- package/dist/cjs/src/utils/CachingUtils.js +4 -0
- package/dist/cjs/src/utils/CachingUtils.js.map +1 -1
- package/dist/cjs/src/utils/common.d.ts +1 -13
- package/dist/cjs/src/utils/common.js +8 -19
- package/dist/cjs/src/utils/common.js.map +1 -1
- package/dist/esm/src/caching/Arweave/ArweaveClient.d.ts +2 -0
- package/dist/esm/src/caching/Arweave/ArweaveClient.js +117 -47
- package/dist/esm/src/caching/Arweave/ArweaveClient.js.map +1 -1
- package/dist/esm/src/clients/BundleDataClient/BundleDataClient.d.ts +5 -2
- package/dist/esm/src/clients/BundleDataClient/BundleDataClient.js +77 -13
- package/dist/esm/src/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/src/coingecko/Coingecko.js +2 -9
- package/dist/esm/src/coingecko/Coingecko.js.map +1 -1
- package/dist/esm/src/utils/CachingUtils.d.ts +1 -0
- package/dist/esm/src/utils/CachingUtils.js +3 -0
- package/dist/esm/src/utils/CachingUtils.js.map +1 -1
- package/dist/esm/src/utils/common.d.ts +6 -33
- package/dist/esm/src/utils/common.js +13 -26
- package/dist/esm/src/utils/common.js.map +1 -1
- package/dist/types/src/caching/Arweave/ArweaveClient.d.ts +2 -0
- package/dist/types/src/caching/Arweave/ArweaveClient.d.ts.map +1 -1
- package/dist/types/src/clients/BundleDataClient/BundleDataClient.d.ts +5 -2
- package/dist/types/src/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/src/coingecko/Coingecko.d.ts.map +1 -1
- package/dist/types/src/utils/CachingUtils.d.ts +1 -0
- package/dist/types/src/utils/CachingUtils.d.ts.map +1 -1
- package/dist/types/src/utils/common.d.ts +6 -33
- package/dist/types/src/utils/common.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/caching/Arweave/ArweaveClient.ts +142 -54
- package/src/clients/BundleDataClient/BundleDataClient.ts +86 -17
- package/src/coingecko/Coingecko.ts +2 -9
- package/src/utils/CachingUtils.ts +4 -0
- package/src/utils/common.ts +14 -49
package/src/utils/common.ts
CHANGED
|
@@ -221,55 +221,20 @@ export function delay(seconds: number) {
|
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
/**
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
/** Base delay in seconds for the exponential backoff. Defaults to 1. */
|
|
239
|
-
delaySeconds?: number;
|
|
240
|
-
/** Predicate evaluated against the thrown error to decide whether to retry. Defaults to retrying every error. */
|
|
241
|
-
isRetryable?: (err: unknown) => boolean;
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
const DEFAULT_RETRY_OPTIONS: Required<RetryOptions> = {
|
|
245
|
-
retries: 2,
|
|
246
|
-
delaySeconds: 1,
|
|
247
|
-
isRetryable: () => true,
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Attempt a function call with exponential backoff and a retryability predicate, returning a
|
|
252
|
-
* {@link Result} that encodes success or the terminal failure. Exhausted retries and errors
|
|
253
|
-
* rejected by `isRetryable` both surface as `{ ok: false, error }` — the caller decides how
|
|
254
|
-
* to react instead of catching a throw.
|
|
255
|
-
* @param call The function to call.
|
|
256
|
-
* @param options Retry configuration — see {@link RetryOptions}. All fields are optional.
|
|
257
|
-
* @returns A `Result<T>` wrapping the terminal outcome.
|
|
258
|
-
*/
|
|
259
|
-
export async function retry<T>(call: () => Promise<T>, options: RetryOptions = {}): Promise<Result<T>> {
|
|
260
|
-
const resolved: Required<RetryOptions> = { ...DEFAULT_RETRY_OPTIONS, ...options };
|
|
261
|
-
const backoffSeconds = (attempt: number): number => resolved.delaySeconds * 2 ** attempt + Math.random();
|
|
262
|
-
|
|
263
|
-
for (let nAttempts = 0; ; ++nAttempts) {
|
|
264
|
-
try {
|
|
265
|
-
return { ok: true, value: await call() };
|
|
266
|
-
} catch (err) {
|
|
267
|
-
if (nAttempts >= resolved.retries || !resolved.isRetryable(err)) {
|
|
268
|
-
return { ok: false, error: err instanceof Error ? err : new Error(String(err)) };
|
|
269
|
-
}
|
|
270
|
-
await delay(backoffSeconds(nAttempts));
|
|
271
|
-
}
|
|
272
|
-
}
|
|
224
|
+
* Attempt to retry a function call a number of times with a delay between each attempt
|
|
225
|
+
* @param call The function to call
|
|
226
|
+
* @param times The number of times to retry
|
|
227
|
+
* @param delayS The number of seconds to delay between each attempt
|
|
228
|
+
* @returns The result of the function call.
|
|
229
|
+
*/
|
|
230
|
+
export function retry<T>(call: () => Promise<T>, times: number, delayS: number): Promise<T> {
|
|
231
|
+
let promiseChain = call();
|
|
232
|
+
for (let i = 0; i < times; i++)
|
|
233
|
+
promiseChain = promiseChain.catch(async () => {
|
|
234
|
+
await delay(delayS);
|
|
235
|
+
return await call();
|
|
236
|
+
});
|
|
237
|
+
return promiseChain;
|
|
273
238
|
}
|
|
274
239
|
|
|
275
240
|
export type TransactionCostEstimate = {
|