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()
  • If maxStaleSeconds != 0:
    • updatedAt must be non-zero
    • block.timestamp <= updatedAt + maxStaleSeconds
    • otherwise 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; MAOB may be configured with a strict staleness window.
  • 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 depending on maxStaleSeconds).