Skip to content

Instantly share code, notes, and snippets.

@0xmikko
Created February 4, 2022 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xmikko/034a51202ea197434c1a5f1d28b39f3c to your computer and use it in GitHub Desktop.
Save 0xmikko/034a51202ea197434c1a5f1d28b39f3c to your computer and use it in GitHub Desktop.
/// @dev Calculates Threshold Weighted Total Value
/// More: https://dev.gearbox.fi/developers/credit/economy#threshold-weighted-value
///
/// @param creditAccount Credit account address
function calcThresholdWeightedValue(address creditAccount)
public
view
override
returns (uint256 total)
{
uint256 tokenMask;
uint256 eTokens = enabledTokens[creditAccount];
for (uint256 i = 0; i < allowedTokens.length; i++) {
tokenMask = 1 << i; // T:[CF-18]
if (eTokens & tokenMask > 0) {
(, , , uint256 twv) = getCreditAccountTokenById(
creditAccount,
i
);
total += twv;
}
} // T:[CF-18]
return total / PERCENTAGE_FACTOR; // T:[CF-18]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment