Instructions

Key user facing instructions

cancel_order

This function can be used by any user to cancel a pending order that has not yet been filled (if an order has been partially filled, the unfilled portion can be cancelled with this function). In this case, the order is removed from the user's OpenOrders, the Order Book (Bids/Asks PDA), and the user's initial marginal deposit is refunded.

cancel_with_penalty

This function is used specifically to handle settlement failure. When an order has been matched and three conditions are met: 1) 60 seconds has elapsed since the order was matched (as per event.timestamp), and 2) The counterparty does not have the required funds (finalize_matches fails)3) The honest counterparty has liquidity to fulfil the trade. After validating these conditions, the program cancels the trade, refunds the trade value to the honest counterparty, and debits the margin amount from the dishonest counterparty as penalty, as issues it to the honest counterparty.

close_market

Used to close an unused market and refund the lamports

create_market

Used to create a new market, and associated accounts including orderbook (bids/asks), eventQueue, vaults for quote/base tokens. It also stores the lot size and decimal information of the tokens involved.

create_open_orders

Used to create a position tracking account for a trader. This is a one time task for limit order placement in a market. Not required for purely posting taker/market orders.

deposit

Used to independently deposit funds to the market vaults and credit it to openorders balance of the user. Can be used to "push" liquidity in cases where the program "pulling" liquidity in the finalize step is not suitable for the user.

finalize_matches

Utilised to execute just-in-time settlement for a matched order. Takes a FillEvent index as input, and utilises market authority seeds to execute transfers of both tokens to the respective market vaults. Then, updates the counterparties' openorders balances to reflect the completed trade.

finalize_matches_direct

Used for easier integration with market/taker orders on other platforms. Same as finalize_matches, but settles trades directly to each counterparties wallet, instead of to the market vaults.

place order

Key entrypoint to place a limit order. Validates all structs, ensures margin (1%) is deposited and undeposited trade value is approved from your wallet. Adds the order to the orderbook, or if partially or fully matched, generates FillEvents for settlement of the matched order.

place take order

Used to place market order without utilising openorders.

settle_funds

Used to withdraw all free balances (both quote and base token) available in Open Orders for a user. Can be used after finalize_matches to withdraw funds to wallet.

Last updated