Polymarket's next-generation prediction market smart contract system. Manages position tokens (ERC1155), collateral wrapping/unwrapping, market resolution via modular oracles, order matching, and cross-chain bridging. Built with Foundry and Solady.
Positions are represented as structured IDs that encode module routing, condition identity, and outcome index directly in the token ID — eliminating storage lookups and enabling pure derivation of all relationships.
[moduleId(8) | baseHash(128) | arity(16) | reserved(64) | resolutionChain(16) | conditionIndex(16) | outcomeIndex(8)]
──────────── ───────────── ───────── ──────────── ───────────────── ──────────────── ──────────────
bits 248-255 bits 120-247 bits 104-119 bits 40-103 bits 24-39 bits 8-23 bits 0-7
| Field | Bits | Description |
|---|---|---|
moduleId |
8 | Identifies which module owns this position (O(1) lookup) |
baseHash |
128 | Truncated hash of event/question data |
arity |
16 | Neg-risk condition count (zero for binary and other modules) |
reserved |
64 | Event-scoped reserved bits, part of event identity |
resolutionChain |
16 | Chain enum allowed to resolve this condition (0 = Polygon) |
conditionIndex |
16 | Index within multi-condition events (0 for binary markets) |
outcomeIndex |
8 | Outcome index (0 = YES, 1 = NO for binary markets) |
See Position IDs for the full spec, library API, gas analysis, and migration details.
Polygon
Amoy
- Architecture — system overview, design patterns, contract relationships
- Position IDs — structured ID schema, Ids.sol API (ConditionIdLib / EventIdLib / PositionIdLib), gas savings
- Modules — BinaryModule, NegRiskModule, CombinatorialModule, abstract hierarchy, resolution roles
- Position Manager — core ERC1155 contract, module registration, unsafe transfers
- Collateral — CollateralToken (PMCT), onramp, offramp, PermissionedRamp
- Oracle — OracleAggregator, modular resolution system
- Bridge — cross-chain bridging (Chainlink CCIP), hub-and-spoke topology
- Auth — roles, access control, role assignment
- Router — Router, BridgeRouter, CtfRouter, pre-transfer pattern, combinatorial operations
- Exchange — order matching, EIP-712 signatures, fee model
- Migration — legacy CTF/NegRiskAdapter position migration
forge install # install pinned Foundry dependencies
forge build # compile
forge test # run tests
forge fmt # format
forge snapshot # gas snapshots
make setup # install git hooks (pre-commit: fmt + snapshot)