2020-07-21 07:53:38 +00:00
|
|
|
// SPDX-License-Identifier: agpl-3.0
|
2020-11-20 10:45:20 +00:00
|
|
|
pragma solidity 0.6.12;
|
2020-07-21 07:53:38 +00:00
|
|
|
|
2020-10-28 09:54:09 +00:00
|
|
|
import {Errors} from '../helpers/Errors.sol';
|
2020-11-24 13:53:34 +00:00
|
|
|
import {DataTypes} from '../types/DataTypes.sol';
|
2020-07-21 07:53:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @title ReserveConfiguration library
|
|
|
|
* @author Aave
|
2020-07-27 07:49:45 +00:00
|
|
|
* @notice Implements the bitmap logic to handle the reserve configuration
|
2020-07-21 07:53:38 +00:00
|
|
|
*/
|
|
|
|
library ReserveConfiguration {
|
2020-10-29 11:09:07 +00:00
|
|
|
uint256 constant LTV_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000; // prettier-ignore
|
|
|
|
uint256 constant LIQUIDATION_THRESHOLD_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFF; // prettier-ignore
|
|
|
|
uint256 constant LIQUIDATION_BONUS_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFF; // prettier-ignore
|
|
|
|
uint256 constant DECIMALS_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFF; // prettier-ignore
|
|
|
|
uint256 constant ACTIVE_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFF; // prettier-ignore
|
|
|
|
uint256 constant FROZEN_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDFFFFFFFFFFFFFF; // prettier-ignore
|
|
|
|
uint256 constant BORROWING_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBFFFFFFFFFFFFFF; // prettier-ignore
|
|
|
|
uint256 constant STABLE_BORROWING_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFFFFF; // prettier-ignore
|
|
|
|
uint256 constant RESERVE_FACTOR_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFF; // prettier-ignore
|
2020-07-21 07:53:38 +00:00
|
|
|
|
2020-11-25 17:33:49 +00:00
|
|
|
/// @dev For the LTV, the start bit is 0 (up to 15), hence no bitshifting is needed
|
2020-09-30 09:24:22 +00:00
|
|
|
uint256 constant LIQUIDATION_THRESHOLD_START_BIT_POSITION = 16;
|
|
|
|
uint256 constant LIQUIDATION_BONUS_START_BIT_POSITION = 32;
|
|
|
|
uint256 constant RESERVE_DECIMALS_START_BIT_POSITION = 48;
|
|
|
|
uint256 constant IS_ACTIVE_START_BIT_POSITION = 56;
|
|
|
|
uint256 constant IS_FROZEN_START_BIT_POSITION = 57;
|
|
|
|
uint256 constant BORROWING_ENABLED_START_BIT_POSITION = 58;
|
|
|
|
uint256 constant STABLE_BORROWING_ENABLED_START_BIT_POSITION = 59;
|
|
|
|
uint256 constant RESERVE_FACTOR_START_BIT_POSITION = 64;
|
|
|
|
|
2020-10-28 09:54:09 +00:00
|
|
|
uint256 constant MAX_VALID_LTV = 65535;
|
|
|
|
uint256 constant MAX_VALID_LIQUIDATION_THRESHOLD = 65535;
|
|
|
|
uint256 constant MAX_VALID_LIQUIDATION_BONUS = 65535;
|
|
|
|
uint256 constant MAX_VALID_DECIMALS = 255;
|
|
|
|
uint256 constant MAX_VALID_RESERVE_FACTOR = 65535;
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Sets the Loan to Value of the reserve
|
|
|
|
* @param self The reserve configuration
|
2020-08-21 12:50:28 +00:00
|
|
|
* @param ltv the new ltv
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2020-11-24 15:17:27 +00:00
|
|
|
function setLtv(DataTypes.ReserveConfigurationMap memory self, uint256 ltv) internal pure {
|
2020-10-30 12:40:06 +00:00
|
|
|
require(ltv <= MAX_VALID_LTV, Errors.RC_INVALID_LTV);
|
2020-10-28 09:54:09 +00:00
|
|
|
|
2020-08-21 12:50:28 +00:00
|
|
|
self.data = (self.data & LTV_MASK) | ltv;
|
2020-07-21 07:53:38 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Gets the Loan to Value of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @return The loan to value
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2020-11-24 15:17:27 +00:00
|
|
|
function getLtv(DataTypes.ReserveConfigurationMap storage self) internal view returns (uint256) {
|
2020-08-21 12:50:28 +00:00
|
|
|
return self.data & ~LTV_MASK;
|
2020-07-21 07:53:38 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Sets the liquidation threshold of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @param threshold The new liquidation threshold
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2020-11-24 15:17:27 +00:00
|
|
|
function setLiquidationThreshold(DataTypes.ReserveConfigurationMap memory self, uint256 threshold)
|
2020-07-21 08:20:51 +00:00
|
|
|
internal
|
2020-08-21 12:50:28 +00:00
|
|
|
pure
|
2020-07-21 08:20:51 +00:00
|
|
|
{
|
2020-10-30 12:40:06 +00:00
|
|
|
require(threshold <= MAX_VALID_LIQUIDATION_THRESHOLD, Errors.RC_INVALID_LIQ_THRESHOLD);
|
2020-10-28 09:54:09 +00:00
|
|
|
|
2020-09-30 09:24:22 +00:00
|
|
|
self.data =
|
|
|
|
(self.data & LIQUIDATION_THRESHOLD_MASK) |
|
|
|
|
(threshold << LIQUIDATION_THRESHOLD_START_BIT_POSITION);
|
2020-07-21 07:53:38 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Gets the liquidation threshold of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @return The liquidation threshold
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2020-11-24 15:17:27 +00:00
|
|
|
function getLiquidationThreshold(DataTypes.ReserveConfigurationMap storage self)
|
2020-07-21 08:20:51 +00:00
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (uint256)
|
|
|
|
{
|
2020-09-30 09:24:22 +00:00
|
|
|
return (self.data & ~LIQUIDATION_THRESHOLD_MASK) >> LIQUIDATION_THRESHOLD_START_BIT_POSITION;
|
2020-07-21 07:53:38 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Sets the liquidation bonus of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @param bonus The new liquidation bonus
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2021-01-27 14:43:34 +00:00
|
|
|
function setLiquidationBonus(DataTypes.ReserveConfigurationMap memory self, uint256 bonus)
|
|
|
|
internal
|
|
|
|
pure
|
|
|
|
{
|
2020-10-30 12:40:06 +00:00
|
|
|
require(bonus <= MAX_VALID_LIQUIDATION_BONUS, Errors.RC_INVALID_LIQ_BONUS);
|
2020-10-28 09:54:09 +00:00
|
|
|
|
2020-09-30 09:24:22 +00:00
|
|
|
self.data =
|
|
|
|
(self.data & LIQUIDATION_BONUS_MASK) |
|
|
|
|
(bonus << LIQUIDATION_BONUS_START_BIT_POSITION);
|
2020-07-21 07:53:38 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Gets the liquidation bonus of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @return The liquidation bonus
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2020-11-24 15:17:27 +00:00
|
|
|
function getLiquidationBonus(DataTypes.ReserveConfigurationMap storage self)
|
2020-07-21 08:20:51 +00:00
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (uint256)
|
|
|
|
{
|
2020-09-30 09:24:22 +00:00
|
|
|
return (self.data & ~LIQUIDATION_BONUS_MASK) >> LIQUIDATION_BONUS_START_BIT_POSITION;
|
2020-07-21 07:53:38 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Sets the decimals of the underlying asset of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @param decimals The decimals
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2021-01-27 14:43:34 +00:00
|
|
|
function setDecimals(DataTypes.ReserveConfigurationMap memory self, uint256 decimals)
|
|
|
|
internal
|
|
|
|
pure
|
|
|
|
{
|
2020-10-30 12:40:06 +00:00
|
|
|
require(decimals <= MAX_VALID_DECIMALS, Errors.RC_INVALID_DECIMALS);
|
2020-10-28 09:54:09 +00:00
|
|
|
|
2020-09-30 09:24:22 +00:00
|
|
|
self.data = (self.data & DECIMALS_MASK) | (decimals << RESERVE_DECIMALS_START_BIT_POSITION);
|
2020-07-21 07:53:38 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Gets the decimals of the underlying asset of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @return The decimals of the asset
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2021-01-27 14:43:34 +00:00
|
|
|
function getDecimals(DataTypes.ReserveConfigurationMap storage self)
|
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (uint256)
|
|
|
|
{
|
2020-09-30 09:24:22 +00:00
|
|
|
return (self.data & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION;
|
2020-07-21 07:53:38 +00:00
|
|
|
}
|
2020-07-23 15:18:06 +00:00
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Sets the active state of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @param active The active state
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2020-11-24 15:17:27 +00:00
|
|
|
function setActive(DataTypes.ReserveConfigurationMap memory self, bool active) internal pure {
|
2020-09-30 09:24:22 +00:00
|
|
|
self.data =
|
|
|
|
(self.data & ACTIVE_MASK) |
|
|
|
|
(uint256(active ? 1 : 0) << IS_ACTIVE_START_BIT_POSITION);
|
2020-07-23 15:18:06 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Gets the active state of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @return The active state
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2020-11-24 15:17:27 +00:00
|
|
|
function getActive(DataTypes.ReserveConfigurationMap storage self) internal view returns (bool) {
|
2020-10-29 11:09:07 +00:00
|
|
|
return (self.data & ~ACTIVE_MASK) != 0;
|
2020-07-23 15:18:06 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Sets the frozen state of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @param frozen The frozen state
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2020-11-24 15:17:27 +00:00
|
|
|
function setFrozen(DataTypes.ReserveConfigurationMap memory self, bool frozen) internal pure {
|
2020-09-30 09:24:22 +00:00
|
|
|
self.data =
|
|
|
|
(self.data & FROZEN_MASK) |
|
|
|
|
(uint256(frozen ? 1 : 0) << IS_FROZEN_START_BIT_POSITION);
|
2020-07-23 15:18:06 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Gets the frozen state of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @return The frozen state
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2020-11-24 15:17:27 +00:00
|
|
|
function getFrozen(DataTypes.ReserveConfigurationMap storage self) internal view returns (bool) {
|
2020-10-29 11:09:07 +00:00
|
|
|
return (self.data & ~FROZEN_MASK) != 0;
|
2020-07-23 15:18:06 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Enables or disables borrowing on the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @param enabled True if the borrowing needs to be enabled, false otherwise
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2021-01-27 14:43:34 +00:00
|
|
|
function setBorrowingEnabled(DataTypes.ReserveConfigurationMap memory self, bool enabled)
|
|
|
|
internal
|
|
|
|
pure
|
|
|
|
{
|
2020-09-30 09:24:22 +00:00
|
|
|
self.data =
|
|
|
|
(self.data & BORROWING_MASK) |
|
|
|
|
(uint256(enabled ? 1 : 0) << BORROWING_ENABLED_START_BIT_POSITION);
|
2020-07-23 15:18:06 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Gets the borrowing state of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @return The borrowing state
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2021-01-27 14:43:34 +00:00
|
|
|
function getBorrowingEnabled(DataTypes.ReserveConfigurationMap storage self)
|
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (bool)
|
|
|
|
{
|
2020-10-29 11:09:07 +00:00
|
|
|
return (self.data & ~BORROWING_MASK) != 0;
|
2020-07-23 15:18:06 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Enables or disables stable rate borrowing on the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @param enabled True if the stable rate borrowing needs to be enabled, false otherwise
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2021-01-27 14:43:34 +00:00
|
|
|
function setStableRateBorrowingEnabled(
|
|
|
|
DataTypes.ReserveConfigurationMap memory self,
|
|
|
|
bool enabled
|
|
|
|
) internal pure {
|
2020-09-30 09:24:22 +00:00
|
|
|
self.data =
|
|
|
|
(self.data & STABLE_BORROWING_MASK) |
|
|
|
|
(uint256(enabled ? 1 : 0) << STABLE_BORROWING_ENABLED_START_BIT_POSITION);
|
2020-07-23 15:18:06 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Gets the stable rate borrowing state of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @return The stable rate borrowing state
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2020-11-24 15:17:27 +00:00
|
|
|
function getStableRateBorrowingEnabled(DataTypes.ReserveConfigurationMap storage self)
|
2020-07-23 15:18:06 +00:00
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (bool)
|
|
|
|
{
|
2020-10-29 11:09:07 +00:00
|
|
|
return (self.data & ~STABLE_BORROWING_MASK) != 0;
|
2020-09-30 09:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Sets the reserve factor of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @param reserveFactor The reserve factor
|
2020-09-30 09:24:22 +00:00
|
|
|
**/
|
2020-11-24 15:17:27 +00:00
|
|
|
function setReserveFactor(DataTypes.ReserveConfigurationMap memory self, uint256 reserveFactor)
|
2020-09-30 09:24:22 +00:00
|
|
|
internal
|
|
|
|
pure
|
|
|
|
{
|
2020-10-30 12:40:06 +00:00
|
|
|
require(reserveFactor <= MAX_VALID_RESERVE_FACTOR, Errors.RC_INVALID_RESERVE_FACTOR);
|
2020-10-28 09:54:09 +00:00
|
|
|
|
2020-09-30 09:24:22 +00:00
|
|
|
self.data =
|
|
|
|
(self.data & RESERVE_FACTOR_MASK) |
|
|
|
|
(reserveFactor << RESERVE_FACTOR_START_BIT_POSITION);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Gets the reserve factor of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @return The reserve factor
|
2020-09-30 09:24:22 +00:00
|
|
|
**/
|
2021-01-27 14:43:34 +00:00
|
|
|
function getReserveFactor(DataTypes.ReserveConfigurationMap storage self)
|
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (uint256)
|
|
|
|
{
|
2020-09-30 09:24:22 +00:00
|
|
|
return (self.data & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION;
|
2020-07-23 15:18:06 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Gets the configuration flags of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @return The state flags representing active, frozen, borrowing enabled, stableRateBorrowing enabled
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2020-11-24 15:17:27 +00:00
|
|
|
function getFlags(DataTypes.ReserveConfigurationMap storage self)
|
2020-07-23 15:18:06 +00:00
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (
|
|
|
|
bool,
|
|
|
|
bool,
|
|
|
|
bool,
|
|
|
|
bool
|
|
|
|
)
|
|
|
|
{
|
2020-08-21 12:50:28 +00:00
|
|
|
uint256 dataLocal = self.data;
|
2020-07-23 15:18:06 +00:00
|
|
|
|
|
|
|
return (
|
2020-10-29 11:09:07 +00:00
|
|
|
(dataLocal & ~ACTIVE_MASK) != 0,
|
|
|
|
(dataLocal & ~FROZEN_MASK) != 0,
|
|
|
|
(dataLocal & ~BORROWING_MASK) != 0,
|
|
|
|
(dataLocal & ~STABLE_BORROWING_MASK) != 0
|
2020-07-23 15:18:06 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-07-27 07:49:45 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Gets the configuration paramters of the reserve
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @return The state params representing ltv, liquidation threshold, liquidation bonus, the reserve decimals
|
2020-07-27 07:49:45 +00:00
|
|
|
**/
|
2020-11-24 15:17:27 +00:00
|
|
|
function getParams(DataTypes.ReserveConfigurationMap storage self)
|
2020-07-23 15:18:06 +00:00
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (
|
|
|
|
uint256,
|
|
|
|
uint256,
|
|
|
|
uint256,
|
2020-10-12 09:23:18 +00:00
|
|
|
uint256,
|
2020-07-23 15:18:06 +00:00
|
|
|
uint256
|
|
|
|
)
|
|
|
|
{
|
2020-08-21 12:50:28 +00:00
|
|
|
uint256 dataLocal = self.data;
|
2020-07-23 15:18:06 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
dataLocal & ~LTV_MASK,
|
2020-09-30 09:24:22 +00:00
|
|
|
(dataLocal & ~LIQUIDATION_THRESHOLD_MASK) >> LIQUIDATION_THRESHOLD_START_BIT_POSITION,
|
|
|
|
(dataLocal & ~LIQUIDATION_BONUS_MASK) >> LIQUIDATION_BONUS_START_BIT_POSITION,
|
2020-10-12 09:23:18 +00:00
|
|
|
(dataLocal & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION,
|
|
|
|
(dataLocal & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @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
|
2020-10-12 09:23:18 +00:00
|
|
|
**/
|
2020-11-24 15:17:27 +00:00
|
|
|
function getParamsMemory(DataTypes.ReserveConfigurationMap memory self)
|
2020-10-12 09:23:18 +00:00
|
|
|
internal
|
|
|
|
pure
|
|
|
|
returns (
|
|
|
|
uint256,
|
2020-07-23 15:18:06 +00:00
|
|
|
uint256,
|
|
|
|
uint256,
|
|
|
|
uint256,
|
|
|
|
uint256
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return (
|
2020-10-12 12:25:03 +00:00
|
|
|
self.data & ~LTV_MASK,
|
|
|
|
(self.data & ~LIQUIDATION_THRESHOLD_MASK) >> LIQUIDATION_THRESHOLD_START_BIT_POSITION,
|
|
|
|
(self.data & ~LIQUIDATION_BONUS_MASK) >> LIQUIDATION_BONUS_START_BIT_POSITION,
|
|
|
|
(self.data & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION,
|
|
|
|
(self.data & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION
|
2020-10-12 09:23:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-28 09:54:09 +00:00
|
|
|
/**
|
2020-11-25 17:33:49 +00:00
|
|
|
* @dev Gets the configuration flags of the reserve from a memory object
|
|
|
|
* @param self The reserve configuration
|
|
|
|
* @return The state flags representing active, frozen, borrowing enabled, stableRateBorrowing enabled
|
2020-10-12 09:23:18 +00:00
|
|
|
**/
|
2020-11-24 15:17:27 +00:00
|
|
|
function getFlagsMemory(DataTypes.ReserveConfigurationMap memory self)
|
2020-10-12 09:23:18 +00:00
|
|
|
internal
|
|
|
|
pure
|
|
|
|
returns (
|
|
|
|
bool,
|
|
|
|
bool,
|
|
|
|
bool,
|
|
|
|
bool
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return (
|
2020-10-29 11:09:07 +00:00
|
|
|
(self.data & ~ACTIVE_MASK) != 0,
|
|
|
|
(self.data & ~FROZEN_MASK) != 0,
|
|
|
|
(self.data & ~BORROWING_MASK) != 0,
|
|
|
|
(self.data & ~STABLE_BORROWING_MASK) != 0
|
2020-07-23 15:18:06 +00:00
|
|
|
);
|
|
|
|
}
|
2020-07-21 07:53:38 +00:00
|
|
|
}
|