Skip to content

Commit

Permalink
Merge pull request #111 from aave/refactor/remove-config-memory-acces…
Browse files Browse the repository at this point in the history
…sors

refactor: removed unneded functions in ReserveConfiguration
  • Loading branch information
The-3D authored Sep 22, 2021
2 parents d8942c1 + 5296720 commit 1031915
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 209 deletions.
16 changes: 5 additions & 11 deletions contracts/misc/AaveProtocolDataProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ contract AaveProtocolDataProvider {
.getConfiguration(asset);

(ltv, liquidationThreshold, liquidationBonus, decimals, reserveFactor) = configuration
.getParamsMemory();
.getParams();

(isActive, isFrozen, borrowingEnabled, stableBorrowRateEnabled, ) = configuration
.getFlagsMemory();
(isActive, isFrozen, borrowingEnabled, stableBorrowRateEnabled, ) = configuration.getFlags();

usageAsCollateralEnabled = liquidationThreshold > 0;
}
Expand All @@ -131,9 +130,7 @@ contract AaveProtocolDataProvider {
view
returns (uint256 borrowCap, uint256 supplyCap)
{
(borrowCap, supplyCap) = IPool(ADDRESSES_PROVIDER.getPool())
.getConfiguration(asset)
.getCapsMemory();
(borrowCap, supplyCap) = IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getCaps();
}

/**
Expand All @@ -142,9 +139,7 @@ contract AaveProtocolDataProvider {
* @return isPaused True if the pool is paused, false otherwise
**/
function getPaused(address asset) external view returns (bool isPaused) {
(, , , , isPaused) = IPool(ADDRESSES_PROVIDER.getPool())
.getConfiguration(asset)
.getFlagsMemory();
(, , , , isPaused) = IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getFlags();
}

/**
Expand All @@ -153,8 +148,7 @@ contract AaveProtocolDataProvider {
* @return The protocol fee on liquidation
**/
function getLiquidationProtocolFee(address asset) external view returns (uint256) {
return
IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getLiquidationProtocolFeeMemory();
return IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getLiquidationProtocolFee();
}

/**
Expand Down
198 changes: 22 additions & 176 deletions contracts/protocol/libraries/configuration/ReserveConfiguration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,7 @@ library ReserveConfiguration {
* @param self The reserve configuration
* @return The loan to value
**/
function getLtv(DataTypes.ReserveConfigurationMap storage self) internal view returns (uint256) {
return self.data & ~LTV_MASK;
}

/**
* @notice Gets the Loan to Value of the reserve
* @param self The reserve configuration
* @return The loan to value
**/
function getLtvMemory(DataTypes.ReserveConfigurationMap memory self)
internal
pure
returns (uint256)
{
function getLtv(DataTypes.ReserveConfigurationMap memory self) internal pure returns (uint256) {
return self.data & ~LTV_MASK;
}

Expand Down Expand Up @@ -158,20 +145,7 @@ library ReserveConfiguration {
* @param self The reserve configuration
* @return The decimals of the asset
**/
function getDecimals(DataTypes.ReserveConfigurationMap storage self)
internal
view
returns (uint256)
{
return (self.data & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION;
}

/**
* @notice Gets the decimals of the underlying asset of the reserve
* @param self The reserve configuration
* @return The decimals of the asset
**/
function getDecimalsMemory(DataTypes.ReserveConfigurationMap memory self)
function getDecimals(DataTypes.ReserveConfigurationMap memory self)
internal
pure
returns (uint256)
Expand All @@ -195,7 +169,7 @@ library ReserveConfiguration {
* @param self The reserve configuration
* @return The active state
**/
function getActive(DataTypes.ReserveConfigurationMap storage self) internal view returns (bool) {
function getActive(DataTypes.ReserveConfigurationMap memory self) internal pure returns (bool) {
return (self.data & ~ACTIVE_MASK) != 0;
}

Expand All @@ -215,7 +189,7 @@ library ReserveConfiguration {
* @param self The reserve configuration
* @return The frozen state
**/
function getFrozen(DataTypes.ReserveConfigurationMap storage self) internal view returns (bool) {
function getFrozen(DataTypes.ReserveConfigurationMap memory self) internal pure returns (bool) {
return (self.data & ~FROZEN_MASK) != 0;
}

Expand All @@ -235,7 +209,7 @@ library ReserveConfiguration {
* @param self The reserve configuration
* @return The paused state
**/
function getPaused(DataTypes.ReserveConfigurationMap storage self) internal view returns (bool) {
function getPaused(DataTypes.ReserveConfigurationMap memory self) internal pure returns (bool) {
return (self.data & ~PAUSED_MASK) != 0;
}

Expand All @@ -258,9 +232,9 @@ library ReserveConfiguration {
* @param self The reserve configuration
* @return The borrowing state
**/
function getBorrowingEnabled(DataTypes.ReserveConfigurationMap storage self)
function getBorrowingEnabled(DataTypes.ReserveConfigurationMap memory self)
internal
view
pure
returns (bool)
{
return (self.data & ~BORROWING_MASK) != 0;
Expand All @@ -285,9 +259,9 @@ library ReserveConfiguration {
* @param self The reserve configuration
* @return The stable rate borrowing state
**/
function getStableRateBorrowingEnabled(DataTypes.ReserveConfigurationMap storage self)
function getStableRateBorrowingEnabled(DataTypes.ReserveConfigurationMap memory self)
internal
view
pure
returns (bool)
{
return (self.data & ~STABLE_BORROWING_MASK) != 0;
Expand All @@ -314,20 +288,7 @@ library ReserveConfiguration {
* @param self The reserve configuration
* @return The reserve factor
**/
function getReserveFactor(DataTypes.ReserveConfigurationMap storage self)
internal
view
returns (uint256)
{
return (self.data & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION;
}

/**
* @notice Gets the reserve factor of the reserve
* @param self The reserve configuration
* @return The reserve factor
**/
function getReserveFactorMemory(DataTypes.ReserveConfigurationMap memory self)
function getReserveFactor(DataTypes.ReserveConfigurationMap memory self)
internal
pure
returns (uint256)
Expand All @@ -354,9 +315,9 @@ library ReserveConfiguration {
* @param self The reserve configuration
* @return The borrow cap
**/
function getBorrowCap(DataTypes.ReserveConfigurationMap storage self)
function getBorrowCap(DataTypes.ReserveConfigurationMap memory self)
internal
view
pure
returns (uint256)
{
return (self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION;
Expand All @@ -381,9 +342,9 @@ library ReserveConfiguration {
* @param self The reserve configuration
* @return The supply cap
**/
function getSupplyCap(DataTypes.ReserveConfigurationMap storage self)
function getSupplyCap(DataTypes.ReserveConfigurationMap memory self)
internal
view
pure
returns (uint256)
{
return (self.data & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION;
Expand Down Expand Up @@ -413,9 +374,9 @@ library ReserveConfiguration {
* @param self The reserve configuration
* @return The liquidation protocol fee
**/
function getLiquidationProtocolFee(DataTypes.ReserveConfigurationMap storage self)
function getLiquidationProtocolFee(DataTypes.ReserveConfigurationMap memory self)
internal
view
pure
returns (uint256)
{
return
Expand All @@ -431,9 +392,9 @@ library ReserveConfiguration {
* @return The state flag representing stabelRateBorrowing enabled
* @return The state flag representing paused
**/
function getFlags(DataTypes.ReserveConfigurationMap storage self)
function getFlags(DataTypes.ReserveConfigurationMap memory self)
internal
view
pure
returns (
bool,
bool,
Expand Down Expand Up @@ -462,9 +423,9 @@ library ReserveConfiguration {
* @return The state param representing reserve decimals
* @return The state param representing reserve factor
**/
function getParams(DataTypes.ReserveConfigurationMap storage self)
function getParams(DataTypes.ReserveConfigurationMap memory self)
internal
view
pure
returns (
uint256,
uint256,
Expand All @@ -490,9 +451,9 @@ library ReserveConfiguration {
* @return The state param representing borrow cap
* @return The state param representing supply cap.
**/
function getCaps(DataTypes.ReserveConfigurationMap storage self)
function getCaps(DataTypes.ReserveConfigurationMap memory self)
internal
view
pure
returns (uint256, uint256)
{
uint256 dataLocal = self.data;
Expand All @@ -502,119 +463,4 @@ library ReserveConfiguration {
(dataLocal & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION
);
}

/**
* @notice Gets the configuration paramters of the reserve from a memory object
* @param self The reserve configuration
* @return The state param representing ltv
* @return The state param representing liquidation threshold
* @return The state param representing liquidation bonus
* @return The state param representing reserve decimals
* @return The state param representing reserve factor
**/
function getParamsMemory(DataTypes.ReserveConfigurationMap memory self)
internal
pure
returns (
uint256,
uint256,
uint256,
uint256,
uint256
)
{
return (
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
);
}

/**
* @notice Gets the caps paramters of the reserve from a memory object
* @param self The reserve configuration
* @return The state param representing borrow cap
* @return The state param representing supply cap.
**/
function getCapsMemory(DataTypes.ReserveConfigurationMap memory self)
internal
pure
returns (uint256, uint256)
{
return (
(self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION,
(self.data & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION
);
}

/**
* @notice Gets the configuration flags of the reserve from a memory object
* @param self The reserve configuration
* @return The state flag representing active
* @return The state flag representing frozen
* @return The state flag representing borrowing enabled
* @return The state flag representing stabelRateBorrowing enabled
* @return The state flag representing paused
**/
function getFlagsMemory(DataTypes.ReserveConfigurationMap memory self)
internal
pure
returns (
bool,
bool,
bool,
bool,
bool
)
{
return (
(self.data & ~ACTIVE_MASK) != 0,
(self.data & ~FROZEN_MASK) != 0,
(self.data & ~BORROWING_MASK) != 0,
(self.data & ~STABLE_BORROWING_MASK) != 0,
(self.data & ~PAUSED_MASK) != 0
);
}

/**
* @notice Gets the supply cap of the reserve from a memory objet
* @param self The reserve configuration
* @return The supply cap
**/
function getSupplyCapMemory(DataTypes.ReserveConfigurationMap memory self)
internal
pure
returns (uint256)
{
return (self.data & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION;
}

/**
* @notice Gets the borrow cap of the reserve from a memory object
* @param self The reserve configuration
* @return The borrow cap
**/
function getBorrowCapMemory(DataTypes.ReserveConfigurationMap memory self)
internal
pure
returns (uint256)
{
return (self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION;
}

/**
* @dev Gets the liquidation protocol fee from a memory object
* @param self The reserve configuration
* @return The liquidation protocol fee
**/
function getLiquidationProtocolFeeMemory(DataTypes.ReserveConfigurationMap memory self)
internal
view
returns (uint256)
{
return
(self.data & ~LIQUIDATION_PROTOCOL_FEE_MASK) >> LIQUIDATION_PROTOCOL_FEE_START_BIT_POSITION;
}
}
6 changes: 3 additions & 3 deletions contracts/protocol/libraries/logic/ConfiguratorLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ library ConfiguratorLogic {
{
DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset);

(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory();
(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParams();

bytes memory encodedCall = abi.encodeWithSelector(
IInitializableAToken.initialize.selector,
Expand All @@ -151,7 +151,7 @@ library ConfiguratorLogic {
) public {
DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset);

(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory();
(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParams();

bytes memory encodedCall = abi.encodeWithSelector(
IInitializableDebtToken.initialize.selector,
Expand Down Expand Up @@ -183,7 +183,7 @@ library ConfiguratorLogic {
) public {
DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset);

(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory();
(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParams();

bytes memory encodedCall = abi.encodeWithSelector(
IInitializableDebtToken.initialize.selector,
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/libraries/logic/LiquidationLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ library LiquidationLogic {
(, , vars.liquidationBonus, vars.collateralDecimals, ) = collateralReserve
.configuration
.getParams();
vars.debtAssetDecimals = debtReserveCache.reserveConfiguration.getDecimalsMemory();
vars.debtAssetDecimals = debtReserveCache.reserveConfiguration.getDecimals();
unchecked {
vars.collateralAssetUnit = 10**vars.collateralDecimals;
vars.debtAssetUnit = 10**vars.debtAssetDecimals;
Expand Down
Loading

0 comments on commit 1031915

Please sign in to comment.