@drift-labs/sdk 2.142.0-beta.8 → 2.142.0-beta.9

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.8
1
+ 2.142.0-beta.9
@@ -140,7 +140,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
140
140
  }
141
141
  });
142
142
  for (const data of this.initialPerpMarketAccountData.values()) {
143
- this.perpMarketsSubscriber.setAccountData(data.pubkey, data);
143
+ this.perpMarketsSubscriber.setAccountData(data.pubkey.toBase58(), data);
144
144
  }
145
145
  await this.perpMarketsSubscriber.subscribe(perpMarketPubkeys, (_accountId, data) => {
146
146
  this.eventEmitter.emit('perpMarketAccountUpdate', data);
@@ -171,7 +171,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
171
171
  }
172
172
  });
173
173
  for (const data of this.initialSpotMarketAccountData.values()) {
174
- this.spotMarketsSubscriber.setAccountData(data.pubkey, data);
174
+ this.spotMarketsSubscriber.setAccountData(data.pubkey.toBase58(), data);
175
175
  }
176
176
  await this.spotMarketsSubscriber.subscribe(spotMarketPubkeys, (_accountId, data) => {
177
177
  this.eventEmitter.emit('spotMarketAccountUpdate', data);
@@ -216,7 +216,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
216
216
  });
217
217
  for (const data of this.initialOraclePriceData.entries()) {
218
218
  const { publicKey } = (0, oracleId_1.getPublicKeyAndSourceFromOracleId)(data[0]);
219
- this.oracleMultiSubscriber.setAccountData(publicKey, data[1]);
219
+ this.oracleMultiSubscriber.setAccountData(publicKey.toBase58(), data[1]);
220
220
  }
221
221
  await this.oracleMultiSubscriber.subscribe(oraclePubkeys, (accountId, data) => {
222
222
  const source = pubkeyToSource.get(accountId.toBase58());
@@ -22,7 +22,7 @@ export declare class grpcMultiAccountSubscriber<T> {
22
22
  private dataMap;
23
23
  private constructor();
24
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
- setAccountData(accountPubkey: PublicKey, data: T, slot?: number): void;
25
+ setAccountData(accountPubkey: string, data: T, slot?: number): void;
26
26
  getAccountData(accountPubkey: string): DataAndSlot<T> | undefined;
27
27
  getAccountDataMap(): Map<string, DataAndSlot<T>>;
28
28
  subscribe(accounts: PublicKey[], onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer) => void): Promise<void>;
@@ -57,7 +57,7 @@ class grpcMultiAccountSubscriber {
57
57
  return new grpcMultiAccountSubscriber(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe);
58
58
  }
59
59
  setAccountData(accountPubkey, data, slot) {
60
- this.dataMap.set(accountPubkey.toBase58(), { data, slot });
60
+ this.dataMap.set(accountPubkey, { data, slot });
61
61
  }
62
62
  getAccountData(accountPubkey) {
63
63
  return this.dataMap.get(accountPubkey);
@@ -73,7 +73,10 @@ class grpcMultiAccountSubscriber {
73
73
  for (const pk of accounts) {
74
74
  const key = pk.toBase58();
75
75
  this.subscribedAccounts.add(key);
76
- this.onChangeMap.set(key, (data, ctx, buffer) => onChange(new web3_js_1.PublicKey(key), data, ctx, buffer));
76
+ this.onChangeMap.set(key, (data, ctx, buffer) => {
77
+ this.setAccountData(key, data, ctx.slot);
78
+ onChange(new web3_js_1.PublicKey(key), data, ctx, buffer);
79
+ });
77
80
  }
78
81
  this.stream =
79
82
  (await this.client.subscribe());
@@ -140,7 +140,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
140
140
  }
141
141
  });
142
142
  for (const data of this.initialPerpMarketAccountData.values()) {
143
- this.perpMarketsSubscriber.setAccountData(data.pubkey, data);
143
+ this.perpMarketsSubscriber.setAccountData(data.pubkey.toBase58(), data);
144
144
  }
145
145
  await this.perpMarketsSubscriber.subscribe(perpMarketPubkeys, (_accountId, data) => {
146
146
  this.eventEmitter.emit('perpMarketAccountUpdate', data);
@@ -171,7 +171,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
171
171
  }
172
172
  });
173
173
  for (const data of this.initialSpotMarketAccountData.values()) {
174
- this.spotMarketsSubscriber.setAccountData(data.pubkey, data);
174
+ this.spotMarketsSubscriber.setAccountData(data.pubkey.toBase58(), data);
175
175
  }
176
176
  await this.spotMarketsSubscriber.subscribe(spotMarketPubkeys, (_accountId, data) => {
177
177
  this.eventEmitter.emit('spotMarketAccountUpdate', data);
@@ -216,7 +216,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
216
216
  });
217
217
  for (const data of this.initialOraclePriceData.entries()) {
218
218
  const { publicKey } = (0, oracleId_1.getPublicKeyAndSourceFromOracleId)(data[0]);
219
- this.oracleMultiSubscriber.setAccountData(publicKey, data[1]);
219
+ this.oracleMultiSubscriber.setAccountData(publicKey.toBase58(), data[1]);
220
220
  }
221
221
  await this.oracleMultiSubscriber.subscribe(oraclePubkeys, (accountId, data) => {
222
222
  const source = pubkeyToSource.get(accountId.toBase58());
@@ -22,7 +22,7 @@ export declare class grpcMultiAccountSubscriber<T> {
22
22
  private dataMap;
23
23
  private constructor();
24
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
- setAccountData(accountPubkey: PublicKey, data: T, slot?: number): void;
25
+ setAccountData(accountPubkey: string, data: T, slot?: number): void;
26
26
  getAccountData(accountPubkey: string): DataAndSlot<T> | undefined;
27
27
  getAccountDataMap(): Map<string, DataAndSlot<T>>;
28
28
  subscribe(accounts: PublicKey[], onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer) => void): 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,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIrD,OAAO,EACN,MAAM,EAMN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAU9D,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,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,EAChB,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,CAAC,EACrD,SAAS,CAAC,EAAE,SAAS,EACrB,UAAU,CAAC,EAAE,MAAM,EACnB,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GACjC,OAAO,CAAC,0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S,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiCjD,cAAc,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAmCpD,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IA4ClC,OAAO,CAAC,UAAU;IAelB,OAAO,CAAC,UAAU;CAIlB"}
@@ -57,7 +57,7 @@ class grpcMultiAccountSubscriber {
57
57
  return new grpcMultiAccountSubscriber(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe);
58
58
  }
59
59
  setAccountData(accountPubkey, data, slot) {
60
- this.dataMap.set(accountPubkey.toBase58(), { data, slot });
60
+ this.dataMap.set(accountPubkey, { data, slot });
61
61
  }
62
62
  getAccountData(accountPubkey) {
63
63
  return this.dataMap.get(accountPubkey);
@@ -73,7 +73,10 @@ class grpcMultiAccountSubscriber {
73
73
  for (const pk of accounts) {
74
74
  const key = pk.toBase58();
75
75
  this.subscribedAccounts.add(key);
76
- this.onChangeMap.set(key, (data, ctx, buffer) => onChange(new web3_js_1.PublicKey(key), data, ctx, buffer));
76
+ this.onChangeMap.set(key, (data, ctx, buffer) => {
77
+ this.setAccountData(key, data, ctx.slot);
78
+ onChange(new web3_js_1.PublicKey(key), data, ctx, buffer);
79
+ });
77
80
  }
78
81
  this.stream =
79
82
  (await this.client.subscribe());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.142.0-beta.8",
3
+ "version": "2.142.0-beta.9",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "module": "./lib/browser/index.js",
@@ -96,20 +96,29 @@ async function initializeGrpcDriftClientV2() {
96
96
  driftClient.accountSubscriber.eventEmitter.on(
97
97
  'perpMarketAccountUpdate',
98
98
  (data) => {
99
- console.log('Perp market account update:', decodeName(data.name));
100
- const perpMarketData = driftClient.getPerpMarketAccount(
101
- data.marketIndex
102
- );
103
99
  console.log(
104
- 'Perp market data market index:',
105
- perpMarketData?.marketIndex
106
- );
107
- const oracle = driftClient.getOracleDataForPerpMarket(data.marketIndex);
108
- const mmOracle = driftClient.getMMOracleDataForPerpMarket(
109
- data.marketIndex
100
+ 'Perp market account update:',
101
+ decodeName(data.name),
102
+ 'mmOracleSequenceId:',
103
+ data.amm.mmOracleSequenceId.toString()
110
104
  );
111
- console.log('Perp oracle price:', oracle.price.toString());
112
- console.log('Perp MM oracle price:', mmOracle.price.toString());
105
+ // const perpMarketData = driftClient.getPerpMarketAccount(
106
+ // data.marketIndex
107
+ // );
108
+ // console.log(
109
+ // 'Perp market data market index:',
110
+ // perpMarketData?.marketIndex
111
+ // );
112
+ // const oracle = driftClient.getOracleDataForPerpMarket(data.marketIndex);
113
+ // const mmOracle = driftClient.getMMOracleDataForPerpMarket(
114
+ // data.marketIndex
115
+ // );
116
+ // console.log('Perp oracle price:', oracle.price.toString());
117
+ // console.log('Perp MM oracle price:', mmOracle.price.toString());
118
+ // console.log(
119
+ // 'Perp MM oracle sequence id:',
120
+ // perpMarketData?.amm?.mmOracleSequenceId?.toString()
121
+ // );
113
122
  perpMarketUpdateCount++;
114
123
  if (
115
124
  perpMarketUpdateCount >= 10 &&
@@ -246,7 +246,7 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
246
246
  );
247
247
 
248
248
  for (const data of this.initialPerpMarketAccountData.values()) {
249
- this.perpMarketsSubscriber.setAccountData(data.pubkey, data);
249
+ this.perpMarketsSubscriber.setAccountData(data.pubkey.toBase58(), data);
250
250
  }
251
251
 
252
252
  await this.perpMarketsSubscriber.subscribe(
@@ -308,7 +308,7 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
308
308
  );
309
309
 
310
310
  for (const data of this.initialSpotMarketAccountData.values()) {
311
- this.spotMarketsSubscriber.setAccountData(data.pubkey, data);
311
+ this.spotMarketsSubscriber.setAccountData(data.pubkey.toBase58(), data);
312
312
  }
313
313
 
314
314
  await this.spotMarketsSubscriber.subscribe(
@@ -383,7 +383,7 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
383
383
 
384
384
  for (const data of this.initialOraclePriceData.entries()) {
385
385
  const { publicKey } = getPublicKeyAndSourceFromOracleId(data[0]);
386
- this.oracleMultiSubscriber.setAccountData(publicKey, data[1]);
386
+ this.oracleMultiSubscriber.setAccountData(publicKey.toBase58(), data[1]);
387
387
  }
388
388
 
389
389
  await this.oracleMultiSubscriber.subscribe(
@@ -93,8 +93,8 @@ export class grpcMultiAccountSubscriber<T> {
93
93
  );
94
94
  }
95
95
 
96
- setAccountData(accountPubkey: PublicKey, data: T, slot?: number): void {
97
- this.dataMap.set(accountPubkey.toBase58(), { data, slot });
96
+ setAccountData(accountPubkey: string, data: T, slot?: number): void {
97
+ this.dataMap.set(accountPubkey, { data, slot });
98
98
  }
99
99
 
100
100
  getAccountData(accountPubkey: string): DataAndSlot<T> | undefined {
@@ -122,9 +122,10 @@ export class grpcMultiAccountSubscriber<T> {
122
122
  for (const pk of accounts) {
123
123
  const key = pk.toBase58();
124
124
  this.subscribedAccounts.add(key);
125
- this.onChangeMap.set(key, (data, ctx, buffer) =>
126
- onChange(new PublicKey(key), data, ctx, buffer)
127
- );
125
+ this.onChangeMap.set(key, (data, ctx, buffer) => {
126
+ this.setAccountData(key, data, ctx.slot);
127
+ onChange(new PublicKey(key), data, ctx, buffer);
128
+ });
128
129
  }
129
130
 
130
131
  this.stream =