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

     1  # DIA Data Oracles on Binance Smart Chain
     2  
     3  ## Introduction
     4  
     5  DApp developers who want to leverage DIA oracles can access the published data on Binance Smart Chain. 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  |             Binance Coin              |  Crypto Price   |
    14  |                Bitcoin                |  Crypto Price  |
    15  |               Ethereum                |  Crypto Price   |
    16  |                Tether                 |  Crypto Price  |
    17  |                  XRP                  |  Crypto price   |
    18  |              Barnbridge Protocol      |  Farming Pool Data |
    19  |              yearn.finance            |  Farming Pool Data |
    20  |              CREX on Crex            |  Chart Point on Exchange |
    21  |              DAI on CurveFi            |  Chart Point on Exchange |
    22  |              WBNB on PancakeSwap           |  Chart Point on Exchange |
    23  
    24  ## Data Access
    25  
    26  All asset prices are determined in USD.
    27  Where appliccable, the oracle also provides information on circulating supply and the timestamp of data collection.
    28  The query in the smart contract is realized with the symbol of the asset.
    29  
    30  ### Smart Contract
    31  
    32  DIA data is published in the `DIAOracle` smart contract. By querying the `getCoinInfo()` function you can retrieve the requested data.
    33  
    34  It takes the name of the asset as input, e.g., `Bitcoin` and returns this struct of data:
    35  
    36  ```
    37  struct CoinInfo {
    38  	uint256 price;
    39  	uint256 supply;
    40  	uint256 lastUpdateTimestamp;
    41  	string symbol;
    42  }
    43  ```
    44  
    45  The following snippet shows how to retrieve the BTC price of an asset (e.g. `Binance Coin`) using a smart contract.
    46  
    47  ```
    48  pragma solidity ^0.4.24;
    49  
    50  contract DiaOracle {
    51  	address owner;
    52  
    53  	struct CoinInfo {
    54  		uint256 price;
    55  		uint256 supply;
    56  		uint256 lastUpdateTimestamp;
    57  		string symbol;
    58  	}
    59  
    60  	mapping(string => CoinInfo) diaOracles;
    61  
    62  	event newCoinInfo(
    63  		string name,
    64  		string symbol,
    65  		uint256 price,
    66  		uint256 supply,
    67  		uint256 lastUpdateTimestamp
    68  	);
    69  
    70  	constructor() public {
    71  		owner = msg.sender;
    72  	}
    73  
    74  	function changeOwner(address newOwner) public {
    75  		require(msg.sender == owner);
    76  		owner = newOwner;
    77  	}
    78  
    79  	function updateCoinInfo(string name, string symbol, uint256 newPrice, uint256 newSupply, uint256 newTimestamp) public {
    80  		require(msg.sender == owner);
    81  		diaOracles[name] = (CoinInfo(newPrice, newSupply, newTimestamp, symbol));
    82  		emit newCoinInfo(name, symbol, newPrice, newSupply, newTimestamp);
    83  	}
    84  
    85  	function getCoinInfo(string name) public view returns (uint256, uint256, uint256, string) {
    86  		return (
    87  			diaOracles[name].price,
    88  			diaOracles[name].supply,
    89  			diaOracles[name].lastUpdateTimestamp,
    90  			diaOracles[name].symbol
    91  		);
    92  	}
    93  }
    94  
    95  contract DiaAssetBtcOracle {
    96  	DiaOracle oracle;
    97  	address owner;
    98      
    99  	constructor() public {
   100  		owner = msg.sender;
   101  	}
   102      
   103  	function setOracleAddress(address _address) public {
   104  		require(msg.sender == owner);
   105  		oracle = DiaOracle(_address);
   106  	}
   107      
   108  	function getAssetEurRate(string asset) constant public returns (uint256) {
   109  		(uint assetPrice,,,) = oracle.getCoinInfo(asset);
   110  		(uint btcPrice,,,) = oracle.getCoinInfo("Bitcoin");
   111  		return (assetPrice * 100000 / btcPrice);
   112  	}
   113      
   114  }
   115  ```
   116  
   117  #### Deployed Addresses
   118  
   119  | Chain name    |        Oracle Contract Address          | Update Frequency |
   120  | :------------ | :------------------------------------------: | :----------: |
   121  | BSC: Testnet | `0xf35bEE4B6727D2D1c9167C5fB4D51855D6bB693c` |    1/day    |
   122  | BSC: Mainnet | `0xf35bEE4B6727D2D1c9167C5fB4D51855D6bB693c` |    1/day    |
   123  
   124  The full documentation of the DIA oracle is located [here](https://docs.diadata.org/documentation/oracle-documentation).