Skip to content

Instantly share code, notes, and snippets.

@sekrystal
Last active March 8, 2023 19:46
Show Gist options
  • Save sekrystal/5d848e710008f8b0ce2444d160efe8ab to your computer and use it in GitHub Desktop.
Save sekrystal/5d848e710008f8b0ce2444d160efe8ab to your computer and use it in GitHub Desktop.
Defi Lending Concepts 1
pragma solidity ^0.8.13;
function exchangeRateStoredInternal() internal view returns (MathError, uint) {
uint _totalSupply = totalSupply;
if (_totalSupply == 0) {
return (MathError.NO_ERROR, initialExchangeRateMantissa);
} else {
uint totalCash = getCashPrior();
uint cashPlusBorrowsMinusReserves;
Exp memory exchangeRate;
MathError mathErr;
(mathErr, cashPlusBorrowsMinusReserves) = addThenSubUInt(totalCash, totalBorrows, totalReserves);
if (mathErr != MathError.NO_ERROR) {
return (mathErr, 0);
}
(mathErr, exchangeRate) = getExp(cashPlusBorrowsMinusReserves, _totalSupply);
if (mathErr != MathError.NO_ERROR) {
return (mathErr, 0);
}
return (MathError.NO_ERROR, exchangeRate.mantissa);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment