@@ -349,6 +349,7 @@ const getMarketAuctionParams = ({
349
349
duration,
350
350
auctionStartPriceOffset,
351
351
auctionEndPriceOffset,
352
+ additionalEndPriceBuffer,
352
353
} : {
353
354
direction : PositionDirection ;
354
355
startPriceFromSettings : BN ;
@@ -357,13 +358,14 @@ const getMarketAuctionParams = ({
357
358
duration : number ;
358
359
auctionStartPriceOffset : number ;
359
360
auctionEndPriceOffset : number ;
361
+ additionalEndPriceBuffer ?: BN ;
360
362
} ) : AuctionParams => {
361
363
let auctionStartPrice : BN ;
362
364
let auctionEndPrice : BN ;
363
365
let constrainedBySlippage : boolean ;
364
366
365
367
const auctionEndPriceBuffer = BigNum . from ( PRICE_PRECISION ) . scale (
366
- auctionEndPriceOffset * 100 ,
368
+ Math . abs ( auctionEndPriceOffset * 100 ) ,
367
369
10000
368
370
) . val ;
369
371
@@ -389,6 +391,12 @@ const getMarketAuctionParams = ({
389
391
// use BEST (limit price, auction end price) as end price
390
392
auctionEndPrice = BN . min ( limitPrice , auctionEndPrice ) ;
391
393
394
+ // apply additional buffer if provided
395
+ if ( additionalEndPriceBuffer ) {
396
+ auctionEndPrice = auctionEndPrice . add ( additionalEndPriceBuffer ) ;
397
+ constrainedBySlippage = limitPrice . lt ( auctionEndPrice ) ;
398
+ }
399
+
392
400
auctionStartPrice = BN . min ( auctionStartPrice , auctionEndPrice ) ;
393
401
} else {
394
402
auctionStartPrice = startPriceFromSettings . add ( auctionStartPriceBuffer ) ;
@@ -407,6 +415,12 @@ const getMarketAuctionParams = ({
407
415
// use BEST (limit price, auction end price) as end price
408
416
auctionEndPrice = BN . max ( limitPrice , auctionEndPrice ) ;
409
417
418
+ // apply additional buffer if provided
419
+ if ( additionalEndPriceBuffer ) {
420
+ auctionEndPrice = auctionEndPrice . sub ( additionalEndPriceBuffer ) ;
421
+ constrainedBySlippage = limitPrice . gt ( auctionEndPrice ) ;
422
+ }
423
+
410
424
auctionStartPrice = BN . max ( auctionStartPrice , auctionEndPrice ) ;
411
425
}
412
426
@@ -445,6 +459,7 @@ const deriveMarketOrderParams = ({
445
459
auctionPriceCaps,
446
460
slippageTolerance,
447
461
isOracleOrder,
462
+ additionalEndPriceBuffer,
448
463
} : {
449
464
marketType : MarketType ;
450
465
marketIndex : number ;
@@ -470,6 +485,7 @@ const deriveMarketOrderParams = ({
470
485
auctionEndPriceOffsetFrom : TradeOffsetPrice ;
471
486
slippageTolerance : number ;
472
487
isOracleOrder ?: boolean ;
488
+ additionalEndPriceBuffer ?: BN ;
473
489
} ) : OptionalOrderParams & { constrainedBySlippage ?: boolean } => {
474
490
const priceObject = getPriceObject ( {
475
491
oraclePrice,
@@ -481,12 +497,18 @@ const deriveMarketOrderParams = ({
481
497
} ) ;
482
498
483
499
// max slippage price
484
- const limitPrice = getMarketOrderLimitPrice ( {
500
+ let limitPrice = getMarketOrderLimitPrice ( {
485
501
direction,
486
502
baselinePrice : priceObject [ auctionStartPriceOffsetFrom ] ,
487
503
slippageTolerance : allowInfSlippage ? undefined : slippageTolerance ,
488
504
} ) ;
489
505
506
+ if ( additionalEndPriceBuffer ) {
507
+ limitPrice = isVariant ( direction , 'long' )
508
+ ? limitPrice . add ( additionalEndPriceBuffer )
509
+ : limitPrice . sub ( additionalEndPriceBuffer ) ;
510
+ }
511
+
490
512
const auctionParams = getMarketAuctionParams ( {
491
513
direction,
492
514
startPriceFromSettings : priceObject [ auctionStartPriceOffsetFrom ] ,
@@ -495,6 +517,7 @@ const deriveMarketOrderParams = ({
495
517
duration : auctionDuration ,
496
518
auctionStartPriceOffset : auctionStartPriceOffset ,
497
519
auctionEndPriceOffset : auctionEndPriceOffset ,
520
+ additionalEndPriceBuffer,
498
521
} ) ;
499
522
500
523
let orderParams = getMarketOrderParams ( {
0 commit comments