@drift-labs/sdk-browser 2.121.0-beta.11 → 2.121.0-beta.13

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.121.0-beta.11
1
+ 2.121.0-beta.13
@@ -100,6 +100,7 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, to
100
100
  ? [__1.ZERO, __1.ZERO]
101
101
  : (0, __1.calculateMarketOpenBidAsk)(updatedAmm.baseAssetReserve, updatedAmm.minBaseAssetReserve, updatedAmm.maxBaseAssetReserve, updatedAmm.orderStepSize);
102
102
  const minOrderSize = marketAccount.amm.minOrderSize;
103
+ const orderTickSize = marketAccount.amm.orderTickSize;
103
104
  if (openBids.lt(minOrderSize.muln(2))) {
104
105
  openBids = __1.ZERO;
105
106
  }
@@ -127,7 +128,7 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, to
127
128
  quoteSwapped = topOfBookQuoteAmounts[numBids];
128
129
  [afterSwapQuoteReserves, afterSwapBaseReserves] =
129
130
  (0, __1.calculateAmmReservesAfterSwap)(bidAmm, 'quote', quoteSwapped, __1.SwapDirection.REMOVE);
130
- baseSwapped = bidAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs();
131
+ (0, __1.standardizeBaseAssetAmount)(bidAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs(), marketAccount.amm.orderStepSize);
131
132
  if (baseSwapped.eq(__1.ZERO)) {
132
133
  return;
133
134
  }
@@ -141,12 +142,12 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, to
141
142
  bidSize = openBids.sub(topOfBookBidSize).div(new __1.BN(numBaseOrders));
142
143
  }
143
144
  else {
144
- baseSwapped = bidSize;
145
+ baseSwapped = (0, __1.standardizeBaseAssetAmount)(bidSize, marketAccount.amm.orderStepSize);
145
146
  [afterSwapQuoteReserves, afterSwapBaseReserves] =
146
147
  (0, __1.calculateAmmReservesAfterSwap)(bidAmm, 'base', baseSwapped, __1.SwapDirection.ADD);
147
148
  quoteSwapped = (0, __1.calculateQuoteAssetAmountSwapped)(bidAmm.quoteAssetReserve.sub(afterSwapQuoteReserves).abs(), bidAmm.pegMultiplier, __1.SwapDirection.ADD);
148
149
  }
149
- const price = quoteSwapped.mul(__1.BASE_PRECISION).div(baseSwapped);
150
+ const price = (0, __1.standardizePrice)(quoteSwapped.mul(__1.BASE_PRECISION).div(baseSwapped), orderTickSize, __1.PositionDirection.LONG);
150
151
  bidAmm.baseAssetReserve = afterSwapBaseReserves;
151
152
  bidAmm.quoteAssetReserve = afterSwapQuoteReserves;
152
153
  yield {
@@ -178,7 +179,7 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, to
178
179
  quoteSwapped = topOfBookQuoteAmounts[numAsks];
179
180
  [afterSwapQuoteReserves, afterSwapBaseReserves] =
180
181
  (0, __1.calculateAmmReservesAfterSwap)(askAmm, 'quote', quoteSwapped, __1.SwapDirection.ADD);
181
- baseSwapped = askAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs();
182
+ baseSwapped = (0, __1.standardizeBaseAssetAmount)(askAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs(), marketAccount.amm.orderStepSize);
182
183
  if (baseSwapped.eq(__1.ZERO)) {
183
184
  return;
184
185
  }
@@ -195,12 +196,12 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, to
195
196
  .div(new __1.BN(numBaseOrders));
196
197
  }
197
198
  else {
198
- baseSwapped = askSize;
199
+ baseSwapped = (0, __1.standardizeBaseAssetAmount)(askSize, marketAccount.amm.orderStepSize);
199
200
  [afterSwapQuoteReserves, afterSwapBaseReserves] =
200
201
  (0, __1.calculateAmmReservesAfterSwap)(askAmm, 'base', askSize, __1.SwapDirection.REMOVE);
201
202
  quoteSwapped = (0, __1.calculateQuoteAssetAmountSwapped)(askAmm.quoteAssetReserve.sub(afterSwapQuoteReserves).abs(), askAmm.pegMultiplier, __1.SwapDirection.REMOVE);
202
203
  }
203
- const price = quoteSwapped.mul(__1.BASE_PRECISION).div(baseSwapped);
204
+ const price = (0, __1.standardizePrice)(quoteSwapped.mul(__1.BASE_PRECISION).div(baseSwapped), orderTickSize, __1.PositionDirection.SHORT);
204
205
  askAmm.baseAssetReserve = afterSwapBaseReserves;
205
206
  askAmm.quoteAssetReserve = afterSwapQuoteReserves;
206
207
  yield {
@@ -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;
@@ -2771,114 +2771,33 @@ class DriftClient {
2771
2771
  * @param swapMode jupiter swapMode (ExactIn or ExactOut), default is ExactIn
2772
2772
  * @param route the jupiter route to use for the swap
2773
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
2774
2776
  * @param txParams
2775
2777
  */
2776
- async swap({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, route, reduceOnly, txParams, v6, onlyDirectRoutes = false, }) {
2777
- let ixs;
2778
- let lookupTables;
2779
- if (v6) {
2780
- const res = await this.getJupiterSwapIxV6({
2781
- jupiterClient,
2782
- outMarketIndex,
2783
- inMarketIndex,
2784
- outAssociatedTokenAccount,
2785
- inAssociatedTokenAccount,
2786
- amount,
2787
- slippageBps,
2788
- swapMode,
2789
- quote: v6.quote,
2790
- reduceOnly,
2791
- onlyDirectRoutes,
2792
- });
2793
- ixs = res.ixs;
2794
- lookupTables = res.lookupTables;
2795
- }
2796
- else {
2797
- const res = await this.getJupiterSwapIx({
2798
- jupiterClient,
2799
- outMarketIndex,
2800
- inMarketIndex,
2801
- outAssociatedTokenAccount,
2802
- inAssociatedTokenAccount,
2803
- amount,
2804
- slippageBps,
2805
- swapMode,
2806
- route,
2807
- reduceOnly,
2808
- });
2809
- ixs = res.ixs;
2810
- lookupTables = res.lookupTables;
2811
- }
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;
2812
2795
  const tx = (await this.buildTransaction(ixs, txParams, 0, lookupTables));
2813
2796
  const { txSig, slot } = await this.sendTransaction(tx);
2814
2797
  this.spotMarketLastSlotCache.set(outMarketIndex, slot);
2815
2798
  this.spotMarketLastSlotCache.set(inMarketIndex, slot);
2816
2799
  return txSig;
2817
2800
  }
2818
- async getJupiterSwapIx({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, onlyDirectRoutes, route, reduceOnly, userAccountPublicKey, }) {
2819
- const outMarket = this.getSpotMarketAccount(outMarketIndex);
2820
- const inMarket = this.getSpotMarketAccount(inMarketIndex);
2821
- if (!route) {
2822
- const routes = await jupiterClient.getRoutes({
2823
- inputMint: inMarket.mint,
2824
- outputMint: outMarket.mint,
2825
- amount,
2826
- slippageBps,
2827
- swapMode,
2828
- onlyDirectRoutes,
2829
- });
2830
- if (!routes || routes.length === 0) {
2831
- throw new Error('No jupiter routes found');
2832
- }
2833
- route = routes[0];
2834
- }
2835
- const transaction = await jupiterClient.getSwapTransaction({
2836
- route,
2837
- userPublicKey: this.provider.wallet.publicKey,
2838
- slippageBps,
2839
- });
2840
- const { transactionMessage, lookupTables } = await jupiterClient.getTransactionMessageAndLookupTables({
2841
- transaction,
2842
- });
2843
- const jupiterInstructions = jupiterClient.getJupiterInstructions({
2844
- transactionMessage,
2845
- inputMint: inMarket.mint,
2846
- outputMint: outMarket.mint,
2847
- });
2848
- const preInstructions = [];
2849
- if (!outAssociatedTokenAccount) {
2850
- const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
2851
- outAssociatedTokenAccount = await this.getAssociatedTokenAccount(outMarket.marketIndex, false, tokenProgram);
2852
- const accountInfo = await this.connection.getAccountInfo(outAssociatedTokenAccount);
2853
- if (!accountInfo) {
2854
- preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(outAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, outMarket.mint, tokenProgram));
2855
- }
2856
- }
2857
- if (!inAssociatedTokenAccount) {
2858
- const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
2859
- inAssociatedTokenAccount = await this.getAssociatedTokenAccount(inMarket.marketIndex, false, tokenProgram);
2860
- const accountInfo = await this.connection.getAccountInfo(inAssociatedTokenAccount);
2861
- if (!accountInfo) {
2862
- preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(inAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, inMarket.mint, tokenProgram));
2863
- }
2864
- }
2865
- const { beginSwapIx, endSwapIx } = await this.getSwapIx({
2866
- outMarketIndex,
2867
- inMarketIndex,
2868
- amountIn: new anchor_1.BN(route.inAmount),
2869
- inTokenAccount: inAssociatedTokenAccount,
2870
- outTokenAccount: outAssociatedTokenAccount,
2871
- reduceOnly,
2872
- userAccountPublicKey,
2873
- });
2874
- const ixs = [
2875
- ...preInstructions,
2876
- beginSwapIx,
2877
- ...jupiterInstructions,
2878
- endSwapIx,
2879
- ];
2880
- return { ixs, lookupTables };
2881
- }
2882
2801
  async getJupiterSwapIxV6({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, onlyDirectRoutes, quote, reduceOnly, userAccountPublicKey, }) {
2883
2802
  const outMarket = this.getSpotMarketAccount(outMarketIndex);
2884
2803
  const inMarket = this.getSpotMarketAccount(inMarketIndex);
@@ -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
@@ -3,37 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.JupiterClient = void 0;
6
+ exports.JupiterClient = exports.RECOMMENDED_JUPITER_API = exports.RECOMMENDED_JUPITER_API_VERSION = void 0;
7
7
  const web3_js_1 = require("@solana/web3.js");
8
8
  const node_fetch_1 = __importDefault(require("node-fetch"));
9
+ exports.RECOMMENDED_JUPITER_API_VERSION = '/v1';
10
+ exports.RECOMMENDED_JUPITER_API = 'https://lite-api.jup.ag/swap';
9
11
  class JupiterClient {
10
12
  constructor({ connection, url }) {
11
13
  this.lookupTableCahce = new Map();
12
14
  this.connection = connection;
13
- this.url = url !== null && url !== void 0 ? url : 'https://quote-api.jup.ag';
14
- }
15
- /**
16
- * ** @deprecated - use getQuote
17
- * Get routes for a swap
18
- * @param inputMint the mint of the input token
19
- * @param outputMint the mint of the output token
20
- * @param amount the amount of the input token
21
- * @param slippageBps the slippage tolerance in basis points
22
- * @param swapMode the swap mode (ExactIn or ExactOut)
23
- * @param onlyDirectRoutes whether to only return direct routes
24
- */
25
- async getRoutes({ inputMint, outputMint, amount, slippageBps = 50, swapMode = 'ExactIn', onlyDirectRoutes = false, }) {
26
- const params = new URLSearchParams({
27
- inputMint: inputMint.toString(),
28
- outputMint: outputMint.toString(),
29
- amount: amount.toString(),
30
- slippageBps: slippageBps.toString(),
31
- swapMode,
32
- onlyDirectRoutes: onlyDirectRoutes.toString(),
33
- }).toString();
34
- const apiVersionParam = this.url === 'https://quote-api.jup.ag' ? '/v4' : '';
35
- const { data: routes } = await (await (0, node_fetch_1.default)(`${this.url}${apiVersionParam}/quote?${params}`)).json();
36
- return routes;
15
+ this.url = url !== null && url !== void 0 ? url : exports.RECOMMENDED_JUPITER_API;
37
16
  }
38
17
  /**
39
18
  * Get routes for a swap
@@ -64,7 +43,9 @@ class JupiterClient {
64
43
  if (swapMode === 'ExactOut') {
65
44
  params.delete('maxAccounts');
66
45
  }
67
- const apiVersionParam = this.url === 'https://quote-api.jup.ag' ? '/v6' : '';
46
+ const apiVersionParam = this.url === exports.RECOMMENDED_JUPITER_API
47
+ ? exports.RECOMMENDED_JUPITER_API_VERSION
48
+ : '';
68
49
  const quote = await (await (0, node_fetch_1.default)(`${this.url}${apiVersionParam}/quote?${params.toString()}`)).json();
69
50
  return quote;
70
51
  }
@@ -79,7 +60,9 @@ class JupiterClient {
79
60
  if (!quote) {
80
61
  throw new Error('Jupiter swap quote not provided. Please try again.');
81
62
  }
82
- const apiVersionParam = this.url === 'https://quote-api.jup.ag' ? '/v6' : '';
63
+ const apiVersionParam = this.url === exports.RECOMMENDED_JUPITER_API
64
+ ? exports.RECOMMENDED_JUPITER_API_VERSION
65
+ : '';
83
66
  const resp = await (await (0, node_fetch_1.default)(`${this.url}${apiVersionParam}/swap`, {
84
67
  method: 'POST',
85
68
  headers: {
@@ -103,30 +86,6 @@ class JupiterClient {
103
86
  throw new Error('Something went wrong with creating the Jupiter swap transaction. Please try again.');
104
87
  }
105
88
  }
106
- /**
107
- * ** @deprecated - use getSwap
108
- * Get a swap transaction for a route
109
- * @param route the route to perform swap
110
- * @param userPublicKey the signer's wallet public key
111
- * @param slippageBps the slippage tolerance in basis points
112
- */
113
- async getSwapTransaction({ route, userPublicKey, slippageBps = 50, }) {
114
- const apiVersionParam = this.url === 'https://quote-api.jup.ag' ? '/v4' : '';
115
- const resp = await (await (0, node_fetch_1.default)(`${this.url}${apiVersionParam}/swap`, {
116
- method: 'POST',
117
- headers: {
118
- 'Content-Type': 'application/json',
119
- },
120
- body: JSON.stringify({
121
- route,
122
- userPublicKey,
123
- slippageBps,
124
- }),
125
- })).json();
126
- const { swapTransaction } = resp;
127
- const swapTransactionBuf = Buffer.from(swapTransaction, 'base64');
128
- return web3_js_1.VersionedTransaction.deserialize(swapTransactionBuf);
129
- }
130
89
  /**
131
90
  * Get the transaction message and lookup tables for a transaction
132
91
  * @param transaction
@@ -1 +1 @@
1
- {"version":3,"file":"orderBookLevels.d.ts","sourceRoot":"","sources":["../../../src/dlob/orderBookLevels.ts"],"names":[],"mappings":";AAAA,OAAO,EAEN,EAAE,EAMF,QAAQ,EAGR,eAAe,EACf,iBAAiB,EAOjB,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,KAAK,eAAe,GACjB,OAAO,GACP,MAAM,GACN,MAAM,GACN,SAAS,GACT,UAAU,GACV,YAAY,CAAC;AAEhB,MAAM,MAAM,OAAO,GAAG;IACrB,KAAK,EAAE,EAAE,CAAC;IACV,IAAI,EAAE,EAAE,CAAC;IACT,OAAO,EAAE;SAAG,GAAG,IAAI,eAAe,CAAC,CAAC,EAAE,EAAE;KAAE,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CA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EAAE,MAAM,GACX,WAAW,CAMb;AAiFD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CACxB,IAAI,EAAE,OAAO,EAAE,EACf,IAAI,EAAE,OAAO,EAAE,EACf,WAAW,EAAE,EAAE,EACf,cAAc,EAAE,EAAE,EAClB,YAAY,EAAE,EAAE,EAChB,QAAQ,EAAE,EAAE,EACZ,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,EACrB,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,GACnB;IAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAAC,IAAI,EAAE,OAAO,EAAE,CAAA;CAAE,CAoJtC"}
@@ -100,6 +100,7 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, to
100
100
  ? [__1.ZERO, __1.ZERO]
101
101
  : (0, __1.calculateMarketOpenBidAsk)(updatedAmm.baseAssetReserve, updatedAmm.minBaseAssetReserve, updatedAmm.maxBaseAssetReserve, updatedAmm.orderStepSize);
102
102
  const minOrderSize = marketAccount.amm.minOrderSize;
103
+ const orderTickSize = marketAccount.amm.orderTickSize;
103
104
  if (openBids.lt(minOrderSize.muln(2))) {
104
105
  openBids = __1.ZERO;
105
106
  }
@@ -127,7 +128,7 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, to
127
128
  quoteSwapped = topOfBookQuoteAmounts[numBids];
128
129
  [afterSwapQuoteReserves, afterSwapBaseReserves] =
129
130
  (0, __1.calculateAmmReservesAfterSwap)(bidAmm, 'quote', quoteSwapped, __1.SwapDirection.REMOVE);
130
- baseSwapped = bidAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs();
131
+ (0, __1.standardizeBaseAssetAmount)(bidAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs(), marketAccount.amm.orderStepSize);
131
132
  if (baseSwapped.eq(__1.ZERO)) {
132
133
  return;
133
134
  }
@@ -141,12 +142,12 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, to
141
142
  bidSize = openBids.sub(topOfBookBidSize).div(new __1.BN(numBaseOrders));
142
143
  }
143
144
  else {
144
- baseSwapped = bidSize;
145
+ baseSwapped = (0, __1.standardizeBaseAssetAmount)(bidSize, marketAccount.amm.orderStepSize);
145
146
  [afterSwapQuoteReserves, afterSwapBaseReserves] =
146
147
  (0, __1.calculateAmmReservesAfterSwap)(bidAmm, 'base', baseSwapped, __1.SwapDirection.ADD);
147
148
  quoteSwapped = (0, __1.calculateQuoteAssetAmountSwapped)(bidAmm.quoteAssetReserve.sub(afterSwapQuoteReserves).abs(), bidAmm.pegMultiplier, __1.SwapDirection.ADD);
148
149
  }
149
- const price = quoteSwapped.mul(__1.BASE_PRECISION).div(baseSwapped);
150
+ const price = (0, __1.standardizePrice)(quoteSwapped.mul(__1.BASE_PRECISION).div(baseSwapped), orderTickSize, __1.PositionDirection.LONG);
150
151
  bidAmm.baseAssetReserve = afterSwapBaseReserves;
151
152
  bidAmm.quoteAssetReserve = afterSwapQuoteReserves;
152
153
  yield {
@@ -178,7 +179,7 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, to
178
179
  quoteSwapped = topOfBookQuoteAmounts[numAsks];
179
180
  [afterSwapQuoteReserves, afterSwapBaseReserves] =
180
181
  (0, __1.calculateAmmReservesAfterSwap)(askAmm, 'quote', quoteSwapped, __1.SwapDirection.ADD);
181
- baseSwapped = askAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs();
182
+ baseSwapped = (0, __1.standardizeBaseAssetAmount)(askAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs(), marketAccount.amm.orderStepSize);
182
183
  if (baseSwapped.eq(__1.ZERO)) {
183
184
  return;
184
185
  }
@@ -195,12 +196,12 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, to
195
196
  .div(new __1.BN(numBaseOrders));
196
197
  }
197
198
  else {
198
- baseSwapped = askSize;
199
+ baseSwapped = (0, __1.standardizeBaseAssetAmount)(askSize, marketAccount.amm.orderStepSize);
199
200
  [afterSwapQuoteReserves, afterSwapBaseReserves] =
200
201
  (0, __1.calculateAmmReservesAfterSwap)(askAmm, 'base', askSize, __1.SwapDirection.REMOVE);
201
202
  quoteSwapped = (0, __1.calculateQuoteAssetAmountSwapped)(askAmm.quoteAssetReserve.sub(afterSwapQuoteReserves).abs(), askAmm.pegMultiplier, __1.SwapDirection.REMOVE);
202
203
  }
203
- const price = quoteSwapped.mul(__1.BASE_PRECISION).div(baseSwapped);
204
+ const price = (0, __1.standardizePrice)(quoteSwapped.mul(__1.BASE_PRECISION).div(baseSwapped), orderTickSize, __1.PositionDirection.SHORT);
204
205
  askAmm.baseAssetReserve = afterSwapBaseReserves;
205
206
  askAmm.quoteAssetReserve = afterSwapQuoteReserves;
206
207
  yield {
@@ -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;