Using DIAOracleV2 Interface
The following is an example of how to retrieve price value from a standard DIA oracle. For the purpose of this example, we will be using the following demo oracle on Ethereum: 0xCD5F…f3cB.1
Access any DIA oracle smart contract.
2
Call
getValue(pair_name)
with pair_name
being the full pair name such as BTC/USD
. You can use the “Read” section on Etherscan to execute this call.3
The response of the call contains four values:
- The current asset’s price in USD with a fix-comma notation of 8 decimals.
- The UNIX timestamp of the last oracle update.
Solidity integration example
Using 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
Methods
getPrice
Name | Type | Description |
---|---|---|
oracle | address | Address of the oracle that we want to use |
key | string | The asset that we want to use e.g. “ETH/USD” |
Name | Type | Description |
---|---|---|
latestPrice | uint128 | Price of the specified asset returned by the DIAOracle |
timestampOflatestPrice | uint128 | The update timestamp of the latest price |
getPriceIfNotOlderThan
maxTimePassed
Parameters:
Name | Type | Description |
---|---|---|
oracle | address | Address of the oracle that we want to use |
key | string | The asset that we want to use e.g. “ETH/USD” |
maxTimePassed | uint128 | The maximum acceptable time passed in seconds since the the price was updated |
Name | Type | Description |
---|---|---|
price | uint128 | Price of the specified asset returned by the DIAOracle |
inTime | bool | A boolian that is true if the price was updated at most maxTimePassed seconds ago, otherwise false |