@drift-labs/sdk 2.142.0-beta.14 → 2.142.0-beta.15

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.14
1
+ 2.142.0-beta.15
@@ -30,6 +30,7 @@ export declare class grpcDriftClientAccountSubscriberV2 implements DriftClientAc
30
30
  perpOracleStringMap: Map<number, string>;
31
31
  spotOracleMap: Map<number, PublicKey>;
32
32
  spotOracleStringMap: Map<number, string>;
33
+ private oracleIdToOracleDataMap;
33
34
  stateAccountSubscriber?: AccountSubscriber<StateAccount>;
34
35
  oracleClientCache: OracleClientCache;
35
36
  private resubOpts?;
@@ -19,6 +19,7 @@ class grpcDriftClientAccountSubscriberV2 {
19
19
  this.perpOracleStringMap = new Map();
20
20
  this.spotOracleMap = new Map();
21
21
  this.spotOracleStringMap = new Map();
22
+ this.oracleIdToOracleDataMap = new Map();
22
23
  this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
23
24
  this.chunks = (array, size) => {
24
25
  return new Array(Math.ceil(array.length / size))
@@ -157,11 +158,11 @@ class grpcDriftClientAccountSubscriberV2 {
157
158
  return true;
158
159
  }
159
160
  async fetch() {
160
- var _a, _b, _c, _d;
161
+ var _a, _c, _d, _e;
161
162
  await ((_a = this.stateAccountSubscriber) === null || _a === void 0 ? void 0 : _a.fetch());
162
- await ((_b = this.perpMarketsSubscriber) === null || _b === void 0 ? void 0 : _b.fetch());
163
- await ((_c = this.spotMarketsSubscriber) === null || _c === void 0 ? void 0 : _c.fetch());
164
- await ((_d = this.oracleMultiSubscriber) === null || _d === void 0 ? void 0 : _d.fetch());
163
+ await ((_c = this.perpMarketsSubscriber) === null || _c === void 0 ? void 0 : _c.fetch());
164
+ await ((_d = this.spotMarketsSubscriber) === null || _d === void 0 ? void 0 : _d.fetch());
165
+ await ((_e = this.oracleMultiSubscriber) === null || _e === void 0 ? void 0 : _e.fetch());
165
166
  }
166
167
  assertIsSubscribed() {
167
168
  if (!this.isSubscribed) {
@@ -173,14 +174,14 @@ class grpcDriftClientAccountSubscriberV2 {
173
174
  return this.stateAccountSubscriber.dataAndSlot;
174
175
  }
175
176
  getMarketAccountsAndSlots() {
176
- var _a, _b;
177
+ var _a, _c;
177
178
  const map = (_a = this.perpMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap();
178
- return Array.from((_b = map === null || map === void 0 ? void 0 : map.values()) !== null && _b !== void 0 ? _b : []);
179
+ return Array.from((_c = map === null || map === void 0 ? void 0 : map.values()) !== null && _c !== void 0 ? _c : []);
179
180
  }
180
181
  getSpotMarketAccountsAndSlots() {
181
- var _a, _b;
182
+ var _a, _c;
182
183
  const map = (_a = this.spotMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap();
183
- return Array.from((_b = map === null || map === void 0 ? void 0 : map.values()) !== null && _b !== void 0 ? _b : []);
184
+ return Array.from((_c = map === null || map === void 0 ? void 0 : map.values()) !== null && _c !== void 0 ? _c : []);
184
185
  }
185
186
  getMarketAccountAndSlot(marketIndex) {
186
187
  var _a;
@@ -191,10 +192,10 @@ class grpcDriftClientAccountSubscriberV2 {
191
192
  return (_a = this.spotMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountData(this.spotMarketIndexToAccountPubkeyMap.get(marketIndex));
192
193
  }
193
194
  getOraclePriceDataAndSlot(oracleId) {
194
- var _a;
195
195
  this.assertIsSubscribed();
196
- const { publicKey } = (0, oracleId_1.getPublicKeyAndSourceFromOracleId)(oracleId);
197
- return (_a = this.oracleMultiSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountData(publicKey.toBase58());
196
+ // we need to rely on a map we store in this class because the grpcMultiAccountSubscriber does not track a mapping or oracle ID.
197
+ // DO NOT call getAccountData on the oracleMultiSubscriber, it will not return the correct data in certain cases(BONK spot and perp market subscribed too at once).
198
+ return this.oracleIdToOracleDataMap.get(oracleId);
198
199
  }
199
200
  getOraclePriceDataAndSlotForPerpMarket(marketIndex) {
200
201
  const perpMarketAccount = this.getMarketAccountAndSlot(marketIndex);
@@ -223,7 +224,7 @@ class grpcDriftClientAccountSubscriberV2 {
223
224
  return this.getOraclePriceDataAndSlot(oracleId);
224
225
  }
225
226
  async setPerpOracleMap() {
226
- var _a, _b;
227
+ var _a, _c;
227
228
  const perpMarketsMap = (_a = this.perpMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap();
228
229
  const perpMarkets = Array.from(perpMarketsMap.values());
229
230
  const addOraclePromises = [];
@@ -235,7 +236,7 @@ class grpcDriftClientAccountSubscriberV2 {
235
236
  const perpMarketIndex = perpMarketAccount.marketIndex;
236
237
  const oracle = perpMarketAccount.amm.oracle;
237
238
  const oracleId = (0, oracleId_1.getOracleId)(oracle, perpMarket.data.amm.oracleSource);
238
- if (!((_b = this.oracleMultiSubscriber) === null || _b === void 0 ? void 0 : _b.getAccountDataMap().has(oracleId))) {
239
+ if (!((_c = this.oracleMultiSubscriber) === null || _c === void 0 ? void 0 : _c.getAccountDataMap().has(oracleId))) {
239
240
  addOraclePromises.push(this.addOracle({
240
241
  publicKey: oracle,
241
242
  source: perpMarket.data.amm.oracleSource,
@@ -247,7 +248,7 @@ class grpcDriftClientAccountSubscriberV2 {
247
248
  await Promise.all(addOraclePromises);
248
249
  }
249
250
  async setSpotOracleMap() {
250
- var _a, _b;
251
+ var _a, _c;
251
252
  const spotMarketsMap = (_a = this.spotMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap();
252
253
  const spotMarkets = Array.from(spotMarketsMap.values());
253
254
  const addOraclePromises = [];
@@ -259,7 +260,7 @@ class grpcDriftClientAccountSubscriberV2 {
259
260
  const spotMarketIndex = spotMarketAccount.marketIndex;
260
261
  const oracle = spotMarketAccount.oracle;
261
262
  const oracleId = (0, oracleId_1.getOracleId)(oracle, spotMarketAccount.oracleSource);
262
- if (!((_b = this.oracleMultiSubscriber) === null || _b === void 0 ? void 0 : _b.getAccountDataMap().has(oracleId))) {
263
+ if (!((_c = this.oracleMultiSubscriber) === null || _c === void 0 ? void 0 : _c.getAccountDataMap().has(oracleId))) {
263
264
  addOraclePromises.push(this.addOracle({
264
265
  publicKey: oracle,
265
266
  source: spotMarketAccount.oracleSource,
@@ -333,65 +334,59 @@ class grpcDriftClientAccountSubscriberV2 {
333
334
  return true;
334
335
  }
335
336
  async subscribeToOracles() {
336
- const pubkeyToSources = new Map();
337
+ const oraclePubkeyToInfosMap = new Map();
337
338
  for (const info of this.oracleInfos) {
338
- if (info.publicKey.equals(web3_js_1.PublicKey.default)) {
339
- continue;
340
- }
341
- const key = info.publicKey.toBase58();
342
- let sources = pubkeyToSources.get(key);
343
- if (!sources) {
344
- sources = new Set();
345
- pubkeyToSources.set(key, sources);
339
+ const pubkey = info.publicKey.toBase58();
340
+ if (!oraclePubkeyToInfosMap.has(pubkey)) {
341
+ oraclePubkeyToInfosMap.set(pubkey, []);
346
342
  }
347
- sources.add(info.source);
343
+ oraclePubkeyToInfosMap.get(pubkey).push(info);
348
344
  }
349
- const oraclePubkeys = Array.from(pubkeyToSources.keys()).map((k) => new web3_js_1.PublicKey(k));
350
- this.oracleMultiSubscriber =
351
- await grpcMultiAccountSubscriber_1.grpcMultiAccountSubscriber.create(this.grpcConfigs, 'oracle', this.program, (buffer, pubkey) => {
352
- if (!pubkey) {
353
- throw new Error('Oracle pubkey missing in decode');
354
- }
355
- const sources = pubkeyToSources.get(pubkey);
356
- if (!sources || sources.size === 0) {
357
- throw new Error('Oracle sources missing for pubkey in decode');
358
- }
359
- const primarySource = sources.values().next().value;
360
- const client = this.oracleClientCache.get(primarySource, this.program.provider.connection, this.program);
361
- return client.getOraclePriceDataFromBuffer(buffer);
362
- }, this.resubOpts, undefined, async () => {
363
- var _a;
364
- try {
365
- if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.logResubMessages) {
366
- console.log('[grpcDriftClientAccountSubscriberV2] oracle subscriber unsubscribed; resubscribing');
367
- }
368
- await this.subscribeToOracles();
369
- }
370
- catch (e) {
371
- console.error('Oracle resubscribe failed:', e);
345
+ const oraclePubkeys = Array.from(new Set(this.oracleInfos.map((info) => info.publicKey)));
346
+ this.oracleMultiSubscriber = await grpcMultiAccountSubscriber_1.grpcMultiAccountSubscriber.create(this.grpcConfigs, 'oracle', this.program, (buffer, pubkey, accountProps) => {
347
+ if (!pubkey) {
348
+ throw new Error('Oracle pubkey missing in decode');
349
+ }
350
+ const client = this.oracleClientCache.get(accountProps.source, this.program.provider.connection, this.program);
351
+ const price = client.getOraclePriceDataFromBuffer(buffer);
352
+ return price;
353
+ }, this.resubOpts, undefined, async () => {
354
+ var _a;
355
+ try {
356
+ if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.logResubMessages) {
357
+ console.log('[grpcDriftClientAccountSubscriberV2] oracle subscriber unsubscribed; resubscribing');
372
358
  }
373
- });
359
+ await this.subscribeToOracles();
360
+ }
361
+ catch (e) {
362
+ console.error('Oracle resubscribe failed:', e);
363
+ }
364
+ }, oraclePubkeyToInfosMap);
374
365
  for (const data of this.initialOraclePriceData.entries()) {
375
366
  const { publicKey } = (0, oracleId_1.getPublicKeyAndSourceFromOracleId)(data[0]);
376
367
  this.oracleMultiSubscriber.setAccountData(publicKey.toBase58(), data[1]);
368
+ this.oracleIdToOracleDataMap.set(data[0], {
369
+ data: data[1],
370
+ slot: 0,
371
+ });
377
372
  }
378
- await this.oracleMultiSubscriber.subscribe(oraclePubkeys, (accountId, data) => {
379
- const sources = pubkeyToSources.get(accountId.toBase58());
380
- if (sources) {
381
- for (const source of sources.values()) {
382
- this.eventEmitter.emit('oraclePriceUpdate', accountId, source, data);
383
- }
384
- }
373
+ await this.oracleMultiSubscriber.subscribe(oraclePubkeys, (accountId, data, context, _b, accountProps) => {
374
+ const oracleId = (0, oracleId_1.getOracleId)(accountId, accountProps.source);
375
+ this.oracleIdToOracleDataMap.set(oracleId, {
376
+ data,
377
+ slot: context.slot,
378
+ });
379
+ this.eventEmitter.emit('oraclePriceUpdate', accountId, accountProps.source, data);
385
380
  this.eventEmitter.emit('update');
386
381
  });
387
382
  return true;
388
383
  }
389
384
  async handleDelistedMarkets() {
390
- var _a, _b;
385
+ var _a, _c;
391
386
  if (this.delistedMarketSetting === types_1.DelistedMarketSetting.Subscribe) {
392
387
  return;
393
388
  }
394
- const { perpMarketIndexes, oracles } = (0, utils_1.findDelistedPerpMarketsAndOracles)(Array.from(((_a = this.perpMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap().values()) || []), Array.from(((_b = this.spotMarketsSubscriber) === null || _b === void 0 ? void 0 : _b.getAccountDataMap().values()) || []));
389
+ const { perpMarketIndexes, oracles } = (0, utils_1.findDelistedPerpMarketsAndOracles)(Array.from(((_a = this.perpMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap().values()) || []), Array.from(((_c = this.spotMarketsSubscriber) === null || _c === void 0 ? void 0 : _c.getAccountDataMap().values()) || []));
395
390
  for (const perpMarketIndex of perpMarketIndexes) {
396
391
  await this.perpMarketsSubscriber.removeAccounts([
397
392
  new web3_js_1.PublicKey(this.perpMarketIndexToAccountPubkeyMap.get(perpMarketIndex) || ''),
@@ -417,14 +412,14 @@ class grpcDriftClientAccountSubscriberV2 {
417
412
  }
418
413
  }
419
414
  async unsubscribe() {
420
- var _a, _b;
415
+ var _a, _c;
421
416
  if (this.isSubscribed) {
422
417
  return;
423
418
  }
424
419
  await this.stateAccountSubscriber.unsubscribe();
425
420
  await this.unsubscribeFromOracles();
426
421
  await ((_a = this.perpMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.unsubscribe());
427
- await ((_b = this.spotMarketsSubscriber) === null || _b === void 0 ? void 0 : _b.unsubscribe());
422
+ await ((_c = this.spotMarketsSubscriber) === null || _c === void 0 ? void 0 : _c.unsubscribe());
428
423
  }
429
424
  }
430
425
  exports.grpcDriftClientAccountSubscriberV2 = grpcDriftClientAccountSubscriberV2;
@@ -4,7 +4,7 @@ import { Program } from '@coral-xyz/anchor';
4
4
  import { Context, PublicKey } from '@solana/web3.js';
5
5
  import { Client } from '../isomorphic/grpc';
6
6
  import { DataAndSlot, GrpcConfigs, ResubOpts } from './types';
7
- export declare class grpcMultiAccountSubscriber<T> {
7
+ export declare class grpcMultiAccountSubscriber<T, U = undefined> {
8
8
  private client;
9
9
  private stream;
10
10
  private commitmentLevel;
@@ -20,13 +20,14 @@ export declare class grpcMultiAccountSubscriber<T> {
20
20
  private subscribedAccounts;
21
21
  private onChangeMap;
22
22
  private dataMap;
23
+ private accountPropsMap;
23
24
  private constructor();
24
- static create<U>(grpcConfigs: GrpcConfigs, accountName: string, program: Program, decodeBuffer?: (buffer: Buffer, pubkey?: string) => U, resubOpts?: ResubOpts, clientProp?: Client, onUnsubscribe?: () => Promise<void>): Promise<grpcMultiAccountSubscriber<U>>;
25
+ static create<T, U = undefined>(grpcConfigs: GrpcConfigs, accountName: string, program: Program, decodeBuffer?: (buffer: Buffer, pubkey?: string, accountProps?: U) => T, resubOpts?: ResubOpts, clientProp?: Client, onUnsubscribe?: () => Promise<void>, accountPropsMap?: Map<string, U | Array<U>>): Promise<grpcMultiAccountSubscriber<T, U>>;
25
26
  setAccountData(accountPubkey: string, data: T, slot?: number): void;
26
27
  getAccountData(accountPubkey: string): DataAndSlot<T> | undefined;
27
28
  getAccountDataMap(): Map<string, DataAndSlot<T>>;
28
29
  fetch(): Promise<void>;
29
- subscribe(accounts: PublicKey[], onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer) => void): Promise<void>;
30
+ subscribe(accounts: PublicKey[], onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer, accountProps: U) => void): Promise<void>;
30
31
  addAccounts(accounts: PublicKey[]): Promise<void>;
31
32
  removeAccounts(accounts: PublicKey[]): Promise<void>;
32
33
  unsubscribe(): Promise<void>;
@@ -44,12 +44,13 @@ function commitmentLevelToCommitment(commitmentLevel) {
44
44
  }
45
45
  }
46
46
  class grpcMultiAccountSubscriber {
47
- constructor(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe) {
47
+ constructor(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe, accountPropsMap) {
48
48
  this.isUnsubscribing = false;
49
49
  this.receivingData = false;
50
50
  this.subscribedAccounts = new Set();
51
51
  this.onChangeMap = new Map();
52
52
  this.dataMap = new Map();
53
+ this.accountPropsMap = new Map();
53
54
  this.client = client;
54
55
  this.commitmentLevel = commitmentLevel;
55
56
  this.accountName = accountName;
@@ -57,8 +58,9 @@ class grpcMultiAccountSubscriber {
57
58
  this.decodeBufferFn = decodeBuffer;
58
59
  this.resubOpts = resubOpts;
59
60
  this.onUnsubscribe = onUnsubscribe;
61
+ this.accountPropsMap = accountPropsMap;
60
62
  }
61
- static async create(grpcConfigs, accountName, program, decodeBuffer, resubOpts, clientProp, onUnsubscribe) {
63
+ static async create(grpcConfigs, accountName, program, decodeBuffer, resubOpts, clientProp, onUnsubscribe, accountPropsMap) {
62
64
  var _a, _b;
63
65
  const client = clientProp
64
66
  ? clientProp
@@ -66,7 +68,7 @@ class grpcMultiAccountSubscriber {
66
68
  const commitmentLevel =
67
69
  // @ts-ignore :: isomorphic exported enum fails typescript but will work at runtime
68
70
  (_b = grpcConfigs.commitmentLevel) !== null && _b !== void 0 ? _b : grpc_1.CommitmentLevel.CONFIRMED;
69
- return new grpcMultiAccountSubscriber(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe);
71
+ return new grpcMultiAccountSubscriber(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe, accountPropsMap);
70
72
  }
71
73
  setAccountData(accountPubkey, data, slot) {
72
74
  this.dataMap.set(accountPubkey, { data, slot });
@@ -119,9 +121,9 @@ class grpcMultiAccountSubscriber {
119
121
  for (const pk of accounts) {
120
122
  const key = pk.toBase58();
121
123
  this.subscribedAccounts.add(key);
122
- this.onChangeMap.set(key, (data, ctx, buffer) => {
124
+ this.onChangeMap.set(key, (data, ctx, buffer, accountProps) => {
123
125
  this.setAccountData(key, data, ctx.slot);
124
- onChange(new web3_js_1.PublicKey(key), data, ctx, buffer);
126
+ onChange(new web3_js_1.PublicKey(key), data, ctx, buffer, accountProps);
125
127
  });
126
128
  }
127
129
  this.stream =
@@ -163,21 +165,33 @@ class grpcMultiAccountSubscriber {
163
165
  };
164
166
  const context = { slot };
165
167
  const buffer = accountInfo.data;
166
- const data = this.decodeBufferFn
167
- ? this.decodeBufferFn(buffer, accountPubkey)
168
- : this.program.account[this.accountName].coder.accounts.decode(this.capitalize(this.accountName), buffer);
169
- const handler = this.onChangeMap.get(accountPubkey);
170
- if (handler) {
171
- if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
172
- this.receivingData = true;
173
- clearTimeout(this.timeoutId);
174
- handler(data, context, buffer);
175
- this.setTimeout();
168
+ const accountProps = (_a = this.accountPropsMap) === null || _a === void 0 ? void 0 : _a.get(accountPubkey);
169
+ const handleDataBuffer = (context, buffer, accountProps) => {
170
+ var _a;
171
+ const data = this.decodeBufferFn
172
+ ? this.decodeBufferFn(buffer, accountPubkey, accountProps)
173
+ : this.program.account[this.accountName].coder.accounts.decode(this.capitalize(this.accountName), buffer);
174
+ const handler = this.onChangeMap.get(accountPubkey);
175
+ if (handler) {
176
+ if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
177
+ this.receivingData = true;
178
+ clearTimeout(this.timeoutId);
179
+ handler(data, context, buffer, accountProps);
180
+ this.setTimeout();
181
+ }
182
+ else {
183
+ handler(data, context, buffer, accountProps);
184
+ }
176
185
  }
177
- else {
178
- handler(data, context, buffer);
186
+ };
187
+ if (Array.isArray(accountProps)) {
188
+ for (const props of accountProps) {
189
+ handleDataBuffer(context, buffer, props);
179
190
  }
180
191
  }
192
+ else {
193
+ handleDataBuffer(context, buffer, accountProps);
194
+ }
181
195
  });
182
196
  return new Promise((resolve, reject) => {
183
197
  this.stream.write(request, (err) => {
@@ -30,6 +30,7 @@ export declare class grpcDriftClientAccountSubscriberV2 implements DriftClientAc
30
30
  perpOracleStringMap: Map<number, string>;
31
31
  spotOracleMap: Map<number, PublicKey>;
32
32
  spotOracleStringMap: Map<number, string>;
33
+ private oracleIdToOracleDataMap;
33
34
  stateAccountSubscriber?: AccountSubscriber<StateAccount>;
34
35
  oracleClientCache: OracleClientCache;
35
36
  private resubOpts?;
@@ -1 +1 @@
1
- {"version":3,"file":"grpcDriftClientAccountSubscriberV2.d.ts","sourceRoot":"","sources":["../../../src/accounts/grpcDriftClientAccountSubscriberV2.ts"],"names":[],"mappings":";AAAA,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C,OAAO,EACN,iBAAiB,EACjB,WAAW,EACX,qBAAqB,EACrB,wBAAwB,EACxB,4BAA4B,EAE5B,WAAW,EACX,SAAS,EACT,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAK9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAGjE,qBAAa,kCACZ,YAAW,4BAA4B;IAEvC,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;IACtE,OAAO,CAAC,qBAAqB,CAAwB;IAE9C,YAAY,EAAE,kBAAkB,CAC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AK7D,6BAA6B,IAAI,WAAW,CAAC,iBAAiB,CAAC,EAAE;IAKxE,uBAAuB,CACtB,WAAW,EAAE,MAAM,GACjB,WAAW,CAAC,iBAAiB,CAAC,GAAG,SAAS;IAM7C,2BAA2B,CAC1B,WAAW,EAAE,MAAM,GACjB,WAAW,CAAC,iBAAiB,CAAC,GAAG,SAAS;IAMtC,yBAAyB,CAC/B,QAAQ,EAAE,MAAM,GACd,WAAW,CAAC,eAAe,CAAC,GAAG,SAAS;IAOpC,sCAAsC,CAC5C,WAAW,EAAE,MAAM,GACjB,WAAW,CAAC,eAAe,CAAC,GAAG,SAAS;IAgBpC,sCAAsC,CAC5C,WAAW,EAAE,MAAM,GACjB,WAAW,CAAC,eAAe,CAAC,GAAG,SAAS;IAgBrC,gBAAgB;IA0BhB,gBAAgB;IA0BhB,6BAA6B,IAAI,OAAO,CAAC,OAAO,CAAC;IA8DjD,6BAA6B,IAAI,OAAO,CAAC,OAAO,CAAC;IA8DjD,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC;IAkFtC,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IA4B5C,iBAAiB;IAMX,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAQvC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAUlC"}
@@ -19,6 +19,7 @@ class grpcDriftClientAccountSubscriberV2 {
19
19
  this.perpOracleStringMap = new Map();
20
20
  this.spotOracleMap = new Map();
21
21
  this.spotOracleStringMap = new Map();
22
+ this.oracleIdToOracleDataMap = new Map();
22
23
  this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
23
24
  this.chunks = (array, size) => {
24
25
  return new Array(Math.ceil(array.length / size))
@@ -157,11 +158,11 @@ class grpcDriftClientAccountSubscriberV2 {
157
158
  return true;
158
159
  }
159
160
  async fetch() {
160
- var _a, _b, _c, _d;
161
+ var _a, _c, _d, _e;
161
162
  await ((_a = this.stateAccountSubscriber) === null || _a === void 0 ? void 0 : _a.fetch());
162
- await ((_b = this.perpMarketsSubscriber) === null || _b === void 0 ? void 0 : _b.fetch());
163
- await ((_c = this.spotMarketsSubscriber) === null || _c === void 0 ? void 0 : _c.fetch());
164
- await ((_d = this.oracleMultiSubscriber) === null || _d === void 0 ? void 0 : _d.fetch());
163
+ await ((_c = this.perpMarketsSubscriber) === null || _c === void 0 ? void 0 : _c.fetch());
164
+ await ((_d = this.spotMarketsSubscriber) === null || _d === void 0 ? void 0 : _d.fetch());
165
+ await ((_e = this.oracleMultiSubscriber) === null || _e === void 0 ? void 0 : _e.fetch());
165
166
  }
166
167
  assertIsSubscribed() {
167
168
  if (!this.isSubscribed) {
@@ -173,14 +174,14 @@ class grpcDriftClientAccountSubscriberV2 {
173
174
  return this.stateAccountSubscriber.dataAndSlot;
174
175
  }
175
176
  getMarketAccountsAndSlots() {
176
- var _a, _b;
177
+ var _a, _c;
177
178
  const map = (_a = this.perpMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap();
178
- return Array.from((_b = map === null || map === void 0 ? void 0 : map.values()) !== null && _b !== void 0 ? _b : []);
179
+ return Array.from((_c = map === null || map === void 0 ? void 0 : map.values()) !== null && _c !== void 0 ? _c : []);
179
180
  }
180
181
  getSpotMarketAccountsAndSlots() {
181
- var _a, _b;
182
+ var _a, _c;
182
183
  const map = (_a = this.spotMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap();
183
- return Array.from((_b = map === null || map === void 0 ? void 0 : map.values()) !== null && _b !== void 0 ? _b : []);
184
+ return Array.from((_c = map === null || map === void 0 ? void 0 : map.values()) !== null && _c !== void 0 ? _c : []);
184
185
  }
185
186
  getMarketAccountAndSlot(marketIndex) {
186
187
  var _a;
@@ -191,10 +192,10 @@ class grpcDriftClientAccountSubscriberV2 {
191
192
  return (_a = this.spotMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountData(this.spotMarketIndexToAccountPubkeyMap.get(marketIndex));
192
193
  }
193
194
  getOraclePriceDataAndSlot(oracleId) {
194
- var _a;
195
195
  this.assertIsSubscribed();
196
- const { publicKey } = (0, oracleId_1.getPublicKeyAndSourceFromOracleId)(oracleId);
197
- return (_a = this.oracleMultiSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountData(publicKey.toBase58());
196
+ // we need to rely on a map we store in this class because the grpcMultiAccountSubscriber does not track a mapping or oracle ID.
197
+ // DO NOT call getAccountData on the oracleMultiSubscriber, it will not return the correct data in certain cases(BONK spot and perp market subscribed too at once).
198
+ return this.oracleIdToOracleDataMap.get(oracleId);
198
199
  }
199
200
  getOraclePriceDataAndSlotForPerpMarket(marketIndex) {
200
201
  const perpMarketAccount = this.getMarketAccountAndSlot(marketIndex);
@@ -223,7 +224,7 @@ class grpcDriftClientAccountSubscriberV2 {
223
224
  return this.getOraclePriceDataAndSlot(oracleId);
224
225
  }
225
226
  async setPerpOracleMap() {
226
- var _a, _b;
227
+ var _a, _c;
227
228
  const perpMarketsMap = (_a = this.perpMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap();
228
229
  const perpMarkets = Array.from(perpMarketsMap.values());
229
230
  const addOraclePromises = [];
@@ -235,7 +236,7 @@ class grpcDriftClientAccountSubscriberV2 {
235
236
  const perpMarketIndex = perpMarketAccount.marketIndex;
236
237
  const oracle = perpMarketAccount.amm.oracle;
237
238
  const oracleId = (0, oracleId_1.getOracleId)(oracle, perpMarket.data.amm.oracleSource);
238
- if (!((_b = this.oracleMultiSubscriber) === null || _b === void 0 ? void 0 : _b.getAccountDataMap().has(oracleId))) {
239
+ if (!((_c = this.oracleMultiSubscriber) === null || _c === void 0 ? void 0 : _c.getAccountDataMap().has(oracleId))) {
239
240
  addOraclePromises.push(this.addOracle({
240
241
  publicKey: oracle,
241
242
  source: perpMarket.data.amm.oracleSource,
@@ -247,7 +248,7 @@ class grpcDriftClientAccountSubscriberV2 {
247
248
  await Promise.all(addOraclePromises);
248
249
  }
249
250
  async setSpotOracleMap() {
250
- var _a, _b;
251
+ var _a, _c;
251
252
  const spotMarketsMap = (_a = this.spotMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap();
252
253
  const spotMarkets = Array.from(spotMarketsMap.values());
253
254
  const addOraclePromises = [];
@@ -259,7 +260,7 @@ class grpcDriftClientAccountSubscriberV2 {
259
260
  const spotMarketIndex = spotMarketAccount.marketIndex;
260
261
  const oracle = spotMarketAccount.oracle;
261
262
  const oracleId = (0, oracleId_1.getOracleId)(oracle, spotMarketAccount.oracleSource);
262
- if (!((_b = this.oracleMultiSubscriber) === null || _b === void 0 ? void 0 : _b.getAccountDataMap().has(oracleId))) {
263
+ if (!((_c = this.oracleMultiSubscriber) === null || _c === void 0 ? void 0 : _c.getAccountDataMap().has(oracleId))) {
263
264
  addOraclePromises.push(this.addOracle({
264
265
  publicKey: oracle,
265
266
  source: spotMarketAccount.oracleSource,
@@ -333,65 +334,59 @@ class grpcDriftClientAccountSubscriberV2 {
333
334
  return true;
334
335
  }
335
336
  async subscribeToOracles() {
336
- const pubkeyToSources = new Map();
337
+ const oraclePubkeyToInfosMap = new Map();
337
338
  for (const info of this.oracleInfos) {
338
- if (info.publicKey.equals(web3_js_1.PublicKey.default)) {
339
- continue;
340
- }
341
- const key = info.publicKey.toBase58();
342
- let sources = pubkeyToSources.get(key);
343
- if (!sources) {
344
- sources = new Set();
345
- pubkeyToSources.set(key, sources);
339
+ const pubkey = info.publicKey.toBase58();
340
+ if (!oraclePubkeyToInfosMap.has(pubkey)) {
341
+ oraclePubkeyToInfosMap.set(pubkey, []);
346
342
  }
347
- sources.add(info.source);
343
+ oraclePubkeyToInfosMap.get(pubkey).push(info);
348
344
  }
349
- const oraclePubkeys = Array.from(pubkeyToSources.keys()).map((k) => new web3_js_1.PublicKey(k));
350
- this.oracleMultiSubscriber =
351
- await grpcMultiAccountSubscriber_1.grpcMultiAccountSubscriber.create(this.grpcConfigs, 'oracle', this.program, (buffer, pubkey) => {
352
- if (!pubkey) {
353
- throw new Error('Oracle pubkey missing in decode');
354
- }
355
- const sources = pubkeyToSources.get(pubkey);
356
- if (!sources || sources.size === 0) {
357
- throw new Error('Oracle sources missing for pubkey in decode');
358
- }
359
- const primarySource = sources.values().next().value;
360
- const client = this.oracleClientCache.get(primarySource, this.program.provider.connection, this.program);
361
- return client.getOraclePriceDataFromBuffer(buffer);
362
- }, this.resubOpts, undefined, async () => {
363
- var _a;
364
- try {
365
- if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.logResubMessages) {
366
- console.log('[grpcDriftClientAccountSubscriberV2] oracle subscriber unsubscribed; resubscribing');
367
- }
368
- await this.subscribeToOracles();
369
- }
370
- catch (e) {
371
- console.error('Oracle resubscribe failed:', e);
345
+ const oraclePubkeys = Array.from(new Set(this.oracleInfos.map((info) => info.publicKey)));
346
+ this.oracleMultiSubscriber = await grpcMultiAccountSubscriber_1.grpcMultiAccountSubscriber.create(this.grpcConfigs, 'oracle', this.program, (buffer, pubkey, accountProps) => {
347
+ if (!pubkey) {
348
+ throw new Error('Oracle pubkey missing in decode');
349
+ }
350
+ const client = this.oracleClientCache.get(accountProps.source, this.program.provider.connection, this.program);
351
+ const price = client.getOraclePriceDataFromBuffer(buffer);
352
+ return price;
353
+ }, this.resubOpts, undefined, async () => {
354
+ var _a;
355
+ try {
356
+ if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.logResubMessages) {
357
+ console.log('[grpcDriftClientAccountSubscriberV2] oracle subscriber unsubscribed; resubscribing');
372
358
  }
373
- });
359
+ await this.subscribeToOracles();
360
+ }
361
+ catch (e) {
362
+ console.error('Oracle resubscribe failed:', e);
363
+ }
364
+ }, oraclePubkeyToInfosMap);
374
365
  for (const data of this.initialOraclePriceData.entries()) {
375
366
  const { publicKey } = (0, oracleId_1.getPublicKeyAndSourceFromOracleId)(data[0]);
376
367
  this.oracleMultiSubscriber.setAccountData(publicKey.toBase58(), data[1]);
368
+ this.oracleIdToOracleDataMap.set(data[0], {
369
+ data: data[1],
370
+ slot: 0,
371
+ });
377
372
  }
378
- await this.oracleMultiSubscriber.subscribe(oraclePubkeys, (accountId, data) => {
379
- const sources = pubkeyToSources.get(accountId.toBase58());
380
- if (sources) {
381
- for (const source of sources.values()) {
382
- this.eventEmitter.emit('oraclePriceUpdate', accountId, source, data);
383
- }
384
- }
373
+ await this.oracleMultiSubscriber.subscribe(oraclePubkeys, (accountId, data, context, _b, accountProps) => {
374
+ const oracleId = (0, oracleId_1.getOracleId)(accountId, accountProps.source);
375
+ this.oracleIdToOracleDataMap.set(oracleId, {
376
+ data,
377
+ slot: context.slot,
378
+ });
379
+ this.eventEmitter.emit('oraclePriceUpdate', accountId, accountProps.source, data);
385
380
  this.eventEmitter.emit('update');
386
381
  });
387
382
  return true;
388
383
  }
389
384
  async handleDelistedMarkets() {
390
- var _a, _b;
385
+ var _a, _c;
391
386
  if (this.delistedMarketSetting === types_1.DelistedMarketSetting.Subscribe) {
392
387
  return;
393
388
  }
394
- const { perpMarketIndexes, oracles } = (0, utils_1.findDelistedPerpMarketsAndOracles)(Array.from(((_a = this.perpMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap().values()) || []), Array.from(((_b = this.spotMarketsSubscriber) === null || _b === void 0 ? void 0 : _b.getAccountDataMap().values()) || []));
389
+ const { perpMarketIndexes, oracles } = (0, utils_1.findDelistedPerpMarketsAndOracles)(Array.from(((_a = this.perpMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap().values()) || []), Array.from(((_c = this.spotMarketsSubscriber) === null || _c === void 0 ? void 0 : _c.getAccountDataMap().values()) || []));
395
390
  for (const perpMarketIndex of perpMarketIndexes) {
396
391
  await this.perpMarketsSubscriber.removeAccounts([
397
392
  new web3_js_1.PublicKey(this.perpMarketIndexToAccountPubkeyMap.get(perpMarketIndex) || ''),
@@ -417,14 +412,14 @@ class grpcDriftClientAccountSubscriberV2 {
417
412
  }
418
413
  }
419
414
  async unsubscribe() {
420
- var _a, _b;
415
+ var _a, _c;
421
416
  if (this.isSubscribed) {
422
417
  return;
423
418
  }
424
419
  await this.stateAccountSubscriber.unsubscribe();
425
420
  await this.unsubscribeFromOracles();
426
421
  await ((_a = this.perpMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.unsubscribe());
427
- await ((_b = this.spotMarketsSubscriber) === null || _b === void 0 ? void 0 : _b.unsubscribe());
422
+ await ((_c = this.spotMarketsSubscriber) === null || _c === void 0 ? void 0 : _c.unsubscribe());
428
423
  }
429
424
  }
430
425
  exports.grpcDriftClientAccountSubscriberV2 = grpcDriftClientAccountSubscriberV2;
@@ -4,7 +4,7 @@ import { Program } from '@coral-xyz/anchor';
4
4
  import { Context, PublicKey } from '@solana/web3.js';
5
5
  import { Client } from '../isomorphic/grpc';
6
6
  import { DataAndSlot, GrpcConfigs, ResubOpts } from './types';
7
- export declare class grpcMultiAccountSubscriber<T> {
7
+ export declare class grpcMultiAccountSubscriber<T, U = undefined> {
8
8
  private client;
9
9
  private stream;
10
10
  private commitmentLevel;
@@ -20,13 +20,14 @@ export declare class grpcMultiAccountSubscriber<T> {
20
20
  private subscribedAccounts;
21
21
  private onChangeMap;
22
22
  private dataMap;
23
+ private accountPropsMap;
23
24
  private constructor();
24
- static create<U>(grpcConfigs: GrpcConfigs, accountName: string, program: Program, decodeBuffer?: (buffer: Buffer, pubkey?: string) => U, resubOpts?: ResubOpts, clientProp?: Client, onUnsubscribe?: () => Promise<void>): Promise<grpcMultiAccountSubscriber<U>>;
25
+ static create<T, U = undefined>(grpcConfigs: GrpcConfigs, accountName: string, program: Program, decodeBuffer?: (buffer: Buffer, pubkey?: string, accountProps?: U) => T, resubOpts?: ResubOpts, clientProp?: Client, onUnsubscribe?: () => Promise<void>, accountPropsMap?: Map<string, U | Array<U>>): Promise<grpcMultiAccountSubscriber<T, U>>;
25
26
  setAccountData(accountPubkey: string, data: T, slot?: number): void;
26
27
  getAccountData(accountPubkey: string): DataAndSlot<T> | undefined;
27
28
  getAccountDataMap(): Map<string, DataAndSlot<T>>;
28
29
  fetch(): Promise<void>;
29
- subscribe(accounts: PublicKey[], onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer) => void): Promise<void>;
30
+ subscribe(accounts: PublicKey[], onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer, accountProps: U) => void): Promise<void>;
30
31
  addAccounts(accounts: PublicKey[]): Promise<void>;
31
32
  removeAccounts(accounts: PublicKey[]): Promise<void>;
32
33
  unsubscribe(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"grpcMultiAccountSubscriber.d.ts","sourceRoot":"","sources":["../../../src/accounts/grpcMultiAccountSubscriber.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAc,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIjE,OAAO,EACN,MAAM,EAMN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAyB9D,qBAAa,0BAA0B,CAAC,CAAC;IACxC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAwD;IACtE,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,cAAc,CAAC,CAAyC;IAChE,OAAO,CAAC,SAAS,CAAC,CAAY;IAC9B,OAAO,CAAC,aAAa,CAAC,CAAsB;IAErC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,UAAS;IAC/B,OAAO,CAAC,SAAS,CAAC,CAAgC;IAClD,OAAO,CAAC,aAAa,CAAS;IAE9B,OAAO,CAAC,kBAAkB,CAAqB;IAC/C,OAAO,CAAC,WAAW,CAGf;IAEJ,OAAO,CAAC,OAAO,CAAqC;IAEpD,OAAO;WAkBa,MAAM,CAAC,CAAC,EAC3B,WAAW,EAAE,WAAW,EACxB,WAAW,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