Skip to content
Lattice

OracleGuard

Git Source

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

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
answerWadint256The 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

NameTypeDescription
sequencerFeedaddressThe uptime feed (address(0) when the check is disabled).
gracePerioduint48The 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

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
oracleaddressThe oracle read for key (address(0) when unconfigured).
minAnswerint256Lowest accepted WAD answer.
maxAnswerint256Highest 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

NameTypeDescription
sequencerFeedaddressThe uptime feed for this chain.
gracePerioduint48Seconds 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 &lt;= minAnswer &lt;= maxAnswer.

function setGuardedFeed(bytes32 key, address oracle, int256 minAnswer, int256 maxAnswer) external virtual override;

Parameters

NameTypeDescription
keybytes32The feed identifier, passed through to the oracle's latestAnswer(key).
oracleaddressThe adapter (or adapter diamond) to read; the guard's own diamond when co-cut.
minAnswerint256Lowest accepted WAD answer.
maxAnswerint256Highest 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

NameTypeDescription
keybytes32The 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

NameTypeDescription
selectorsbytes