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

// Emitted when a deposit is successfully made.
event Deposit(
    address account, 
    address token, 
    uint256 amountInAtoms
);

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

// Emitted when a withdrawal is successfully made.
event Withdraw(
    address account, 
    address token, 
    uint256 amountInAtoms
);

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

// 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
);
// 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
);

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

// Emitted when a fill order is submitted.
event FillOrderSubmitted(
    uint256 orderId,
    uint256 amountInBaseLots,
    uint256 priceInTicks,
    Side side,
    FillOrderType fillOrderType,
    Settlement settlement,
    address owner
);
// 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
);

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

// Emitted when an order is successfully reduced.
event OrderReduced(
    uint256 orderId, 
    uint256 newAmountInBaseLots, 
    uint256 refundAmountInBaseLots, 
    Settlement settlement
);

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

// Emitted when an order is successfully canceled.
event OrderCanceled(
    uint256 orderId,
    address owner,
    uint256 quoteTokenRefundedInAtoms,
    uint256 baseTokenRefundedInAtoms,
    Settlement settlement
);
// Emitted if an order cancellation fails if the order does not exist or is null.
event CancelFailed(
    uint256 orderId, 
    address owner
);

Reverts

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