From 45f6413d0df022022ed00643198837d46e2d16b5 Mon Sep 17 00:00:00 2001 From: Luke Steyn Date: Wed, 17 Jul 2024 23:18:55 +0900 Subject: [PATCH] Updated auction end price param calculation to use a min offset based on tick size --- .../src/common-ui-utils/commonUiUtils.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/common-ts/src/common-ui-utils/commonUiUtils.ts b/common-ts/src/common-ui-utils/commonUiUtils.ts index b8bd5c34..cde769d6 100644 --- a/common-ts/src/common-ui-utils/commonUiUtils.ts +++ b/common-ts/src/common-ui-utils/commonUiUtils.ts @@ -41,6 +41,9 @@ import { ORDER_COMMON_UTILS } from './order'; const ACCOUNT_INITIALIZATION_RETRY_DELAY_MS = 1000; const ACCOUNT_INITIALIZATION_RETRY_ATTEMPTS = 5; +// Min number of tick sizes that the auction end price should be away from the otherwise calculated end price +const AUCTION_END_TICK_SIZE_MIN_OFFSET = new BN(3); + export const EMPTY_AUCTION_PARAMS: AuctionParams = { auctionStartPrice: null, auctionEndPrice: null, @@ -344,7 +347,7 @@ const getMarketAuctionParams = ({ worstPrice, limitPrice, duration, - marketTickSize: _marketTickSize, + marketTickSize: marketTickSize, auctionStartPriceOffset, auctionEndPriceOffset, }: { @@ -375,10 +378,15 @@ const getMarketAuctionParams = ({ const worstPriceToUse = BN.max(worstPrice, startPriceFromSettings); // Handles edge cases like if the worst price on the book was better than the oracle price, and the settings are asking to be relative to the oracle price - auctionEndPrice = PRICE_PRECISION.add(auctionEndPriceBuffer) + const bufferedEndPrice = PRICE_PRECISION.add(auctionEndPriceBuffer) .mul(worstPriceToUse) .div(PRICE_PRECISION); + auctionEndPrice = BN.max( + bufferedEndPrice, + worstPriceToUse.add(marketTickSize.mul(AUCTION_END_TICK_SIZE_MIN_OFFSET)) + ); + auctionEndPrice = BN.min(limitPrice, auctionEndPrice); auctionStartPrice = BN.min(auctionStartPrice, auctionEndPrice); @@ -387,10 +395,15 @@ const getMarketAuctionParams = ({ const worstPriceToUse = BN.min(worstPrice, startPriceFromSettings); // Handles edge cases like if the worst price on the book was better than the oracle price, and the settings are asking to be relative to the oracle price - auctionEndPrice = PRICE_PRECISION.sub(auctionEndPriceBuffer) + const bufferedAuctionEndPrice = PRICE_PRECISION.sub(auctionEndPriceBuffer) .mul(worstPriceToUse) .div(PRICE_PRECISION); + auctionEndPrice = BN.min( + bufferedAuctionEndPrice, + worstPriceToUse.sub(marketTickSize.mul(AUCTION_END_TICK_SIZE_MIN_OFFSET)) + ); + auctionEndPrice = BN.max(limitPrice, auctionEndPrice); auctionStartPrice = BN.max(auctionStartPrice, auctionEndPrice);