PredictionLabs

Contract Reference

Complete API reference for all PredictionLabs smart contracts.

MarketFactory

Immutables

NameTypeDescription
CTFIConditionalTokensGnosis CTF address

State

NameTypeDescription
marketCountuint256Total markets created
marketsmapping(bytes32 => Market)Market data by conditionId
pendingResolutionCountmapping(bytes32 => uint256)conditionId → count of pending resolution attempts

Constants

NameValueDescription
VOID_TIMEOUT90 daysPermissionless void after deadline + 90 days (no pending)
EMERGENCY_VOID_TIMEOUT180 daysEmergency void regardless of pending

Types

Market (struct)

FieldType
questionIdbytes32
deadlineuint64
outcomeSlotCountuint8
resolvedbool
creatoraddress
resolveraddress

Functions

createMarket(string question, uint256 outcomeSlotCount, uint256 deadline, address resolver) → bytes32 conditionId

Creates a new prediction market with a per-market resolver.

  • outcomeSlotCount: 2–255
  • deadline: must be in the future
  • resolver: address of the resolver module for this market

resolveMarket(bytes32 conditionId, uint256[] payouts)

Called by the market's resolver to finalize the outcome. Reports payouts to the CTF.

notifyResolutionInitiated(bytes32 conditionId)

Called by a resolver to signal that a resolution attempt has started. Increments pendingResolutionCount.

notifyResolutionFinalized(bytes32 conditionId)

Called by a resolver to signal that a resolution attempt has finished (settled or disputed). Decrements pendingResolutionCount.

forceVoid(bytes32 conditionId)

Permissionless void. Anyone can call.

  • After deadline + 90 days with pendingResolutionCount == 0
  • After deadline + 180 days regardless of pending count

isTrading(bytes32 conditionId) → bool

True if market exists and is not resolved.

isResolvable(bytes32 conditionId) → bool

True if deadline has passed and market is not resolved.

Events

EventParameters
MarketCreatedconditionId (indexed), questionId (indexed), creator (indexed), resolver, outcomeSlotCount, deadline, question
MarketResolvedconditionId (indexed), resolver (indexed)
MarketVoidedconditionId (indexed)
ResolutionInitiatedconditionId (indexed), resolver (indexed)
ResolutionFinalizedconditionId (indexed), resolver (indexed)

OrderBook

Immutables

NameTypeDescription
CTFIConditionalTokensGnosis CTF address
FACTORYMarketFactoryMarketFactory address
TREASURYTreasuryTreasury address
COLLATERALIERC20USDC address

State

NameTypeDescription
nextOrderIduint256Counter for order IDs
ordersmapping(uint256 => Order)All orders by ID

Constants

NameValueDescription
MIN_ORDER_COST1e40.01 USDC minimum order cost; minimum fill amount (shares)
PRICE_SCALE1e6$1.00 = 1e6
MAX_AMOUNT1e18Maximum shares per order
FEE_BPS100.1% fee
BPS_DENOMINATOR10000Basis point denominator

Types

Side (enum)

ValueDescription
BUY (0)Buying outcome tokens with USDC
SELL (1)Selling outcome tokens for USDC

Order (struct)

FieldType
makeraddress
sideSide
cancelledbool
conditionIdbytes32
outcomeIndexuint256
priceuint256
amountuint256
filleduint256

Functions

placeBuyOrder(bytes32 conditionId, uint256 outcomeIndex, uint256 price, uint256 amount) → uint256 orderId

Place a limit buy order. Transfers USDC from caller.

  • price: 1 to 999999
  • amount: shares wanted
  • Cost locked: price * amount / 1e6

placeSellOrder(bytes32 conditionId, uint256 outcomeIndex, uint256 price, uint256 amount) → uint256 orderId

Place a limit sell order. Transfers outcome tokens from caller (requires CTF approval).

  • price: minimum acceptable price

placeBuyOrders(bytes32[] conditionIds, uint256[] outcomeIndexes, uint256[] prices, uint256[] amounts) → uint256[] orderIds

Batch buy order placement.

fillBuyVsBuy(uint256 buyId0, uint256 buyId1, uint256 fillAmount)

Match two BUY orders on opposite outcomes. Combined USDC splits into tokens. fillAmount is in shares (6 decimals, e.g. 100e6 = 100 shares).

  • Both must be BUY, same market, different outcomes
  • price0 + price1 >= 1e6 (prices cross)
  • Surplus refunded proportionally

fillBuyVsSell(uint256 buyId, uint256 sellId, uint256 fillAmount)

Match a BUY against a SELL on the same outcome. Executes at seller's price.

  • Buyer's price >= seller's price
  • Buyer gets tokens, seller gets USDC minus fee
  • Buyer's excess USDC refunded

cancelOrder(uint256 orderId)

Cancel your own order. Refunds remaining USDC (BUY) or tokens (SELL).

cancelOrders(uint256[] orderIds)

Batch cancel.

cancelExpiredOrder(uint256 orderId)

Cancel any order on a resolved market. Anyone can call.

onERC1155Received / onERC1155BatchReceived

ERC-1155 receiver hooks. Only accepts tokens from CTF.

supportsInterface(bytes4 interfaceId) → bool

Returns true for ERC-165 (0x01ffc9a7) and ERC-1155 receiver (0x4e2312e0).

Events

EventParameters
OrderPlacedorderId (indexed), maker (indexed), conditionId (indexed), outcomeIndex, side, price, amount
OrderFilledorderId (indexed), matchedOrderId (indexed), fillAmount
OrderCancelledorderId (indexed)

Treasury

Constants

NameValue
FEE_BPS10 (0.1%)
BPS_DENOMINATOR10000

Immutables

NameTypeDescription
RECIPIENTaddressFee recipient, set at deploy

Functions

calculateFee(uint256 amount) → uint256

Returns the fee for a given amount. Rounds up.

withdraw(IERC20 token)

Sends full token balance to RECIPIENT. Anyone can call.

  • Reverts: ZeroAddress (custom error), NoFees (custom error)

Events

EventParameters
FeesWithdrawntoken (indexed), amount

NegRiskAdapter

Immutables

NameTypeDescription
FACTORYMarketFactoryMarketFactory address

State

NameTypeDescription
nextMarketIduint256Counter for market IDs

Functions

createMultiOutcomeMarket(string question, string[] outcomeLabels, uint256 deadline, address resolver) → uint256 marketId

Creates N binary markets from a multi-outcome question. Each binary leg is created on the MarketFactory with the specified resolver.

  • 2–64 outcomes, no duplicates, no empty labels, question max 1024 bytes

getOutcomeConditionId(uint256 marketId, uint256 outcomeIndex) → bytes32

Returns the binary conditionId for a specific outcome.

getOutcomeCount(uint256 marketId) → uint256

Returns the number of outcomes.

getAllConditionIds(uint256 marketId) → bytes32[]

Returns all binary conditionIds.

getOutcomeLabel(uint256 marketId, uint256 outcomeIndex) → string

Returns the label for an outcome.

isResolved(uint256 marketId) → bool

True when ALL underlying binary markets are resolved.

Events

EventParameters
MultiOutcomeMarketCreatedmarketId (indexed), creator (indexed), resolver (indexed), question, outcomeCount, deadline, binaryConditionIds

BaseResolver (abstract)

Abstract base contract for building custom resolvers. Provides factory reference, common validations, and payout helpers.

Immutables

NameTypeDescription
FACTORYMarketFactoryMarketFactory address

Internal Functions

FunctionDescription
_requireResolver(bytes32 conditionId)Reverts NotThisResolver if this contract isn't the market's resolver
_requireResolvable(bytes32 conditionId)Reverts NotResolvable if before deadline or already resolved
_resolveOutcome(bytes32 conditionId, uint256 winnerIndex)Builds payouts and calls factory.resolveMarket(). type(uint256).max = void (equal payouts). Reverts InvalidOutcome if index out of bounds.
_notifyInitiated(bytes32 conditionId)Calls factory.notifyResolutionInitiated()
_notifyFinalized(bytes32 conditionId)Calls factory.notifyResolutionFinalized()

Errors

ErrorWhen
ZeroAddressFactory address is zero in constructor
NotThisResolverContract is not the resolver for the given market
NotResolvableMarket is before deadline or already resolved
InvalidOutcomeWinner index >= outcome count (and not type(uint256).max)

UMAResolver

Immutables

NameTypeDescription
FACTORYMarketFactoryMarketFactory address
ORACLEIOptimisticOracleV3UMA OOv3 address
BOND_TOKENIERC20Bond/collateral token (USDC)

State

NameTypeDescription
activeAssertionsmapping(bytes32 => bytes32)conditionId → active assertionId
assertionsmapping(bytes32 => Assertion)assertionId → assertion data

Constants

NameValueDescription
LIVENESS72002-hour challenge window
BOND_AMOUNT750e6750 USDC bond floor

Types

Assertion (struct)

FieldType
conditionIdbytes32
assertedOutcomeuint256
asserteraddress

Functions

assertOutcome(bytes32 conditionId, uint256 assertedOutcome)

Assert which outcome won. Caller pays bond.

  • Market must be resolvable (deadline passed, not resolved)
  • No other active assertion on this market
  • assertedOutcome: any index from 0 to outcomeSlotCount - 1, or type(uint256).max for VOID

assertOutcomeFor(bytes32 conditionId, uint256 assertedOutcome, address asserter)

Assert on behalf of another address. Bond pulled from msg.sender, refund goes to asserter.

settleAssertion(bytes32 assertionId)

Poke UMA to settle a liveness-expired assertion. Anyone can call.

bondAmount() → uint256

Returns the effective bond: max of 750 USDC and UMA's current minimum.

Callbacks (called by UMA only)

assertionResolvedCallback(bytes32 assertionId, bool assertedTruthfully)

Called when assertion settles. If truthful, resolves the market via factory.resolveMarket().

assertionDisputedCallback(bytes32 assertionId)

Called when assertion is disputed. Clears the active assertion slot.

Events

EventParameters
ResolutionAssertedconditionId (indexed), assertionId (indexed), assertedOutcome, asserter
MarketResolvedconditionId (indexed), winningOutcome
MarketVoidedconditionId (indexed)
AssertionDisputedconditionId (indexed), assertionId (indexed)
AssertionRejectedconditionId (indexed), assertionId (indexed)

KalshiResolver

Immutables

NameTypeDescription
FACTORYMarketFactoryMarketFactory address
ORACLEIOptimisticOracleV3UMA OOv3 address
BOND_TOKENIERC20Bond/collateral token (USDC)

State

NameTypeDescription
assertionsmapping(bytes32 => Assertion)Assertion data by assertionId
activeAssertionsmapping(bytes32 => bytes32)conditionId → active assertionId
kalshiTickersmapping(bytes32 => bytes32)conditionId → Kalshi ticker

Functions

linkMarket(bytes32 conditionId, bytes32 ticker)

Links an PredictionLabs market to a Kalshi ticker. Must be called before asserting.

assertOutcome(bytes32 conditionId, uint256 assertedOutcome)

Assert which outcome won. Caller pays bond.

assertOutcomeFor(bytes32 conditionId, uint256 assertedOutcome, address asserter)

Assert on behalf of another address. Bond pulled from msg.sender, refund goes to asserter.

settleAssertion(bytes32 assertionId)

Poke UMA to settle a liveness-expired assertion. Anyone can call.

bondAmount() → uint256

Returns the effective bond.

Callbacks (called by UMA only)

assertionResolvedCallback(bytes32 assertionId, bool assertedTruthfully)

Called when assertion settles. If truthful, resolves the market.

assertionDisputedCallback(bytes32 assertionId)

Called when assertion is disputed. Clears the active assertion slot.


PolymarketResolver

Immutables

NameTypeDescription
FACTORYMarketFactoryMarketFactory address
CTFIConditionalTokensGnosis CTF address (shared with Polymarket)

State

NameTypeDescription
polymarketConditionsmapping(bytes32 => bytes32)PredictionLabs conditionId → Polymarket conditionId

Functions

linkMarket(bytes32 conditionId, bytes32 polymarketConditionId)

Links an PredictionLabs market to a Polymarket condition. The condition does not need to be resolved at link time.

resolve(bytes32 conditionId)

Reads payouts from the Gnosis CTF (payoutNumerators/payoutDenominator) and resolves the market via factory.resolveMarket(). The Polymarket condition must be resolved on the CTF before calling.

On this page

MarketFactoryImmutablesStateConstantsTypesMarket (struct)FunctionscreateMarket(string question, uint256 outcomeSlotCount, uint256 deadline, address resolver) → bytes32 conditionIdresolveMarket(bytes32 conditionId, uint256[] payouts)notifyResolutionInitiated(bytes32 conditionId)notifyResolutionFinalized(bytes32 conditionId)forceVoid(bytes32 conditionId)isTrading(bytes32 conditionId) → boolisResolvable(bytes32 conditionId) → boolEventsOrderBookImmutablesStateConstantsTypesSide (enum)Order (struct)FunctionsplaceBuyOrder(bytes32 conditionId, uint256 outcomeIndex, uint256 price, uint256 amount) → uint256 orderIdplaceSellOrder(bytes32 conditionId, uint256 outcomeIndex, uint256 price, uint256 amount) → uint256 orderIdplaceBuyOrders(bytes32[] conditionIds, uint256[] outcomeIndexes, uint256[] prices, uint256[] amounts) → uint256[] orderIdsfillBuyVsBuy(uint256 buyId0, uint256 buyId1, uint256 fillAmount)fillBuyVsSell(uint256 buyId, uint256 sellId, uint256 fillAmount)cancelOrder(uint256 orderId)cancelOrders(uint256[] orderIds)cancelExpiredOrder(uint256 orderId)onERC1155Received / onERC1155BatchReceivedsupportsInterface(bytes4 interfaceId) → boolEventsTreasuryConstantsImmutablesFunctionscalculateFee(uint256 amount) → uint256withdraw(IERC20 token)EventsNegRiskAdapterImmutablesStateFunctionscreateMultiOutcomeMarket(string question, string[] outcomeLabels, uint256 deadline, address resolver) → uint256 marketIdgetOutcomeConditionId(uint256 marketId, uint256 outcomeIndex) → bytes32getOutcomeCount(uint256 marketId) → uint256getAllConditionIds(uint256 marketId) → bytes32[]getOutcomeLabel(uint256 marketId, uint256 outcomeIndex) → stringisResolved(uint256 marketId) → boolEventsBaseResolver (abstract)ImmutablesInternal FunctionsErrorsUMAResolverImmutablesStateConstantsTypesAssertion (struct)FunctionsassertOutcome(bytes32 conditionId, uint256 assertedOutcome)assertOutcomeFor(bytes32 conditionId, uint256 assertedOutcome, address asserter)settleAssertion(bytes32 assertionId)bondAmount() → uint256Callbacks (called by UMA only)assertionResolvedCallback(bytes32 assertionId, bool assertedTruthfully)assertionDisputedCallback(bytes32 assertionId)EventsKalshiResolverImmutablesStateFunctionslinkMarket(bytes32 conditionId, bytes32 ticker)assertOutcome(bytes32 conditionId, uint256 assertedOutcome)assertOutcomeFor(bytes32 conditionId, uint256 assertedOutcome, address asserter)settleAssertion(bytes32 assertionId)bondAmount() → uint256Callbacks (called by UMA only)assertionResolvedCallback(bytes32 assertionId, bool assertedTruthfully)assertionDisputedCallback(bytes32 assertionId)PolymarketResolverImmutablesStateFunctionslinkMarket(bytes32 conditionId, bytes32 polymarketConditionId)resolve(bytes32 conditionId)