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
Gas Wallets
The gas wallet is used for pushing data to your contracts. To ensure uninterrupted Oracle operation, please maintain sufficient funds in the gas wallet. You can monitor the wallets below to ensure they remain adequately funded at all times.
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
Mainnet
Asset Ticker
Adapter Address
Asset Markets Overview
Testnet
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.
Using the Solidity Library
DIA has a dedicated Solidity library to facilitate the integration of DIA oracles in your own contracts. The library consists of two functions, getPrice
and getPriceIfNotOlderThan
.
Access the library
import { DIAOracleLib } from "./libraries/DIAOracleLib.sol";
getPrice
getPrice
function getPrice(
address oracle,
string memory key
)
public
view
returns (uint128 latestPrice, uint128 timestampOflatestPrice);
Returns the price of a specified asset along with the update timestamp.
getPriceIfNotOlderThan
getPriceIfNotOlderThan
function getPriceIfNotOlderThan(
address oracle,
string memory key,
uint128 maxTimePassed
)
public
view
returns (uint128 price, bool inTime)
{
Checks if the Oracle price is older than maxTimePassed
Using DIAOracleV2 Interface
The following contract provides an integration example of retrieving prices and verifying price age.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
interface IDIAOracleV2 {
function getValue(string memory) external view returns (uint128,
uint128);
}
contract DIAOracleSample {
address diaOracle;
constructor(address _oracle) {
diaOracle = _oracle;
}
function getPrice(string memory key)
external
view
returns (
uint128 latestPrice,
uint128 timestampOflatestPrice
) {
(latestPrice, timestampOflatestPrice) =
IDIAOracleV2(diaOracle).getValue(key);
}
}
Adapter contracts
To consume price data from DIA Oracle, you can use the adapter Smart Contract located at the adapter address for each asset. This will allow you to access the same methods on the AggregatorV3Interface
such as getRoundData
& latestRoundData
. You can learn more here.
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