@drift-labs/sdk 2.36.1-beta.0 → 2.36.1-beta.1

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.36.1-beta.0
1
+ 2.36.1-beta.1
@@ -207,6 +207,7 @@ export declare class DriftClient {
207
207
  private checkIfAccountExists;
208
208
  getWrappedSolAccountCreationIxs(amount: BN, includeRent?: boolean): Promise<{
209
209
  ixs: anchor.web3.TransactionInstruction[];
210
+ /** @deprecated - this array is always going to be empty, in the current implementation */
210
211
  signers: Signer[];
211
212
  pubkey: PublicKey;
212
213
  }>;
@@ -931,12 +931,11 @@ class DriftClient {
931
931
  const signerAuthority = this.wallet.publicKey;
932
932
  const createWSOLTokenAccount = isSolMarket && associatedTokenAccount.equals(signerAuthority);
933
933
  if (createWSOLTokenAccount) {
934
- const { ixs, signers, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, true);
934
+ const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, true);
935
935
  associatedTokenAccount = pubkey;
936
936
  ixs.forEach((ix) => {
937
937
  tx.add(ix);
938
938
  });
939
- signers.forEach((signer) => additionalSigners.push(signer));
940
939
  }
941
940
  const depositCollateralIx = await this.getDepositInstruction(amount, marketIndex, associatedTokenAccount, subAccountId, reduceOnly, true);
942
941
  tx.add(depositCollateralIx);
@@ -990,26 +989,30 @@ class DriftClient {
990
989
  }
991
990
  }
992
991
  async getWrappedSolAccountCreationIxs(amount, includeRent) {
993
- const wrappedSolAccount = new web3_js_1.Keypair();
992
+ const authority = this.wallet.publicKey;
993
+ // Generate a random seed for wrappedSolAccount.
994
+ const seed = web3_js_1.Keypair.generate().publicKey.toBase58().slice(0, 32);
995
+ // Calculate a publicKey that will be controlled by the authority.
996
+ const wrappedSolAccount = await web3_js_1.PublicKey.createWithSeed(authority, seed, spl_token_1.TOKEN_PROGRAM_ID);
994
997
  const result = {
995
998
  ixs: [],
996
999
  signers: [],
997
- pubkey: wrappedSolAccount.publicKey,
1000
+ pubkey: wrappedSolAccount,
998
1001
  };
999
1002
  const rentSpaceLamports = new anchor_1.BN(web3_js_1.LAMPORTS_PER_SOL / 100);
1000
1003
  const lamports = includeRent
1001
1004
  ? amount.add(rentSpaceLamports)
1002
1005
  : rentSpaceLamports;
1003
- const authority = this.wallet.publicKey;
1004
- result.ixs.push(web3_js_1.SystemProgram.createAccount({
1006
+ result.ixs.push(web3_js_1.SystemProgram.createAccountWithSeed({
1005
1007
  fromPubkey: authority,
1006
- newAccountPubkey: wrappedSolAccount.publicKey,
1008
+ basePubkey: authority,
1009
+ seed,
1010
+ newAccountPubkey: wrappedSolAccount,
1007
1011
  lamports: lamports.toNumber(),
1008
1012
  space: 165,
1009
1013
  programId: spl_token_1.TOKEN_PROGRAM_ID,
1010
1014
  }));
1011
- result.ixs.push((0, spl_token_1.createInitializeAccountInstruction)(wrappedSolAccount.publicKey, spotMarkets_1.WRAPPED_SOL_MINT, authority));
1012
- result.signers.push(wrappedSolAccount);
1015
+ result.ixs.push((0, spl_token_1.createInitializeAccountInstruction)(wrappedSolAccount, spotMarkets_1.WRAPPED_SOL_MINT, authority));
1013
1016
  return result;
1014
1017
  }
1015
1018
  getAssociatedTokenAccountCreationIx(tokenMintAddress, associatedTokenAddress) {
@@ -1046,12 +1049,11 @@ class DriftClient {
1046
1049
  !isNaN(fromSubAccountId);
1047
1050
  const createWSOLTokenAccount = isSolMarket && userTokenAccount.equals(authority) && !isFromSubaccount;
1048
1051
  if (createWSOLTokenAccount) {
1049
- const { ixs: startIxs, signers, pubkey, } = await this.getWrappedSolAccountCreationIxs(amount, true);
1052
+ const { ixs: startIxs, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, true);
1050
1053
  userTokenAccount = pubkey;
1051
1054
  startIxs.forEach((ix) => {
1052
1055
  tx.add(ix);
1053
1056
  });
1054
- signers.forEach((signer) => additionalSigners.push(signer));
1055
1057
  }
1056
1058
  const depositCollateralIx = isFromSubaccount
1057
1059
  ? await this.getTransferDepositIx(amount, marketIndex, fromSubAccountId, subAccountId)
@@ -1104,12 +1106,11 @@ class DriftClient {
1104
1106
  const authority = this.wallet.publicKey;
1105
1107
  const createWSOLTokenAccount = isSolMarket && associatedTokenAddress.equals(authority);
1106
1108
  if (createWSOLTokenAccount) {
1107
- const { ixs, signers, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, false);
1109
+ const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, false);
1108
1110
  associatedTokenAddress = pubkey;
1109
1111
  ixs.forEach((ix) => {
1110
1112
  tx.add(ix);
1111
1113
  });
1112
- signers.forEach((signer) => additionalSigners.push(signer));
1113
1114
  }
1114
1115
  else {
1115
1116
  const accountExists = await this.checkIfAccountExists(associatedTokenAddress);
@@ -2904,12 +2905,11 @@ class DriftClient {
2904
2905
  const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
2905
2906
  let tokenAccount;
2906
2907
  if (createWSOLTokenAccount) {
2907
- const { ixs, signers, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, true);
2908
+ const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, true);
2908
2909
  tokenAccount = pubkey;
2909
2910
  ixs.forEach((ix) => {
2910
2911
  tx.add(ix);
2911
2912
  });
2912
- signers.forEach((signer) => additionalSigners.push(signer));
2913
2913
  }
2914
2914
  else {
2915
2915
  tokenAccount = collateralAccountPublicKey;
@@ -2983,12 +2983,11 @@ class DriftClient {
2983
2983
  const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
2984
2984
  let tokenAccount;
2985
2985
  if (createWSOLTokenAccount) {
2986
- const { ixs, signers, pubkey } = await this.getWrappedSolAccountCreationIxs(numericConstants_1.ZERO, true);
2986
+ const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(numericConstants_1.ZERO, true);
2987
2987
  tokenAccount = pubkey;
2988
2988
  ixs.forEach((ix) => {
2989
2989
  tx.add(ix);
2990
2990
  });
2991
- signers.forEach((signer) => additionalSigners.push(signer));
2992
2991
  }
2993
2992
  else {
2994
2993
  tokenAccount = collateralAccountPublicKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.36.1-beta.0",
3
+ "version": "2.36.1-beta.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -1568,16 +1568,16 @@ export class DriftClient {
1568
1568
  isSolMarket && associatedTokenAccount.equals(signerAuthority);
1569
1569
 
1570
1570
  if (createWSOLTokenAccount) {
1571
- const { ixs, signers, pubkey } =
1572
- await this.getWrappedSolAccountCreationIxs(amount, true);
1571
+ const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(
1572
+ amount,
1573
+ true
1574
+ );
1573
1575
 
1574
1576
  associatedTokenAccount = pubkey;
1575
1577
 
1576
1578
  ixs.forEach((ix) => {
1577
1579
  tx.add(ix);
1578
1580
  });
1579
-
1580
- signers.forEach((signer) => additionalSigners.push(signer));
1581
1581
  }
1582
1582
 
1583
1583
  const depositCollateralIx = await this.getDepositInstruction(
@@ -1677,15 +1677,26 @@ export class DriftClient {
1677
1677
  includeRent?: boolean
1678
1678
  ): Promise<{
1679
1679
  ixs: anchor.web3.TransactionInstruction[];
1680
+ /** @deprecated - this array is always going to be empty, in the current implementation */
1680
1681
  signers: Signer[];
1681
1682
  pubkey: PublicKey;
1682
1683
  }> {
1683
- const wrappedSolAccount = new Keypair();
1684
+ const authority = this.wallet.publicKey;
1685
+
1686
+ // Generate a random seed for wrappedSolAccount.
1687
+ const seed = Keypair.generate().publicKey.toBase58().slice(0, 32);
1688
+
1689
+ // Calculate a publicKey that will be controlled by the authority.
1690
+ const wrappedSolAccount = await PublicKey.createWithSeed(
1691
+ authority,
1692
+ seed,
1693
+ TOKEN_PROGRAM_ID
1694
+ );
1684
1695
 
1685
1696
  const result = {
1686
1697
  ixs: [],
1687
1698
  signers: [],
1688
- pubkey: wrappedSolAccount.publicKey,
1699
+ pubkey: wrappedSolAccount,
1689
1700
  };
1690
1701
 
1691
1702
  const rentSpaceLamports = new BN(LAMPORTS_PER_SOL / 100);
@@ -1694,12 +1705,12 @@ export class DriftClient {
1694
1705
  ? amount.add(rentSpaceLamports)
1695
1706
  : rentSpaceLamports;
1696
1707
 
1697
- const authority = this.wallet.publicKey;
1698
-
1699
1708
  result.ixs.push(
1700
- SystemProgram.createAccount({
1709
+ SystemProgram.createAccountWithSeed({
1701
1710
  fromPubkey: authority,
1702
- newAccountPubkey: wrappedSolAccount.publicKey,
1711
+ basePubkey: authority,
1712
+ seed,
1713
+ newAccountPubkey: wrappedSolAccount,
1703
1714
  lamports: lamports.toNumber(),
1704
1715
  space: 165,
1705
1716
  programId: TOKEN_PROGRAM_ID,
@@ -1708,14 +1719,12 @@ export class DriftClient {
1708
1719
 
1709
1720
  result.ixs.push(
1710
1721
  createInitializeAccountInstruction(
1711
- wrappedSolAccount.publicKey,
1722
+ wrappedSolAccount,
1712
1723
  WRAPPED_SOL_MINT,
1713
1724
  authority
1714
1725
  )
1715
1726
  );
1716
1727
 
1717
- result.signers.push(wrappedSolAccount);
1718
-
1719
1728
  return result;
1720
1729
  }
1721
1730
 
@@ -1791,19 +1800,14 @@ export class DriftClient {
1791
1800
  isSolMarket && userTokenAccount.equals(authority) && !isFromSubaccount;
1792
1801
 
1793
1802
  if (createWSOLTokenAccount) {
1794
- const {
1795
- ixs: startIxs,
1796
- signers,
1797
- pubkey,
1798
- } = await this.getWrappedSolAccountCreationIxs(amount, true);
1803
+ const { ixs: startIxs, pubkey } =
1804
+ await this.getWrappedSolAccountCreationIxs(amount, true);
1799
1805
 
1800
1806
  userTokenAccount = pubkey;
1801
1807
 
1802
1808
  startIxs.forEach((ix) => {
1803
1809
  tx.add(ix);
1804
1810
  });
1805
-
1806
- signers.forEach((signer) => additionalSigners.push(signer));
1807
1811
  }
1808
1812
 
1809
1813
  const depositCollateralIx = isFromSubaccount
@@ -1935,16 +1939,16 @@ export class DriftClient {
1935
1939
  isSolMarket && associatedTokenAddress.equals(authority);
1936
1940
 
1937
1941
  if (createWSOLTokenAccount) {
1938
- const { ixs, signers, pubkey } =
1939
- await this.getWrappedSolAccountCreationIxs(amount, false);
1942
+ const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(
1943
+ amount,
1944
+ false
1945
+ );
1940
1946
 
1941
1947
  associatedTokenAddress = pubkey;
1942
1948
 
1943
1949
  ixs.forEach((ix) => {
1944
1950
  tx.add(ix);
1945
1951
  });
1946
-
1947
- signers.forEach((signer) => additionalSigners.push(signer));
1948
1952
  } else {
1949
1953
  const accountExists = await this.checkIfAccountExists(
1950
1954
  associatedTokenAddress
@@ -5251,14 +5255,14 @@ export class DriftClient {
5251
5255
  let tokenAccount;
5252
5256
 
5253
5257
  if (createWSOLTokenAccount) {
5254
- const { ixs, signers, pubkey } =
5255
- await this.getWrappedSolAccountCreationIxs(amount, true);
5258
+ const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(
5259
+ amount,
5260
+ true
5261
+ );
5256
5262
  tokenAccount = pubkey;
5257
5263
  ixs.forEach((ix) => {
5258
5264
  tx.add(ix);
5259
5265
  });
5260
-
5261
- signers.forEach((signer) => additionalSigners.push(signer));
5262
5266
  } else {
5263
5267
  tokenAccount = collateralAccountPublicKey;
5264
5268
  }
@@ -5400,14 +5404,14 @@ export class DriftClient {
5400
5404
  let tokenAccount;
5401
5405
 
5402
5406
  if (createWSOLTokenAccount) {
5403
- const { ixs, signers, pubkey } =
5404
- await this.getWrappedSolAccountCreationIxs(ZERO, true);
5407
+ const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(
5408
+ ZERO,
5409
+ true
5410
+ );
5405
5411
  tokenAccount = pubkey;
5406
5412
  ixs.forEach((ix) => {
5407
5413
  tx.add(ix);
5408
5414
  });
5409
-
5410
- signers.forEach((signer) => additionalSigners.push(signer));
5411
5415
  } else {
5412
5416
  tokenAccount = collateralAccountPublicKey;
5413
5417
  }