@drift-labs/sdk 2.63.0-beta.2 → 2.63.0-beta.4

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.63.0-beta.2
1
+ 2.63.0-beta.4
@@ -304,7 +304,7 @@ class DriftClient {
304
304
  * @param includeDelegates
305
305
  */
306
306
  async updateWallet(newWallet, subAccountIds, activeSubAccountId, includeDelegates, authoritySubaccountMap) {
307
- var _a, _b;
307
+ var _a, _b, _c;
308
308
  const newProvider = new anchor_1.AnchorProvider(this.connection,
309
309
  // @ts-ignore
310
310
  newWallet, this.opts);
@@ -337,18 +337,20 @@ class DriftClient {
337
337
  : subAccountIds
338
338
  ? new Map([[this.authority.toString(), subAccountIds]])
339
339
  : new Map();
340
+ /* Reset user stats account */
341
+ if ((_c = this.userStats) === null || _c === void 0 ? void 0 : _c.isSubscribed) {
342
+ await this.userStats.unsubscribe();
343
+ }
344
+ this.userStats = undefined;
345
+ this.userStats = new userStats_1.UserStats({
346
+ driftClient: this,
347
+ userStatsAccountPublicKey: this.getUserStatsAccountPublicKey(),
348
+ accountSubscription: this.userStatsAccountSubscriptionConfig,
349
+ });
350
+ await this.userStats.subscribe();
340
351
  let success = true;
341
352
  if (this.isSubscribed) {
342
353
  await Promise.all(this.unsubscribeUsers());
343
- if (this.userStats) {
344
- await this.userStats.unsubscribe();
345
- this.userStats = new userStats_1.UserStats({
346
- driftClient: this,
347
- userStatsAccountPublicKey: this.getUserStatsAccountPublicKey(),
348
- accountSubscription: this.userStatsAccountSubscriptionConfig,
349
- });
350
- await this.userStats.subscribe();
351
- }
352
354
  this.users.clear();
353
355
  success = await this.addAndSubscribeToUsers();
354
356
  }
@@ -1,4 +1,4 @@
1
- import { User, DriftClient, UserAccount, OrderRecord, WrappedEvent, DLOB } from '..';
1
+ import { User, DriftClient, UserAccount, OrderRecord, WrappedEvent, DLOB, UserSubscriptionConfig } from '..';
2
2
  import { PublicKey } from '@solana/web3.js';
3
3
  import { UserAccountFilterCriteria as UserFilterCriteria, UserMapConfig } from './userMapConfig';
4
4
  export interface UserMapInterface {
@@ -31,7 +31,7 @@ export declare class UserMap implements UserMapInterface {
31
31
  */
32
32
  constructor(config: UserMapConfig);
33
33
  subscribe(): Promise<void>;
34
- addPubkey(userAccountPublicKey: PublicKey, userAccount?: UserAccount, slot?: number): Promise<void>;
34
+ addPubkey(userAccountPublicKey: PublicKey, userAccount?: UserAccount, slot?: number, accountSubscription?: UserSubscriptionConfig): Promise<void>;
35
35
  has(key: string): boolean;
36
36
  /**
37
37
  * gets the User for a particular userAccountPublicKey, if no User exists, undefined is returned
@@ -44,7 +44,7 @@ export declare class UserMap implements UserMapInterface {
44
44
  * @param key userAccountPublicKey to get User for
45
45
  * @returns User
46
46
  */
47
- mustGet(key: string): Promise<User>;
47
+ mustGet(key: string, accountSubscription?: UserSubscriptionConfig): Promise<User>;
48
48
  /**
49
49
  * gets the Authority for a particular userAccountPublicKey, if no User exists, undefined is returned
50
50
  * @param key userAccountPublicKey to get User for
@@ -72,11 +72,11 @@ class UserMap {
72
72
  }
73
73
  await this.subscription.subscribe();
74
74
  }
75
- async addPubkey(userAccountPublicKey, userAccount, slot) {
75
+ async addPubkey(userAccountPublicKey, userAccount, slot, accountSubscription) {
76
76
  const user = new __1.User({
77
77
  driftClient: this.driftClient,
78
78
  userAccountPublicKey,
79
- accountSubscription: {
79
+ accountSubscription: accountSubscription !== null && accountSubscription !== void 0 ? accountSubscription : {
80
80
  type: 'custom',
81
81
  userAccountSubscriber: new __1.OneShotUserAccountSubscriber(this.driftClient.program, userAccountPublicKey, userAccount, slot, this.commitment),
82
82
  },
@@ -100,9 +100,9 @@ class UserMap {
100
100
  * @param key userAccountPublicKey to get User for
101
101
  * @returns User
102
102
  */
103
- async mustGet(key) {
103
+ async mustGet(key, accountSubscription) {
104
104
  if (!this.has(key)) {
105
- await this.addPubkey(new web3_js_1.PublicKey(key));
105
+ await this.addPubkey(new web3_js_1.PublicKey(key), undefined, undefined, accountSubscription);
106
106
  }
107
107
  const user = this.userMap.get(key);
108
108
  return user;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.63.0-beta.2",
3
+ "version": "2.63.0-beta.4",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -586,23 +586,25 @@ export class DriftClient {
586
586
  ? new Map([[this.authority.toString(), subAccountIds]])
587
587
  : new Map<string, number[]>();
588
588
 
589
- let success = true;
589
+ /* Reset user stats account */
590
+ if (this.userStats?.isSubscribed) {
591
+ await this.userStats.unsubscribe();
592
+ }
590
593
 
591
- if (this.isSubscribed) {
592
- await Promise.all(this.unsubscribeUsers());
594
+ this.userStats = undefined;
593
595
 
594
- if (this.userStats) {
595
- await this.userStats.unsubscribe();
596
+ this.userStats = new UserStats({
597
+ driftClient: this,
598
+ userStatsAccountPublicKey: this.getUserStatsAccountPublicKey(),
599
+ accountSubscription: this.userStatsAccountSubscriptionConfig,
600
+ });
596
601
 
597
- this.userStats = new UserStats({
598
- driftClient: this,
599
- userStatsAccountPublicKey: this.getUserStatsAccountPublicKey(),
600
- accountSubscription: this.userStatsAccountSubscriptionConfig,
601
- });
602
+ await this.userStats.subscribe();
602
603
 
603
- await this.userStats.subscribe();
604
- }
604
+ let success = true;
605
605
 
606
+ if (this.isSubscribed) {
607
+ await Promise.all(this.unsubscribeUsers());
606
608
  this.users.clear();
607
609
  success = await this.addAndSubscribeToUsers();
608
610
  }
@@ -15,6 +15,7 @@ import {
15
15
  DLOB,
16
16
  OneShotUserAccountSubscriber,
17
17
  BN,
18
+ UserSubscriptionConfig,
18
19
  } from '..';
19
20
 
20
21
  import {
@@ -131,12 +132,13 @@ export class UserMap implements UserMapInterface {
131
132
  public async addPubkey(
132
133
  userAccountPublicKey: PublicKey,
133
134
  userAccount?: UserAccount,
134
- slot?: number
135
+ slot?: number,
136
+ accountSubscription?: UserSubscriptionConfig
135
137
  ) {
136
138
  const user = new User({
137
139
  driftClient: this.driftClient,
138
140
  userAccountPublicKey,
139
- accountSubscription: {
141
+ accountSubscription: accountSubscription ?? {
140
142
  type: 'custom',
141
143
  userAccountSubscriber: new OneShotUserAccountSubscriber(
142
144
  this.driftClient.program,
@@ -169,9 +171,17 @@ export class UserMap implements UserMapInterface {
169
171
  * @param key userAccountPublicKey to get User for
170
172
  * @returns User
171
173
  */
172
- public async mustGet(key: string): Promise<User> {
174
+ public async mustGet(
175
+ key: string,
176
+ accountSubscription?: UserSubscriptionConfig
177
+ ): Promise<User> {
173
178
  if (!this.has(key)) {
174
- await this.addPubkey(new PublicKey(key));
179
+ await this.addPubkey(
180
+ new PublicKey(key),
181
+ undefined,
182
+ undefined,
183
+ accountSubscription
184
+ );
175
185
  }
176
186
  const user = this.userMap.get(key);
177
187
  return user;