Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

luke/dpe-2140-patch-auction-end-price #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions common-ts/src/common-ui-utils/commonUiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -344,7 +347,7 @@ const getMarketAuctionParams = ({
worstPrice,
limitPrice,
duration,
marketTickSize: _marketTickSize,
marketTickSize: marketTickSize,
auctionStartPriceOffset,
auctionEndPriceOffset,
}: {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down