> 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/besuto-purakutisu.md).

# ベストプラクティス

## 価格を使用する前に必ずバリデーションを行う

`latestRoundData()` は round が存在しない場合に `NoDataAvailable()` でリバートしますが、staleness や一時停止のチェックは行いません。保存された値をそのまま返します。価格値を消費する前に、常に以下の 3 つのチェックを実施してください。

1. **一時停止チェック**: `paused()` を呼び出し、feed が一時停止中であれば拒否する。
2. **正の値チェック**: `answer > 0` を要求する。
3. **Staleness チェック**: `getHealthStatus().isHealthy` でゲート処理を行う。

[価格の読み取り方](/jp/kaihatsu/joukyu/on-chain-kakaku-feed/kakaku-no-yomikata.md)の `getSafePrice()` の例がこの 3 つすべてを実装しています。

## Health Status API

各 `PriceFeed` は 1 回の呼び出しで鮮度情報を集約した `getHealthStatus()` ビューを公開しています。

```solidity
function getHealthStatus()
    external view
    returns (
        uint256 lastUpdateTimestamp,
        uint256 totalRounds,
        uint256 timeSinceLastUpdate,
        bool isHealthy
    );
```

| フィールド                 | 説明                                                                   |
| --------------------- | -------------------------------------------------------------------- |
| `lastUpdateTimestamp` | 最新の round の `updatedAt`                                              |
| `totalRounds`         | 書き込まれた round の総数                                                     |
| `timeSinceLastUpdate` | `block.timestamp - lastUpdateTimestamp`（データがない場合は `block.timestamp`） |
| `isHealthy`           | `timeSinceLastUpdate <= updateInterval × healthFactor` の場合に `true`   |

health factor はデフォルトで `2` に初期化されていますが、oracle 管理者が `setHealthFactor()` を通じて feed ごとに設定可能です。`2` をハードコードしないでください。コントラクトから直接読み取ってください。

```solidity
uint80 factor = priceFeed.healthFactor(); // per-feed; do NOT assume the default of 2 (live feeds use 720)
```

health ウィンドウは `updateInterval × healthFactor` で、どちらも feed ごとに設定されます。`updateInterval` は小さなオンチェーンの最小間隔であり、heartbeat ではありません。feed によって異なります。CHZ/USDC は `5s × 720 = 1時間`のウィンドウ、PEPPER/CHZ は `10s × 720 = 2時間`のウィンドウを使用し、オフチェーンパイプラインは約 1 時間の heartbeat でプッシュします。staleness の基準として `updateInterval` 単独で使用しないでください。`isHealthy` でゲート処理を行ってください。完全なパターンについては[価格の読み取り方](/jp/kaihatsu/joukyu/on-chain-kakaku-feed/kakaku-no-yomikata.md)の `getSafePrice()` を参照してください。

システム内のすべての feed を一度に監視するには `OracleFactoryReader` の `getAllOracleHealthStatus()` を使用してください。オフチェーンのダッシュボードやアラートに役立ちます。

## `decimals()` をキャッシュする

各ペアには独自の小数点精度があります。価格値を解釈する前に必ず `decimals()` を呼び出して確認してください。decimals はデプロイ時に設定され変更されないため、価格を読み取るたびではなく、コントラクトの初期化時に一度だけ読み取ってください。

```solidity
uint8 public immutable feedDecimals;

constructor(address _feed) {
    priceFeed = IChilizPriceFeed(_feed);
    feedDecimals = priceFeed.decimals();
}
```

## 一時停止状態を適切に処理する

緊急時に oracle 管理者は feed を一時停止できます。不正な値をサイレントに消費するのではなく、発生するリバートをクリーンに処理してください。

```solidity
require(!priceFeed.paused(), "Feed paused");
```

## 開発中はトラッカーを活用する

[Price Oracle Tracker](https://price-oracle-tracker.vercel.app/?network=mainnet) では、オンチェーン価格を CoinMarketCap および CoinGecko とリアルタイムで比較できるため、統合中に feed の精度を検証しやすくなります。また、すべてのペアのライブヘルス状態、heartbeat パラメーター、個別のコントラクトアドレスも表示されます。

## 統合チェックリスト

* [ ] トラッカー、`pairToOracle()`、または `getActiveOracles()` を通じて `PriceFeed` アドレスを取得する
* [ ] `description()` と `decimals()` を使ってペアの説明と decimals を確認する
* [ ] コントラクトの初期化時に `decimals()` をキャッシュする
* [ ] `latestRoundData()` で価格を読み取る（round がまだ存在しない場合は `NoDataAvailable()` でリバートします）
* [ ] 価格を消費する前に `paused()` をチェックする
* [ ] `answer > 0` をバリデーションする
* [ ] staleness のために `getHealthStatus().isHealthy` でゲート処理を行う（`updateInterval` 単独から独自のしきい値を導出しないこと）
* [ ] 必要に応じて価格を内部精度（例: 18 decimals）に正規化する
* [ ] Mainnet にデプロイする前に Spicy Testnet でテストする


---

# 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/besuto-purakutisu.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.
