@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(
|
|
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(
|
|
101
|
-
if (
|
|
100
|
+
async loadChunk(accountsToLoadChunks) {
|
|
101
|
+
if (accountsToLoadChunks.length === 0) {
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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.
|
|
119
|
+
this.connection._rpcBatchRequest(requests), 10 * 1000 // 30 second timeout
|
|
113
120
|
);
|
|
114
|
-
if (
|
|
121
|
+
if (rpcResponses === null) {
|
|
115
122
|
this.log('request to rpc timed out');
|
|
116
123
|
return;
|
|
117
124
|
}
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
}
|
package/lib/idl/drift.json
CHANGED
package/package.json
CHANGED
|
@@ -117,8 +117,11 @@ export class BulkAccountLoader {
|
|
|
117
117
|
|
|
118
118
|
try {
|
|
119
119
|
const chunks = this.chunks(
|
|
120
|
-
|
|
121
|
-
|
|
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(
|
|
142
|
-
if (
|
|
144
|
+
async loadChunk(accountsToLoadChunks: AccountToLoad[][]): Promise<void> {
|
|
145
|
+
if (accountsToLoadChunks.length === 0) {
|
|
143
146
|
return;
|
|
144
147
|
}
|
|
145
148
|
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
|
164
|
+
const rpcResponses: any | null = await promiseTimeout(
|
|
154
165
|
// @ts-ignore
|
|
155
|
-
this.connection.
|
|
166
|
+
this.connection._rpcBatchRequest(requests),
|
|
156
167
|
10 * 1000 // 30 second timeout
|
|
157
168
|
);
|
|
158
169
|
|
|
159
|
-
if (
|
|
170
|
+
if (rpcResponses === null) {
|
|
160
171
|
this.log('request to rpc timed out');
|
|
161
172
|
return;
|
|
162
173
|
}
|
|
163
174
|
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
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
|
|
192
|
-
|
|
179
|
+
if (newSlot > this.mostRecentSlot) {
|
|
180
|
+
this.mostRecentSlot = newSlot;
|
|
193
181
|
}
|
|
194
182
|
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
}
|