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

# Oracle Gateway

Oracle Gateway mengekspos umpan harga native Solana (Pyth, Switchboard V3) melalui `AggregatorV3Interface`, jadi protokol Ethereum yang dipindahkan ke Rome tetap menggunakan kode integrasi oracle yang sudah ada. **Oracle Gateway V2 sudah aktif di setiap chain publik**, dengan keeper yang menjamin kesegaran feed dan portal pelanggan untuk pendaftaran. Adapter, factory, dan model keeper dibahas di [rome-oracle-gateway](https://github.com/rome-protocol/rome-oracle-gateway) repositori.

## Masalahnya

DeFi Ethereum mengharapkan `AggregatorV3Interface`:

```solidity
(, int256 price,,,) = priceFeed.latestRoundData();
```

Penyedia oracle Solana (Pyth, Switchboard) memiliki format data yang berbeda. Tanpa adaptasi, setiap protokol yang dipindahkan akan memerlukan kode oracle kustom.

## Solusinya

Oracle Gateway V2 men-deploy kontrak adapter ringan yang:

1. Membaca data harga langsung dari akun Pyth atau Switchboard di Solana (cross-state reads, bukan CPI)
2. Mengurai data on-chain
3. Menormalisasi harga ke 8 desimal
4. Mengekspos standar Chainlink `AggregatorV3Interface`

```solidity
import {IAggregatorV3Interface} from "@rome-protocol/rome-solidity/contracts/oracle/IAggregatorV3Interface.sol";

// Antarmuka yang sama seperti Chainlink di Ethereum
(, int256 price,,,) = IAggregatorV3Interface(ADAPTER).latestRoundData();
// harga = SOL/USD pada 8 desimal (mis. 15000000000 = $150.00)
```

## Menggunakan sebuah feed dalam tiga langkah

1. **Menyelesaikan alamat adapter dari registry** — jangan pernah di-hardcode:

```ts
import { getOracle } from "@rome-protocol/registry";
const solUsd = getOracle(200010).feeds["SOL/USD"].address;
// Hadrian saat ini: 0x76b92646D63FB1AFEa687C7Dac48b437bF99C1B4
```

2. **Baca** dengan antarmuka yang sudah digunakan protokol Anda — `IAggregatorV3Interface(solUsd).latestRoundData()`. Feed yang kedaluwarsa atau belum diinisialisasi **melakukan revert** daripada menyajikan harga yang membeku.
3. **Beberapa feed sekaligus?** `BatchReader.getLatestPrices(adapters[])` (Hadrian: `0x306d670dff7f51ae33f263f5122bd2b18d98adc7`) — dan `getFeedHealth(adapters[])` sebelum bergantung padanya. Adapter cached membuat setiap konsumen membaca sebuah `SLOAD`, sehingga transaksi multi-feed (pinjaman multi-agunan, tampilan portofolio) tetap murah.

[cardo](https://github.com/rome-protocol/cardo) mengonsumsi feed ini di produksi saat ini. Karena antarmukanya persis `AggregatorV3Interface`, protokol kelas Compound dan Aave **drop-in** — arahkan konfigurasi price-feed mereka ke alamat adapter; kode oracle mereka tidak perlu diubah sama sekali.

## Jenis adapter

* **PythPullAdapter** — membaca akun harga Pyth (harga, confidence, EMA, waktu publikasi).
* **SwitchboardV3Adapter** — membaca akun aggregator Switchboard (harga, timestamp; tanpa EMA).
* **CachedPyth / CachedFeed adapters** — varian cached-track untuk pembacaan yang efisien CU.

Adapter di-deploy sebagai klon minimal-proxy EIP-1167 oleh `OracleAdapterFactory` dan mengekspos antarmuka yang diperluas bersama `AggregatorV3Interface` (`latestPriceData`, `maxStaleness`, `oracleType`, serta `metadata()` yang digunakan untuk pemeriksaan kesehatan).

## Kesegaran — oracle-keeper

Adapter menerapkan sebuah `maxStaleness` jendela: jika `block.timestamp - publishTime > maxStaleness`, pembacaan melakukan revert. Di mainnet Solana, Pyth menjalankan keeper produksi. Di devnet Solana (tempat chain publik berada), pusher Pyth bersifat best-effort, jadi Rome menjalankan **oracle-keeper** sidecar sendiri untuk menjaga akun Pyth yang mendasarinya tetap segar. Kesegaran dipantau dan diberi peringatan.

Periksa kesehatan feed dengan `BatchReader.getFeedHealth` (yang membaca masing-masing adapter `metadata()`), bukan hanya `latestRoundData` — sebuah feed bisa dapat dijangkau tetapi kedaluwarsa.

## Portal pelanggan

Daftarkan feed dan konfigurasikan konsumen per chain melalui [portal Oracle Gateway](https://oracle.testnet.romeprotocol.xyz/). Lihat [halaman portal](/id/aplikasi-di-rome/oracle-gateway.md) untuk cakupan yang dibahas.

## Alamat yang dideploy

Alamat kanonik per chain (factory, implementasi adapter, dan feed yang aktif) berada di [registry](https://github.com/rome-protocol/rome-registry/tree/main/chains). Factory utama:

| Kontrak              | Hadrian                                      | Martius                                      |
| -------------------- | -------------------------------------------- | -------------------------------------------- |
| OracleAdapterFactory | `0xe68e7bc697010c73f1798b356f8ae2f0ba1319db` | `0xbc06fe9603a02ff4aead265c253f5c6303ee5fbb` |
| BatchReader          | `0x306d670dff7f51ae33f263f5122bd2b18d98adc7` | `0xc5e6d932bfd2b4da27643848063905f46861fae8` |

## Batasan

* **Tidak ada data ronde historis** — `getRoundData(roundId)` melakukan revert; hanya `latestRoundData()` yang didukung.
* **EMA Switchboard tidak didukung** — data EMA hanya untuk Pyth.
* **Kedaluwarsa per chain** — `maxStaleness` ditetapkan per lingkungan saat penyiapan: adapter langsung (membaca Pyth) default sekitar 60 detik; adapter cached default 3600 detik (keeper menyegarkan jauh lebih sering — sekitar 25 detik di devnet/testnet saat ini).
* **Offset parser** divalidasi terhadap layout Pyth/Switchboard saat ini; perubahan layout memerlukan validasi ulang.

## Selanjutnya

* [portal Oracle Gateway](/id/aplikasi-di-rome/oracle-gateway.md) — daftarkan feed, konfigurasikan konsumen
* [Alamat Kontrak](/id/referensi/contract-addresses.md) — precompile dan alamat per chain


---

# 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.rome.builders/id/produk/oracle-gateway.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.
