@scallop-io/sui-scallop-sdk 1.4.1-alpha.1 → 1.4.11

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.
@@ -16,11 +16,14 @@ class TokenBucket {
16
16
  refill() {
17
17
  const now = Date.now();
18
18
  const elapsed = now - this.lastRefill;
19
- if (elapsed > this.interval) {
19
+
20
+ if (elapsed >= this.interval) {
20
21
  const tokensToAdd =
21
22
  Math.floor(elapsed / this.interval) * this.tokensPerInterval;
22
23
  this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
23
- this.lastRefill = now;
24
+
25
+ // Update lastRefill to reflect the exact time of the last "refill"
26
+ this.lastRefill += Math.floor(elapsed / this.interval) * this.interval;
24
27
  }
25
28
  }
26
29
 
@@ -45,35 +48,12 @@ const callWithRateLimit = async <T>(
45
48
 
46
49
  const tryRequest = async (): Promise<T | null> => {
47
50
  if (tokenBucket.removeTokens(1)) {
48
- try {
49
- const result = await fn();
50
-
51
- // Check if the result is an object with status code (assuming the response has a status property)
52
- if (result && (result as any).status === 429) {
53
- throw new Error('Unexpected status code: 429');
54
- }
55
-
56
- return result;
57
- } catch (error: any) {
58
- if (
59
- error.message === 'Unexpected status code: 429' &&
60
- retries < maxRetries
61
- ) {
62
- retries++;
63
- const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
64
- // console.warn(`429 encountered, retrying in ${delay} ms`);
65
- await new Promise((resolve) => setTimeout(resolve, delay));
66
- return tryRequest();
67
- } else {
68
- // console.error(error);
69
- console.error('An error occurred:', error.message);
70
- return null;
71
- }
72
- }
51
+ const result = await fn();
52
+ return result;
73
53
  } else if (retries < maxRetries) {
74
54
  retries++;
75
55
  const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
76
- // console.warn(`Rate limit exceeded, retrying in ${delay} ms`);
56
+ console.error(`Rate limit exceeded, retrying in ${delay} ms`);
77
57
  await new Promise((resolve) => setTimeout(resolve, delay));
78
58
  return tryRequest();
79
59
  } else {
package/dist/test.d.ts DELETED
File without changes
package/src/test.ts DELETED
@@ -1,20 +0,0 @@
1
- // import { ScallopQuery } from './models';
2
-
3
- // const main = async () => {
4
- // try {
5
- // const query = new ScallopQuery({
6
- // walletAddress:
7
- // '0x61819c99588108d9f7710047e6ad8f2da598de8e98a26ea62bd7ad9847f5329c',
8
- // });
9
- // await query.init();
10
-
11
- // const res = await query.getAllCoinPrices();
12
- // console.dir(res, { depth: null });
13
- // } catch (e) {
14
- // console.error(e);
15
- // } finally {
16
- // process.exit(0);
17
- // }
18
- // };
19
-
20
- // main();