4.2 Oracle Integration

Fetch real-time prices using AI-Driven Oracles.

const oracle = new ethers.Contract(ORACLE_ADDRESS, oracleAbi, provider);
const key = ethers.utils.formatBytes32String("BTC/USD");
const [priceX1e18, timestamp] = await oracle.getPrice(key);

if (Date.now()/1000 - timestamp > 300) {
  throw new Error("Stale data");
}

Config Example

{
  "oracleAddress": "0xOracleContract",
  "refreshInterval": 60,
  "staleThresholdSeconds": 300
}