Fixed UserConfiguration

This commit is contained in:
The3D 2020-08-21 14:52:10 +02:00
parent e39cf64183
commit b13e08cfde

View File

@ -18,94 +18,94 @@ library UserConfiguration {
} }
/** /**
* @dev sets if the user is borrowing the reserve identified by _reserveIndex * @dev sets if the user is borrowing the reserve identified by reserveIndex
* @param _self the configuration object * @param self the configuration object
* @param _reserveIndex the index of the reserve in the bitmap * @param reserveIndex the index of the reserve in the bitmap
* @param _borrowing true if the user is borrowing the reserve, false otherwise * @param borrowing true if the user is borrowing the reserve, false otherwise
**/ **/
function setBorrowing( function setBorrowing(
UserConfiguration.Map storage _self, UserConfiguration.Map storage self,
uint256 _reserveIndex, uint256 reserveIndex,
bool _borrowing bool borrowing
) internal { ) internal {
_self.data = self.data =
(_self.data & ~(1 << (_reserveIndex * 2))) | (self.data & ~(1 << (reserveIndex * 2))) |
(uint256(_borrowing ? 1 : 0) << (_reserveIndex * 2)); (uint256(borrowing ? 1 : 0) << (reserveIndex * 2));
} }
/** /**
* @dev sets if the user is using as collateral the reserve identified by _reserveIndex * @dev sets if the user is using as collateral the reserve identified by reserveIndex
* @param _self the configuration object * @param self the configuration object
* @param _reserveIndex the index of the reserve in the bitmap * @param reserveIndex the index of the reserve in the bitmap
* @param _usingAsCollateral true if the user is usin the reserve as collateral, false otherwise * @param _usingAsCollateral true if the user is usin the reserve as collateral, false otherwise
**/ **/
function setUsingAsCollateral( function setUsingAsCollateral(
UserConfiguration.Map storage _self, UserConfiguration.Map storage self,
uint256 _reserveIndex, uint256 reserveIndex,
bool _usingAsCollateral bool _usingAsCollateral
) internal { ) internal {
_self.data = self.data =
(_self.data & ~(1 << (_reserveIndex * 2 + 1))) | (self.data & ~(1 << (reserveIndex * 2 + 1))) |
(uint256(_usingAsCollateral ? 1 : 0) << (_reserveIndex * 2 + 1)); (uint256(_usingAsCollateral ? 1 : 0) << (reserveIndex * 2 + 1));
} }
/** /**
* @dev used to validate if a user has been using the reserve for borrowing or as collateral * @dev used to validate if a user has been using the reserve for borrowing or as collateral
* @param _self the configuration object * @param self the configuration object
* @param _reserveIndex the index of the reserve in the bitmap * @param reserveIndex the index of the reserve in the bitmap
* @return true if the user has been using a reserve for borrowing or as collateral, false otherwise * @return true if the user has been using a reserve for borrowing or as collateral, false otherwise
**/ **/
function isUsingAsCollateralOrBorrowing(UserConfiguration.Map memory _self, uint256 _reserveIndex) function isUsingAsCollateralOrBorrowing(UserConfiguration.Map memory self, uint256 reserveIndex)
internal internal
view pure
returns (bool) returns (bool)
{ {
return (_self.data >> (_reserveIndex * 2)) & 3 != 0; return (self.data >> (reserveIndex * 2)) & 3 != 0;
} }
/** /**
* @dev used to validate if a user has been using the reserve for borrowing * @dev used to validate if a user has been using the reserve for borrowing
* @param _self the configuration object * @param self the configuration object
* @param _reserveIndex the index of the reserve in the bitmap * @param reserveIndex the index of the reserve in the bitmap
* @return true if the user has been using a reserve for borrowing, false otherwise * @return true if the user has been using a reserve for borrowing, false otherwise
**/ **/
function isBorrowing(UserConfiguration.Map memory _self, uint256 _reserveIndex) function isBorrowing(UserConfiguration.Map memory self, uint256 reserveIndex)
internal internal
view pure
returns (bool) returns (bool)
{ {
return (_self.data >> (_reserveIndex * 2)) & 1 != 0; return (self.data >> (reserveIndex * 2)) & 1 != 0;
} }
/** /**
* @dev used to validate if a user has been using the reserve as collateral * @dev used to validate if a user has been using the reserve as collateral
* @param _self the configuration object * @param self the configuration object
* @param _reserveIndex the index of the reserve in the bitmap * @param reserveIndex the index of the reserve in the bitmap
* @return true if the user has been using a reserve as collateral, false otherwise * @return true if the user has been using a reserve as collateral, false otherwise
**/ **/
function isUsingAsCollateral(UserConfiguration.Map memory _self, uint256 _reserveIndex) function isUsingAsCollateral(UserConfiguration.Map memory self, uint256 reserveIndex)
internal internal
view pure
returns (bool) returns (bool)
{ {
return (_self.data >> (_reserveIndex * 2 + 1)) & 1 != 0; return (self.data >> (reserveIndex * 2 + 1)) & 1 != 0;
} }
/** /**
* @dev used to validate if a user has been borrowing from any reserve * @dev used to validate if a user has been borrowing from any reserve
* @param _self the configuration object * @param self the configuration object
* @return true if the user has been borrowing any reserve, false otherwise * @return true if the user has been borrowing any reserve, false otherwise
**/ **/
function isBorrowingAny(UserConfiguration.Map memory _self) internal view returns (bool) { function isBorrowingAny(UserConfiguration.Map memory self) internal pure returns (bool) {
return _self.data & BORROWING_MASK != 0; return self.data & BORROWING_MASK != 0;
} }
/** /**
* @dev used to validate if a user has not been using any reserve * @dev used to validate if a user has not been using any reserve
* @param _self the configuration object * @param self the configuration object
* @return true if the user has been borrowing any reserve, false otherwise * @return true if the user has been borrowing any reserve, false otherwise
**/ **/
function isEmpty(UserConfiguration.Map memory _self) internal view returns (bool) { function isEmpty(UserConfiguration.Map memory self) internal pure returns (bool) {
return _self.data == 0; return self.data == 0;
} }
} }