> For the complete documentation index, see [llms.txt](https://docs.chiliz.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.chiliz.com/jp/kaihatsu/joukyu/on-chain-kakaku-feed/kakaku-no-yomikata.md).

# 価格の読み取り方

## ステップ 1: Oracle アドレスを見つける

指定されたペアの `PriceFeed` コントラクトアドレスを見つける方法は 3 つあります。

* **Price Oracle Tracker**（開発中に最も簡単）: [price-oracle-tracker.vercel.app](https://price-oracle-tracker.vercel.app/?network=mainnet) — デプロイ済みのすべてのペア、ライブ価格、decimals、heartbeat、アドレスを表示します。
* **オンチェーンで OracleFactory を使う**: `pairToOracle(string pair)` を呼び出します。ペアシンボルは大文字で渡す必要があります（例: `"PSG/USDT"`）。ファクトリーは読み取り時に入力を正規化しません。
* **OracleFactoryReader でまとめてオンチェーン取得**: `getActiveOracles()` を呼び出して、すべてのアクティブなペアとそのアドレスを 1 回の呼び出しで取得します。

```solidity
interface IOracleFactory {
    function pairToOracle(string memory pair) external view returns (address);
    function getOracleCount() external view returns (uint256);
}

function resolveFeed(address factory, string memory pair)
    external view returns (address)
{
    // Pair symbol must be passed in uppercase (e.g. "PSG/USDT").
    return IOracleFactory(factory).pairToOracle(pair);
}
```

## ステップ 2: インターフェースで接続する

`PriceFeed` コントラクトは標準の Chainlink `IAggregatorV3Interface` を実装しており、ヘルス状態や一時停止ステータスのための Chiliz 固有の拡張機能も備えています。

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;

interface IAggregatorV3Interface {
    function decimals() external view returns (uint8);
    function description() external view returns (string memory);
    function version() external view returns (uint256);

    function getRoundData(uint80 _roundId)
        external view
        returns (
            uint80 roundId,
            int256 answer,
            uint256 startedAt,
            uint256 updatedAt,
            uint80 answeredInRound
        );

    function latestRoundData()
        external view
        returns (
            uint80 roundId,
            int256 answer,
            uint256 startedAt,
            uint256 updatedAt,
            uint80 answeredInRound
        );
}

interface IChilizPriceFeed is IAggregatorV3Interface {
    function paused() external view returns (bool);
    function updateInterval() external view returns (uint256);
    function healthFactor() external view returns (uint80);
    function getHealthStatus()
        external view
        returns (
            uint256 lastUpdateTimestamp,
            uint256 totalRounds,
            uint256 timeSinceLastUpdate,
            bool isHealthy
        );
}
```

## ステップ 3: 価格を読み取る

{% hint style="warning" %}
**feed は古い状態や一時停止状態でリバートしません — これは意図的な設計です。** `latestRoundData()` はまだ round が存在しない場合に `NoDataAvailable()` でリバートしますが、feed が一時停止中または古い状態かどうかはチェックしません。これは Chainlink AggregatorV3Interface の設計に合わせたものです。価格を消費する前に `paused()` と `getHealthStatus()` でゲート処理を行う責任はコンシューマー側にあります。注意: スカラーヘルパー（`latestAnswer()`、`latestTimestamp()`、`getAnswer()`、`getTimestamp()`）はデータがない場合にリバートせず `0` を返します。完全なバリデーションパターンについては[ベストプラクティス](/jp/kaihatsu/joukyu/on-chain-kakaku-feed/besuto-purakutisu.md)を参照してください。
{% endhint %}

主要な関数は `latestRoundData()` で、現在の価格と round およびタイムスタンプのメタデータを返します。

```solidity
contract LendingOracleConsumer {
    IChilizPriceFeed public priceFeed;

    constructor(address _feed) {
        priceFeed = IChilizPriceFeed(_feed);
    }

    function getSafePrice() public view returns (uint256 price18) {
        // 1. Check feed is not paused
        require(!priceFeed.paused(), "Feed paused");

        // 2. Read latest data (reverts with NoDataAvailable() if no rounds exist)
        (
            uint80 roundId,
            int256 answer,
            uint256 startedAt,
            uint256 updatedAt,
            uint80 answeredInRound
        ) = priceFeed.latestRoundData();

        // 3. Basic sanity checks
        require(answer > 0, "Invalid price");

        // 4. Optional: use explicit health check for staleness
        (, , , bool isHealthy) = priceFeed.getHealthStatus();
        require(isHealthy, "Stale price");

        // 5. Normalize to 18 decimals for internal math
        uint8 decimals_ = priceFeed.decimals();
        uint256 scale = 10 ** uint256(decimals_);
        price18 = uint256(answer) * 1e18 / scale; // This is the actual price of an asset
    }
}
```

プロトコルが 18 decimals に正規化せず feed のネイティブ decimals を使う場合:

```solidity
function getRawPriceWithMeta()
    external view
    returns (int256 price, uint8 decimals_, uint256 updatedAt)
{
    require(!priceFeed.paused(), "Feed paused");

    (, int256 answer, , uint256 _updatedAt, ) =
        priceFeed.latestRoundData();
    require(answer > 0, "Invalid price");

    (, , , bool isHealthy) = priceFeed.getHealthStatus();
    require(isHealthy, "Stale price");

    decimals_ = priceFeed.decimals();
    price = answer;
    updatedAt = _updatedAt;
}
```

## 過去のデータ

Oracle はすべての過去の round データをオンチェーンに保存します。価格が更新されるたびに、インクリメントする `roundId` を持つ新しい round が作成されます。

```solidity
(uint80 roundId, int256 answer, , uint256 updatedAt, ) =
    priceFeed.getRoundData(targetRoundId);
```

Chiliz feed が公開しているその他のヘルパービュー:

| 関数                                 | 返り値                                |
| ---------------------------------- | ---------------------------------- |
| `latestAnswer()`                   | 最新の価格。データがない場合は `0`                |
| `latestTimestamp()`                | 最新の `updatedAt`。データがない場合は `0`      |
| `latestRound()`                    | 現在の round ID                       |
| `getAnswer(uint80 roundId)`        | 指定された round の価格。データがない場合は `0`      |
| `getTimestamp(uint80 roundId)`     | 指定された round のタイムスタンプ。データがない場合は `0` |
| `getRoundsData(uint80[] roundIds)` | まとめて `RoundData` 配列を返す             |
| `roundExists(uint80 roundId)`      | `updatedAt > 0` の場合に `true`        |

## イベント

各 `PriceFeed` コントラクトは以下を発行します。

* **`AnswerUpdated(int256 indexed current, uint80 indexed roundId, uint256 updatedAt)`**: 価格が更新されるたびに発行されます。価格または round でフィルタリングできます。
* **`NewRound(uint80 indexed roundId, address indexed startedBy, uint256 startedAt)`**: 新しい round が始まるときに発行されます。round または開始したアドレスでフィルタリングできます。

## 検索関数（OracleFactoryReader）

| 関数                                      | 説明                                 |
| --------------------------------------- | ---------------------------------- |
| `getActiveOracles()`                    | すべてのアクティブなペアと oracle アドレスを返す       |
| `getAllOracles()`                       | 非アクティブなものも含めすべての oracle を返す        |
| `getOraclesByPairs(string[] pairs)`     | 複数のペア名を oracle アドレスに 1 回の呼び出しで解決する |
| `getOracleHealthStatus(address oracle)` | 単一の oracle のヘルス状態                  |
| `getAllOracleHealthStatus()`            | システム内すべての oracle のヘルス状態            |


---

# 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.chiliz.com/jp/kaihatsu/joukyu/on-chain-kakaku-feed/kakaku-no-yomikata.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.
