Partner Workshop: DIA
Ecosystem Price Oracles, powered by DIA
Introduction to DIA Oracles
DIA is a cross-chain oracle provider that sources granular market data from diverse exchanges, including CEXs, DEXs, and NFT marketplaces. Its data sourcing is thorough, enabling unparalleled transparency and customizability for resilient price feeds for 20,000+ assets. Its versatile data processing and delivery ensures adaptability and reliability for any decentralized application.
Usage of DIA Oracles on CrossFi
dApps building on CrossFi can utilize DIA oracles to obtain up-to-date asset price information. These deployed oracles are suitable for use in production environments. They come with a list of supported assets and settings. However, if dApps require a custom oracle with a different set of assets and configurations, they should contact DIA on Telegram.
Token Price Oracle
Deployed contracts
Access the oracles in the smart contracts below:
CrossFi Testnet Oracle: 0x33df80cdf0c9ff686261b11263d9f4a3ccc3d07f
Included price feeds + data sources
The CrossFi oracle includes the following price feeds:
Learn more about DIA’s data sourcing and data computation architecture.
Oracle configuration settings
Oracle specifications:
Methodology: VWAPIR
The final price point for each asset is calculated by computing the assets' trade information across multiple DEXs and CEXs. This is done using a Volume Weighted Average Price with Interquartile Range (VWAPIR) methodology. Learn more about VWAPIR.
Update frequency: 24-hour heartbeat + 0.5% deviation threshold
A consistent heartbeat refreshes all asset prices every 2 minutes. Moreover, if the oracle detects a price fluctuation exceeding 0.5% from the last published rate, it promptly sends an update on-chain.
How to access DIA oracles?
Here is an example of how to access a price value on DIA oracles:
Access your custom oracle smart contract on CrossFi.
Call getValue(pair_name) with pair_name being the full pair name such as BTC/USD. You can use the "Read" section on the explorer to execute this call.
The response of the call contains two values:
The current asset price in USD with a fix-comma notation of 8 decimals.
The UNIX timestamp of the last oracle update.
You can find DIA's oracle integration samples in Solidity and Vyper languages by visiting:
→ Access the Oracle | DIA Documentation
Randomness Oracle
Deployed contracts
Access the oracles in the smart contracts below:
CrossFi Testnet Oracle: 0xad19b5b3a0bf2bacf028ed6cc9e3fc153cb405b6
How to access the oracle
Anyone can access published random values via round ID.
{
"round": 1597683,
"randomness": "24138936fcbf7fc3951c928158be6998cee3af622142d0790333608d17a5c5f6",
"signature": "8c04905c0adf34f1fb007915d9ccc7d07b97305fc63952726f9367c87f36ab687c5e190c151f6ac4d760a9e009fc54230adb8513885449d649a229bc727be9ff347bdbce1c609cebf993b6ae57133fbcf23f96b15dbd3510cb5f2ade6b30b647",
"previous_signature": "ada42197a2db89866da4c44348f77f7868e41e961ec32e636b912d43c625386afae9e54944ac573047dbd227ee495b52059586c8d8cd0edfe18cc15ca0666a66651da1d62b12af2d0fac19735bed9298690a593571965c3ad7c7b11947e76ec0"
}
The DIA randomness smart contract is structured as follows:
pragma solidity ^0.8.0;
contract DIARandomOracle {
struct Random {
string randomness;
string signature;
string previousSignature;
}
mapping (uint256 => Random) public values;
uint256 public lastRound = 0;
address public oracleUpdater;
event OracleUpdate(string key, uint128 value, uint128 timestamp);
event UpdaterAddressChange(address newUpdater);
constructor() {
oracleUpdater = msg.sender;
}
function setRandomValue(uint256 _round, string memory _randomness, string memory _signature, string memory _previousSignature) public {
require(msg.sender == oracleUpdater,"not a updater");
require(lastRound<_round, "old round");
lastRound = _round;
values[_round] = Random(_randomness, _signature, _previousSignature);
}
function getValue(uint256 _round) external view returns (Random memory) {
return values[_round];
}
function updateOracleUpdaterAddress(address newOracleUpdaterAddress) public {
require(msg.sender == oracleUpdater,"not a updater");
oracleUpdater = newOracleUpdaterAddress;
emit UpdaterAddressChange(newOracleUpdaterAddress);
}
function getRandomValueFromRound(uint256 _round) external view returns (string memory) {
return values[_round].randomness;
}
function getRandomValueFromRoundWithSignature(uint256 _round) external view returns (Random memory) {
return values[_round];
}
function getLastRound() public view returns(uint256) {
return lastRound;
}
}
Users can call getLastRound() to obtain the ID of the latest published round. To obtain the randomness of a certain round, users can call getRandomValueFromRound(uint256 _round) using the obtaines round ID.
The signature can also be requested by calling getRandomValueFromRoundWithSignature(uint256 _round).
Please be aware that you should always let all inputs commit before any randomness is used in a later round. For example, if you build a lottery, only call randomness after the last participant has committed their stake. To show this in an example, we will build a simple dice game.
Make sure to never directly query the latest randomness value, otherwise the miner and the randomness oracle can interfere with the result. Always commit values before the randomness is used in a later round.
Support
For developer assistance, connect with the DIA team directly on Discord or Telegram.
Developers seeking other specialized, production-grade oracle with tailored price feeds and configurations can initiate the request by contacting the DIA BD Team via Telegram.
Last updated