mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Refactored LendingPool
This commit is contained in:
parent
44ba72540c
commit
40ff898011
|
@ -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)
|
function getReserveData(address asset)
|
||||||
external
|
external
|
||||||
override
|
override
|
||||||
|
@ -660,13 +661,23 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
return _reserves[asset];
|
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)
|
function getUserAccountData(address user)
|
||||||
external
|
external
|
||||||
override
|
override
|
||||||
view
|
view
|
||||||
returns (
|
returns (
|
||||||
uint256 totalCollateralETH,
|
uint256 totalCollateralETH,
|
||||||
uint256 totalBorrowsETH,
|
uint256 totalDebtETH,
|
||||||
uint256 availableBorrowsETH,
|
uint256 availableBorrowsETH,
|
||||||
uint256 currentLiquidationThreshold,
|
uint256 currentLiquidationThreshold,
|
||||||
uint256 ltv,
|
uint256 ltv,
|
||||||
|
@ -675,7 +686,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
{
|
{
|
||||||
(
|
(
|
||||||
totalCollateralETH,
|
totalCollateralETH,
|
||||||
totalBorrowsETH,
|
totalDebtETH,
|
||||||
ltv,
|
ltv,
|
||||||
currentLiquidationThreshold,
|
currentLiquidationThreshold,
|
||||||
healthFactor
|
healthFactor
|
||||||
|
@ -690,11 +701,103 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
|
|
||||||
availableBorrowsETH = GenericLogic.calculateAvailableBorrowsETH(
|
availableBorrowsETH = GenericLogic.calculateAvailableBorrowsETH(
|
||||||
totalCollateralETH,
|
totalCollateralETH,
|
||||||
totalBorrowsETH,
|
totalDebtETH,
|
||||||
ltv
|
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 {
|
receive() external payable {
|
||||||
revert();
|
revert();
|
||||||
}
|
}
|
||||||
|
@ -727,7 +830,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
* @param asset the address of the reserve
|
* @param asset the address of the reserve
|
||||||
* @param rateStrategyAddress the address of the interest rate strategy contract
|
* @param rateStrategyAddress the address of the interest rate strategy contract
|
||||||
**/
|
**/
|
||||||
|
|
||||||
function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress)
|
function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress)
|
||||||
external
|
external
|
||||||
override
|
override
|
||||||
|
@ -736,20 +838,30 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
_reserves[asset].interestRateStrategyAddress = rateStrategyAddress;
|
_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 {
|
function setConfiguration(address asset, uint256 configuration) external override {
|
||||||
_onlyLendingPoolConfigurator();
|
_onlyLendingPoolConfigurator();
|
||||||
_reserves[asset].configuration.data = configuration;
|
_reserves[asset].configuration.data = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getConfiguration(address asset)
|
/**
|
||||||
external
|
* @dev Set the _pause state
|
||||||
override
|
* @param val the boolean value to set the current pause state of LendingPool
|
||||||
view
|
*/
|
||||||
returns (ReserveConfiguration.Map memory)
|
function setPause(bool val) external override {
|
||||||
{
|
_onlyLendingPoolConfigurator();
|
||||||
return _reserves[asset].configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
_paused = val;
|
||||||
|
if (_paused) {
|
||||||
|
emit Paused();
|
||||||
|
} else {
|
||||||
|
emit Unpaused();
|
||||||
|
}
|
||||||
|
}
|
||||||
// internal functions
|
// internal functions
|
||||||
struct ExecuteBorrowParams {
|
struct ExecuteBorrowParams {
|
||||||
address asset;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user