Price Oracle
Price Oracle
A Somnia Agents base agent that serves the weighted 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 weighted median across exchanges. No network call happens while a request is served, and no LLM is involved, so it is fast and cheap. It runs on the Global L1 and the Tokyo Subchain, mainnet and testnet.
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.
See it in use
- Price Oracle in Somnia Explorer. The registered agents of this type, with their methods and price. Each agent's page has Try it, which sends a request from your wallet and follows it until the validators agree; the Price Oracle's own page is agent 9911223344556677889.
- Live requests. Every agent request as it is created, with each validator's signed receipt on its request page.
Use it from the CLI and MCP
The Somnia CLI and MCP server have no Somnia Agents commands yet. Send a request from a contract, as in Invoking from Solidity, or from a script with viem: each agent's page in the Explorer generates both. somnia explorer tx $HASH reads the transaction that sent a request (add --network testnet for a testnet one), as does the MCP server's explorer_transaction tool given the same network.
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.