Created
March 20, 2023 18:42
-
-
Save sekrystal/11ccda0a6f08a23f12ee38f985cb273f to your computer and use it in GitHub Desktop.
Defi Lending Concepts 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.13; | |
vars.healthFactor = calculateHealthFactorFromBalances( | |
vars.totalCollateralInETH, | |
vars.totalDebtInETH, | |
vars.avgLiquidationThreshold | |
); | |
// ... | |
/** | |
* @dev Calculates the health factor from the corresponding balances | |
* @param totalCollateralInETH The total collateral in ETH | |
* @param totalDebtInETH The total debt in ETH | |
* @param liquidationThreshold The avg liquidation threshold | |
* @return The health factor calculated from the balances provided | |
**/ | |
function calculateHealthFactorFromBalances( | |
uint256 totalCollateralInETH, | |
uint256 totalDebtInETH, | |
uint256 liquidationThreshold | |
) internal pure returns (uint256) { | |
if (totalDebtInETH == 0) return uint256(-1); | |
return (totalCollateralInETH.percentMul(liquidationThreshold)).wadDiv(totalDebtInETH); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment