Category: Business Logic
Inconsistency between the function getPosition
and function _isPositionSafe
in calculating borrowed assets
Informational Impact
Informational Severity
N/A Likelihood
Description
When calculating the borrowAssets
, the function getPosition
uses the function toAssetsDown
, which rounds down during division.
function getPosition(
PoolStorage.PoolState storage s,
address account
) internal view returns (BorrowPosition memory currentPosition) {
(currentPosition.borrowShares, currentPosition.collateral) = (s.positions[account].borrowShares, s.positions[account].collateral);
PoolData memory previewPool = _previewAccrueInterest(s);
! currentPosition.borrowAssets = currentPosition.borrowShares.toAssetsDown(
previewPool.totalBorrowAssets,
previewPool.totalBorrowShares
);
}
However, the function _isPositionSafe
uses the function toAssetsUp
when calculating the user's borrowedAssets
, i.e. rounding up during division.
function _isPositionSafe(
PoolStorage.PoolState storage s,
address borrower
) internal view returns (bool) {
PoolStorage.Position memory position = s.positions[borrower];
if (position.borrowShares == 0) return true;
uint256 assetRatio = s.totalBorrowAssets.toAssetsUp(PoolConstants.WAD, s.totalBorrowShares);
uint256 borrowedAssets = position.borrowShares * assetRatio;
// [...]
}
Impact
There is an inconsistency between the function getPosition
and function _isPositionSafe
in calculating borrowed assets, while the function toAssetsDown
is in the borrower's favor.
Recommendations
Consider using the function toAssetsUp
to calculate.