github.com/diadata-org/diadata@v1.4.593/documentation/oracle-documentation/xdai.md (about) 1 # DIA Data Oracles on xDai 2 3 ## Introduction 4 5 DApp developers who want to leverage DIA oracles can access the published data on xDai. DIA offers cryptocurrency and data about traditional financial assets. 6 7 ## Supported Assets 8 9 DIA supports assets from various categories to be included into the oracle. A selection of assets is listed here: 10 11 | Data Feed Name | Data Type | 12 | :-----------------------------------: | :----: | 13 | Bitcoin | Crypto Price | 14 | Ethereum | Crypto Price | 15 | Tether | Crypto Price | 16 | XRP | Crypto price | 17 | Barnbridge Protocol | Farming Pool Data | 18 | yearn.finance | Farming Pool Data | 19 20 ## Data Access 21 22 All asset prices are determined in USD with 5 decimals. 23 Where appliccable, the oracle also provides information on circulating supply and the timestamp of data collection. 24 The query in the smart contract is realized with the symbol of the asset. 25 26 ### Smart Contract 27 28 DIA data is published in the `DIAOracle` smart contract. By querying the `getCoinInfo()` function you can retrieve the requested data. 29 30 It takes the name of the asset as input, e.g., `Bitcoin` and returns this struct of data: 31 32 ``` 33 struct CoinInfo { 34 uint256 price; 35 uint256 supply; 36 uint256 lastUpdateTimestamp; 37 string symbol; 38 } 39 ``` 40 41 The following snippet shows how to retrieve the BTC price of an asset (e.g. `Ethereum`) using a smart contract. 42 43 ``` 44 pragma solidity ^0.4.24; 45 46 contract DiaOracle { 47 address owner; 48 49 struct CoinInfo { 50 uint256 price; 51 uint256 supply; 52 uint256 lastUpdateTimestamp; 53 string symbol; 54 } 55 56 mapping(string => CoinInfo) diaOracles; 57 58 event newCoinInfo( 59 string name, 60 string symbol, 61 uint256 price, 62 uint256 supply, 63 uint256 lastUpdateTimestamp 64 ); 65 66 constructor() public { 67 owner = msg.sender; 68 } 69 70 function changeOwner(address newOwner) public { 71 require(msg.sender == owner); 72 owner = newOwner; 73 } 74 75 function updateCoinInfo(string name, string symbol, uint256 newPrice, uint256 newSupply, uint256 newTimestamp) public { 76 require(msg.sender == owner); 77 diaOracles[name] = (CoinInfo(newPrice, newSupply, newTimestamp, symbol)); 78 emit newCoinInfo(name, symbol, newPrice, newSupply, newTimestamp); 79 } 80 81 function getCoinInfo(string name) public view returns (uint256, uint256, uint256, string) { 82 return ( 83 diaOracles[name].price, 84 diaOracles[name].supply, 85 diaOracles[name].lastUpdateTimestamp, 86 diaOracles[name].symbol 87 ); 88 } 89 } 90 91 contract DiaAssetBtcOracle { 92 DiaOracle oracle; 93 address owner; 94 95 constructor() public { 96 owner = msg.sender; 97 } 98 99 function setOracleAddress(address _address) public { 100 require(msg.sender == owner); 101 oracle = DiaOracle(_address); 102 } 103 104 function getAssetBtcRate(string asset) constant public returns (uint256) { 105 (uint assetPrice,,,) = oracle.getCoinInfo(asset); 106 (uint btcPrice,,,) = oracle.getCoinInfo("Bitcoin"); 107 return (assetPrice / btcPrice); 108 } 109 110 } 111 ``` 112 113 #### Deployed Addresses 114 115 | Chain name | Oracle Contract Address | Update Frequency | 116 | :------------ | :------------------------------------------: | :----------: | 117 | xDai Chain | `0xcF2374824C2Ff84F07Ff4adcA074dfeDDa5C7569` | 1/day | 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 For the deployment of specific oracles (source/methodology/frequency) please [contact the DIA team](mailto:bd@diadata.org).