@drift-labs/sdk 2.121.0-beta.2 → 2.121.0-beta.21

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 (47) hide show
  1. package/VERSION +1 -1
  2. package/lib/browser/adminClient.js +9 -7
  3. package/lib/browser/constants/perpMarkets.js +10 -0
  4. package/lib/browser/constants/spotMarkets.js +28 -4
  5. package/lib/browser/driftClient.d.ts +8 -23
  6. package/lib/browser/driftClient.js +52 -127
  7. package/lib/browser/indicative-quotes/indicativeQuotesSender.d.ts +0 -1
  8. package/lib/browser/indicative-quotes/indicativeQuotesSender.js +19 -3
  9. package/lib/browser/jupiter/jupiterClient.d.ts +2 -30
  10. package/lib/browser/jupiter/jupiterClient.js +10 -51
  11. package/lib/browser/math/spotBalance.js +1 -1
  12. package/lib/browser/swift/swiftOrderSubscriber.d.ts +1 -0
  13. package/lib/browser/swift/swiftOrderSubscriber.js +8 -0
  14. package/lib/browser/user.d.ts +6 -5
  15. package/lib/browser/user.js +12 -11
  16. package/lib/node/adminClient.d.ts.map +1 -1
  17. package/lib/node/adminClient.js +9 -7
  18. package/lib/node/constants/perpMarkets.d.ts.map +1 -1
  19. package/lib/node/constants/perpMarkets.js +10 -0
  20. package/lib/node/constants/spotMarkets.d.ts.map +1 -1
  21. package/lib/node/constants/spotMarkets.js +28 -4
  22. package/lib/node/driftClient.d.ts +8 -23
  23. package/lib/node/driftClient.d.ts.map +1 -1
  24. package/lib/node/driftClient.js +52 -127
  25. package/lib/node/indicative-quotes/indicativeQuotesSender.d.ts +0 -1
  26. package/lib/node/indicative-quotes/indicativeQuotesSender.d.ts.map +1 -1
  27. package/lib/node/indicative-quotes/indicativeQuotesSender.js +19 -3
  28. package/lib/node/jupiter/jupiterClient.d.ts +2 -30
  29. package/lib/node/jupiter/jupiterClient.d.ts.map +1 -1
  30. package/lib/node/jupiter/jupiterClient.js +10 -51
  31. package/lib/node/math/spotBalance.js +1 -1
  32. package/lib/node/swift/swiftOrderSubscriber.d.ts +1 -0
  33. package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
  34. package/lib/node/swift/swiftOrderSubscriber.js +8 -0
  35. package/lib/node/user.d.ts +6 -5
  36. package/lib/node/user.d.ts.map +1 -1
  37. package/lib/node/user.js +12 -11
  38. package/package.json +3 -2
  39. package/src/adminClient.ts +10 -11
  40. package/src/constants/perpMarkets.ts +10 -0
  41. package/src/constants/spotMarkets.ts +30 -4
  42. package/src/driftClient.ts +66 -209
  43. package/src/indicative-quotes/indicativeQuotesSender.ts +27 -5
  44. package/src/jupiter/jupiterClient.ts +10 -84
  45. package/src/math/spotBalance.ts +1 -1
  46. package/src/swift/swiftOrderSubscriber.ts +9 -0
  47. package/src/user.ts +26 -11
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.121.0-beta.2
1
+ 2.121.0-beta.21
@@ -1963,19 +1963,21 @@ class AdminClient extends driftClient_1.DriftClient {
1963
1963
  }
1964
1964
  async getAdminDepositIx(marketIndex, amount, depositUserAccount, adminTokenAccount) {
1965
1965
  const state = await this.getStatePublicKey();
1966
- const spotMarketVault = await (0, pda_1.getSpotMarketVaultPublicKey)(this.program.programId, marketIndex);
1966
+ const spotMarket = this.getSpotMarketAccount(marketIndex);
1967
+ const remainingAccounts = this.getRemainingAccounts({
1968
+ userAccounts: [],
1969
+ writableSpotMarketIndexes: [marketIndex],
1970
+ });
1971
+ this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
1967
1972
  return this.program.instruction.adminDeposit(marketIndex, amount, {
1968
- remainingAccounts: this.getRemainingAccounts({
1969
- userAccounts: [],
1970
- writableSpotMarketIndexes: [marketIndex],
1971
- }),
1973
+ remainingAccounts,
1972
1974
  accounts: {
1973
1975
  state,
1974
1976
  user: depositUserAccount,
1975
1977
  admin: this.wallet.publicKey,
1976
- spotMarketVault,
1978
+ spotMarketVault: spotMarket.vault,
1977
1979
  adminTokenAccount: adminTokenAccount !== null && adminTokenAccount !== void 0 ? adminTokenAccount : (await this.getAssociatedTokenAccount(marketIndex)),
1978
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
1980
+ tokenProgram: (0, pda_1.getTokenProgramForSpotMarket)(spotMarket),
1979
1981
  },
1980
1982
  });
1981
1983
  }
@@ -1187,6 +1187,16 @@ exports.MainnetPerpMarkets = [
1187
1187
  oracleSource: __1.OracleSource.PYTH_LAZER,
1188
1188
  pythLazerId: 163,
1189
1189
  },
1190
+ {
1191
+ fullName: 'LAUNCHCOIN',
1192
+ category: ['Meme'],
1193
+ symbol: 'LAUNCHCOIN-PERP',
1194
+ baseAssetSymbol: 'LAUNCHCOIN',
1195
+ marketIndex: 74,
1196
+ oracle: new web3_js_1.PublicKey('4zXs8GrbMwd9EhDwuaWLngX2yY5BApb2UxeHrTzu3Ckr'),
1197
+ launchTs: 1747318237000,
1198
+ oracleSource: __1.OracleSource.SWITCHBOARD_ON_DEMAND,
1199
+ },
1190
1200
  ];
1191
1201
  exports.PerpMarkets = {
1192
1202
  devnet: exports.DevnetPerpMarkets,
@@ -516,12 +516,12 @@ exports.MainnetSpotMarkets = [
516
516
  symbol: 'JLP-1',
517
517
  marketIndex: 33,
518
518
  poolId: 1,
519
- oracle: new web3_js_1.PublicKey('5Mb11e5rt1Sp6A286B145E4TmgMzsM2UX9nCF2vas5bs'),
519
+ oracle: new web3_js_1.PublicKey('3ZLn5XDgSLWhTk2NjqAU44cPkSeC5JAhW5o6w5Nz4p8R'),
520
520
  oracleSource: __1.OracleSource.PYTH_PULL,
521
521
  mint: new web3_js_1.PublicKey('27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4'),
522
522
  precision: new __1.BN(10).pow(numericConstants_1.SIX),
523
523
  precisionExp: numericConstants_1.SIX,
524
- pythFeedId: '0xc811abc82b4bad1f9bd711a2773ccaa935b03ecef974236942cec5e0eb845a3a',
524
+ pythFeedId: '0x6704952e00b6a088b6dcdb8170dcd591eaf64cff9e996ca75ae0ca55bfb96687',
525
525
  launchTs: 1735255852000,
526
526
  },
527
527
  {
@@ -614,7 +614,7 @@ exports.MainnetSpotMarkets = [
614
614
  pythFeedId: '0x67be9f519b95cf24338801051f9a808eff0a578ccb388db73b7f6fe1de019ffb',
615
615
  },
616
616
  {
617
- symbol: 'PT-fragSOL-15JUN25-3',
617
+ symbol: 'PT-fragSOL-10JUL25-3',
618
618
  marketIndex: 41,
619
619
  poolId: 3,
620
620
  oracle: new web3_js_1.PublicKey('CLjvwowzQ2L9PrmXA6zqbamxLVeDY9vE87aBxMZLJLoY'),
@@ -624,7 +624,7 @@ exports.MainnetSpotMarkets = [
624
624
  precisionExp: numericConstants_1.NINE,
625
625
  },
626
626
  {
627
- symbol: 'PT-kySOL-10JUL25-3',
627
+ symbol: 'PT-kySOL-15JUN25-3',
628
628
  marketIndex: 42,
629
629
  poolId: 3,
630
630
  oracle: new web3_js_1.PublicKey('G4FdLzuezfaJxBd8eChuw1NU4Sq3n1rasGTwSh7dXegN'),
@@ -653,6 +653,30 @@ exports.MainnetSpotMarkets = [
653
653
  precision: new __1.BN(10).pow(numericConstants_1.NINE),
654
654
  precisionExp: numericConstants_1.NINE,
655
655
  },
656
+ {
657
+ symbol: 'zBTC',
658
+ marketIndex: 45,
659
+ poolId: 0,
660
+ oracle: new web3_js_1.PublicKey('CN9QvvbGQzMnN8vJaSek2so4vFnTqgJDFrdJB8Y4tQfB'),
661
+ oracleSource: __1.OracleSource.PYTH_PULL,
662
+ mint: new web3_js_1.PublicKey('zBTCug3er3tLyffELcvDNrKkCymbPWysGcWihESYfLg'),
663
+ precision: new __1.BN(10).pow(numericConstants_1.EIGHT),
664
+ precisionExp: numericConstants_1.EIGHT,
665
+ pythFeedId: '0x3d824c7f7c26ed1c85421ecec8c754e6b52d66a4e45de20a9c9ea91de8b396f9',
666
+ launchTs: 1747155600000,
667
+ },
668
+ {
669
+ symbol: 'ZEUS',
670
+ marketIndex: 46,
671
+ poolId: 0,
672
+ oracle: new web3_js_1.PublicKey('ABetWkmf1dpQX8gbtrt947ma2j7KzTPjVAdFWHkuEzi3'),
673
+ oracleSource: __1.OracleSource.PYTH_PULL,
674
+ mint: new web3_js_1.PublicKey('ZEUS1aR7aX8DFFJf5QjWj2ftDDdNTroMNGo8YoQm3Gq'),
675
+ precision: new __1.BN(10).pow(numericConstants_1.SIX),
676
+ precisionExp: numericConstants_1.SIX,
677
+ pythFeedId: '0x31558e9ccb18c151af6c52bf78afd03098a7aca1b9cf171a65b693b464c2f066',
678
+ launchTs: 1747155600000,
679
+ },
656
680
  ];
657
681
  exports.SpotMarkets = {
658
682
  devnet: exports.DevnetSpotMarkets,
@@ -18,7 +18,7 @@ import { User } from './user';
18
18
  import { UserSubscriptionConfig } from './userConfig';
19
19
  import { DriftEnv } from './config';
20
20
  import { UserStats } from './userStats';
21
- import { JupiterClient, QuoteResponse, Route, SwapMode } from './jupiter/jupiterClient';
21
+ import { JupiterClient, QuoteResponse, SwapMode } from './jupiter/jupiterClient';
22
22
  import { UserStatsSubscriptionConfig } from './userStatsConfig';
23
23
  import { TxHandler } from './tx/txHandler';
24
24
  import { WormholeCoreBridgeSolana } from '@pythnetwork/pyth-solana-receiver/lib/idl/wormhole_core_bridge_solana';
@@ -464,9 +464,11 @@ export declare class DriftClient {
464
464
  * @param swapMode jupiter swapMode (ExactIn or ExactOut), default is ExactIn
465
465
  * @param route the jupiter route to use for the swap
466
466
  * @param reduceOnly specify if In or Out token on the drift account must reduceOnly, checked at end of swap
467
+ * @param v6 pass in the quote response from Jupiter quote's API (deprecated, use quote instead)
468
+ * @param quote pass in the quote response from Jupiter quote's API
467
469
  * @param txParams
468
470
  */
469
- swap({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, route, reduceOnly, txParams, v6, onlyDirectRoutes, }: {
471
+ swap({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, reduceOnly, txParams, v6, quote, onlyDirectRoutes, }: {
470
472
  jupiterClient: JupiterClient;
471
473
  outMarketIndex: number;
472
474
  inMarketIndex: number;
@@ -475,31 +477,14 @@ export declare class DriftClient {
475
477
  amount: BN;
476
478
  slippageBps?: number;
477
479
  swapMode?: SwapMode;
478
- route?: Route;
479
480
  reduceOnly?: SwapReduceOnly;
480
481
  txParams?: TxParams;
481
482
  onlyDirectRoutes?: boolean;
482
483
  v6?: {
483
484
  quote?: QuoteResponse;
484
485
  };
486
+ quote?: QuoteResponse;
485
487
  }): Promise<TransactionSignature>;
486
- getJupiterSwapIx({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, onlyDirectRoutes, route, reduceOnly, userAccountPublicKey, }: {
487
- jupiterClient: JupiterClient;
488
- outMarketIndex: number;
489
- inMarketIndex: number;
490
- outAssociatedTokenAccount?: PublicKey;
491
- inAssociatedTokenAccount?: PublicKey;
492
- amount: BN;
493
- slippageBps?: number;
494
- swapMode?: SwapMode;
495
- onlyDirectRoutes?: boolean;
496
- route?: Route;
497
- reduceOnly?: SwapReduceOnly;
498
- userAccountPublicKey?: PublicKey;
499
- }): Promise<{
500
- ixs: TransactionInstruction[];
501
- lookupTables: AddressLookupTableAccount[];
502
- }>;
503
488
  getJupiterSwapIxV6({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, onlyDirectRoutes, quote, reduceOnly, userAccountPublicKey, }: {
504
489
  jupiterClient: JupiterClient;
505
490
  outMarketIndex: number;
@@ -586,13 +571,13 @@ export declare class DriftClient {
586
571
  takerStats: PublicKey;
587
572
  takerUserAccount: UserAccount;
588
573
  signingAuthority: PublicKey;
589
- }, precedingIxs?: TransactionInstruction[], overrideCustomIxIndex?: number, includeHighLeverageModeConfig?: boolean, txParams?: TxParams): Promise<TransactionSignature>;
574
+ }, precedingIxs?: TransactionInstruction[], overrideCustomIxIndex?: number, txParams?: TxParams): Promise<TransactionSignature>;
590
575
  getPlaceSignedMsgTakerPerpOrderIxs(signedSignedMsgOrderParams: SignedMsgOrderParams, marketIndex: number, takerInfo: {
591
576
  taker: PublicKey;
592
577
  takerStats: PublicKey;
593
578
  takerUserAccount: UserAccount;
594
579
  signingAuthority: PublicKey;
595
- }, precedingIxs?: TransactionInstruction[], overrideCustomIxIndex?: number, includeHighLeverageModeConfig?: boolean): Promise<TransactionInstruction[]>;
580
+ }, precedingIxs?: TransactionInstruction[], overrideCustomIxIndex?: number): Promise<TransactionInstruction[]>;
596
581
  placeAndMakeSignedMsgPerpOrder(signedSignedMsgOrderParams: SignedMsgOrderParams, signedMsgOrderUuid: Uint8Array, takerInfo: {
597
582
  taker: PublicKey;
598
583
  takerStats: PublicKey;
@@ -883,7 +868,7 @@ export declare class DriftClient {
883
868
  * @param positionMarketIndex
884
869
  * @returns : {takerFee: number, makerFee: number} Precision None
885
870
  */
886
- getMarketFees(marketType: MarketType, marketIndex?: number, user?: User): {
871
+ getMarketFees(marketType: MarketType, marketIndex?: number, user?: User, enteringHighLeverageMode?: boolean): {
887
872
  takerFee: number;
888
873
  makerFee: number;
889
874
  };
@@ -29,7 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.DriftClient = void 0;
30
30
  const anchor = __importStar(require("@coral-xyz/anchor"));
31
31
  const anchor_1 = require("@coral-xyz/anchor");
32
- const anchor_30_1 = require("@coral-xyz/anchor-30");
33
32
  const bs58_1 = __importDefault(require("bs58"));
34
33
  const spl_token_1 = require("@solana/spl-token");
35
34
  const types_1 = require("./types");
@@ -2314,6 +2313,15 @@ class DriftClient {
2314
2313
  readableSpotMarketIndexes,
2315
2314
  useMarketLastSlotCache: true,
2316
2315
  });
2316
+ for (const param of params) {
2317
+ if ((0, orderParams_1.isUpdateHighLeverageMode)(param.bitFlags)) {
2318
+ remainingAccounts.push({
2319
+ pubkey: (0, pda_1.getHighLeverageModeConfigPublicKey)(this.program.programId),
2320
+ isWritable: true,
2321
+ isSigner: false,
2322
+ });
2323
+ }
2324
+ }
2317
2325
  const formattedParams = params.map((item) => (0, orderParams_1.getOrderParams)(item));
2318
2326
  return await this.program.instruction.placeOrders(formattedParams, {
2319
2327
  accounts: {
@@ -2763,114 +2771,33 @@ class DriftClient {
2763
2771
  * @param swapMode jupiter swapMode (ExactIn or ExactOut), default is ExactIn
2764
2772
  * @param route the jupiter route to use for the swap
2765
2773
  * @param reduceOnly specify if In or Out token on the drift account must reduceOnly, checked at end of swap
2774
+ * @param v6 pass in the quote response from Jupiter quote's API (deprecated, use quote instead)
2775
+ * @param quote pass in the quote response from Jupiter quote's API
2766
2776
  * @param txParams
2767
2777
  */
2768
- async swap({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, route, reduceOnly, txParams, v6, onlyDirectRoutes = false, }) {
2769
- let ixs;
2770
- let lookupTables;
2771
- if (v6) {
2772
- const res = await this.getJupiterSwapIxV6({
2773
- jupiterClient,
2774
- outMarketIndex,
2775
- inMarketIndex,
2776
- outAssociatedTokenAccount,
2777
- inAssociatedTokenAccount,
2778
- amount,
2779
- slippageBps,
2780
- swapMode,
2781
- quote: v6.quote,
2782
- reduceOnly,
2783
- onlyDirectRoutes,
2784
- });
2785
- ixs = res.ixs;
2786
- lookupTables = res.lookupTables;
2787
- }
2788
- else {
2789
- const res = await this.getJupiterSwapIx({
2790
- jupiterClient,
2791
- outMarketIndex,
2792
- inMarketIndex,
2793
- outAssociatedTokenAccount,
2794
- inAssociatedTokenAccount,
2795
- amount,
2796
- slippageBps,
2797
- swapMode,
2798
- route,
2799
- reduceOnly,
2800
- });
2801
- ixs = res.ixs;
2802
- lookupTables = res.lookupTables;
2803
- }
2778
+ async swap({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, reduceOnly, txParams, v6, quote, onlyDirectRoutes = false, }) {
2779
+ const quoteToUse = quote !== null && quote !== void 0 ? quote : v6 === null || v6 === void 0 ? void 0 : v6.quote;
2780
+ const res = await this.getJupiterSwapIxV6({
2781
+ jupiterClient,
2782
+ outMarketIndex,
2783
+ inMarketIndex,
2784
+ outAssociatedTokenAccount,
2785
+ inAssociatedTokenAccount,
2786
+ amount,
2787
+ slippageBps,
2788
+ swapMode,
2789
+ quote: quoteToUse,
2790
+ reduceOnly,
2791
+ onlyDirectRoutes,
2792
+ });
2793
+ const ixs = res.ixs;
2794
+ const lookupTables = res.lookupTables;
2804
2795
  const tx = (await this.buildTransaction(ixs, txParams, 0, lookupTables));
2805
2796
  const { txSig, slot } = await this.sendTransaction(tx);
2806
2797
  this.spotMarketLastSlotCache.set(outMarketIndex, slot);
2807
2798
  this.spotMarketLastSlotCache.set(inMarketIndex, slot);
2808
2799
  return txSig;
2809
2800
  }
2810
- async getJupiterSwapIx({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, onlyDirectRoutes, route, reduceOnly, userAccountPublicKey, }) {
2811
- const outMarket = this.getSpotMarketAccount(outMarketIndex);
2812
- const inMarket = this.getSpotMarketAccount(inMarketIndex);
2813
- if (!route) {
2814
- const routes = await jupiterClient.getRoutes({
2815
- inputMint: inMarket.mint,
2816
- outputMint: outMarket.mint,
2817
- amount,
2818
- slippageBps,
2819
- swapMode,
2820
- onlyDirectRoutes,
2821
- });
2822
- if (!routes || routes.length === 0) {
2823
- throw new Error('No jupiter routes found');
2824
- }
2825
- route = routes[0];
2826
- }
2827
- const transaction = await jupiterClient.getSwapTransaction({
2828
- route,
2829
- userPublicKey: this.provider.wallet.publicKey,
2830
- slippageBps,
2831
- });
2832
- const { transactionMessage, lookupTables } = await jupiterClient.getTransactionMessageAndLookupTables({
2833
- transaction,
2834
- });
2835
- const jupiterInstructions = jupiterClient.getJupiterInstructions({
2836
- transactionMessage,
2837
- inputMint: inMarket.mint,
2838
- outputMint: outMarket.mint,
2839
- });
2840
- const preInstructions = [];
2841
- if (!outAssociatedTokenAccount) {
2842
- const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
2843
- outAssociatedTokenAccount = await this.getAssociatedTokenAccount(outMarket.marketIndex, false, tokenProgram);
2844
- const accountInfo = await this.connection.getAccountInfo(outAssociatedTokenAccount);
2845
- if (!accountInfo) {
2846
- preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(outAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, outMarket.mint, tokenProgram));
2847
- }
2848
- }
2849
- if (!inAssociatedTokenAccount) {
2850
- const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
2851
- inAssociatedTokenAccount = await this.getAssociatedTokenAccount(inMarket.marketIndex, false, tokenProgram);
2852
- const accountInfo = await this.connection.getAccountInfo(inAssociatedTokenAccount);
2853
- if (!accountInfo) {
2854
- preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(inAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, inMarket.mint, tokenProgram));
2855
- }
2856
- }
2857
- const { beginSwapIx, endSwapIx } = await this.getSwapIx({
2858
- outMarketIndex,
2859
- inMarketIndex,
2860
- amountIn: new anchor_1.BN(route.inAmount),
2861
- inTokenAccount: inAssociatedTokenAccount,
2862
- outTokenAccount: outAssociatedTokenAccount,
2863
- reduceOnly,
2864
- userAccountPublicKey,
2865
- });
2866
- const ixs = [
2867
- ...preInstructions,
2868
- beginSwapIx,
2869
- ...jupiterInstructions,
2870
- endSwapIx,
2871
- ];
2872
- return { ixs, lookupTables };
2873
- }
2874
2801
  async getJupiterSwapIxV6({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, onlyDirectRoutes, quote, reduceOnly, userAccountPublicKey, }) {
2875
2802
  const outMarket = this.getSpotMarketAccount(outMarketIndex);
2876
2803
  const inMarket = this.getSpotMarketAccount(inMarketIndex);
@@ -3432,23 +3359,31 @@ class DriftClient {
3432
3359
  signMessage(message, keypair = this.wallet.payer) {
3433
3360
  return Buffer.from(tweetnacl_1.default.sign.detached(message, keypair.secretKey));
3434
3361
  }
3435
- async placeSignedMsgTakerOrder(signedSignedMsgOrderParams, marketIndex, takerInfo, precedingIxs = [], overrideCustomIxIndex, includeHighLeverageModeConfig, txParams) {
3436
- const ixs = await this.getPlaceSignedMsgTakerPerpOrderIxs(signedSignedMsgOrderParams, marketIndex, takerInfo, precedingIxs, overrideCustomIxIndex, includeHighLeverageModeConfig);
3362
+ async placeSignedMsgTakerOrder(signedSignedMsgOrderParams, marketIndex, takerInfo, precedingIxs = [], overrideCustomIxIndex, txParams) {
3363
+ const ixs = await this.getPlaceSignedMsgTakerPerpOrderIxs(signedSignedMsgOrderParams, marketIndex, takerInfo, precedingIxs, overrideCustomIxIndex);
3437
3364
  const { txSig } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
3438
3365
  return txSig;
3439
3366
  }
3440
- async getPlaceSignedMsgTakerPerpOrderIxs(signedSignedMsgOrderParams, marketIndex, takerInfo, precedingIxs = [], overrideCustomIxIndex, includeHighLeverageModeConfig) {
3367
+ async getPlaceSignedMsgTakerPerpOrderIxs(signedSignedMsgOrderParams, marketIndex, takerInfo, precedingIxs = [], overrideCustomIxIndex) {
3441
3368
  const remainingAccounts = this.getRemainingAccounts({
3442
3369
  userAccounts: [takerInfo.takerUserAccount],
3443
3370
  useMarketLastSlotCache: false,
3444
3371
  readablePerpMarketIndex: marketIndex,
3445
3372
  });
3446
- if (includeHighLeverageModeConfig) {
3447
- remainingAccounts.push({
3448
- pubkey: (0, pda_1.getHighLeverageModeConfigPublicKey)(this.program.programId),
3449
- isWritable: true,
3450
- isSigner: false,
3451
- });
3373
+ const isDelegateSigner = takerInfo.signingAuthority.equals(takerInfo.takerUserAccount.delegate);
3374
+ const borshBuf = Buffer.from(signedSignedMsgOrderParams.orderParams.toString(), 'hex');
3375
+ try {
3376
+ const { signedMsgOrderParams } = this.decodeSignedMsgOrderParamsMessage(borshBuf, isDelegateSigner);
3377
+ if ((0, orderParams_1.isUpdateHighLeverageMode)(signedMsgOrderParams.bitFlags)) {
3378
+ remainingAccounts.push({
3379
+ pubkey: (0, pda_1.getHighLeverageModeConfigPublicKey)(this.program.programId),
3380
+ isWritable: true,
3381
+ isSigner: false,
3382
+ });
3383
+ }
3384
+ }
3385
+ catch (err) {
3386
+ console.error('invalid signed order encoding');
3452
3387
  }
3453
3388
  const messageLengthBuffer = Buffer.alloc(2);
3454
3389
  messageLengthBuffer.writeUInt16LE(signedSignedMsgOrderParams.orderParams.length);
@@ -3459,7 +3394,6 @@ class DriftClient {
3459
3394
  signedSignedMsgOrderParams.orderParams,
3460
3395
  ]);
3461
3396
  const signedMsgOrderParamsSignatureIx = (0, ed25519Utils_1.createMinimalEd25519VerifyIx)(overrideCustomIxIndex || precedingIxs.length + 1, 12, signedMsgIxData, 0);
3462
- const isDelegateSigner = takerInfo.signingAuthority.equals(takerInfo.takerUserAccount.delegate);
3463
3397
  const placeTakerSignedMsgPerpOrderIx = this.program.instruction.placeSignedMsgTakerOrder(signedMsgIxData, isDelegateSigner, {
3464
3398
  accounts: {
3465
3399
  state: await this.getStatePublicKey(),
@@ -4688,7 +4622,7 @@ class DriftClient {
4688
4622
  * @param positionMarketIndex
4689
4623
  * @returns : {takerFee: number, makerFee: number} Precision None
4690
4624
  */
4691
- getMarketFees(marketType, marketIndex, user) {
4625
+ getMarketFees(marketType, marketIndex, user, enteringHighLeverageMode) {
4692
4626
  let feeTier;
4693
4627
  if (user) {
4694
4628
  feeTier = user.getUserFeeTier(marketType);
@@ -4710,7 +4644,7 @@ class DriftClient {
4710
4644
  marketAccount = this.getSpotMarketAccount(marketIndex);
4711
4645
  }
4712
4646
  takerFee += (takerFee * marketAccount.feeAdjustment) / 100;
4713
- if (user && user.isHighLeverageMode()) {
4647
+ if (user && (user.isHighLeverageMode() || enteringHighLeverageMode)) {
4714
4648
  takerFee *= 2;
4715
4649
  }
4716
4650
  makerFee += (makerFee * marketAccount.feeAdjustment) / 100;
@@ -4753,9 +4687,8 @@ class DriftClient {
4753
4687
  return this.receiverProgram;
4754
4688
  }
4755
4689
  async getSwitchboardOnDemandProgram() {
4756
- const idl = (await anchor_30_1.Program.fetchIdl(this.sbOnDemandProgramdId, this.provider));
4757
4690
  if (this.sbOnDemandProgram === undefined) {
4758
- this.sbOnDemandProgram = new anchor_30_1.Program(idl, this.provider);
4691
+ this.sbOnDemandProgram = await on_demand_1.AnchorUtils.loadProgramFromConnection(this.connection);
4759
4692
  }
4760
4693
  return this.sbOnDemandProgram;
4761
4694
  }
@@ -4881,24 +4814,16 @@ class DriftClient {
4881
4814
  }
4882
4815
  async getPostManySwitchboardOnDemandUpdatesAtomicIxs(feeds, recentSlothash, numSignatures = 3) {
4883
4816
  const program = await this.getSwitchboardOnDemandProgram();
4884
- for (const feed of feeds) {
4885
- const feedAccount = new on_demand_1.PullFeed(program, feed);
4886
- if (!this.sbProgramFeedConfigs) {
4887
- this.sbProgramFeedConfigs = new Map();
4888
- }
4889
- if (!this.sbProgramFeedConfigs.has(feedAccount.pubkey.toString())) {
4890
- const feedConfig = await feedAccount.loadConfigs();
4891
- this.sbProgramFeedConfigs.set(feed.toString(), feedConfig);
4892
- }
4893
- }
4894
- const [pullIxs, _responses, success] = await on_demand_1.PullFeed.fetchUpdateManyLightIx(program, {
4817
+ const [pullIxs, _luts, _rawResponse] = await on_demand_1.PullFeed.fetchUpdateManyLightIx(program, {
4895
4818
  feeds,
4896
4819
  numSignatures,
4897
4820
  recentSlothashes: recentSlothash
4898
4821
  ? [[new anchor_1.BN(recentSlothash.slot), recentSlothash.hash]]
4899
4822
  : undefined,
4823
+ chain: 'solana',
4824
+ network: this.env,
4900
4825
  });
4901
- if (!success) {
4826
+ if (!pullIxs) {
4902
4827
  return undefined;
4903
4828
  }
4904
4829
  return pullIxs;
@@ -17,7 +17,6 @@ export declare class IndicativeQuotesSender {
17
17
  private readonly heartbeatIntervalMs;
18
18
  private reconnectDelay;
19
19
  private ws;
20
- private driftClient;
21
20
  private connected;
22
21
  private quotes;
23
22
  constructor(endpoint: string, keypair: Keypair);
@@ -8,6 +8,7 @@ const tweetnacl_1 = __importDefault(require("tweetnacl"));
8
8
  const tweetnacl_util_1 = require("tweetnacl-util");
9
9
  const ws_1 = __importDefault(require("ws"));
10
10
  const SEND_INTERVAL = 500;
11
+ const MAX_BUFFERED_AMOUNT = 10 * 1024; // 10 KB as worst case scenario
11
12
  class IndicativeQuotesSender {
12
13
  constructor(endpoint, keypair) {
13
14
  this.endpoint = endpoint;
@@ -63,7 +64,7 @@ class IndicativeQuotesSender {
63
64
  if (message['channel'] === 'auth' &&
64
65
  ((_a = message['message']) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'authenticated') {
65
66
  this.sendQuotesInterval = setInterval(() => {
66
- var _a;
67
+ var _a, _b;
67
68
  if (this.connected) {
68
69
  for (const [marketIndex, quote] of this.quotes.entries()) {
69
70
  const message = {
@@ -76,7 +77,8 @@ class IndicativeQuotesSender {
76
77
  is_oracle_offset: quote.isOracleOffset,
77
78
  };
78
79
  try {
79
- if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN) {
80
+ if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN &&
81
+ ((_b = this.ws) === null || _b === void 0 ? void 0 : _b.bufferedAmount) < MAX_BUFFERED_AMOUNT) {
80
82
  this.ws.send(JSON.stringify(message));
81
83
  }
82
84
  }
@@ -98,7 +100,7 @@ class IndicativeQuotesSender {
98
100
  });
99
101
  });
100
102
  ws.on('unexpected-response', async (request, response) => {
101
- console.error('Unexpected response, reconnecting in 5s:', response.statusCode);
103
+ console.error('Unexpected response, reconnecting in 5s:', response === null || response === void 0 ? void 0 : response.statusCode);
102
104
  setTimeout(() => {
103
105
  if (this.heartbeatTimeout)
104
106
  clearTimeout(this.heartbeatTimeout);
@@ -128,6 +130,20 @@ class IndicativeQuotesSender {
128
130
  }, this.heartbeatIntervalMs);
129
131
  }
130
132
  setQuote(quote) {
133
+ if (!this.connected) {
134
+ console.warn('Setting quote before connected to the server, ignoring');
135
+ }
136
+ if (quote.marketIndex == null ||
137
+ quote.bidPrice == null ||
138
+ quote.askPrice == null ||
139
+ quote.bidBaseAssetAmount == null ||
140
+ quote.askBaseAssetAmount == null) {
141
+ console.warn('Received incomplete quote, ignoring and deleting old quote', quote);
142
+ if (quote.marketIndex != null) {
143
+ this.quotes.delete(quote.marketIndex);
144
+ }
145
+ return;
146
+ }
131
147
  this.quotes.set(quote.marketIndex, quote);
132
148
  }
133
149
  reconnect() {
@@ -208,6 +208,8 @@ export interface QuoteResponse {
208
208
  */
209
209
  errorCode?: string;
210
210
  }
211
+ export declare const RECOMMENDED_JUPITER_API_VERSION = "/v1";
212
+ export declare const RECOMMENDED_JUPITER_API = "https://lite-api.jup.ag/swap";
211
213
  export declare class JupiterClient {
212
214
  url: string;
213
215
  connection: Connection;
@@ -216,24 +218,6 @@ export declare class JupiterClient {
216
218
  connection: Connection;
217
219
  url?: string;
218
220
  });
219
- /**
220
- * ** @deprecated - use getQuote
221
- * Get routes for a swap
222
- * @param inputMint the mint of the input token
223
- * @param outputMint the mint of the output token
224
- * @param amount the amount of the input token
225
- * @param slippageBps the slippage tolerance in basis points
226
- * @param swapMode the swap mode (ExactIn or ExactOut)
227
- * @param onlyDirectRoutes whether to only return direct routes
228
- */
229
- getRoutes({ inputMint, outputMint, amount, slippageBps, swapMode, onlyDirectRoutes, }: {
230
- inputMint: PublicKey;
231
- outputMint: PublicKey;
232
- amount: BN;
233
- slippageBps?: number;
234
- swapMode?: SwapMode;
235
- onlyDirectRoutes?: boolean;
236
- }): Promise<Route[]>;
237
221
  /**
238
222
  * Get routes for a swap
239
223
  * @param inputMint the mint of the input token
@@ -268,18 +252,6 @@ export declare class JupiterClient {
268
252
  userPublicKey: PublicKey;
269
253
  slippageBps?: number;
270
254
  }): Promise<VersionedTransaction>;
271
- /**
272
- * ** @deprecated - use getSwap
273
- * Get a swap transaction for a route
274
- * @param route the route to perform swap
275
- * @param userPublicKey the signer's wallet public key
276
- * @param slippageBps the slippage tolerance in basis points
277
- */
278
- getSwapTransaction({ route, userPublicKey, slippageBps, }: {
279
- route: Route;
280
- userPublicKey: PublicKey;
281
- slippageBps?: number;
282
- }): Promise<VersionedTransaction>;
283
255
  /**
284
256
  * Get the transaction message and lookup tables for a transaction
285
257
  * @param transaction