@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.
Files changed (43) hide show
  1. package/dist/cjs/src/caching/Arweave/ArweaveClient.d.ts +2 -0
  2. package/dist/cjs/src/caching/Arweave/ArweaveClient.js +116 -40
  3. package/dist/cjs/src/caching/Arweave/ArweaveClient.js.map +1 -1
  4. package/dist/cjs/src/clients/BundleDataClient/BundleDataClient.d.ts +5 -2
  5. package/dist/cjs/src/clients/BundleDataClient/BundleDataClient.js +74 -10
  6. package/dist/cjs/src/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  7. package/dist/cjs/src/coingecko/Coingecko.js +2 -9
  8. package/dist/cjs/src/coingecko/Coingecko.js.map +1 -1
  9. package/dist/cjs/src/utils/CachingUtils.d.ts +1 -0
  10. package/dist/cjs/src/utils/CachingUtils.js +4 -0
  11. package/dist/cjs/src/utils/CachingUtils.js.map +1 -1
  12. package/dist/cjs/src/utils/common.d.ts +1 -13
  13. package/dist/cjs/src/utils/common.js +8 -19
  14. package/dist/cjs/src/utils/common.js.map +1 -1
  15. package/dist/esm/src/caching/Arweave/ArweaveClient.d.ts +2 -0
  16. package/dist/esm/src/caching/Arweave/ArweaveClient.js +117 -47
  17. package/dist/esm/src/caching/Arweave/ArweaveClient.js.map +1 -1
  18. package/dist/esm/src/clients/BundleDataClient/BundleDataClient.d.ts +5 -2
  19. package/dist/esm/src/clients/BundleDataClient/BundleDataClient.js +77 -13
  20. package/dist/esm/src/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  21. package/dist/esm/src/coingecko/Coingecko.js +2 -9
  22. package/dist/esm/src/coingecko/Coingecko.js.map +1 -1
  23. package/dist/esm/src/utils/CachingUtils.d.ts +1 -0
  24. package/dist/esm/src/utils/CachingUtils.js +3 -0
  25. package/dist/esm/src/utils/CachingUtils.js.map +1 -1
  26. package/dist/esm/src/utils/common.d.ts +6 -33
  27. package/dist/esm/src/utils/common.js +13 -26
  28. package/dist/esm/src/utils/common.js.map +1 -1
  29. package/dist/types/src/caching/Arweave/ArweaveClient.d.ts +2 -0
  30. package/dist/types/src/caching/Arweave/ArweaveClient.d.ts.map +1 -1
  31. package/dist/types/src/clients/BundleDataClient/BundleDataClient.d.ts +5 -2
  32. package/dist/types/src/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  33. package/dist/types/src/coingecko/Coingecko.d.ts.map +1 -1
  34. package/dist/types/src/utils/CachingUtils.d.ts +1 -0
  35. package/dist/types/src/utils/CachingUtils.d.ts.map +1 -1
  36. package/dist/types/src/utils/common.d.ts +6 -33
  37. package/dist/types/src/utils/common.d.ts.map +1 -1
  38. package/package.json +1 -1
  39. package/src/caching/Arweave/ArweaveClient.ts +142 -54
  40. package/src/clients/BundleDataClient/BundleDataClient.ts +86 -17
  41. package/src/coingecko/Coingecko.ts +2 -9
  42. package/src/utils/CachingUtils.ts +4 -0
  43. package/src/utils/common.ts +14 -49
@@ -221,55 +221,20 @@ export function delay(seconds: number) {
221
221
  }
222
222
 
223
223
  /**
224
- * Discriminated union for operations that can fail. Callers narrow on `.ok`: success
225
- * carries `value`, failure carries the original `error` for inspection. Avoids the
226
- * control-flow cost of try/catch at call sites that want to handle failure as data.
227
- */
228
- export type Result<T, E = Error> = { ok: true; value: T } | { ok: false; error: E };
229
-
230
- /**
231
- * Configures {@link retry}. Retries always use exponential backoff
232
- * (`delaySeconds * 2 ** attempt + random()` seconds) to play nicely with upstream
233
- * rate-limits; callers that want tighter spacing should lower {@link delaySeconds}.
234
- */
235
- export type RetryOptions = {
236
- /** Maximum number of retry attempts after the initial call (total attempts = retries + 1). Defaults to 2 (3 total tries). */
237
- retries?: number;
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 = {