circle-info
This is the first version of our Documentation, it will be improved and extended soon.
Page cover

Running Price Monitoring

In production environments, monitoring IFÁ Labs price feeds is essential to detect staleness, unexpected deviations, or update issues early. This guide provides practical tools and scripts to set up robust onchain price monitoring.

Why Monitor?

  • Detect Stale Feeds: Alert if lastUpdateTime exceeds your threshold.

  • Peg Deviation Alerts: Notify on off-peg events for stablecoins.

  • Health Checks: Ensure the oracle is updating as expected.

  • Incident Response: Quickly pause protocols if anomalies occur.

Simple Monitoring Script (JavaScript + ethers.js)

const { ethers } = require("ethers");

const ORACLE_ADDRESS = "0xA9F17344689C2c2328F94464998db1d3e35B80dC";
const RPC_URL = "https://mainnet.base.org";

const provider = new ethers.JsonRpcProvider(RPC_URL);
const oracle = new ethers.Contract(ORACLE_ADDRESS, [
  "function getAssetInfo(bytes32) view returns ((int256 price, int8 decimal, uint256 lastUpdateTime), bool exists)"
], provider);

const ASSET_IDS = {
  "USDT/USD": "0x6ca0cef6107263f3b09a51448617b659278cff744f0e702c24a2f88c91e65a0d",
  "CNGN/USD": "0x83a18c73cf75a028a24b79cbedb3b8d8ba363b748a3210ddbcaa95eec3b87b3a"
};

const MAX_STALENESS = 3600; // 1 hour
const MAX_DEVIATION = 0.05; // 5%

async function checkPrices() {
  console.log(`\nPrice Monitor Check — ${new Date().toISOString()}\n`);

  for (const [symbol, assetId] of Object.entries(ASSET_IDS)) {
    try {
      const [info, exists] = await oracle.getAssetInfo(assetId);
      
      if (!exists) {
        console.log(`${symbol}: Asset not supported`);
        continue;
      }

      const age = Date.now() / 1000 - info.lastUpdateTime;
      const price = Number(info.price) / 10 ** -info.decimal;

      console.log(`${symbol}: $${price.toFixed(4)} | Age: ${Math.floor(age)}s`);

      if (age > MAX_STALENESS) {
        console.log(`⚠️  STALE: ${symbol} not updated in ${Math.floor(age/60)} minutes`);
      }

      if (Math.abs(price - 1.0) > MAX_DEVIATION) {
        console.log(`⚠️  DEVIATION: ${symbol} off-peg by ${(Math.abs(price - 1)*100).toFixed(2)}%`);
      }
    } catch (err) {
      console.log(`${symbol}: Error fetching price`, err.message);
    }
  }
}

// Run every 5 minutes
setInterval(checkPrices, 300000);
checkPrices(); // Initial run

Advanced Options

  • Alerting: Integrate with PagerDuty, Discord webhooks, or Telegram bots.

  • Dashboard: Feed data into Grafana + Prometheus (via custom exporter).

  • Multi-Chain: Extend script to poll testnets or upcoming deployments.

  • Event Listening: Use PriceUpdated events for real-time push notifications.

  • Tenderly Alerts: Set up onchain monitors visually.

  • The Graph: Query historical updates via subgraph (community-maintained).

  • Chainlink Automation: Trigger upkeep if staleness detected (for auto-pausing).

Regular monitoring ensures your protocol stays safe and responsive.

Next: Building Fallback Strategies, combining IFÁ Labs with other oracles for redundancy.

Last updated

Was this helpful?