@drift-labs/jit-proxy 0.10.204 → 0.10.206
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/jitterSniper.js +26 -5
- package/package.json +2 -2
- package/src/jitter/baseJitter.ts +4 -5
- package/src/jitter/jitterShotgun.ts +17 -14
- package/src/jitter/jitterSniper.ts +44 -20
|
@@ -181,6 +181,26 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
181
181
|
}
|
|
182
182
|
slotsTilCross++;
|
|
183
183
|
}
|
|
184
|
+
// if it doesnt cross during auction, check if limit price crosses
|
|
185
|
+
if (!willCross) {
|
|
186
|
+
const slotAfterAuction = order.slot.toNumber() + order.auctionDuration + 1;
|
|
187
|
+
const limitPrice = (0, sdk_1.getLimitPrice)(order, oraclePrice, slotAfterAuction);
|
|
188
|
+
if (!limitPrice) {
|
|
189
|
+
willCross = true;
|
|
190
|
+
slotsTilCross = order.auctionDuration + 1;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
const limitPriceNum = (0, sdk_1.convertToNumber)(limitPrice, sdk_1.PRICE_PRECISION);
|
|
194
|
+
if (makerOrderDir === 'buy' || limitPriceNum <= bid) {
|
|
195
|
+
willCross = true;
|
|
196
|
+
slotsTilCross = order.auctionDuration + 1;
|
|
197
|
+
}
|
|
198
|
+
else if (makerOrderDir === 'sell' || limitPriceNum >= ask) {
|
|
199
|
+
willCross = true;
|
|
200
|
+
slotsTilCross = order.auctionDuration + 1;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
184
204
|
return {
|
|
185
205
|
slotsTilCross,
|
|
186
206
|
willCross,
|
|
@@ -193,11 +213,11 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
193
213
|
};
|
|
194
214
|
}
|
|
195
215
|
async waitForSlotOrCrossOrExpiry(targetSlot, order, initialDetails) {
|
|
196
|
-
const auctionEndSlot = order.auctionDuration + order.slot.toNumber();
|
|
197
216
|
let currentDetails = initialDetails;
|
|
198
217
|
let willCross = initialDetails.willCross;
|
|
199
|
-
if (this.slotSubscriber.currentSlot >
|
|
200
|
-
|
|
218
|
+
if (this.slotSubscriber.currentSlot > targetSlot) {
|
|
219
|
+
const slot = willCross ? this.slotSubscriber.currentSlot : -1;
|
|
220
|
+
return new Promise((resolve) => resolve({ slot, updatedDetails: currentDetails }));
|
|
201
221
|
}
|
|
202
222
|
return new Promise((resolve) => {
|
|
203
223
|
// Immediately return if we are past target slot
|
|
@@ -210,10 +230,11 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
210
230
|
this.slotSubscriber.eventEmitter.once('newSlot', slotListener);
|
|
211
231
|
// Update target slot as the bid/ask and the oracle changes
|
|
212
232
|
const intervalId = setInterval(async () => {
|
|
213
|
-
if (this.slotSubscriber.currentSlot >=
|
|
233
|
+
if (this.slotSubscriber.currentSlot >= targetSlot) {
|
|
214
234
|
this.slotSubscriber.eventEmitter.removeListener('newSlot', slotListener);
|
|
215
235
|
clearInterval(intervalId);
|
|
216
|
-
|
|
236
|
+
const slot = willCross ? this.slotSubscriber.currentSlot : -1;
|
|
237
|
+
resolve({ slot, updatedDetails: currentDetails });
|
|
217
238
|
}
|
|
218
239
|
currentDetails = this.getAuctionAndOrderDetails(order);
|
|
219
240
|
willCross = currentDetails.willCross;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/jit-proxy",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.206",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"clean": "rm -rf lib",
|
|
6
6
|
"build": "yarn clean && tsc"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@coral-xyz/anchor": "^0.26.0",
|
|
10
|
-
"@drift-labs/sdk": "2.
|
|
10
|
+
"@drift-labs/sdk": "2.57.0-beta.0",
|
|
11
11
|
"@solana/web3.js": "1.73.2"
|
|
12
12
|
},
|
|
13
13
|
"engines": {
|
package/src/jitter/baseJitter.ts
CHANGED
|
@@ -68,11 +68,10 @@ export abstract class BaseJitter {
|
|
|
68
68
|
this.jitProxyClient = jitProxyClient;
|
|
69
69
|
this.userStatsMap =
|
|
70
70
|
userStatsMap ||
|
|
71
|
-
new UserStatsMap(
|
|
72
|
-
this.driftClient
|
|
73
|
-
'confirmed',
|
|
74
|
-
|
|
75
|
-
));
|
|
71
|
+
new UserStatsMap(
|
|
72
|
+
this.driftClient,
|
|
73
|
+
new BulkAccountLoader(this.driftClient.connection, 'confirmed', 0)
|
|
74
|
+
);
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
async subscribe(): Promise<void> {
|
|
@@ -73,20 +73,23 @@ export class JitterShotgun extends BaseJitter {
|
|
|
73
73
|
|
|
74
74
|
console.log(`Trying to fill ${orderSignature}`);
|
|
75
75
|
try {
|
|
76
|
-
const { txSig } = await this.jitProxyClient.jit(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
76
|
+
const { txSig } = await this.jitProxyClient.jit(
|
|
77
|
+
{
|
|
78
|
+
takerKey,
|
|
79
|
+
takerStatsKey,
|
|
80
|
+
taker,
|
|
81
|
+
takerOrderId: order.orderId,
|
|
82
|
+
maxPosition: params.maxPosition,
|
|
83
|
+
minPosition: params.minPosition,
|
|
84
|
+
bid: params.bid,
|
|
85
|
+
ask: params.ask,
|
|
86
|
+
postOnly: null,
|
|
87
|
+
priceType: params.priceType,
|
|
88
|
+
referrerInfo,
|
|
89
|
+
subAccountId: params.subAccountId,
|
|
90
|
+
},
|
|
91
|
+
txParams
|
|
92
|
+
);
|
|
90
93
|
|
|
91
94
|
console.log(`Filled ${orderSignature} txSig ${txSig}`);
|
|
92
95
|
await sleep(10000);
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
DriftClient,
|
|
7
7
|
getAuctionPrice,
|
|
8
8
|
getAuctionPriceForOracleOffsetAuction,
|
|
9
|
+
getLimitPrice,
|
|
9
10
|
getVariant,
|
|
10
11
|
isVariant,
|
|
11
12
|
OraclePriceData,
|
|
@@ -191,21 +192,24 @@ export class JitterSniper extends BaseJitter {
|
|
|
191
192
|
const txParams = {
|
|
192
193
|
computeUnits: this.computeUnits,
|
|
193
194
|
computeUnitsPrice: this.computeUnitsPrice,
|
|
194
|
-
}
|
|
195
|
-
const { txSig } = await this.jitProxyClient.jit(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
195
|
+
};
|
|
196
|
+
const { txSig } = await this.jitProxyClient.jit(
|
|
197
|
+
{
|
|
198
|
+
takerKey,
|
|
199
|
+
takerStatsKey,
|
|
200
|
+
taker,
|
|
201
|
+
takerOrderId: order.orderId,
|
|
202
|
+
maxPosition: params.maxPosition,
|
|
203
|
+
minPosition: params.minPosition,
|
|
204
|
+
bid: params.bid,
|
|
205
|
+
ask: params.ask,
|
|
206
|
+
postOnly: null,
|
|
207
|
+
priceType: params.priceType,
|
|
208
|
+
referrerInfo,
|
|
209
|
+
subAccountId: params.subAccountId,
|
|
210
|
+
},
|
|
211
|
+
txParams
|
|
212
|
+
);
|
|
209
213
|
|
|
210
214
|
console.log(`Filled ${orderSignature} txSig ${txSig}`);
|
|
211
215
|
await sleep(3000);
|
|
@@ -308,6 +312,25 @@ export class JitterSniper extends BaseJitter {
|
|
|
308
312
|
slotsTilCross++;
|
|
309
313
|
}
|
|
310
314
|
|
|
315
|
+
// if it doesnt cross during auction, check if limit price crosses
|
|
316
|
+
if (!willCross) {
|
|
317
|
+
const slotAfterAuction = order.slot.toNumber() + order.auctionDuration + 1;
|
|
318
|
+
const limitPrice = getLimitPrice(order, oraclePrice, slotAfterAuction);
|
|
319
|
+
if (!limitPrice) {
|
|
320
|
+
willCross = true;
|
|
321
|
+
slotsTilCross = order.auctionDuration + 1;
|
|
322
|
+
} else {
|
|
323
|
+
const limitPriceNum = convertToNumber(limitPrice, PRICE_PRECISION);
|
|
324
|
+
if (makerOrderDir === 'buy' || limitPriceNum <= bid) {
|
|
325
|
+
willCross = true;
|
|
326
|
+
slotsTilCross = order.auctionDuration + 1;
|
|
327
|
+
} else if (makerOrderDir === 'sell' || limitPriceNum >= ask) {
|
|
328
|
+
willCross = true;
|
|
329
|
+
slotsTilCross = order.auctionDuration + 1;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
311
334
|
return {
|
|
312
335
|
slotsTilCross,
|
|
313
336
|
willCross,
|
|
@@ -325,12 +348,12 @@ export class JitterSniper extends BaseJitter {
|
|
|
325
348
|
order: Order,
|
|
326
349
|
initialDetails: AuctionAndOrderDetails
|
|
327
350
|
): Promise<{ slot: number; updatedDetails: AuctionAndOrderDetails }> {
|
|
328
|
-
const auctionEndSlot = order.auctionDuration + order.slot.toNumber();
|
|
329
351
|
let currentDetails: AuctionAndOrderDetails = initialDetails;
|
|
330
352
|
let willCross = initialDetails.willCross;
|
|
331
|
-
if (this.slotSubscriber.currentSlot >
|
|
353
|
+
if (this.slotSubscriber.currentSlot > targetSlot) {
|
|
354
|
+
const slot = willCross ? this.slotSubscriber.currentSlot : -1;
|
|
332
355
|
return new Promise((resolve) =>
|
|
333
|
-
resolve({ slot
|
|
356
|
+
resolve({ slot, updatedDetails: currentDetails })
|
|
334
357
|
);
|
|
335
358
|
}
|
|
336
359
|
|
|
@@ -348,13 +371,14 @@ export class JitterSniper extends BaseJitter {
|
|
|
348
371
|
|
|
349
372
|
// Update target slot as the bid/ask and the oracle changes
|
|
350
373
|
const intervalId = setInterval(async () => {
|
|
351
|
-
if (this.slotSubscriber.currentSlot >=
|
|
374
|
+
if (this.slotSubscriber.currentSlot >= targetSlot) {
|
|
352
375
|
this.slotSubscriber.eventEmitter.removeListener(
|
|
353
376
|
'newSlot',
|
|
354
377
|
slotListener
|
|
355
378
|
);
|
|
356
379
|
clearInterval(intervalId);
|
|
357
|
-
|
|
380
|
+
const slot = willCross ? this.slotSubscriber.currentSlot : -1;
|
|
381
|
+
resolve({ slot, updatedDetails: currentDetails });
|
|
358
382
|
}
|
|
359
383
|
|
|
360
384
|
currentDetails = this.getAuctionAndOrderDetails(order);
|