Structs & Enums

PostLimitOrderArgs

struct PostLimitOrderArgs {
    uint256 amountInBaseLots;
    uint256 priceInTicks;
    uint256 cancelTimestamp;
    Side side;
    LimitOrderType limitOrderType;
    Settlement settlement;
}
  • amountInBaseLots: The size of the order, measured in base lots.
  • priceInTicks: The price of the order, expressed in ticks (quote lots per base unit).
  • cancelTimestamp: Unix timestamp after which the order is automatically canceled; ignored if set to 0.
  • side: Defined in the Side enum:
    enum Side {
        BUY,
        SELL
    }
    
  • limitOrderType: Defined in the LimitOrderType enum.
  • settlement: Defined in the Settlement enum.

PostLimitOrderResult

struct PostLimitOrderResult {
    uint256 orderId;
    uint256 amountPostedInBaseLots;
    int256 quoteTokenAmountTradedInAtoms;
    int256 baseTokenAmountTradedInAtoms;
}
  • orderId: A unique identifier for the submitted order.
  • amountPostedInBaseLots: The amount of the order that was successfully posted to the order book, measured in base lots.
  • quoteTokenAmountTradedInAtoms: The amount of quote tokens traded, measured in atoms; negative if outgoing, positive if incoming, and includes fees.
  • baseTokenAmountTradedInAtoms: The amount of base tokens traded, measured in atoms; negative if outgoing, positive if incoming.

PostFillOrderArgs

struct PostFillOrderArgs {
    uint256 amountInBaseLots;
    uint256 priceInTicks;
    Side side;
    FillOrderType fillOrderType;
    Settlement settlement;
}
  • amountInBaseLots: The size of the fill order, measured in base lots.
  • priceInTicks: The price of the fill order, expressed in ticks.
  • side: Defined in the Side enum:
    enum Side {
        BUY,
        SELL
    }
    
  • fillOrderType: Defined in the FillOrderType enum.
  • settlement: Defined in the Settlement enum.

PostFillOrderResult

struct PostFillOrderResult {
    uint256 orderId;
    uint256 amountFilledInBaseLots;
    int256 quoteTokenAmountTradedInAtoms;
    int256 baseTokenAmountTradedInAtoms;
}
  • orderId: A unique identifier for the fill order.
  • amountFilledInBaseLots: The amount of the order that was successfully filled, measured in base lots.
  • quoteTokenAmountTradedInAtoms: The amount of quote tokens traded, measured in atoms; negative if outgoing, positive if incoming, and includes fees.
  • baseTokenAmountTradedInAtoms: The amount of base tokens traded, measured in atoms; negative if outgoing, positive if incoming.

ReduceArgs

struct ReduceArgs {
    uint256 orderId;
    uint256 amountInBaseLots;
    Settlement settlement;
}
  • orderId: The unique identifier of the order to be reduced.
  • amountInBaseLots: The amount by which the order should be reduced, measured in base lots.
  • settlement: Defined in the Settlement enum.

CancelArgs

struct CancelArgs {
    uint256[] orderIds;
    Settlement settlement;
}
  • orderIds: An array of unique identifiers for the orders to be canceled.
  • settlement: Defined in the Settlement enum.

Settlement

enum Settlement {
    INSTANT,
    ACCOUNT
}
  • INSTANT: Immediate token transfers upon cancel, reduce, or trade execution.
  • ACCOUNT: Updates internal account balances within the CLOB contracts without immediate token transfers.

LimitOrderType

enum LimitOrderType {
    GOOD_TILL_CANCELLED,
    POST_ONLY
}
  • GOOD_TILL_CANCELLED: Orders remain in the book until filled or canceled.
  • POST_ONLY: Orders are added only if they do not immediately match.

FillOrderType

enum FillOrderType {
    FILL_OR_KILL,
    IMMEDIATE_OR_CANCEL
}
  • FILL_OR_KILL: Orders are filled immediately, completely or not at all.
  • IMMEDIATE_OR_CANCEL: Orders are filled immediately if possible, with any remaining portion canceled.

Events

Deposit

// Emitted when a deposit is successfully made.
event Deposit(
    address account, 
    address token, 
    uint256 amountInAtoms
);
  • account: The address of the account making the deposit.
  • token: The address of the token being deposited.
  • amountInAtoms: The amount of the token being deposited, measured in atoms.

Withdraw

// Emitted when a withdrawal is successfully made.
event Withdraw(
    address account, 
    address token, 
    uint256 amountInAtoms
);
  • account: The address of the account making the withdrawal.
  • token: The address of the token being withdrawn.
  • amountInAtoms: The amount of the token being withdrawn, measured in atoms.

LimitOrderSubmitted

// Emitted when a limit order is submitted.
event LimitOrderSubmitted(
    uint256 orderId,
    uint256 amountInBaseLots,
    uint256 priceInTicks,
    uint256 cancelTimestamp,
    Side side,
    LimitOrderType limitOrderType,
    Settlement settlement,
    address owner
);
  • orderId: A unique identifier for the submitted order.
  • amountInBaseLots: The size of the order, measured in base lots.
  • priceInTicks: The price level of the order, expressed in ticks.
  • cancelTimestamp: Unix timestamp after which the order is automatically canceled; ignored if set to 0.
  • side: The side of the order. Either BUY or SELL.
  • limitOrderType: Defined in the LimitOrderType enum.
  • settlement: Defined in the Settlement enum.
  • owner: The address of the account submitting the order.

LimitOrderProcessed

// Emitted when a limit order is processed.
event LimitOrderProcessed( // negative if outgoing, positive if incoming. Includes fees
    uint256 orderId,
    uint256 amountPostedInBaseLots,
    int256 quoteTokenAmountTradedInAtoms,
    int256 baseTokenAmountTradedInAtoms
);
  • orderId: A unique identifier for the processed order.
  • amountPostedInBaseLots: The amount of the order that was successfully posted to the order book, measured in base lots.
  • quoteTokenAmountTradedInAtoms: The amount of quote tokens traded, measured in atoms; negative if outgoing, positive if incoming, and includes fees.
  • baseTokenAmountTradedInAtoms: The amount of base tokens traded, measured in atoms; negative if outgoing, positive if incoming.

FillOrderSubmitted

// Emitted when a fill order is submitted.
event FillOrderSubmitted(
    uint256 orderId,
    uint256 amountInBaseLots,
    uint256 priceInTicks,
    Side side,
    FillOrderType fillOrderType,
    Settlement settlement,
    address owner
);
  • orderId: A unique identifier for the submitted order.
  • amountInBaseLots: The size of the order, measured in base lots.
  • priceInTicks: The price level of the order, expressed in ticks.
  • side: The side of the order. Either BUY or SELL.
  • fillOrderType: Defined in the FillOrderType enum.
  • settlement: Defined in the Settlement enum.
  • owner: The address of the account submitting the order.

FillOrderProcessed

// Emitted when a fill order is processed.
event FillOrderProcessed( // negative if outgoing, positive if incoming. Includes fees
    uint256 orderId,
    uint256 amountFilledInBaseLots,
    int256 quoteTokenAmountTradedInAtoms,
    int256 baseTokenAmountTradedInAtoms
);
  • orderId: A unique identifier for the processed order.
  • amountFilledInBaseLots: The amount of the order that was successfully filled, measured in base lots.
  • quoteTokenAmountTradedInAtoms: The amount of quote tokens traded, measured in atoms; negative if outgoing, positive if incoming, and includes fees.
  • baseTokenAmountTradedInAtoms: The amount of base tokens traded, measured in atoms; negative if outgoing, positive if incoming.

OrderMatched

// Emitted when an order is matched in the order book.
event OrderMatched(
    uint256 makerOrderId,
    uint256 takerOrderId,
    uint256 amountInBaseLots,
    uint256 priceInTicks,
    Side makerSide,
    address maker,
    address taker
);
  • makerOrderId: A unique identifier for the maker order.
  • takerOrderId: A unique identifier for the taker order.
  • amountInBaseLots: The size of the fill, measured in base lots.
  • priceInTicks: The price level of the fill, expressed in ticks.
  • makerSide: The side of the maker order. Either BUY or SELL.
  • maker: The address of the maker.
  • taker: The address of the taker.

OrderReduced

// Emitted when an order is successfully reduced.
event OrderReduced(
    uint256 orderId, 
    uint256 newAmountInBaseLots, 
    uint256 refundAmountInBaseLots, 
    Settlement settlement
);
  • orderId: A unique identifier for the reduced order.
  • newAmountInBaseLots: The new amount of the order, measured in base lots.
  • refundAmountInBaseLots: The amount of the order that was refunded, measured in base lots.
  • settlement: Defined in the Settlement enum.

OrderCanceled

// Emitted when an order is successfully canceled.
event OrderCanceled(
    uint256 orderId,
    address owner,
    uint256 quoteTokenRefundedInAtoms,
    uint256 baseTokenRefundedInAtoms,
    Settlement settlement
);
  • orderId: A unique identifier for the canceled order.
  • owner: The address of the account canceling the order.
  • quoteTokenRefundedInAtoms: The amount of quote tokens refunded, measured in atoms.
  • baseTokenRefundedInAtoms: The amount of base tokens refunded, measured in atoms.
  • settlement: Defined in the Settlement enum.

CancelFailed

// Emitted if an order cancellation fails if the order does not exist or is null.
event CancelFailed(
    uint256 orderId, 
    address owner
);
  • orderId: A unique identifier for the canceled order.
  • owner: The address of the account canceling the order.

Functions

deposit

deposit
function deposit(
    address token, 
    uint256 amount
) external

Allows a user to deposit a specified amount of a token into their account on the CLOB platform. The function checks if the token is valid and if the user has approved the contract to transfer the specified amount. If the token is the quote token, it updates the user’s quote token balance; otherwise, it updates the base token balance.

Parameters

TypeNameDescription
addresstokenThe address of the token to be deposited.
uint256amountThe amount of the token to be deposited.

Events

Reverts

  • InsufficientTokenApproved: If the user has not approved enough tokens for the contract to transfer.

withdraw

withdraw
function withdraw(
    address token, 
    uint256 amount
) external

Allows a user to withdraw a specified amount of a token from their account on the CLOB platform. The function checks if the token is valid and if the user has sufficient balance. If the token is the quote token, it updates the user’s quote token balance; otherwise, it updates the base token balance.

Parameters

TypeNameDescription
addresstokenThe address of the token to be withdrawn.
uint256amountThe amount of the token to be withdrawn.

Events

Reverts

  • InsufficientTokenBalance: If the user does not have enough balance to withdraw the specified amount.

postLimitOrder

postLimitOrder
function postLimitOrder(
    PostLimitOrderArgs memory args
) external returns (PostLimitOrderResult memory)

Submits a limit order to the CLOB platform. The order will be matched and filled against existing orders in the order book as much as possible. Any unmatched portion of the order will be added to the order book. For GOOD_TILL_CANCELLED orders, the unmatched portion remains in the book until filled or canceled, while POST_ONLY orders are added only if they do not immediately match, ensuring no taker fees are incurred. The function returns details about the order’s execution, including the amount posted and the tokens traded.

Parameters

TypeNameDescription
PostLimitOrderArgsargsA struct containing the order details, including amount, price, side, and settlement type.

Return Values

TypeDescription
PostLimitOrderResultA struct containing the order ID, amount posted, and the amounts of quote and base tokens traded.

Events

Reverts

  • PostOnlyOrderWouldBeFilled: If a post-only order would be immediately filled.
  • MaxOrdersInBookPostNotCompetitive: If the order book is full and the new order is not competitive enough to replace an existing order.

postFillOrder

postFillOrder
function postFillOrder(
    PostFillOrderArgs memory args
) external returns (PostFillOrderResult memory)

Submits a fill order to the CLOB platform. This order attempts to match existing orders in the order book immediately. For a FILL_OR_KILL order, the order must be immediately completely filled or not at all. For an IMMEDIATE_OR_CANCEL order, the order immediately fills as much as possible and any remaining amount is not added to the order book. The function returns details about the order’s execution, including the amount filled and the tokens traded.

Parameters

TypeNameDescription
PostFillOrderArgsargsA struct containing the order details, including amount, price, side, and settlement type.

Return Values

TypeDescription
PostFillOrderResultA struct containing the order ID, amount filled, and the amounts of quote and base tokens traded.

Events

Reverts

  • FOKNotFilled: If a fill-or-kill order is not completely filled.

reduce

reduce
function reduce(
    ReduceArgs memory args
) external returns (uint256)

Reduces the amount of an existing order on the CLOB platform. This function allows the order owner to decrease the order size, and it returns the amount of tokens refunded as a result of the reduction.

Parameters

TypeNameDescription
ReduceArgsargsA struct containing the order ID, amount to reduce, and settlement type.

Return Values

TypeDescription
uint256The amount of tokens refunded in atoms as a result of the order reduction.

Events

Reverts

  • ReduceAmountOutOfBounds: If the reduction amount is zero or exceeds the order’s current amount.
  • UnauthorizedReduce: If the caller is not the owner of the order.

cancel

cancel
function cancel(
    CancelArgs memory args
) external returns (uint256, uint256)

Cancels one or more existing orders on the CLOB platform. This function allows the order owner to cancel their orders and receive a refund of the tokens. It returns the total amounts of quote and base tokens refunded.

Parameters

TypeNameDescription
CancelArgsargsA struct containing the order IDs to cancel and the settlement type.

Return Values

TypeDescription
uint256The total amount of quote tokens refunded in atoms.
uint256The total amount of base tokens refunded in atoms.

Events

Reverts

  • UnauthorizedCancel: If the caller is not the owner of the order.

Getter Functions

getQuoteToken

getQuoteToken
function getQuoteToken() external view returns (IERC20)

Retrieves the quote token used in the CLOB platform.

Return Values

TypeDescription
IERC20The address of the quote token.

getBaseToken

getBaseToken
function getBaseToken() external view returns (IERC20)

Retrieves the base token used in the CLOB platform.

Return Values

TypeDescription
IERC20The address of the base token.

getMarketConfig

getMarketConfig
function getMarketConfig() external view returns (MarketConfig memory)

Retrieves the market configuration settings for the CLOB platform.

Return Values

TypeDescription
MarketConfigA struct containing market settings.

getTokenConfig

getTokenConfig
function getTokenConfig() external view returns (TokenConfig memory)

Retrieves the token configuration settings for the CLOB platform.

Return Values

TypeDescription
TokenConfigA struct containing token settings.

getOpenInterest

getOpenInterest
function getOpenInterest() external view returns (uint256, uint256)

Retrieves the current open interest for both quote and base tokens in the CLOB platform.

Return Values

TypeDescription
uint256The open interest of quote tokens in atoms.
uint256The open interest of base tokens in atoms.

getOrder

getOrder
function getOrder(uint256 orderId) external view returns (Order memory)

Retrieves the details of a specific order by its unique identifier.

Parameters

TypeNameDescription
uint256orderIdThe unique identifier of the order.

Return Values

TypeDescription
OrderA struct containing order details.

getTOB

getTOB
function getTOB() external view returns (uint256, uint256)

Retrieves the top of book prices for both bid and ask sides (the highest bid and lowest ask).

Return Values

TypeDescription
uint256The highest bid price in ticks.
uint256The lowest ask price in ticks.

getLimit

getLimit
function getLimit(uint256 priceInTicks, Side side) external view returns (Limit memory)

Retrieves the limit level details at a specific price level for a given side.

Parameters

TypeNameDescription
uint256priceInTicksThe price level in ticks.
SidesideThe side of the order (BUY or SELL).

Return Values

TypeDescription
LimitA struct containing limit details.

getNumBids

getNumBids
function getNumBids() external view returns (uint256)

Retrieves the total number of bid orders currently in the order book.

Return Values

TypeDescription
uint256The number of bid orders.

getNumAsks

getNumAsks
function getNumAsks() external view returns (uint256)

Retrieves the total number of ask orders currently in the order book.

Return Values

TypeDescription
uint256The number of ask orders.

getNextBiggestTick

getNextBiggestTick
function getNextBiggestTick(uint256 priceInTicks, Side side) external view returns (uint256)

Retrieves the next biggest price tick for a given side in the order book.

Parameters

TypeNameDescription
uint256priceInTicksThe current price level in ticks.
SidesideThe side of the order (BUY or SELL).

Return Values

TypeDescription
uint256The next biggest price tick.

getNextSmallestTick

getNextSmallestTick
function getNextSmallestTick(uint256 priceInTicks, Side side) external view returns (uint256)

Retrieves the next smallest price tick for a given side in the order book.

Parameters

TypeNameDescription
uint256priceInTicksThe current price level in ticks.
SidesideThe side of the order (BUY or SELL).

Return Values

TypeDescription
uint256The next smallest price tick.

getOrders

getOrders
function getOrders(uint256 startOrderId, uint256 numOrders) external view returns (Order[] memory)

Retrieves a list of orders starting from a specific order ID.

Parameters

TypeNameDescription
uint256startOrderIdThe starting order ID.
uint256numOrdersThe number of orders to retrieve.

Return Values

TypeDescription
Order[]An array of order structs.

getQuoteTokenAccountBalance

getQuoteTokenAccountBalance
function getQuoteTokenAccountBalance(address account) external view returns (uint256)

Retrieves the quote token balance of a specific account.

Parameters

TypeNameDescription
addressaccountThe address of the account.

Return Values

TypeDescription
uint256The quote token balance in atoms.

getBaseTokenAccountBalance

getBaseTokenAccountBalance
function getBaseTokenAccountBalance(address account) external view returns (uint256)

Retrieves the base token balance of a specific account.

Parameters

TypeNameDescription
addressaccountThe address of the account.

Return Values

TypeDescription
uint256The base token balance in atoms.

getNextOrderId

getNextOrderId
function getNextOrderId() external view returns (uint256)

Retrieves the next order ID that will be assigned to a new order on the CLOB platform.

Return Values

TypeDescription
uint256The next order ID.

getFactory

getFactory
function getFactory() external view returns (address)

Retrieves the address of the factory associated with the CLOB platform.

Return Values

TypeDescription
addressThe address of the factory.

getFactoryOwner

getFactoryOwner
function getFactoryOwner() external view returns (address)

Retrieves the owner of the factory associated with the CLOB platform.

Return Values

TypeDescription
addressThe address of the factory owner.

getFeeRecipient

getFeeRecipient
function getFeeRecipient() external view returns (address)

Retrieves the address designated to receive fees on the CLOB platform.

Return Values

TypeDescription
addressThe address of the fee recipient.