Integrating DIA Oracles on Somnia
Overview
DIA Oracles provide secure, customizable, and decentralized price feeds that can be integrated into smart contracts on the Somnia Testnet. This guide will walk you through how to access on-chain price data, understand the oracle’s functionality, and integrate it into your Solidity Smart Contracts.
Oracle Details
Contracts on Somnia Testnet
DIA Oracle contract address:
Oracle Configuration
Pricing Methodology: MAIR
Deviation Threshold: 0.5% (Triggers price update if exceeded)
Refresh Frequency: Every 120 seconds
Heartbeat: Forced price update every 24 hours
Supported Asset Feeds
USDT
0x67d2C2a87A17b7267a6DBb1A59575C0E9A1D1c3e
USDC
0x235266D5ca6f19F134421C49834C108b32C2124e
BTC
0x4803db1ca3A1DA49c3DB991e1c390321c20e1f21
ARB
0x74952812B6a9e4f826b2969C6D189c4425CBc19B
SOL
0xD5Ea6C434582F827303423dA21729bEa4F87D519
How the Oracle Works
DIA oracles continuously fetch and push asset prices on-chain using an oracleUpdater, which operates within the DIAOracleV2
contract. The oracle uses predefined update intervals and deviation thresholds to determine when price updates are necessary.
Each asset price feed has an adapter contract, allowing access through the AggregatorV3Interface. You can use the methods getRoundData and latestRoundData to fetch pricing information. Learn more here.
Accessing Oracle Data
Fetching Prices On-Chain (Solidity)
To consume price data, you must invoke the getValue
method on the DIAOracleV2 contract. Below is an example Solidity contract demonstrating how to retrieve price data from the oracle.
Calling
exampleGetPrice("BTC/USD")
returns the latest BTC price in USD with 8 decimal places.Example: A returned value of 9601458065403 represents $96,014.58065403.
Example: Using DIA Oracle in RemixIDE
The following contract provides an integration example in RemixIDE, retrieving prices and verifying price age.
Glossary
Deviation
Percentage threshold that triggers a price update when exceeded.
Refresh Frequency
Time interval for checking and updating prices if conditions are met.
Trade Window
Time interval used to aggregate trades for price calculation.
Heartbeat
Forced price update at a fixed interval.
Support
If you need further assistance integrating DIA Oracles, reach out through DIA’s official documentation and ask your questions in the #dev-support channel on Discord.
Developers can build secure, real-time, and on-chain financial applications with reliable pricing data by integrating DIA Oracles on Somnia.
Last updated