CanonicCanonic Docs
Documentation

Oracle Adapter

Interface

MAOB depends on an oracle adapter implementing:

getPrice(address orderBook) -> (uint256 price, uint256 precision, uint48 updatedAt)

Where:

  • price is the raw price value (midpoint)
  • precision is the scale factor such that: mid = price / precision
  • updatedAt is the timestamp of the price update (0 if unavailable)

MAOB calls the adapter with its own address as orderBook.

Requirements enforced by MAOB

From MAOB.sol internal _getMidPrice():

  • price != 0 and precision != 0 or the call reverts with MAOB__OraclePriceMissing()
  • updatedAt != 0 or the call reverts with MAOB__OracleStale()
  • Overflow-safety checks ensure the price, precision, and token scales won’t overflow internal math; otherwise MAOB__OracleOutOfRange()

Precision and decimals

MAOB supports tokens up to 18 decimals. Internally it computes:

  • baseScale = 10^baseDecimals
  • quoteScale = 10^quoteDecimals

The adapter can choose any precision, but it must be consistent and stable for the pair. Common patterns:

  • precision = 1e18 and price expressed as base token/quote token with 18 decimals
  • precision = 1e8 like many Chainlink feeds (ensure downstream scaling remains safe)

Operational guidance

  • Prefer returning a midpoint price for the specific pair MAOB trades (base token/quote token).
  • Ensure timestamps advance as the oracle updates; per-leg staleness is enforced inside the OracleAdapter (for composite feeds).
  • If your oracle can be paused or degraded, decide whether to return (0,0,0) to hard-fail trading, or a last-known price with a timestamp (which may still be rejected as stale if the adapter’s per-leg staleness threshold is exceeded).

Timelock scheduling note

If the OracleAdapter is owned by a timelock, feed configuration calls (setCompositeFeed / setFeedAdvanced) are scheduled and do not take effect immediately. Until the timelock executes the scheduled call, MAOB will not receive a valid midpoint and getMidPrice() will revert. The frontend treats this as “Pending (timelock)” for the oracle feed until the timelock operation is executed.