Skip to main content
  • Bots listen for oracle-trigger conditions (e.g. asset price ≥ target).
  • Upon trigger they call MarketContract.resolve() passing Pyth price ID.
  • Contract sets outcome ⟶ users burn winning tokens for $1 each.
/**
     * @notice Push a Pyth update, evaluate the condition, and settle a market.
     * @param market      The prediction-market contract being settled.
     * @param updateData  Raw Pyth price-feed update packets.
     */
    function updatePriceAndFulfill(
        address market,
        bytes[] calldata updateData
    ) external onlyServer payable {
        require(market != address(0), "Oracle: zero market");
        require(updateData.length > 0,  "Oracle: empty update");

        /*── 1. Pay Pyth fee and publish the update ───────────────────*/
        uint256 fee = PYTH.getUpdateFee(updateData);
        require(msg.value >= fee, "Oracle: fee too low");
        PYTH.updatePriceFeeds{value: fee}(updateData);

        /*── 2. Pull market parameters in one shot ────────────────────*/
        IMarket.TriggerCondition memory tc = IMarket(market).getMarketParams();

        /*── 3. Fetch and validate a fresh price ──────────────────────*/
        IPyth.Price memory p =
            PYTH.getPriceNoOlderThan(tc.assetId, MAX_AGE_SECONDS);  // reverts if too old

        _validatePriceStruct(p);                      
        uint256 spot = _toUint(p.price, p.expo);

        /*── 4. Decide winner based on the validated spot ─────────────*/
        uint256 winningToken;
        if (tc.op == IMarket.Operator.LT) {
            winningToken = (spot <= tc.triggerPrice) ? 1 : 2;
        } else { // GT
            winningToken = (spot >= tc.triggerPrice) ? 1 : 2;
        }

        /*── 5. Resolve the market ───────────────────────────────────*/
        IMarket(market).resolveMarketOracle(winningToken);

        /*── 6. Refund any excess ETH ────────────────────────────────*/
        uint256 refund = msg.value - fee;
        if (refund != 0) payable(msg.sender).transfer(refund);
    }

Typical resolution timeline

  1. A market’s trigger condition is met and a bot submits the relevant Pyth update.
  2. The contract fetches a fresh price, validates it, and determines the winning side.
  3. The market resolves on-chain and claims open immediately for the winning token.
Most markets finalize within minutes of the oracle reporting the triggering price.

Oracle failure contingency

  • If Pyth is unavailable or returns stale data, updatePriceAndFulfill reverts.
  • Bots continually retry the call until a valid price is published.
  • Until then, the market remains unresolved and funds stay locked.
The retry and escalation flow is:
Resolution is deterministic—no human can override oracle data.