From 1a29def14d9262e4190359e056c645073d3b0d67 Mon Sep 17 00:00:00 2001 From: The3D Date: Mon, 27 Jul 2020 09:49:45 +0200 Subject: [PATCH] Added natspec comments to ReserveConfiguration --- contracts/lendingpool/LendingPool.sol | 2 +- .../lendingpool/LendingPoolConfigurator.sol | 6 +- contracts/libraries/ReserveConfiguration.sol | 107 ++++++++++++++++-- 3 files changed, 102 insertions(+), 13 deletions(-) diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index b95dc018..74d1d89a 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -755,7 +755,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable { reserve.configuration.getBorrowingEnabled(), reserve.configuration.getStableRateBorrowingEnabled(), reserve.configuration.getActive(), - reserve.configuration.getFreezed() + reserve.configuration.getFrozen() ); } diff --git a/contracts/lendingpool/LendingPoolConfigurator.sol b/contracts/lendingpool/LendingPoolConfigurator.sol index 78948d6b..be9bf78c 100644 --- a/contracts/lendingpool/LendingPoolConfigurator.sol +++ b/contracts/lendingpool/LendingPoolConfigurator.sol @@ -229,7 +229,7 @@ contract LendingPoolConfigurator is VersionedInitializable { currentConfig.setDecimals(_underlyingAssetDecimals); currentConfig.setActive(true); - currentConfig.setFreezed(false); + currentConfig.setFrozen(false); pool.setConfiguration(_reserve, currentConfig.data); @@ -391,7 +391,7 @@ contract LendingPoolConfigurator is VersionedInitializable { function freezeReserve(address _reserve) external onlyLendingPoolManager { ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(_reserve); - currentConfig.setFreezed(true); + currentConfig.setFrozen(true); pool.setConfiguration(_reserve, currentConfig.data); @@ -405,7 +405,7 @@ contract LendingPoolConfigurator is VersionedInitializable { function unfreezeReserve(address _reserve) external onlyLendingPoolManager { ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(_reserve); - currentConfig.setFreezed(false); + currentConfig.setFrozen(false); pool.setConfiguration(_reserve, currentConfig.data); diff --git a/contracts/libraries/ReserveConfiguration.sol b/contracts/libraries/ReserveConfiguration.sol index 0ae44c82..5f058dca 100644 --- a/contracts/libraries/ReserveConfiguration.sol +++ b/contracts/libraries/ReserveConfiguration.sol @@ -8,14 +8,13 @@ import {ReserveLogic} from './ReserveLogic.sol'; import {UserLogic} from './UserLogic.sol'; import {WadRayMath} from './WadRayMath.sol'; -import '../interfaces/IPriceOracleGetter.sol'; +import {IPriceOracleGetter} from '../interfaces/IPriceOracleGetter.sol'; import {IFeeProvider} from '../interfaces/IFeeProvider.sol'; -import '@nomiclabs/buidler/console.sol'; /** * @title ReserveConfiguration library * @author Aave - * @title Implements the bitmap logic to handle the configuration mapping + * @notice Implements the bitmap logic to handle the reserve configuration */ library ReserveConfiguration { uint256 constant LTV_MASK = 0xFFFFFFFFFFF0000; @@ -23,7 +22,7 @@ library ReserveConfiguration { uint256 constant LIQUIDATION_BONUS_MASK = 0xFFF0000FFFFFFFF; uint256 constant DECIMALS_MASK = 0xF00FFFFFFFFFFFF; uint256 constant ACTIVE_MASK = 0xEFFFFFFFFFFFFFF; - uint256 constant FREEZED_MASK = 0xDFFFFFFFFFFFFFF; + uint256 constant FROZEN_MASK = 0xDFFFFFFFFFFFFFF; uint256 constant BORROWING_MASK = 0xBFFFFFFFFFFFFFF; uint256 constant STABLE_BORROWING_MASK = 0x7FFFFFFFFFFFFFF; @@ -39,20 +38,40 @@ library ReserveConfiguration { uint256 data; } + /** + * @dev sets the Loan to Value of the reserve + * @param _self the reserve configuration + * @param _ltv the new ltv + **/ function setLtv(ReserveConfiguration.Map memory _self, uint256 _ltv) internal { _self.data = (_self.data & LTV_MASK) | _ltv; } + /** + * @dev gets the Loan to Value of the reserve + * @param _self the reserve configuration + * @return the loan to value + **/ function getLtv(ReserveConfiguration.Map storage _self) internal view returns (uint256) { return _self.data & ~LTV_MASK; } + /** + * @dev sets the liquidation threshold of the reserve + * @param _self the reserve configuration + * @param _threshold the new liquidation threshold + **/ function setLiquidationThreshold(ReserveConfiguration.Map memory _self, uint256 _threshold) internal { _self.data = (_self.data & LIQUIDATION_THRESHOLD_MASK) | (_threshold << 16); } + /** + * @dev gets the Loan to Value of the reserve + * @param _self the reserve configuration + * @return the liquidation threshold + **/ function getLiquidationThreshold(ReserveConfiguration.Map storage _self) internal view @@ -61,10 +80,20 @@ library ReserveConfiguration { return (_self.data & ~LIQUIDATION_THRESHOLD_MASK) >> 16; } + /** + * @dev sets the liquidation bonus of the reserve + * @param _self the reserve configuration + * @param _ltv the new liquidation bonus + **/ function setLiquidationBonus(ReserveConfiguration.Map memory _self, uint256 _bonus) internal { _self.data = (_self.data & LIQUIDATION_BONUS_MASK) | (_bonus << 32); } + /** + * @dev gets the liquidation bonus of the reserve + * @param _self the reserve configuration + * @return the liquidation bonus + **/ function getLiquidationBonus(ReserveConfiguration.Map storage _self) internal view @@ -73,34 +102,74 @@ library ReserveConfiguration { return (_self.data & ~LIQUIDATION_BONUS_MASK) >> 32; } + /** + * @dev sets the decimals of the underlying asset of the reserve + * @param _self the reserve configuration + * @param _decimals the decimals + **/ function setDecimals(ReserveConfiguration.Map memory _self, uint256 _decimals) internal { _self.data = (_self.data & DECIMALS_MASK) | (_decimals << 48); } + /** + * @dev gets the decimals of the underlying asset of the reserve + * @param _self the reserve configuration + * @return the decimals of the asset + **/ function getDecimals(ReserveConfiguration.Map storage _self) internal view returns (uint256) { return (_self.data & ~DECIMALS_MASK) >> 48; } + /** + * @dev sets the active state of the reserve + * @param _self the reserve configuration + * @param _active the active state + **/ function setActive(ReserveConfiguration.Map memory _self, bool _active) internal { _self.data = (_self.data & ACTIVE_MASK) | (uint256(_active ? 1 : 0) << 56); } + /** + * @dev gets the active state of the reserve + * @param _self the reserve configuration + * @return the active state + **/ function getActive(ReserveConfiguration.Map storage _self) internal view returns (bool) { return ((_self.data & ~ACTIVE_MASK) >> 56) != 0; } - function setFreezed(ReserveConfiguration.Map memory _self, bool _freezed) internal { - _self.data = (_self.data & FREEZED_MASK) | (uint256(_freezed ? 1 : 0) << 57); + /** + * @dev sets the frozen state of the reserve + * @param _self the reserve configuration + * @param _frozen the frozen state + **/ + function setFrozen(ReserveConfiguration.Map memory _self, bool _frozen) internal { + _self.data = (_self.data & FROZEN_MASK) | (uint256(_frozen ? 1 : 0) << 57); } - function getFreezed(ReserveConfiguration.Map storage _self) internal view returns (bool) { - return ((_self.data & ~FREEZED_MASK) >> 57) != 0; + /** + * @dev gets the frozen state of the reserve + * @param _self the reserve configuration + * @return the frozen state + **/ + function getFrozen(ReserveConfiguration.Map storage _self) internal view returns (bool) { + return ((_self.data & ~FROZEN_MASK) >> 57) != 0; } + /** + * @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 + **/ function setBorrowingEnabled(ReserveConfiguration.Map memory _self, bool _enabled) internal { _self.data = (_self.data & BORROWING_MASK) | (uint256(_enabled ? 1 : 0) << 58); } + /** + * @dev gets the borrowing state of the reserve + * @param _self the reserve configuration + * @return the borrowing state + **/ function getBorrowingEnabled(ReserveConfiguration.Map storage _self) internal view @@ -109,12 +178,22 @@ library ReserveConfiguration { return ((_self.data & ~BORROWING_MASK) >> 58) != 0; } + /** + * @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 + **/ function setStableRateBorrowingEnabled(ReserveConfiguration.Map memory _self, bool _enabled) internal { _self.data = (_self.data & STABLE_BORROWING_MASK) | (uint256(_enabled ? 1 : 0) << 59); } + /** + * @dev gets the stable rate borrowing state of the reserve + * @param _self the reserve configuration + * @return the stable rate borrowing state + **/ function getStableRateBorrowingEnabled(ReserveConfiguration.Map storage _self) internal view @@ -123,6 +202,11 @@ library ReserveConfiguration { return ((_self.data & ~STABLE_BORROWING_MASK) >> 59) != 0; } + /** + * @dev gets the configuration flags of the reserve + * @param _self the reserve configuration + * @return the state flags representing active, freezed, borrowing enabled, stableRateBorrowing enabled + **/ function getFlags(ReserveConfiguration.Map storage _self) internal view @@ -137,12 +221,17 @@ library ReserveConfiguration { return ( (dataLocal & ~ACTIVE_MASK) >> 56 != 0, - (dataLocal & ~FREEZED_MASK) >> 57 != 0, + (dataLocal & ~FROZEN_MASK) >> 57 != 0, (dataLocal & ~BORROWING_MASK) >> 58 != 0, (dataLocal & ~STABLE_BORROWING_MASK) >> 59 != 0 ); } + /** + * @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 + **/ function getParams(ReserveConfiguration.Map storage _self) internal view