
Running Price Monitoring
Why Monitor?
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 runAdvanced Options
Recommended Tools
Last updated
Was this helpful?

