github.com/diadata-org/diadata@v1.4.593/documentation/oracle-documentation/optimism.md (about)

     1  ---
     2  title: DIA Data
     3  description: How to use request data from a DIA Oracle in your Optimism Dapp using smart contracts
     4  ---
     5  
     6  # DIA Data Oracles on Optimism
     7  
     8  ## Introduction
     9  
    10  DIA is an ecosystem for open financial data in a financial smart contract ecosystem.
    11  The target of DIA is to bring together data analysts, data providers and data users.
    12  In general, DIA provides a reliable and verifiable bridge between off-chain data from various sources and on-chain smart contracts that can be used to build a variety of financial dApps. 
    13  DApp developers who want to leverage DIA oracles can access the published data on Optimism.
    14  DIA offers data about traditional financial assets and cryptocurrencies.
    15  [Read our documentation](https://docs.diadata.org) to learn about our methodologies, API, oracles, and how to contribute.
    16  
    17  ## Supported Assets
    18  
    19  DIA supports assets from various categories to be included into the oracle. A selection of assets is listed here:
    20  
    21  Data Feed Name  |   Data Feed Query           | Data Type                           |
    22  | :-----------: | :-------------------------: | :---------------------------------: |
    23  | Bitcoin       |   BTC/USD                   |  Crypto Price                       |
    24  | Ethereum      |   ETH/USD                   |  Crypto Price                       |
    25  | USDC          |   USDC/USD                  |  Crypto Price                       |
    26  | USDT          |   USDT/USD                  |  Crypto Price                       |
    27  | DAI           |   DAI/USD                   |  Crypto price                       |
    28  | DIA Token     |   DIA/USD                   |  Crypto price                       |
    29  
    30  To retrieve data, query the oracle read function `getValue()` for an asset as listed in column "Data Field Query".
    31  The query string is case-sensitive.
    32  
    33  ## Data Access
    34  
    35  All asset prices are determined in USD according to our [methodology](https://docs.diadata.org/documentation/methodology).
    36  They are denominated in a fix comma format with 8 decimals, so you need to divide them by 1e8 to retrieve the actual value in USD.
    37  Where applicable, the oracle also provides information on circulating supply and the timestamp of data collection.
    38  The query in the smart contract is realized with the symbol of the asset.
    39  
    40  ### Smart Contract
    41  
    42  DIA data is published in the `DIAOracle` smart contract.
    43  By querying the `getValue()` function you can retrieve the requested data.
    44  You can interact with our contract in the [blockchain explorer](https://optimistic.etherscan.io/address/0x7a924305e8c00757db6131d665e5d559ead9f7cd), where you can query for any supported asset.
    45  
    46  The contract takes the symbol name of the asset as input, e.g., `BTC/USD` and returns a tuple of the timestamp of the last update and the actual value.
    47  
    48  ### Write your own DApp
    49  
    50  To access oracle data, you can either use the explorer above or write your own contract and reference the oracle.
    51  The following snippet shows how to retrieve the price of an asset (e.g. `DIA`) measured in another asset (BTC) using a wrapper smart contract.
    52  On Optimism, you can initialize the oracle address in your wrapper contract by calling `setOracleAddress()` with the address of our deployed demo contract `0x7A924305e8C00757db6131D665e5D559EAD9f7Cd`.
    53  
    54  ```
    55  pragma solidity 0.7.4;
    56  
    57  contract DIAOracle {
    58      mapping (string => uint256) public values;
    59      address oracleUpdater;
    60      
    61      event OracleUpdate(string key, uint128 value, uint128 timestamp);
    62      event UpdaterAddressChange(address newUpdater);
    63      
    64      constructor() {
    65          oracleUpdater = msg.sender;
    66      }
    67      
    68      function setValue(string memory key, uint128 value, uint128 timestamp) public {
    69          require(msg.sender == oracleUpdater);
    70          uint256 cValue = (((uint256)(value)) << 128) + timestamp;
    71          values[key] = cValue;
    72          emit OracleUpdate(key, value, timestamp);
    73      }
    74      
    75      function getValue(string memory key) public view returns (uint128, uint128) {
    76          uint256 cValue = values[key];
    77          uint128 timestamp = (uint128)(cValue % 2**128);
    78          uint128 value = (uint128)(cValue >> 128);
    79          return (value, timestamp);
    80      }
    81      
    82      function updateOracleUpdaterAddress(address newOracleUpdaterAddress) public {
    83          require(msg.sender == oracleUpdater);
    84          oracleUpdater = newOracleUpdaterAddress;
    85          emit UpdaterAddressChange(newOracleUpdaterAddress);
    86      }
    87  }
    88  
    89  contract DiaAssetBtcOracle {
    90  	DIAOracle oracle;
    91  	address owner;
    92      
    93  	constructor() public {
    94  		owner = msg.sender;
    95  	}
    96      
    97  	function setOracleAddress(address _address) public {
    98  		require(msg.sender == owner);
    99  		oracle = DIAOracle(_address);
   100  	}
   101      
   102  	function getAssetBtcRate(string asset) constant public returns (uint256) {
   103  		(uint assetPrice,) = oracle.getValue(asset);
   104  		(uint btcPrice,) = oracle.getValue("BTC/USD");
   105  		return (assetPrice / btcPrice);
   106  	}
   107      
   108  }
   109  ```
   110  
   111  #### Deployed Addresses
   112  
   113  | Chain name    |        Oracle Contract Address               | Update Frequency |
   114  | :------------ | :------------------------------------------: | :----------: |
   115  | Optimism      | `0x7A924305e8C00757db6131D665e5D559EAD9f7Cd` |    1/hour    |
   116  
   117  ### Github and Contact
   118  
   119  DIA provides a broad range of assets. You can find an overview in the DIA documentation [here](https://docs.diadata.org/documentation/oracle-documentation).
   120  All our code is open-source and can be found on our [Github repositoy](https://github.com/diadata-org/diadata).
   121  For the deployment of specific oracles (source/methodology/frequency) please [contact the DIA team](mailto:bd@diadata.org).
   122  
   123  You can follow us on [Telegram](https://t.me/DIAdata_org), [Github](https://github.com/diadata-org), and [Medium](https://medium.com/dia-insights).