MidnightLib
Git Source - Generated with forge doc
Title: MidnightLib
View helpers that extend the Morpho Midnight contract.
Intended for using MidnightLib for IMidnight.
Functions
computeMaxDebt
Returns the LLTV-weighted collateral value (maxDebt) of borrower, rounded down: the maximum debt the borrower's collateral can support.
Mirrors Morpho Midnight's isHealthy() logic: maxDebt = sum(collateral * price / ORACLE_PRICE_SCALE * lltv / WAD).
function computeMaxDebt(
IMidnight morphoMidnight,
bytes32 marketId,
address borrower,
CollateralParams[] memory collaterals
) internal view returns (uint256 maxDebt);
Parameters
| Name | Type | Description |
|---|---|---|
morphoMidnight | IMidnight | |
marketId | bytes32 | |
borrower | address | |
collaterals | CollateralParams[] | The collateral config array from the market. |
computeMaxDebtFromAmounts
Returns the LLTV-weighted collateral value (maxDebt) from explicit amounts, rounded down.
Same math as computeMaxDebt but with caller-supplied amounts instead of onchain balances.
function computeMaxDebtFromAmounts(CollateralParams[] memory collaterals, uint256[] memory amounts)
internal
view
returns (uint256 maxDebt);
Parameters
| Name | Type | Description |
|---|---|---|
collaterals | CollateralParams[] | |
amounts | uint256[] | The collateral amounts, indexed by collateral slot (same indexing as collaterals). |
computeMaxDebtFromAmounts
Returns maxDebt from explicit amounts, rounded down, lazily fetching and caching oracle prices.
Mutates prices in place: unfetched slots (value 0) are populated on first access.
Callers can pass the same prices array across multiple calls to avoid redundant oracle reads.
Note that 0 is the "not yet fetched" sentinel: if an oracle legitimately returns price 0, it is re-fetched on every call instead of cached.
function computeMaxDebtFromAmounts(
CollateralParams[] memory collaterals,
uint256[] memory amounts,
uint256[] memory prices
) internal view returns (uint256 maxDebt);