@drift-labs/sdk 2.47.0-beta.0 → 2.47.0-beta.2

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.47.0-beta.0
1
+ 2.47.0-beta.2
@@ -2,7 +2,7 @@
2
2
  /// <reference types="node" />
3
3
  import { DataAndSlot, BufferAndSlot, AccountSubscriber } from './types';
4
4
  import { Program } from '@coral-xyz/anchor';
5
- import { AccountInfo, Context, PublicKey } from '@solana/web3.js';
5
+ import { AccountInfo, Commitment, Context, PublicKey } from '@solana/web3.js';
6
6
  export declare class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
7
7
  dataAndSlot?: DataAndSlot<T>;
8
8
  bufferAndSlot?: BufferAndSlot;
@@ -13,10 +13,11 @@ export declare class WebSocketAccountSubscriber<T> implements AccountSubscriber<
13
13
  onChange: (data: T) => void;
14
14
  listenerId?: number;
15
15
  resubTimeoutMs?: number;
16
+ commitment?: Commitment;
16
17
  isUnsubscribing: boolean;
17
18
  timeoutId?: NodeJS.Timeout;
18
19
  receivingData: boolean;
19
- constructor(accountName: string, program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => T, resubTimeoutMs?: number);
20
+ constructor(accountName: string, program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => T, resubTimeoutMs?: number, commitment?: Commitment);
20
21
  subscribe(onChange: (data: T) => void): Promise<void>;
21
22
  setData(data: T, slot?: number): void;
22
23
  private setTimeout;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebSocketAccountSubscriber = void 0;
4
4
  const utils_1 = require("./utils");
5
5
  class WebSocketAccountSubscriber {
6
- constructor(accountName, program, accountPublicKey, decodeBuffer, resubTimeoutMs) {
6
+ constructor(accountName, program, accountPublicKey, decodeBuffer, resubTimeoutMs, commitment) {
7
7
  this.isUnsubscribing = false;
8
8
  this.accountName = accountName;
9
9
  this.program = program;
@@ -11,6 +11,8 @@ class WebSocketAccountSubscriber {
11
11
  this.decodeBufferFn = decodeBuffer;
12
12
  this.resubTimeoutMs = resubTimeoutMs;
13
13
  this.receivingData = false;
14
+ this.commitment =
15
+ commitment !== null && commitment !== void 0 ? commitment : this.program.provider.opts.commitment;
14
16
  }
15
17
  async subscribe(onChange) {
16
18
  if (this.listenerId || this.isUnsubscribing) {
@@ -30,7 +32,7 @@ class WebSocketAccountSubscriber {
30
32
  else {
31
33
  this.handleRpcResponse(context, accountInfo);
32
34
  }
33
- }, this.program.provider.opts.commitment);
35
+ }, this.commitment);
34
36
  if (this.resubTimeoutMs) {
35
37
  this.setTimeout();
36
38
  }
@@ -3,16 +3,17 @@ import { DataAndSlot, AccountSubscriber, UserAccountEvents, UserAccountSubscribe
3
3
  import { Program } from '@coral-xyz/anchor';
4
4
  import StrictEventEmitter from 'strict-event-emitter-types';
5
5
  import { EventEmitter } from 'events';
6
- import { PublicKey } from '@solana/web3.js';
6
+ import { Commitment, PublicKey } from '@solana/web3.js';
7
7
  import { UserAccount } from '../types';
8
8
  export declare class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
9
9
  isSubscribed: boolean;
10
10
  reconnectTimeoutMs?: number;
11
+ commitment?: Commitment;
11
12
  program: Program;
12
13
  eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
13
14
  userAccountPublicKey: PublicKey;
14
15
  userDataAccountSubscriber: AccountSubscriber<UserAccount>;
15
- constructor(program: Program, userAccountPublicKey: PublicKey, reconnectTimeoutMs?: number);
16
+ constructor(program: Program, userAccountPublicKey: PublicKey, reconnectTimeoutMs?: number, commitment?: Commitment);
16
17
  subscribe(userAccount?: UserAccount): Promise<boolean>;
17
18
  fetch(): Promise<void>;
18
19
  unsubscribe(): Promise<void>;
@@ -5,18 +5,19 @@ const types_1 = require("./types");
5
5
  const events_1 = require("events");
6
6
  const webSocketAccountSubscriber_1 = require("./webSocketAccountSubscriber");
7
7
  class WebSocketUserAccountSubscriber {
8
- constructor(program, userAccountPublicKey, reconnectTimeoutMs) {
8
+ constructor(program, userAccountPublicKey, reconnectTimeoutMs, commitment) {
9
9
  this.isSubscribed = false;
10
10
  this.program = program;
11
11
  this.userAccountPublicKey = userAccountPublicKey;
12
12
  this.eventEmitter = new events_1.EventEmitter();
13
13
  this.reconnectTimeoutMs = reconnectTimeoutMs;
14
+ this.commitment = commitment;
14
15
  }
15
16
  async subscribe(userAccount) {
16
17
  if (this.isSubscribed) {
17
18
  return true;
18
19
  }
19
- this.userDataAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('user', this.program, this.userAccountPublicKey, undefined, this.reconnectTimeoutMs);
20
+ this.userDataAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('user', this.program, this.userAccountPublicKey, undefined, this.reconnectTimeoutMs, this.commitment);
20
21
  if (userAccount) {
21
22
  this.userDataAccountSubscriber.setData(userAccount);
22
23
  }
@@ -3,16 +3,17 @@ import { DataAndSlot, AccountSubscriber, UserStatsAccountSubscriber, UserStatsAc
3
3
  import { Program } from '@coral-xyz/anchor';
4
4
  import StrictEventEmitter from 'strict-event-emitter-types';
5
5
  import { EventEmitter } from 'events';
6
- import { PublicKey } from '@solana/web3.js';
6
+ import { Commitment, PublicKey } from '@solana/web3.js';
7
7
  import { UserStatsAccount } from '../types';
8
8
  export declare class WebSocketUserStatsAccountSubscriber implements UserStatsAccountSubscriber {
9
9
  isSubscribed: boolean;
10
10
  reconnectTimeoutMs?: number;
11
+ commitment?: Commitment;
11
12
  program: Program;
12
13
  eventEmitter: StrictEventEmitter<EventEmitter, UserStatsAccountEvents>;
13
14
  userStatsAccountPublicKey: PublicKey;
14
15
  userStatsAccountSubscriber: AccountSubscriber<UserStatsAccount>;
15
- constructor(program: Program, userStatsAccountPublicKey: PublicKey, reconnectTimeoutMs?: number);
16
+ constructor(program: Program, userStatsAccountPublicKey: PublicKey, reconnectTimeoutMs?: number, commitment?: Commitment);
16
17
  subscribe(userStatsAccount?: UserStatsAccount): Promise<boolean>;
17
18
  fetch(): Promise<void>;
18
19
  unsubscribe(): Promise<void>;
@@ -5,18 +5,19 @@ const types_1 = require("./types");
5
5
  const events_1 = require("events");
6
6
  const webSocketAccountSubscriber_1 = require("./webSocketAccountSubscriber");
7
7
  class WebSocketUserStatsAccountSubscriber {
8
- constructor(program, userStatsAccountPublicKey, reconnectTimeoutMs) {
8
+ constructor(program, userStatsAccountPublicKey, reconnectTimeoutMs, commitment) {
9
9
  this.isSubscribed = false;
10
10
  this.program = program;
11
11
  this.userStatsAccountPublicKey = userStatsAccountPublicKey;
12
12
  this.eventEmitter = new events_1.EventEmitter();
13
13
  this.reconnectTimeoutMs = reconnectTimeoutMs;
14
+ this.commitment = commitment;
14
15
  }
15
16
  async subscribe(userStatsAccount) {
16
17
  if (this.isSubscribed) {
17
18
  return true;
18
19
  }
19
- this.userStatsAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('userStats', this.program, this.userStatsAccountPublicKey, undefined, this.reconnectTimeoutMs);
20
+ this.userStatsAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('userStats', this.program, this.userStatsAccountPublicKey, undefined, this.reconnectTimeoutMs, this.commitment);
20
21
  if (userStatsAccount) {
21
22
  this.userStatsAccountSubscriber.setData(userStatsAccount);
22
23
  }
@@ -66,7 +66,7 @@ class DriftClient {
66
66
  this._isSubscribed = val;
67
67
  }
68
68
  constructor(config) {
69
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
69
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
70
70
  this.users = new Map();
71
71
  this._isSubscribed = false;
72
72
  this.perpMarketLastSlotCache = new Map();
@@ -116,9 +116,13 @@ class DriftClient {
116
116
  else {
117
117
  this.userAccountSubscriptionConfig = {
118
118
  type: 'websocket',
119
+ resubTimeoutMs: (_m = config.accountSubscription) === null || _m === void 0 ? void 0 : _m.resubTimeoutMs,
120
+ commitment: (_o = config.accountSubscription) === null || _o === void 0 ? void 0 : _o.commitment,
119
121
  };
120
122
  this.userStatsAccountSubscriptionConfig = {
121
123
  type: 'websocket',
124
+ resubTimeoutMs: (_p = config.accountSubscription) === null || _p === void 0 ? void 0 : _p.resubTimeoutMs,
125
+ commitment: (_q = config.accountSubscription) === null || _q === void 0 ? void 0 : _q.commitment,
122
126
  };
123
127
  }
124
128
  if (config.userStats) {
@@ -135,15 +139,15 @@ class DriftClient {
135
139
  const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
136
140
  config.spotMarketIndexes === undefined &&
137
141
  config.oracleInfos === undefined;
138
- if (((_m = config.accountSubscription) === null || _m === void 0 ? void 0 : _m.type) === 'polling') {
139
- this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_o = config.perpMarketIndexes) !== null && _o !== void 0 ? _o : [], (_p = config.spotMarketIndexes) !== null && _p !== void 0 ? _p : [], (_q = config.oracleInfos) !== null && _q !== void 0 ? _q : [], noMarketsAndOraclesSpecified);
142
+ if (((_r = config.accountSubscription) === null || _r === void 0 ? void 0 : _r.type) === 'polling') {
143
+ this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_s = config.perpMarketIndexes) !== null && _s !== void 0 ? _s : [], (_t = config.spotMarketIndexes) !== null && _t !== void 0 ? _t : [], (_u = config.oracleInfos) !== null && _u !== void 0 ? _u : [], noMarketsAndOraclesSpecified);
140
144
  }
141
145
  else {
142
- this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_r = config.perpMarketIndexes) !== null && _r !== void 0 ? _r : [], (_s = config.spotMarketIndexes) !== null && _s !== void 0 ? _s : [], (_t = config.oracleInfos) !== null && _t !== void 0 ? _t : [], noMarketsAndOraclesSpecified, (_u = config.accountSubscription) === null || _u === void 0 ? void 0 : _u.resubTimeoutMs);
146
+ this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_v = config.perpMarketIndexes) !== null && _v !== void 0 ? _v : [], (_w = config.spotMarketIndexes) !== null && _w !== void 0 ? _w : [], (_x = config.oracleInfos) !== null && _x !== void 0 ? _x : [], noMarketsAndOraclesSpecified, (_y = config.accountSubscription) === null || _y === void 0 ? void 0 : _y.resubTimeoutMs);
143
147
  }
144
148
  this.eventEmitter = this.accountSubscriber.eventEmitter;
145
149
  this.txSender =
146
- (_v = config.txSender) !== null && _v !== void 0 ? _v : new retryTxSender_1.RetryTxSender({
150
+ (_z = config.txSender) !== null && _z !== void 0 ? _z : new retryTxSender_1.RetryTxSender({
147
151
  connection: this.connection,
148
152
  wallet: this.wallet,
149
153
  opts: this.opts,
@@ -1,4 +1,4 @@
1
- import { ConfirmOptions, Connection, PublicKey, TransactionVersion } from '@solana/web3.js';
1
+ import { Commitment, ConfirmOptions, Connection, PublicKey, TransactionVersion } from '@solana/web3.js';
2
2
  import { IWallet, TxParams } from './types';
3
3
  import { OracleInfo } from './oracles/types';
4
4
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
@@ -29,6 +29,7 @@ export type DriftClientConfig = {
29
29
  export type DriftClientSubscriptionConfig = {
30
30
  type: 'websocket';
31
31
  resubTimeoutMs?: number;
32
+ commitment?: Commitment;
32
33
  } | {
33
34
  type: 'polling';
34
35
  accountLoader: BulkAccountLoader;
@@ -65,6 +65,7 @@ class JupiterClient {
65
65
  * @param slippageBps the slippage tolerance in basis points
66
66
  */
67
67
  async getSwap({ quote, userPublicKey, slippageBps = 50, }) {
68
+ var _a;
68
69
  if (!quote) {
69
70
  throw new Error('Jupiter swap quote not provided. Please try again.');
70
71
  }
@@ -79,6 +80,9 @@ class JupiterClient {
79
80
  slippageBps,
80
81
  }),
81
82
  })).json();
83
+ if (!('swapTransaction' in resp)) {
84
+ throw new Error(`swapTransaction not found, error from Jupiter: ${resp.error} ${(_a = ', ' + resp.message) !== null && _a !== void 0 ? _a : ''}`);
85
+ }
82
86
  const { swapTransaction } = resp;
83
87
  try {
84
88
  const swapTransactionBuf = Buffer.from(swapTransaction, 'base64');
@@ -25,7 +25,7 @@ function getAuctionPrice(order, slot, oraclePrice) {
25
25
  return getAuctionPriceForOracleOffsetAuction(order, slot, oraclePrice);
26
26
  }
27
27
  else {
28
- throw Error(`Cant get auction price for order type ${order.orderType}`);
28
+ throw Error(`Cant get auction price for order type ${(0, _1.getVariant)(order.orderType)}`);
29
29
  }
30
30
  }
31
31
  exports.getAuctionPrice = getAuctionPrice;
package/lib/user.js CHANGED
@@ -22,7 +22,7 @@ class User {
22
22
  this._isSubscribed = val;
23
23
  }
24
24
  constructor(config) {
25
- var _a, _b;
25
+ var _a, _b, _c;
26
26
  this._isSubscribed = false;
27
27
  this.driftClient = config.driftClient;
28
28
  this.userAccountPublicKey = config.userAccountPublicKey;
@@ -32,8 +32,8 @@ class User {
32
32
  else if (((_b = config.accountSubscription) === null || _b === void 0 ? void 0 : _b.type) === 'custom') {
33
33
  this.accountSubscriber = config.accountSubscription.userAccountSubscriber;
34
34
  }
35
- else {
36
- this.accountSubscriber = new webSocketUserAccountSubscriber_1.WebSocketUserAccountSubscriber(config.driftClient.program, config.userAccountPublicKey);
35
+ else if (((_c = config.accountSubscription) === null || _c === void 0 ? void 0 : _c.type) === 'websocket') {
36
+ this.accountSubscriber = new webSocketUserAccountSubscriber_1.WebSocketUserAccountSubscriber(config.driftClient.program, config.userAccountPublicKey, config.accountSubscription.resubTimeoutMs, config.accountSubscription.commitment);
37
37
  }
38
38
  this.eventEmitter = this.accountSubscriber.eventEmitter;
39
39
  }
@@ -1,5 +1,5 @@
1
1
  import { DriftClient } from './driftClient';
2
- import { PublicKey } from '@solana/web3.js';
2
+ import { Commitment, PublicKey } from '@solana/web3.js';
3
3
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
4
  import { UserAccountSubscriber } from './accounts/types';
5
5
  export type UserConfig = {
@@ -9,6 +9,8 @@ export type UserConfig = {
9
9
  };
10
10
  export type UserSubscriptionConfig = {
11
11
  type: 'websocket';
12
+ resubTimeoutMs?: number;
13
+ commitment?: Commitment;
12
14
  } | {
13
15
  type: 'polling';
14
16
  accountLoader: BulkAccountLoader;
package/lib/userStats.js CHANGED
@@ -7,17 +7,17 @@ const webSocketUserStatsAccountSubsriber_1 = require("./accounts/webSocketUserSt
7
7
  const pda_1 = require("./addresses/pda");
8
8
  class UserStats {
9
9
  constructor(config) {
10
- var _a, _b;
10
+ var _a, _b, _c;
11
11
  this.driftClient = config.driftClient;
12
12
  this.userStatsAccountPublicKey = config.userStatsAccountPublicKey;
13
13
  if (((_a = config.accountSubscription) === null || _a === void 0 ? void 0 : _a.type) === 'polling') {
14
14
  this.accountSubscriber = new pollingUserStatsAccountSubscriber_1.PollingUserStatsAccountSubscriber(config.driftClient.program, config.userStatsAccountPublicKey, config.accountSubscription.accountLoader);
15
15
  }
16
- else if (((_b = config.accountSubscription) === null || _b === void 0 ? void 0 : _b.type) === 'custom') {
17
- throw new Error('Custom account subscription not yet implemented for user stats');
16
+ else if (((_b = config.accountSubscription) === null || _b === void 0 ? void 0 : _b.type) === 'websocket') {
17
+ this.accountSubscriber = new webSocketUserStatsAccountSubsriber_1.WebSocketUserStatsAccountSubscriber(config.driftClient.program, config.userStatsAccountPublicKey, config.accountSubscription.resubTimeoutMs, config.accountSubscription.commitment);
18
18
  }
19
19
  else {
20
- this.accountSubscriber = new webSocketUserStatsAccountSubsriber_1.WebSocketUserStatsAccountSubscriber(config.driftClient.program, config.userStatsAccountPublicKey);
20
+ throw new Error(`Unknown user stats account subscription type: ${(_c = config.accountSubscription) === null || _c === void 0 ? void 0 : _c.type}`);
21
21
  }
22
22
  }
23
23
  async subscribe(userStatsAccount) {
@@ -1,5 +1,5 @@
1
1
  import { DriftClient } from './driftClient';
2
- import { PublicKey } from '@solana/web3.js';
2
+ import { Commitment, PublicKey } from '@solana/web3.js';
3
3
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
4
  export type UserStatsConfig = {
5
5
  accountSubscription?: UserStatsSubscriptionConfig;
@@ -8,6 +8,8 @@ export type UserStatsConfig = {
8
8
  };
9
9
  export type UserStatsSubscriptionConfig = {
10
10
  type: 'websocket';
11
+ resubTimeoutMs?: number;
12
+ commitment?: Commitment;
11
13
  } | {
12
14
  type: 'polling';
13
15
  accountLoader: BulkAccountLoader;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.47.0-beta.0",
3
+ "version": "2.47.0-beta.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -1,6 +1,6 @@
1
1
  import { DataAndSlot, BufferAndSlot, AccountSubscriber } from './types';
2
2
  import { AnchorProvider, Program } from '@coral-xyz/anchor';
3
- import { AccountInfo, Context, PublicKey } from '@solana/web3.js';
3
+ import { AccountInfo, Commitment, Context, PublicKey } from '@solana/web3.js';
4
4
  import { capitalize } from './utils';
5
5
  import * as Buffer from 'buffer';
6
6
 
@@ -14,6 +14,7 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
14
14
  onChange: (data: T) => void;
15
15
  listenerId?: number;
16
16
  resubTimeoutMs?: number;
17
+ commitment?: Commitment;
17
18
  isUnsubscribing = false;
18
19
 
19
20
  timeoutId?: NodeJS.Timeout;
@@ -25,7 +26,8 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
25
26
  program: Program,
26
27
  accountPublicKey: PublicKey,
27
28
  decodeBuffer?: (buffer: Buffer) => T,
28
- resubTimeoutMs?: number
29
+ resubTimeoutMs?: number,
30
+ commitment?: Commitment
29
31
  ) {
30
32
  this.accountName = accountName;
31
33
  this.program = program;
@@ -33,6 +35,8 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
33
35
  this.decodeBufferFn = decodeBuffer;
34
36
  this.resubTimeoutMs = resubTimeoutMs;
35
37
  this.receivingData = false;
38
+ this.commitment =
39
+ commitment ?? (this.program.provider as AnchorProvider).opts.commitment;
36
40
  }
37
41
 
38
42
  async subscribe(onChange: (data: T) => void): Promise<void> {
@@ -57,7 +61,7 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
57
61
  this.handleRpcResponse(context, accountInfo);
58
62
  }
59
63
  },
60
- (this.program.provider as AnchorProvider).opts.commitment
64
+ this.commitment
61
65
  );
62
66
 
63
67
  if (this.resubTimeoutMs) {
@@ -8,13 +8,14 @@ import {
8
8
  import { Program } from '@coral-xyz/anchor';
9
9
  import StrictEventEmitter from 'strict-event-emitter-types';
10
10
  import { EventEmitter } from 'events';
11
- import { PublicKey } from '@solana/web3.js';
11
+ import { Commitment, PublicKey } from '@solana/web3.js';
12
12
  import { WebSocketAccountSubscriber } from './webSocketAccountSubscriber';
13
13
  import { UserAccount } from '../types';
14
14
 
15
15
  export class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
16
16
  isSubscribed: boolean;
17
17
  reconnectTimeoutMs?: number;
18
+ commitment?: Commitment;
18
19
  program: Program;
19
20
  eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
20
21
  userAccountPublicKey: PublicKey;
@@ -24,13 +25,15 @@ export class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
24
25
  public constructor(
25
26
  program: Program,
26
27
  userAccountPublicKey: PublicKey,
27
- reconnectTimeoutMs?: number
28
+ reconnectTimeoutMs?: number,
29
+ commitment?: Commitment
28
30
  ) {
29
31
  this.isSubscribed = false;
30
32
  this.program = program;
31
33
  this.userAccountPublicKey = userAccountPublicKey;
32
34
  this.eventEmitter = new EventEmitter();
33
35
  this.reconnectTimeoutMs = reconnectTimeoutMs;
36
+ this.commitment = commitment;
34
37
  }
35
38
 
36
39
  async subscribe(userAccount?: UserAccount): Promise<boolean> {
@@ -43,7 +46,8 @@ export class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
43
46
  this.program,
44
47
  this.userAccountPublicKey,
45
48
  undefined,
46
- this.reconnectTimeoutMs
49
+ this.reconnectTimeoutMs,
50
+ this.commitment
47
51
  );
48
52
 
49
53
  if (userAccount) {
@@ -8,7 +8,7 @@ import {
8
8
  import { Program } from '@coral-xyz/anchor';
9
9
  import StrictEventEmitter from 'strict-event-emitter-types';
10
10
  import { EventEmitter } from 'events';
11
- import { PublicKey } from '@solana/web3.js';
11
+ import { Commitment, PublicKey } from '@solana/web3.js';
12
12
  import { WebSocketAccountSubscriber } from './webSocketAccountSubscriber';
13
13
  import { UserStatsAccount } from '../types';
14
14
 
@@ -17,6 +17,7 @@ export class WebSocketUserStatsAccountSubscriber
17
17
  {
18
18
  isSubscribed: boolean;
19
19
  reconnectTimeoutMs?: number;
20
+ commitment?: Commitment;
20
21
  program: Program;
21
22
  eventEmitter: StrictEventEmitter<EventEmitter, UserStatsAccountEvents>;
22
23
  userStatsAccountPublicKey: PublicKey;
@@ -26,13 +27,15 @@ export class WebSocketUserStatsAccountSubscriber
26
27
  public constructor(
27
28
  program: Program,
28
29
  userStatsAccountPublicKey: PublicKey,
29
- reconnectTimeoutMs?: number
30
+ reconnectTimeoutMs?: number,
31
+ commitment?: Commitment
30
32
  ) {
31
33
  this.isSubscribed = false;
32
34
  this.program = program;
33
35
  this.userStatsAccountPublicKey = userStatsAccountPublicKey;
34
36
  this.eventEmitter = new EventEmitter();
35
37
  this.reconnectTimeoutMs = reconnectTimeoutMs;
38
+ this.commitment = commitment;
36
39
  }
37
40
 
38
41
  async subscribe(userStatsAccount?: UserStatsAccount): Promise<boolean> {
@@ -45,7 +48,8 @@ export class WebSocketUserStatsAccountSubscriber
45
48
  this.program,
46
49
  this.userStatsAccountPublicKey,
47
50
  undefined,
48
- this.reconnectTimeoutMs
51
+ this.reconnectTimeoutMs,
52
+ this.commitment
49
53
  );
50
54
 
51
55
  if (userStatsAccount) {
@@ -235,9 +235,13 @@ export class DriftClient {
235
235
  } else {
236
236
  this.userAccountSubscriptionConfig = {
237
237
  type: 'websocket',
238
+ resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
239
+ commitment: config.accountSubscription?.commitment,
238
240
  };
239
241
  this.userStatsAccountSubscriptionConfig = {
240
242
  type: 'websocket',
243
+ resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
244
+ commitment: config.accountSubscription?.commitment,
241
245
  };
242
246
  }
243
247
 
@@ -1,4 +1,5 @@
1
1
  import {
2
+ Commitment,
2
3
  ConfirmOptions,
3
4
  Connection,
4
5
  PublicKey,
@@ -37,6 +38,7 @@ export type DriftClientSubscriptionConfig =
37
38
  | {
38
39
  type: 'websocket';
39
40
  resubTimeoutMs?: number;
41
+ commitment?: Commitment;
40
42
  }
41
43
  | {
42
44
  type: 'polling';
@@ -336,6 +336,13 @@ export class JupiterClient {
336
336
  }),
337
337
  })
338
338
  ).json();
339
+ if (!('swapTransaction' in resp)) {
340
+ throw new Error(
341
+ `swapTransaction not found, error from Jupiter: ${resp.error} ${
342
+ ', ' + resp.message ?? ''
343
+ }`
344
+ );
345
+ }
339
346
  const { swapTransaction } = resp;
340
347
 
341
348
  try {
@@ -1,5 +1,5 @@
1
1
  import { isOneOfVariant, isVariant, Order, PositionDirection } from '../types';
2
- import { BN, ONE, ZERO } from '../.';
2
+ import { BN, getVariant, ONE, ZERO } from '../.';
3
3
 
4
4
  export function isAuctionComplete(order: Order, slot: number): boolean {
5
5
  if (order.auctionDuration === 0) {
@@ -31,7 +31,9 @@ export function getAuctionPrice(
31
31
  } else if (isVariant(order.orderType, 'oracle')) {
32
32
  return getAuctionPriceForOracleOffsetAuction(order, slot, oraclePrice);
33
33
  } else {
34
- throw Error(`Cant get auction price for order type ${order.orderType}`);
34
+ throw Error(
35
+ `Cant get auction price for order type ${getVariant(order.orderType)}`
36
+ );
35
37
  }
36
38
  }
37
39
 
package/src/user.ts CHANGED
@@ -109,10 +109,12 @@ export class User {
109
109
  );
110
110
  } else if (config.accountSubscription?.type === 'custom') {
111
111
  this.accountSubscriber = config.accountSubscription.userAccountSubscriber;
112
- } else {
112
+ } else if (config.accountSubscription?.type === 'websocket') {
113
113
  this.accountSubscriber = new WebSocketUserAccountSubscriber(
114
114
  config.driftClient.program,
115
- config.userAccountPublicKey
115
+ config.userAccountPublicKey,
116
+ config.accountSubscription.resubTimeoutMs,
117
+ config.accountSubscription.commitment
116
118
  );
117
119
  }
118
120
  this.eventEmitter = this.accountSubscriber.eventEmitter;
package/src/userConfig.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DriftClient } from './driftClient';
2
- import { PublicKey } from '@solana/web3.js';
2
+ import { Commitment, PublicKey } from '@solana/web3.js';
3
3
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
4
  import { UserAccountSubscriber } from './accounts/types';
5
5
 
@@ -12,6 +12,8 @@ export type UserConfig = {
12
12
  export type UserSubscriptionConfig =
13
13
  | {
14
14
  type: 'websocket';
15
+ resubTimeoutMs?: number;
16
+ commitment?: Commitment;
15
17
  }
16
18
  | {
17
19
  type: 'polling';
package/src/userStats.ts CHANGED
@@ -25,14 +25,16 @@ export class UserStats {
25
25
  config.userStatsAccountPublicKey,
26
26
  config.accountSubscription.accountLoader
27
27
  );
28
- } else if (config.accountSubscription?.type === 'custom') {
29
- throw new Error(
30
- 'Custom account subscription not yet implemented for user stats'
31
- );
32
- } else {
28
+ } else if (config.accountSubscription?.type === 'websocket') {
33
29
  this.accountSubscriber = new WebSocketUserStatsAccountSubscriber(
34
30
  config.driftClient.program,
35
- config.userStatsAccountPublicKey
31
+ config.userStatsAccountPublicKey,
32
+ config.accountSubscription.resubTimeoutMs,
33
+ config.accountSubscription.commitment
34
+ );
35
+ } else {
36
+ throw new Error(
37
+ `Unknown user stats account subscription type: ${config.accountSubscription?.type}`
36
38
  );
37
39
  }
38
40
  }
@@ -1,5 +1,5 @@
1
1
  import { DriftClient } from './driftClient';
2
- import { PublicKey } from '@solana/web3.js';
2
+ import { Commitment, PublicKey } from '@solana/web3.js';
3
3
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
4
 
5
5
  export type UserStatsConfig = {
@@ -11,6 +11,8 @@ export type UserStatsConfig = {
11
11
  export type UserStatsSubscriptionConfig =
12
12
  | {
13
13
  type: 'websocket';
14
+ resubTimeoutMs?: number;
15
+ commitment?: Commitment;
14
16
  }
15
17
  | {
16
18
  type: 'polling';