Price Oracle

Price Oracle

A Somnia Agents base agent that serves the median price of a token across several exchanges, from a cache it keeps up to date, to your contract.

Price Oracle is a base agent on Somnia Agents. It polls the price of a configured set of tokens on several exchanges, keeps each exchange's latest quote in memory, and answers a request with the median across exchanges. No network call happens while a request is served, and no LLM is involved, so it is fast and cheap.

Symbols are exchange-style pairs such as BTC/USDC, or BTC/USDC:PERP for a perpetual. Prices come back scaled by the decimals the caller asks for, with how many exchanges contributed and when the quote was last updated.

Methods

Method Returns For
getPrices median, source count and update time per symbol Several symbols at once
getPricesPacked the same medians, two symbols per word Gas-efficient batches
getPricesSlots the same medians, one 48-bit slot per symbol Many symbols in one call
getExchangePrice one exchange's latest quote and its time A named exchange, with a freshness limit the caller sets

Price Oracle and Somnia Price Feeds

Price Oracle answers a contract's request on demand. Somnia Price Feeds is built on the same agents but pushes a spot and a mark price for every tracked pair into contract storage about once a second, so any contract reads a price for free with no request. Use Price Oracle for a symbol the feeds don't track or for one exchange's quote; use Price Feeds for a price a market or a lending pool reads every block.

Reference

Parameters, freshness rules, the minimum number of sources, receipts and the price per subcommittee member are in the agent's reference page, Price Oracle. Calling any agent from Solidity is in Invoking from Solidity.

Every registered agent, with its methods and price, is in the Agents directory in the Somnia Explorer.

Edit this page

Send feedback

Agents: POST the same to /api/feedback.