ChronicleAdapterLib
Title: ChronicleAdapterLib
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Chronicle (https://github.com/chronicleprotocol)
Library wrapping Chronicle oracle feeds with per-feed staleness configuration, exposing the shared IPriceOracleReader read surface.
Three-layer pattern: this library holds the logic + namespaced storage; the stateless
ChronicleAdapter facet forwards to it. Chronicle values are already 18-decimals (WAD), so
normalization only casts uint256 -> int256 (no rescaling); reads validate zero value, future
age, and staleness on-chain. Chronicle feeds are toll-gated (Schnorr-signed): the adapter contract
must be kissed by the oracle operator before reads will succeed.
Functions
chronicleAdapterStorage
function chronicleAdapterStorage() internal pure returns (ChronicleAdapterStorage storage $);Returns
| Name | Type | Description |
|---|---|---|
| $ | ChronicleAdapterStorage |
__ChronicleAdapter_init
Registers the IChronicleAdapter ERC-165 interface.
Must be called between preInitializer / postInitializer.
function __ChronicleAdapter_init() internal;registerInterface
Writes true to the ERC-165 map slot for IChronicleAdapter.
function registerInterface() internal;getFeed
function getFeed(bytes32 key) internal view returns (address chronicle, uint48 maxStaleness);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| chronicle | address | |
| maxStaleness | uint48 |
readWithAge
Returns the validated raw Chronicle value and the timestamp it was last written on-chain.
Validates: registration, non-zero value, future-age guard, and staleness. Chronicle values are uint256 WAD; zero is the invalid-data sentinel (price can never be 0).
function readWithAge(bytes32 key) internal view returns (uint256 value, uint256 age);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| value | uint256 | |
| age | uint256 |
latestAnswer
Returns the latest Chronicle value normalized to 18 decimals (WAD).
Chronicle values are already 1e18-scaled, so this only casts uint256 -> int256. A value
>= 2^255 would wrap to a negative int256, so it is rejected rather than cast.
function latestAnswer(bytes32 key) internal view returns (int256 answerWad);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| answerWad | int256 |
registerFeed
function registerFeed(bytes32 key, address chronicle, uint48 maxStaleness) internal;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | |
| chronicle | address | |
| maxStaleness | uint48 |
unregisterFeed
function unregisterFeed(bytes32 key) internal;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |