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

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