Skip to main content

MorphoOracleCloneable

Git Source

Inherits: IMorphoOracle, IOraclePriceCache, Clone

Title: MorphoOracleCloneable

Author: OlympusDAO

forge-lint: disable-start(mixed-case-function,mixed-case-variable)

Oracle adapter that implements Morpho's IOracle interface from cached collateral/loan pair snapshots

Returns the price of 1 collateral token quoted in loan tokens, scaled by 1e36 as required by Morpho's IOracle interface. The price precision is 36 + loan_token_decimals - collateral_token_decimals. This contract is deployed as a clone with immutable args.

State Variables

_MORPHO_DECIMALS

uint8 internal constant _MORPHO_DECIMALS = 36

Functions

factory

The factory address

Does not revert.

function factory() public pure returns (IOracleFactory);

Returns

NameTypeDescription
<none>IOracleFactoryThe factory address stored in immutable args

collateralToken

The collateral token address

Does not revert.

function collateralToken() public pure returns (address);

Returns

NameTypeDescription
<none>addressaddress The collateral token address stored in immutable args

loanToken

The loan token address

Does not revert.

function loanToken() public pure returns (address);

Returns

NameTypeDescription
<none>addressaddress The loan token address stored in immutable args

scaleFactor

The scale factor for the oracle

Uses the current asset decimals reported by the factory's active price cache. For non-contract assets, decimals are PriceCache metadata rather than token metadata, so this value can change when PriceCache.setNonContractAssetMetadata() updates decimals. Call PriceCache.assetDecimals() to confirm the active NCA scale.

function scaleFactor() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256uint256 The current scale factor

maxAge

The maximum allowed age for cached prices

Does not revert.

function maxAge() public pure override returns (uint48);

Returns

NameTypeDescription
<none>uint48uint48 The max age stored in immutable args

name

The name of the oracle

Does not revert.

function name() public pure returns (string memory);

Returns

NameTypeDescription
<none>stringstring The name stored in immutable args

_getEnabledPriceCache

Returns the enabled price cache policy for this oracle.

Calls factory().getOracleContext(address(this)) to read the enabled state and price cache address for the current contract. Reverts with MorphoOracle_NotEnabled() when the returned enabled flag is false. Assumes the factory returns a valid IPriceCache address.

function _getEnabledPriceCache() internal view returns (IPriceCache priceCache_);

Returns

NameTypeDescription
priceCache_IPriceCacheThe enabled price cache policy for this oracle.

price

Returns the price of 1 collateral token quoted in loan tokens, scaled by 1e36

This function uses cached pair snapshots only.

The Morpho scale factor is recomputed from the active price cache's current collateral and loan decimals. If either asset is a non-contract asset, decimals are PriceCache metadata rather than token metadata and can change when PriceCache.setNonContractAssetMetadata() updates decimals. Call PriceCache.assetDecimals() to confirm the active NCA scale. This function will revert if:

  • The oracle is not enabled in the factory context
  • The factory policy is deactivated in Kernel (checked via factory.getOracleContext())
  • The IPriceCache.getCachedPrice() call reverts because the cache policy is deactivated in Kernel or the cache contract is disabled
  • The collateral/loan pair is invalid for the configured cache policy
  • Either the collateral or loan token cached price is zero
  • The cached timestamp is stale If callers encounter a feed-state revert, they should cache prices then retry. A caller can alternatively call isStale(), call cachePrice() (if the result is true), and then this function.
function price() external view override returns (uint256);

_scaleFactor

Calculates the current Morpho scale factor from the active price cache

Morpho expects prices scaled by 1e36, adjusted for collateral and loan token decimals: 10 ** (36 + loanDecimals - collateralDecimals). For non-contract assets, decimals are PriceCache metadata and can change when PriceCache.setNonContractAssetMetadata() updates them, so the scale factor is recalculated instead of read from immutable args. Reverts if the exponent is negative or greater than 77, since 10 ** 78 exceeds uint256.

function _scaleFactor(IPriceCache priceCache_) internal view returns (uint256 scaleFactor_);

Parameters

NameTypeDescription
priceCache_IPriceCacheThe price cache used to resolve the current asset decimals

Returns

NameTypeDescription
scaleFactor_uint256The current Morpho scale factor

_isStaleFromTimestamp

function _isStaleFromTimestamp(uint48 timestamp_, uint48 maxAge_) internal view returns (bool);

_latestPermissibleTimestamp

function _latestPermissibleTimestamp(uint48 maxAge_) internal view returns (uint256);

isStale

Returns whether the cached feed state is stale.

Reverts if:

  • The oracle is not enabled in the factory context
  • The factory policy is deactivated in Kernel (checked via factory.getOracleContext())
  • The IPriceCache.isStale() call reverts because the cache policy is deactivated in Kernel or the cache contract is disabled
  • The configured pair is invalid for the active cache policy
function isStale() external view override returns (bool);

Returns

NameTypeDescription
<none>boolisStale_ Returns true if the pair cache is unset or older than maxAge.

timestamp

Returns the cached timestamp for the collateral/loan pair.

Reverts if:

  • The oracle is not enabled in the factory context
  • The factory policy is deactivated in Kernel (checked via factory.getOracleContext())
  • The cache policy is deactivated in Kernel or the cache contract is disabled
  • The configured pair is invalid for the active cache policy
function timestamp() external view override returns (uint48);

Returns

NameTypeDescription
<none>uint48timestamp_ Returns the timestamp of the cached prices

cachePrice

Triggers a cache update for the oracle's configured pair

Unconditionally asks the factory to cache the configured pair. The factory validates caller/oracle/factory enabled state. Reverts if:

  • The factory is disabled
  • The caller is not a deployed oracle from this factory
  • The caller oracle is disabled
  • The configured pair is invalid in the active cache policy
  • The active cache policy reverts while evaluating staleness or caching
function cachePrice() external override;

cachePriceIfNecessary

Triggers a cache update only when the oracle's configured pair cache is stale

Defers staleness checks to the factory using this oracle's configured maxAge. Reverts if:

  • The factory is disabled
  • The caller is not a deployed oracle from this factory
  • The caller oracle is disabled
  • The configured pair is invalid in the active cache policy
  • The active cache policy reverts while evaluating staleness or caching
function cachePriceIfNecessary() external override;

supportsInterface

Query if a contract implements an interface

Does not revert.

function supportsInterface(bytes4 interfaceId_) public pure returns (bool);

Parameters

NameTypeDescription
interfaceId_bytes4The interface identifier, as specified in ERC-165

Returns

NameTypeDescription
<none>boolbool true if the contract implements interfaceId_ and false otherwise