@drift-labs/sdk 2.141.0-beta.4 → 2.141.0-beta.6

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.
Files changed (41) hide show
  1. package/VERSION +1 -1
  2. package/lib/browser/accounts/basicUserStatsAccountSubscriber.d.ts +27 -0
  3. package/lib/browser/accounts/basicUserStatsAccountSubscriber.js +38 -0
  4. package/lib/browser/accounts/oneShotUserStatsAccountSubscriber.d.ts +18 -0
  5. package/lib/browser/accounts/oneShotUserStatsAccountSubscriber.js +48 -0
  6. package/lib/browser/constants/spotMarkets.js +10 -0
  7. package/lib/browser/driftClient.js +1 -1
  8. package/lib/browser/index.d.ts +1 -0
  9. package/lib/browser/index.js +1 -0
  10. package/lib/browser/userStats.js +6 -1
  11. package/lib/browser/userStatsConfig.d.ts +2 -1
  12. package/lib/browser/wallet.d.ts +5 -0
  13. package/lib/browser/wallet.js +15 -1
  14. package/lib/node/accounts/basicUserStatsAccountSubscriber.d.ts +28 -0
  15. package/lib/node/accounts/basicUserStatsAccountSubscriber.d.ts.map +1 -0
  16. package/lib/node/accounts/basicUserStatsAccountSubscriber.js +38 -0
  17. package/lib/node/accounts/oneShotUserStatsAccountSubscriber.d.ts +19 -0
  18. package/lib/node/accounts/oneShotUserStatsAccountSubscriber.d.ts.map +1 -0
  19. package/lib/node/accounts/oneShotUserStatsAccountSubscriber.js +48 -0
  20. package/lib/node/constants/spotMarkets.d.ts.map +1 -1
  21. package/lib/node/constants/spotMarkets.js +10 -0
  22. package/lib/node/driftClient.js +1 -1
  23. package/lib/node/index.d.ts +1 -0
  24. package/lib/node/index.d.ts.map +1 -1
  25. package/lib/node/index.js +1 -0
  26. package/lib/node/userStats.d.ts.map +1 -1
  27. package/lib/node/userStats.js +6 -1
  28. package/lib/node/userStatsConfig.d.ts +2 -1
  29. package/lib/node/userStatsConfig.d.ts.map +1 -1
  30. package/lib/node/wallet.d.ts +5 -0
  31. package/lib/node/wallet.d.ts.map +1 -1
  32. package/lib/node/wallet.js +15 -1
  33. package/package.json +1 -1
  34. package/src/accounts/basicUserStatsAccountSubscriber.ts +65 -0
  35. package/src/accounts/oneShotUserStatsAccountSubscriber.ts +69 -0
  36. package/src/constants/spotMarkets.ts +10 -0
  37. package/src/driftClient.ts +1 -1
  38. package/src/index.ts +1 -0
  39. package/src/userStats.ts +6 -1
  40. package/src/userStatsConfig.ts +2 -1
  41. package/src/wallet.ts +11 -0
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.141.0-beta.4
1
+ 2.141.0-beta.6
@@ -0,0 +1,27 @@
1
+ /// <reference types="node" />
2
+ import { DataAndSlot, UserStatsAccountEvents, UserStatsAccountSubscriber } from './types';
3
+ import { PublicKey } from '@solana/web3.js';
4
+ import StrictEventEmitter from 'strict-event-emitter-types';
5
+ import { EventEmitter } from 'events';
6
+ import { UserStatsAccount } from '../types';
7
+ /**
8
+ * Basic implementation of UserStatsAccountSubscriber. It will only take in UserStatsAccount
9
+ * data during initialization and will not fetch or subscribe to updates.
10
+ */
11
+ export declare class BasicUserStatsAccountSubscriber implements UserStatsAccountSubscriber {
12
+ isSubscribed: boolean;
13
+ eventEmitter: StrictEventEmitter<EventEmitter, UserStatsAccountEvents>;
14
+ userStatsAccountPublicKey: PublicKey;
15
+ callbackId?: string;
16
+ errorCallbackId?: string;
17
+ userStats: DataAndSlot<UserStatsAccount>;
18
+ constructor(userStatsAccountPublicKey: PublicKey, data?: UserStatsAccount, slot?: number);
19
+ subscribe(_userStatsAccount?: UserStatsAccount): Promise<boolean>;
20
+ addToAccountLoader(): Promise<void>;
21
+ fetch(): Promise<void>;
22
+ doesAccountExist(): boolean;
23
+ unsubscribe(): Promise<void>;
24
+ assertIsSubscribed(): void;
25
+ getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount>;
26
+ updateData(userStatsAccount: UserStatsAccount, slot: number): void;
27
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BasicUserStatsAccountSubscriber = void 0;
4
+ const events_1 = require("events");
5
+ /**
6
+ * Basic implementation of UserStatsAccountSubscriber. It will only take in UserStatsAccount
7
+ * data during initialization and will not fetch or subscribe to updates.
8
+ */
9
+ class BasicUserStatsAccountSubscriber {
10
+ constructor(userStatsAccountPublicKey, data, slot) {
11
+ this.isSubscribed = true;
12
+ this.eventEmitter = new events_1.EventEmitter();
13
+ this.userStatsAccountPublicKey = userStatsAccountPublicKey;
14
+ this.userStats = { data, slot };
15
+ }
16
+ async subscribe(_userStatsAccount) {
17
+ return true;
18
+ }
19
+ async addToAccountLoader() { }
20
+ async fetch() { }
21
+ doesAccountExist() {
22
+ return this.userStats !== undefined;
23
+ }
24
+ async unsubscribe() { }
25
+ assertIsSubscribed() { }
26
+ getUserStatsAccountAndSlot() {
27
+ return this.userStats;
28
+ }
29
+ updateData(userStatsAccount, slot) {
30
+ var _a;
31
+ if (!this.userStats || slot >= ((_a = this.userStats.slot) !== null && _a !== void 0 ? _a : 0)) {
32
+ this.userStats = { data: userStatsAccount, slot };
33
+ this.eventEmitter.emit('userStatsAccountUpdate', userStatsAccount);
34
+ this.eventEmitter.emit('update');
35
+ }
36
+ }
37
+ }
38
+ exports.BasicUserStatsAccountSubscriber = BasicUserStatsAccountSubscriber;
@@ -0,0 +1,18 @@
1
+ import { Commitment, PublicKey } from '@solana/web3.js';
2
+ import { UserStatsAccount } from '../types';
3
+ import { BasicUserStatsAccountSubscriber } from './basicUserStatsAccountSubscriber';
4
+ import { Program } from '@coral-xyz/anchor';
5
+ import { UserStatsAccountSubscriber } from './types';
6
+ /**
7
+ * Simple implementation of UserStatsAccountSubscriber. It will fetch the UserStatsAccount
8
+ * data on subscribe (or call to fetch) if no account data is provided on init.
9
+ * Expect to use only 1 RPC call unless you call fetch repeatedly.
10
+ */
11
+ export declare class OneShotUserStatsAccountSubscriber extends BasicUserStatsAccountSubscriber implements UserStatsAccountSubscriber {
12
+ program: Program;
13
+ commitment: Commitment;
14
+ constructor(program: Program, userStatsAccountPublicKey: PublicKey, data?: UserStatsAccount, slot?: number, commitment?: Commitment);
15
+ subscribe(userStatsAccount?: UserStatsAccount): Promise<boolean>;
16
+ fetchIfUnloaded(): Promise<void>;
17
+ fetch(): Promise<void>;
18
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OneShotUserStatsAccountSubscriber = void 0;
4
+ const basicUserStatsAccountSubscriber_1 = require("./basicUserStatsAccountSubscriber");
5
+ /**
6
+ * Simple implementation of UserStatsAccountSubscriber. It will fetch the UserStatsAccount
7
+ * data on subscribe (or call to fetch) if no account data is provided on init.
8
+ * Expect to use only 1 RPC call unless you call fetch repeatedly.
9
+ */
10
+ class OneShotUserStatsAccountSubscriber extends basicUserStatsAccountSubscriber_1.BasicUserStatsAccountSubscriber {
11
+ constructor(program, userStatsAccountPublicKey, data, slot, commitment) {
12
+ super(userStatsAccountPublicKey, data, slot);
13
+ this.program = program;
14
+ this.commitment = commitment !== null && commitment !== void 0 ? commitment : 'confirmed';
15
+ }
16
+ async subscribe(userStatsAccount) {
17
+ if (userStatsAccount) {
18
+ this.userStats = { data: userStatsAccount, slot: this.userStats.slot };
19
+ return true;
20
+ }
21
+ await this.fetchIfUnloaded();
22
+ if (this.doesAccountExist()) {
23
+ this.eventEmitter.emit('update');
24
+ }
25
+ return true;
26
+ }
27
+ async fetchIfUnloaded() {
28
+ if (this.userStats.data === undefined) {
29
+ await this.fetch();
30
+ }
31
+ }
32
+ async fetch() {
33
+ var _a, _b;
34
+ try {
35
+ const dataAndContext = await this.program.account.userStats.fetchAndContext(this.userStatsAccountPublicKey, this.commitment);
36
+ if (dataAndContext.context.slot > ((_b = (_a = this.userStats) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : 0)) {
37
+ this.userStats = {
38
+ data: dataAndContext.data,
39
+ slot: dataAndContext.context.slot,
40
+ };
41
+ }
42
+ }
43
+ catch (e) {
44
+ console.error(`OneShotUserStatsAccountSubscriber.fetch() UserStatsAccount does not exist: ${e.message}`);
45
+ }
46
+ }
47
+ }
48
+ exports.OneShotUserStatsAccountSubscriber = OneShotUserStatsAccountSubscriber;
@@ -103,6 +103,16 @@ exports.DevnetSpotMarkets = [
103
103
  precisionExp: numericConstants_1.SIX,
104
104
  pythFeedId: '0x67e031d1723e5c89e4a826d80b2f3b41a91b05ef6122d523b8829a02e0f563aa',
105
105
  },
106
+ {
107
+ symbol: 'bSOL',
108
+ marketIndex: 8,
109
+ poolId: 2,
110
+ oracle: new web3_js_1.PublicKey('4wFrjUQHzRBc6qjVtMDbt28aEVgn6GaNiWR6vEff4KxR'),
111
+ oracleSource: types_1.OracleSource.Prelaunch,
112
+ mint: new web3_js_1.PublicKey('2vVfXmcWXEaFzp7iaTVnQ4y1gR41S6tJQQMo1S5asJyC'),
113
+ precision: new anchor_1.BN(10).pow(numericConstants_1.NINE),
114
+ precisionExp: numericConstants_1.NINE,
115
+ },
106
116
  ];
107
117
  exports.MainnetSpotMarkets = [
108
118
  {
@@ -520,7 +520,7 @@ class DriftClient {
520
520
  this.userStats = new userStats_1.UserStats({
521
521
  driftClient: this,
522
522
  userStatsAccountPublicKey: this.userStatsAccountPublicKey,
523
- accountSubscription: this.userAccountSubscriptionConfig,
523
+ accountSubscription: this.userStatsAccountSubscriptionConfig,
524
524
  });
525
525
  this.userStats.subscribe();
526
526
  }
@@ -28,6 +28,7 @@ export * from './accounts/pollingInsuranceFundStakeAccountSubscriber';
28
28
  export * from './accounts/pollingHighLeverageModeConfigAccountSubscriber';
29
29
  export * from './accounts/basicUserAccountSubscriber';
30
30
  export * from './accounts/oneShotUserAccountSubscriber';
31
+ export * from './accounts/oneShotUserStatsAccountSubscriber';
31
32
  export * from './accounts/types';
32
33
  export * from './addresses/pda';
33
34
  export * from './adminClient';
@@ -57,6 +57,7 @@ __exportStar(require("./accounts/pollingInsuranceFundStakeAccountSubscriber"), e
57
57
  __exportStar(require("./accounts/pollingHighLeverageModeConfigAccountSubscriber"), exports);
58
58
  __exportStar(require("./accounts/basicUserAccountSubscriber"), exports);
59
59
  __exportStar(require("./accounts/oneShotUserAccountSubscriber"), exports);
60
+ __exportStar(require("./accounts/oneShotUserStatsAccountSubscriber"), exports);
60
61
  __exportStar(require("./accounts/types"), exports);
61
62
  __exportStar(require("./addresses/pda"), exports);
62
63
  __exportStar(require("./adminClient"), exports);
@@ -31,8 +31,13 @@ class UserStats {
31
31
  logResubMessages: (_g = config.accountSubscription) === null || _g === void 0 ? void 0 : _g.logResubMessages,
32
32
  }, config.accountSubscription.commitment);
33
33
  }
34
+ else if (((_h = config.accountSubscription) === null || _h === void 0 ? void 0 : _h.type) === 'custom') {
35
+ this.accountSubscriber =
36
+ config.accountSubscription.userStatsAccountSubscriber;
37
+ }
34
38
  else {
35
- throw new Error(`Unknown user stats account subscription type: ${(_h = config.accountSubscription) === null || _h === void 0 ? void 0 : _h.type}`);
39
+ const exhaustiveCheck = config.accountSubscription;
40
+ throw new Error(`Unknown user stats account subscription type: ${exhaustiveCheck}`);
36
41
  }
37
42
  }
38
43
  async subscribe(userStatsAccount) {
@@ -1,7 +1,7 @@
1
1
  import { DriftClient } from './driftClient';
2
2
  import { Commitment, PublicKey } from '@solana/web3.js';
3
3
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
- import { GrpcConfigs } from './accounts/types';
4
+ import { GrpcConfigs, UserStatsAccountSubscriber } from './accounts/types';
5
5
  export type UserStatsConfig = {
6
6
  accountSubscription?: UserStatsSubscriptionConfig;
7
7
  driftClient: DriftClient;
@@ -17,6 +17,7 @@ export type UserStatsSubscriptionConfig = {
17
17
  accountLoader: BulkAccountLoader;
18
18
  } | {
19
19
  type: 'custom';
20
+ userStatsAccountSubscriber: UserStatsAccountSubscriber;
20
21
  } | {
21
22
  type: 'grpc';
22
23
  resubTimeoutMs?: number;
@@ -9,3 +9,8 @@ export declare class Wallet implements IWallet, IVersionedWallet {
9
9
  signAllVersionedTransactions(txs: VersionedTransaction[]): Promise<VersionedTransaction[]>;
10
10
  get publicKey(): PublicKey;
11
11
  }
12
+ export declare class WalletV2 extends Wallet {
13
+ readonly payer: Keypair;
14
+ constructor(payer: Keypair);
15
+ signMessage(message: Uint8Array): Promise<Uint8Array>;
16
+ }
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Wallet = void 0;
6
+ exports.WalletV2 = exports.Wallet = void 0;
7
+ const tweetnacl_1 = __importDefault(require("tweetnacl"));
4
8
  class Wallet {
5
9
  constructor(payer) {
6
10
  this.payer = payer;
@@ -30,3 +34,13 @@ class Wallet {
30
34
  }
31
35
  }
32
36
  exports.Wallet = Wallet;
37
+ class WalletV2 extends Wallet {
38
+ constructor(payer) {
39
+ super(payer);
40
+ this.payer = payer;
41
+ }
42
+ async signMessage(message) {
43
+ return Buffer.from(tweetnacl_1.default.sign.detached(message, this.payer.secretKey));
44
+ }
45
+ }
46
+ exports.WalletV2 = WalletV2;
@@ -0,0 +1,28 @@
1
+ /// <reference types="node" />
2
+ import { DataAndSlot, UserStatsAccountEvents, UserStatsAccountSubscriber } from './types';
3
+ import { PublicKey } from '@solana/web3.js';
4
+ import StrictEventEmitter from 'strict-event-emitter-types';
5
+ import { EventEmitter } from 'events';
6
+ import { UserStatsAccount } from '../types';
7
+ /**
8
+ * Basic implementation of UserStatsAccountSubscriber. It will only take in UserStatsAccount
9
+ * data during initialization and will not fetch or subscribe to updates.
10
+ */
11
+ export declare class BasicUserStatsAccountSubscriber implements UserStatsAccountSubscriber {
12
+ isSubscribed: boolean;
13
+ eventEmitter: StrictEventEmitter<EventEmitter, UserStatsAccountEvents>;
14
+ userStatsAccountPublicKey: PublicKey;
15
+ callbackId?: string;
16
+ errorCallbackId?: string;
17
+ userStats: DataAndSlot<UserStatsAccount>;
18
+ constructor(userStatsAccountPublicKey: PublicKey, data?: UserStatsAccount, slot?: number);
19
+ subscribe(_userStatsAccount?: UserStatsAccount): Promise<boolean>;
20
+ addToAccountLoader(): Promise<void>;
21
+ fetch(): Promise<void>;
22
+ doesAccountExist(): boolean;
23
+ unsubscribe(): Promise<void>;
24
+ assertIsSubscribed(): void;
25
+ getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount>;
26
+ updateData(userStatsAccount: UserStatsAccount, slot: number): void;
27
+ }
28
+ //# sourceMappingURL=basicUserStatsAccountSubscriber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basicUserStatsAccountSubscriber.d.ts","sourceRoot":"","sources":["../../../src/accounts/basicUserStatsAccountSubscriber.ts"],"names":[],"mappings":";AAAA,OAAO,EACN,WAAW,EACX,sBAAsB,EACtB,0BAA0B,EAC1B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C;;;GAGG;AACH,qBAAa,+BACZ,YAAW,0BAA0B;IAErC,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,kBAAkB,CAAC,YAAY,EAAE,sBAAsB,CAAC,CAAC;IACvE,yBAAyB,EAAE,SAAS,CAAC;IAErC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,SAAS,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAC;gBAGxC,yBAAyB,EAAE,SAAS,EACpC,IAAI,CAAC,EAAE,gBAAgB,EACvB,IAAI,CAAC,EAAE,MAAM;IAQR,SAAS,CAAC,iBAAiB,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAIjE,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAEnC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAE5B,gBAAgB,IAAI,OAAO;IAIrB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAElC,kBAAkB,IAAI,IAAI;IAEnB,0BAA0B,IAAI,WAAW,CAAC,gBAAgB,CAAC;IAI3D,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;CAOzE"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BasicUserStatsAccountSubscriber = void 0;
4
+ const events_1 = require("events");
5
+ /**
6
+ * Basic implementation of UserStatsAccountSubscriber. It will only take in UserStatsAccount
7
+ * data during initialization and will not fetch or subscribe to updates.
8
+ */
9
+ class BasicUserStatsAccountSubscriber {
10
+ constructor(userStatsAccountPublicKey, data, slot) {
11
+ this.isSubscribed = true;
12
+ this.eventEmitter = new events_1.EventEmitter();
13
+ this.userStatsAccountPublicKey = userStatsAccountPublicKey;
14
+ this.userStats = { data, slot };
15
+ }
16
+ async subscribe(_userStatsAccount) {
17
+ return true;
18
+ }
19
+ async addToAccountLoader() { }
20
+ async fetch() { }
21
+ doesAccountExist() {
22
+ return this.userStats !== undefined;
23
+ }
24
+ async unsubscribe() { }
25
+ assertIsSubscribed() { }
26
+ getUserStatsAccountAndSlot() {
27
+ return this.userStats;
28
+ }
29
+ updateData(userStatsAccount, slot) {
30
+ var _a;
31
+ if (!this.userStats || slot >= ((_a = this.userStats.slot) !== null && _a !== void 0 ? _a : 0)) {
32
+ this.userStats = { data: userStatsAccount, slot };
33
+ this.eventEmitter.emit('userStatsAccountUpdate', userStatsAccount);
34
+ this.eventEmitter.emit('update');
35
+ }
36
+ }
37
+ }
38
+ exports.BasicUserStatsAccountSubscriber = BasicUserStatsAccountSubscriber;
@@ -0,0 +1,19 @@
1
+ import { Commitment, PublicKey } from '@solana/web3.js';
2
+ import { UserStatsAccount } from '../types';
3
+ import { BasicUserStatsAccountSubscriber } from './basicUserStatsAccountSubscriber';
4
+ import { Program } from '@coral-xyz/anchor';
5
+ import { UserStatsAccountSubscriber } from './types';
6
+ /**
7
+ * Simple implementation of UserStatsAccountSubscriber. It will fetch the UserStatsAccount
8
+ * data on subscribe (or call to fetch) if no account data is provided on init.
9
+ * Expect to use only 1 RPC call unless you call fetch repeatedly.
10
+ */
11
+ export declare class OneShotUserStatsAccountSubscriber extends BasicUserStatsAccountSubscriber implements UserStatsAccountSubscriber {
12
+ program: Program;
13
+ commitment: Commitment;
14
+ constructor(program: Program, userStatsAccountPublicKey: PublicKey, data?: UserStatsAccount, slot?: number, commitment?: Commitment);
15
+ subscribe(userStatsAccount?: UserStatsAccount): Promise<boolean>;
16
+ fetchIfUnloaded(): Promise<void>;
17
+ fetch(): Promise<void>;
18
+ }
19
+ //# sourceMappingURL=oneShotUserStatsAccountSubscriber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oneShotUserStatsAccountSubscriber.d.ts","sourceRoot":"","sources":["../../../src/accounts/oneShotUserStatsAccountSubscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAErD;;;;GAIG;AACH,qBAAa,iCACZ,SAAQ,+BACR,YAAW,0BAA0B;IAErC,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,UAAU,CAAC;gBAGtB,OAAO,EAAE,OAAO,EAChB,yBAAyB,EAAE,SAAS,EACpC,IAAI,CAAC,EAAE,gBAAgB,EACvB,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,UAAU;IAOlB,SAAS,CAAC,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAahE,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAMhC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAmB5B"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OneShotUserStatsAccountSubscriber = void 0;
4
+ const basicUserStatsAccountSubscriber_1 = require("./basicUserStatsAccountSubscriber");
5
+ /**
6
+ * Simple implementation of UserStatsAccountSubscriber. It will fetch the UserStatsAccount
7
+ * data on subscribe (or call to fetch) if no account data is provided on init.
8
+ * Expect to use only 1 RPC call unless you call fetch repeatedly.
9
+ */
10
+ class OneShotUserStatsAccountSubscriber extends basicUserStatsAccountSubscriber_1.BasicUserStatsAccountSubscriber {
11
+ constructor(program, userStatsAccountPublicKey, data, slot, commitment) {
12
+ super(userStatsAccountPublicKey, data, slot);
13
+ this.program = program;
14
+ this.commitment = commitment !== null && commitment !== void 0 ? commitment : 'confirmed';
15
+ }
16
+ async subscribe(userStatsAccount) {
17
+ if (userStatsAccount) {
18
+ this.userStats = { data: userStatsAccount, slot: this.userStats.slot };
19
+ return true;
20
+ }
21
+ await this.fetchIfUnloaded();
22
+ if (this.doesAccountExist()) {
23
+ this.eventEmitter.emit('update');
24
+ }
25
+ return true;
26
+ }
27
+ async fetchIfUnloaded() {
28
+ if (this.userStats.data === undefined) {
29
+ await this.fetch();
30
+ }
31
+ }
32
+ async fetch() {
33
+ var _a, _b;
34
+ try {
35
+ const dataAndContext = await this.program.account.userStats.fetchAndContext(this.userStatsAccountPublicKey, this.commitment);
36
+ if (dataAndContext.context.slot > ((_b = (_a = this.userStats) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : 0)) {
37
+ this.userStats = {
38
+ data: dataAndContext.data,
39
+ slot: dataAndContext.context.slot,
40
+ };
41
+ }
42
+ }
43
+ catch (e) {
44
+ console.error(`OneShotUserStatsAccountSubscriber.fetch() UserStatsAccount does not exist: ${e.message}`);
45
+ }
46
+ }
47
+ }
48
+ exports.OneShotUserStatsAccountSubscriber = OneShotUserStatsAccountSubscriber;
@@ -1 +1 @@
1
- {"version":3,"file":"spotMarkets.d.ts","sourceRoot":"","sources":["../../../src/constants/spotMarkets.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAW5C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,MAAM,gBAAgB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE,EAAE,CAAC;IACd,YAAY,EAAE,EAAE,CAAC;IACjB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,aAAa,CAAC,EAAE,SAAS,CAAC;IAC1B,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,gBAAgB,WAE5B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,gBAAgB,EA2G/C,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,gBAAgB,EAizBhD,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE;KAAG,GAAG,IAAI,QAAQ,GAAG,gBAAgB,EAAE;CAGhE,CAAC"}
1
+ {"version":3,"file":"spotMarkets.d.ts","sourceRoot":"","sources":["../../../src/constants/spotMarkets.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAW5C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,MAAM,gBAAgB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE,EAAE,CAAC;IACd,YAAY,EAAE,EAAE,CAAC;IACjB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,aAAa,CAAC,EAAE,SAAS,CAAC;IAC1B,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,gBAAgB,WAE5B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,gBAAgB,EAqH/C,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,gBAAgB,EAizBhD,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE;KAAG,GAAG,IAAI,QAAQ,GAAG,gBAAgB,EAAE;CAGhE,CAAC"}
@@ -103,6 +103,16 @@ exports.DevnetSpotMarkets = [
103
103
  precisionExp: numericConstants_1.SIX,
104
104
  pythFeedId: '0x67e031d1723e5c89e4a826d80b2f3b41a91b05ef6122d523b8829a02e0f563aa',
105
105
  },
106
+ {
107
+ symbol: 'bSOL',
108
+ marketIndex: 8,
109
+ poolId: 2,
110
+ oracle: new web3_js_1.PublicKey('4wFrjUQHzRBc6qjVtMDbt28aEVgn6GaNiWR6vEff4KxR'),
111
+ oracleSource: types_1.OracleSource.Prelaunch,
112
+ mint: new web3_js_1.PublicKey('2vVfXmcWXEaFzp7iaTVnQ4y1gR41S6tJQQMo1S5asJyC'),
113
+ precision: new anchor_1.BN(10).pow(numericConstants_1.NINE),
114
+ precisionExp: numericConstants_1.NINE,
115
+ },
106
116
  ];
107
117
  exports.MainnetSpotMarkets = [
108
118
  {
@@ -520,7 +520,7 @@ class DriftClient {
520
520
  this.userStats = new userStats_1.UserStats({
521
521
  driftClient: this,
522
522
  userStatsAccountPublicKey: this.userStatsAccountPublicKey,
523
- accountSubscription: this.userAccountSubscriptionConfig,
523
+ accountSubscription: this.userStatsAccountSubscriptionConfig,
524
524
  });
525
525
  this.userStats.subscribe();
526
526
  }
@@ -28,6 +28,7 @@ export * from './accounts/pollingInsuranceFundStakeAccountSubscriber';
28
28
  export * from './accounts/pollingHighLeverageModeConfigAccountSubscriber';
29
29
  export * from './accounts/basicUserAccountSubscriber';
30
30
  export * from './accounts/oneShotUserAccountSubscriber';
31
+ export * from './accounts/oneShotUserStatsAccountSubscriber';
31
32
  export * from './accounts/types';
32
33
  export * from './addresses/pda';
33
34
  export * from './adminClient';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,IAAI,MAAM,qBAAqB,CAAC;AAEvC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,kDAAkD,CAAC;AACjE,cAAc,yDAAyD,CAAC;AACxE,c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AAuC,CAAC;AACtD,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4CAA4C,CAAC;AAC3D,cAAc,aAAa,CAAC;AAE5B,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC"}
package/lib/node/index.js CHANGED
@@ -57,6 +57,7 @@ __exportStar(require("./accounts/pollingInsuranceFundStakeAccountSubscriber"), e
57
57
  __exportStar(require("./accounts/pollingHighLeverageModeConfigAccountSubscriber"), exports);
58
58
  __exportStar(require("./accounts/basicUserAccountSubscriber"), exports);
59
59
  __exportStar(require("./accounts/oneShotUserAccountSubscriber"), exports);
60
+ __exportStar(require("./accounts/oneShotUserStatsAccountSubscriber"), exports);
60
61
  __exportStar(require("./accounts/types"), exports);
61
62
  __exportStar(require("./addresses/pda"), exports);
62
63
  __exportStar(require("./adminClient"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"userStats.d.ts","sourceRoot":"","sources":["../../src/userStats.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,YAAY,EAAqB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAY5E,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAGvC,qBAAa,SAAS;IACrB,WAAW,EAAE,WAAW,CAAC;IACzB,yBAAyB,EAAE,SAAS,CAAC;IACrC,iBAAiB,EAAE,0BAA0B,CAAC;IAC9C,YAAY,EAAE,OAAO,CAAC;gBAEH,MAAM,EAAE,eAAe;IAoC7B,SAAS,CACrB,gBAAgB,CAAC,EAAE,gBAAgB,GACjC,OAAO,CAAC,OAAO,CAAC;IAON,aAAa,I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UAAO,GACrB,EAAE;IAuDE,eAAe,IAAI,YAAY,GAAG,SAAS;WAkBpC,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM;CAOlE"}
@@ -31,8 +31,13 @@ class UserStats {
31
31
  logResubMessages: (_g = config.accountSubscription) === null || _g === void 0 ? void 0 : _g.logResubMessages,
32
32
  }, config.accountSubscription.commitment);
33
33
  }
34
+ else if (((_h = config.accountSubscription) === null || _h === void 0 ? void 0 : _h.type) === 'custom') {
35
+ this.accountSubscriber =
36
+ config.accountSubscription.userStatsAccountSubscriber;
37
+ }
34
38
  else {
35
- throw new Error(`Unknown user stats account subscription type: ${(_h = config.accountSubscription) === null || _h === void 0 ? void 0 : _h.type}`);
39
+ const exhaustiveCheck = config.accountSubscription;
40
+ throw new Error(`Unknown user stats account subscription type: ${exhaustiveCheck}`);
36
41
  }
37
42
  }
38
43
  async subscribe(userStatsAccount) {
@@ -1,7 +1,7 @@
1
1
  import { DriftClient } from './driftClient';
2
2
  import { Commitment, PublicKey } from '@solana/web3.js';
3
3
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
- import { GrpcConfigs } from './accounts/types';
4
+ import { GrpcConfigs, UserStatsAccountSubscriber } from './accounts/types';
5
5
  export type UserStatsConfig = {
6
6
  accountSubscription?: UserStatsSubscriptionConfig;
7
7
  driftClient: DriftClient;
@@ -17,6 +17,7 @@ export type UserStatsSubscriptionConfig = {
17
17
  accountLoader: BulkAccountLoader;
18
18
  } | {
19
19
  type: 'custom';
20
+ userStatsAccountSubscriber: UserStatsAccountSubscriber;
20
21
  } | {
21
22
  type: 'grpc';
22
23
  resubTimeoutMs?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"userStatsConfig.d.ts","sourceRoot":"","sources":["../../src/userStatsConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC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AAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,UAAU,CAAC;CACvB,GACD;IACA,IAAI,EAAE,SAAS,CAAC;IAChB,aAAa,EAAE,iBAAiB,CAAC;CAChC,GACD;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,0BAA0B,EAAE,0BAA0B,CAAC;CACtD,GACD;IACA,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,WAAW,EAAE,WAAW,CAAC;CACxB,CAAC"}
@@ -9,4 +9,9 @@ export declare class Wallet implements IWallet, IVersionedWallet {
9
9
  signAllVersionedTransactions(txs: VersionedTransaction[]): Promise<VersionedTransaction[]>;
10
10
  get publicKey(): PublicKey;
11
11
  }
12
+ export declare class WalletV2 extends Wallet {
13
+ readonly payer: Keypair;
14
+ constructor(payer: Keypair);
15
+ signMessage(message: Uint8Array): Promise<Uint8Array>;
16
+ }
12
17
  //# sourceMappingURL=wallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,OAAO,EACP,SAAS,EACT,WAAW,EACX,oBAAoB,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEpD,qBAAa,MAAO,YAAW,OAAO,EAAE,gBAAgB;IAC3C,QAAQ,CAAC,KAAK,EAAE,OAAO;gBAAd,KAAK,EAAE,OAAO;IAE7B,eAAe,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAKtD,wBAAwB,CAC7B,EAAE,EAAE,oBAAoB,GACtB,OAAO,CAAC,oBAAoB,CAAC;IAK1B,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAO/D,4BAA4B,CACjC,GAAG,EAAE,oBAAoB,EAAE,GACzB,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAOlC,IAAI,SAAS,IAAI,SAAS,CAEzB;CACD"}
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,OAAO,EACP,SAAS,EACT,WAAW,EACX,oBAAoB,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGpD,qBAAa,MAAO,YAAW,OAAO,EAAE,gBAAgB;IAC3C,QAAQ,CAAC,KAAK,EAAE,OAAO;gBAAd,KAAK,EAAE,OAAO;IAE7B,eAAe,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAKtD,wBAAwB,CAC7B,EAAE,EAAE,oBAAoB,GACtB,OAAO,CAAC,oBAAoB,CAAC;IAK1B,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAO/D,4BAA4B,CACjC,GAAG,EAAE,oBAAoB,EAAE,GACzB,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAOlC,IAAI,SAAS,IAAI,SAAS,CAEzB;CACD;AAED,qBAAa,QAAS,SAAQ,MAAM;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO;gBAAd,KAAK,EAAE,OAAO;IAI7B,WAAW,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;CAG3D"}
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Wallet = void 0;
6
+ exports.WalletV2 = exports.Wallet = void 0;
7
+ const tweetnacl_1 = __importDefault(require("tweetnacl"));
4
8
  class Wallet {
5
9
  constructor(payer) {
6
10
  this.payer = payer;
@@ -30,3 +34,13 @@ class Wallet {
30
34
  }
31
35
  }
32
36
  exports.Wallet = Wallet;
37
+ class WalletV2 extends Wallet {
38
+ constructor(payer) {
39
+ super(payer);
40
+ this.payer = payer;
41
+ }
42
+ async signMessage(message) {
43
+ return Buffer.from(tweetnacl_1.default.sign.detached(message, this.payer.secretKey));
44
+ }
45
+ }
46
+ exports.WalletV2 = WalletV2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.141.0-beta.4",
3
+ "version": "2.141.0-beta.6",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "browser": "./lib/browser/index.js",
@@ -0,0 +1,65 @@
1
+ import {
2
+ DataAndSlot,
3
+ UserStatsAccountEvents,
4
+ UserStatsAccountSubscriber,
5
+ } from './types';
6
+ import { PublicKey } from '@solana/web3.js';
7
+ import StrictEventEmitter from 'strict-event-emitter-types';
8
+ import { EventEmitter } from 'events';
9
+ import { UserStatsAccount } from '../types';
10
+
11
+ /**
12
+ * Basic implementation of UserStatsAccountSubscriber. It will only take in UserStatsAccount
13
+ * data during initialization and will not fetch or subscribe to updates.
14
+ */
15
+ export class BasicUserStatsAccountSubscriber
16
+ implements UserStatsAccountSubscriber
17
+ {
18
+ isSubscribed: boolean;
19
+ eventEmitter: StrictEventEmitter<EventEmitter, UserStatsAccountEvents>;
20
+ userStatsAccountPublicKey: PublicKey;
21
+
22
+ callbackId?: string;
23
+ errorCallbackId?: string;
24
+
25
+ userStats: DataAndSlot<UserStatsAccount>;
26
+
27
+ public constructor(
28
+ userStatsAccountPublicKey: PublicKey,
29
+ data?: UserStatsAccount,
30
+ slot?: number
31
+ ) {
32
+ this.isSubscribed = true;
33
+ this.eventEmitter = new EventEmitter();
34
+ this.userStatsAccountPublicKey = userStatsAccountPublicKey;
35
+ this.userStats = { data, slot };
36
+ }
37
+
38
+ async subscribe(_userStatsAccount?: UserStatsAccount): Promise<boolean> {
39
+ return true;
40
+ }
41
+
42
+ async addToAccountLoader(): Promise<void> {}
43
+
44
+ async fetch(): Promise<void> {}
45
+
46
+ doesAccountExist(): boolean {
47
+ return this.userStats !== undefined;
48
+ }
49
+
50
+ async unsubscribe(): Promise<void> {}
51
+
52
+ assertIsSubscribed(): void {}
53
+
54
+ public getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount> {
55
+ return this.userStats;
56
+ }
57
+
58
+ public updateData(userStatsAccount: UserStatsAccount, slot: number): void {
59
+ if (!this.userStats || slot >= (this.userStats.slot ?? 0)) {
60
+ this.userStats = { data: userStatsAccount, slot };
61
+ this.eventEmitter.emit('userStatsAccountUpdate', userStatsAccount);
62
+ this.eventEmitter.emit('update');
63
+ }
64
+ }
65
+ }
@@ -0,0 +1,69 @@
1
+ import { Commitment, PublicKey } from '@solana/web3.js';
2
+ import { UserStatsAccount } from '../types';
3
+ import { BasicUserStatsAccountSubscriber } from './basicUserStatsAccountSubscriber';
4
+ import { Program } from '@coral-xyz/anchor';
5
+ import { UserStatsAccountSubscriber } from './types';
6
+
7
+ /**
8
+ * Simple implementation of UserStatsAccountSubscriber. It will fetch the UserStatsAccount
9
+ * data on subscribe (or call to fetch) if no account data is provided on init.
10
+ * Expect to use only 1 RPC call unless you call fetch repeatedly.
11
+ */
12
+ export class OneShotUserStatsAccountSubscriber
13
+ extends BasicUserStatsAccountSubscriber
14
+ implements UserStatsAccountSubscriber
15
+ {
16
+ program: Program;
17
+ commitment: Commitment;
18
+
19
+ public constructor(
20
+ program: Program,
21
+ userStatsAccountPublicKey: PublicKey,
22
+ data?: UserStatsAccount,
23
+ slot?: number,
24
+ commitment?: Commitment
25
+ ) {
26
+ super(userStatsAccountPublicKey, data, slot);
27
+ this.program = program;
28
+ this.commitment = commitment ?? 'confirmed';
29
+ }
30
+
31
+ async subscribe(userStatsAccount?: UserStatsAccount): Promise<boolean> {
32
+ if (userStatsAccount) {
33
+ this.userStats = { data: userStatsAccount, slot: this.userStats.slot };
34
+ return true;
35
+ }
36
+
37
+ await this.fetchIfUnloaded();
38
+ if (this.doesAccountExist()) {
39
+ this.eventEmitter.emit('update');
40
+ }
41
+ return true;
42
+ }
43
+
44
+ async fetchIfUnloaded(): Promise<void> {
45
+ if (this.userStats.data === undefined) {
46
+ await this.fetch();
47
+ }
48
+ }
49
+
50
+ async fetch(): Promise<void> {
51
+ try {
52
+ const dataAndContext =
53
+ await this.program.account.userStats.fetchAndContext(
54
+ this.userStatsAccountPublicKey,
55
+ this.commitment
56
+ );
57
+ if (dataAndContext.context.slot > (this.userStats?.slot ?? 0)) {
58
+ this.userStats = {
59
+ data: dataAndContext.data as UserStatsAccount,
60
+ slot: dataAndContext.context.slot,
61
+ };
62
+ }
63
+ } catch (e) {
64
+ console.error(
65
+ `OneShotUserStatsAccountSubscriber.fetch() UserStatsAccount does not exist: ${e.message}`
66
+ );
67
+ }
68
+ }
69
+ }
@@ -141,6 +141,16 @@ export const DevnetSpotMarkets: SpotMarketConfig[] = [
141
141
  pythFeedId:
142
142
  '0x67e031d1723e5c89e4a826d80b2f3b41a91b05ef6122d523b8829a02e0f563aa',
143
143
  },
144
+ {
145
+ symbol: 'bSOL',
146
+ marketIndex: 8,
147
+ poolId: 2,
148
+ oracle: new PublicKey('4wFrjUQHzRBc6qjVtMDbt28aEVgn6GaNiWR6vEff4KxR'),
149
+ oracleSource: OracleSource.Prelaunch,
150
+ mint: new PublicKey('2vVfXmcWXEaFzp7iaTVnQ4y1gR41S6tJQQMo1S5asJyC'),
151
+ precision: new BN(10).pow(NINE),
152
+ precisionExp: NINE,
153
+ },
144
154
  ];
145
155
 
146
156
  export const MainnetSpotMarkets: SpotMarketConfig[] = [
@@ -933,7 +933,7 @@ export class DriftClient {
933
933
  this.userStats = new UserStats({
934
934
  driftClient: this,
935
935
  userStatsAccountPublicKey: this.userStatsAccountPublicKey,
936
- accountSubscription: this.userAccountSubscriptionConfig,
936
+ accountSubscription: this.userStatsAccountSubscriptionConfig,
937
937
  });
938
938
 
939
939
  this.userStats.subscribe();
package/src/index.ts CHANGED
@@ -29,6 +29,7 @@ export * from './accounts/pollingInsuranceFundStakeAccountSubscriber';
29
29
  export * from './accounts/pollingHighLeverageModeConfigAccountSubscriber';
30
30
  export * from './accounts/basicUserAccountSubscriber';
31
31
  export * from './accounts/oneShotUserAccountSubscriber';
32
+ export * from './accounts/oneShotUserStatsAccountSubscriber';
32
33
  export * from './accounts/types';
33
34
  export * from './addresses/pda';
34
35
  export * from './adminClient';
package/src/userStats.ts CHANGED
@@ -54,9 +54,14 @@ export class UserStats {
54
54
  },
55
55
  config.accountSubscription.commitment
56
56
  );
57
+ } else if (config.accountSubscription?.type === 'custom') {
58
+ this.accountSubscriber =
59
+ config.accountSubscription.userStatsAccountSubscriber;
57
60
  } else {
61
+ const exhaustiveCheck: never = config.accountSubscription;
62
+
58
63
  throw new Error(
59
- `Unknown user stats account subscription type: ${config.accountSubscription?.type}`
64
+ `Unknown user stats account subscription type: ${exhaustiveCheck}`
60
65
  );
61
66
  }
62
67
  }
@@ -1,7 +1,7 @@
1
1
  import { DriftClient } from './driftClient';
2
2
  import { Commitment, PublicKey } from '@solana/web3.js';
3
3
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
- import { GrpcConfigs } from './accounts/types';
4
+ import { GrpcConfigs, UserStatsAccountSubscriber } from './accounts/types';
5
5
 
6
6
  export type UserStatsConfig = {
7
7
  accountSubscription?: UserStatsSubscriptionConfig;
@@ -22,6 +22,7 @@ export type UserStatsSubscriptionConfig =
22
22
  }
23
23
  | {
24
24
  type: 'custom';
25
+ userStatsAccountSubscriber: UserStatsAccountSubscriber;
25
26
  }
26
27
  | {
27
28
  type: 'grpc';
package/src/wallet.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  VersionedTransaction,
6
6
  } from '@solana/web3.js';
7
7
  import { IWallet, IVersionedWallet } from './types';
8
+ import nacl from 'tweetnacl';
8
9
 
9
10
  export class Wallet implements IWallet, IVersionedWallet {
10
11
  constructor(readonly payer: Keypair) {}
@@ -41,3 +42,13 @@ export class Wallet implements IWallet, IVersionedWallet {
41
42
  return this.payer.publicKey;
42
43
  }
43
44
  }
45
+
46
+ export class WalletV2 extends Wallet {
47
+ constructor(readonly payer: Keypair) {
48
+ super(payer);
49
+ }
50
+
51
+ async signMessage(message: Uint8Array): Promise<Uint8Array> {
52
+ return Buffer.from(nacl.sign.detached(message, this.payer.secretKey));
53
+ }
54
+ }