@drift-labs/vaults-sdk 0.1.191 → 0.1.193

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.
@@ -515,6 +515,12 @@ class VaultClient {
515
515
  if (!spotMarket) {
516
516
  throw new Error(`Spot market ${vaultAccount.spotMarketIndex} not found on driftClient`);
517
517
  }
518
+ const userAta = (0, spl_token_1.getAssociatedTokenAddressSync)(spotMarket.mint, this.driftClient.wallet.publicKey, true);
519
+ let createAtaIx = undefined;
520
+ const userAtaExists = await this.driftClient.connection.getAccountInfo(userAta);
521
+ if (userAtaExists === null) {
522
+ createAtaIx = (0, spl_token_1.createAssociatedTokenAccountInstruction)(this.driftClient.wallet.publicKey, userAta, this.driftClient.wallet.publicKey, spotMarket.mint);
523
+ }
518
524
  const accounts = {
519
525
  vault: vaultDepositorAccount.vault,
520
526
  vaultDepositor,
@@ -524,7 +530,7 @@ class VaultClient {
524
530
  driftState: driftStateKey,
525
531
  driftSpotMarketVault: spotMarket.vault,
526
532
  driftSigner: this.driftClient.getStateAccount().signer,
527
- userTokenAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(spotMarket.mint, this.driftClient.wallet.publicKey, true),
533
+ userTokenAccount: userAta,
528
534
  driftProgram: this.driftClient.program.programId,
529
535
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
530
536
  };
@@ -536,15 +542,20 @@ class VaultClient {
536
542
  .rpc();
537
543
  }
538
544
  else {
539
- const withdrawIx = this.program.instruction.withdraw({
540
- accounts: {
541
- authority: this.driftClient.wallet.publicKey,
542
- ...accounts,
543
- },
544
- remainingAccounts,
545
- });
546
- return await this.createAndSendTxn([withdrawIx], {
547
- cuLimit: (_a = txParams === null || txParams === void 0 ? void 0 : txParams.cuLimit) !== null && _a !== void 0 ? _a : 650000,
545
+ const ixs = [
546
+ this.program.instruction.withdraw({
547
+ accounts: {
548
+ authority: this.driftClient.wallet.publicKey,
549
+ ...accounts,
550
+ },
551
+ remainingAccounts,
552
+ }),
553
+ ];
554
+ if (createAtaIx) {
555
+ ixs.unshift(createAtaIx);
556
+ }
557
+ return await this.createAndSendTxn(ixs, {
558
+ cuLimit: ((_a = txParams === null || txParams === void 0 ? void 0 : txParams.cuLimit) !== null && _a !== void 0 ? _a : 650000) + (createAtaIx ? 100000 : 0),
548
559
  ...txParams,
549
560
  });
550
561
  }
@@ -691,7 +702,10 @@ class VaultClient {
691
702
  }),
692
703
  ...vaultIxs,
693
704
  ];
694
- const tx = await this.driftClient.txSender.getVersionedTransaction(ixs, [], undefined, this.driftClient.opts);
705
+ const tx = await this.driftClient.txSender.getVersionedTransaction(ixs, [], undefined, {
706
+ preflightCommitment: 'confirmed',
707
+ ...this.driftClient.opts,
708
+ });
695
709
  let txSig = bytes_1.bs58.encode(tx.signatures[0]);
696
710
  if (txParams === null || txParams === void 0 ? void 0 : txParams.simulateTransaction) {
697
711
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/vaults-sdk",
3
- "version": "0.1.191",
3
+ "version": "0.1.193",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "directories": {
@@ -29,6 +29,7 @@ import {
29
29
  TransactionSignature,
30
30
  } from '@solana/web3.js';
31
31
  import {
32
+ createAssociatedTokenAccountInstruction,
32
33
  getAssociatedTokenAddressSync,
33
34
  TOKEN_PROGRAM_ID,
34
35
  } from '@solana/spl-token';
@@ -825,6 +826,25 @@ export class VaultClient {
825
826
  );
826
827
  }
827
828
 
829
+ const userAta = getAssociatedTokenAddressSync(
830
+ spotMarket.mint,
831
+ this.driftClient.wallet.publicKey,
832
+ true
833
+ );
834
+
835
+ let createAtaIx: TransactionInstruction | undefined = undefined;
836
+ const userAtaExists = await this.driftClient.connection.getAccountInfo(
837
+ userAta
838
+ );
839
+ if (userAtaExists === null) {
840
+ createAtaIx = createAssociatedTokenAccountInstruction(
841
+ this.driftClient.wallet.publicKey,
842
+ userAta,
843
+ this.driftClient.wallet.publicKey,
844
+ spotMarket.mint
845
+ );
846
+ }
847
+
828
848
  const accounts = {
829
849
  vault: vaultDepositorAccount.vault,
830
850
  vaultDepositor,
@@ -834,11 +854,7 @@ export class VaultClient {
834
854
  driftState: driftStateKey,
835
855
  driftSpotMarketVault: spotMarket.vault,
836
856
  driftSigner: this.driftClient.getStateAccount().signer,
837
- userTokenAccount: getAssociatedTokenAddressSync(
838
- spotMarket.mint,
839
- this.driftClient.wallet.publicKey,
840
- true
841
- ),
857
+ userTokenAccount: userAta,
842
858
  driftProgram: this.driftClient.program.programId,
843
859
  tokenProgram: TOKEN_PROGRAM_ID,
844
860
  };
@@ -850,16 +866,21 @@ export class VaultClient {
850
866
  .remainingAccounts(remainingAccounts)
851
867
  .rpc();
852
868
  } else {
853
- const withdrawIx = this.program.instruction.withdraw({
854
- accounts: {
855
- authority: this.driftClient.wallet.publicKey,
856
- ...accounts,
857
- },
858
- remainingAccounts,
859
- });
869
+ const ixs = [
870
+ this.program.instruction.withdraw({
871
+ accounts: {
872
+ authority: this.driftClient.wallet.publicKey,
873
+ ...accounts,
874
+ },
875
+ remainingAccounts,
876
+ }),
877
+ ];
878
+ if (createAtaIx) {
879
+ ixs.unshift(createAtaIx);
880
+ }
860
881
 
861
- return await this.createAndSendTxn([withdrawIx], {
862
- cuLimit: txParams?.cuLimit ?? 650_000,
882
+ return await this.createAndSendTxn(ixs, {
883
+ cuLimit: (txParams?.cuLimit ?? 650_000) + (createAtaIx ? 100_000 : 0),
863
884
  ...txParams,
864
885
  });
865
886
  }
@@ -1064,7 +1085,10 @@ export class VaultClient {
1064
1085
  ixs,
1065
1086
  [],
1066
1087
  undefined,
1067
- this.driftClient.opts
1088
+ {
1089
+ preflightCommitment: 'confirmed',
1090
+ ...this.driftClient.opts,
1091
+ }
1068
1092
  );
1069
1093
 
1070
1094
  let txSig = bs58.encode(tx.signatures[0]);