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
TheRegistry mixin enables “binary matching” on the CTF Exchange by maintaining a mapping of token IDs to their complementary tokens and parent condition IDs. This is essential for matching buy orders of complementary tokens (via a “mint” operation) and sell orders of complementary tokens (via a “merge” operation).
Binary matching assumes that two complementary tokens are always worth, in sum, 1 unit of underlying collateral. This is enforced by the CTF contract which allows minting and merging of full sets (complete collections of outcomes).
Source: src/exchange/mixins/Registry.sol
Data Structures
OutcomeToken
complement: The token ID of the complementary tokenconditionId: The parent condition ID from the CTF contract
State Variables
registry
OutcomeToken information, including complement and condition ID.
Functions
getConditionId
Parameters
token(uint256): The token ID to look up
Returns
bytes32: The parent condition ID of the token according to the registry
getComplement
Parameters
token(uint256): The token ID to get the complement for
Returns
uint256: The complement token ID
Requirements
- The token must be registered (validated via
validateTokenId)
validateComplement
Parameters
token(uint256): The token ID to checkcomplement(uint256): The suspected complement token ID
Reverts
InvalidComplement()if the complement doesn’t match the registered value
validateTokenId
Parameters
tokenId(uint256): The token ID to validate
Reverts
InvalidTokenId()if the token is not registered (complement is 0)
_registerToken
Parameters
token0(uint256): The first token ID of the pairtoken1(uint256): The second token ID of the pairconditionId(bytes32): The CTF condition ID for the pair
Requirements
token0andtoken1must not be equal- Neither
token0nortoken1can be zero - Neither token can already be registered
Emits
TokenRegistered(token0, token1, conditionId)TokenRegistered(token1, token0, conditionId)
It is the responsibility of operators to register new outcome tokens with correct token IDs, complements, and condition IDs. All registrations assume binary outcomes that are valid in the context of the CTF contract.
Events
TokenRegistered
Parameters
token0(uint256): The token being registeredtoken1(uint256): Its complement tokenconditionId(bytes32): The parent condition ID
Errors
InvalidComplement
InvalidTokenId
AlreadyRegistered
How Binary Matching Works
- Matching Buy Orders: When matching buy orders for tokens A and A’ (complements), the exchange can mint a full set from collateral, then distribute token A to one buyer and token A’ to the other.
- Matching Sell Orders: When matching sell orders for tokens A and A’, the exchange can receive both tokens, merge them back into collateral, and pay out the sellers.
- Finding Complements: The registry allows the exchange to quickly look up the complement of any token and its condition ID, which is required for the mint/merge operations on the CTF contract.