Contract Implementation Example of IChronicle
info
You can find an example of our IChronicle.sol interface here . Please see the comments corresponding to each function to better understand the utility it provides.
Example Contract
The Example contract is a basic implementation of the IChronicle interface. It demonstrates basic interaction with an oracle interface defined by IChronicle. The contract has no protections, and should only be used for learning purposes.
Key Features​
1. State Variables:
2. Immutable Variables:
3. Functions:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
import {IChronicle} from "chronicle-std/IChronicle.sol";
// This contract has ZERO protections, never use for anything other than learning!
contract Example is IChronicle {
uint private _val;
uint32 private _age;
/// @inheritdoc IChronicle
/// The Oracle identifier; mostly asset pairs, e.g. ETH/USD
bytes32 public immutable wat;
constructor(bytes32 _wat) {
wat = _wat;
}
/// @inheritdoc IChronicle
function read() external view returns (uint) {
return _val;
}
/// @inheritdoc IChronicle
function tryRead() external view returns (bool, uint) {
uint val = _val;
return (val != 0, val);
}
/// @inheritdoc IChronicle
/// @return value The oracle's current value.
/// @return age The value's age.
function readWithAge() external view returns (uint, uint) {
uint val = _val;
uint age = _age;
require(val != 0);
return (val, age);
}
/// @inheritdoc IChronicle
function tryReadWithAge() external view returns (bool, uint, uint)
{
uint val = _val;
uint age = _age;
return val != 0 ? (true, val, age) : (false, 0, 0);
}
function poke(uint val, uint32 age) external {
_val = val;
_age = age;
}
}