@drift-labs/sdk 2.79.0-beta.0 → 2.79.0-beta.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.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.79.0-beta.0
1
+ 2.79.0-beta.2
@@ -20,6 +20,7 @@ export declare class EventSubscriber {
20
20
  private lastSeenBlockTime;
21
21
  lastSeenTxSig: string;
22
22
  constructor(connection: Connection, program: Program, options?: EventSubscriptionOptions);
23
+ private populateInitialEventListMap;
23
24
  subscribe(): Promise<boolean>;
24
25
  private handleTxLogs;
25
26
  fetchPreviousTx(fetchMax?: boolean): Promise<void>;
@@ -22,9 +22,6 @@ class EventSubscriber {
22
22
  this.address = (_a = this.options.address) !== null && _a !== void 0 ? _a : program.programId;
23
23
  this.txEventCache = new txEventCache_1.TxEventCache(this.options.maxTx);
24
24
  this.eventListMap = new Map();
25
- for (const eventType of this.options.eventTypes) {
26
- this.eventListMap.set(eventType, new eventList_1.EventList(eventType, this.options.maxEventsPerType, (0, sort_1.getSortFn)(this.options.orderBy, this.options.orderDir), this.options.orderDir));
27
- }
28
25
  this.eventEmitter = new events_1.EventEmitter();
29
26
  if (this.options.logProviderConfig.type === 'websocket') {
30
27
  this.logProvider = new webSocketLogProvider_1.WebSocketLogProvider(this.connection, this.address, this.options.commitment, this.options.logProviderConfig.resubTimeoutMs);
@@ -33,11 +30,17 @@ class EventSubscriber {
33
30
  this.logProvider = new pollingLogProvider_1.PollingLogProvider(this.connection, this.address, options.commitment, this.options.logProviderConfig.frequency, this.options.logProviderConfig.batchSize);
34
31
  }
35
32
  }
33
+ populateInitialEventListMap() {
34
+ for (const eventType of this.options.eventTypes) {
35
+ this.eventListMap.set(eventType, new eventList_1.EventList(eventType, this.options.maxEventsPerType, (0, sort_1.getSortFn)(this.options.orderBy, this.options.orderDir), this.options.orderDir));
36
+ }
37
+ }
36
38
  async subscribe() {
37
39
  try {
38
40
  if (this.logProvider.isSubscribed()) {
39
41
  return true;
40
42
  }
43
+ this.populateInitialEventListMap();
41
44
  if (this.options.logProviderConfig.type === 'websocket') {
42
45
  if (this.options.logProviderConfig.resubTimeoutMs) {
43
46
  if (this.options.logProviderConfig.maxReconnectAttempts &&
@@ -117,6 +120,10 @@ class EventSubscriber {
117
120
  }
118
121
  }
119
122
  async unsubscribe() {
123
+ this.eventListMap.clear();
124
+ this.txEventCache.clear();
125
+ this.awaitTxPromises.clear();
126
+ this.awaitTxResolver.clear();
120
127
  return await this.logProvider.unsubscribe(true);
121
128
  }
122
129
  parseEventsFromLogs(txSig, slot, logs) {
@@ -152,6 +152,7 @@ class OrderSubscriber {
152
152
  return (_a = this.mostRecentSlot) !== null && _a !== void 0 ? _a : 0;
153
153
  }
154
154
  async unsubscribe() {
155
+ this.usersAccounts.clear();
155
156
  await this.subscription.unsubscribe();
156
157
  }
157
158
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.79.0-beta.0",
3
+ "version": "2.79.0-beta.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -41,18 +41,8 @@ export class EventSubscriber {
41
41
  this.address = this.options.address ?? program.programId;
42
42
  this.txEventCache = new TxEventCache(this.options.maxTx);
43
43
  this.eventListMap = new Map<EventType, EventList<EventType>>();
44
- for (const eventType of this.options.eventTypes) {
45
- this.eventListMap.set(
46
- eventType,
47
- new EventList(
48
- eventType,
49
- this.options.maxEventsPerType,
50
- getSortFn(this.options.orderBy, this.options.orderDir),
51
- this.options.orderDir
52
- )
53
- );
54
- }
55
44
  this.eventEmitter = new EventEmitter();
45
+
56
46
  if (this.options.logProviderConfig.type === 'websocket') {
57
47
  this.logProvider = new WebSocketLogProvider(
58
48
  this.connection,
@@ -71,12 +61,28 @@ export class EventSubscriber {
71
61
  }
72
62
  }
73
63
 
64
+ private populateInitialEventListMap() {
65
+ for (const eventType of this.options.eventTypes) {
66
+ this.eventListMap.set(
67
+ eventType,
68
+ new EventList(
69
+ eventType,
70
+ this.options.maxEventsPerType,
71
+ getSortFn(this.options.orderBy, this.options.orderDir),
72
+ this.options.orderDir
73
+ )
74
+ );
75
+ }
76
+ }
77
+
74
78
  public async subscribe(): Promise<boolean> {
75
79
  try {
76
80
  if (this.logProvider.isSubscribed()) {
77
81
  return true;
78
82
  }
79
83
 
84
+ this.populateInitialEventListMap();
85
+
80
86
  if (this.options.logProviderConfig.type === 'websocket') {
81
87
  if (this.options.logProviderConfig.resubTimeoutMs) {
82
88
  if (
@@ -203,6 +209,11 @@ export class EventSubscriber {
203
209
  }
204
210
 
205
211
  public async unsubscribe(): Promise<boolean> {
212
+ this.eventListMap.clear();
213
+ this.txEventCache.clear();
214
+ this.awaitTxPromises.clear();
215
+ this.awaitTxResolver.clear();
216
+
206
217
  return await this.logProvider.unsubscribe(true);
207
218
  }
208
219
 
@@ -229,6 +229,7 @@ export class OrderSubscriber {
229
229
  }
230
230
 
231
231
  public async unsubscribe(): Promise<void> {
232
+ this.usersAccounts.clear();
232
233
  await this.subscription.unsubscribe();
233
234
  }
234
235
  }