@drift-labs/sdk 2.40.0-beta.12 → 2.40.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.40.0-beta.12
1
+ 2.40.0-beta.13
@@ -230,7 +230,7 @@ export declare class JupiterClient {
230
230
  * @param onlyDirectRoutes whether to only return direct routes
231
231
  */
232
232
  getQuote({ inputMint, outputMint, amount, maxAccounts, // 52 is an estimated amount with buffer
233
- slippageBps, swapMode, onlyDirectRoutes, }: {
233
+ slippageBps, swapMode, onlyDirectRoutes, excludeDexes, }: {
234
234
  inputMint: PublicKey;
235
235
  outputMint: PublicKey;
236
236
  amount: BN;
@@ -238,6 +238,7 @@ export declare class JupiterClient {
238
238
  slippageBps?: number;
239
239
  swapMode?: SwapMode;
240
240
  onlyDirectRoutes?: boolean;
241
+ excludeDexes?: string[];
241
242
  }): Promise<QuoteResponse>;
242
243
  /**
243
244
  * Get a swap transaction for quote
@@ -44,7 +44,7 @@ class JupiterClient {
44
44
  * @param onlyDirectRoutes whether to only return direct routes
45
45
  */
46
46
  async getQuote({ inputMint, outputMint, amount, maxAccounts = 52, // 52 is an estimated amount with buffer
47
- slippageBps = 50, swapMode = 'ExactIn', onlyDirectRoutes = false, }) {
47
+ slippageBps = 50, swapMode = 'ExactIn', onlyDirectRoutes = false, excludeDexes = [], }) {
48
48
  const params = new URLSearchParams({
49
49
  inputMint: inputMint.toString(),
50
50
  outputMint: outputMint.toString(),
@@ -53,6 +53,7 @@ class JupiterClient {
53
53
  swapMode,
54
54
  onlyDirectRoutes: onlyDirectRoutes.toString(),
55
55
  maxAccounts: maxAccounts.toString(),
56
+ excludeDexes: excludeDexes.join(','),
56
57
  }).toString();
57
58
  const quote = await (await (0, node_fetch_1.default)(`${this.url}/v6/quote?${params}`)).json();
58
59
  return quote;
@@ -1,7 +1,18 @@
1
- import { Order } from '../types';
1
+ import { Order, PositionDirection } from '../types';
2
2
  import { BN } from '../.';
3
3
  export declare function isAuctionComplete(order: Order, slot: number): boolean;
4
4
  export declare function isFallbackAvailableLiquiditySource(order: Order, minAuctionDuration: number, slot: number): boolean;
5
5
  export declare function getAuctionPrice(order: Order, slot: number, oraclePrice: BN): BN;
6
6
  export declare function getAuctionPriceForFixedAuction(order: Order, slot: number): BN;
7
7
  export declare function getAuctionPriceForOracleOffsetAuction(order: Order, slot: number, oraclePrice: BN): BN;
8
+ export declare function deriveOracleAuctionParams({ direction, oraclePrice, auctionStartPrice, auctionEndPrice, limitPrice, }: {
9
+ direction: PositionDirection;
10
+ oraclePrice: BN;
11
+ auctionStartPrice: BN;
12
+ auctionEndPrice: BN;
13
+ limitPrice: BN;
14
+ }): {
15
+ auctionStartPrice: BN;
16
+ auctionEndPrice: BN;
17
+ oraclePriceOffset: number;
18
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAuctionPriceForOracleOffsetAuction = exports.getAuctionPriceForFixedAuction = exports.getAuctionPrice = exports.isFallbackAvailableLiquiditySource = exports.isAuctionComplete = void 0;
3
+ exports.deriveOracleAuctionParams = exports.getAuctionPriceForOracleOffsetAuction = exports.getAuctionPriceForFixedAuction = exports.getAuctionPrice = exports.isFallbackAvailableLiquiditySource = exports.isAuctionComplete = void 0;
4
4
  const types_1 = require("../types");
5
5
  const _1 = require("../.");
6
6
  function isAuctionComplete(order, slot) {
@@ -89,3 +89,24 @@ function getAuctionPriceForOracleOffsetAuction(order, slot, oraclePrice) {
89
89
  return oraclePrice.add(priceOffset);
90
90
  }
91
91
  exports.getAuctionPriceForOracleOffsetAuction = getAuctionPriceForOracleOffsetAuction;
92
+ function deriveOracleAuctionParams({ direction, oraclePrice, auctionStartPrice, auctionEndPrice, limitPrice, }) {
93
+ let oraclePriceOffset = limitPrice.sub(oraclePrice);
94
+ if (oraclePriceOffset.eq(_1.ZERO)) {
95
+ oraclePriceOffset = (0, types_1.isVariant)(direction, 'long')
96
+ ? auctionEndPrice.sub(oraclePrice).add(_1.ONE)
97
+ : auctionEndPrice.sub(oraclePrice).sub(_1.ONE);
98
+ }
99
+ let oraclePriceOffsetNum;
100
+ try {
101
+ oraclePriceOffsetNum = oraclePriceOffset.toNumber();
102
+ }
103
+ catch (e) {
104
+ oraclePriceOffsetNum = 0;
105
+ }
106
+ return {
107
+ auctionStartPrice: auctionStartPrice.sub(oraclePrice),
108
+ auctionEndPrice: auctionEndPrice.sub(oraclePrice),
109
+ oraclePriceOffset: oraclePriceOffsetNum,
110
+ };
111
+ }
112
+ exports.deriveOracleAuctionParams = deriveOracleAuctionParams;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.40.0-beta.12",
3
+ "version": "2.40.0-beta.13",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -279,6 +279,7 @@ export class JupiterClient {
279
279
  slippageBps = 50,
280
280
  swapMode = 'ExactIn',
281
281
  onlyDirectRoutes = false,
282
+ excludeDexes = [],
282
283
  }: {
283
284
  inputMint: PublicKey;
284
285
  outputMint: PublicKey;
@@ -287,6 +288,7 @@ export class JupiterClient {
287
288
  slippageBps?: number;
288
289
  swapMode?: SwapMode;
289
290
  onlyDirectRoutes?: boolean;
291
+ excludeDexes?: string[];
290
292
  }): Promise<QuoteResponse> {
291
293
  const params = new URLSearchParams({
292
294
  inputMint: inputMint.toString(),
@@ -296,6 +298,7 @@ export class JupiterClient {
296
298
  swapMode,
297
299
  onlyDirectRoutes: onlyDirectRoutes.toString(),
298
300
  maxAccounts: maxAccounts.toString(),
301
+ excludeDexes: excludeDexes.join(','),
299
302
  }).toString();
300
303
  const quote = await (await fetch(`${this.url}/v6/quote?${params}`)).json();
301
304
  return quote;
@@ -1,5 +1,5 @@
1
- import { isOneOfVariant, isVariant, Order } from '../types';
2
- import { BN, ZERO } from '../.';
1
+ import { isOneOfVariant, isVariant, Order, PositionDirection } from '../types';
2
+ import { BN, ONE, ZERO } from '../.';
3
3
 
4
4
  export function isAuctionComplete(order: Order, slot: number): boolean {
5
5
  if (order.auctionDuration === 0) {
@@ -104,3 +104,37 @@ export function getAuctionPriceForOracleOffsetAuction(
104
104
 
105
105
  return oraclePrice.add(priceOffset);
106
106
  }
107
+
108
+ export function deriveOracleAuctionParams({
109
+ direction,
110
+ oraclePrice,
111
+ auctionStartPrice,
112
+ auctionEndPrice,
113
+ limitPrice,
114
+ }: {
115
+ direction: PositionDirection;
116
+ oraclePrice: BN;
117
+ auctionStartPrice: BN;
118
+ auctionEndPrice: BN;
119
+ limitPrice: BN;
120
+ }): { auctionStartPrice: BN; auctionEndPrice: BN; oraclePriceOffset: number } {
121
+ let oraclePriceOffset = limitPrice.sub(oraclePrice);
122
+ if (oraclePriceOffset.eq(ZERO)) {
123
+ oraclePriceOffset = isVariant(direction, 'long')
124
+ ? auctionEndPrice.sub(oraclePrice).add(ONE)
125
+ : auctionEndPrice.sub(oraclePrice).sub(ONE);
126
+ }
127
+
128
+ let oraclePriceOffsetNum;
129
+ try {
130
+ oraclePriceOffsetNum = oraclePriceOffset.toNumber();
131
+ } catch (e) {
132
+ oraclePriceOffsetNum = 0;
133
+ }
134
+
135
+ return {
136
+ auctionStartPrice: auctionStartPrice.sub(oraclePrice),
137
+ auctionEndPrice: auctionEndPrice.sub(oraclePrice),
138
+ oraclePriceOffset: oraclePriceOffsetNum,
139
+ };
140
+ }
@@ -0,0 +1,66 @@
1
+ import {PRICE_PRECISION, BN, deriveOracleAuctionParams} from "../../src";
2
+ import {assert} from "chai";
3
+ import {PositionDirection} from "../../lib";
4
+
5
+ describe('Auction Tests', () => {
6
+
7
+ it('deriveOracleAuctionParams', async () => {
8
+ let oraclePrice = new BN(100).mul(PRICE_PRECISION);
9
+ let auctionStartPrice = new BN(90).mul(PRICE_PRECISION);
10
+ let auctionEndPrice = new BN(110).mul(PRICE_PRECISION);
11
+ let limitPrice = new BN(120).mul(PRICE_PRECISION);
12
+
13
+ let oracleOrderParams = deriveOracleAuctionParams({
14
+ direction: PositionDirection.LONG,
15
+ oraclePrice,
16
+ auctionStartPrice,
17
+ auctionEndPrice,
18
+ limitPrice,
19
+ });
20
+
21
+ assert(oracleOrderParams.auctionStartPrice.eq(new BN(-10).mul(PRICE_PRECISION)));
22
+ assert(oracleOrderParams.auctionEndPrice.eq(new BN(10).mul(PRICE_PRECISION)));
23
+ assert(oracleOrderParams.oraclePriceOffset === 20 * PRICE_PRECISION.toNumber());
24
+
25
+ oracleOrderParams = deriveOracleAuctionParams({
26
+ direction: PositionDirection.LONG,
27
+ oraclePrice,
28
+ auctionStartPrice: oraclePrice,
29
+ auctionEndPrice: oraclePrice,
30
+ limitPrice: oraclePrice,
31
+ });
32
+
33
+ assert(oracleOrderParams.auctionStartPrice.eq(new BN(0)));
34
+ assert(oracleOrderParams.auctionEndPrice.eq(new BN(0)));
35
+ assert(oracleOrderParams.oraclePriceOffset === 1);
36
+
37
+ oraclePrice = new BN(100).mul(PRICE_PRECISION);
38
+ auctionStartPrice = new BN(110).mul(PRICE_PRECISION);
39
+ auctionEndPrice = new BN(90).mul(PRICE_PRECISION);
40
+ limitPrice = new BN(80).mul(PRICE_PRECISION);
41
+
42
+ oracleOrderParams = deriveOracleAuctionParams({
43
+ direction: PositionDirection.SHORT,
44
+ oraclePrice,
45
+ auctionStartPrice,
46
+ auctionEndPrice,
47
+ limitPrice,
48
+ });
49
+
50
+ assert(oracleOrderParams.auctionStartPrice.eq(new BN(10).mul(PRICE_PRECISION)));
51
+ assert(oracleOrderParams.auctionEndPrice.eq(new BN(-10).mul(PRICE_PRECISION)));
52
+ assert(oracleOrderParams.oraclePriceOffset === -20 * PRICE_PRECISION.toNumber());
53
+
54
+ oracleOrderParams = deriveOracleAuctionParams({
55
+ direction: PositionDirection.SHORT,
56
+ oraclePrice,
57
+ auctionStartPrice: oraclePrice,
58
+ auctionEndPrice: oraclePrice,
59
+ limitPrice: oraclePrice,
60
+ });
61
+
62
+ assert(oracleOrderParams.auctionStartPrice.eq(new BN(0)));
63
+ assert(oracleOrderParams.auctionEndPrice.eq(new BN(0)));
64
+ assert(oracleOrderParams.oraclePriceOffset === -1);
65
+ });
66
+ });