@drift-labs/sdk 2.42.0-beta.5 → 2.42.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.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.42.0-beta.5
1
+ 2.42.0-beta.6
@@ -269,7 +269,7 @@ export declare class DriftClient {
269
269
  * @param bracketOrdersParams
270
270
  * @returns
271
271
  */
272
- sendMarketOrderAndGetSignedFillTx(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount, makerInfo?: MakerInfo | MakerInfo[], txParams?: TxParams, bracketOrdersParams?: OptionalOrderParams[], referrerInfo?: ReferrerInfo, useVersionedTx?: boolean): Promise<{
272
+ sendMarketOrderAndGetSignedFillTx(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount, makerInfo?: MakerInfo | MakerInfo[], txParams?: TxParams, bracketOrdersParams?: OptionalOrderParams[], referrerInfo?: ReferrerInfo): Promise<{
273
273
  txSig: TransactionSignature;
274
274
  signedFillTx: Transaction;
275
275
  }>;
@@ -294,6 +294,7 @@ class DriftClient {
294
294
  * @param includeDelegates
295
295
  */
296
296
  async updateWallet(newWallet, subAccountIds, activeSubAccountId, includeDelegates, authoritySubaccountMap) {
297
+ var _a, _b;
297
298
  const newProvider = new anchor_1.AnchorProvider(this.connection,
298
299
  // @ts-ignore
299
300
  newWallet, this.opts);
@@ -308,6 +309,10 @@ class DriftClient {
308
309
  this.activeSubAccountId = activeSubAccountId;
309
310
  this.userStatsAccountPublicKey = undefined;
310
311
  this.includeDelegates = includeDelegates !== null && includeDelegates !== void 0 ? includeDelegates : false;
312
+ const walletSupportsVersionedTxns =
313
+ //@ts-ignore
314
+ (_b = (_a = this.wallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0 > 1;
315
+ this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
311
316
  if (includeDelegates && subAccountIds) {
312
317
  throw new Error('Can only pass one of includeDelegates or subAccountIds. If you want to specify subaccount ids for multiple authorities, pass authoritySubaccountMap instead');
313
318
  }
@@ -939,28 +944,25 @@ class DriftClient {
939
944
  * @param reduceOnly
940
945
  */
941
946
  async deposit(amount, marketIndex, associatedTokenAccount, subAccountId, reduceOnly = false) {
942
- const tx = new web3_js_1.Transaction();
943
- tx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
944
- units: 600000,
945
- }));
946
947
  const additionalSigners = [];
947
948
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
948
949
  const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
949
950
  const signerAuthority = this.wallet.publicKey;
950
951
  const createWSOLTokenAccount = isSolMarket && associatedTokenAccount.equals(signerAuthority);
952
+ const instructions = [];
951
953
  if (createWSOLTokenAccount) {
952
954
  const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, true);
953
955
  associatedTokenAccount = pubkey;
954
- ixs.forEach((ix) => {
955
- tx.add(ix);
956
- });
956
+ instructions.push(...ixs);
957
957
  }
958
958
  const depositCollateralIx = await this.getDepositInstruction(amount, marketIndex, associatedTokenAccount, subAccountId, reduceOnly, true);
959
- tx.add(depositCollateralIx);
959
+ instructions.push(depositCollateralIx);
960
960
  // Close the wrapped sol account at the end of the transaction
961
961
  if (createWSOLTokenAccount) {
962
- tx.add((0, spl_token_1.createCloseAccountInstruction)(associatedTokenAccount, signerAuthority, signerAuthority, []));
962
+ instructions.push((0, spl_token_1.createCloseAccountInstruction)(associatedTokenAccount, signerAuthority, signerAuthority, []));
963
963
  }
964
+ const txParams = { ...this.txParams, computeUnits: 600000 };
965
+ const tx = await this.buildTransaction(instructions, txParams);
964
966
  const { txSig, slot } = await this.sendTransaction(tx, additionalSigners, this.opts);
965
967
  this.spotMarketLastSlotCache.set(marketIndex, slot);
966
968
  return txSig;
@@ -1363,8 +1365,7 @@ class DriftClient {
1363
1365
  * @param bracketOrdersParams
1364
1366
  * @returns
1365
1367
  */
1366
- async sendMarketOrderAndGetSignedFillTx(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams = new Array(), referrerInfo, useVersionedTx = true) {
1367
- var _a, _b;
1368
+ async sendMarketOrderAndGetSignedFillTx(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams = new Array(), referrerInfo) {
1368
1369
  const marketIndex = orderParams.marketIndex;
1369
1370
  const orderId = userAccount.nextOrderId;
1370
1371
  const bracketOrderIxs = [];
@@ -1377,11 +1378,8 @@ class DriftClient {
1377
1378
  orderId,
1378
1379
  marketIndex,
1379
1380
  }, makerInfo, referrerInfo);
1380
- const walletSupportsVersionedTxns =
1381
- //@ts-ignore
1382
- (_b = (_a = this.wallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0 > 1;
1383
1381
  // use versioned transactions if there is a lookup table account and wallet is compatible
1384
- if (walletSupportsVersionedTxns && useVersionedTx) {
1382
+ if (this.txVersion === 0) {
1385
1383
  const versionedMarketOrderTx = await this.buildTransaction([placePerpOrderIx].concat(bracketOrderIxs), txParams, 0);
1386
1384
  const versionedFillTx = await this.buildTransaction([fillPerpOrderIx], txParams, 0);
1387
1385
  const [signedVersionedMarketOrderTx, signedVersionedFillTx] = await this.provider.wallet.signAllTransactions([
@@ -3252,12 +3250,11 @@ class DriftClient {
3252
3250
  return undefined;
3253
3251
  }
3254
3252
  sendTransaction(tx, additionalSigners, opts, preSigned) {
3255
- // @ts-ignore
3256
- if (!tx.message) {
3257
- return this.txSender.send(tx, additionalSigners, opts, preSigned);
3253
+ if (tx instanceof web3_js_1.VersionedTransaction) {
3254
+ return this.txSender.sendVersionedTransaction(tx, additionalSigners, opts, preSigned);
3258
3255
  }
3259
3256
  else {
3260
- return this.txSender.sendVersionedTransaction(tx, additionalSigners, opts, preSigned);
3257
+ return this.txSender.send(tx, additionalSigners, opts, preSigned);
3261
3258
  }
3262
3259
  }
3263
3260
  async buildTransaction(instructions, txParams, txVersion, lookupTables) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.42.0-beta.5",
3
+ "version": "2.42.0-beta.6",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -539,6 +539,10 @@ export class DriftClient {
539
539
  this.activeSubAccountId = activeSubAccountId;
540
540
  this.userStatsAccountPublicKey = undefined;
541
541
  this.includeDelegates = includeDelegates ?? false;
542
+ const walletSupportsVersionedTxns =
543
+ //@ts-ignore
544
+ this.wallet.supportedTransactionVersions?.size ?? 0 > 1;
545
+ this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
542
546
 
543
547
  if (includeDelegates && subAccountIds) {
544
548
  throw new Error(
@@ -1574,13 +1578,6 @@ export class DriftClient {
1574
1578
  subAccountId?: number,
1575
1579
  reduceOnly = false
1576
1580
  ): Promise<TransactionSignature> {
1577
- const tx = new Transaction();
1578
- tx.add(
1579
- ComputeBudgetProgram.setComputeUnitLimit({
1580
- units: 600_000,
1581
- })
1582
- );
1583
-
1584
1581
  const additionalSigners: Array<Signer> = [];
1585
1582
 
1586
1583
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
@@ -1592,6 +1589,8 @@ export class DriftClient {
1592
1589
  const createWSOLTokenAccount =
1593
1590
  isSolMarket && associatedTokenAccount.equals(signerAuthority);
1594
1591
 
1592
+ const instructions = [];
1593
+
1595
1594
  if (createWSOLTokenAccount) {
1596
1595
  const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(
1597
1596
  amount,
@@ -1600,9 +1599,7 @@ export class DriftClient {
1600
1599
 
1601
1600
  associatedTokenAccount = pubkey;
1602
1601
 
1603
- ixs.forEach((ix) => {
1604
- tx.add(ix);
1605
- });
1602
+ instructions.push(...ixs);
1606
1603
  }
1607
1604
 
1608
1605
  const depositCollateralIx = await this.getDepositInstruction(
@@ -1614,11 +1611,11 @@ export class DriftClient {
1614
1611
  true
1615
1612
  );
1616
1613
 
1617
- tx.add(depositCollateralIx);
1614
+ instructions.push(depositCollateralIx);
1618
1615
 
1619
1616
  // Close the wrapped sol account at the end of the transaction
1620
1617
  if (createWSOLTokenAccount) {
1621
- tx.add(
1618
+ instructions.push(
1622
1619
  createCloseAccountInstruction(
1623
1620
  associatedTokenAccount,
1624
1621
  signerAuthority,
@@ -1628,6 +1625,10 @@ export class DriftClient {
1628
1625
  );
1629
1626
  }
1630
1627
 
1628
+ const txParams = { ...this.txParams, computeUnits: 600_000 };
1629
+
1630
+ const tx = await this.buildTransaction(instructions, txParams);
1631
+
1631
1632
  const { txSig, slot } = await this.sendTransaction(
1632
1633
  tx,
1633
1634
  additionalSigners,
@@ -2442,8 +2443,7 @@ export class DriftClient {
2442
2443
  makerInfo?: MakerInfo | MakerInfo[],
2443
2444
  txParams?: TxParams,
2444
2445
  bracketOrdersParams = new Array<OptionalOrderParams>(),
2445
- referrerInfo?: ReferrerInfo,
2446
- useVersionedTx = true
2446
+ referrerInfo?: ReferrerInfo
2447
2447
  ): Promise<{ txSig: TransactionSignature; signedFillTx: Transaction }> {
2448
2448
  const marketIndex = orderParams.marketIndex;
2449
2449
  const orderId = userAccount.nextOrderId;
@@ -2469,12 +2469,8 @@ export class DriftClient {
2469
2469
  referrerInfo
2470
2470
  );
2471
2471
 
2472
- const walletSupportsVersionedTxns =
2473
- //@ts-ignore
2474
- this.wallet.supportedTransactionVersions?.size ?? 0 > 1;
2475
-
2476
2472
  // use versioned transactions if there is a lookup table account and wallet is compatible
2477
- if (walletSupportsVersionedTxns && useVersionedTx) {
2473
+ if (this.txVersion === 0) {
2478
2474
  const versionedMarketOrderTx = await this.buildTransaction(
2479
2475
  [placePerpOrderIx].concat(bracketOrderIxs),
2480
2476
  txParams,
@@ -5852,17 +5848,16 @@ export class DriftClient {
5852
5848
  opts?: ConfirmOptions,
5853
5849
  preSigned?: boolean
5854
5850
  ): Promise<TxSigAndSlot> {
5855
- // @ts-ignore
5856
- if (!tx.message) {
5857
- return this.txSender.send(
5858
- tx as Transaction,
5851
+ if (tx instanceof VersionedTransaction) {
5852
+ return this.txSender.sendVersionedTransaction(
5853
+ tx as VersionedTransaction,
5859
5854
  additionalSigners,
5860
5855
  opts,
5861
5856
  preSigned
5862
5857
  );
5863
5858
  } else {
5864
- return this.txSender.sendVersionedTransaction(
5865
- tx as VersionedTransaction,
5859
+ return this.txSender.send(
5860
+ tx as Transaction,
5866
5861
  additionalSigners,
5867
5862
  opts,
5868
5863
  preSigned