Skip to main content

MorphoOracleFactory

Git Source

Inherits: BaseOracleFactory

Title: MorphoOracleFactory

Author: OlympusDAO

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

Factory contract for deploying MorphoOracle clones for collateral/loan token pairs

Uses ClonesWithImmutableArgs for gas-efficient oracle deployment

State Variables

ORACLE_IMPLEMENTATION

Reference implementation for cloning

MorphoOracleCloneable public immutable ORACLE_IMPLEMENTATION

MORPHO_DECIMALS

The Morpho scale factor decimals

uint8 internal constant MORPHO_DECIMALS = 36

Functions

constructor

Constructs a new MorphoOracleFactory

Reverts if priceCache_ is not a valid IPriceCache policy for this Kernel.

constructor(Kernel kernel_, address priceCache_) BaseOracleFactory(kernel_, priceCache_);

Parameters

NameTypeDescription
kernel_KernelThe Kernel address
priceCache_addressThe price cache policy address

_getOracleImplementation

Returns the Morpho oracle implementation address for cloning

function _getOracleImplementation() internal view override returns (address);

Returns

NameTypeDescription
<none>addressThe address of the MorphoOracleCloneable implementation

_encodeOracleData

Encodes Morpho-specific oracle data for cloning

Performs Morpho-specific validation (decimals bounds check), generates oracle name, and encodes immutable args. Note: baseTokenis used as collateralToken, quoteToken is used as loanToken. If either token is a non-contract asset, decimals are PriceCache metadata rather than token metadata. The clone recalculates from PriceCache.assetDecimals() on reads, so later NCA decimal updates can change the live Morpho scale factor.

function _encodeOracleData(address collateralToken_, address loanToken_, uint48 maxAge_, bytes calldata)
internal
view
override
returns (bytes memory);

Parameters

NameTypeDescription
collateralToken_address
loanToken_address
maxAge_uint48The maximum age (in seconds) of cached prices used by the oracle
<none>bytes

Returns

NameTypeDescription
<none>bytesbytes The encoded bytes for cloning

Errors

MorphoOracleFactory_TokenDecimalsOutOfBounds

Thrown when token decimals result in invalid scale factor (overflow or negative)

error MorphoOracleFactory_TokenDecimalsOutOfBounds(address collateralToken, address loanToken);

Parameters

NameTypeDescription
collateralTokenaddressThe collateral token address
loanTokenaddressThe loan token address