@across-protocol/sdk 4.3.145-alpha.2 → 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 -24
  13. package/dist/cjs/src/utils/common.js +8 -33
  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 -55
  27. package/dist/esm/src/utils/common.js +15 -32
  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 -55
  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 -93
@@ -378,7 +378,7 @@ export class Coingecko {
378
378
  return this.call("asset_platforms");
379
379
  }
380
380
 
381
- async call<T>(path: string): Promise<T> {
381
+ call<T>(path: string): Promise<T> {
382
382
  const sendRequest = async () => {
383
383
  const { proHost } = this;
384
384
 
@@ -401,14 +401,7 @@ export class Coingecko {
401
401
  };
402
402
 
403
403
  // Note: If a pro API key is configured, there is no need to retry as the Pro API will act as the basic's fall back.
404
- const result = await retry(sendRequest, {
405
- retries: this.apiKey === undefined ? this.numRetries : 0,
406
- delaySeconds: this.retryDelay,
407
- });
408
- if (!result.ok) {
409
- throw result.error;
410
- }
411
- return result.value;
404
+ return retry(sendRequest, this.apiKey === undefined ? this.numRetries : 0, this.retryDelay);
412
405
  }
413
406
 
414
407
  protected getPriceCache(currency: string, platform_id: string): { [addr: string]: CoinGeckoPrice } {
@@ -54,3 +54,7 @@ export function getDepositKey(bridgeEvent: Deposit | Fill | SlowFillRequest): st
54
54
  const relayHash = getRelayEventKey(bridgeEvent);
55
55
  return `deposit_${bridgeEvent.originChainId}_${bridgeEvent.depositId.toString()}_${relayHash}`;
56
56
  }
57
+
58
+ export function getArweaveTopicCacheKey(tag: string): string {
59
+ return `arweave-topic:${tag}`;
60
+ }
@@ -1,7 +1,6 @@
1
1
  import Decimal from "decimal.js";
2
2
  import bs58 from "bs58";
3
3
  import { ethers } from "ethers";
4
- import { create, Struct } from "superstruct";
5
4
  import { BigNumber, BigNumberish, BN, formatUnits, parseUnits, toBN } from "./BigNumberUtils";
6
5
  import { ConvertDecimals } from "./FormattingUtils";
7
6
 
@@ -222,98 +221,20 @@ export function delay(seconds: number) {
222
221
  }
223
222
 
224
223
  /**
225
- * Discriminated union for operations that can fail. Callers narrow on `.ok`: success
226
- * carries `value`, failure carries the original `error` for inspection. Avoids the
227
- * control-flow cost of try/catch at call sites that want to handle failure as data.
228
- */
229
- export type Result<T, E = Error> = { ok: true; value: T } | { ok: false; error: E };
230
-
231
- /**
232
- * Configures a single {@link attempt}. `schema`, when supplied, runs the successful value
233
- * through `create(value, schema)` before wrapping validation failures surface as a
234
- * `{ ok: false }` Result like any other throw.
235
- */
236
- export type AttemptOptions<T = unknown> = {
237
- schema?: Struct<T>;
238
- };
239
-
240
- /**
241
- * Configures the outer loop of {@link retry}. Backoff is always exponential
242
- * (`delaySeconds * 2 ** attempt + random()` seconds) to play nicely with upstream
243
- * rate-limits; callers that want tighter spacing should lower {@link delaySeconds}.
244
- */
245
- export type RetryOptions = {
246
- /** Maximum number of retry attempts after the initial call (total attempts = retries + 1). Defaults to 2 (3 total tries). */
247
- retries?: number;
248
- /** Base delay in seconds for the exponential backoff. Defaults to 1. */
249
- delaySeconds?: number;
250
- /** Predicate evaluated against the thrown error to decide whether to retry. Defaults to retrying every error. */
251
- isRetryable?: (err: unknown) => boolean;
252
- };
253
-
254
- const DEFAULT_RETRY_OPTIONS: Required<RetryOptions> = {
255
- retries: 2,
256
- delaySeconds: 1,
257
- isRetryable: () => true,
258
- };
259
-
260
- /**
261
- * Run a failable operation once, catching throws and returning a {@link Result}. When
262
- * `schema` is supplied, the successful value is validated via `create(value, schema)`
263
- * before being wrapped; a failed validation lands in `{ ok: false, error }` with the
264
- * superstruct error preserved.
265
- */
266
- export function attempt<T>(
267
- call: () => Promise<unknown>,
268
- options: AttemptOptions<T> & { schema: Struct<T> }
269
- ): Promise<Result<T>>;
270
- export function attempt<T>(call: () => Promise<T>, options?: AttemptOptions): Promise<Result<T>>;
271
- export async function attempt<T>(
272
- call: () => Promise<unknown>,
273
- options: AttemptOptions<T> = {}
274
- ): Promise<Result<T>> {
275
- try {
276
- const raw = await call();
277
- const value = options.schema ? create(raw, options.schema) : (raw as T);
278
- return { ok: true, value };
279
- } catch (err) {
280
- return { ok: false, error: err instanceof Error ? err : new Error(String(err)) };
281
- }
282
- }
283
-
284
- /**
285
- * Loop {@link attempt} with exponential backoff until success or a terminal failure —
286
- * exhausted retry budget or a failure rejected by `isRetryable`. The inner attempt's
287
- * validation (via `schema`) participates in the retry budget; a malformed response is
288
- * retried unless `isRetryable` opts out.
289
- * @param call The function to call on each attempt.
290
- * @param options Retry + attempt configuration (see {@link RetryOptions}, {@link AttemptOptions}).
291
- * @returns A `Result<T>` wrapping the terminal outcome.
292
- */
293
- export function retry<T>(
294
- call: () => Promise<unknown>,
295
- options: RetryOptions & AttemptOptions<T> & { schema: Struct<T> }
296
- ): Promise<Result<T>>;
297
- export function retry<T>(call: () => Promise<T>, options?: RetryOptions): Promise<Result<T>>;
298
- export async function retry<T>(
299
- call: () => Promise<unknown>,
300
- options: RetryOptions & AttemptOptions<T> = {}
301
- ): Promise<Result<T>> {
302
- const resolved: Required<RetryOptions> = { ...DEFAULT_RETRY_OPTIONS, ...options };
303
- const backoffSeconds = (n: number): number => resolved.delaySeconds * 2 ** n + Math.random();
304
-
305
- for (let nAttempts = 0; ; ++nAttempts) {
306
- try {
307
- const raw = await call();
308
- const value = options.schema ? create(raw, options.schema) : (raw as T);
309
- return { ok: true, value };
310
- } catch (err) {
311
- if (nAttempts >= resolved.retries || !resolved.isRetryable(err)) {
312
- return { ok: false, error: err instanceof Error ? err : new Error(String(err)) };
313
- }
314
- await delay(backoffSeconds(nAttempts));
315
- }
316
- }
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;
317
238
  }
318
239
 
319
240
  export type TransactionCostEstimate = {