> For the complete documentation index, see [llms.txt](https://docs.delphirhc.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.delphirhc.com/the-oracle/reading-the-oracle.md).

# Reading the oracle

The oracle is the Delphi hook contract. Every function below is a view, costs no gas to call from off-chain, and can be called from another contract at the cost of a few storage reads.

## The main call

```solidity
function consult(address token, uint32 window) external view returns (uint256 price);
```

`consult` returns the time-weighted average price of one whole token, over the last `window` seconds, in the smallest unit of the pool's quote asset. For a token launched against ETH the answer is in wei per token. `consult(token, 1800)` is the thirty-minute TWAP.

It reverts with `NotEnoughHistory` when the pool has fewer than twelve observations, and with `OldestObservation` when the buffer does not reach back the full window. Check `maturity` first if you would rather not handle the revert.

## Pricing an amount

```solidity
function quote(address token, uint256 baseAmount, uint32 window) external view returns (uint256 quoteAmount);
```

Returns the quote-asset value of `baseAmount` of the token at the TWAP. This is the call a lending market makes to value collateral, since it handles decimals for you.

## Working in ticks

```solidity
function consultTick(address token, uint32 window) external view returns (int24 meanTick);
```

Returns the average tick rather than a price, in the pool's `currency1` per `currency0` orientation. Use it if you are composing with other Uniswap maths or want to avoid the conversion.

## Everything else

```solidity
function quoteOf(address token) external view returns (address);
function observationCount(address token) external view returns (uint16);
function oldestObservation(address token) external view returns (uint32);
function maturity(address token) external view returns (uint8);
function truncatedTick(address token) external view returns (int24);
function depth(address token, uint24 ticks) external view returns (uint256 quoteAmount);
```

`quoteOf` returns the quote asset, with the zero address meaning native ETH. `observationCount` and `oldestObservation` describe how much history exists. `maturity` and `depth` are covered under [Maturity and depth](/the-oracle/maturity-and-depth.md). `truncatedTick` is the last tick the oracle recorded, which is the value the TWAP extrapolates from when there has been no trade since.

## Examples

From the command line with Foundry, against the testnet:

```bash
cast call 0xBb7B970B56BE8f016349D35F5CDfC4299557bAcc \
  "consult(address,uint32)(uint256)" \
  0x4db8781128404F96e53eBf7814CC3C929437dA08 1800 \
  --rpc-url https://rpc.testnet.chain.robinhood.com
```

From a contract:

```solidity
import {IDelphiOracle} from "./IDelphiOracle.sol";

contract Example {
    IDelphiOracle constant ORACLE = IDelphiOracle(0xBb7B970B56BE8f016349D35F5CDfC4299557bAcc);

    function collateralValue(address token, uint256 amount) external view returns (uint256) {
        require(ORACLE.maturity(token) >= 1, "oracle not ready");
        return ORACLE.quote(token, amount, 1800);
    }
}
```

From TypeScript with viem:

```ts
const price = await client.readContract({
  address: "0xBb7B970B56BE8f016349D35F5CDfC4299557bAcc",
  abi: parseAbi(["function consult(address,uint32) view returns (uint256)"]),
  functionName: "consult",
  args: ["0x4db8781128404F96e53eBf7814CC3C929437dA08", 1800],
});
```

The same calls are available as buttons on the explorer, since the hook is source-verified. The interface file is reproduced in full under [Interfaces](/contracts/interfaces.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.delphirhc.com/the-oracle/reading-the-oracle.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
