Skip to main content

Module orderbook

Module orderbook 

Source
Expand description

Orderbook and tick level management for the stablecoin DEX.

Modules§

__packing_orderbook
__packing_tick_level

Structs§

Orderbook
Orderbook for token pair with price-time priority Uses tick-based pricing with bitmaps for price discovery
OrderbookHandler
Type-safe handler for accessing #struct_name in storage.
TickLevel
Represents a price level in the orderbook with a doubly-linked list of orders Orders are maintained in FIFO order at each tick level
TickLevelHandler
Type-safe handler for accessing #struct_name in storage.

Enums§

RoundingDirection
Rounding direction for price conversions.

Constants§

MAX_PRICE 🔒
Highest representable scaled price (PRICE_SCALE + MAX_TICK).
MAX_TICK
Maximum allowed tick value (corresponds to MAX_PRICE).
MIN_PRICE 🔒
Lowest representable scaled price (PRICE_SCALE + MIN_TICK).
MIN_TICK
Minimum allowed tick value (corresponds to MIN_PRICE).
PRICE_SCALE
Scaling factor for tick-to-price conversion. A tick of 0 maps to PRICE_SCALE (peg).

Functions§

base_to_quote
Convert base token amount to quote token amount at a given tick.
compute_book_key
Compute deterministic book key from ordered (base, quote) token pair
price_to_tick
Converts a scaled price back to a relative tick.
quote_to_base
Convert quote token amount to base token amount at a given tick.
tick_to_price
Convert relative tick to scaled price
validate_tick_spacing
Validates that a tick is aligned to TICK_SPACING.