Usage

The Oracle maintains updates as a mapping, where each key maps to a Data struct containing the latest timestamp and value. The updates mapping is a key-value store where:
  • Key: A unique identifier, typically a string, representing the asset or data type (e.g., DIA/USD, BTC/USD).
  • Value: A Data struct containing:
    • key: The identifier of the data entry (redundant for reference but useful for integrity checks).
    • timestamp: The timestamp of the latest update.
    • value: The most recent value associated with the key.
Here’s an example of a DIAOracleSample contract that consumes the BTC/USD price feed:
pragma solidity ^0.8.13;

import { PushOracleReceiver } from "@dia-data/contracts-spectra/PushOracleReceiver.sol";

contract DIAOracleSample {

    PushOracleReceiver public diaOracle;
    string public key = "BTC/USD";

    constructor(address _oracle) {
        diaOracle = PushOracleReceiver(payable(_oracle));
    }

    function getPrice() 
    external 
    view
    returns (
        uint128 timestampOflatestPrice, 
        uint128 latestPrice
    ) {
        (timestampOflatestPrice, latestPrice) =   
                 diaOracle.updates(key); 
    }
}
To deploy the contract, pass the oracle address on the destination chain from the list of demo oracles. As an example, if you want to access the oracle on Ethereum Sepolia, you’ll pass the Push Oracle address: 0x9bb71344Ed950F9cFD85EE1C7258553B01d95FA0 to the constructor above. You can also change the key to any of the supported assets (e.g. DIA/USD).