@drift-labs/sdk 2.38.1-beta.6 → 2.38.1-beta.7

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.38.1-beta.6
1
+ 2.38.1-beta.7
@@ -28,6 +28,173 @@ export interface Route {
28
28
  slippageBps: number;
29
29
  swapMode: SwapMode;
30
30
  }
31
+ /**
32
+ *
33
+ * @export
34
+ * @interface RoutePlanStep
35
+ */
36
+ export interface RoutePlanStep {
37
+ /**
38
+ *
39
+ * @type {SwapInfo}
40
+ * @memberof RoutePlanStep
41
+ */
42
+ swapInfo: SwapInfo;
43
+ /**
44
+ *
45
+ * @type {number}
46
+ * @memberof RoutePlanStep
47
+ */
48
+ percent: number;
49
+ }
50
+ export interface SwapInfo {
51
+ /**
52
+ *
53
+ * @type {string}
54
+ * @memberof SwapInfo
55
+ */
56
+ ammKey: string;
57
+ /**
58
+ *
59
+ * @type {string}
60
+ * @memberof SwapInfo
61
+ */
62
+ label?: string;
63
+ /**
64
+ *
65
+ * @type {string}
66
+ * @memberof SwapInfo
67
+ */
68
+ inputMint: string;
69
+ /**
70
+ *
71
+ * @type {string}
72
+ * @memberof SwapInfo
73
+ */
74
+ outputMint: string;
75
+ /**
76
+ *
77
+ * @type {string}
78
+ * @memberof SwapInfo
79
+ */
80
+ inAmount: string;
81
+ /**
82
+ *
83
+ * @type {string}
84
+ * @memberof SwapInfo
85
+ */
86
+ outAmount: string;
87
+ /**
88
+ *
89
+ * @type {string}
90
+ * @memberof SwapInfo
91
+ */
92
+ feeAmount: string;
93
+ /**
94
+ *
95
+ * @type {string}
96
+ * @memberof SwapInfo
97
+ */
98
+ feeMint: string;
99
+ }
100
+ /**
101
+ *
102
+ * @export
103
+ * @interface PlatformFee
104
+ */
105
+ export interface PlatformFee {
106
+ /**
107
+ *
108
+ * @type {string}
109
+ * @memberof PlatformFee
110
+ */
111
+ amount?: string;
112
+ /**
113
+ *
114
+ * @type {number}
115
+ * @memberof PlatformFee
116
+ */
117
+ feeBps?: number;
118
+ }
119
+ /**
120
+ *
121
+ * @export
122
+ * @interface QuoteResponse
123
+ */
124
+ export interface QuoteResponse {
125
+ /**
126
+ *
127
+ * @type {string}
128
+ * @memberof QuoteResponse
129
+ */
130
+ inputMint: string;
131
+ /**
132
+ *
133
+ * @type {string}
134
+ * @memberof QuoteResponse
135
+ */
136
+ inAmount: string;
137
+ /**
138
+ *
139
+ * @type {string}
140
+ * @memberof QuoteResponse
141
+ */
142
+ outputMint: string;
143
+ /**
144
+ *
145
+ * @type {string}
146
+ * @memberof QuoteResponse
147
+ */
148
+ outAmount: string;
149
+ /**
150
+ *
151
+ * @type {string}
152
+ * @memberof QuoteResponse
153
+ */
154
+ otherAmountThreshold: string;
155
+ /**
156
+ *
157
+ * @type {SwapMode}
158
+ * @memberof QuoteResponse
159
+ */
160
+ swapMode: SwapMode;
161
+ /**
162
+ *
163
+ * @type {number}
164
+ * @memberof QuoteResponse
165
+ */
166
+ slippageBps: number;
167
+ /**
168
+ *
169
+ * @type {PlatformFee}
170
+ * @memberof QuoteResponse
171
+ */
172
+ platformFee?: PlatformFee;
173
+ /**
174
+ *
175
+ * @type {string}
176
+ * @memberof QuoteResponse
177
+ */
178
+ priceImpactPct: string;
179
+ /**
180
+ *
181
+ * @type {Array<RoutePlanStep>}
182
+ * @memberof QuoteResponse
183
+ */
184
+ routePlan: Array<RoutePlanStep>;
185
+ /**
186
+ *
187
+ * @type {number}
188
+ * @memberof QuoteResponse
189
+ */
190
+ contextSlot?: number;
191
+ /**
192
+ *
193
+ * @type {number}
194
+ * @memberof QuoteResponse
195
+ */
196
+ timeTaken?: number;
197
+ }
31
198
  export declare class JupiterClient {
32
199
  url: string;
33
200
  connection: Connection;
@@ -36,6 +203,7 @@ export declare class JupiterClient {
36
203
  connection: Connection;
37
204
  });
38
205
  /**
206
+ * ** @deprecated - use getQuote
39
207
  * Get routes for a swap
40
208
  * @param inputMint the mint of the input token
41
209
  * @param outputMint the mint of the output token
@@ -53,6 +221,35 @@ export declare class JupiterClient {
53
221
  onlyDirectRoutes?: boolean;
54
222
  }): Promise<Route[]>;
55
223
  /**
224
+ * Get routes for a swap
225
+ * @param inputMint the mint of the input token
226
+ * @param outputMint the mint of the output token
227
+ * @param amount the amount of the input token
228
+ * @param slippageBps the slippage tolerance in basis points
229
+ * @param swapMode the swap mode (ExactIn or ExactOut)
230
+ * @param onlyDirectRoutes whether to only return direct routes
231
+ */
232
+ getQuote({ inputMint, outputMint, amount, slippageBps, swapMode, onlyDirectRoutes, }: {
233
+ inputMint: PublicKey;
234
+ outputMint: PublicKey;
235
+ amount: BN;
236
+ slippageBps?: number;
237
+ swapMode?: SwapMode;
238
+ onlyDirectRoutes?: boolean;
239
+ }): Promise<QuoteResponse>;
240
+ /**
241
+ * Get a swap transaction for quote
242
+ * @param quoteResponse quote to perform swap
243
+ * @param userPublicKey the signer's wallet public key
244
+ * @param slippageBps the slippage tolerance in basis points
245
+ */
246
+ getSwap({ quote, userPublicKey, slippageBps, }: {
247
+ quote: QuoteResponse;
248
+ userPublicKey: PublicKey;
249
+ slippageBps?: number;
250
+ }): Promise<VersionedTransaction>;
251
+ /**
252
+ * ** @deprecated - use getSwap
56
253
  * Get a swap transaction for a route
57
254
  * @param route the route to perform swap
58
255
  * @param userPublicKey the signer's wallet public key
@@ -8,11 +8,12 @@ const web3_js_1 = require("@solana/web3.js");
8
8
  const node_fetch_1 = __importDefault(require("node-fetch"));
9
9
  class JupiterClient {
10
10
  constructor({ connection }) {
11
- this.url = 'https://quote-api.jup.ag/v4';
11
+ this.url = 'https://quote-api.jup.ag';
12
12
  this.lookupTableCahce = new Map();
13
13
  this.connection = connection;
14
14
  }
15
15
  /**
16
+ * ** @deprecated - use getQuote
16
17
  * Get routes for a swap
17
18
  * @param inputMint the mint of the input token
18
19
  * @param outputMint the mint of the output token
@@ -30,17 +31,61 @@ class JupiterClient {
30
31
  swapMode,
31
32
  onlyDirectRoutes: onlyDirectRoutes.toString(),
32
33
  }).toString();
33
- const { data: routes } = await (await (0, node_fetch_1.default)(`https://quote-api.jup.ag/v4/quote?${params}`)).json();
34
+ const { data: routes } = await (await (0, node_fetch_1.default)(`${this.url}/v4/quote?${params}`)).json();
34
35
  return routes;
35
36
  }
36
37
  /**
38
+ * Get routes for a swap
39
+ * @param inputMint the mint of the input token
40
+ * @param outputMint the mint of the output token
41
+ * @param amount the amount of the input token
42
+ * @param slippageBps the slippage tolerance in basis points
43
+ * @param swapMode the swap mode (ExactIn or ExactOut)
44
+ * @param onlyDirectRoutes whether to only return direct routes
45
+ */
46
+ async getQuote({ inputMint, outputMint, amount, slippageBps = 50, swapMode = 'ExactIn', onlyDirectRoutes = false, }) {
47
+ const params = new URLSearchParams({
48
+ inputMint: inputMint.toString(),
49
+ outputMint: outputMint.toString(),
50
+ amount: amount.toString(),
51
+ slippageBps: slippageBps.toString(),
52
+ swapMode,
53
+ onlyDirectRoutes: onlyDirectRoutes.toString(),
54
+ }).toString();
55
+ const quote = await (await (0, node_fetch_1.default)(`${this.url}/v6/quote?${params}`)).json();
56
+ return quote;
57
+ }
58
+ /**
59
+ * Get a swap transaction for quote
60
+ * @param quoteResponse quote to perform swap
61
+ * @param userPublicKey the signer's wallet public key
62
+ * @param slippageBps the slippage tolerance in basis points
63
+ */
64
+ async getSwap({ quote, userPublicKey, slippageBps = 50, }) {
65
+ const resp = await (await (0, node_fetch_1.default)(`${this.url}/v6/swap`, {
66
+ method: 'POST',
67
+ headers: {
68
+ 'Content-Type': 'application/json',
69
+ },
70
+ body: JSON.stringify({
71
+ quoteResponse: quote,
72
+ userPublicKey,
73
+ slippageBps,
74
+ }),
75
+ })).json();
76
+ const { swapTransaction } = resp;
77
+ const swapTransactionBuf = Buffer.from(swapTransaction, 'base64');
78
+ return web3_js_1.VersionedTransaction.deserialize(swapTransactionBuf);
79
+ }
80
+ /**
81
+ * ** @deprecated - use getSwap
37
82
  * Get a swap transaction for a route
38
83
  * @param route the route to perform swap
39
84
  * @param userPublicKey the signer's wallet public key
40
85
  * @param slippageBps the slippage tolerance in basis points
41
86
  */
42
87
  async getSwapTransaction({ route, userPublicKey, slippageBps = 50, }) {
43
- const resp = await (await (0, node_fetch_1.default)(`${this.url}/swap`, {
88
+ const resp = await (await (0, node_fetch_1.default)(`${this.url}/v4/swap`, {
44
89
  method: 'POST',
45
90
  headers: {
46
91
  'Content-Type': 'application/json',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.38.1-beta.6",
3
+ "version": "2.38.1-beta.7",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -41,8 +41,179 @@ export interface Route {
41
41
  swapMode: SwapMode;
42
42
  }
43
43
 
44
+ /**
45
+ *
46
+ * @export
47
+ * @interface RoutePlanStep
48
+ */
49
+ export interface RoutePlanStep {
50
+ /**
51
+ *
52
+ * @type {SwapInfo}
53
+ * @memberof RoutePlanStep
54
+ */
55
+ swapInfo: SwapInfo;
56
+ /**
57
+ *
58
+ * @type {number}
59
+ * @memberof RoutePlanStep
60
+ */
61
+ percent: number;
62
+ }
63
+
64
+ export interface SwapInfo {
65
+ /**
66
+ *
67
+ * @type {string}
68
+ * @memberof SwapInfo
69
+ */
70
+ ammKey: string;
71
+ /**
72
+ *
73
+ * @type {string}
74
+ * @memberof SwapInfo
75
+ */
76
+ label?: string;
77
+ /**
78
+ *
79
+ * @type {string}
80
+ * @memberof SwapInfo
81
+ */
82
+ inputMint: string;
83
+ /**
84
+ *
85
+ * @type {string}
86
+ * @memberof SwapInfo
87
+ */
88
+ outputMint: string;
89
+ /**
90
+ *
91
+ * @type {string}
92
+ * @memberof SwapInfo
93
+ */
94
+ inAmount: string;
95
+ /**
96
+ *
97
+ * @type {string}
98
+ * @memberof SwapInfo
99
+ */
100
+ outAmount: string;
101
+ /**
102
+ *
103
+ * @type {string}
104
+ * @memberof SwapInfo
105
+ */
106
+ feeAmount: string;
107
+ /**
108
+ *
109
+ * @type {string}
110
+ * @memberof SwapInfo
111
+ */
112
+ feeMint: string;
113
+ }
114
+
115
+ /**
116
+ *
117
+ * @export
118
+ * @interface PlatformFee
119
+ */
120
+ export interface PlatformFee {
121
+ /**
122
+ *
123
+ * @type {string}
124
+ * @memberof PlatformFee
125
+ */
126
+ amount?: string;
127
+ /**
128
+ *
129
+ * @type {number}
130
+ * @memberof PlatformFee
131
+ */
132
+ feeBps?: number;
133
+ }
134
+
135
+ /**
136
+ *
137
+ * @export
138
+ * @interface QuoteResponse
139
+ */
140
+ export interface QuoteResponse {
141
+ /**
142
+ *
143
+ * @type {string}
144
+ * @memberof QuoteResponse
145
+ */
146
+ inputMint: string;
147
+ /**
148
+ *
149
+ * @type {string}
150
+ * @memberof QuoteResponse
151
+ */
152
+ inAmount: string;
153
+ /**
154
+ *
155
+ * @type {string}
156
+ * @memberof QuoteResponse
157
+ */
158
+ outputMint: string;
159
+ /**
160
+ *
161
+ * @type {string}
162
+ * @memberof QuoteResponse
163
+ */
164
+ outAmount: string;
165
+ /**
166
+ *
167
+ * @type {string}
168
+ * @memberof QuoteResponse
169
+ */
170
+ otherAmountThreshold: string;
171
+ /**
172
+ *
173
+ * @type {SwapMode}
174
+ * @memberof QuoteResponse
175
+ */
176
+ swapMode: SwapMode;
177
+ /**
178
+ *
179
+ * @type {number}
180
+ * @memberof QuoteResponse
181
+ */
182
+ slippageBps: number;
183
+ /**
184
+ *
185
+ * @type {PlatformFee}
186
+ * @memberof QuoteResponse
187
+ */
188
+ platformFee?: PlatformFee;
189
+ /**
190
+ *
191
+ * @type {string}
192
+ * @memberof QuoteResponse
193
+ */
194
+ priceImpactPct: string;
195
+ /**
196
+ *
197
+ * @type {Array<RoutePlanStep>}
198
+ * @memberof QuoteResponse
199
+ */
200
+ routePlan: Array<RoutePlanStep>;
201
+ /**
202
+ *
203
+ * @type {number}
204
+ * @memberof QuoteResponse
205
+ */
206
+ contextSlot?: number;
207
+ /**
208
+ *
209
+ * @type {number}
210
+ * @memberof QuoteResponse
211
+ */
212
+ timeTaken?: number;
213
+ }
214
+
44
215
  export class JupiterClient {
45
- url = 'https://quote-api.jup.ag/v4';
216
+ url = 'https://quote-api.jup.ag';
46
217
  connection: Connection;
47
218
  lookupTableCahce = new Map<string, AddressLookupTableAccount>();
48
219
 
@@ -51,6 +222,7 @@ export class JupiterClient {
51
222
  }
52
223
 
53
224
  /**
225
+ * ** @deprecated - use getQuote
54
226
  * Get routes for a swap
55
227
  * @param inputMint the mint of the input token
56
228
  * @param outputMint the mint of the output token
@@ -84,13 +256,84 @@ export class JupiterClient {
84
256
  }).toString();
85
257
 
86
258
  const { data: routes } = await (
87
- await fetch(`https://quote-api.jup.ag/v4/quote?${params}`)
259
+ await fetch(`${this.url}/v4/quote?${params}`)
88
260
  ).json();
89
261
 
90
262
  return routes;
91
263
  }
92
264
 
93
265
  /**
266
+ * Get routes for a swap
267
+ * @param inputMint the mint of the input token
268
+ * @param outputMint the mint of the output token
269
+ * @param amount the amount of the input token
270
+ * @param slippageBps the slippage tolerance in basis points
271
+ * @param swapMode the swap mode (ExactIn or ExactOut)
272
+ * @param onlyDirectRoutes whether to only return direct routes
273
+ */
274
+ public async getQuote({
275
+ inputMint,
276
+ outputMint,
277
+ amount,
278
+ slippageBps = 50,
279
+ swapMode = 'ExactIn',
280
+ onlyDirectRoutes = false,
281
+ }: {
282
+ inputMint: PublicKey;
283
+ outputMint: PublicKey;
284
+ amount: BN;
285
+ slippageBps?: number;
286
+ swapMode?: SwapMode;
287
+ onlyDirectRoutes?: boolean;
288
+ }): Promise<QuoteResponse> {
289
+ const params = new URLSearchParams({
290
+ inputMint: inputMint.toString(),
291
+ outputMint: outputMint.toString(),
292
+ amount: amount.toString(),
293
+ slippageBps: slippageBps.toString(),
294
+ swapMode,
295
+ onlyDirectRoutes: onlyDirectRoutes.toString(),
296
+ }).toString();
297
+ const quote = await (await fetch(`${this.url}/v6/quote?${params}`)).json();
298
+ return quote;
299
+ }
300
+
301
+ /**
302
+ * Get a swap transaction for quote
303
+ * @param quoteResponse quote to perform swap
304
+ * @param userPublicKey the signer's wallet public key
305
+ * @param slippageBps the slippage tolerance in basis points
306
+ */
307
+ public async getSwap({
308
+ quote,
309
+ userPublicKey,
310
+ slippageBps = 50,
311
+ }: {
312
+ quote: QuoteResponse;
313
+ userPublicKey: PublicKey;
314
+ slippageBps?: number;
315
+ }): Promise<VersionedTransaction> {
316
+ const resp = await (
317
+ await fetch(`${this.url}/v6/swap`, {
318
+ method: 'POST',
319
+ headers: {
320
+ 'Content-Type': 'application/json',
321
+ },
322
+ body: JSON.stringify({
323
+ quoteResponse: quote,
324
+ userPublicKey,
325
+ slippageBps,
326
+ }),
327
+ })
328
+ ).json();
329
+ const { swapTransaction } = resp;
330
+
331
+ const swapTransactionBuf = Buffer.from(swapTransaction, 'base64');
332
+ return VersionedTransaction.deserialize(swapTransactionBuf);
333
+ }
334
+
335
+ /**
336
+ * ** @deprecated - use getSwap
94
337
  * Get a swap transaction for a route
95
338
  * @param route the route to perform swap
96
339
  * @param userPublicKey the signer's wallet public key
@@ -106,7 +349,7 @@ export class JupiterClient {
106
349
  slippageBps?: number;
107
350
  }): Promise<VersionedTransaction> {
108
351
  const resp = await (
109
- await fetch(`${this.url}/swap`, {
352
+ await fetch(`${this.url}/v4/swap`, {
110
353
  method: 'POST',
111
354
  headers: {
112
355
  'Content-Type': 'application/json',