Added memory accessors to reserveConfiguration

This commit is contained in:
The3D 2020-10-12 11:23:18 +02:00
parent 4b35df5c4c
commit be517ad960

View File

@ -282,6 +282,7 @@ library ReserveConfiguration {
uint256,
uint256,
uint256,
uint256,
uint256
)
{
@ -291,7 +292,61 @@ library ReserveConfiguration {
dataLocal & ~LTV_MASK,
(dataLocal & ~LIQUIDATION_THRESHOLD_MASK) >> LIQUIDATION_THRESHOLD_START_BIT_POSITION,
(dataLocal & ~LIQUIDATION_BONUS_MASK) >> LIQUIDATION_BONUS_START_BIT_POSITION,
(dataLocal & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION
(dataLocal & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION,
(dataLocal & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION
);
}
/**
* @dev gets the configuration paramters of the reserve from a memory object
* @param self the reserve configuration
* @return the state params representing ltv, liquidation threshold, liquidation bonus, the reserve decimals
**/
function getParamsMemory(ReserveConfiguration.Map memory self)
internal
pure
returns (
uint256,
uint256,
uint256,
uint256,
uint256
)
{
uint256 dataLocal = self.data;
return (
dataLocal & ~LTV_MASK,
(dataLocal & ~LIQUIDATION_THRESHOLD_MASK) >> LIQUIDATION_THRESHOLD_START_BIT_POSITION,
(dataLocal & ~LIQUIDATION_BONUS_MASK) >> LIQUIDATION_BONUS_START_BIT_POSITION,
(dataLocal & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION,
(dataLocal & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION
);
}
/**
* @dev gets the configuration flags of the reserve from a memory object
* @param self the reserve configuration
* @return the state flags representing active, freezed, borrowing enabled, stableRateBorrowing enabled
**/
function getFlagsMemory(ReserveConfiguration.Map memory self)
internal
pure
returns (
bool,
bool,
bool,
bool
)
{
uint256 dataLocal = self.data;
return (
(dataLocal & ~ACTIVE_MASK) >> IS_ACTIVE_START_BIT_POSITION != 0,
(dataLocal & ~FROZEN_MASK) >> IS_FROZEN_START_BIT_POSITION != 0,
(dataLocal & ~BORROWING_MASK) >> BORROWING_ENABLED_START_BIT_POSITION != 0,
(dataLocal & ~STABLE_BORROWING_MASK) >> STABLE_BORROWING_ENABLED_START_BIT_POSITION != 0
);
}
}