@drift-labs/sdk 2.36.1-beta.0 → 2.36.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.36.1-beta.0
1
+ 2.36.1-beta.2
@@ -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
  }>;
@@ -549,6 +550,8 @@ export declare class DriftClient {
549
550
  getResolveSpotBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
550
551
  updateFundingRate(perpMarketIndex: number, oracle: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
551
552
  getUpdateFundingRateIx(perpMarketIndex: number, oracle: PublicKey): Promise<TransactionInstruction>;
553
+ updatePerpBidAskTwap(perpMarketIndex: number, makers: [PublicKey, PublicKey][], txParams?: TxParams): Promise<TransactionSignature>;
554
+ getUpdatePerpBidAskTwapIx(perpMarketIndex: number, makers: [PublicKey, PublicKey][]): Promise<TransactionInstruction>;
552
555
  settleFundingPayment(userAccountPublicKey: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
553
556
  getSettleFundingPaymentIx(userAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
554
557
  triggerEvent(eventName: keyof DriftClientAccountEvents, data?: any): void;
@@ -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);
@@ -2812,6 +2813,36 @@ class DriftClient {
2812
2813
  },
2813
2814
  });
2814
2815
  }
2816
+ async updatePerpBidAskTwap(perpMarketIndex, makers, txParams) {
2817
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdatePerpBidAskTwapIx(perpMarketIndex, makers), txParams), [], this.opts);
2818
+ return txSig;
2819
+ }
2820
+ async getUpdatePerpBidAskTwapIx(perpMarketIndex, makers) {
2821
+ const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
2822
+ const remainingAccounts = [];
2823
+ for (const [maker, makerStats] of makers) {
2824
+ remainingAccounts.push({
2825
+ pubkey: maker,
2826
+ isWritable: false,
2827
+ isSigner: false,
2828
+ });
2829
+ remainingAccounts.push({
2830
+ pubkey: makerStats,
2831
+ isWritable: false,
2832
+ isSigner: false,
2833
+ });
2834
+ }
2835
+ return await this.program.instruction.updatePerpBidAskTwap(perpMarketIndex, {
2836
+ accounts: {
2837
+ state: await this.getStatePublicKey(),
2838
+ perpMarket: perpMarket.pubkey,
2839
+ oracle: perpMarket.amm.oracle,
2840
+ authority: this.wallet.publicKey,
2841
+ keeperStats: this.getUserStatsAccountPublicKey(),
2842
+ },
2843
+ remainingAccounts,
2844
+ });
2845
+ }
2815
2846
  async settleFundingPayment(userAccountPublicKey, txParams) {
2816
2847
  const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getSettleFundingPaymentIx(userAccountPublicKey), txParams), [], this.opts);
2817
2848
  return txSig;
@@ -2904,12 +2935,11 @@ class DriftClient {
2904
2935
  const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
2905
2936
  let tokenAccount;
2906
2937
  if (createWSOLTokenAccount) {
2907
- const { ixs, signers, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, true);
2938
+ const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, true);
2908
2939
  tokenAccount = pubkey;
2909
2940
  ixs.forEach((ix) => {
2910
2941
  tx.add(ix);
2911
2942
  });
2912
- signers.forEach((signer) => additionalSigners.push(signer));
2913
2943
  }
2914
2944
  else {
2915
2945
  tokenAccount = collateralAccountPublicKey;
@@ -2983,12 +3013,11 @@ class DriftClient {
2983
3013
  const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
2984
3014
  let tokenAccount;
2985
3015
  if (createWSOLTokenAccount) {
2986
- const { ixs, signers, pubkey } = await this.getWrappedSolAccountCreationIxs(numericConstants_1.ZERO, true);
3016
+ const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(numericConstants_1.ZERO, true);
2987
3017
  tokenAccount = pubkey;
2988
3018
  ixs.forEach((ix) => {
2989
3019
  tx.add(ix);
2990
3020
  });
2991
- signers.forEach((signer) => additionalSigners.push(signer));
2992
3021
  }
2993
3022
  else {
2994
3023
  tokenAccount = collateralAccountPublicKey;
@@ -1932,6 +1932,42 @@
1932
1932
  }
1933
1933
  ]
1934
1934
  },
1935
+ {
1936
+ "name": "updatePerpBidAskTwap",
1937
+ "accounts": [
1938
+ {
1939
+ "name": "state",
1940
+ "isMut": false,
1941
+ "isSigner": false
1942
+ },
1943
+ {
1944
+ "name": "perpMarket",
1945
+ "isMut": true,
1946
+ "isSigner": false
1947
+ },
1948
+ {
1949
+ "name": "oracle",
1950
+ "isMut": false,
1951
+ "isSigner": false
1952
+ },
1953
+ {
1954
+ "name": "user",
1955
+ "isMut": true,
1956
+ "isSigner": false
1957
+ },
1958
+ {
1959
+ "name": "userStats",
1960
+ "isMut": true,
1961
+ "isSigner": false
1962
+ },
1963
+ {
1964
+ "name": "authority",
1965
+ "isMut": false,
1966
+ "isSigner": true
1967
+ }
1968
+ ],
1969
+ "args": []
1970
+ },
1935
1971
  {
1936
1972
  "name": "updateSpotMarketCumulativeInterest",
1937
1973
  "accounts": [
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.2",
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
@@ -5069,6 +5073,57 @@ export class DriftClient {
5069
5073
  });
5070
5074
  }
5071
5075
 
5076
+ public async updatePerpBidAskTwap(
5077
+ perpMarketIndex: number,
5078
+ makers: [PublicKey, PublicKey][],
5079
+ txParams?: TxParams
5080
+ ): Promise<TransactionSignature> {
5081
+ const { txSig } = await this.sendTransaction(
5082
+ await this.buildTransaction(
5083
+ await this.getUpdatePerpBidAskTwapIx(perpMarketIndex, makers),
5084
+ txParams
5085
+ ),
5086
+ [],
5087
+ this.opts
5088
+ );
5089
+ return txSig;
5090
+ }
5091
+
5092
+ public async getUpdatePerpBidAskTwapIx(
5093
+ perpMarketIndex: number,
5094
+ makers: [PublicKey, PublicKey][]
5095
+ ): Promise<TransactionInstruction> {
5096
+ const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
5097
+
5098
+ const remainingAccounts = [];
5099
+ for (const [maker, makerStats] of makers) {
5100
+ remainingAccounts.push({
5101
+ pubkey: maker,
5102
+ isWritable: false,
5103
+ isSigner: false,
5104
+ });
5105
+ remainingAccounts.push({
5106
+ pubkey: makerStats,
5107
+ isWritable: false,
5108
+ isSigner: false,
5109
+ });
5110
+ }
5111
+
5112
+ return await this.program.instruction.updatePerpBidAskTwap(
5113
+ perpMarketIndex,
5114
+ {
5115
+ accounts: {
5116
+ state: await this.getStatePublicKey(),
5117
+ perpMarket: perpMarket.pubkey,
5118
+ oracle: perpMarket.amm.oracle,
5119
+ authority: this.wallet.publicKey,
5120
+ keeperStats: this.getUserStatsAccountPublicKey(),
5121
+ },
5122
+ remainingAccounts,
5123
+ }
5124
+ );
5125
+ }
5126
+
5072
5127
  public async settleFundingPayment(
5073
5128
  userAccountPublicKey: PublicKey,
5074
5129
  txParams?: TxParams
@@ -5251,14 +5306,14 @@ export class DriftClient {
5251
5306
  let tokenAccount;
5252
5307
 
5253
5308
  if (createWSOLTokenAccount) {
5254
- const { ixs, signers, pubkey } =
5255
- await this.getWrappedSolAccountCreationIxs(amount, true);
5309
+ const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(
5310
+ amount,
5311
+ true
5312
+ );
5256
5313
  tokenAccount = pubkey;
5257
5314
  ixs.forEach((ix) => {
5258
5315
  tx.add(ix);
5259
5316
  });
5260
-
5261
- signers.forEach((signer) => additionalSigners.push(signer));
5262
5317
  } else {
5263
5318
  tokenAccount = collateralAccountPublicKey;
5264
5319
  }
@@ -5400,14 +5455,14 @@ export class DriftClient {
5400
5455
  let tokenAccount;
5401
5456
 
5402
5457
  if (createWSOLTokenAccount) {
5403
- const { ixs, signers, pubkey } =
5404
- await this.getWrappedSolAccountCreationIxs(ZERO, true);
5458
+ const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(
5459
+ ZERO,
5460
+ true
5461
+ );
5405
5462
  tokenAccount = pubkey;
5406
5463
  ixs.forEach((ix) => {
5407
5464
  tx.add(ix);
5408
5465
  });
5409
-
5410
- signers.forEach((signer) => additionalSigners.push(signer));
5411
5466
  } else {
5412
5467
  tokenAccount = collateralAccountPublicKey;
5413
5468
  }
@@ -1932,6 +1932,42 @@
1932
1932
  }
1933
1933
  ]
1934
1934
  },
1935
+ {
1936
+ "name": "updatePerpBidAskTwap",
1937
+ "accounts": [
1938
+ {
1939
+ "name": "state",
1940
+ "isMut": false,
1941
+ "isSigner": false
1942
+ },
1943
+ {
1944
+ "name": "perpMarket",
1945
+ "isMut": true,
1946
+ "isSigner": false
1947
+ },
1948
+ {
1949
+ "name": "oracle",
1950
+ "isMut": false,
1951
+ "isSigner": false
1952
+ },
1953
+ {
1954
+ "name": "user",
1955
+ "isMut": true,
1956
+ "isSigner": false
1957
+ },
1958
+ {
1959
+ "name": "userStats",
1960
+ "isMut": true,
1961
+ "isSigner": false
1962
+ },
1963
+ {
1964
+ "name": "authority",
1965
+ "isMut": false,
1966
+ "isSigner": true
1967
+ }
1968
+ ],
1969
+ "args": []
1970
+ },
1935
1971
  {
1936
1972
  "name": "updateSpotMarketCumulativeInterest",
1937
1973
  "accounts": [