@drift-labs/sdk 2.146.0-beta.9 → 2.147.0-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.
Files changed (57) hide show
  1. package/VERSION +1 -1
  2. package/lib/browser/accounts/grpcMultiUserAccountSubscriber.js +8 -1
  3. package/lib/browser/adminClient.d.ts +3 -3
  4. package/lib/browser/adminClient.js +13 -17
  5. package/lib/browser/constants/numericConstants.d.ts +2 -0
  6. package/lib/browser/constants/numericConstants.js +5 -1
  7. package/lib/browser/constants/perpMarkets.d.ts +2 -1
  8. package/lib/browser/constants/perpMarkets.js +31 -1
  9. package/lib/browser/constants/spotMarkets.d.ts +2 -0
  10. package/lib/browser/constants/spotMarkets.js +21 -14
  11. package/lib/browser/driftClient.d.ts +22 -12
  12. package/lib/browser/driftClient.js +37 -25
  13. package/lib/browser/idl/drift.json +38 -251
  14. package/lib/browser/math/superStake.d.ts +1 -1
  15. package/lib/browser/math/superStake.js +1 -1
  16. package/lib/browser/swap/UnifiedSwapClient.d.ts +28 -3
  17. package/lib/browser/swap/UnifiedSwapClient.js +2 -2
  18. package/lib/browser/types.d.ts +3 -1
  19. package/lib/browser/types.js +1 -0
  20. package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts.map +1 -1
  21. package/lib/node/accounts/grpcMultiUserAccountSubscriber.js +8 -1
  22. package/lib/node/adminClient.d.ts +3 -3
  23. package/lib/node/adminClient.d.ts.map +1 -1
  24. package/lib/node/adminClient.js +13 -17
  25. package/lib/node/constants/numericConstants.d.ts +2 -0
  26. package/lib/node/constants/numericConstants.d.ts.map +1 -1
  27. package/lib/node/constants/numericConstants.js +5 -1
  28. package/lib/node/constants/perpMarkets.d.ts +2 -1
  29. package/lib/node/constants/perpMarkets.d.ts.map +1 -1
  30. package/lib/node/constants/perpMarkets.js +31 -1
  31. package/lib/node/constants/spotMarkets.d.ts +2 -0
  32. package/lib/node/constants/spotMarkets.d.ts.map +1 -1
  33. package/lib/node/constants/spotMarkets.js +21 -14
  34. package/lib/node/driftClient.d.ts +22 -12
  35. package/lib/node/driftClient.d.ts.map +1 -1
  36. package/lib/node/driftClient.js +37 -25
  37. package/lib/node/idl/drift.json +38 -251
  38. package/lib/node/math/superStake.d.ts +1 -1
  39. package/lib/node/math/superStake.js +1 -1
  40. package/lib/node/swap/UnifiedSwapClient.d.ts +28 -3
  41. package/lib/node/swap/UnifiedSwapClient.d.ts.map +1 -1
  42. package/lib/node/swap/UnifiedSwapClient.js +2 -2
  43. package/lib/node/types.d.ts +3 -1
  44. package/lib/node/types.d.ts.map +1 -1
  45. package/lib/node/types.js +1 -0
  46. package/package.json +1 -1
  47. package/src/accounts/grpcMultiUserAccountSubscriber.ts +8 -1
  48. package/src/adminClient.ts +28 -30
  49. package/src/constants/numericConstants.ts +5 -0
  50. package/src/constants/perpMarkets.ts +33 -3
  51. package/src/constants/spotMarkets.ts +23 -14
  52. package/src/driftClient.ts +65 -36
  53. package/src/idl/drift.json +39 -252
  54. package/src/math/superStake.ts +1 -1
  55. package/src/swap/UnifiedSwapClient.ts +25 -3
  56. package/src/types.ts +2 -0
  57. package/tests/dlob/helpers.ts +3 -3
@@ -12,6 +12,7 @@ import {
12
12
  import { OracleSource } from '../types';
13
13
  import { BN } from '@coral-xyz/anchor';
14
14
  import { DriftEnv } from '../config';
15
+ import { MarketStatus } from '@ellipsis-labs/phoenix-sdk';
15
16
 
16
17
  export type SpotMarketConfig = {
17
18
  symbol: string;
@@ -28,6 +29,7 @@ export type SpotMarketConfig = {
28
29
  launchTs?: number;
29
30
  pythFeedId?: string;
30
31
  pythLazerId?: number;
32
+ marketStatus?: MarketStatus;
31
33
  };
32
34
 
33
35
  export const WRAPPED_SOL_MINT = new PublicKey(
@@ -193,14 +195,15 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
193
195
  symbol: 'mSOL',
194
196
  marketIndex: 2,
195
197
  poolId: 0,
196
- oracle: new PublicKey('FAq7hqjn7FWGXKDwJHzsXGgBcydGTcK4kziJpAGWXjDb'),
197
- oracleSource: OracleSource.PYTH_PULL,
198
+ oracle: new PublicKey('FY2JMi1vYz1uayVT2GJ96ysZgpagjhdPRG2upNPtSZsC'),
199
+ oracleSource: OracleSource.PYTH_LAZER,
198
200
  mint: new PublicKey('mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So'),
199
201
  precision: new BN(10).pow(NINE),
200
202
  precisionExp: NINE,
201
203
  serumMarket: new PublicKey('9Lyhks5bQQxb9EyyX55NtgKQzpM4WK7JCmeaWuQ5MoXD'),
202
204
  pythFeedId:
203
205
  '0xc2289a6a43d2ce91c6f55caec370f4acc38a2ed477f58813334c6d03749ff2a4',
206
+ pythLazerId: 503,
204
207
  },
205
208
  {
206
209
  symbol: 'wBTC',
@@ -253,8 +256,8 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
253
256
  symbol: 'jitoSOL',
254
257
  marketIndex: 6,
255
258
  poolId: 0,
256
- oracle: new PublicKey('9QE1P5EfzthYDgoQ9oPeTByCEKaRJeZbVVqKJfgU9iau'),
257
- oracleSource: OracleSource.PYTH_PULL,
259
+ oracle: new PublicKey('2cHCtAkMnttMh3bNKSCgSKSP5D4yN3p8bfnMdS3VZsDf'),
260
+ oracleSource: OracleSource.PYTH_LAZER,
258
261
  mint: new PublicKey('J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn'),
259
262
  precision: new BN(10).pow(NINE),
260
263
  precisionExp: NINE,
@@ -264,6 +267,7 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
264
267
  ),
265
268
  pythFeedId:
266
269
  '0x67be9f519b95cf24338801051f9a808eff0a578ccb388db73b7f6fe1de019ffb',
270
+ pythLazerId: 458,
267
271
  },
268
272
  {
269
273
  symbol: 'PYTH',
@@ -530,25 +534,27 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
530
534
  symbol: 'sUSDe',
531
535
  marketIndex: 24,
532
536
  poolId: 0,
533
- oracle: new PublicKey('BRuNuzLAPHHGSSVAJPKMcmJMdgDfrekvnSxkxPDGdeqp'),
534
- oracleSource: OracleSource.PYTH_PULL,
537
+ oracle: new PublicKey('CX7JCXtUTiC43ZA4uzoH7iQBD15jtVwdBNCnjKHt1BrQ'),
538
+ oracleSource: OracleSource.PYTH_LAZER,
535
539
  mint: new PublicKey('Eh6XEPhSwoLv5wFApukmnaVSHQ6sAnoD9BmgmwQoN2sN'),
536
540
  precision: new BN(10).pow(NINE),
537
541
  precisionExp: NINE,
538
542
  pythFeedId:
539
543
  '0xca3ba9a619a4b3755c10ac7d5e760275aa95e9823d38a84fedd416856cdba37c',
544
+ pythLazerId: 582,
540
545
  },
541
546
  {
542
547
  symbol: 'BNSOL',
543
548
  marketIndex: 25,
544
549
  poolId: 0,
545
- oracle: new PublicKey('8DmXTfhhtb9kTcpTVfb6Ygx8WhZ8wexGqcpxfn23zooe'),
546
- oracleSource: OracleSource.PYTH_PULL,
550
+ oracle: new PublicKey('2LxMbHBHsw74aE3XgfthmUNkdDfUGcSEy3G3D3t642fd'),
551
+ oracleSource: OracleSource.PYTH_LAZER,
547
552
  mint: new PublicKey('BNso1VUJnh4zcfpZa6986Ea66P6TCp59hvtNJ8b1X85'),
548
553
  precision: LAMPORTS_PRECISION,
549
554
  precisionExp: LAMPORTS_EXP,
550
555
  pythFeedId:
551
556
  '0x55f8289be7450f1ae564dd9798e49e7d797d89adbc54fe4f8c906b1fcb94b0c3',
557
+ pythLazerId: 384,
552
558
  },
553
559
  {
554
560
  symbol: 'MOTHER',
@@ -582,13 +588,14 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
582
588
  symbol: 'USDS',
583
589
  marketIndex: 28,
584
590
  poolId: 0,
585
- oracle: new PublicKey('7pT9mxKXyvfaZKeKy1oe2oV2K1RFtF7tPEJHUY3h2vVV'),
586
- oracleSource: OracleSource.PYTH_STABLE_COIN_PULL,
591
+ oracle: new PublicKey('5Km85n3s9Zs5wEoXYWuHbpoDzst4EBkS5f1XuQJGG1DL'),
592
+ oracleSource: OracleSource.PYTH_LAZER_STABLE_COIN,
587
593
  mint: new PublicKey('USDSwr9ApdHk5bvJKMjzff41FfuX8bSxdKcR81vTwcA'),
588
594
  precision: new BN(10).pow(SIX),
589
595
  precisionExp: SIX,
590
596
  pythFeedId:
591
597
  '0x77f0971af11cc8bac224917275c1bf55f2319ed5c654a1ca955c82fa2d297ea1',
598
+ pythLazerId: 611,
592
599
  },
593
600
  {
594
601
  symbol: 'META',
@@ -716,14 +723,15 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
716
723
  symbol: 'AUSD',
717
724
  marketIndex: 38,
718
725
  poolId: 0,
719
- oracle: new PublicKey('8FZhpiM8n3mpgvENWLcEvHsKB1bBhYBAyL4Ypr4gptLZ'),
720
- oracleSource: OracleSource.PYTH_STABLE_COIN_PULL,
726
+ oracle: new PublicKey('9JYpqJfLXgrW8Wqzfd93GvJF73m2jJFjNqpQv3wQtehZ'),
727
+ oracleSource: OracleSource.PYTH_LAZER_STABLE_COIN,
721
728
  mint: new PublicKey('AUSD1jCcCyPLybk1YnvPWsHQSrZ46dxwoMniN4N2UEB9'),
722
729
  precision: new BN(10).pow(SIX),
723
730
  precisionExp: SIX,
724
731
  pythFeedId:
725
732
  '0xd9912df360b5b7f21a122f15bdd5e27f62ce5e72bd316c291f7c86620e07fb2a',
726
733
  launchTs: 1738255943000,
734
+ pythLazerId: 367,
727
735
  },
728
736
  {
729
737
  symbol: 'FARTCOIN',
@@ -797,14 +805,15 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
797
805
  symbol: 'zBTC',
798
806
  marketIndex: 45,
799
807
  poolId: 0,
800
- oracle: new PublicKey('CN9QvvbGQzMnN8vJaSek2so4vFnTqgJDFrdJB8Y4tQfB'),
801
- oracleSource: OracleSource.PYTH_PULL,
808
+ oracle: new PublicKey('3xcpvBUVV8ALVV4Wod733Vyic3fe8iJAeXDpRdk19Z3p'),
809
+ oracleSource: OracleSource.PYTH_LAZER,
802
810
  mint: new PublicKey('zBTCug3er3tLyffELcvDNrKkCymbPWysGcWihESYfLg'),
803
811
  precision: new BN(10).pow(EIGHT),
804
812
  precisionExp: EIGHT,
805
813
  pythFeedId:
806
814
  '0x3d824c7f7c26ed1c85421ecec8c754e6b52d66a4e45de20a9c9ea91de8b396f9',
807
815
  launchTs: 1747155600000,
816
+ pythLazerId: 640,
808
817
  },
809
818
  {
810
819
  symbol: 'ZEUS',
@@ -172,7 +172,7 @@ import { calculateMarketMaxAvailableInsurance } from './math/market';
172
172
  import { fetchUserStatsAccount } from './accounts/fetch';
173
173
  import { castNumberToSpotPrecision } from './math/spotMarket';
174
174
  import { JupiterClient, QuoteResponse } from './jupiter/jupiterClient';
175
- import { SwapMode } from './swap/UnifiedSwapClient';
175
+ import { SwapMode, UnifiedQuoteResponse } from './swap/UnifiedSwapClient';
176
176
  import { getNonIdleUserFilter } from './memcmp';
177
177
  import { UserStatsSubscriptionConfig } from './userStatsConfig';
178
178
  import { getMarinadeDepositIx, getMarinadeFinanceProgram } from './marinade';
@@ -1776,15 +1776,24 @@ export class DriftClient {
1776
1776
  public async getUpdateUserPerpPositionCustomMarginRatioIx(
1777
1777
  perpMarketIndex: number,
1778
1778
  marginRatio: number,
1779
- subAccountId = 0
1779
+ subAccountId = 0,
1780
+ overrides?: {
1781
+ userAccountPublicKey?: PublicKey;
1782
+ authority?: PublicKey;
1783
+ signingAuthority?: PublicKey;
1784
+ }
1780
1785
  ): Promise<TransactionInstruction> {
1781
- const userAccountPublicKey = getUserAccountPublicKeySync(
1782
- this.program.programId,
1783
- this.authority,
1784
- subAccountId
1785
- );
1786
+ let userAccountPublicKey = overrides?.userAccountPublicKey;
1787
+ if (!userAccountPublicKey) {
1788
+ userAccountPublicKey = getUserAccountPublicKeySync(
1789
+ this.program.programId,
1790
+ overrides?.authority ?? this.authority,
1791
+ subAccountId
1792
+ );
1793
+ }
1786
1794
 
1787
- await this.addUser(subAccountId, this.authority);
1795
+ const signingAuthority =
1796
+ overrides?.signingAuthority ?? this.wallet.publicKey;
1788
1797
 
1789
1798
  const ix = this.program.instruction.updateUserPerpPositionCustomMarginRatio(
1790
1799
  subAccountId,
@@ -1793,7 +1802,7 @@ export class DriftClient {
1793
1802
  {
1794
1803
  accounts: {
1795
1804
  user: userAccountPublicKey,
1796
- authority: this.wallet.publicKey,
1805
+ authority: signingAuthority,
1797
1806
  },
1798
1807
  }
1799
1808
  );
@@ -5756,21 +5765,23 @@ export class DriftClient {
5756
5765
  /**
5757
5766
  * Swap tokens in drift account using titan or jupiter
5758
5767
  * @param swapClient swap client to find routes and instructions (Titan or Jupiter)
5768
+ * @param jupiterClient @deprecated Use swapClient instead. Legacy parameter for backward compatibility
5759
5769
  * @param outMarketIndex the market index of the token you're buying
5760
5770
  * @param inMarketIndex the market index of the token you're selling
5761
- * @param outAssociatedTokenAccount the token account to receive the token being sold on titan or jupiter
5771
+ * @param outAssociatedTokenAccount the token account to receive the token being sold on the swap provider
5762
5772
  * @param inAssociatedTokenAccount the token account to
5763
5773
  * @param amount the amount of TokenIn, regardless of swapMode
5764
- * @param slippageBps the max slippage passed to titan or jupiter api
5765
- * @param swapMode titan or jupiter swapMode (ExactIn or ExactOut), default is ExactIn
5766
- * @param route the titan or jupiter route to use for the swap
5774
+ * @param slippageBps the max slippage passed to the swap provider api
5775
+ * @param swapMode swap provider swapMode (ExactIn or ExactOut), default is ExactIn
5776
+ * @param route the swap provider route to use for the swap
5767
5777
  * @param reduceOnly specify if In or Out token on the drift account must reduceOnly, checked at end of swap
5768
- * @param v6 pass in the quote response from Jupiter quote's API (deprecated, use quote instead)
5769
- * @param quote pass in the quote response from Jupiter quote's API
5778
+ * @param v6 pass in the quote response from swap provider quote's API (deprecated, use quote instead)
5779
+ * @param quote pass in the quote response from swap provider quote's API
5770
5780
  * @param txParams
5771
5781
  */
5772
5782
  public async swap({
5773
5783
  swapClient,
5784
+ jupiterClient,
5774
5785
  outMarketIndex,
5775
5786
  inMarketIndex,
5776
5787
  outAssociatedTokenAccount,
@@ -5784,7 +5795,9 @@ export class DriftClient {
5784
5795
  quote,
5785
5796
  onlyDirectRoutes = false,
5786
5797
  }: {
5787
- swapClient: UnifiedSwapClient | SwapClient;
5798
+ swapClient?: UnifiedSwapClient | SwapClient;
5799
+ /** @deprecated Use swapClient instead. Legacy parameter for backward compatibility */
5800
+ jupiterClient?: JupiterClient;
5788
5801
  outMarketIndex: number;
5789
5802
  inMarketIndex: number;
5790
5803
  outAssociatedTokenAccount?: PublicKey;
@@ -5798,17 +5811,24 @@ export class DriftClient {
5798
5811
  v6?: {
5799
5812
  quote?: QuoteResponse;
5800
5813
  };
5801
- quote?: QuoteResponse;
5814
+ quote?: UnifiedQuoteResponse;
5802
5815
  }): Promise<TransactionSignature> {
5816
+ // Handle backward compatibility: use jupiterClient if swapClient is not provided
5817
+ const clientToUse = swapClient || jupiterClient;
5818
+
5819
+ if (!clientToUse) {
5820
+ throw new Error('Either swapClient or jupiterClient must be provided');
5821
+ }
5822
+
5803
5823
  let res: {
5804
5824
  ixs: TransactionInstruction[];
5805
5825
  lookupTables: AddressLookupTableAccount[];
5806
5826
  };
5807
5827
 
5808
5828
  // Use unified SwapClient if available
5809
- if (swapClient instanceof UnifiedSwapClient) {
5829
+ if (clientToUse instanceof UnifiedSwapClient) {
5810
5830
  res = await this.getSwapIxV2({
5811
- swapClient,
5831
+ swapClient: clientToUse,
5812
5832
  outMarketIndex,
5813
5833
  inMarketIndex,
5814
5834
  outAssociatedTokenAccount,
@@ -5821,9 +5841,9 @@ export class DriftClient {
5821
5841
  quote,
5822
5842
  v6,
5823
5843
  });
5824
- } else if (swapClient instanceof TitanClient) {
5844
+ } else if (clientToUse instanceof TitanClient) {
5825
5845
  res = await this.getTitanSwapIx({
5826
- titanClient: swapClient,
5846
+ titanClient: clientToUse,
5827
5847
  outMarketIndex,
5828
5848
  inMarketIndex,
5829
5849
  outAssociatedTokenAccount,
@@ -5834,10 +5854,10 @@ export class DriftClient {
5834
5854
  onlyDirectRoutes,
5835
5855
  reduceOnly,
5836
5856
  });
5837
- } else if (swapClient instanceof JupiterClient) {
5857
+ } else if (clientToUse instanceof JupiterClient) {
5838
5858
  const quoteToUse = quote ?? v6?.quote;
5839
5859
  res = await this.getJupiterSwapIxV6({
5840
- jupiterClient: swapClient,
5860
+ jupiterClient: clientToUse,
5841
5861
  outMarketIndex,
5842
5862
  inMarketIndex,
5843
5863
  outAssociatedTokenAccount,
@@ -5845,7 +5865,7 @@ export class DriftClient {
5845
5865
  amount,
5846
5866
  slippageBps,
5847
5867
  swapMode,
5848
- quote: quoteToUse,
5868
+ quote: quoteToUse as QuoteResponse,
5849
5869
  reduceOnly,
5850
5870
  onlyDirectRoutes,
5851
5871
  });
@@ -6039,7 +6059,7 @@ export class DriftClient {
6039
6059
  }
6040
6060
 
6041
6061
  if (!quote) {
6042
- throw new Error("Could not fetch Jupiter's quote. Please try again.");
6062
+ throw new Error('Could not fetch swap quote. Please try again.');
6043
6063
  }
6044
6064
 
6045
6065
  const isExactOut = swapMode === 'ExactOut' || quote.swapMode === 'ExactOut';
@@ -6295,7 +6315,7 @@ export class DriftClient {
6295
6315
  swapMode?: SwapMode;
6296
6316
  onlyDirectRoutes?: boolean;
6297
6317
  reduceOnly?: SwapReduceOnly;
6298
- quote?: QuoteResponse;
6318
+ quote?: UnifiedQuoteResponse;
6299
6319
  v6?: {
6300
6320
  quote?: QuoteResponse;
6301
6321
  };
@@ -8890,7 +8910,7 @@ export class DriftClient {
8890
8910
  }
8891
8911
 
8892
8912
  if (!quote) {
8893
- throw new Error("Could not fetch Jupiter's quote. Please try again.");
8913
+ throw new Error('Could not fetch swap quote. Please try again.');
8894
8914
  }
8895
8915
 
8896
8916
  const amountIn = new BN(quote.inAmount);
@@ -10969,14 +10989,27 @@ export class DriftClient {
10969
10989
  isMakingNewAccount: boolean;
10970
10990
  depositMarketIndex: number;
10971
10991
  orderMarketIndex: number;
10992
+ },
10993
+ overrides?: {
10994
+ user?: User;
10995
+ signingAuthority?: PublicKey;
10972
10996
  }
10973
10997
  ): Promise<TransactionInstruction> {
10974
10998
  const isDepositToTradeTx = depositToTradeArgs !== undefined;
10999
+ const userAccountPublicKey =
11000
+ overrides?.user?.getUserAccountPublicKey() ??
11001
+ getUserAccountPublicKeySync(
11002
+ this.program.programId,
11003
+ this.wallet.publicKey,
11004
+ subAccountId
11005
+ );
11006
+ const signingAuthority =
11007
+ overrides?.signingAuthority ?? this.wallet.publicKey;
11008
+ const userAccount =
11009
+ overrides?.user.getUserAccount() ?? this.getUserAccount(subAccountId);
10975
11010
 
10976
11011
  const remainingAccounts = this.getRemainingAccounts({
10977
- userAccounts: depositToTradeArgs?.isMakingNewAccount
10978
- ? []
10979
- : [this.getUserAccount(subAccountId)],
11012
+ userAccounts: depositToTradeArgs?.isMakingNewAccount ? [] : [userAccount],
10980
11013
  useMarketLastSlotCache: false,
10981
11014
  readablePerpMarketIndex: depositToTradeArgs?.orderMarketIndex,
10982
11015
  readableSpotMarketIndexes: isDepositToTradeTx
@@ -10989,12 +11022,8 @@ export class DriftClient {
10989
11022
  {
10990
11023
  accounts: {
10991
11024
  state: await this.getStatePublicKey(),
10992
- user: getUserAccountPublicKeySync(
10993
- this.program.programId,
10994
- this.wallet.publicKey,
10995
- subAccountId
10996
- ),
10997
- authority: this.wallet.publicKey,
11025
+ user: userAccountPublicKey,
11026
+ authority: signingAuthority,
10998
11027
  highLeverageModeConfig: getHighLeverageModeConfigPublicKey(
10999
11028
  this.program.programId
11000
11029
  ),