Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Polymarket/ctf-exchange/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Matches a taker order against an array of maker orders. This function enables sophisticated order matching including complementary fills (buy vs sell), minting (two buys), and merging (two sells). The exchange acts as an intermediary to facilitate complex trades.Parameters
The active order to be matched (taker side). See Order Structure for details.This order is filled using the exchange as the counterparty, with the exchange then filling the maker orders to satisfy the taker.
Array of passive orders to be matched against the taker order.Requirements:
- Each order must be compatible with the taker order
- For complementary matches: must have the same token ID but opposite sides
- For mint matches (two buys): must be for complementary tokens
- For merge matches (two sells): must be for complementary tokens
- Orders must be crossing (prices must allow profitable execution)
The amount to fill on the taker order, denominated in terms of the taker’s maker amount.This represents how much of the taker order to execute in this match.
Array of amounts to fill for each maker order, denominated in terms of each maker’s maker amount.Requirements:
- Array length must match the
makerOrdersarray length - Total fill amounts must be sufficient to satisfy the taker order
- Each amount must not exceed the corresponding order’s remaining amount
Requirements
- Caller must be an authorized operator (
onlyOperator) - Trading must not be paused (
notPaused) - Function must not be re-entered (
nonReentrant) - Taker order must pass all validation checks
- Each maker order must pass all validation checks
- Orders must be crossing (economically viable to match)
- Token IDs must be compatible based on match type
- Sufficient balances must exist for all asset transfers
Match Types
The function automatically determines the match type based on the order sides:Complementary (Buy vs Sell)
Matches a buy order with a sell order for the same token. Example: YES buy at 60¢ matched with YES sell at 50¢- No CTF operations needed
- Direct asset transfers between parties
- Token IDs must match
Mint (Two Buys)
Matches two buy orders for complementary tokens by minting new outcome tokens. Example: YES buy matched with NO buy- Exchange mints new outcome token pairs using collateral
- Requires complementary token IDs
- Buys must “cross” (priceYes + priceNo > 1)
Merge (Two Sells)
Matches two sell orders for complementary tokens by merging outcome tokens into collateral. Example: YES sell matched with NO sell- Exchange merges outcome tokens into collateral
- Requires complementary token IDs
- Sells must “cross” (priceYes + priceNo < 1)
Behavior
Execution Flow
-
Taker Order Setup:
- Validate taker order
- Calculate required taking amount
- Transfer taker’s maker asset to the exchange
-
Maker Order Processing:
- For each maker order:
- Validate the order
- Determine match type (complementary, mint, or merge)
- Validate orders are crossing
- Execute CTF operations if needed (mint/merge)
- Transfer assets between maker and exchange
- Charge fees to maker
- For each maker order:
-
Taker Order Settlement:
- Calculate actual taker proceeds (may include price improvement)
- Transfer proceeds to taker (minus fees)
- Charge fees to taker
- Refund any unused maker assets to taker
Price Improvement
If maker orders provide better pricing than the taker order’s limit price, the taker receives the surplus. Fees are calculated on the actual fill price, including any price improvement.Fee Collection
Fees are charged to both taker and maker(s) based on their respectivefeeRateBps. The operator receives all fees explicitly through transfers.
Events
Emitted for the taker order and each maker order that is filled.
- For taker order:
takerisaddress(this)(the exchange) - For maker orders:
takeris the taker order’s maker
Emitted once after all orders are successfully matched.
takerOrderHash: Hash of the taker ordertakerOrderMaker: Maker of the taker ordermakerAssetId: Token ID of asset provided by takertakerAssetId: Token ID of asset received by takermakerAmountFilled: Amount provided by takertakerAmountFilled: Amount received by taker
Emitted for each fee charged to taker and maker(s).
Errors
Caller is not an authorized operator
Trading is currently paused
Orders do not cross (prices don’t allow profitable execution)
- For complementary: buy price must be >= sell price
- For mint: buy prices must sum to > 1
- For merge: sell prices must sum to < 1
For complementary matches, taker and maker token IDs don’t match
After executing match operations, insufficient tokens were received to fill orders
One or more orders have passed their expiration timestamp
One or more orders have already been fully filled or cancelled
One or more order signatures are invalid
One or more order nonces are invalid
One or more fill amounts exceed the remaining unfilled amount
Taker order specifies a specific taker and caller is not that address
Example Usage
Complementary Match (Buy vs Sell)
Mint Match (Two Buys)
Merge Match (Two Sells)
See Also
- fillOrder - Fill a single order
- fillOrders - Fill multiple orders
- Order Structure - Details on the Order type
- CTF Exchange - Core contract reference