@drift-labs/sdk 2.37.1-beta.11 → 2.37.1-beta.13

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.37.1-beta.11
1
+ 2.37.1-beta.13
@@ -168,7 +168,18 @@ class BulkAccountLoader {
168
168
  }
169
169
  handleAccountCallbacks(accountToLoad, buffer, slot) {
170
170
  for (const [_, callback] of accountToLoad.callbacks) {
171
- callback(buffer, slot);
171
+ try {
172
+ callback(buffer, slot);
173
+ }
174
+ catch (e) {
175
+ console.log('Bulk account load: error in account callback');
176
+ console.log('accounto to load', accountToLoad.publicKey.toString());
177
+ console.log('buffer', buffer.toString('base64'));
178
+ for (const callback of accountToLoad.callbacks.values()) {
179
+ console.log('account to load cb', callback);
180
+ }
181
+ throw e;
182
+ }
172
183
  }
173
184
  }
174
185
  getBufferAndSlot(publicKey) {
@@ -30,7 +30,7 @@ class EventSubscriber {
30
30
  this.logProvider = new webSocketLogProvider_1.WebSocketLogProvider(this.connection, this.address, this.options.commitment);
31
31
  }
32
32
  else {
33
- this.logProvider = new pollingLogProvider_1.PollingLogProvider(this.connection, this.address, options.commitment, this.options.logProviderConfig.frequency);
33
+ this.logProvider = new pollingLogProvider_1.PollingLogProvider(this.connection, this.address, options.commitment, this.options.logProviderConfig.frequency, this.options.logProviderConfig.batchSize);
34
34
  }
35
35
  }
36
36
  async subscribe() {
@@ -14,7 +14,7 @@ type FetchLogsResponse = {
14
14
  transactionLogs: Log[];
15
15
  mostRecentBlockTime: number | undefined;
16
16
  };
17
- export declare function fetchLogs(connection: Connection, address: PublicKey, finality: Finality, beforeTx?: TransactionSignature, untilTx?: TransactionSignature, limit?: number): Promise<FetchLogsResponse>;
17
+ export declare function fetchLogs(connection: Connection, address: PublicKey, finality: Finality, beforeTx?: TransactionSignature, untilTx?: TransactionSignature, limit?: number, batchSize?: number): Promise<FetchLogsResponse>;
18
18
  export declare function fetchTransactionLogs(connection: Connection, signatures: TransactionSignature[], finality: Finality): Promise<Log[]>;
19
19
  export declare class LogParser {
20
20
  private program;
@@ -9,7 +9,7 @@ function mapTransactionResponseToLog(transaction) {
9
9
  logs: transaction.meta.logMessages,
10
10
  };
11
11
  }
12
- async function fetchLogs(connection, address, finality, beforeTx, untilTx, limit) {
12
+ async function fetchLogs(connection, address, finality, beforeTx, untilTx, limit, batchSize = 25) {
13
13
  const signatures = await connection.getSignaturesForAddress(address, {
14
14
  before: beforeTx,
15
15
  until: untilTx,
@@ -20,7 +20,7 @@ async function fetchLogs(connection, address, finality, beforeTx, untilTx, limit
20
20
  if (filteredSignatures.length === 0) {
21
21
  return undefined;
22
22
  }
23
- const chunkedSignatures = chunk(filteredSignatures, 100);
23
+ const chunkedSignatures = chunk(filteredSignatures, batchSize);
24
24
  const transactionLogs = (await Promise.all(chunkedSignatures.map(async (chunk) => {
25
25
  return await fetchTransactionLogs(connection, chunk.map((confirmedSignature) => confirmedSignature.signature), finality);
26
26
  }))).flat();
@@ -4,12 +4,13 @@ export declare class PollingLogProvider implements LogProvider {
4
4
  private connection;
5
5
  private address;
6
6
  private frequency;
7
+ private batchSize?;
7
8
  private finality;
8
9
  private intervalId;
9
10
  private mostRecentSeenTx?;
10
11
  private mutex;
11
12
  private firstFetch;
12
- constructor(connection: Connection, address: PublicKey, commitment: Commitment, frequency?: number);
13
+ constructor(connection: Connection, address: PublicKey, commitment: Commitment, frequency?: number, batchSize?: number);
13
14
  subscribe(callback: logProviderCallback, skipHistory?: boolean): boolean;
14
15
  isSubscribed(): boolean;
15
16
  unsubscribe(): Promise<boolean>;
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PollingLogProvider = void 0;
4
4
  const fetchLogs_1 = require("./fetchLogs");
5
5
  class PollingLogProvider {
6
- constructor(connection, address, commitment, frequency = 15 * 1000) {
6
+ constructor(connection, address, commitment, frequency = 15 * 1000, batchSize) {
7
7
  this.connection = connection;
8
8
  this.address = address;
9
9
  this.frequency = frequency;
10
+ this.batchSize = batchSize;
10
11
  this.firstFetch = true;
11
12
  this.finality = commitment === 'finalized' ? 'finalized' : 'confirmed';
12
13
  }
@@ -22,7 +23,7 @@ class PollingLogProvider {
22
23
  try {
23
24
  const response = await (0, fetchLogs_1.fetchLogs)(this.connection, this.address, this.finality, undefined, this.mostRecentSeenTx,
24
25
  // If skipping history, only fetch one log back, not the maximum amount available
25
- skipHistory && this.firstFetch ? 1 : undefined);
26
+ skipHistory && this.firstFetch ? 1 : undefined, this.batchSize);
26
27
  if (response === undefined) {
27
28
  return;
28
29
  }
@@ -57,5 +57,6 @@ export type WebSocketLogProviderConfig = {
57
57
  export type PollingLogProviderConfig = {
58
58
  type: 'polling';
59
59
  frequency: number;
60
+ batchSize?: number;
60
61
  };
61
62
  export type LogProviderConfig = WebSocketLogProviderConfig | PollingLogProviderConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.37.1-beta.11",
3
+ "version": "2.37.1-beta.13",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -229,7 +229,17 @@ export class BulkAccountLoader {
229
229
  slot: number
230
230
  ): void {
231
231
  for (const [_, callback] of accountToLoad.callbacks) {
232
- callback(buffer, slot);
232
+ try {
233
+ callback(buffer, slot);
234
+ } catch (e) {
235
+ console.log('Bulk account load: error in account callback');
236
+ console.log('accounto to load', accountToLoad.publicKey.toString());
237
+ console.log('buffer', buffer.toString('base64'));
238
+ for (const callback of accountToLoad.callbacks.values()) {
239
+ console.log('account to load cb', callback);
240
+ }
241
+ throw e;
242
+ }
233
243
  }
234
244
  }
235
245
 
@@ -63,7 +63,8 @@ export class EventSubscriber {
63
63
  this.connection,
64
64
  this.address,
65
65
  options.commitment,
66
- this.options.logProviderConfig.frequency
66
+ this.options.logProviderConfig.frequency,
67
+ this.options.logProviderConfig.batchSize
67
68
  );
68
69
  }
69
70
  }
@@ -36,7 +36,8 @@ export async function fetchLogs(
36
36
  finality: Finality,
37
37
  beforeTx?: TransactionSignature,
38
38
  untilTx?: TransactionSignature,
39
- limit?: number
39
+ limit?: number,
40
+ batchSize = 25
40
41
  ): Promise<FetchLogsResponse> {
41
42
  const signatures = await connection.getSignaturesForAddress(
42
43
  address,
@@ -60,7 +61,7 @@ export async function fetchLogs(
60
61
  return undefined;
61
62
  }
62
63
 
63
- const chunkedSignatures = chunk(filteredSignatures, 100);
64
+ const chunkedSignatures = chunk(filteredSignatures, batchSize);
64
65
 
65
66
  const transactionLogs = (
66
67
  await Promise.all(
@@ -19,7 +19,8 @@ export class PollingLogProvider implements LogProvider {
19
19
  private connection: Connection,
20
20
  private address: PublicKey,
21
21
  commitment: Commitment,
22
- private frequency = 15 * 1000
22
+ private frequency = 15 * 1000,
23
+ private batchSize?: number
23
24
  ) {
24
25
  this.finality = commitment === 'finalized' ? 'finalized' : 'confirmed';
25
26
  }
@@ -46,7 +47,8 @@ export class PollingLogProvider implements LogProvider {
46
47
  undefined,
47
48
  this.mostRecentSeenTx,
48
49
  // If skipping history, only fetch one log back, not the maximum amount available
49
- skipHistory && this.firstFetch ? 1 : undefined
50
+ skipHistory && this.firstFetch ? 1 : undefined,
51
+ this.batchSize
50
52
  );
51
53
 
52
54
  if (response === undefined) {
@@ -137,6 +137,7 @@ export type WebSocketLogProviderConfig = {
137
137
  export type PollingLogProviderConfig = {
138
138
  type: 'polling';
139
139
  frequency: number;
140
+ batchSize?: number;
140
141
  };
141
142
 
142
143
  export type LogProviderConfig =