Created
March 2, 2023 18:40
-
-
Save sekrystal/ec151c91240f568c79d06cae6a760652 to your computer and use it in GitHub Desktop.
Defi Lending Concepts
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; | |
function computeExchangeRate(AssetCache memory assetCache) private pure returns (uint) { | |
uint totalAssets = assetCache.poolSize + (assetCache.totalBorrows / INTERNAL_DEBT_PRECISION); | |
if (totalAssets == 0 || assetCache.totalBalances == 0) return 1e18; | |
return totalAssets * 1e18 / assetCache.totalBalances; | |
} | |
function underlyingAmountToBalance(AssetCache memory assetCache, uint amount) internal pure returns (uint) { | |
uint exchangeRate = computeExchangeRate(assetCache); | |
return amount * 1e18 / exchangeRate; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment