Skip to content
Lattice

OracleGuardLib

Git Source

Title: OracleGuardLib

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Chainlink (https://docs.chain.link/data-feeds/l2-sequencer-feeds)

Library behind the OracleGuard facet: an opt-in L2 sequencer-uptime check and per-key WAD bounds applied on top of any IPriceOracleReader adapter. See IOracleGuard for the full semantics.

Functions

oracleGuardStorage

Returns the ERC-7201 storage struct for OracleGuard.

function oracleGuardStorage() internal pure returns (OracleGuardStorage storage $);

Returns

NameTypeDescription
$OracleGuardStorage

__OracleGuard_init

Registers the IOracleGuard ERC-165 interface.

Must be called between preInitializer / postInitializer.

function __OracleGuard_init() internal;

registerInterface

Writes true to the ERC-165 map slot for IOracleGuard.

function registerInterface() internal;

guardedAnswer

Returns the oracle's WAD answer for key after the sequencer and bounds checks.

function guardedAnswer(bytes32 key) internal view 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.

function checkSequencerUptime() internal view;

getSequencerConfig

Returns the sequencer-uptime configuration.

function getSequencerConfig() internal view returns (address sequencerFeed, uint48 gracePeriod);

Returns

NameTypeDescription
sequencerFeedaddress
gracePerioduint48

getGuardedFeed

Returns the guard configuration of key.

function getGuardedFeed(bytes32 key) internal view returns (address oracle, int256 minAnswer, int256 maxAnswer);

Parameters

NameTypeDescription
keybytes32

Returns

NameTypeDescription
oracleaddress
minAnswerint256
maxAnswerint256

setSequencerConfig

Sets the sequencer-uptime feed and grace period. address(0) disables the check.

Caller must hold DEFAULT_ADMIN_ROLE. A non-zero feed requires a non-zero grace period.

function setSequencerConfig(address sequencerFeed, uint48 gracePeriod) internal;

Parameters

NameTypeDescription
sequencerFeedaddress
gracePerioduint48

setGuardedFeed

Configures the oracle and WAD bounds of key.

Caller must hold DEFAULT_ADMIN_ROLE. Requires a non-zero oracle and 0 &lt;= minAnswer &lt;= maxAnswer.

function setGuardedFeed(bytes32 key, address oracle, int256 minAnswer, int256 maxAnswer) internal;

Parameters

NameTypeDescription
keybytes32
oracleaddress
minAnswerint256
maxAnswerint256

removeGuardedFeed

Removes the guard configuration of key.

Caller must hold DEFAULT_ADMIN_ROLE.

function removeGuardedFeed(bytes32 key) internal;

Parameters

NameTypeDescription
keybytes32