-
Notifications
You must be signed in to change notification settings - Fork 100
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
Crispheaney/guard bad limit order fills #304
Changes from 3 commits
e1b1d5f
7cb05b3
73c7962
6529e30
c06c8e9
86750dd
7bbb64f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,9 @@ import { | |
UserMap, | ||
OrderRecord, | ||
OrderActionRecord, | ||
isLimitOrder, | ||
ZERO, | ||
BN_MAX, | ||
} from '..'; | ||
import { PublicKey } from '@solana/web3.js'; | ||
import { DLOBNode, DLOBNodeType, TriggerOrderNode } from '..'; | ||
|
@@ -1009,7 +1012,9 @@ export class DLOB { | |
marketIndex: number, | ||
slot: number, | ||
marketType: MarketType, | ||
oraclePriceData: OraclePriceData | ||
oraclePriceData: OraclePriceData, | ||
fallbackAsk: BN | undefined, | ||
fallbackBid: BN | undefined | ||
): NodeToFill[] { | ||
const nodesToFill = new Array<NodeToFill>(); | ||
|
||
|
@@ -1047,6 +1052,33 @@ export class DLOB { | |
bidNode | ||
); | ||
|
||
// extra guard against bad fills for perp limit orders where auction is incomplete | ||
if ( | ||
isVariant(takerNode.order.marketType, 'perp') && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we really want to enforce market type here? this seems like a nice check for spot as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's a bit tricky to do it on the smart contract, but we always try to fill against serum first, so i think it's ok to remove the perp check here |
||
isLimitOrder(takerNode.order) && | ||
!isAuctionComplete(takerNode.order, slot) | ||
) { | ||
let bidPrice: BN; | ||
let askPrice: BN; | ||
if (isVariant(takerNode.order.direction, 'long')) { | ||
bidPrice = BN.min( | ||
takerNode.getPrice(oraclePriceData, slot), | ||
fallbackAsk || BN_MAX | ||
); | ||
askPrice = makerNode.getPrice(oraclePriceData, slot); | ||
} else { | ||
bidPrice = makerNode.getPrice(oraclePriceData, slot); | ||
askPrice = BN.max( | ||
takerNode.getPrice(oraclePriceData, slot), | ||
fallbackBid || ZERO | ||
); | ||
} | ||
|
||
if (bidPrice.lt(askPrice)) { | ||
continue; | ||
} | ||
} | ||
|
||
const bidBaseRemaining = bidOrder.baseAssetAmount.sub( | ||
bidOrder.baseAssetAmountFilled | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should check vs
min_perp_auction_duration
instead of auction completeness