@drift-labs/sdk 0.1.36-master.0 → 0.1.36-master.1

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.
@@ -41,8 +41,13 @@ class PollingClearingHouseAccountSubscriber {
41
41
  });
42
42
  yield this.updateAccountsToPoll();
43
43
  yield this.addToAccountLoader();
44
- yield this.fetch();
45
- const subscriptionSucceeded = this.didSubscriptionSucceed();
44
+ let subscriptionSucceeded = false;
45
+ let retries = 0;
46
+ while (!subscriptionSucceeded && retries < 5) {
47
+ yield this.fetch();
48
+ subscriptionSucceeded = this.didSubscriptionSucceed();
49
+ retries++;
50
+ }
46
51
  if (subscriptionSucceeded) {
47
52
  this.eventEmitter.emit('update');
48
53
  }
@@ -162,6 +167,9 @@ class PollingClearingHouseAccountSubscriber {
162
167
  // @ts-ignore
163
168
  this.eventEmitter.emit(accountToPoll.eventType, account);
164
169
  this.eventEmitter.emit('update');
170
+ if (!this.isSubscribed) {
171
+ this.isSubscribed = this.didSubscriptionSucceed();
172
+ }
165
173
  });
166
174
  }
167
175
  this.errorCallbackId = this.accountLoader.addErrorCallbacks((error) => {
@@ -23,4 +23,5 @@ export declare class PollingOracleSubscriber implements OracleSubscriber {
23
23
  unsubscribe(): Promise<void>;
24
24
  assertIsSubscribed(): void;
25
25
  getOraclePriceData(): OraclePriceData;
26
+ didSubscriptionSucceed(): boolean;
26
27
  }
@@ -26,10 +26,18 @@ class PollingOracleSubscriber {
26
26
  return true;
27
27
  }
28
28
  this.addToAccountLoader();
29
- yield this.fetch();
30
- this.eventEmitter.emit('update');
31
- this.isSubscribed = true;
32
- return true;
29
+ let subscriptionSucceeded = false;
30
+ let retries = 0;
31
+ while (!subscriptionSucceeded && retries < 5) {
32
+ yield this.fetch();
33
+ subscriptionSucceeded = this.didSubscriptionSucceed();
34
+ retries++;
35
+ }
36
+ if (subscriptionSucceeded) {
37
+ this.eventEmitter.emit('update');
38
+ }
39
+ this.isSubscribed = subscriptionSucceeded;
40
+ return subscriptionSucceeded;
33
41
  });
34
42
  }
35
43
  addToAccountLoader() {
@@ -75,5 +83,8 @@ class PollingOracleSubscriber {
75
83
  this.assertIsSubscribed();
76
84
  return this.oraclePriceData;
77
85
  }
86
+ didSubscriptionSucceed() {
87
+ return !!this.oraclePriceData;
88
+ }
78
89
  }
79
90
  exports.PollingOracleSubscriber = PollingOracleSubscriber;
@@ -22,4 +22,5 @@ export declare class PollingTokenAccountSubscriber implements TokenAccountSubscr
22
22
  unsubscribe(): Promise<void>;
23
23
  assertIsSubscribed(): void;
24
24
  getTokenAccount(): AccountInfo;
25
+ didSubscriptionSucceed(): boolean;
25
26
  }
@@ -26,10 +26,18 @@ class PollingTokenAccountSubscriber {
26
26
  return true;
27
27
  }
28
28
  this.addToAccountLoader();
29
- yield this.fetch();
30
- this.eventEmitter.emit('update');
31
- this.isSubscribed = true;
32
- return true;
29
+ let subscriptionSucceeded = false;
30
+ let retries = 0;
31
+ while (!subscriptionSucceeded && retries < 5) {
32
+ yield this.fetch();
33
+ subscriptionSucceeded = this.didSubscriptionSucceed();
34
+ retries++;
35
+ }
36
+ if (subscriptionSucceeded) {
37
+ this.eventEmitter.emit('update');
38
+ }
39
+ this.isSubscribed = subscriptionSucceeded;
40
+ return subscriptionSucceeded;
33
41
  });
34
42
  }
35
43
  addToAccountLoader() {
@@ -75,5 +83,8 @@ class PollingTokenAccountSubscriber {
75
83
  this.assertIsSubscribed();
76
84
  return this.tokenAccount;
77
85
  }
86
+ didSubscriptionSucceed() {
87
+ return !!this.tokenAccount;
88
+ }
78
89
  }
79
90
  exports.PollingTokenAccountSubscriber = PollingTokenAccountSubscriber;
@@ -30,8 +30,13 @@ class PollingUserAccountSubscriber {
30
30
  return true;
31
31
  }
32
32
  yield this.addToAccountLoader();
33
- yield this.fetchIfUnloaded();
34
- const subscriptionSucceeded = this.didSubscriptionSucceed();
33
+ let subscriptionSucceeded = false;
34
+ let retries = 0;
35
+ while (!subscriptionSucceeded && retries < 5) {
36
+ yield this.fetchIfUnloaded();
37
+ subscriptionSucceeded = this.didSubscriptionSucceed();
38
+ retries++;
39
+ }
35
40
  if (subscriptionSucceeded) {
36
41
  this.eventEmitter.emit('update');
37
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "0.1.36-master.0",
3
+ "version": "0.1.36-master.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -85,8 +85,14 @@ export class PollingClearingHouseAccountSubscriber
85
85
 
86
86
  await this.updateAccountsToPoll();
87
87
  await this.addToAccountLoader();
88
- await this.fetch();
89
- const subscriptionSucceeded = this.didSubscriptionSucceed();
88
+
89
+ let subscriptionSucceeded = false;
90
+ let retries = 0;
91
+ while (!subscriptionSucceeded && retries < 5) {
92
+ await this.fetch();
93
+ subscriptionSucceeded = this.didSubscriptionSucceed();
94
+ retries++;
95
+ }
90
96
 
91
97
  if (subscriptionSucceeded) {
92
98
  this.eventEmitter.emit('update');
@@ -237,6 +243,10 @@ export class PollingClearingHouseAccountSubscriber
237
243
  // @ts-ignore
238
244
  this.eventEmitter.emit(accountToPoll.eventType, account);
239
245
  this.eventEmitter.emit('update');
246
+
247
+ if (!this.isSubscribed) {
248
+ this.isSubscribed = this.didSubscriptionSucceed();
249
+ }
240
250
  }
241
251
  );
242
252
  }
@@ -37,11 +37,21 @@ export class PollingOracleSubscriber implements OracleSubscriber {
37
37
  }
38
38
 
39
39
  this.addToAccountLoader();
40
- await this.fetch();
41
- this.eventEmitter.emit('update');
42
40
 
43
- this.isSubscribed = true;
44
- return true;
41
+ let subscriptionSucceeded = false;
42
+ let retries = 0;
43
+ while (!subscriptionSucceeded && retries < 5) {
44
+ await this.fetch();
45
+ subscriptionSucceeded = this.didSubscriptionSucceed();
46
+ retries++;
47
+ }
48
+
49
+ if (subscriptionSucceeded) {
50
+ this.eventEmitter.emit('update');
51
+ }
52
+
53
+ this.isSubscribed = subscriptionSucceeded;
54
+ return subscriptionSucceeded;
45
55
  }
46
56
 
47
57
  addToAccountLoader(): void {
@@ -100,4 +110,8 @@ export class PollingOracleSubscriber implements OracleSubscriber {
100
110
  this.assertIsSubscribed();
101
111
  return this.oraclePriceData;
102
112
  }
113
+
114
+ didSubscriptionSucceed(): boolean {
115
+ return !!this.oraclePriceData;
116
+ }
103
117
  }
@@ -36,11 +36,20 @@ export class PollingTokenAccountSubscriber implements TokenAccountSubscriber {
36
36
  }
37
37
 
38
38
  this.addToAccountLoader();
39
- await this.fetch();
40
- this.eventEmitter.emit('update');
39
+ let subscriptionSucceeded = false;
40
+ let retries = 0;
41
+ while (!subscriptionSucceeded && retries < 5) {
42
+ await this.fetch();
43
+ subscriptionSucceeded = this.didSubscriptionSucceed();
44
+ retries++;
45
+ }
46
+
47
+ if (subscriptionSucceeded) {
48
+ this.eventEmitter.emit('update');
49
+ }
41
50
 
42
- this.isSubscribed = true;
43
- return true;
51
+ this.isSubscribed = subscriptionSucceeded;
52
+ return subscriptionSucceeded;
44
53
  }
45
54
 
46
55
  addToAccountLoader(): void {
@@ -96,4 +105,8 @@ export class PollingTokenAccountSubscriber implements TokenAccountSubscriber {
96
105
  this.assertIsSubscribed();
97
106
  return this.tokenAccount;
98
107
  }
108
+
109
+ didSubscriptionSucceed(): boolean {
110
+ return !!this.tokenAccount;
111
+ }
99
112
  }
@@ -52,9 +52,14 @@ export class PollingUserAccountSubscriber implements UserAccountSubscriber {
52
52
  }
53
53
 
54
54
  await this.addToAccountLoader();
55
- await this.fetchIfUnloaded();
56
55
 
57
- const subscriptionSucceeded = this.didSubscriptionSucceed();
56
+ let subscriptionSucceeded = false;
57
+ let retries = 0;
58
+ while (!subscriptionSucceeded && retries < 5) {
59
+ await this.fetchIfUnloaded();
60
+ subscriptionSucceeded = this.didSubscriptionSucceed();
61
+ retries++;
62
+ }
58
63
 
59
64
  if (subscriptionSucceeded) {
60
65
  this.eventEmitter.emit('update');