Skip to content

Instantly share code, notes, and snippets.

@sekrystal
Last active March 8, 2023 19:45
Show Gist options
  • Save sekrystal/763701a8347d41563e13d9613d9629e2 to your computer and use it in GitHub Desktop.
Save sekrystal/763701a8347d41563e13d9613d9629e2 to your computer and use it in GitHub Desktop.
Defi Lending Concepts 1
pragma solidity ^0.8.13;
function getOverallBorrowRateInternal(
uint256 _totalBorrowsStable,
uint256 _totalBorrowsVariable,
uint256 _currentVariableBorrowRate,
uint256 _currentAverageStableBorrowRate
) internal pure returns (uint256) {
uint256 totalBorrows = _totalBorrowsStable.add(_totalBorrowsVariable);
if (totalBorrows == 0) return 0;
uint256 weightedVariableRate = _totalBorrowsVariable.wadToRay().rayMul(
_currentVariableBorrowRate
);
uint256 weightedStableRate = _totalBorrowsStable.wadToRay().rayMul(
_currentAverageStableBorrowRate
);
uint256 overallBorrowRate = weightedVariableRate.add(weightedStableRate).rayDiv(
totalBorrows.wadToRay()
);
return overallBorrowRate;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment