@drift-labs/sdk 2.142.0-beta.10 → 2.142.0-beta.11
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 +1 -1
- package/lib/browser/accounts/grpcDriftClientAccountSubscriberV2.js +23 -15
- package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.js +23 -15
- package/package.json +1 -1
- package/src/accounts/grpcDriftClientAccountSubscriberV2.ts +29 -20
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.142.0-beta.
|
|
1
|
+
2.142.0-beta.11
|
|
@@ -180,27 +180,31 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
180
180
|
return true;
|
|
181
181
|
}
|
|
182
182
|
async subscribeToOracles() {
|
|
183
|
-
|
|
184
|
-
const uniqueOraclePubkeys = new Map();
|
|
183
|
+
const pubkeyToSources = new Map();
|
|
185
184
|
for (const info of this.oracleInfos) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
185
|
+
if (info.publicKey.equals(web3_js_1.PublicKey.default)) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const key = info.publicKey.toBase58();
|
|
189
|
+
let sources = pubkeyToSources.get(key);
|
|
190
|
+
if (!sources) {
|
|
191
|
+
sources = new Set();
|
|
192
|
+
pubkeyToSources.set(key, sources);
|
|
190
193
|
}
|
|
194
|
+
sources.add(info.source);
|
|
191
195
|
}
|
|
192
|
-
const oraclePubkeys = Array.from(
|
|
193
|
-
const pubkeyToSource = new Map(Array.from(uniqueOraclePubkeys.values()).map((i) => [
|
|
194
|
-
i.publicKey.toBase58(),
|
|
195
|
-
i.source,
|
|
196
|
-
]));
|
|
196
|
+
const oraclePubkeys = Array.from(pubkeyToSources.keys()).map((k) => new web3_js_1.PublicKey(k));
|
|
197
197
|
this.oracleMultiSubscriber =
|
|
198
198
|
await grpcMultiAccountSubscriber_1.grpcMultiAccountSubscriber.create(this.grpcConfigs, 'oracle', this.program, (buffer, pubkey) => {
|
|
199
199
|
if (!pubkey) {
|
|
200
200
|
throw new Error('Oracle pubkey missing in decode');
|
|
201
201
|
}
|
|
202
|
-
const
|
|
203
|
-
|
|
202
|
+
const sources = pubkeyToSources.get(pubkey);
|
|
203
|
+
if (!sources || sources.size === 0) {
|
|
204
|
+
throw new Error('Oracle sources missing for pubkey in decode');
|
|
205
|
+
}
|
|
206
|
+
const primarySource = sources.values().next().value;
|
|
207
|
+
const client = this.oracleClientCache.get(primarySource, this.program.provider.connection, this.program);
|
|
204
208
|
return client.getOraclePriceDataFromBuffer(buffer);
|
|
205
209
|
}, this.resubOpts, undefined, async () => {
|
|
206
210
|
var _a;
|
|
@@ -219,8 +223,12 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
219
223
|
this.oracleMultiSubscriber.setAccountData(publicKey.toBase58(), data[1]);
|
|
220
224
|
}
|
|
221
225
|
await this.oracleMultiSubscriber.subscribe(oraclePubkeys, (accountId, data) => {
|
|
222
|
-
const
|
|
223
|
-
|
|
226
|
+
const sources = pubkeyToSources.get(accountId.toBase58());
|
|
227
|
+
if (sources) {
|
|
228
|
+
for (const source of sources.values()) {
|
|
229
|
+
this.eventEmitter.emit('oraclePriceUpdate', accountId, source, data);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
224
232
|
this.eventEmitter.emit('update');
|
|
225
233
|
});
|
|
226
234
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grpcDriftClientAccountSubscriberV2.d.ts","sourceRoot":"","sources":["../../../src/accounts/grpcDriftClientAccountSubscriberV2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qCAAqC,EAAE,MAAM,yCAAyC,CAAC;AAChG,OAAO,EAAE,UAAU,EAAmB,MAAM,kBAAkB,CAAC;AAC/D,OAAO,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,CAAC;CAO3C"}
|
|
@@ -180,27 +180,31 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
180
180
|
return true;
|
|
181
181
|
}
|
|
182
182
|
async subscribeToOracles() {
|
|
183
|
-
|
|
184
|
-
const uniqueOraclePubkeys = new Map();
|
|
183
|
+
const pubkeyToSources = new Map();
|
|
185
184
|
for (const info of this.oracleInfos) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
185
|
+
if (info.publicKey.equals(web3_js_1.PublicKey.default)) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const key = info.publicKey.toBase58();
|
|
189
|
+
let sources = pubkeyToSources.get(key);
|
|
190
|
+
if (!sources) {
|
|
191
|
+
sources = new Set();
|
|
192
|
+
pubkeyToSources.set(key, sources);
|
|
190
193
|
}
|
|
194
|
+
sources.add(info.source);
|
|
191
195
|
}
|
|
192
|
-
const oraclePubkeys = Array.from(
|
|
193
|
-
const pubkeyToSource = new Map(Array.from(uniqueOraclePubkeys.values()).map((i) => [
|
|
194
|
-
i.publicKey.toBase58(),
|
|
195
|
-
i.source,
|
|
196
|
-
]));
|
|
196
|
+
const oraclePubkeys = Array.from(pubkeyToSources.keys()).map((k) => new web3_js_1.PublicKey(k));
|
|
197
197
|
this.oracleMultiSubscriber =
|
|
198
198
|
await grpcMultiAccountSubscriber_1.grpcMultiAccountSubscriber.create(this.grpcConfigs, 'oracle', this.program, (buffer, pubkey) => {
|
|
199
199
|
if (!pubkey) {
|
|
200
200
|
throw new Error('Oracle pubkey missing in decode');
|
|
201
201
|
}
|
|
202
|
-
const
|
|
203
|
-
|
|
202
|
+
const sources = pubkeyToSources.get(pubkey);
|
|
203
|
+
if (!sources || sources.size === 0) {
|
|
204
|
+
throw new Error('Oracle sources missing for pubkey in decode');
|
|
205
|
+
}
|
|
206
|
+
const primarySource = sources.values().next().value;
|
|
207
|
+
const client = this.oracleClientCache.get(primarySource, this.program.provider.connection, this.program);
|
|
204
208
|
return client.getOraclePriceDataFromBuffer(buffer);
|
|
205
209
|
}, this.resubOpts, undefined, async () => {
|
|
206
210
|
var _a;
|
|
@@ -219,8 +223,12 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
219
223
|
this.oracleMultiSubscriber.setAccountData(publicKey.toBase58(), data[1]);
|
|
220
224
|
}
|
|
221
225
|
await this.oracleMultiSubscriber.subscribe(oraclePubkeys, (accountId, data) => {
|
|
222
|
-
const
|
|
223
|
-
|
|
226
|
+
const sources = pubkeyToSources.get(accountId.toBase58());
|
|
227
|
+
if (sources) {
|
|
228
|
+
for (const source of sources.values()) {
|
|
229
|
+
this.eventEmitter.emit('oraclePriceUpdate', accountId, source, data);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
224
232
|
this.eventEmitter.emit('update');
|
|
225
233
|
});
|
|
226
234
|
return true;
|
package/package.json
CHANGED
|
@@ -326,26 +326,22 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
|
|
|
326
326
|
}
|
|
327
327
|
|
|
328
328
|
override async subscribeToOracles(): Promise<boolean> {
|
|
329
|
-
|
|
330
|
-
const uniqueOraclePubkeys = new Map<string, OracleInfo>();
|
|
329
|
+
const pubkeyToSources = new Map<string, Set<OracleInfo['source']>>();
|
|
331
330
|
for (const info of this.oracleInfos) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
)
|
|
337
|
-
|
|
331
|
+
if (info.publicKey.equals((PublicKey as any).default)) {
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
const key = info.publicKey.toBase58();
|
|
335
|
+
let sources = pubkeyToSources.get(key);
|
|
336
|
+
if (!sources) {
|
|
337
|
+
sources = new Set<OracleInfo['source']>();
|
|
338
|
+
pubkeyToSources.set(key, sources);
|
|
338
339
|
}
|
|
340
|
+
sources.add(info.source);
|
|
339
341
|
}
|
|
340
342
|
|
|
341
|
-
const oraclePubkeys = Array.from(
|
|
342
|
-
(
|
|
343
|
-
);
|
|
344
|
-
const pubkeyToSource = new Map<string, OracleInfo['source']>(
|
|
345
|
-
Array.from(uniqueOraclePubkeys.values()).map((i) => [
|
|
346
|
-
i.publicKey.toBase58(),
|
|
347
|
-
i.source,
|
|
348
|
-
])
|
|
343
|
+
const oraclePubkeys = Array.from(pubkeyToSources.keys()).map(
|
|
344
|
+
(k) => new PublicKey(k)
|
|
349
345
|
);
|
|
350
346
|
|
|
351
347
|
this.oracleMultiSubscriber =
|
|
@@ -357,9 +353,13 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
|
|
|
357
353
|
if (!pubkey) {
|
|
358
354
|
throw new Error('Oracle pubkey missing in decode');
|
|
359
355
|
}
|
|
360
|
-
const
|
|
356
|
+
const sources = pubkeyToSources.get(pubkey);
|
|
357
|
+
if (!sources || sources.size === 0) {
|
|
358
|
+
throw new Error('Oracle sources missing for pubkey in decode');
|
|
359
|
+
}
|
|
360
|
+
const primarySource = sources.values().next().value;
|
|
361
361
|
const client = this.oracleClientCache.get(
|
|
362
|
-
|
|
362
|
+
primarySource,
|
|
363
363
|
this.program.provider.connection,
|
|
364
364
|
this.program
|
|
365
365
|
);
|
|
@@ -389,8 +389,17 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
|
|
|
389
389
|
await this.oracleMultiSubscriber.subscribe(
|
|
390
390
|
oraclePubkeys,
|
|
391
391
|
(accountId, data) => {
|
|
392
|
-
const
|
|
393
|
-
|
|
392
|
+
const sources = pubkeyToSources.get(accountId.toBase58());
|
|
393
|
+
if (sources) {
|
|
394
|
+
for (const source of sources.values()) {
|
|
395
|
+
this.eventEmitter.emit(
|
|
396
|
+
'oraclePriceUpdate',
|
|
397
|
+
accountId,
|
|
398
|
+
source,
|
|
399
|
+
data
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
394
403
|
this.eventEmitter.emit('update');
|
|
395
404
|
}
|
|
396
405
|
);
|