Skip to main content

OracleWithValidation

Git Source - Generated with forge doc

Inherits: IOracleWithValidation, Ownable2Step

Title: OracleWithValidation

Oracle that checks the deviation between a primary and a validation oracle.

Conforms to the Morpho IOracle interface.

The primary oracle is always used for the price, but price() reverts if the deviation from the validation oracle exceeds the threshold.

The deployer must ensure VALIDATION_ORACLE returns a well-formed (uint256) payload. Malformed returndata (length != 32) bypasses try/catch and reverts price(); excess returndata is truncated to the first 32 bytes.

Pausing validation and then renouncing ownership permanently locks the wrapper into primary-only mode. To make the validated configuration immutable, renounce ownership while validationCheckPaused is false.

The deviation is scaled by the primary price, so a threshold d allows up to d / (1 - d) overpricing relative to the validation oracle (e.g. 5% configured allows ~5.26% effective).

A validation oracle that signals failure by returning 0 instead of reverting is not caught by the try/catch: against a nonzero primary price the deviation check fails and price() reverts with ExcessiveOracleDeviation even when REVERT_ON_VALIDATION_ORACLE_FAILURE is false.

price() can return 0 to Morpho Markets: this happens when the primary oracle returns 0 and the deviation check does not revert (the validation check is paused, the validation price is also 0, or the validation call reverts while REVERT_ON_VALIDATION_ORACLE_FAILURE is false).

When REVERT_ON_VALIDATION_ORACLE_FAILURE is true, pausing the validation check is the only way to keep price() working if the validation oracle permanently breaks. Renouncing ownership removes that option: price() reverts until the validation oracle recovers.

Constants

PRIMARY_ORACLE

IOracle public immutable PRIMARY_ORACLE

VALIDATION_ORACLE

IOracle public immutable VALIDATION_ORACLE

MAX_ORACLE_DEVIATION

uint256 public immutable MAX_ORACLE_DEVIATION

REVERT_ON_VALIDATION_ORACLE_FAILURE

Whether price() reverts when the validation oracle call reverts.

When false, the primary price is returned unchecked instead.

bool public immutable REVERT_ON_VALIDATION_ORACLE_FAILURE

State Variables

validationCheckPaused

bool public validationCheckPaused

Functions

constructor

constructor(
IOracle primaryOracle,
IOracle validationOracle,
uint256 maxOracleDeviation,
bool revertOnValidationOracleFailure,
address initialOwner
) Ownable(initialOwner);

Parameters

NameTypeDescription
primaryOracleIOracle
validationOracleIOracle
maxOracleDeviationuint256Max deviation between the two oracle prices, as a WAD fraction (1e18 = 100%).
revertOnValidationOracleFailurebool
initialOwneraddress

price

function price() external view returns (uint256);

pauseValidationCheck

Pauses validation: price() returns the primary price unchecked until unpauseValidationCheck is called.

Only callable by the owner. Reverts if already paused.

function pauseValidationCheck() external onlyOwner;

unpauseValidationCheck

Unpauses the validation check.

Only callable by the owner. Reverts if not paused.

function unpauseValidationCheck() external onlyOwner;