Skip to main content

MarketFactory

Core market lifecycle contract: market creation, resolution, mint/burn/redeem flows, and negative-risk conversion for multi-binary markets.

Functions

createMarket

function createMarket(CreateMarketParams calldata params) returns (bytes32 marketId);

struct CreateMarketParams {
    address oracle;
    bytes32 questionId;
    string[] outcomeNames;
    bytes metadata;
    address collateralToken;
    bool isMultiBinary;
    bytes[] childMetadata;
}
Creates a new market. Requires MARKET_CREATOR_ROLE. For multi-binary markets (isMultiBinary: true), creates a parent market plus one binary child market per outcome. Returns the market ID; for multi-binary creation this is the parent market ID.

addChildMarket

function addChildMarket(bytes32 parentMarketId, string memory questionName, bytes memory metadata) returns (bytes32)
Adds a new child binary market to an existing multi-binary parent. Requires MARKET_CREATOR_ROLE. Cannot be called after the parent or any child has resolved.

resolveMarket

function resolveMarket(bytes32 marketId, uint256[] calldata payoutPcts)
Resolves a market with final payout percentages. Only callable by the market oracle. For multi-binary child markets, only pure YES ([scale, 0]) or pure NO ([0, scale]) resolutions are allowed, and at most one child across the parent can resolve YES.

mintCompleteSets

function mintCompleteSets(bytes32 marketId, uint256 amount, address to)
Deposits collateral and mints one full set of outcome tokens per amount to to. Not valid on multi-binary parent markets; mint against regular markets or individual child markets.

burnCompleteSets

function burnCompleteSets(bytes32 marketId, uint256 amount, address to)
Burns one of each outcome token from msg.sender and returns collateral to to. Not valid on multi-binary parent markets.

redeemOutcomes

function redeemOutcomes(bytes32 marketId, uint256[] calldata amounts, address to)
Redeems resolved outcome tokens for collateral based on the market payout vector. Burns outcome tokens from msg.sender and sends collateral to to.

convertPositions

function convertPositions(bytes32 marketId, uint256 indexSet, uint256 amount, uint256 expectedQuestionCount)
Negative-risk conversion for a multi-binary parent market. indexSet is a bitmask of the NO positions being converted. Reverts if any child has already resolved YES, or if expectedQuestionCount does not match the current child count. Conversion rule for a parent with M total child questions, when converting N NO positions:
N NO -> (M - N) YES + (N - 1) collateral

Read helpers

function getTokens(bytes32 marketId) returns (address collateralToken, address[] memory outcomeTokens);
function getChildMarketIds(bytes32 parentMarketId) returns (bytes32[] memory);
function getTradingInfo(bytes32 marketId)
    returns (
        address collateralToken,
        address[] memory outcomeTokens,
        bool resolved,
        bool isMultiBinary,
        bytes32 parentMarketId,
        bool anyChildOrSiblingResolvedYes
    );
function getParentMarket(bytes32 childMarketId) returns (bytes32);
function getQuestionMarketId(bytes32 parentMarketId, uint8 questionIndex) returns (bytes32);
These are the main read paths for discovering token addresses, distinguishing parent vs child markets, and determining whether a multi-binary market is still convertible/tradable.

Events

event MarketCreated(
    bytes32 indexed marketId,
    address indexed oracle,
    address indexed creator,
    bytes32 questionId,
    address[] outcomeTokens,
    string[] outcomeNames,
    bytes metadata,
    address collateralToken,
    bytes32 parentMarketId,
    bytes32 parentQuestionId,
    string childOutcomeName,
    bytes parentMetadata,
    uint8 childQuestionIndex
);

event MarketResolved(bytes32 indexed marketId, uint256[] payoutPcts);

event PositionsConverted(address indexed stakeholder, bytes32 indexed marketId, uint256 indexSet, uint256 amount);

event OutcomesRedeemed(
    bytes32 indexed marketId,
    address indexed redeemer,
    address indexed to,
    uint256[] outcomeAmounts,
    uint256 totalPayout
);

event ParentMarketStateUpdated(bytes32 indexed parentMarketId, bool anyChildResolved, bool anyChildResolvedYes);