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

     1  ---
     2  title: DIA Data
     3  description: How to use request data from a DIA Oracle in your Celo Dapp using smart contracts
     4  ---
     5  
     6  # DIA Data Oracles on Celo
     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 Celo.
    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  | DOT Token     |   DOT                       |  Crypto Price                       |
    24  | Bitcoin       |   Bitcoin                   |  Crypto Price                       |
    25  | Ethereum      |   Ethereum                  |  Crypto Price                       |
    26  | USDT          |   Tether                    |  Crypto Price                       |
    27  | XRP           |   Ripple                    |  Crypto price                       |
    28  | Barnbridge    |   BARNBRIDGE                |  Farming Pool Rate: Stablecoin Pool |
    29  | yearn.finance |   YFI                       |  Farming Pool Rate: WETH Pool       |
    30  
    31  To retrieve data, query the oracle for an asset as listed in column "Data Field Query".
    32  The query string is case-sensitive.
    33  
    34  ## Data Access
    35  
    36  All asset prices are determined in USD according to our [methodology](https://docs.diadata.org/documentation/methodology).
    37  They are denominated in a fix comma format with 5 decimals, so you need to divide them by 100000 to retrieve the actual value in USD.
    38  Where applicable, the oracle also provides information on circulating supply and the timestamp of data collection.
    39  The query in the smart contract is realized with the symbol of the asset.
    40  
    41  ### Smart Contract
    42  
    43  DIA data is published in the `DIAOracle` smart contract.
    44  By querying the `getCoinInfo()` function you can retrieve the requested data.
    45  You can interact with our contract in the [blockchain explorer](https://explorer.celo.org/address/0xCd8E18890E416Aa7ab09aa793b406C187747C687), where you can query for any supported asset.
    46  
    47  The contract takes the full name of the asset as input, e.g., `Bitcoin` and returns this struct of data:
    48  
    49  ```
    50  struct CoinInfo {
    51  	uint256 price;
    52  	uint256 supply;
    53  	uint256 lastUpdateTimestamp;
    54  	string symbol;
    55  }
    56  ```
    57  
    58  ### Write your own DApp
    59  
    60  To access oracle data, you can either use the explorer above or write your own contract and reference the oracle.
    61  The following snippet shows how to retrieve the price of an asset (e.g. `DOT`) measured in another asset (BTC) using a wrapper smart contract.
    62  On Celo, you can initialize the oracle address in your wrapper contract by calling `setOracleAddress()` with the address of our deployed demo contract `0xCd8E18890E416Aa7ab09aa793b406C187747C687`.
    63  
    64  ```
    65  pragma solidity ^0.4.24;
    66  
    67  contract DiaOracle {
    68  	address owner;
    69  
    70  	struct CoinInfo {
    71  		uint256 price;
    72  		uint256 supply;
    73  		uint256 lastUpdateTimestamp;
    74  		string symbol;
    75  	}
    76  
    77  	mapping(string => CoinInfo) diaOracles;
    78  
    79  	event newCoinInfo(
    80  		string name,
    81  		string symbol,
    82  		uint256 price,
    83  		uint256 supply,
    84  		uint256 lastUpdateTimestamp
    85  	);
    86  
    87  	constructor() public {
    88  		owner = msg.sender;
    89  	}
    90  
    91  	function changeOwner(address newOwner) public {
    92  		require(msg.sender == owner);
    93  		owner = newOwner;
    94  	}
    95  
    96  	function updateCoinInfo(string name, string symbol, uint256 newPrice, uint256 newSupply, uint256 newTimestamp) public {
    97  		require(msg.sender == owner);
    98  		diaOracles[name] = (CoinInfo(newPrice, newSupply, newTimestamp, symbol));
    99  		emit newCoinInfo(name, symbol, newPrice, newSupply, newTimestamp);
   100  	}
   101  
   102  	function getCoinInfo(string name) public view returns (uint256, uint256, uint256, string) {
   103  		return (
   104  			diaOracles[name].price,
   105  			diaOracles[name].supply,
   106  			diaOracles[name].lastUpdateTimestamp,
   107  			diaOracles[name].symbol
   108  		);
   109  	}
   110  }
   111  
   112  contract DiaAssetBtcOracle {
   113  	DiaOracle oracle;
   114  	address owner;
   115      
   116  	constructor() public {
   117  		owner = msg.sender;
   118  	}
   119      
   120  	function setOracleAddress(address _address) public {
   121  		require(msg.sender == owner);
   122  		oracle = DiaOracle(_address);
   123  	}
   124      
   125  	function getAssetBtcRate(string asset) constant public returns (uint256) {
   126  		(uint assetPrice,,,) = oracle.getCoinInfo(asset);
   127  		(uint btcPrice,,,) = oracle.getCoinInfo("Bitcoin");
   128  		return (assetPrice / btcPrice);
   129  	}
   130      
   131  }
   132  ```
   133  
   134  #### Deployed Addresses
   135  
   136  | Chain name    |        Oracle Contract Address          | Update Frequency |
   137  | :------------ | :------------------------------------------: | :----------: |
   138  | Celo | `0xCd8E18890E416Aa7ab09aa793b406C187747C687` |    1/day    |
   139  
   140  ### Github and Contact
   141  
   142  DIA provides a broad range of assets. You can find an overview in the DIA documentation [here](https://docs.diadata.org/documentation/oracle-documentation).
   143  All our code is open-source and can be found on our [Github repositoy](https://github.com/diadata-org/diadata).
   144  For the deployment of specific oracles (source/methodology/frequency) please [contact the DIA team](mailto:bd@diadata.org).
   145  
   146  You can follow us on [Telegram](https://t.me/DIAdata_org), [Github](https://github.com/diadata-org), and [Medium](https://medium.com/dia-insights).