OracleGuard
Inherits: IOracleGuard
Title: OracleGuard
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Chainlink (https://docs.chain.link/data-feeds/l2-sequencer-feeds)
Diamond facet that serves guarded price reads over any Lattice price adapter: an opt-in Chainlink L2 sequencer-uptime check with a grace period, plus per-key WAD bounds.
Stateless delegator — all logic and storage live in OracleGuardLib. Its selectors do not overlap the adapters', so it can be cut next to an adapter (reading its own diamond) or into a separate diamond.
Notes:
- lattice-version: 0.5.0
- lattice-source: Chainlink
Functions
guardedAnswer
Returns the oracle's WAD answer for key after the sequencer and bounds checks.
Reverts with the oracle's own error when its checks fail, and with this interface's errors when the guard's checks fail.
function guardedAnswer(bytes32 key) external view virtual override returns (int256 answerWad);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier. |
Returns
| Name | Type | Description |
|---|---|---|
| answerWad | int256 | The checked price scaled to 1e18. |
checkSequencerUptime
Reverts unless the sequencer is up and past its grace period. No-op while no feed is set.
For integrators that read something other than guardedAnswer (raw reads, TWAPs) on an L2.
function checkSequencerUptime() external view virtual override;getSequencerConfig
Returns the sequencer-uptime configuration.
function getSequencerConfig() external view virtual override returns (address sequencerFeed, uint48 gracePeriod);Returns
| Name | Type | Description |
|---|---|---|
| sequencerFeed | address | The uptime feed (address(0) when the check is disabled). |
| gracePeriod | uint48 | The grace period in seconds. |
getGuardedFeed
Returns the guard configuration of key.
function getGuardedFeed(bytes32 key)
external
view
virtual
override
returns (address oracle, int256 minAnswer, int256 maxAnswer);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier. |
Returns
| Name | Type | Description |
|---|---|---|
| oracle | address | The oracle read for key (address(0) when unconfigured). |
| minAnswer | int256 | Lowest accepted WAD answer. |
| maxAnswer | int256 | Highest accepted WAD answer. |
setSequencerConfig
Sets the Chainlink L2 sequencer-uptime feed and the grace period after a restart.
Caller must hold DEFAULT_ADMIN_ROLE. sequencerFeed == address(0) disables the check; a non-zero
feed requires a non-zero gracePeriod (Chainlink's example uses 3600 seconds).
function setSequencerConfig(address sequencerFeed, uint48 gracePeriod) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| sequencerFeed | address | The uptime feed for this chain. |
| gracePeriod | uint48 | Seconds after a restart during which reads revert. |
setGuardedFeed
Configures key: the oracle to read and the accepted WAD range.
Caller must hold DEFAULT_ADMIN_ROLE. oracle must be non-zero. (0, 0) disables the bounds;
otherwise 0 <= minAnswer <= maxAnswer.
function setGuardedFeed(bytes32 key, address oracle, int256 minAnswer, int256 maxAnswer) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier, passed through to the oracle's latestAnswer(key). |
| oracle | address | The adapter (or adapter diamond) to read; the guard's own diamond when co-cut. |
| minAnswer | int256 | Lowest accepted WAD answer. |
| maxAnswer | int256 | Highest accepted WAD answer. |
removeGuardedFeed
Removes the guard configuration of key; guardedAnswer then reverts for it.
Caller must hold DEFAULT_ADMIN_ROLE.
function removeGuardedFeed(bytes32 key) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier. |
exportSelectors
ERC-8153 selector export: this facet's cuttable selectors, tightly packed (4 bytes each).
Excludes exportSelectors() itself (0x0ef22643) - it is never cut into a diamond. Order matches
forge inspect OracleGuard methodIdentifiers (alphabetical by signature); kept in exact parity by
ExportSelectorsParityTest. Chunks:
checkSequencerUptime() 0x6244363c
getGuardedFeed(bytes32) 0x8ea079a7
getSequencerConfig() 0xb4eee64e
guardedAnswer(bytes32) 0x12ac8379
removeGuardedFeed(bytes32) 0x11bdc3e7
setGuardedFeed(bytes32,address,int256,int256) 0x20c84cb8
setSequencerConfig(address,uint48) 0x487205e4
function exportSelectors() external pure virtual returns (bytes memory selectors);Returns
| Name | Type | Description |
|---|---|---|
| selectors | bytes |