@drift-labs/sdk 2.31.1-beta.1 → 2.31.1-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.31.1-beta.1
1
+ 2.31.1-beta.2
@@ -64,7 +64,7 @@ class DriftClient {
64
64
  this._isSubscribed = val;
65
65
  }
66
66
  constructor(config) {
67
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
67
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
68
68
  this.users = new Map();
69
69
  this._isSubscribed = false;
70
70
  this.perpMarketLastSlotCache = new Map();
@@ -123,7 +123,7 @@ class DriftClient {
123
123
  this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_m = config.perpMarketIndexes) !== null && _m !== void 0 ? _m : [], (_o = config.spotMarketIndexes) !== null && _o !== void 0 ? _o : [], (_p = config.oracleInfos) !== null && _p !== void 0 ? _p : [], noMarketsAndOraclesSpecified);
124
124
  }
125
125
  this.eventEmitter = this.accountSubscriber.eventEmitter;
126
- this.txSender = new retryTxSender_1.RetryTxSender(this.provider, (_q = config.txSenderConfig) === null || _q === void 0 ? void 0 : _q.timeout, (_r = config.txSenderConfig) === null || _r === void 0 ? void 0 : _r.retrySleep, (_s = config.txSenderConfig) === null || _s === void 0 ? void 0 : _s.additionalConnections);
126
+ this.txSender = (_q = config.txSender) !== null && _q !== void 0 ? _q : new retryTxSender_1.RetryTxSender(this.provider);
127
127
  }
128
128
  getUserMapKey(subAccountId, authority) {
129
129
  return `${subAccountId}_${authority.toString()}`;
@@ -3,6 +3,7 @@ import { IWallet } from './types';
3
3
  import { OracleInfo } from './oracles/types';
4
4
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
5
5
  import { DriftEnv } from './config';
6
+ import { TxSender } from './tx/types';
6
7
  export type DriftClientConfig = {
7
8
  connection: Connection;
8
9
  wallet: IWallet;
@@ -10,7 +11,7 @@ export type DriftClientConfig = {
10
11
  programID?: PublicKey;
11
12
  accountSubscription?: DriftClientSubscriptionConfig;
12
13
  opts?: ConfirmOptions;
13
- txSenderConfig?: TxSenderConfig;
14
+ txSender?: TxSender;
14
15
  subAccountIds?: number[];
15
16
  activeSubAccountId?: number;
16
17
  perpMarketIndexes?: number[];
@@ -30,10 +31,3 @@ export type DriftClientSubscriptionConfig = {
30
31
  type: 'polling';
31
32
  accountLoader: BulkAccountLoader;
32
33
  };
33
- type TxSenderConfig = {
34
- type: 'retry';
35
- timeout?: number;
36
- retrySleep?: number;
37
- additionalConnections?: Connection[];
38
- };
39
- export {};
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.31.1-beta.0",
2
+ "version": "2.31.1-beta.1",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -10,6 +10,7 @@ export declare class RetryTxSender implements TxSender {
10
10
  timeout: number;
11
11
  retrySleep: number;
12
12
  additionalConnections: Connection[];
13
+ timoutCount: number;
13
14
  constructor(provider: AnchorProvider, timeout?: number, retrySleep?: number, additionalConnections?: Connection[]);
14
15
  send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
15
16
  prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions): Promise<Transaction>;
@@ -22,5 +23,6 @@ export declare class RetryTxSender implements TxSender {
22
23
  promiseTimeout<T>(promises: Promise<T>[], timeoutMs: number): Promise<T | null>;
23
24
  sendToAdditionalConnections(rawTx: Buffer | Uint8Array, opts: ConfirmOptions): void;
24
25
  addAdditionalConnection(newConnection: Connection): void;
26
+ getTimeoutCount(): number;
25
27
  }
26
28
  export {};
@@ -11,6 +11,7 @@ const DEFAULT_TIMEOUT = 35000;
11
11
  const DEFAULT_RETRY = 8000;
12
12
  class RetryTxSender {
13
13
  constructor(provider, timeout, retrySleep, additionalConnections = new Array()) {
14
+ this.timoutCount = 0;
14
15
  this.provider = provider;
15
16
  this.timeout = timeout !== null && timeout !== void 0 ? timeout : DEFAULT_TIMEOUT;
16
17
  this.retrySleep = retrySleep !== null && retrySleep !== void 0 ? retrySleep : DEFAULT_RETRY;
@@ -174,6 +175,7 @@ class RetryTxSender {
174
175
  }
175
176
  }
176
177
  if (response === null) {
178
+ this.timoutCount += 1;
177
179
  const duration = (Date.now() - start) / 1000;
178
180
  throw new Error(`Transaction was not confirmed in ${duration.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`);
179
181
  }
@@ -217,5 +219,8 @@ class RetryTxSender {
217
219
  this.additionalConnections.push(newConnection);
218
220
  }
219
221
  }
222
+ getTimeoutCount() {
223
+ return this.timoutCount;
224
+ }
220
225
  }
221
226
  exports.RetryTxSender = RetryTxSender;
package/lib/tx/types.d.ts CHANGED
@@ -11,4 +11,5 @@ export interface TxSender {
11
11
  sendVersionedTransaction(tx: VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
12
12
  getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<VersionedTransaction>;
13
13
  sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
14
+ getTimeoutCount(): number;
14
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.31.1-beta.1",
3
+ "version": "2.31.1-beta.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -257,12 +257,7 @@ export class DriftClient {
257
257
  );
258
258
  }
259
259
  this.eventEmitter = this.accountSubscriber.eventEmitter;
260
- this.txSender = new RetryTxSender(
261
- this.provider,
262
- config.txSenderConfig?.timeout,
263
- config.txSenderConfig?.retrySleep,
264
- config.txSenderConfig?.additionalConnections
265
- );
260
+ this.txSender = config.txSender ?? new RetryTxSender(this.provider);
266
261
  }
267
262
 
268
263
  public getUserMapKey(subAccountId: number, authority: PublicKey): string {
@@ -8,6 +8,7 @@ import { IWallet } from './types';
8
8
  import { OracleInfo } from './oracles/types';
9
9
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
10
10
  import { DriftEnv } from './config';
11
+ import { TxSender } from './tx/types';
11
12
 
12
13
  export type DriftClientConfig = {
13
14
  connection: Connection;
@@ -16,7 +17,7 @@ export type DriftClientConfig = {
16
17
  programID?: PublicKey;
17
18
  accountSubscription?: DriftClientSubscriptionConfig;
18
19
  opts?: ConfirmOptions;
19
- txSenderConfig?: TxSenderConfig;
20
+ txSender?: TxSender;
20
21
  subAccountIds?: number[];
21
22
  activeSubAccountId?: number;
22
23
  perpMarketIndexes?: number[];
@@ -39,10 +40,3 @@ export type DriftClientSubscriptionConfig =
39
40
  type: 'polling';
40
41
  accountLoader: BulkAccountLoader;
41
42
  };
42
-
43
- type TxSenderConfig = {
44
- type: 'retry';
45
- timeout?: number;
46
- retrySleep?: number;
47
- additionalConnections?: Connection[];
48
- };
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.31.1-beta.1",
2
+ "version": "2.31.1-beta.2",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -30,6 +30,7 @@ export class RetryTxSender implements TxSender {
30
30
  timeout: number;
31
31
  retrySleep: number;
32
32
  additionalConnections: Connection[];
33
+ timoutCount = 0;
33
34
 
34
35
  public constructor(
35
36
  provider: AnchorProvider,
@@ -260,6 +261,7 @@ export class RetryTxSender implements TxSender {
260
261
  }
261
262
 
262
263
  if (response === null) {
264
+ this.timoutCount += 1;
263
265
  const duration = (Date.now() - start) / 1000;
264
266
  throw new Error(
265
267
  `Transaction was not confirmed in ${duration.toFixed(
@@ -325,4 +327,8 @@ export class RetryTxSender implements TxSender {
325
327
  this.additionalConnections.push(newConnection);
326
328
  }
327
329
  }
330
+
331
+ public getTimeoutCount(): number {
332
+ return this.timoutCount;
333
+ }
328
334
  }
package/src/tx/types.ts CHANGED
@@ -42,4 +42,6 @@ export interface TxSender {
42
42
  rawTransaction: Buffer | Uint8Array,
43
43
  opts: ConfirmOptions
44
44
  ): Promise<TxSigAndSlot>;
45
+
46
+ getTimeoutCount(): number;
45
47
  }