Refactored LendingPool

This commit is contained in:
The3D 2020-10-12 10:50:06 +02:00
parent 44ba72540c
commit 40ff898011

View File

@ -648,9 +648,10 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
}
/**
* @dev accessory functions to fetch data from the core contract
* @dev returns the state and configuration of the reserve
* @param asset the address of the reserve
* @return the state of the reserve
**/
function getReserveData(address asset)
external
override
@ -660,13 +661,23 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
return _reserves[asset];
}
/**
* @dev returns the user account data across all the reserves
* @param user the address of the user
* @return totalCollateralETH the total collateral in ETH of the user
* @return totalDebtETH the total debt in ETH of the user
* @return availableBorrowsETH the borrowing power left of the user
* @return currentLiquidationThreshold the liquidation threshold of the user
* @return ltv the loan to value of the user
* @return healthFactor the current health factor of the user
**/
function getUserAccountData(address user)
external
override
view
returns (
uint256 totalCollateralETH,
uint256 totalBorrowsETH,
uint256 totalDebtETH,
uint256 availableBorrowsETH,
uint256 currentLiquidationThreshold,
uint256 ltv,
@ -675,7 +686,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
{
(
totalCollateralETH,
totalBorrowsETH,
totalDebtETH,
ltv,
currentLiquidationThreshold,
healthFactor
@ -690,11 +701,103 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
availableBorrowsETH = GenericLogic.calculateAvailableBorrowsETH(
totalCollateralETH,
totalBorrowsETH,
totalDebtETH,
ltv
);
}
/**
* @dev returns the configuration of the reserve
* @param asset the address of the reserve
* @return the configuration of the reserve
**/
function getConfiguration(address asset)
external
override
view
returns (ReserveConfiguration.Map memory)
{
return _reserves[asset].configuration;
}
/**
* @dev returns the normalized income per unit of asset
* @param asset the address of the reserve
* @return the reserve normalized income
*/
function getReserveNormalizedIncome(address asset) external override view returns (uint256) {
return _reserves[asset].getNormalizedIncome();
}
/**
* @dev returns the normalized variable debt per unit of asset
* @param asset the address of the reserve
* @return the reserve normalized debt
*/
function getReserveNormalizedVariableDebt(address asset)
external
override
view
returns (uint256)
{
return _reserves[asset].getNormalizedDebt();
}
/**
* @dev Returns if the LendingPool is paused
*/
function paused() external override view returns (bool) {
return _paused;
}
/**
* @dev returns the list of the initialized reserves
**/
function getReservesList() external override view returns (address[] memory) {
address[] memory _activeReserves = new address[](_reservesCount);
for (uint256 i = 0; i < _reservesCount; i++) {
_activeReserves[i] = _reservesList[i];
}
return _activeReserves;
}
/**
* @dev returns the addresses provider
**/
function getAddressesProvider() external view returns (ILendingPoolAddressesProvider) {
return _addressesProvider;
}
/**
* @dev validate if a balance decrease for an asset is allowed
* @param asset the address of the reserve
* @param user the user related to the balance decrease
* @param amount the amount being transferred/redeemed
* @return true if the balance decrease can be allowed, false otherwise
*/
function balanceDecreaseAllowed(
address asset,
address user,
uint256 amount
) external override view returns (bool) {
_whenNotPaused();
return
GenericLogic.balanceDecreaseAllowed(
asset,
user,
amount,
_reserves,
_usersConfig[user],
_reservesList,
_reservesCount,
_addressesProvider.getPriceOracle()
);
}
/**
* @dev avoids direct transfers of ETH
**/
receive() external payable {
revert();
}
@ -727,7 +830,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
* @param asset the address of the reserve
* @param rateStrategyAddress the address of the interest rate strategy contract
**/
function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress)
external
override
@ -736,20 +838,30 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
_reserves[asset].interestRateStrategyAddress = rateStrategyAddress;
}
/**
* @dev sets the configuration map of the reserve
* @param asset the address of the reserve
* @param configuration the configuration map
**/
function setConfiguration(address asset, uint256 configuration) external override {
_onlyLendingPoolConfigurator();
_reserves[asset].configuration.data = configuration;
}
function getConfiguration(address asset)
external
override
view
returns (ReserveConfiguration.Map memory)
{
return _reserves[asset].configuration;
}
/**
* @dev Set the _pause state
* @param val the boolean value to set the current pause state of LendingPool
*/
function setPause(bool val) external override {
_onlyLendingPoolConfigurator();
_paused = val;
if (_paused) {
emit Paused();
} else {
emit Unpaused();
}
}
// internal functions
struct ExecuteBorrowParams {
address asset;
@ -858,93 +970,4 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
}
}
/**
* @dev returns the normalized income per unit of asset
* @param asset the address of the reserve
* @return the reserve normalized income
*/
function getReserveNormalizedIncome(address asset) external override view returns (uint256) {
return _reserves[asset].getNormalizedIncome();
}
/**
* @dev returns the normalized variable debt per unit of asset
* @param asset the address of the reserve
* @return the reserve normalized debt
*/
function getReserveNormalizedVariableDebt(address asset)
external
override
view
returns (uint256)
{
return _reserves[asset].getNormalizedDebt();
}
/**
* @dev validate if a balance decrease for an asset is allowed
* @param asset the address of the reserve
* @param user the user related to the balance decrease
* @param amount the amount being transferred/redeemed
* @return true if the balance decrease can be allowed, false otherwise
*/
function balanceDecreaseAllowed(
address asset,
address user,
uint256 amount
) external override view returns (bool) {
_whenNotPaused();
return
GenericLogic.balanceDecreaseAllowed(
asset,
user,
amount,
_reserves,
_usersConfig[user],
_reservesList,
_reservesCount,
_addressesProvider.getPriceOracle()
);
}
/**
* @dev Set the _pause state
* @param val the boolean value to set the current pause state of LendingPool
*/
function setPause(bool val) external override {
_onlyLendingPoolConfigurator();
_paused = val;
if (_paused) {
emit Paused();
} else {
emit Unpaused();
}
}
/**
* @dev Returns if the LendingPool is paused
*/
function paused() external override view returns (bool) {
return _paused;
}
/**
* @dev returns the list of the initialized reserves
**/
function getReservesList() external override view returns (address[] memory) {
address[] memory _activeReserves = new address[](_reservesCount);
for (uint256 i = 0; i < _reservesCount; i++) {
_activeReserves[i] = _reservesList[i];
}
return _activeReserves;
}
/**
* @dev returns the addresses provider
**/
function getAddressesProvider() external view returns (ILendingPoolAddressesProvider) {
return _addressesProvider;
}
}