Lending Health Factor
Assert that the health factor of a lending protocol is above a certain threshold
Use Case
Check that the health factor of a position in a lending protocol is above a certain threshold. In this specific example we use Morpho as a lending protocol, but this could be any lending protocol. The Morpho protocol is very well implemented in general and they follow all the best practices.
Explanation
The health factor is a measure of the riskiness of a position in a lending protocol. It is calculated as the ratio of the total value of the collateral to the total value of the debt.
In this example we use a cheatcode that gives us all defined state changes. In this case the state changes of all positions. We then iterate over all the state changes and check if the health factor is still healthy after each state change. Morpho have correctly implemented the health factor in all functions that update positions, but if we assume that the check was mistakenly removed for a future upgrade. This assertion could be used to check that positions are still healthy after the transaction. It wouldn’t be the first time that a protocol has mistakenly removed a check or forgotten to add it to a new function (Euler).