> 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 0x53202B38eaEc1CC715aEa7A25Cb43FdAF9F9facC \
  "consult(address,uint32)(uint256)" \
  0x70F389B0B34229c6d007C836D425D5dea3FEE304 1800 \
  --rpc-url https://rpc.testnet.chain.robinhood.com
```

From a contract:

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

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

    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: "0x53202B38eaEc1CC715aEa7A25Cb43FdAF9F9facC",
  abi: parseAbi(["function consult(address,uint32) view returns (uint256)"]),
  functionName: "consult",
  args: ["0x70F389B0B34229c6d007C836D425D5dea3FEE304", 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).
