@drift-labs/sdk 2.31.1-beta.0 → 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.0
1
+ 2.31.1-beta.2
@@ -472,6 +472,10 @@ export declare class DriftClient {
472
472
  settleeUserAccountPublicKey: PublicKey;
473
473
  settleeUserAccount: UserAccount;
474
474
  }[], marketIndexes: number[]): Promise<TransactionSignature>;
475
+ getSettlePNLsIxs(users: {
476
+ settleeUserAccountPublicKey: PublicKey;
477
+ settleeUserAccount: UserAccount;
478
+ }[], marketIndexes: number[]): Promise<Array<TransactionInstruction>>;
475
479
  settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
476
480
  settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
477
481
  liquidatePerp(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: BN, txParams?: TxParams): Promise<TransactionSignature>;
@@ -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()}`;
@@ -2527,12 +2527,7 @@ class DriftClient {
2527
2527
  });
2528
2528
  }
2529
2529
  async settlePNLs(users, marketIndexes) {
2530
- const ixs = [];
2531
- for (const { settleeUserAccountPublicKey, settleeUserAccount } of users) {
2532
- for (const marketIndex of marketIndexes) {
2533
- ixs.push(await this.settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex));
2534
- }
2535
- }
2530
+ const ixs = await this.getSettlePNLsIxs(users, marketIndexes);
2536
2531
  const tx = new web3_js_1.Transaction()
2537
2532
  .add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
2538
2533
  units: 1000000,
@@ -2541,6 +2536,15 @@ class DriftClient {
2541
2536
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
2542
2537
  return txSig;
2543
2538
  }
2539
+ async getSettlePNLsIxs(users, marketIndexes) {
2540
+ const ixs = [];
2541
+ for (const { settleeUserAccountPublicKey, settleeUserAccount } of users) {
2542
+ for (const marketIndex of marketIndexes) {
2543
+ ixs.push(await this.settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex));
2544
+ }
2545
+ }
2546
+ return ixs;
2547
+ }
2544
2548
  async settlePNL(settleeUserAccountPublicKey, settleeUserAccount, marketIndex, txParams) {
2545
2549
  const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex), txParams), [], this.opts);
2546
2550
  return txSig;
@@ -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.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.0",
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 {
@@ -4309,6 +4304,26 @@ export class DriftClient {
4309
4304
  }[],
4310
4305
  marketIndexes: number[]
4311
4306
  ): Promise<TransactionSignature> {
4307
+ const ixs = await this.getSettlePNLsIxs(users, marketIndexes);
4308
+ const tx = new Transaction()
4309
+ .add(
4310
+ ComputeBudgetProgram.setComputeUnitLimit({
4311
+ units: 1_000_000,
4312
+ })
4313
+ )
4314
+ .add(...ixs);
4315
+
4316
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
4317
+ return txSig;
4318
+ }
4319
+
4320
+ public async getSettlePNLsIxs(
4321
+ users: {
4322
+ settleeUserAccountPublicKey: PublicKey;
4323
+ settleeUserAccount: UserAccount;
4324
+ }[],
4325
+ marketIndexes: number[]
4326
+ ): Promise<Array<TransactionInstruction>> {
4312
4327
  const ixs = [];
4313
4328
  for (const { settleeUserAccountPublicKey, settleeUserAccount } of users) {
4314
4329
  for (const marketIndex of marketIndexes) {
@@ -4322,16 +4337,7 @@ export class DriftClient {
4322
4337
  }
4323
4338
  }
4324
4339
 
4325
- const tx = new Transaction()
4326
- .add(
4327
- ComputeBudgetProgram.setComputeUnitLimit({
4328
- units: 1_000_000,
4329
- })
4330
- )
4331
- .add(...ixs);
4332
-
4333
- const { txSig } = await this.sendTransaction(tx, [], this.opts);
4334
- return txSig;
4340
+ return ixs;
4335
4341
  }
4336
4342
 
4337
4343
  public async settlePNL(
@@ -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.0",
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
  }