Smart Contracts
MarketFactory
Section titled “MarketFactory”Address: 0x0027Adb36E28fA1C037286Da59BB348fA2B63Bd6
The factory creates and tracks all prediction markets.
Write Functions
Section titled “Write Functions”createMarketAndBet
Section titled “createMarketAndBet”Creates a market and places an initial seed bet in a single transaction.
function createMarketAndBet( string _question, bytes32 _feedId, int256 _strikePrice, uint256 _resolutionTime, uint256 _bettingCloseTime, bool _betYes) external payable returns (address market)| Parameter | Description |
|---|---|
_question | Human-readable market question |
_feedId | keccak256(toUtf8Bytes("BTCUSD")) — get from Feed API |
_strikePrice | Strike price in 18-decimal fixed point (e.g. 100000 * 1e18) |
_bettingCloseTime | Unix timestamp (seconds) when betting closes |
_resolutionTime | Unix timestamp (seconds) when market resolves via oracle |
_betYes | true = bet Yes, false = bet No |
msg.value | QUAI amount for the seed bet (must meet minSeedBet) |
createMarket
Section titled “createMarket”Creates a market without a seed bet (owner only in practice).
function createMarket( string question, bytes32 feedId, int256 strikePrice, uint256 resolutionTime, uint256 bettingCloseTime) external returns (address market)Read Functions
Section titled “Read Functions”| Function | Returns | Description |
|---|---|---|
getMarkets() | address[] | All market addresses |
getMarketCount() | uint256 | Number of markets created |
markets(i) | address | Market address at index i |
isMarket(addr) | bool | Whether addr is a valid market |
minSeedBet() | uint256 | Minimum seed bet in wei |
treasuryFeeBps() | uint256 | Treasury fee in basis points |
creatorFeeBps() | uint256 | Creator fee in basis points |
Events
Section titled “Events”| Event | Parameters |
|---|---|
MarketCreated | market (indexed), creator (indexed), question, feedId, strikePrice, resolutionTime, bettingCloseTime |
ParimutuelMarket
Section titled “ParimutuelMarket”Each market is a separate contract deployed by the factory.
Write Functions
Section titled “Write Functions”betYes() / betNo()
Section titled “betYes() / betNo()”Place a bet on the Yes or No outcome. Send QUAI as msg.value.
function betYes() external payablefunction betNo() external payableclaim()
Section titled “claim()”Claim winnings after market resolution. Reverts if you have nothing to claim.
function claim() externalresolve(storkUpdateData)
Section titled “resolve(storkUpdateData)”Resolve the market using Stork Oracle signed price data. Anyone can call this after resolutionTime. Requires sending the oracle update fee as msg.value.
function resolve( IStorkOracle.TemporalNumericValueInput[] storkUpdateData) external payableRead Functions
Section titled “Read Functions”| Function | Returns | Description |
|---|---|---|
question() | string | Market question text |
feedId() | bytes32 | Oracle feed identifier |
strikePrice() | int256 | Strike price (18-decimal fixed point) |
resolutionTime() | uint256 | Unix timestamp for resolution |
bettingCloseTime() | uint256 | Unix timestamp when betting closes |
status() | uint8 | 0=Active, 1=Resolved, 2=Cancelled |
yesPool() | uint256 | Total QUAI in Yes pool |
noPool() | uint256 | Total QUAI in No pool |
getUserBets(user) | (uint256, uint256) | User’s (yesBet, noBet) amounts |
calculatePayout(user) | uint256 | User’s payout if they win |
estimatePayout(isYes, amount) | uint256 | Estimated payout for a hypothetical bet |
getImpliedOdds() | (uint256, uint256) | (yesProb, noProb) as percentages |
isBettingOpen() | bool | Whether betting is still open |
yesWon() | bool | Whether Yes won (after resolution) |
resolvedPrice() | int256 | Actual price at resolution |
totalVolume() | uint256 | Total QUAI wagered |
creator() | address | Market creator address |
hasClaimed(user) | bool | Whether user has claimed winnings |
Events
Section titled “Events”| Event | Parameters |
|---|---|
BetPlaced | user (indexed), isYes, amount, newYesPool, newNoPool |
MarketResolved | yesWon, resolvedPrice |
WinningsClaimed | user (indexed), payout |
MarketCancelled | (none) |