@drift-labs/sdk 2.107.0-beta.3 → 2.107.0-beta.5
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 +1 -1
- package/lib/browser/jupiter/jupiterClient.d.ts +4 -1
- package/lib/browser/jupiter/jupiterClient.js +7 -2
- package/lib/browser/swift/swiftOrderSubscriber.d.ts +3 -3
- package/lib/browser/swift/swiftOrderSubscriber.js +8 -5
- package/lib/node/jupiter/jupiterClient.d.ts +4 -1
- package/lib/node/jupiter/jupiterClient.js +7 -2
- package/lib/node/swift/swiftOrderSubscriber.d.ts +3 -3
- package/lib/node/swift/swiftOrderSubscriber.js +8 -5
- package/package.json +1 -1
- package/src/jupiter/jupiterClient.ts +12 -1
- package/src/swift/swiftOrderSubscriber.ts +19 -10
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.107.0-beta.
|
|
1
|
+
2.107.0-beta.5
|
|
@@ -244,7 +244,7 @@ export declare class JupiterClient {
|
|
|
244
244
|
* @param onlyDirectRoutes whether to only return direct routes
|
|
245
245
|
*/
|
|
246
246
|
getQuote({ inputMint, outputMint, amount, maxAccounts, // 50 is an estimated amount with buffer
|
|
247
|
-
slippageBps, swapMode, onlyDirectRoutes, excludeDexes, }: {
|
|
247
|
+
slippageBps, swapMode, onlyDirectRoutes, excludeDexes, autoSlippage, maxAutoSlippageBps, usdEstimate, }: {
|
|
248
248
|
inputMint: PublicKey;
|
|
249
249
|
outputMint: PublicKey;
|
|
250
250
|
amount: BN;
|
|
@@ -253,6 +253,9 @@ export declare class JupiterClient {
|
|
|
253
253
|
swapMode?: SwapMode;
|
|
254
254
|
onlyDirectRoutes?: boolean;
|
|
255
255
|
excludeDexes?: string[];
|
|
256
|
+
autoSlippage?: boolean;
|
|
257
|
+
maxAutoSlippageBps?: number;
|
|
258
|
+
usdEstimate?: number;
|
|
256
259
|
}): Promise<QuoteResponse>;
|
|
257
260
|
/**
|
|
258
261
|
* Get a swap transaction for quote
|
|
@@ -45,15 +45,20 @@ class JupiterClient {
|
|
|
45
45
|
* @param onlyDirectRoutes whether to only return direct routes
|
|
46
46
|
*/
|
|
47
47
|
async getQuote({ inputMint, outputMint, amount, maxAccounts = 50, // 50 is an estimated amount with buffer
|
|
48
|
-
slippageBps = 50, swapMode = 'ExactIn', onlyDirectRoutes = false, excludeDexes, }) {
|
|
48
|
+
slippageBps = 50, swapMode = 'ExactIn', onlyDirectRoutes = false, excludeDexes, autoSlippage = false, maxAutoSlippageBps, usdEstimate, }) {
|
|
49
49
|
const params = new URLSearchParams({
|
|
50
50
|
inputMint: inputMint.toString(),
|
|
51
51
|
outputMint: outputMint.toString(),
|
|
52
52
|
amount: amount.toString(),
|
|
53
|
-
slippageBps: slippageBps.toString(),
|
|
53
|
+
slippageBps: autoSlippage ? '0' : slippageBps.toString(),
|
|
54
54
|
swapMode,
|
|
55
55
|
onlyDirectRoutes: onlyDirectRoutes.toString(),
|
|
56
56
|
maxAccounts: maxAccounts.toString(),
|
|
57
|
+
autoSlippage: autoSlippage.toString(),
|
|
58
|
+
maxAutoSlippageBps: autoSlippage ? maxAutoSlippageBps.toString() : '0',
|
|
59
|
+
autoSlippageCollisionUsdValue: autoSlippage
|
|
60
|
+
? usdEstimate.toString()
|
|
61
|
+
: '0',
|
|
57
62
|
...(excludeDexes && { excludeDexes: excludeDexes.join(',') }),
|
|
58
63
|
});
|
|
59
64
|
if (swapMode === 'ExactOut') {
|
|
@@ -10,18 +10,18 @@ export type SwiftOrderSubscriberConfig = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare class SwiftOrderSubscriber {
|
|
12
12
|
private config;
|
|
13
|
-
private onOrder;
|
|
14
13
|
private heartbeatTimeout;
|
|
15
14
|
private readonly heartbeatIntervalMs;
|
|
16
15
|
private ws;
|
|
17
16
|
private driftClient;
|
|
18
17
|
private userMap;
|
|
18
|
+
private onOrder;
|
|
19
19
|
subscribed: boolean;
|
|
20
|
-
constructor(config: SwiftOrderSubscriberConfig
|
|
20
|
+
constructor(config: SwiftOrderSubscriberConfig);
|
|
21
21
|
getSymbolForMarketIndex(marketIndex: number): string;
|
|
22
22
|
generateChallengeResponse(nonce: string): string;
|
|
23
23
|
handleAuthMessage(message: any): void;
|
|
24
|
-
subscribe(): Promise<void>;
|
|
24
|
+
subscribe(onOrder: (orderMessageRaw: any, swiftOrderParamsMessage: SwiftOrderParamsMessage) => Promise<void>): Promise<void>;
|
|
25
25
|
getPlaceAndMakeSwiftOrderIxs(orderMessageRaw: any, swiftOrderParamsMessage: SwiftOrderParamsMessage, makerOrderParams: OptionalOrderParams): Promise<TransactionInstruction[]>;
|
|
26
26
|
private startHeartbeatTimer;
|
|
27
27
|
private reconnect;
|
|
@@ -10,9 +10,8 @@ const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
|
10
10
|
const tweetnacl_util_1 = require("tweetnacl-util");
|
|
11
11
|
const ws_1 = __importDefault(require("ws"));
|
|
12
12
|
class SwiftOrderSubscriber {
|
|
13
|
-
constructor(config
|
|
13
|
+
constructor(config) {
|
|
14
14
|
this.config = config;
|
|
15
|
-
this.onOrder = onOrder;
|
|
16
15
|
this.heartbeatTimeout = null;
|
|
17
16
|
this.heartbeatIntervalMs = 60000;
|
|
18
17
|
this.ws = null;
|
|
@@ -55,7 +54,8 @@ class SwiftOrderSubscriber {
|
|
|
55
54
|
});
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
|
-
async subscribe() {
|
|
57
|
+
async subscribe(onOrder) {
|
|
58
|
+
this.onOrder = onOrder;
|
|
59
59
|
const endpoint = this.config.endpoint || this.config.driftEnv === 'devnet'
|
|
60
60
|
? 'wss://master.swift.drift.trade/ws'
|
|
61
61
|
: 'wss://swift.drift.trade/ws';
|
|
@@ -77,7 +77,7 @@ class SwiftOrderSubscriber {
|
|
|
77
77
|
console.error(`order has no price: ${JSON.stringify(swiftOrderParamsMessage.swiftOrderParams)}`);
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
onOrder(order, swiftOrderParamsMessage);
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
83
|
ws.on('close', () => {
|
|
@@ -113,6 +113,9 @@ class SwiftOrderSubscriber {
|
|
|
113
113
|
if (this.heartbeatTimeout) {
|
|
114
114
|
clearTimeout(this.heartbeatTimeout);
|
|
115
115
|
}
|
|
116
|
+
if (!this.onOrder) {
|
|
117
|
+
throw new Error('onOrder callback function must be set');
|
|
118
|
+
}
|
|
116
119
|
this.heartbeatTimeout = setTimeout(() => {
|
|
117
120
|
console.warn('No heartbeat received within 30 seconds, reconnecting...');
|
|
118
121
|
this.reconnect();
|
|
@@ -125,7 +128,7 @@ class SwiftOrderSubscriber {
|
|
|
125
128
|
}
|
|
126
129
|
console.log('Reconnecting to WebSocket...');
|
|
127
130
|
setTimeout(() => {
|
|
128
|
-
this.subscribe();
|
|
131
|
+
this.subscribe(this.onOrder);
|
|
129
132
|
}, 1000);
|
|
130
133
|
}
|
|
131
134
|
}
|
|
@@ -244,7 +244,7 @@ export declare class JupiterClient {
|
|
|
244
244
|
* @param onlyDirectRoutes whether to only return direct routes
|
|
245
245
|
*/
|
|
246
246
|
getQuote({ inputMint, outputMint, amount, maxAccounts, // 50 is an estimated amount with buffer
|
|
247
|
-
slippageBps, swapMode, onlyDirectRoutes, excludeDexes, }: {
|
|
247
|
+
slippageBps, swapMode, onlyDirectRoutes, excludeDexes, autoSlippage, maxAutoSlippageBps, usdEstimate, }: {
|
|
248
248
|
inputMint: PublicKey;
|
|
249
249
|
outputMint: PublicKey;
|
|
250
250
|
amount: BN;
|
|
@@ -253,6 +253,9 @@ export declare class JupiterClient {
|
|
|
253
253
|
swapMode?: SwapMode;
|
|
254
254
|
onlyDirectRoutes?: boolean;
|
|
255
255
|
excludeDexes?: string[];
|
|
256
|
+
autoSlippage?: boolean;
|
|
257
|
+
maxAutoSlippageBps?: number;
|
|
258
|
+
usdEstimate?: number;
|
|
256
259
|
}): Promise<QuoteResponse>;
|
|
257
260
|
/**
|
|
258
261
|
* Get a swap transaction for quote
|
|
@@ -45,15 +45,20 @@ class JupiterClient {
|
|
|
45
45
|
* @param onlyDirectRoutes whether to only return direct routes
|
|
46
46
|
*/
|
|
47
47
|
async getQuote({ inputMint, outputMint, amount, maxAccounts = 50, // 50 is an estimated amount with buffer
|
|
48
|
-
slippageBps = 50, swapMode = 'ExactIn', onlyDirectRoutes = false, excludeDexes, }) {
|
|
48
|
+
slippageBps = 50, swapMode = 'ExactIn', onlyDirectRoutes = false, excludeDexes, autoSlippage = false, maxAutoSlippageBps, usdEstimate, }) {
|
|
49
49
|
const params = new URLSearchParams({
|
|
50
50
|
inputMint: inputMint.toString(),
|
|
51
51
|
outputMint: outputMint.toString(),
|
|
52
52
|
amount: amount.toString(),
|
|
53
|
-
slippageBps: slippageBps.toString(),
|
|
53
|
+
slippageBps: autoSlippage ? '0' : slippageBps.toString(),
|
|
54
54
|
swapMode,
|
|
55
55
|
onlyDirectRoutes: onlyDirectRoutes.toString(),
|
|
56
56
|
maxAccounts: maxAccounts.toString(),
|
|
57
|
+
autoSlippage: autoSlippage.toString(),
|
|
58
|
+
maxAutoSlippageBps: autoSlippage ? maxAutoSlippageBps.toString() : '0',
|
|
59
|
+
autoSlippageCollisionUsdValue: autoSlippage
|
|
60
|
+
? usdEstimate.toString()
|
|
61
|
+
: '0',
|
|
57
62
|
...(excludeDexes && { excludeDexes: excludeDexes.join(',') }),
|
|
58
63
|
});
|
|
59
64
|
if (swapMode === 'ExactOut') {
|
|
@@ -10,18 +10,18 @@ export type SwiftOrderSubscriberConfig = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare class SwiftOrderSubscriber {
|
|
12
12
|
private config;
|
|
13
|
-
private onOrder;
|
|
14
13
|
private heartbeatTimeout;
|
|
15
14
|
private readonly heartbeatIntervalMs;
|
|
16
15
|
private ws;
|
|
17
16
|
private driftClient;
|
|
18
17
|
private userMap;
|
|
18
|
+
private onOrder;
|
|
19
19
|
subscribed: boolean;
|
|
20
|
-
constructor(config: SwiftOrderSubscriberConfig
|
|
20
|
+
constructor(config: SwiftOrderSubscriberConfig);
|
|
21
21
|
getSymbolForMarketIndex(marketIndex: number): string;
|
|
22
22
|
generateChallengeResponse(nonce: string): string;
|
|
23
23
|
handleAuthMessage(message: any): void;
|
|
24
|
-
subscribe(): Promise<void>;
|
|
24
|
+
subscribe(onOrder: (orderMessageRaw: any, swiftOrderParamsMessage: SwiftOrderParamsMessage) => Promise<void>): Promise<void>;
|
|
25
25
|
getPlaceAndMakeSwiftOrderIxs(orderMessageRaw: any, swiftOrderParamsMessage: SwiftOrderParamsMessage, makerOrderParams: OptionalOrderParams): Promise<TransactionInstruction[]>;
|
|
26
26
|
private startHeartbeatTimer;
|
|
27
27
|
private reconnect;
|
|
@@ -10,9 +10,8 @@ const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
|
10
10
|
const tweetnacl_util_1 = require("tweetnacl-util");
|
|
11
11
|
const ws_1 = __importDefault(require("ws"));
|
|
12
12
|
class SwiftOrderSubscriber {
|
|
13
|
-
constructor(config
|
|
13
|
+
constructor(config) {
|
|
14
14
|
this.config = config;
|
|
15
|
-
this.onOrder = onOrder;
|
|
16
15
|
this.heartbeatTimeout = null;
|
|
17
16
|
this.heartbeatIntervalMs = 60000;
|
|
18
17
|
this.ws = null;
|
|
@@ -55,7 +54,8 @@ class SwiftOrderSubscriber {
|
|
|
55
54
|
});
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
|
-
async subscribe() {
|
|
57
|
+
async subscribe(onOrder) {
|
|
58
|
+
this.onOrder = onOrder;
|
|
59
59
|
const endpoint = this.config.endpoint || this.config.driftEnv === 'devnet'
|
|
60
60
|
? 'wss://master.swift.drift.trade/ws'
|
|
61
61
|
: 'wss://swift.drift.trade/ws';
|
|
@@ -77,7 +77,7 @@ class SwiftOrderSubscriber {
|
|
|
77
77
|
console.error(`order has no price: ${JSON.stringify(swiftOrderParamsMessage.swiftOrderParams)}`);
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
onOrder(order, swiftOrderParamsMessage);
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
83
|
ws.on('close', () => {
|
|
@@ -113,6 +113,9 @@ class SwiftOrderSubscriber {
|
|
|
113
113
|
if (this.heartbeatTimeout) {
|
|
114
114
|
clearTimeout(this.heartbeatTimeout);
|
|
115
115
|
}
|
|
116
|
+
if (!this.onOrder) {
|
|
117
|
+
throw new Error('onOrder callback function must be set');
|
|
118
|
+
}
|
|
116
119
|
this.heartbeatTimeout = setTimeout(() => {
|
|
117
120
|
console.warn('No heartbeat received within 30 seconds, reconnecting...');
|
|
118
121
|
this.reconnect();
|
|
@@ -125,7 +128,7 @@ class SwiftOrderSubscriber {
|
|
|
125
128
|
}
|
|
126
129
|
console.log('Reconnecting to WebSocket...');
|
|
127
130
|
setTimeout(() => {
|
|
128
|
-
this.subscribe();
|
|
131
|
+
this.subscribe(this.onOrder);
|
|
129
132
|
}, 1000);
|
|
130
133
|
}
|
|
131
134
|
}
|
package/package.json
CHANGED
|
@@ -295,6 +295,9 @@ export class JupiterClient {
|
|
|
295
295
|
swapMode = 'ExactIn',
|
|
296
296
|
onlyDirectRoutes = false,
|
|
297
297
|
excludeDexes,
|
|
298
|
+
autoSlippage = false,
|
|
299
|
+
maxAutoSlippageBps,
|
|
300
|
+
usdEstimate,
|
|
298
301
|
}: {
|
|
299
302
|
inputMint: PublicKey;
|
|
300
303
|
outputMint: PublicKey;
|
|
@@ -304,15 +307,23 @@ export class JupiterClient {
|
|
|
304
307
|
swapMode?: SwapMode;
|
|
305
308
|
onlyDirectRoutes?: boolean;
|
|
306
309
|
excludeDexes?: string[];
|
|
310
|
+
autoSlippage?: boolean;
|
|
311
|
+
maxAutoSlippageBps?: number;
|
|
312
|
+
usdEstimate?: number;
|
|
307
313
|
}): Promise<QuoteResponse> {
|
|
308
314
|
const params = new URLSearchParams({
|
|
309
315
|
inputMint: inputMint.toString(),
|
|
310
316
|
outputMint: outputMint.toString(),
|
|
311
317
|
amount: amount.toString(),
|
|
312
|
-
slippageBps: slippageBps.toString(),
|
|
318
|
+
slippageBps: autoSlippage ? '0' : slippageBps.toString(),
|
|
313
319
|
swapMode,
|
|
314
320
|
onlyDirectRoutes: onlyDirectRoutes.toString(),
|
|
315
321
|
maxAccounts: maxAccounts.toString(),
|
|
322
|
+
autoSlippage: autoSlippage.toString(),
|
|
323
|
+
maxAutoSlippageBps: autoSlippage ? maxAutoSlippageBps.toString() : '0',
|
|
324
|
+
autoSlippageCollisionUsdValue: autoSlippage
|
|
325
|
+
? usdEstimate.toString()
|
|
326
|
+
: '0',
|
|
316
327
|
...(excludeDexes && { excludeDexes: excludeDexes.join(',') }),
|
|
317
328
|
});
|
|
318
329
|
if (swapMode === 'ExactOut') {
|
|
@@ -31,15 +31,14 @@ export class SwiftOrderSubscriber {
|
|
|
31
31
|
private ws: WebSocket | null = null;
|
|
32
32
|
private driftClient: DriftClient;
|
|
33
33
|
private userMap: UserMap;
|
|
34
|
+
private onOrder: (
|
|
35
|
+
orderMessageRaw: any,
|
|
36
|
+
swiftOrderParamsMessage: SwiftOrderParamsMessage
|
|
37
|
+
) => Promise<void>;
|
|
38
|
+
|
|
34
39
|
subscribed = false;
|
|
35
40
|
|
|
36
|
-
constructor(
|
|
37
|
-
private config: SwiftOrderSubscriberConfig,
|
|
38
|
-
private onOrder: (
|
|
39
|
-
orderMessageRaw: any,
|
|
40
|
-
swiftOrderParamsMessage: SwiftOrderParamsMessage
|
|
41
|
-
) => Promise<void>
|
|
42
|
-
) {
|
|
41
|
+
constructor(private config: SwiftOrderSubscriberConfig) {
|
|
43
42
|
this.driftClient = config.driftClient;
|
|
44
43
|
this.userMap = config.userMap;
|
|
45
44
|
}
|
|
@@ -91,7 +90,14 @@ export class SwiftOrderSubscriber {
|
|
|
91
90
|
}
|
|
92
91
|
}
|
|
93
92
|
|
|
94
|
-
async subscribe(
|
|
93
|
+
async subscribe(
|
|
94
|
+
onOrder: (
|
|
95
|
+
orderMessageRaw: any,
|
|
96
|
+
swiftOrderParamsMessage: SwiftOrderParamsMessage
|
|
97
|
+
) => Promise<void>
|
|
98
|
+
): Promise<void> {
|
|
99
|
+
this.onOrder = onOrder;
|
|
100
|
+
|
|
95
101
|
const endpoint =
|
|
96
102
|
this.config.endpoint || this.config.driftEnv === 'devnet'
|
|
97
103
|
? 'wss://master.swift.drift.trade/ws'
|
|
@@ -132,7 +138,7 @@ export class SwiftOrderSubscriber {
|
|
|
132
138
|
return;
|
|
133
139
|
}
|
|
134
140
|
|
|
135
|
-
|
|
141
|
+
onOrder(order, swiftOrderParamsMessage);
|
|
136
142
|
}
|
|
137
143
|
});
|
|
138
144
|
|
|
@@ -193,6 +199,9 @@ export class SwiftOrderSubscriber {
|
|
|
193
199
|
if (this.heartbeatTimeout) {
|
|
194
200
|
clearTimeout(this.heartbeatTimeout);
|
|
195
201
|
}
|
|
202
|
+
if (!this.onOrder) {
|
|
203
|
+
throw new Error('onOrder callback function must be set');
|
|
204
|
+
}
|
|
196
205
|
this.heartbeatTimeout = setTimeout(() => {
|
|
197
206
|
console.warn('No heartbeat received within 30 seconds, reconnecting...');
|
|
198
207
|
this.reconnect();
|
|
@@ -207,7 +216,7 @@ export class SwiftOrderSubscriber {
|
|
|
207
216
|
|
|
208
217
|
console.log('Reconnecting to WebSocket...');
|
|
209
218
|
setTimeout(() => {
|
|
210
|
-
this.subscribe();
|
|
219
|
+
this.subscribe(this.onOrder);
|
|
211
220
|
}, 1000);
|
|
212
221
|
}
|
|
213
222
|
}
|