|
| 1 | +!!! info "Content disclaimer" |
| 2 | + |
| 3 | + Please view the third-party content disclaimer [here](https://github.com/0xPolygon/polygon-docs/blob/main/CONTENT_DISCLAIMER.md). |
| 4 | + |
| 5 | +## Chronicle |
| 6 | + |
| 7 | +[Chronicle Protocol](https://chroniclelabs.org/) is a novel Oracle solution that has exclusively secured over $10B in assets for MakerDAO and its ecosystem since 2017. Chronicle overcomes the current limitations of transferring data on-chain by developing scalable, cost-efficient, decentralized, and verifiable Oracles, rewriting the rulebook on data transparency and accessibility. |
| 8 | + |
| 9 | +### Querying the price of MATIC using Chronicle |
| 10 | +Chronicle contracts are read-protected by a whitelist, meaning you won't be able to read them on-chain without your address being added to the whitelist. On the Testnet, users can add themselves to the whitelist through the SelfKisser contract, a process playfully referred to as "kissing" themselves. For access to production Oracles on the Mainnet, please open a support ticket on [Discord](https://discord.com/invite/CjgvJ9EspJ) in the 🆘|support channel. |
| 11 | + |
| 12 | +For the deployment addresses, please check out the [Dashboard](https://chroniclelabs.org/dashboard/oracles). |
| 13 | +```solidity |
| 14 | +// SPDX-License-Identifier: MIT |
| 15 | +pragma solidity ^0.8.16; |
| 16 | +
|
| 17 | +/** |
| 18 | + * @title OracleReader |
| 19 | + * @notice A simple contract to read from Chronicle oracles |
| 20 | + * @dev To see the full repository, visit https://github.com/chronicleprotocol/OracleReader-Example. |
| 21 | + * @dev Addresses in this contract are hardcoded for the zkEVM Testnet. |
| 22 | + * For other supported networks, check the https://chroniclelabs.org/dashboard/oracles. |
| 23 | + */ |
| 24 | +contract OracleReader { |
| 25 | + /** |
| 26 | + * @notice The Chronicle oracle to read from. |
| 27 | + * Chronicle_MATIC_USD_1 - 0x55a07a60cd9ed198B5Ba4360FF9800eBb6667388 |
| 28 | + * Network: zkEVM Testnet |
| 29 | + */ |
| 30 | +
|
| 31 | + IChronicle public chronicle = IChronicle(address(0x55a07a60cd9ed198B5Ba4360FF9800eBb6667388)); |
| 32 | +
|
| 33 | + /** |
| 34 | + * @notice The SelfKisser granting access to Chronicle oracles. |
| 35 | + * SelfKisser_1:0x0Dcc19657007713483A5cA76e6A7bbe5f56EA37d |
| 36 | + * Network: zkEVM Testnet |
| 37 | + */ |
| 38 | + ISelfKisser public selfKisser = ISelfKisser(address(0x0Dcc19657007713483A5cA76e6A7bbe5f56EA37d)); |
| 39 | +
|
| 40 | + constructor() { |
| 41 | + // Note to add address(this) to chronicle oracle's whitelist. |
| 42 | + // This allows the contract to read from the chronicle oracle. |
| 43 | + selfKisser.selfKiss(address(chronicle)); |
| 44 | + } |
| 45 | +
|
| 46 | + /** |
| 47 | + * @notice Function to read the latest data from the Chronicle oracle. |
| 48 | + * @return val The current value returned by the oracle. |
| 49 | + * @return age The timestamp of the last update from the oracle. |
| 50 | + */ |
| 51 | + function read() external view returns (uint256 val, uint256 age) { |
| 52 | + (val, age) = chronicle.readWithAge(); |
| 53 | + } |
| 54 | +} |
| 55 | +
|
| 56 | +// Copied from [chronicle-std](https://github.com/chronicleprotocol/chronicle-std/blob/main/src/IChronicle.sol). |
| 57 | +interface IChronicle { |
| 58 | + /** |
| 59 | + * @notice Returns the oracle's current value. |
| 60 | + * @dev Reverts if no value set. |
| 61 | + * @return value The oracle's current value. |
| 62 | + */ |
| 63 | + function read() external view returns (uint256 value); |
| 64 | +
|
| 65 | + /** |
| 66 | + * @notice Returns the oracle's current value and its age. |
| 67 | + * @dev Reverts if no value set. |
| 68 | + * @return value The oracle's current value using 18 decimals places. |
| 69 | + * @return age The value's age as a Unix Timestamp . |
| 70 | + * */ |
| 71 | + function readWithAge() external view returns (uint256 value, uint256 age); |
| 72 | +} |
| 73 | +
|
| 74 | +// Copied from [self-kisser](https://github.com/chronicleprotocol/self-kisser/blob/main/src/ISelfKisser.sol). |
| 75 | +interface ISelfKisser { |
| 76 | + /// @notice Kisses caller on oracle `oracle`. |
| 77 | + function selfKiss(address oracle) external; |
| 78 | +} |
| 79 | +``` |
| 80 | +### More examples |
| 81 | +For more examples on integrating Chronicle Oracles, please check the [documentation portal](https://docs.chroniclelabs.org/). |
| 82 | + |
| 83 | + |
0 commit comments