@drift-labs/sdk 2.103.0-beta.0 → 2.103.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.103.0-beta.0
1
+ 2.103.0-beta.2
@@ -703,6 +703,7 @@ export declare class DriftClient {
703
703
  settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
704
704
  settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
705
705
  settleMultiplePNLs(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode, txParams?: TxParams): Promise<TransactionSignature>;
706
+ settleMultiplePNLsMultipleTxs(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode, txParams?: TxParams): Promise<TransactionSignature[]>;
706
707
  settleMultiplePNLsIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode): Promise<TransactionInstruction>;
707
708
  getSetUserStatusToBeingLiquidatedIx(userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<TransactionInstruction>;
708
709
  setUserStatusToBeingLiquidated(userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<TransactionSignature>;
@@ -3626,6 +3626,37 @@ class DriftClient {
3626
3626
  const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.settleMultiplePNLsIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode), txParams), [], this.opts);
3627
3627
  return txSig;
3628
3628
  }
3629
+ async settleMultiplePNLsMultipleTxs(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode, txParams) {
3630
+ // need multiple TXs because settling more than 4 markets won't fit in a single TX
3631
+ const txsToSign = [];
3632
+ const marketIndexesInFourGroups = [];
3633
+ for (let i = 0; i < marketIndexes.length; i += 4) {
3634
+ marketIndexesInFourGroups.push(marketIndexes.slice(i, i + 4));
3635
+ }
3636
+ for (const marketIndexes of marketIndexesInFourGroups) {
3637
+ const ix = await this.settleMultiplePNLsIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode);
3638
+ const computeUnits = Math.min(300000 * marketIndexes.length, 1400000);
3639
+ const tx = await this.buildTransaction(ix, {
3640
+ ...txParams,
3641
+ computeUnits,
3642
+ });
3643
+ txsToSign.push(tx);
3644
+ }
3645
+ const txsMap = {};
3646
+ let i = 1;
3647
+ for (const tx of txsToSign) {
3648
+ txsMap[`tx-${i}`] = tx;
3649
+ i++;
3650
+ }
3651
+ const signedTxs = (await this.txHandler.getSignedTransactionMap(txsMap, this.provider.wallet)).signedTxMap;
3652
+ const txSigs = [];
3653
+ for (const key in signedTxs) {
3654
+ const tx = signedTxs[key];
3655
+ const { txSig } = await this.sendTransaction(tx, [], this.opts, true);
3656
+ txSigs.push(txSig);
3657
+ }
3658
+ return txSigs;
3659
+ }
3629
3660
  async settleMultiplePNLsIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode) {
3630
3661
  const remainingAccounts = this.getRemainingAccounts({
3631
3662
  userAccounts: [settleeUserAccount],
@@ -32,6 +32,7 @@ export declare class UserMap implements UserMapInterface {
32
32
  private syncConfig;
33
33
  private syncPromise?;
34
34
  private syncPromiseResolver;
35
+ private throwOnFailedSync;
35
36
  /**
36
37
  * Constructs a new UserMap instance.
37
38
  */
@@ -16,7 +16,7 @@ class UserMap {
16
16
  * Constructs a new UserMap instance.
17
17
  */
18
18
  constructor(config) {
19
- var _a, _b, _c, _d, _e;
19
+ var _a, _b, _c, _d, _e, _f;
20
20
  this.userMap = new Map();
21
21
  this.stateAccountUpdateCallback = async (state) => {
22
22
  if (!state.numberOfSubAccounts.eq(this.lastNumberOfSubAccounts)) {
@@ -83,6 +83,8 @@ class UserMap {
83
83
  this.syncConfig = (_e = config.syncConfig) !== null && _e !== void 0 ? _e : {
84
84
  type: 'default',
85
85
  };
86
+ // Whether to throw an error if the userMap fails to sync. Defaults to false.
87
+ this.throwOnFailedSync = (_f = config.throwOnFailedSync) !== null && _f !== void 0 ? _f : false;
86
88
  }
87
89
  async subscribe() {
88
90
  if (this.size() > 0) {
@@ -319,6 +321,9 @@ class UserMap {
319
321
  catch (err) {
320
322
  const e = err;
321
323
  console.error(`Error in UserMap.sync(): ${e.message} ${(_a = e.stack) !== null && _a !== void 0 ? _a : ''}`);
324
+ if (this.throwOnFailedSync) {
325
+ throw e;
326
+ }
322
327
  }
323
328
  finally {
324
329
  this.syncPromiseResolver();
@@ -408,6 +413,9 @@ class UserMap {
408
413
  }
409
414
  catch (err) {
410
415
  console.error(`Error in UserMap.sync():`, err);
416
+ if (this.throwOnFailedSync) {
417
+ throw err;
418
+ }
411
419
  }
412
420
  finally {
413
421
  if (this.syncPromiseResolver) {
@@ -34,4 +34,5 @@ export type UserMapConfig = {
34
34
  fastDecode?: boolean;
35
35
  disableSyncOnTotalAccountsChange?: boolean;
36
36
  syncConfig?: SyncConfig;
37
+ throwOnFailedSync?: boolean;
37
38
  };
@@ -703,6 +703,7 @@ export declare class DriftClient {
703
703
  settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
704
704
  settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
705
705
  settleMultiplePNLs(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode, txParams?: TxParams): Promise<TransactionSignature>;
706
+ settleMultiplePNLsMultipleTxs(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode, txParams?: TxParams): Promise<TransactionSignature[]>;
706
707
  settleMultiplePNLsIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode): Promise<TransactionInstruction>;
707
708
  getSetUserStatusToBeingLiquidatedIx(userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<TransactionInstruction>;
708
709
  setUserStatusToBeingLiquidated(userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<TransactionSignature>;
@@ -3626,6 +3626,37 @@ class DriftClient {
3626
3626
  const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.settleMultiplePNLsIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode), txParams), [], this.opts);
3627
3627
  return txSig;
3628
3628
  }
3629
+ async settleMultiplePNLsMultipleTxs(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode, txParams) {
3630
+ // need multiple TXs because settling more than 4 markets won't fit in a single TX
3631
+ const txsToSign = [];
3632
+ const marketIndexesInFourGroups = [];
3633
+ for (let i = 0; i < marketIndexes.length; i += 4) {
3634
+ marketIndexesInFourGroups.push(marketIndexes.slice(i, i + 4));
3635
+ }
3636
+ for (const marketIndexes of marketIndexesInFourGroups) {
3637
+ const ix = await this.settleMultiplePNLsIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode);
3638
+ const computeUnits = Math.min(300000 * marketIndexes.length, 1400000);
3639
+ const tx = await this.buildTransaction(ix, {
3640
+ ...txParams,
3641
+ computeUnits,
3642
+ });
3643
+ txsToSign.push(tx);
3644
+ }
3645
+ const txsMap = {};
3646
+ let i = 1;
3647
+ for (const tx of txsToSign) {
3648
+ txsMap[`tx-${i}`] = tx;
3649
+ i++;
3650
+ }
3651
+ const signedTxs = (await this.txHandler.getSignedTransactionMap(txsMap, this.provider.wallet)).signedTxMap;
3652
+ const txSigs = [];
3653
+ for (const key in signedTxs) {
3654
+ const tx = signedTxs[key];
3655
+ const { txSig } = await this.sendTransaction(tx, [], this.opts, true);
3656
+ txSigs.push(txSig);
3657
+ }
3658
+ return txSigs;
3659
+ }
3629
3660
  async settleMultiplePNLsIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode) {
3630
3661
  const remainingAccounts = this.getRemainingAccounts({
3631
3662
  userAccounts: [settleeUserAccount],
@@ -32,6 +32,7 @@ export declare class UserMap implements UserMapInterface {
32
32
  private syncConfig;
33
33
  private syncPromise?;
34
34
  private syncPromiseResolver;
35
+ private throwOnFailedSync;
35
36
  /**
36
37
  * Constructs a new UserMap instance.
37
38
  */
@@ -16,7 +16,7 @@ class UserMap {
16
16
  * Constructs a new UserMap instance.
17
17
  */
18
18
  constructor(config) {
19
- var _a, _b, _c, _d, _e;
19
+ var _a, _b, _c, _d, _e, _f;
20
20
  this.userMap = new Map();
21
21
  this.stateAccountUpdateCallback = async (state) => {
22
22
  if (!state.numberOfSubAccounts.eq(this.lastNumberOfSubAccounts)) {
@@ -83,6 +83,8 @@ class UserMap {
83
83
  this.syncConfig = (_e = config.syncConfig) !== null && _e !== void 0 ? _e : {
84
84
  type: 'default',
85
85
  };
86
+ // Whether to throw an error if the userMap fails to sync. Defaults to false.
87
+ this.throwOnFailedSync = (_f = config.throwOnFailedSync) !== null && _f !== void 0 ? _f : false;
86
88
  }
87
89
  async subscribe() {
88
90
  if (this.size() > 0) {
@@ -319,6 +321,9 @@ class UserMap {
319
321
  catch (err) {
320
322
  const e = err;
321
323
  console.error(`Error in UserMap.sync(): ${e.message} ${(_a = e.stack) !== null && _a !== void 0 ? _a : ''}`);
324
+ if (this.throwOnFailedSync) {
325
+ throw e;
326
+ }
322
327
  }
323
328
  finally {
324
329
  this.syncPromiseResolver();
@@ -408,6 +413,9 @@ class UserMap {
408
413
  }
409
414
  catch (err) {
410
415
  console.error(`Error in UserMap.sync():`, err);
416
+ if (this.throwOnFailedSync) {
417
+ throw err;
418
+ }
411
419
  }
412
420
  finally {
413
421
  if (this.syncPromiseResolver) {
@@ -34,4 +34,5 @@ export type UserMapConfig = {
34
34
  fastDecode?: boolean;
35
35
  disableSyncOnTotalAccountsChange?: boolean;
36
36
  syncConfig?: SyncConfig;
37
+ throwOnFailedSync?: boolean;
37
38
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.103.0-beta.0",
3
+ "version": "2.103.0-beta.2",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "browser": "./lib/browser/index.js",
@@ -6792,6 +6792,55 @@ export class DriftClient {
6792
6792
  return txSig;
6793
6793
  }
6794
6794
 
6795
+ public async settleMultiplePNLsMultipleTxs(
6796
+ settleeUserAccountPublicKey: PublicKey,
6797
+ settleeUserAccount: UserAccount,
6798
+ marketIndexes: number[],
6799
+ mode: SettlePnlMode,
6800
+ txParams?: TxParams
6801
+ ): Promise<TransactionSignature[]> {
6802
+ // need multiple TXs because settling more than 4 markets won't fit in a single TX
6803
+ const txsToSign: (Transaction | VersionedTransaction)[] = [];
6804
+ const marketIndexesInFourGroups: number[][] = [];
6805
+ for (let i = 0; i < marketIndexes.length; i += 4) {
6806
+ marketIndexesInFourGroups.push(marketIndexes.slice(i, i + 4));
6807
+ }
6808
+
6809
+ for (const marketIndexes of marketIndexesInFourGroups) {
6810
+ const ix = await this.settleMultiplePNLsIx(
6811
+ settleeUserAccountPublicKey,
6812
+ settleeUserAccount,
6813
+ marketIndexes,
6814
+ mode
6815
+ );
6816
+ const computeUnits = Math.min(300_000 * marketIndexes.length, 1_400_000);
6817
+ const tx = await this.buildTransaction(ix, {
6818
+ ...txParams,
6819
+ computeUnits,
6820
+ });
6821
+ txsToSign.push(tx);
6822
+ }
6823
+
6824
+ const txsMap: Record<string, Transaction | VersionedTransaction> = {};
6825
+ let i = 1;
6826
+ for (const tx of txsToSign) {
6827
+ txsMap[`tx-${i}`] = tx;
6828
+ i++;
6829
+ }
6830
+ const signedTxs = (
6831
+ await this.txHandler.getSignedTransactionMap(txsMap, this.provider.wallet)
6832
+ ).signedTxMap;
6833
+
6834
+ const txSigs: TransactionSignature[] = [];
6835
+ for (const key in signedTxs) {
6836
+ const tx = signedTxs[key];
6837
+ const { txSig } = await this.sendTransaction(tx, [], this.opts, true);
6838
+ txSigs.push(txSig);
6839
+ }
6840
+
6841
+ return txSigs;
6842
+ }
6843
+
6795
6844
  public async settleMultiplePNLsIx(
6796
6845
  settleeUserAccountPublicKey: PublicKey,
6797
6846
  settleeUserAccount: UserAccount,
@@ -93,6 +93,8 @@ export class UserMap implements UserMapInterface {
93
93
  private syncPromise?: Promise<void>;
94
94
  private syncPromiseResolver: () => void;
95
95
 
96
+ private throwOnFailedSync: boolean;
97
+
96
98
  /**
97
99
  * Constructs a new UserMap instance.
98
100
  */
@@ -157,6 +159,9 @@ export class UserMap implements UserMapInterface {
157
159
  this.syncConfig = config.syncConfig ?? {
158
160
  type: 'default',
159
161
  };
162
+
163
+ // Whether to throw an error if the userMap fails to sync. Defaults to false.
164
+ this.throwOnFailedSync = config.throwOnFailedSync ?? false;
160
165
  }
161
166
 
162
167
  public async subscribe() {
@@ -465,6 +470,9 @@ export class UserMap implements UserMapInterface {
465
470
  } catch (err) {
466
471
  const e = err as Error;
467
472
  console.error(`Error in UserMap.sync(): ${e.message} ${e.stack ?? ''}`);
473
+ if (this.throwOnFailedSync) {
474
+ throw e;
475
+ }
468
476
  } finally {
469
477
  this.syncPromiseResolver();
470
478
  this.syncPromise = undefined;
@@ -580,6 +588,9 @@ export class UserMap implements UserMapInterface {
580
588
  }
581
589
  } catch (err) {
582
590
  console.error(`Error in UserMap.sync():`, err);
591
+ if (this.throwOnFailedSync) {
592
+ throw err;
593
+ }
583
594
  } finally {
584
595
  if (this.syncPromiseResolver) {
585
596
  this.syncPromiseResolver();
@@ -55,4 +55,7 @@ export type UserMapConfig = {
55
55
  disableSyncOnTotalAccountsChange?: boolean;
56
56
 
57
57
  syncConfig?: SyncConfig;
58
+
59
+ // Whether to throw an error if the userMap fails to sync. Defaults to true.
60
+ throwOnFailedSync?: boolean;
58
61
  };