EVM Oracle

This page contains an overview over the different smart contract interfaces deployed by DIA.

DIA uses three different smart contracts for its oracles, depending on the use cases for each deployment. Its definitions are listed here. To learn how to access a foreign smart contract (such as our oracles) from your own smart contract, have a look at this tutorial.

You can request a custom oracle for your specific use case by submitting a CDR. Find out more here:

Request an oracle

DIA Key-Value Oracle Contract V2

pragma solidity 0.7.4;

contract DIAOracleV2 {
    mapping (string => uint256) public values;
    address oracleUpdater;
    
    event OracleUpdate(string key, uint128 value, uint128 timestamp);
    event UpdaterAddressChange(address newUpdater);
    
    constructor() {
        oracleUpdater = msg.sender;
    }
    
    function setValue(string memory key, uint128 value, uint128 timestamp) public {
        require(msg.sender == oracleUpdater);
        uint256 cValue = (((uint256)(value)) << 128) + timestamp;
        values[key] = cValue;
        emit OracleUpdate(key, value, timestamp);
    }
    
    function getValue(string memory key) external view returns (uint128, uint128) {
        uint256 cValue = values[key];
        uint128 timestamp = (uint128)(cValue % 2**128);
        uint128 value = (uint128)(cValue >> 128);
        return (value, timestamp);
    }
    
    function updateOracleUpdaterAddress(address newOracleUpdaterAddress) public {
        require(msg.sender == oracleUpdater);
        oracleUpdater = newOracleUpdaterAddress;
        emit UpdaterAddressChange(newOracleUpdaterAddress);
    }
}

Key/Value oracle can be added as an interface in other contracts using all current Solidity versions with the visibility change of the getValue() function from public to external.

The smart contract is audited and the audit can be found here:

To access the key-value oracle, you first need to know the key of the data you are interested in. On querying getValue(key), the oracle returns the latest value for that key and the timestamp of its last update. This key is a string and each update emits an event containing the key of the updated value.

Find out more about accessing the oracles with code samples and libraries in the following page:

Access the Oracle

The response value is an integer in a fix comma format and the timestamp associated with each value is a Unix timestamp for the UTC timezone.

Gas Estimation

All DIA oracles use the go-ethereum gas estimation to estimate the gas costs for an update contract call. To ensure timely delivery of the transaction, the gas estimate is scaled to 110% of the original estimate.

Last updated