# Chain 138 Oracle and Keeper Reference

**Purpose**: ORACLE_AGGREGATOR / ORACLE_PROXY for Chain 138 and keeper/price-update flows so PMM and reporting stay aligned with oracle data.

---

## Environment Variables (Chain 138)

Set in project `.env` (and in token-aggregation or relay when they consume oracle):

| Variable | Description |
|----------|-------------|
| `ORACLE_AGGREGATOR_ADDRESS` | Oracle aggregator contract on Chain 138 (e.g. from deployment). Used by CCIP and other consumers. |
| `ORACLE_PROXY_ADDRESS` | Oracle proxy contract on Chain 138 when applicable. |
| `RESERVE_SYSTEM` | ReserveSystem address (Chain 138). Required for DODOPMMIntegration oracle-backed mid price. |
| `RPC_URL_138` / `RPC_URL` | RPC endpoint for Chain 138 (keeper and scripts). |

References: [DEPLOYMENT_COMPLETE_GUIDE.md](../deployment/DEPLOYMENT_COMPLETE_GUIDE.md), [DEPLOYMENT_CHECKLIST.md](../DEPLOYMENT_CHECKLIST.md), [PARALLEL_COMPLETION_TASK_LIST.md](../PARALLEL_COMPLETION_TASK_LIST.md).

---

## Keeper and Price Feed Updates

1. **OraclePriceFeed → ReserveSystem**  
   ReserveSystem receives prices from OraclePriceFeed. Ensure assets used by PMM pairs (e.g. cUSDT, cUSDC, USDT, USDC) have aggregators set in OraclePriceFeed and are updated on schedule.  
   See: [PRICE_FEED_SETUP.md](PRICE_FEED_SETUP.md).

2. **Keeper (on-chain / off-chain)**  
   - **PriceFeedKeeper** and scripts: `script/reserve/DeployKeeper.s.sol`, `scripts/reserve/keeper-service.js`, `scripts/reserve/keeper-service.sh`.  
   - **Check/perform upkeep**: `PerformUpkeep.s.sol`, `CheckUpkeep.s.sol`.  
   See: [KEEPER_COMPLETE.md](KEEPER_COMPLETE.md), [KEEPER_SETUP.md](KEEPER_SETUP.md) (if present).

3. **Oracle publisher (off-chain)**  
   Service that pushes external prices (e.g. CoinGecko) into the system:  
   - `services/oracle-publisher/` (e.g. `oracle_publisher.py`, `oracle_publisher_optimized.py`).  
   Use for assets that do not have a Chainlink-style aggregator on Chain 138.

4. **Update oracle price script**  
   One-off or cron-driven update of oracle/oracle proxy with current price:  
   - `scripts/update-oracle-price.sh` — usage: `[rpc-url] [oracle-address] [private-key]`; uses `AGGREGATOR_ADDRESS` and fetches ETH/USD from CoinGecko.  
   Schedule this (or the keeper service) so PMM oracle-backed prices and reporting stay fresh.

---

## PMM and Reporting

- **DODOPMMIntegration**: Optional `setReserveSystem(ReserveSystem)`; then `getPoolPriceOrOracle(pool)` uses ReserveSystem when base/quote are registered.  
- **Token-aggregation**: Set `CHAIN_138_DODO_PMM_INTEGRATION` so the pool indexer ingests PMM pools; report API then includes them in `/report/all`, `/report/coingecko`, `/report/cross-chain`.  
See: [DODO_PMM_INTEGRATION.md](DODO_PMM_INTEGRATION.md#oracle-and-reporting).
