Many helper functions are omitted for brevity.
struct Book {
MarketConfig marketConfig;
TokenConfig tokenConfig;
uint256 quoteTokenOpenInterestInAtoms;
uint256 baseTokenOpenInterestInAtoms;
uint256 nextOrderId;
uint256 numBids;
uint256 numAsks;
RedBlackTree bidTree;
RedBlackTree askTree;
mapping(uint256 => Order) orders;
mapping(uint256 => Limit) bidLimits;
mapping(uint256 => Limit) askLimits;
}
removeOrderFromBook
function removeOrderFromBook(
Book storage self,
Order memory order
) internal
Removes a specified order from the book, updating the relevant limits and open interest.
addOrderToBook
function addOrderToBook(
Book storage self,
Order memory order
) internal
Adds a new order to the book, updating the relevant limits and open interest.
getOrder
function getOrder(
Book storage self,
uint256 orderId
) internal view returns (Order storage)
Retrieves an order from the book using the specified order ID.
getLimit
function getLimit(
Book storage self,
uint256 priceInTicks,
Side side
) internal view returns (Limit storage)
Retrieves the limit at a specified price and side (buy or sell) from the book.
getMaxBidPriceInTicks
function getMaxBidPriceInTicks(
Book storage self
) internal view returns (uint256)
Returns the maximum bid price in ticks from the book.
getMinBidPriceInTicks
function getMinBidPriceInTicks(
Book storage self
) internal view returns (uint256)
Returns the minimum bid price in ticks from the book.
getMaxAskPriceInTicks
function getMaxAskPriceInTicks(
Book storage self
) internal view returns (uint256)
Returns the maximum ask price in ticks from the book.
getMinAskPriceInTicks
function getMinAskPriceInTicks(
Book storage self
) internal view returns (uint256)
Returns the minimum ask price in ticks from the book.
getMaxNumOrders
function getMaxNumOrders(
Book storage self
) internal view returns (uint256)
Returns the maximum number of orders allowed in the book.
getTOB
function getTOB(
Book storage self
) internal view returns (uint256, uint256)
Returns the top of book prices, which are the maximum bid and minimum ask prices.
getNextBiggestTick
function getNextBiggestTick(
Book storage self,
uint256 priceInTicks,
Side side
) internal view returns (uint256)
Finds the next biggest price tick on the specified side (buy or sell) in the book.
getNextSmallestTick
function getNextSmallestTick(
Book storage self,
uint256 priceInTicks,
Side side
) internal view returns (uint256)
Finds the next smallest price tick on the specified side (buy or sell) in the book.
getOrders
function getOrders(
Book storage self,
uint256 startOrderId,
uint256 numOrders
) internal view returns (Order[] memory)
Retrieves a specified number of orders starting from a given order ID.
getBidLimit
function getBidLimit(
Book storage self,
uint256 priceInTicks
) internal view returns (Limit storage)
Retrieves the bid limit at a specified tick price from the book.
getAskLimit
function getAskLimit(
Book storage self,
uint256 priceInTicks
) internal view returns (Limit storage)
Retrieves the ask limit at a specified tick price from the book.
getOpenInterest
function getOpenInterest(
Book storage self
) internal view returns (uint256, uint256)
Returns the current open interest for both quote and base tokens in atoms.