@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 CHANGED
@@ -1 +1 @@
1
- 2.142.0-beta.10
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
- // Build list of unique oracle pubkeys and a lookup for sources
184
- const uniqueOraclePubkeys = new Map();
183
+ const pubkeyToSources = new Map();
185
184
  for (const info of this.oracleInfos) {
186
- const id = (0, oracleId_1.getOracleId)(info.publicKey, info.source);
187
- if (!uniqueOraclePubkeys.has(id) &&
188
- !info.publicKey.equals(web3_js_1.PublicKey.default)) {
189
- uniqueOraclePubkeys.set(id, info);
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(uniqueOraclePubkeys.values()).map((i) => i.publicKey);
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 source = pubkeyToSource.get(pubkey);
203
- const client = this.oracleClientCache.get(source, this.program.provider.connection, this.program);
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 source = pubkeyToSource.get(accountId.toBase58());
223
- this.eventEmitter.emit('oraclePriceUpdate', accountId, source, data);
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,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAQ5C,OAAO,EACN,WAAW,EACX,qBAAqB,EACrB,WAAW,EACX,SAAS,EACT,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAgB,MAAM,UAAU,CAAC;AAM9E,qBAAa,kCAAmC,SAAQ,qCAAqC;IAC5F,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,qBAAqB,CAAC,CAAgD;IAC9E,OAAO,CAAC,qBAAqB,CAAC,CAAgD;IAC9E,OAAO,CAAC,qBAA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E,qBAAa,kCAAmC,SAAQ,qCAAqC;IAC5F,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,qBAAqB,CAAC,CAAgD;IAC9E,OAAO,CAAC,qBAAqB,CAAC,CAAgD;IAC9E,OAAO,CAAC,qBAAqB,CAAC,CAA8C;IAC5E,OAAO,CAAC,iCAAiC,CAA6B;IACtE,OAAO,CAAC,iCAAiC,CAA6B;gBAGrE,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,OAAO,EAChB,iBAAiB,EAAE,MAAM,EAAE,EAC3B,iBAAiB,EAAE,MAAM,EAAE,EAC3B,WAAW,EAAE,UAAU,EAAE,EACzB,8BAA8B,EAAE,OAAO,EACvC,qBAAqB,EAAE,qBAAqB,EAC5C,SAAS,CAAC,EAAE,SAAS;IAcT,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAiFjC,uBAAuB,CAC/B,WAAW,EAAE,MAAM,GACjB,WAAW,CAAC,iBAAiB,CAAC,GAAG,SAAS;IAMpC,2BAA2B,CACnC,WAAW,EAAE,MAAM,GACjB,WAAW,CAAC,iBAAiB,CAAC,GAAG,SAAS;IAM9B,gBAAgB;IA0BhB,gBAAgB;IA0BhB,6BAA6B,IAAI,OAAO,CAAC,OAAO,CAAC;IA8DjD,6BAA6B,IAAI,OAAO,CAAC,OAAO,CAAC;IA8DjD,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC;IAkF/C,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAS9B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAO3C"}
@@ -180,27 +180,31 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
180
180
  return true;
181
181
  }
182
182
  async subscribeToOracles() {
183
- // Build list of unique oracle pubkeys and a lookup for sources
184
- const uniqueOraclePubkeys = new Map();
183
+ const pubkeyToSources = new Map();
185
184
  for (const info of this.oracleInfos) {
186
- const id = (0, oracleId_1.getOracleId)(info.publicKey, info.source);
187
- if (!uniqueOraclePubkeys.has(id) &&
188
- !info.publicKey.equals(web3_js_1.PublicKey.default)) {
189
- uniqueOraclePubkeys.set(id, info);
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(uniqueOraclePubkeys.values()).map((i) => i.publicKey);
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 source = pubkeyToSource.get(pubkey);
203
- const client = this.oracleClientCache.get(source, this.program.provider.connection, this.program);
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 source = pubkeyToSource.get(accountId.toBase58());
223
- this.eventEmitter.emit('oraclePriceUpdate', accountId, source, data);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.142.0-beta.10",
3
+ "version": "2.142.0-beta.11",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "module": "./lib/browser/index.js",
@@ -326,26 +326,22 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
326
326
  }
327
327
 
328
328
  override async subscribeToOracles(): Promise<boolean> {
329
- // Build list of unique oracle pubkeys and a lookup for sources
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
- const id = getOracleId(info.publicKey, info.source);
333
- if (
334
- !uniqueOraclePubkeys.has(id) &&
335
- !info.publicKey.equals((PublicKey as any).default)
336
- ) {
337
- uniqueOraclePubkeys.set(id, info);
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(uniqueOraclePubkeys.values()).map(
342
- (i) => i.publicKey
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 source = pubkeyToSource.get(pubkey);
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
- source,
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 source = pubkeyToSource.get(accountId.toBase58());
393
- this.eventEmitter.emit('oraclePriceUpdate', accountId, source, data);
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
  );