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
- takerKey,
197
- takerStatsKey,
198
- taker,
199
- takerOrderId : order . orderId ,
200
- maxPosition : params . maxPosition ,
201
- minPosition : params . minPosition ,
202
- bid : params . bid ,
203
- ask : params . ask ,
204
- postOnly : null ,
205
- priceType : params . priceType ,
206
- referrerInfo,
207
- subAccountId : params . subAccountId ,
208
- } , txParams ) ;
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 > auctionEndSlot ) {
353
+ if ( this . slotSubscriber . currentSlot > targetSlot ) {
354
+ const slot = willCross ? this . slotSubscriber . currentSlot : - 1 ;
332
355
return new Promise ( ( resolve ) =>
333
- resolve ( { slot : - 1 , updatedDetails : currentDetails } )
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 >= auctionEndSlot ) {
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
- resolve ( { slot : - 1 , updatedDetails : currentDetails } ) ;
380
+ const slot = willCross ? this . slotSubscriber . currentSlot : - 1 ;
381
+ resolve ( { slot, updatedDetails : currentDetails } ) ;
358
382
}
359
383
360
384
currentDetails = this . getAuctionAndOrderDetails ( order ) ;
0 commit comments