Oracles and Loan Health Check
Oracles
Lotus is an oracle-agnostic protocol. Markets may be created with an oracle that is not permissioned on Lotus. Lotus tranches are compatible with Morpho Blue Oracles.
Health Check
Oracles are used to check borrower health during borrow(), withdrawCollateral(), and liquidate().
interface IOracle {
function price() external view returns (uint256);
}function _isHealthy(
MarketParams memory marketParams,
Id id,
uint256 trancheIndex,
address borrower,
uint256 collateralPrice // Retrieved from the oracle
) internal view returns (bool) {
(uint256 borrowed, uint256 maxBorrow) =
_getMaxBorrowAndBorrowed(marketParams, id, trancheIndex, borrower, collateralPrice);
return maxBorrow >= borrowed;
}
function _getMaxBorrowAndBorrowed(
MarketParams memory marketParams,
Id id,
uint256 trancheIndex,
address borrower,
uint256 collateralPrice // Retrieved from the oracle
) internal view returns (uint256 borrowed, uint256 maxBorrow) {
borrowed = uint256(positions[id][borrower].borrowShares[trancheIndex])
.toAssetsUp(
marketTranches[id][trancheIndex].trancheBorrowAssets,
marketTranches[id][trancheIndex].trancheBorrowShares
);
uint128 lltvCfg = 0;
if (trancheIndex < marketParams.lltvs.length) {
lltvCfg = marketParams.lltvs[trancheIndex];
}
maxBorrow = uint256(positions[id][borrower].collateral[trancheIndex])
.mulDiv(collateralPrice, ORACLE_PRICE_SCALE).mulWad(lltvCfg);
}Last updated