Fixed configuration library

This commit is contained in:
The3D 2020-07-21 10:20:51 +02:00
parent 8e6ea20a79
commit 77faf4774b

View File

@ -21,7 +21,7 @@ library ReserveConfiguration {
uint256 constant LTV_MASK = 0xFFFFFFFF0000;
uint256 constant LIQUIDATION_THRESHOLD_MASK = 0xFFFF0000FFFF;
uint256 constant LIQUIDATION_BONUS_MASK = 0x0000FFFFFFFF;
uint256 constant LIQUIDATION_BONUS_MASK = 0x00FFFFFFFFFFFF;
uint256 constant DECIMALS_MASK = 0x00FFFFFFFFFFFF;
struct Map {
//bit 0-15: LTV
@ -31,35 +31,45 @@ library ReserveConfiguration {
uint256 data;
}
function setLTV(ReserveConfiguration.Map _self, uint256 _ltv) internal {
function setLTV(ReserveConfiguration.Map storage _self, uint256 _ltv) internal {
_self.data = (_self.data & LTV_MASK) | _ltv;
}
function getLTV(ReserveConfiguration.Map _self) internal view returns (uint256) {
return _self.data & !LTV_MASK;
function getLTV(ReserveConfiguration.Map storage _self) internal view returns (uint256) {
return _self.data & ~LTV_MASK;
}
function setLiquidationThreshold(ReserveConfiguration.Map _self, uint256 _threshold) internal {
function setLiquidationThreshold(ReserveConfiguration.Map storage _self, uint256 _threshold)
internal
{
_self.data = (_self.data & LIQUIDATION_THRESHOLD_MASK) | (_threshold << 16);
}
function getLiquidationThreshold(ReserveConfiguration.Map _self) internal view returns (uint256) {
return (_self.data & !LIQUIDATION_THRESHOLD_MASK) >> 16;
function getLiquidationThreshold(ReserveConfiguration.Map storage _self)
internal
view
returns (uint256)
{
return (_self.data & ~LIQUIDATION_THRESHOLD_MASK) >> 16;
}
function setLiquidationBonus(ReserveConfiguration.Map _self, uint256 _bonus) internal {
function setLiquidationBonus(ReserveConfiguration.Map storage _self, uint256 _bonus) internal {
_self.data = (_self.data & LIQUIDATION_BONUS_MASK) | (_bonus << 32);
}
function getLiquidationBonus(ReserveConfiguration.Map _self) internal view returns (uint256) {
return (_self.data & !LIQUIDATION_BONUS_MASK) >> 32;
function getLiquidationBonus(ReserveConfiguration.Map storage _self)
internal
view
returns (uint256)
{
return (_self.data & ~LIQUIDATION_BONUS_MASK) >> 32;
}
function setDecimals(ReserveConfiguration.Map _self, uint256 _decimals) internal {
_self.data = (_self.data & DECIMALS_MASK) | (_ltv << 48);
function setDecimals(ReserveConfiguration.Map storage _self, uint256 _decimals) internal {
_self.data = (_self.data & DECIMALS_MASK) | (_decimals << 48);
}
function getDecimals(ReserveConfiguration.Map _self) internal view returns (uint256) {
return (_self.data & !DECIMALS_MASK) >> 48;
function getDecimals(ReserveConfiguration.Map storage _self) internal view returns (uint256) {
return (_self.data & ~DECIMALS_MASK) >> 48;
}
}