It is assumed that the reader has already read the documentation on the OrderBook contract before starting with this. Refer to the OrderBook contract documentation here :

OrderBook Contract

To understand why flip orders exist, please refer here :

Flip Orders

Before delving into how flip orders function, we will first look at what encompasses an order:

struct Order {
	address ownerAddress;
	uint96 size;
	uint40 prev;
	uint40 next;
	uint40 flippedId;
	uint32 price;
	uint32 flippedPrice;
	bool isBuy;
}

Non-flip orders are all orders where $flippedPrice = 0$. This means that flip orders aren’t necessarily a new type of order, but a subset of an order itself.

Constraints Of A Flip Order

  1. The $flippedPrice$ must not be equal to zero, which otherwise will make it a normal order.
  2. If $flippedId ≠ NULL$, it means that there should definitely be an active order on the other side with $size ≠ 0$.
  3. If $isBuy = true$, the condition $flippedPrice > price$ must be true and if $isBuy = false$, the condition $price > flippedPrice$ must be true.

A brief overview of the lifecycle of a flip order is given in the non-technical documentation. Here, we will deep dive into the technical lifecycle of a flip order.

Flip Order Placement

The main entry points for placing a flip order are addFlipBuyOrder and addFlipSellOrder.

Both of them have the same input parameters :

  1. price - The price at which the order should be placed
  2. flippedPrice - The price to which the order should be flipped