@drift-labs/jit-proxy 0.10.205 → 0.10.207
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/lib/jitter/baseJitter.d.ts +2 -1
- package/lib/jitter/jitterShotgun.d.ts +2 -11
- package/lib/jitter/jitterShotgun.js +3 -1
- package/lib/jitter/jitterSniper.js +28 -6
- package/package.json +1 -1
- package/src/jitter/baseJitter.ts +6 -11
- package/src/jitter/jitterShotgun.ts +18 -30
- package/src/jitter/jitterSniper.ts +45 -20
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="@pythnetwork/client/node_modules/@solana/web3.js" />
|
|
2
2
|
import { JitProxyClient, PriceType } from '../jitProxyClient';
|
|
3
3
|
import { PublicKey } from '@solana/web3.js';
|
|
4
|
-
import { AuctionSubscriber, BN, DriftClient, Order, UserAccount, UserStatsMap } from '@drift-labs/sdk';
|
|
4
|
+
import { AuctionSubscriber, BN, DriftClient, Order, PostOnlyParams, UserAccount, UserStatsMap } from '@drift-labs/sdk';
|
|
5
5
|
export type UserFilter = (userAccount: UserAccount, userKey: string, order: Order) => boolean;
|
|
6
6
|
export type JitParams = {
|
|
7
7
|
bid: BN;
|
|
@@ -10,6 +10,7 @@ export type JitParams = {
|
|
|
10
10
|
maxPosition: any;
|
|
11
11
|
priceType: PriceType;
|
|
12
12
|
subAccountId?: number;
|
|
13
|
+
postOnlyParams?: PostOnlyParams;
|
|
13
14
|
};
|
|
14
15
|
export declare abstract class BaseJitter {
|
|
15
16
|
auctionSubscriber: AuctionSubscriber;
|
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
/// <reference types="@pythnetwork/client/node_modules/@solana/web3.js" />
|
|
2
|
-
import { JitProxyClient
|
|
2
|
+
import { JitProxyClient } from '../jitProxyClient';
|
|
3
3
|
import { PublicKey } from '@solana/web3.js';
|
|
4
|
-
import { AuctionSubscriber,
|
|
4
|
+
import { AuctionSubscriber, DriftClient, Order, UserAccount, UserStatsMap } from '@drift-labs/sdk';
|
|
5
5
|
import { BaseJitter } from './baseJitter';
|
|
6
|
-
export type UserFilter = (userAccount: UserAccount, userKey: string, order: Order) => boolean;
|
|
7
|
-
export type JitParams = {
|
|
8
|
-
bid: BN;
|
|
9
|
-
ask: BN;
|
|
10
|
-
minPosition: BN;
|
|
11
|
-
maxPosition: any;
|
|
12
|
-
priceType: PriceType;
|
|
13
|
-
subAccountId?: number;
|
|
14
|
-
};
|
|
15
6
|
export declare class JitterShotgun extends BaseJitter {
|
|
16
7
|
constructor({ auctionSubscriber, jitProxyClient, driftClient, userStatsMap, }: {
|
|
17
8
|
driftClient: DriftClient;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JitterShotgun = void 0;
|
|
4
|
+
const sdk_1 = require("@drift-labs/sdk");
|
|
4
5
|
const baseJitter_1 = require("./baseJitter");
|
|
5
6
|
class JitterShotgun extends baseJitter_1.BaseJitter {
|
|
6
7
|
constructor({ auctionSubscriber, jitProxyClient, driftClient, userStatsMap, }) {
|
|
@@ -13,6 +14,7 @@ class JitterShotgun extends baseJitter_1.BaseJitter {
|
|
|
13
14
|
}
|
|
14
15
|
createTryFill(taker, takerKey, takerStatsKey, order, orderSignature) {
|
|
15
16
|
return async () => {
|
|
17
|
+
var _a;
|
|
16
18
|
let i = 0;
|
|
17
19
|
while (i < 10) {
|
|
18
20
|
const params = this.perpParams.get(order.marketIndex);
|
|
@@ -37,7 +39,7 @@ class JitterShotgun extends baseJitter_1.BaseJitter {
|
|
|
37
39
|
minPosition: params.minPosition,
|
|
38
40
|
bid: params.bid,
|
|
39
41
|
ask: params.ask,
|
|
40
|
-
postOnly: null,
|
|
42
|
+
postOnly: (_a = params.postOnlyParams) !== null && _a !== void 0 ? _a : sdk_1.PostOnlyParams.MUST_POST_ONLY,
|
|
41
43
|
priceType: params.priceType,
|
|
42
44
|
referrerInfo,
|
|
43
45
|
subAccountId: params.subAccountId,
|
|
@@ -65,6 +65,7 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
65
65
|
stepSize,
|
|
66
66
|
oraclePrice,
|
|
67
67
|
}).then(async ({ slot, updatedDetails }) => {
|
|
68
|
+
var _a;
|
|
68
69
|
if (slot === -1) {
|
|
69
70
|
console.log('Auction expired without crossing');
|
|
70
71
|
this.deleteOnGoingAuction(orderSignature);
|
|
@@ -108,7 +109,7 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
108
109
|
minPosition: params.minPosition,
|
|
109
110
|
bid: params.bid,
|
|
110
111
|
ask: params.ask,
|
|
111
|
-
postOnly: null,
|
|
112
|
+
postOnly: (_a = params.postOnlyParams) !== null && _a !== void 0 ? _a : sdk_1.PostOnlyParams.MUST_POST_ONLY,
|
|
112
113
|
priceType: params.priceType,
|
|
113
114
|
referrerInfo,
|
|
114
115
|
subAccountId: params.subAccountId,
|
|
@@ -181,6 +182,26 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
181
182
|
}
|
|
182
183
|
slotsTilCross++;
|
|
183
184
|
}
|
|
185
|
+
// if it doesnt cross during auction, check if limit price crosses
|
|
186
|
+
if (!willCross) {
|
|
187
|
+
const slotAfterAuction = order.slot.toNumber() + order.auctionDuration + 1;
|
|
188
|
+
const limitPrice = (0, sdk_1.getLimitPrice)(order, oraclePrice, slotAfterAuction);
|
|
189
|
+
if (!limitPrice) {
|
|
190
|
+
willCross = true;
|
|
191
|
+
slotsTilCross = order.auctionDuration + 1;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
const limitPriceNum = (0, sdk_1.convertToNumber)(limitPrice, sdk_1.PRICE_PRECISION);
|
|
195
|
+
if (makerOrderDir === 'buy' || limitPriceNum <= bid) {
|
|
196
|
+
willCross = true;
|
|
197
|
+
slotsTilCross = order.auctionDuration + 1;
|
|
198
|
+
}
|
|
199
|
+
else if (makerOrderDir === 'sell' || limitPriceNum >= ask) {
|
|
200
|
+
willCross = true;
|
|
201
|
+
slotsTilCross = order.auctionDuration + 1;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
184
205
|
return {
|
|
185
206
|
slotsTilCross,
|
|
186
207
|
willCross,
|
|
@@ -193,11 +214,11 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
193
214
|
};
|
|
194
215
|
}
|
|
195
216
|
async waitForSlotOrCrossOrExpiry(targetSlot, order, initialDetails) {
|
|
196
|
-
const auctionEndSlot = order.auctionDuration + order.slot.toNumber();
|
|
197
217
|
let currentDetails = initialDetails;
|
|
198
218
|
let willCross = initialDetails.willCross;
|
|
199
|
-
if (this.slotSubscriber.currentSlot >
|
|
200
|
-
|
|
219
|
+
if (this.slotSubscriber.currentSlot > targetSlot) {
|
|
220
|
+
const slot = willCross ? this.slotSubscriber.currentSlot : -1;
|
|
221
|
+
return new Promise((resolve) => resolve({ slot, updatedDetails: currentDetails }));
|
|
201
222
|
}
|
|
202
223
|
return new Promise((resolve) => {
|
|
203
224
|
// Immediately return if we are past target slot
|
|
@@ -210,10 +231,11 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
210
231
|
this.slotSubscriber.eventEmitter.once('newSlot', slotListener);
|
|
211
232
|
// Update target slot as the bid/ask and the oracle changes
|
|
212
233
|
const intervalId = setInterval(async () => {
|
|
213
|
-
if (this.slotSubscriber.currentSlot >=
|
|
234
|
+
if (this.slotSubscriber.currentSlot >= targetSlot) {
|
|
214
235
|
this.slotSubscriber.eventEmitter.removeListener('newSlot', slotListener);
|
|
215
236
|
clearInterval(intervalId);
|
|
216
|
-
|
|
237
|
+
const slot = willCross ? this.slotSubscriber.currentSlot : -1;
|
|
238
|
+
resolve({ slot, updatedDetails: currentDetails });
|
|
217
239
|
}
|
|
218
240
|
currentDetails = this.getAuctionAndOrderDetails(order);
|
|
219
241
|
willCross = currentDetails.willCross;
|
package/package.json
CHANGED
package/src/jitter/baseJitter.ts
CHANGED
|
@@ -5,17 +5,12 @@ import {
|
|
|
5
5
|
AuctionSubscriber,
|
|
6
6
|
BN,
|
|
7
7
|
BulkAccountLoader,
|
|
8
|
-
convertToNumber,
|
|
9
8
|
DriftClient,
|
|
10
|
-
getAuctionPrice,
|
|
11
|
-
getAuctionPriceForOracleOffsetAuction,
|
|
12
9
|
getUserStatsAccountPublicKey,
|
|
13
10
|
hasAuctionPrice,
|
|
14
11
|
isVariant,
|
|
15
|
-
OraclePriceData,
|
|
16
12
|
Order,
|
|
17
|
-
|
|
18
|
-
SlotSubscriber,
|
|
13
|
+
PostOnlyParams,
|
|
19
14
|
UserAccount,
|
|
20
15
|
UserStatsMap,
|
|
21
16
|
} from '@drift-labs/sdk';
|
|
@@ -33,6 +28,7 @@ export type JitParams = {
|
|
|
33
28
|
maxPosition;
|
|
34
29
|
priceType: PriceType;
|
|
35
30
|
subAccountId?: number;
|
|
31
|
+
postOnlyParams?: PostOnlyParams;
|
|
36
32
|
};
|
|
37
33
|
|
|
38
34
|
export abstract class BaseJitter {
|
|
@@ -68,11 +64,10 @@ export abstract class BaseJitter {
|
|
|
68
64
|
this.jitProxyClient = jitProxyClient;
|
|
69
65
|
this.userStatsMap =
|
|
70
66
|
userStatsMap ||
|
|
71
|
-
new UserStatsMap(
|
|
72
|
-
this.driftClient
|
|
73
|
-
'confirmed',
|
|
74
|
-
|
|
75
|
-
));
|
|
67
|
+
new UserStatsMap(
|
|
68
|
+
this.driftClient,
|
|
69
|
+
new BulkAccountLoader(this.driftClient.connection, 'confirmed', 0)
|
|
70
|
+
);
|
|
76
71
|
}
|
|
77
72
|
|
|
78
73
|
async subscribe(): Promise<void> {
|
|
@@ -2,29 +2,14 @@ import { JitProxyClient, PriceType } from '../jitProxyClient';
|
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import {
|
|
4
4
|
AuctionSubscriber,
|
|
5
|
-
BN,
|
|
6
5
|
DriftClient,
|
|
7
6
|
Order,
|
|
7
|
+
PostOnlyParams,
|
|
8
8
|
UserAccount,
|
|
9
9
|
UserStatsMap,
|
|
10
10
|
} from '@drift-labs/sdk';
|
|
11
11
|
import { BaseJitter } from './baseJitter';
|
|
12
12
|
|
|
13
|
-
export type UserFilter = (
|
|
14
|
-
userAccount: UserAccount,
|
|
15
|
-
userKey: string,
|
|
16
|
-
order: Order
|
|
17
|
-
) => boolean;
|
|
18
|
-
|
|
19
|
-
export type JitParams = {
|
|
20
|
-
bid: BN;
|
|
21
|
-
ask: BN;
|
|
22
|
-
minPosition: BN;
|
|
23
|
-
maxPosition;
|
|
24
|
-
priceType: PriceType;
|
|
25
|
-
subAccountId?: number;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
13
|
export class JitterShotgun extends BaseJitter {
|
|
29
14
|
constructor({
|
|
30
15
|
auctionSubscriber,
|
|
@@ -73,20 +58,23 @@ export class JitterShotgun extends BaseJitter {
|
|
|
73
58
|
|
|
74
59
|
console.log(`Trying to fill ${orderSignature}`);
|
|
75
60
|
try {
|
|
76
|
-
const { txSig } = await this.jitProxyClient.jit(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
61
|
+
const { txSig } = await this.jitProxyClient.jit(
|
|
62
|
+
{
|
|
63
|
+
takerKey,
|
|
64
|
+
takerStatsKey,
|
|
65
|
+
taker,
|
|
66
|
+
takerOrderId: order.orderId,
|
|
67
|
+
maxPosition: params.maxPosition,
|
|
68
|
+
minPosition: params.minPosition,
|
|
69
|
+
bid: params.bid,
|
|
70
|
+
ask: params.ask,
|
|
71
|
+
postOnly: params.postOnlyParams ?? PostOnlyParams.MUST_POST_ONLY,
|
|
72
|
+
priceType: params.priceType,
|
|
73
|
+
referrerInfo,
|
|
74
|
+
subAccountId: params.subAccountId,
|
|
75
|
+
},
|
|
76
|
+
txParams
|
|
77
|
+
);
|
|
90
78
|
|
|
91
79
|
console.log(`Filled ${orderSignature} txSig ${txSig}`);
|
|
92
80
|
await sleep(10000);
|
|
@@ -6,10 +6,12 @@ import {
|
|
|
6
6
|
DriftClient,
|
|
7
7
|
getAuctionPrice,
|
|
8
8
|
getAuctionPriceForOracleOffsetAuction,
|
|
9
|
+
getLimitPrice,
|
|
9
10
|
getVariant,
|
|
10
11
|
isVariant,
|
|
11
12
|
OraclePriceData,
|
|
12
13
|
Order,
|
|
14
|
+
PostOnlyParams,
|
|
13
15
|
PRICE_PRECISION,
|
|
14
16
|
SlotSubscriber,
|
|
15
17
|
UserAccount,
|
|
@@ -191,21 +193,24 @@ export class JitterSniper extends BaseJitter {
|
|
|
191
193
|
const txParams = {
|
|
192
194
|
computeUnits: this.computeUnits,
|
|
193
195
|
computeUnitsPrice: this.computeUnitsPrice,
|
|
194
|
-
}
|
|
195
|
-
const { txSig } = await this.jitProxyClient.jit(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
196
|
+
};
|
|
197
|
+
const { txSig } = await this.jitProxyClient.jit(
|
|
198
|
+
{
|
|
199
|
+
takerKey,
|
|
200
|
+
takerStatsKey,
|
|
201
|
+
taker,
|
|
202
|
+
takerOrderId: order.orderId,
|
|
203
|
+
maxPosition: params.maxPosition,
|
|
204
|
+
minPosition: params.minPosition,
|
|
205
|
+
bid: params.bid,
|
|
206
|
+
ask: params.ask,
|
|
207
|
+
postOnly: params.postOnlyParams ?? PostOnlyParams.MUST_POST_ONLY,
|
|
208
|
+
priceType: params.priceType,
|
|
209
|
+
referrerInfo,
|
|
210
|
+
subAccountId: params.subAccountId,
|
|
211
|
+
},
|
|
212
|
+
txParams
|
|
213
|
+
);
|
|
209
214
|
|
|
210
215
|
console.log(`Filled ${orderSignature} txSig ${txSig}`);
|
|
211
216
|
await sleep(3000);
|
|
@@ -308,6 +313,25 @@ export class JitterSniper extends BaseJitter {
|
|
|
308
313
|
slotsTilCross++;
|
|
309
314
|
}
|
|
310
315
|
|
|
316
|
+
// if it doesnt cross during auction, check if limit price crosses
|
|
317
|
+
if (!willCross) {
|
|
318
|
+
const slotAfterAuction = order.slot.toNumber() + order.auctionDuration + 1;
|
|
319
|
+
const limitPrice = getLimitPrice(order, oraclePrice, slotAfterAuction);
|
|
320
|
+
if (!limitPrice) {
|
|
321
|
+
willCross = true;
|
|
322
|
+
slotsTilCross = order.auctionDuration + 1;
|
|
323
|
+
} else {
|
|
324
|
+
const limitPriceNum = convertToNumber(limitPrice, PRICE_PRECISION);
|
|
325
|
+
if (makerOrderDir === 'buy' || limitPriceNum <= bid) {
|
|
326
|
+
willCross = true;
|
|
327
|
+
slotsTilCross = order.auctionDuration + 1;
|
|
328
|
+
} else if (makerOrderDir === 'sell' || limitPriceNum >= ask) {
|
|
329
|
+
willCross = true;
|
|
330
|
+
slotsTilCross = order.auctionDuration + 1;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
311
335
|
return {
|
|
312
336
|
slotsTilCross,
|
|
313
337
|
willCross,
|
|
@@ -325,12 +349,12 @@ export class JitterSniper extends BaseJitter {
|
|
|
325
349
|
order: Order,
|
|
326
350
|
initialDetails: AuctionAndOrderDetails
|
|
327
351
|
): Promise<{ slot: number; updatedDetails: AuctionAndOrderDetails }> {
|
|
328
|
-
const auctionEndSlot = order.auctionDuration + order.slot.toNumber();
|
|
329
352
|
let currentDetails: AuctionAndOrderDetails = initialDetails;
|
|
330
353
|
let willCross = initialDetails.willCross;
|
|
331
|
-
if (this.slotSubscriber.currentSlot >
|
|
354
|
+
if (this.slotSubscriber.currentSlot > targetSlot) {
|
|
355
|
+
const slot = willCross ? this.slotSubscriber.currentSlot : -1;
|
|
332
356
|
return new Promise((resolve) =>
|
|
333
|
-
resolve({ slot
|
|
357
|
+
resolve({ slot, updatedDetails: currentDetails })
|
|
334
358
|
);
|
|
335
359
|
}
|
|
336
360
|
|
|
@@ -348,13 +372,14 @@ export class JitterSniper extends BaseJitter {
|
|
|
348
372
|
|
|
349
373
|
// Update target slot as the bid/ask and the oracle changes
|
|
350
374
|
const intervalId = setInterval(async () => {
|
|
351
|
-
if (this.slotSubscriber.currentSlot >=
|
|
375
|
+
if (this.slotSubscriber.currentSlot >= targetSlot) {
|
|
352
376
|
this.slotSubscriber.eventEmitter.removeListener(
|
|
353
377
|
'newSlot',
|
|
354
378
|
slotListener
|
|
355
379
|
);
|
|
356
380
|
clearInterval(intervalId);
|
|
357
|
-
|
|
381
|
+
const slot = willCross ? this.slotSubscriber.currentSlot : -1;
|
|
382
|
+
resolve({ slot, updatedDetails: currentDetails });
|
|
358
383
|
}
|
|
359
384
|
|
|
360
385
|
currentDetails = this.getAuctionAndOrderDetails(order);
|