@trustware/sdk-staging 1.1.10-staging.0 → 1.1.11-staging.2

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 (38) hide show
  1. package/README.md +54 -21
  2. package/dist/constants.cjs +1 -1
  3. package/dist/constants.mjs +1 -1
  4. package/dist/{core-BPLiD1UG.d.ts → core-B1WCJfDI.d.ts} +15 -2
  5. package/dist/{core-B7Ez-5-r.d.cts → core-CeNTuqPz.d.cts} +15 -2
  6. package/dist/core.cjs +365 -279
  7. package/dist/core.cjs.map +1 -1
  8. package/dist/core.d.cts +2 -2
  9. package/dist/core.d.ts +2 -2
  10. package/dist/core.mjs +363 -278
  11. package/dist/core.mjs.map +1 -1
  12. package/dist/index.cjs +375 -170
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +11 -5
  15. package/dist/index.d.ts +11 -5
  16. package/dist/index.mjs +373 -169
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/{manager-B6NNV-E_.d.ts → manager-Bw8b1wSD.d.ts} +136 -21
  19. package/dist/{manager-BwjyFjjz.d.cts → manager-DNGk1YkR.d.cts} +136 -21
  20. package/dist/{metadata-BiTMMvlY.d.ts → metadata-C__KMeuz.d.ts} +1 -1
  21. package/dist/{metadata-HCflXcsF.d.cts → metadata-Dk4R8_-T.d.cts} +1 -1
  22. package/dist/smart-account.cjs +49 -44
  23. package/dist/smart-account.cjs.map +1 -1
  24. package/dist/smart-account.d.cts +17 -12
  25. package/dist/smart-account.d.ts +17 -12
  26. package/dist/smart-account.mjs +49 -44
  27. package/dist/smart-account.mjs.map +1 -1
  28. package/dist/wallet.cjs +54 -39
  29. package/dist/wallet.cjs.map +1 -1
  30. package/dist/wallet.d.cts +3 -3
  31. package/dist/wallet.d.ts +3 -3
  32. package/dist/wallet.mjs +54 -39
  33. package/dist/wallet.mjs.map +1 -1
  34. package/dist/widget.cjs +369 -170
  35. package/dist/widget.cjs.map +1 -1
  36. package/dist/widget.mjs +369 -169
  37. package/dist/widget.mjs.map +1 -1
  38. package/package.json +73 -5
@@ -311,8 +311,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
311
311
  [x: `uint[${string}]`]: undefined;
312
312
  [x: `function[${string}]`]: undefined;
313
313
  [x: `bytes18[${string}]`]: undefined;
314
- [x: `bytes16[${string}]`]: undefined;
315
314
  [x: `bytes1[${string}]`]: undefined;
315
+ [x: `bytes16[${string}]`]: undefined;
316
316
  [x: `bytes2[${string}]`]: undefined;
317
317
  [x: `bytes3[${string}]`]: undefined;
318
318
  [x: `bytes8[${string}]`]: undefined;
@@ -411,8 +411,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
411
411
  bool?: undefined;
412
412
  bytes?: undefined;
413
413
  bytes18?: undefined;
414
- bytes16?: undefined;
415
414
  bytes1?: undefined;
415
+ bytes16?: undefined;
416
416
  bytes2?: undefined;
417
417
  bytes3?: undefined;
418
418
  bytes8?: undefined;
@@ -518,8 +518,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
518
518
  [x: `uint[${string}]`]: undefined;
519
519
  [x: `function[${string}]`]: undefined;
520
520
  [x: `bytes18[${string}]`]: undefined;
521
- [x: `bytes16[${string}]`]: undefined;
522
521
  [x: `bytes1[${string}]`]: undefined;
522
+ [x: `bytes16[${string}]`]: undefined;
523
523
  [x: `bytes2[${string}]`]: undefined;
524
524
  [x: `bytes3[${string}]`]: undefined;
525
525
  [x: `bytes8[${string}]`]: undefined;
@@ -618,8 +618,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
618
618
  bool?: undefined;
619
619
  bytes?: undefined;
620
620
  bytes18?: undefined;
621
- bytes16?: undefined;
622
621
  bytes1?: undefined;
622
+ bytes16?: undefined;
623
623
  bytes2?: undefined;
624
624
  bytes3?: undefined;
625
625
  bytes8?: undefined;
@@ -2761,8 +2761,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
2761
2761
  [x: `uint[${string}]`]: undefined;
2762
2762
  [x: `function[${string}]`]: undefined;
2763
2763
  [x: `bytes18[${string}]`]: undefined;
2764
- [x: `bytes16[${string}]`]: undefined;
2765
2764
  [x: `bytes1[${string}]`]: undefined;
2765
+ [x: `bytes16[${string}]`]: undefined;
2766
2766
  [x: `bytes2[${string}]`]: undefined;
2767
2767
  [x: `bytes3[${string}]`]: undefined;
2768
2768
  [x: `bytes8[${string}]`]: undefined;
@@ -2861,8 +2861,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
2861
2861
  bool?: undefined;
2862
2862
  bytes?: undefined;
2863
2863
  bytes18?: undefined;
2864
- bytes16?: undefined;
2865
2864
  bytes1?: undefined;
2865
+ bytes16?: undefined;
2866
2866
  bytes2?: undefined;
2867
2867
  bytes3?: undefined;
2868
2868
  bytes8?: undefined;
@@ -2984,8 +2984,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
2984
2984
  [x: `uint[${string}]`]: undefined;
2985
2985
  [x: `function[${string}]`]: undefined;
2986
2986
  [x: `bytes18[${string}]`]: undefined;
2987
- [x: `bytes16[${string}]`]: undefined;
2988
2987
  [x: `bytes1[${string}]`]: undefined;
2988
+ [x: `bytes16[${string}]`]: undefined;
2989
2989
  [x: `bytes2[${string}]`]: undefined;
2990
2990
  [x: `bytes3[${string}]`]: undefined;
2991
2991
  [x: `bytes8[${string}]`]: undefined;
@@ -3084,8 +3084,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
3084
3084
  bool?: undefined;
3085
3085
  bytes?: undefined;
3086
3086
  bytes18?: undefined;
3087
- bytes16?: undefined;
3088
3087
  bytes1?: undefined;
3088
+ bytes16?: undefined;
3089
3089
  bytes2?: undefined;
3090
3090
  bytes3?: undefined;
3091
3091
  bytes8?: undefined;
@@ -3458,8 +3458,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
3458
3458
  [x: `uint[${string}]`]: undefined;
3459
3459
  [x: `function[${string}]`]: undefined;
3460
3460
  [x: `bytes18[${string}]`]: undefined;
3461
- [x: `bytes16[${string}]`]: undefined;
3462
3461
  [x: `bytes1[${string}]`]: undefined;
3462
+ [x: `bytes16[${string}]`]: undefined;
3463
3463
  [x: `bytes2[${string}]`]: undefined;
3464
3464
  [x: `bytes3[${string}]`]: undefined;
3465
3465
  [x: `bytes8[${string}]`]: undefined;
@@ -3558,8 +3558,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
3558
3558
  bool?: undefined;
3559
3559
  bytes?: undefined;
3560
3560
  bytes18?: undefined;
3561
- bytes16?: undefined;
3562
3561
  bytes1?: undefined;
3562
+ bytes16?: undefined;
3563
3563
  bytes2?: undefined;
3564
3564
  bytes3?: undefined;
3565
3565
  bytes8?: undefined;
@@ -3681,8 +3681,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
3681
3681
  [x: `uint[${string}]`]: undefined;
3682
3682
  [x: `function[${string}]`]: undefined;
3683
3683
  [x: `bytes18[${string}]`]: undefined;
3684
- [x: `bytes16[${string}]`]: undefined;
3685
3684
  [x: `bytes1[${string}]`]: undefined;
3685
+ [x: `bytes16[${string}]`]: undefined;
3686
3686
  [x: `bytes2[${string}]`]: undefined;
3687
3687
  [x: `bytes3[${string}]`]: undefined;
3688
3688
  [x: `bytes8[${string}]`]: undefined;
@@ -3781,8 +3781,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
3781
3781
  bool?: undefined;
3782
3782
  bytes?: undefined;
3783
3783
  bytes18?: undefined;
3784
- bytes16?: undefined;
3785
3784
  bytes1?: undefined;
3785
+ bytes16?: undefined;
3786
3786
  bytes2?: undefined;
3787
3787
  bytes3?: undefined;
3788
3788
  bytes8?: undefined;
@@ -3953,6 +3953,11 @@ type RoutePlan = {
3953
3953
  };
3954
3954
  steps?: unknown[];
3955
3955
  provider?: string;
3956
+ /** The winning provider's own correlation ID, not Trustware's — it is
3957
+ * absent when that provider issued none, and it is what lands on the
3958
+ * intent as `providerRequestId`. Trustware's request ID for the same call
3959
+ * comes back in the `X-Request-Id` response header (the provider's is also
3960
+ * mirrored there as `X-Provider-Request-Id`). */
3956
3961
  requestId?: string;
3957
3962
  reliabilityScore?: number;
3958
3963
  diagnostics?: {
@@ -311,8 +311,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
311
311
  [x: `uint[${string}]`]: undefined;
312
312
  [x: `function[${string}]`]: undefined;
313
313
  [x: `bytes18[${string}]`]: undefined;
314
- [x: `bytes16[${string}]`]: undefined;
315
314
  [x: `bytes1[${string}]`]: undefined;
315
+ [x: `bytes16[${string}]`]: undefined;
316
316
  [x: `bytes2[${string}]`]: undefined;
317
317
  [x: `bytes3[${string}]`]: undefined;
318
318
  [x: `bytes8[${string}]`]: undefined;
@@ -411,8 +411,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
411
411
  bool?: undefined;
412
412
  bytes?: undefined;
413
413
  bytes18?: undefined;
414
- bytes16?: undefined;
415
414
  bytes1?: undefined;
415
+ bytes16?: undefined;
416
416
  bytes2?: undefined;
417
417
  bytes3?: undefined;
418
418
  bytes8?: undefined;
@@ -518,8 +518,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
518
518
  [x: `uint[${string}]`]: undefined;
519
519
  [x: `function[${string}]`]: undefined;
520
520
  [x: `bytes18[${string}]`]: undefined;
521
- [x: `bytes16[${string}]`]: undefined;
522
521
  [x: `bytes1[${string}]`]: undefined;
522
+ [x: `bytes16[${string}]`]: undefined;
523
523
  [x: `bytes2[${string}]`]: undefined;
524
524
  [x: `bytes3[${string}]`]: undefined;
525
525
  [x: `bytes8[${string}]`]: undefined;
@@ -618,8 +618,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
618
618
  bool?: undefined;
619
619
  bytes?: undefined;
620
620
  bytes18?: undefined;
621
- bytes16?: undefined;
622
621
  bytes1?: undefined;
622
+ bytes16?: undefined;
623
623
  bytes2?: undefined;
624
624
  bytes3?: undefined;
625
625
  bytes8?: undefined;
@@ -2761,8 +2761,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
2761
2761
  [x: `uint[${string}]`]: undefined;
2762
2762
  [x: `function[${string}]`]: undefined;
2763
2763
  [x: `bytes18[${string}]`]: undefined;
2764
- [x: `bytes16[${string}]`]: undefined;
2765
2764
  [x: `bytes1[${string}]`]: undefined;
2765
+ [x: `bytes16[${string}]`]: undefined;
2766
2766
  [x: `bytes2[${string}]`]: undefined;
2767
2767
  [x: `bytes3[${string}]`]: undefined;
2768
2768
  [x: `bytes8[${string}]`]: undefined;
@@ -2861,8 +2861,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
2861
2861
  bool?: undefined;
2862
2862
  bytes?: undefined;
2863
2863
  bytes18?: undefined;
2864
- bytes16?: undefined;
2865
2864
  bytes1?: undefined;
2865
+ bytes16?: undefined;
2866
2866
  bytes2?: undefined;
2867
2867
  bytes3?: undefined;
2868
2868
  bytes8?: undefined;
@@ -2984,8 +2984,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
2984
2984
  [x: `uint[${string}]`]: undefined;
2985
2985
  [x: `function[${string}]`]: undefined;
2986
2986
  [x: `bytes18[${string}]`]: undefined;
2987
- [x: `bytes16[${string}]`]: undefined;
2988
2987
  [x: `bytes1[${string}]`]: undefined;
2988
+ [x: `bytes16[${string}]`]: undefined;
2989
2989
  [x: `bytes2[${string}]`]: undefined;
2990
2990
  [x: `bytes3[${string}]`]: undefined;
2991
2991
  [x: `bytes8[${string}]`]: undefined;
@@ -3084,8 +3084,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
3084
3084
  bool?: undefined;
3085
3085
  bytes?: undefined;
3086
3086
  bytes18?: undefined;
3087
- bytes16?: undefined;
3088
3087
  bytes1?: undefined;
3088
+ bytes16?: undefined;
3089
3089
  bytes2?: undefined;
3090
3090
  bytes3?: undefined;
3091
3091
  bytes8?: undefined;
@@ -3458,8 +3458,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
3458
3458
  [x: `uint[${string}]`]: undefined;
3459
3459
  [x: `function[${string}]`]: undefined;
3460
3460
  [x: `bytes18[${string}]`]: undefined;
3461
- [x: `bytes16[${string}]`]: undefined;
3462
3461
  [x: `bytes1[${string}]`]: undefined;
3462
+ [x: `bytes16[${string}]`]: undefined;
3463
3463
  [x: `bytes2[${string}]`]: undefined;
3464
3464
  [x: `bytes3[${string}]`]: undefined;
3465
3465
  [x: `bytes8[${string}]`]: undefined;
@@ -3558,8 +3558,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
3558
3558
  bool?: undefined;
3559
3559
  bytes?: undefined;
3560
3560
  bytes18?: undefined;
3561
- bytes16?: undefined;
3562
3561
  bytes1?: undefined;
3562
+ bytes16?: undefined;
3563
3563
  bytes2?: undefined;
3564
3564
  bytes3?: undefined;
3565
3565
  bytes8?: undefined;
@@ -3681,8 +3681,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
3681
3681
  [x: `uint[${string}]`]: undefined;
3682
3682
  [x: `function[${string}]`]: undefined;
3683
3683
  [x: `bytes18[${string}]`]: undefined;
3684
- [x: `bytes16[${string}]`]: undefined;
3685
3684
  [x: `bytes1[${string}]`]: undefined;
3685
+ [x: `bytes16[${string}]`]: undefined;
3686
3686
  [x: `bytes2[${string}]`]: undefined;
3687
3687
  [x: `bytes3[${string}]`]: undefined;
3688
3688
  [x: `bytes8[${string}]`]: undefined;
@@ -3781,8 +3781,8 @@ declare function createTrustwareSmartAccountClient(eoaAddress: `0x${string}`, ch
3781
3781
  bool?: undefined;
3782
3782
  bytes?: undefined;
3783
3783
  bytes18?: undefined;
3784
- bytes16?: undefined;
3785
3784
  bytes1?: undefined;
3785
+ bytes16?: undefined;
3786
3786
  bytes2?: undefined;
3787
3787
  bytes3?: undefined;
3788
3788
  bytes8?: undefined;
@@ -3953,6 +3953,11 @@ type RoutePlan = {
3953
3953
  };
3954
3954
  steps?: unknown[];
3955
3955
  provider?: string;
3956
+ /** The winning provider's own correlation ID, not Trustware's — it is
3957
+ * absent when that provider issued none, and it is what lands on the
3958
+ * intent as `providerRequestId`. Trustware's request ID for the same call
3959
+ * comes back in the `X-Request-Id` response header (the provider's is also
3960
+ * mirrored there as `X-Provider-Request-Id`). */
3956
3961
  requestId?: string;
3957
3962
  reliabilityScore?: number;
3958
3963
  diagnostics?: {
@@ -12241,7 +12241,7 @@ var init_constants = __esm({
12241
12241
  "src/constants.ts"() {
12242
12242
  "use strict";
12243
12243
  SDK_NAME = "@trustware/sdk";
12244
- SDK_VERSION = "1.1.10-staging.0";
12244
+ SDK_VERSION = "1.1.11-staging.2";
12245
12245
  API_ROOT = "https://bv-staging-api.trustware.io";
12246
12246
  API_PREFIX = "/api";
12247
12247
  }
@@ -12262,16 +12262,14 @@ var init_defaults3 = __esm({
12262
12262
  });
12263
12263
 
12264
12264
  // src/types/config.ts
12265
- var DEFAULT_RETRY_CONFIG, DEFAULT_FEATURE_FLAGS;
12265
+ var DEFAULT_RETRY_CONFIG, RATE_LIMIT_WAIT_BUDGET_MS, DEFAULT_FEATURE_FLAGS;
12266
12266
  var init_config = __esm({
12267
12267
  "src/types/config.ts"() {
12268
12268
  "use strict";
12269
12269
  DEFAULT_RETRY_CONFIG = {
12270
- autoRetry: true,
12271
- maxRetries: 3,
12272
- baseDelayMs: 1e3,
12273
12270
  approachingThreshold: 5
12274
12271
  };
12272
+ RATE_LIMIT_WAIT_BUDGET_MS = 1e4;
12275
12273
  DEFAULT_FEATURE_FLAGS = {
12276
12274
  tokensPagination: true,
12277
12275
  balanceStreaming: false,
@@ -13547,9 +13545,6 @@ function resolveConfig(input) {
13547
13545
  const theme = input.theme ?? "system";
13548
13546
  const messages = deepMerge(DEFAULT_MESSAGES, input.messages);
13549
13547
  const retry = {
13550
- autoRetry: input.retry?.autoRetry ?? DEFAULT_RETRY_CONFIG.autoRetry,
13551
- maxRetries: input.retry?.maxRetries ?? DEFAULT_RETRY_CONFIG.maxRetries,
13552
- baseDelayMs: input.retry?.baseDelayMs ?? DEFAULT_RETRY_CONFIG.baseDelayMs,
13553
13548
  approachingThreshold: input.retry?.approachingThreshold ?? DEFAULT_RETRY_CONFIG.approachingThreshold,
13554
13549
  onRateLimitInfo: input.retry?.onRateLimitInfo,
13555
13550
  onRateLimited: input.retry?.onRateLimited,
@@ -13660,60 +13655,66 @@ function notifyRateLimitCallbacks(info, isRateLimited, retryCount) {
13660
13655
  retry.onRateLimitApproaching(info, retry.approachingThreshold);
13661
13656
  }
13662
13657
  }
13663
- function calculateBackoffDelay(baseDelayMs, retryCount, retryAfter) {
13664
- if (retryAfter && retryAfter > 0) {
13665
- return retryAfter * 1e3;
13658
+ function serverDirectedWaitMs(info) {
13659
+ if (!info) return null;
13660
+ if (typeof info.retryAfter === "number" && info.retryAfter > 0) {
13661
+ return info.retryAfter * 1e3;
13666
13662
  }
13667
- return baseDelayMs * Math.pow(2, retryCount);
13663
+ if (typeof info.reset === "number" && info.reset > 0) {
13664
+ const untilReset = info.reset * 1e3 - Date.now();
13665
+ if (untilReset > 0) return untilReset;
13666
+ }
13667
+ return null;
13668
13668
  }
13669
13669
  function sleep(ms) {
13670
13670
  return new Promise((resolve) => setTimeout(resolve, ms));
13671
13671
  }
13672
- async function rateLimitedFetch(url, options = {}) {
13673
- const { skipRateLimit, ...fetchOptions } = options;
13674
- const cfg = TrustwareConfigStore.get();
13675
- if (!cfg.retry.autoRetry || skipRateLimit) {
13676
- return fetch(url, fetchOptions);
13677
- }
13678
- const { maxRetries, baseDelayMs } = cfg.retry;
13672
+ async function withRateLimitRetry(attempt) {
13673
+ let waitedMs = 0;
13679
13674
  let retryCount = 0;
13680
13675
  while (true) {
13681
- const response = await fetch(url, fetchOptions);
13676
+ const response = await attempt();
13682
13677
  const rateLimitInfo = parseRateLimitHeaders(response);
13683
- if (response.status === 429) {
13678
+ if (response.status !== 429) {
13684
13679
  if (rateLimitInfo) {
13685
- notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
13686
- }
13687
- if (retryCount >= maxRetries) {
13688
- throw new RateLimitError(
13689
- rateLimitInfo || { limit: 0, remaining: 0, reset: 0 },
13690
- true
13691
- );
13680
+ notifyRateLimitCallbacks(rateLimitInfo, false, 0);
13692
13681
  }
13693
- const delay = calculateBackoffDelay(
13694
- baseDelayMs,
13695
- retryCount,
13696
- rateLimitInfo?.retryAfter
13697
- );
13698
- await sleep(delay);
13699
- retryCount++;
13700
- continue;
13682
+ return response;
13701
13683
  }
13702
13684
  if (rateLimitInfo) {
13703
- notifyRateLimitCallbacks(rateLimitInfo, false, 0);
13685
+ notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
13686
+ }
13687
+ const waitMs = serverDirectedWaitMs(rateLimitInfo);
13688
+ const info = rateLimitInfo || { limit: 0, remaining: 0, reset: 0 };
13689
+ if (waitMs === null) {
13690
+ throw new RateLimitError(info, true);
13691
+ }
13692
+ if (waitedMs + waitMs > RATE_LIMIT_WAIT_BUDGET_MS) {
13693
+ throw new RateLimitError(info, false);
13704
13694
  }
13705
- return response;
13695
+ await sleep(waitMs);
13696
+ waitedMs += waitMs;
13697
+ retryCount++;
13706
13698
  }
13707
13699
  }
13700
+ async function rateLimitedFetch(url, options = {}) {
13701
+ const { skipRateLimit, ...fetchOptions } = options;
13702
+ if (skipRateLimit) {
13703
+ return fetch(url, fetchOptions);
13704
+ }
13705
+ return withRateLimitRetry(() => fetch(url, fetchOptions));
13706
+ }
13708
13707
  var RateLimitError;
13709
13708
  var init_http = __esm({
13710
13709
  "src/core/http.ts"() {
13711
13710
  "use strict";
13712
13711
  init_constants();
13713
13712
  init_config2();
13713
+ init_config();
13714
13714
  RateLimitError = class extends Error {
13715
13715
  constructor(info, retriesExhausted) {
13716
- const message = retriesExhausted ? `Rate limit exceeded after max retries. Try again in ${info.retryAfter ?? Math.ceil((info.reset * 1e3 - Date.now()) / 1e3)} seconds.` : `Rate limit exceeded. Try again in ${info.retryAfter} seconds.`;
13716
+ const seconds = info.retryAfter ?? (info.reset > 0 ? Math.max(0, Math.ceil((info.reset * 1e3 - Date.now()) / 1e3)) : null);
13717
+ const message = seconds === null ? "Rate limit exceeded. The server did not say when to retry." : `Rate limit exceeded. Try again in ${seconds} seconds.`;
13717
13718
  super(message);
13718
13719
  this.name = "RateLimitError";
13719
13720
  this.rateLimitInfo = info;
@@ -13730,7 +13731,7 @@ import {
13730
13731
  keccak256 as keccak2565,
13731
13732
  stringToHex
13732
13733
  } from "viem";
13733
- async function fetchWithTimeout(url, init) {
13734
+ async function fetchOnceWithTimeout(url, init) {
13734
13735
  const controller = new AbortController();
13735
13736
  const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
13736
13737
  try {
@@ -13751,6 +13752,9 @@ async function fetchWithTimeout(url, init) {
13751
13752
  clearTimeout(timer);
13752
13753
  }
13753
13754
  }
13755
+ async function fetchWithTimeout(url, init) {
13756
+ return withRateLimitRetry(() => fetchOnceWithTimeout(url, init));
13757
+ }
13754
13758
  function extractRevertHex(err) {
13755
13759
  if (typeof err.data === "string" && err.data.startsWith("0x"))
13756
13760
  return err.data;
@@ -14250,7 +14254,7 @@ async function estimateRelayFeeInToken(valueWei, fromAmountWei, fromAmountUSD, c
14250
14254
  tokenUnitsPerDollar = Number(fromAmountWei) / fromUSD;
14251
14255
  } else if (fromToken && fromDecimals !== void 0) {
14252
14256
  try {
14253
- const resp = await fetch(
14257
+ const resp = await rateLimitedFetch(
14254
14258
  `${apiBase()}/v1/price/token?chainId=${cid}&address=${fromToken}`,
14255
14259
  { headers: jsonHeaders() }
14256
14260
  );
@@ -14266,9 +14270,10 @@ async function estimateRelayFeeInToken(valueWei, fromAmountWei, fromAmountUSD, c
14266
14270
  return 0n;
14267
14271
  }
14268
14272
  try {
14269
- const resp = await fetch(`${apiBase()}/v1/price/native?chainId=${cid}`, {
14270
- headers: jsonHeaders()
14271
- });
14273
+ const resp = await rateLimitedFetch(
14274
+ `${apiBase()}/v1/price/native?chainId=${cid}`,
14275
+ { headers: jsonHeaders() }
14276
+ );
14272
14277
  if (!resp.ok) throw new Error(`native price HTTP ${resp.status}`);
14273
14278
  const json = await resp.json();
14274
14279
  const ethPriceUSD = parseFloat(json.data?.priceUSD ?? "0");