Skip to main content

Data Structures

  • Order{ address owner, uint96 size, uint40 prev, uint40 next, uint40 flippedId, uint32 price, uint32 flippedPrice, bool isBuy }
  • PricePoint{ uint40 head, uint40 tail }
  • TreeUint24 — Tree structure for active price points

Core Functions

Order Placement

function addBuyOrder(uint32 _price, uint96 _size, bool _postOnly) external
function addSellOrder(uint32 _price, uint96 _size, bool _postOnly) external
Places limit buy/sell orders. Matches against resting orders first. If _postOnly is true, reverts if any portion matches immediately.

Flip Orders

function addFlipBuyOrder(uint32 _price, uint32 _flippedPrice, uint96 _size, bool _provisionOrRevert) external
function addFlipSellOrder(uint32 _price, uint32 _flippedPrice, uint96 _size, bool _provisionOrRevert) external
Places flip orders that create opposite-side orders on fill. _flippedPrice must be better than _price. If _provisionOrRevert is false, reverts if best price equals current book best.

Market Orders

function placeAndExecuteMarketBuy(uint96 _quoteSize, uint96 _minOut, bool _isMargin, bool _isFOK) external payable
function placeAndExecuteMarketSell(uint96 _size, uint96 _minOut, bool _isMargin, bool _isFOK) external payable
Executes market orders against resting liquidity. Supports ERC20–ERC20, NATIVE–ERC20, and ERC20–NATIVE pairs. _isFOK enforces fill-or-kill behavior.

Cancellation

function batchCancelOrders(uint40[] calldata _orderIds) external
function batchCancelFlipOrders(uint40[] calldata _orderIds) external
Batch cancels regular or flip orders. Idempotent—safe to call multiple times.

Liquidity Provision

function addPairedLiquidity(uint32 _bidPrice, uint32 _askPrice, uint96 _bidSize, uint96 _askSize) external
function batchProvisionLiquidity(uint32[] calldata _prices, uint96[] calldata _sizes, bool[] calldata _isBid) external
Adds liquidity to the AMM vault. addPairedLiquidity sets bid/ask prices and sizes. Batch function allows provisioning multiple price points at once.

View Functions

function bestBidAsk() external view returns (uint32, uint32)
function getL2Book() external view returns (bytes)
function getL2Book(uint32 _bidPricePoints, uint32 _askPricePoints) external view returns (bytes)
function getMarketParams() external view returns (MarketParams memory)
Returns best bid/ask prices, L2 order book depth, and market configuration parameters.

Market States

  • ACTIVE — Full operations enabled
  • SOFT_PAUSED — Only cancels, deposits, withdrawals allowed
  • HARD_PAUSED — All operations halted

Order Types

TypeDescriptionprevnext
ASingle orderNULLNULL
BHead with nextNULLNON-NULL
CMiddle orderNON-NULLNON-NULL
DTail orderNON-NULLNULL

Events

OrderCreated

event OrderCreated(
    uint40 indexed orderId,
    address indexed owner,
    uint96 size,
    uint32 price,
    bool isBuy
);
Emitted when a new limit order is placed on the order book.

FlipOrderCreated

event FlipOrderCreated(
    uint40 indexed orderId,
    uint40 indexed flippedId,
    address indexed owner,
    uint96 size,
    uint32 price,
    uint32 flippedPrice,
    bool isBuy
);
Emitted when a flip order is created. flippedId is the order ID that will be created on the opposite side when this order fills.

Trade

event Trade(
    uint40 orderId,
    address indexed maker,
    bool isBuy,
    uint32 price,
    uint96 updatedSize,
    address indexed taker,
    address indexed origin,
    uint96 filledSize
);
Emitted for each order fill. updatedSize is the remaining size after fill. origin is the original transaction sender (supports meta-transactions).

OrderCanceled

event OrderCanceled(
    uint40 indexed orderId,
    address indexed owner,
    uint96 size,
    uint32 price,
    bool isBuy
);
Emitted when an order is successfully canceled. Returns the full order size before cancellation.

MarketStateUpdated

event MarketStateUpdated(
    MarketState prevState,
    MarketState newState
);
Emitted when market state changes (ACTIVE, SOFT_PAUSED, or HARD_PAUSED).