@drift-labs/sdk 2.10.0-beta.4 → 2.10.0-beta.5

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.
@@ -24,7 +24,7 @@ export declare class BulkAccountLoader {
24
24
  removeErrorCallbacks(callbackId: string): void;
25
25
  chunks<T>(array: readonly T[], size: number): T[][];
26
26
  load(): Promise<void>;
27
- loadChunk(accountsToLoad: AccountToLoad[]): Promise<void>;
27
+ loadChunk(accountsToLoadChunks: AccountToLoad[][]): Promise<void>;
28
28
  handleAccountCallbacks(accountToLoad: AccountToLoad, buffer: Buffer, slot: number): void;
29
29
  getBufferAndSlot(publicKey: PublicKey): BufferAndSlot | undefined;
30
30
  startPolling(): void;
@@ -80,7 +80,7 @@ class BulkAccountLoader {
80
80
  });
81
81
  this.lastTimeLoadingPromiseCleared = Date.now();
82
82
  try {
83
- const chunks = this.chunks(Array.from(this.accountsToLoad.values()), GET_MULTIPLE_ACCOUNTS_CHUNK_SIZE);
83
+ const chunks = this.chunks(this.chunks(Array.from(this.accountsToLoad.values()), GET_MULTIPLE_ACCOUNTS_CHUNK_SIZE), 10);
84
84
  await Promise.all(chunks.map((chunk) => {
85
85
  return this.loadChunk(chunk);
86
86
  }));
@@ -97,56 +97,67 @@ class BulkAccountLoader {
97
97
  this.loadPromise = undefined;
98
98
  }
99
99
  }
100
- async loadChunk(accountsToLoad) {
101
- if (accountsToLoad.length === 0) {
100
+ async loadChunk(accountsToLoadChunks) {
101
+ if (accountsToLoadChunks.length === 0) {
102
102
  return;
103
103
  }
104
- const args = [
105
- accountsToLoad.map((accountToLoad) => {
106
- return accountToLoad.publicKey.toBase58();
107
- }),
108
- { commitment: this.commitment },
109
- ];
110
- const rpcResponse = await (0, promiseTimeout_1.promiseTimeout)(
104
+ const requests = new Array();
105
+ for (const accountsToLoadChunk of accountsToLoadChunks) {
106
+ const args = [
107
+ accountsToLoadChunk.map((accountToLoad) => {
108
+ return accountToLoad.publicKey.toBase58();
109
+ }),
110
+ { commitment: this.commitment },
111
+ ];
112
+ requests.push({
113
+ methodName: 'getMultipleAccounts',
114
+ args,
115
+ });
116
+ }
117
+ const rpcResponses = await (0, promiseTimeout_1.promiseTimeout)(
111
118
  // @ts-ignore
112
- this.connection._rpcRequest('getMultipleAccounts', args), 10 * 1000 // 30 second timeout
119
+ this.connection._rpcBatchRequest(requests), 10 * 1000 // 30 second timeout
113
120
  );
114
- if (rpcResponse === null) {
121
+ if (rpcResponses === null) {
115
122
  this.log('request to rpc timed out');
116
123
  return;
117
124
  }
118
- const newSlot = rpcResponse.result.context.slot;
119
- if (newSlot > this.mostRecentSlot) {
120
- this.mostRecentSlot = newSlot;
121
- }
122
- for (const i in accountsToLoad) {
123
- const accountToLoad = accountsToLoad[i];
124
- const key = accountToLoad.publicKey.toString();
125
- const oldRPCResponse = this.bufferAndSlotMap.get(key);
126
- let newBuffer = undefined;
127
- if (rpcResponse.result.value[i]) {
128
- const raw = rpcResponse.result.value[i].data[0];
129
- const dataType = rpcResponse.result.value[i].data[1];
130
- newBuffer = Buffer.from(raw, dataType);
125
+ for (const i in rpcResponses) {
126
+ const rpcResponse = rpcResponses[i];
127
+ const newSlot = rpcResponse.result.context.slot;
128
+ if (newSlot > this.mostRecentSlot) {
129
+ this.mostRecentSlot = newSlot;
131
130
  }
132
- if (!oldRPCResponse) {
133
- this.bufferAndSlotMap.set(key, {
134
- slot: newSlot,
135
- buffer: newBuffer,
136
- });
137
- this.handleAccountCallbacks(accountToLoad, newBuffer, newSlot);
138
- continue;
139
- }
140
- if (newSlot <= oldRPCResponse.slot) {
141
- continue;
142
- }
143
- const oldBuffer = oldRPCResponse.buffer;
144
- if (newBuffer && (!oldBuffer || !newBuffer.equals(oldBuffer))) {
145
- this.bufferAndSlotMap.set(key, {
146
- slot: newSlot,
147
- buffer: newBuffer,
148
- });
149
- this.handleAccountCallbacks(accountToLoad, newBuffer, newSlot);
131
+ const accountsToLoad = accountsToLoadChunks[i];
132
+ for (const j in accountsToLoad) {
133
+ const accountToLoad = accountsToLoad[j];
134
+ const key = accountToLoad.publicKey.toString();
135
+ const oldRPCResponse = this.bufferAndSlotMap.get(key);
136
+ let newBuffer = undefined;
137
+ if (rpcResponse.result.value[j]) {
138
+ const raw = rpcResponse.result.value[j].data[0];
139
+ const dataType = rpcResponse.result.value[j].data[1];
140
+ newBuffer = Buffer.from(raw, dataType);
141
+ }
142
+ if (!oldRPCResponse) {
143
+ this.bufferAndSlotMap.set(key, {
144
+ slot: newSlot,
145
+ buffer: newBuffer,
146
+ });
147
+ this.handleAccountCallbacks(accountToLoad, newBuffer, newSlot);
148
+ continue;
149
+ }
150
+ if (newSlot <= oldRPCResponse.slot) {
151
+ continue;
152
+ }
153
+ const oldBuffer = oldRPCResponse.buffer;
154
+ if (newBuffer && (!oldBuffer || !newBuffer.equals(oldBuffer))) {
155
+ this.bufferAndSlotMap.set(key, {
156
+ slot: newSlot,
157
+ buffer: newBuffer,
158
+ });
159
+ this.handleAccountCallbacks(accountToLoad, newBuffer, newSlot);
160
+ }
150
161
  }
151
162
  }
152
163
  }
@@ -8553,6 +8553,11 @@
8553
8553
  "code": 6222,
8554
8554
  "name": "InvalidMaker",
8555
8555
  "msg": "Invalid Maker"
8556
+ },
8557
+ {
8558
+ "code": 6223,
8559
+ "name": "FailedUnwrap",
8560
+ "msg": "Failed Unwrap"
8556
8561
  }
8557
8562
  ]
8558
8563
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.10.0-beta.4",
3
+ "version": "2.10.0-beta.5",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -117,8 +117,11 @@ export class BulkAccountLoader {
117
117
 
118
118
  try {
119
119
  const chunks = this.chunks(
120
- Array.from(this.accountsToLoad.values()),
121
- GET_MULTIPLE_ACCOUNTS_CHUNK_SIZE
120
+ this.chunks(
121
+ Array.from(this.accountsToLoad.values()),
122
+ GET_MULTIPLE_ACCOUNTS_CHUNK_SIZE
123
+ ),
124
+ 10
122
125
  );
123
126
 
124
127
  await Promise.all(
@@ -138,67 +141,79 @@ export class BulkAccountLoader {
138
141
  }
139
142
  }
140
143
 
141
- async loadChunk(accountsToLoad: AccountToLoad[]): Promise<void> {
142
- if (accountsToLoad.length === 0) {
144
+ async loadChunk(accountsToLoadChunks: AccountToLoad[][]): Promise<void> {
145
+ if (accountsToLoadChunks.length === 0) {
143
146
  return;
144
147
  }
145
148
 
146
- const args = [
147
- accountsToLoad.map((accountToLoad) => {
148
- return accountToLoad.publicKey.toBase58();
149
- }),
150
- { commitment: this.commitment },
151
- ];
149
+ const requests = new Array<{ methodName: string; args: any }>();
150
+ for (const accountsToLoadChunk of accountsToLoadChunks) {
151
+ const args = [
152
+ accountsToLoadChunk.map((accountToLoad) => {
153
+ return accountToLoad.publicKey.toBase58();
154
+ }),
155
+ { commitment: this.commitment },
156
+ ];
157
+
158
+ requests.push({
159
+ methodName: 'getMultipleAccounts',
160
+ args,
161
+ });
162
+ }
152
163
 
153
- const rpcResponse: any | null = await promiseTimeout(
164
+ const rpcResponses: any | null = await promiseTimeout(
154
165
  // @ts-ignore
155
- this.connection._rpcRequest('getMultipleAccounts', args),
166
+ this.connection._rpcBatchRequest(requests),
156
167
  10 * 1000 // 30 second timeout
157
168
  );
158
169
 
159
- if (rpcResponse === null) {
170
+ if (rpcResponses === null) {
160
171
  this.log('request to rpc timed out');
161
172
  return;
162
173
  }
163
174
 
164
- const newSlot = rpcResponse.result.context.slot;
165
-
166
- if (newSlot > this.mostRecentSlot) {
167
- this.mostRecentSlot = newSlot;
168
- }
169
-
170
- for (const i in accountsToLoad) {
171
- const accountToLoad = accountsToLoad[i];
172
- const key = accountToLoad.publicKey.toString();
173
- const oldRPCResponse = this.bufferAndSlotMap.get(key);
174
-
175
- let newBuffer: Buffer | undefined = undefined;
176
- if (rpcResponse.result.value[i]) {
177
- const raw: string = rpcResponse.result.value[i].data[0];
178
- const dataType = rpcResponse.result.value[i].data[1];
179
- newBuffer = Buffer.from(raw, dataType);
180
- }
181
-
182
- if (!oldRPCResponse) {
183
- this.bufferAndSlotMap.set(key, {
184
- slot: newSlot,
185
- buffer: newBuffer,
186
- });
187
- this.handleAccountCallbacks(accountToLoad, newBuffer, newSlot);
188
- continue;
189
- }
175
+ for (const i in rpcResponses) {
176
+ const rpcResponse = rpcResponses[i];
177
+ const newSlot = rpcResponse.result.context.slot;
190
178
 
191
- if (newSlot <= oldRPCResponse.slot) {
192
- continue;
179
+ if (newSlot > this.mostRecentSlot) {
180
+ this.mostRecentSlot = newSlot;
193
181
  }
194
182
 
195
- const oldBuffer = oldRPCResponse.buffer;
196
- if (newBuffer && (!oldBuffer || !newBuffer.equals(oldBuffer))) {
197
- this.bufferAndSlotMap.set(key, {
198
- slot: newSlot,
199
- buffer: newBuffer,
200
- });
201
- this.handleAccountCallbacks(accountToLoad, newBuffer, newSlot);
183
+ const accountsToLoad = accountsToLoadChunks[i];
184
+ for (const j in accountsToLoad) {
185
+ const accountToLoad = accountsToLoad[j];
186
+ const key = accountToLoad.publicKey.toString();
187
+ const oldRPCResponse = this.bufferAndSlotMap.get(key);
188
+
189
+ let newBuffer: Buffer | undefined = undefined;
190
+ if (rpcResponse.result.value[j]) {
191
+ const raw: string = rpcResponse.result.value[j].data[0];
192
+ const dataType = rpcResponse.result.value[j].data[1];
193
+ newBuffer = Buffer.from(raw, dataType);
194
+ }
195
+
196
+ if (!oldRPCResponse) {
197
+ this.bufferAndSlotMap.set(key, {
198
+ slot: newSlot,
199
+ buffer: newBuffer,
200
+ });
201
+ this.handleAccountCallbacks(accountToLoad, newBuffer, newSlot);
202
+ continue;
203
+ }
204
+
205
+ if (newSlot <= oldRPCResponse.slot) {
206
+ continue;
207
+ }
208
+
209
+ const oldBuffer = oldRPCResponse.buffer;
210
+ if (newBuffer && (!oldBuffer || !newBuffer.equals(oldBuffer))) {
211
+ this.bufferAndSlotMap.set(key, {
212
+ slot: newSlot,
213
+ buffer: newBuffer,
214
+ });
215
+ this.handleAccountCallbacks(accountToLoad, newBuffer, newSlot);
216
+ }
202
217
  }
203
218
  }
204
219
  }
@@ -8553,6 +8553,11 @@
8553
8553
  "code": 6222,
8554
8554
  "name": "InvalidMaker",
8555
8555
  "msg": "Invalid Maker"
8556
+ },
8557
+ {
8558
+ "code": 6223,
8559
+ "name": "FailedUnwrap",
8560
+ "msg": "Failed Unwrap"
8556
8561
  }
8557
8562
  ]
8558
8563
  }