Fast Khaki Raccoon
High
Incorrect total assets available calculation leads to incorrect utilisation ratio
Upon adding interest in FraxlendPairCore
, we have the following code:
uint256 _totalAssetsAvailable = _totalAssetAvailable(totalAsset, totalBorrow, true);
_prevUtilizationRate = _totalAssetsAvailable == 0 ? 0 : (UTIL_PREC * totalBorrow.amount) / _totalAssetsAvailable;
_totalAssetsAvailable
is calculated using the following code:
return _totalAsset.totalAmount(address(externalAssetVault)) - _totalBorrow.amount;
This causes the calculation to be incorrect as _totalAssetsAvailable
is already subtracted by the totalBorrow.amount
used in the utilisation ratio calculation.
Another issue stemming from that is the fact that if the _totalAssetsAvailable
are 0, thus all are borrowed (as we are subtracting the borrowed assets), we have a utilisation ratio of 0 which is completely incorrect, it should be 100%.
No response
No response
First scenario:
- The utilisation ratio goes from 0 to 100% in one borrow (completely possible and likely especially during early times of the vault)
- Upon interest being added next time, the previous utilisation ratio is set to 0 incorrectly (should be 100%)
- Then upon adding interest, we won't pass the threshold as we supposedly went from 0 to 0, interest won't accrue even though we have a utilisation ratio change of 100%
Second scenario:
- The total borrow amount is 60 and the total amount is 100
- The total available assets are thus 40, the calculation would be
1e18 * 60 / 40 = 1.5e18
which is 150%, completely incorrect
The utilization ratio is incorrect and is used in multiple checks, the results will be completely incorrect
No response
Use totalAsset.totalAmount(address(externalAssetVault))
instead