OracleLib
Title: OracleLib
Library for common oracle validation patterns.
Provides reusable functions for sequencer checks, staleness validation, and price validation.
Functions
checkSequencer
Check if the L2 sequencer is up and grace period has passed.
Skips check if sequencerFeed is address(0) (e.g., on L1 or testnets).
function checkSequencer(
AggregatorV3Interface sequencerFeed,
uint256 gracePeriod
) internal view;
Parameters
| Name | Type | Description |
|---|---|---|
sequencerFeed | AggregatorV3Interface | The Chainlink sequencer uptime feed. |
gracePeriod | uint256 | The grace period in seconds after sequencer comes back up. |
checkStaleness
Check if the oracle price is stale.
function checkStaleness(
uint256 updatedAt,
uint256 timeout
) internal view;
Parameters
| Name | Type | Description |
|---|---|---|
updatedAt | uint256 | The timestamp when the price was last updated. |
timeout | uint256 | The maximum age in seconds for a valid price. |
getValidatedPrice
Get a validated price from an oracle with staleness and sequencer checks.
Reverts on zero or negative prices to prevent operations during oracle failures.
function getValidatedPrice(
AggregatorV3Interface oracle,
AggregatorV3Interface sequencerFeed,
uint256 gracePeriod,
uint256 timeout
) internal view returns (uint256 price);
Parameters
| Name | Type | Description |
|---|---|---|
oracle | AggregatorV3Interface | The price oracle. |
sequencerFeed | AggregatorV3Interface | The sequencer uptime feed (can be address(0) to skip). |
gracePeriod | uint256 | The sequencer grace period in seconds. |
timeout | uint256 | The staleness timeout in seconds. |
Returns
| Name | Type | Description |
|---|---|---|
price | uint256 | The validated price. |
Errors
OracleLib__SequencerDown
error OracleLib__SequencerDown();
OracleLib__SequencerGracePeriod
error OracleLib__SequencerGracePeriod();
OracleLib__StalePrice
error OracleLib__StalePrice();
OracleLib__InvalidPrice
error OracleLib__InvalidPrice();