From 645ea913b0fc25c8f808c8d388f0557de5422e0c Mon Sep 17 00:00:00 2001 From: The3D Date: Mon, 12 Oct 2020 14:25:03 +0200 Subject: [PATCH] Moved accessors to AaveProtocolTestHelpers --- .../LendingPoolCollateralManager.sol | 2 +- .../lendingpool/LendingPoolConfigurator.sol | 4 +- .../configuration/ReserveConfiguration.sol | 22 ++-- contracts/misc/AaveProtocolTestHelpers.sol | 107 +++++++++++++++++- contracts/misc/WalletBalanceProvider.sol | 8 +- 5 files changed, 124 insertions(+), 19 deletions(-) diff --git a/contracts/lendingpool/LendingPoolCollateralManager.sol b/contracts/lendingpool/LendingPoolCollateralManager.sol index 356ce1a4..16c0d2a9 100644 --- a/contracts/lendingpool/LendingPoolCollateralManager.sol +++ b/contracts/lendingpool/LendingPoolCollateralManager.sol @@ -579,7 +579,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor vars.collateralPrice = oracle.getAssetPrice(collateralAddress); vars.principalCurrencyPrice = oracle.getAssetPrice(principalAddress); - (, , vars.liquidationBonus, vars.collateralDecimals) = collateralReserve + (, , vars.liquidationBonus, vars.collateralDecimals, ) = collateralReserve .configuration .getParams(); vars.principalDecimals = principalReserve.configuration.getDecimals(); diff --git a/contracts/lendingpool/LendingPoolConfigurator.sol b/contracts/lendingpool/LendingPoolConfigurator.sol index c9e34f3e..c122730d 100644 --- a/contracts/lendingpool/LendingPoolConfigurator.sol +++ b/contracts/lendingpool/LendingPoolConfigurator.sol @@ -578,9 +578,11 @@ contract LendingPoolConfigurator is VersionedInitializable { ReserveConfiguration.Map memory configuration = pool.getConfiguration(asset); + (, , , uint256 decimals, ) = configuration.getParamsMemory(); + bytes memory params = abi.encodeWithSignature( 'initialize(uint8,string,string)', - uint8(configuration.getDecimals()), + uint8(decimals), IERC20Detailed(implementation).name(), IERC20Detailed(implementation).symbol() ); diff --git a/contracts/libraries/configuration/ReserveConfiguration.sol b/contracts/libraries/configuration/ReserveConfiguration.sol index 78d1fcf2..864c1b48 100644 --- a/contracts/libraries/configuration/ReserveConfiguration.sol +++ b/contracts/libraries/configuration/ReserveConfiguration.sol @@ -313,14 +313,12 @@ library ReserveConfiguration { uint256 ) { - uint256 dataLocal = self.data; - return ( - dataLocal & ~LTV_MASK, - (dataLocal & ~LIQUIDATION_THRESHOLD_MASK) >> LIQUIDATION_THRESHOLD_START_BIT_POSITION, - (dataLocal & ~LIQUIDATION_BONUS_MASK) >> LIQUIDATION_BONUS_START_BIT_POSITION, - (dataLocal & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION, - (dataLocal & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION + 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 ); } @@ -340,13 +338,11 @@ library ReserveConfiguration { bool ) { - uint256 dataLocal = self.data; - return ( - (dataLocal & ~ACTIVE_MASK) >> IS_ACTIVE_START_BIT_POSITION != 0, - (dataLocal & ~FROZEN_MASK) >> IS_FROZEN_START_BIT_POSITION != 0, - (dataLocal & ~BORROWING_MASK) >> BORROWING_ENABLED_START_BIT_POSITION != 0, - (dataLocal & ~STABLE_BORROWING_MASK) >> STABLE_BORROWING_ENABLED_START_BIT_POSITION != 0 + (self.data & ~ACTIVE_MASK) >> IS_ACTIVE_START_BIT_POSITION != 0, + (self.data & ~FROZEN_MASK) >> IS_FROZEN_START_BIT_POSITION != 0, + (self.data & ~BORROWING_MASK) >> BORROWING_ENABLED_START_BIT_POSITION != 0, + (self.data & ~STABLE_BORROWING_MASK) >> STABLE_BORROWING_ENABLED_START_BIT_POSITION != 0 ); } } diff --git a/contracts/misc/AaveProtocolTestHelpers.sol b/contracts/misc/AaveProtocolTestHelpers.sol index 75778f42..c98e54b9 100644 --- a/contracts/misc/AaveProtocolTestHelpers.sol +++ b/contracts/misc/AaveProtocolTestHelpers.sol @@ -5,8 +5,13 @@ pragma experimental ABIEncoderV2; import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol'; import {IERC20Detailed} from '../interfaces/IERC20Detailed.sol'; import {ILendingPool} from '../interfaces/ILendingPool.sol'; +import {ReserveLogic} from '../libraries/logic/ReserveLogic.sol'; +import {ReserveConfiguration} from '../libraries/configuration/ReserveConfiguration.sol'; +import {IStableDebtToken} from '../tokenization/interfaces/IStableDebtToken.sol'; contract AaveProtocolTestHelpers { + using ReserveConfiguration for ReserveConfiguration.Map; + struct TokenData { string symbol; address tokenAddress; @@ -38,12 +43,108 @@ contract AaveProtocolTestHelpers { address[] memory reserves = pool.getReservesList(); TokenData[] memory aTokens = new TokenData[](reserves.length); for (uint256 i = 0; i < reserves.length; i++) { - (address aTokenAddress, , ) = pool.getReserveTokensAddresses(reserves[i]); + ReserveLogic.ReserveData memory reserveData = pool.getReserveData(reserves[i]); aTokens[i] = TokenData({ - symbol: IERC20Detailed(aTokenAddress).symbol(), - tokenAddress: aTokenAddress + symbol: IERC20Detailed(reserveData.aTokenAddress).symbol(), + tokenAddress: reserveData.aTokenAddress }); } return aTokens; } + + function getReserveConfigurationData(address asset) + external + view + returns ( + uint256 decimals, + uint256 ltv, + uint256 liquidationThreshold, + uint256 liquidationBonus, + uint256 reserveFactor, + bool usageAsCollateralEnabled, + bool borrowingEnabled, + bool stableBorrowRateEnabled, + bool isActive, + bool isFrozen + ) + { + ReserveConfiguration.Map memory configuration = ILendingPool( + ADDRESSES_PROVIDER.getLendingPool() + ) + .getConfiguration(asset); + + (ltv, liquidationThreshold, liquidationBonus, decimals, reserveFactor) = configuration + .getParamsMemory(); + + (isActive, isFrozen, borrowingEnabled, stableBorrowRateEnabled) = configuration + .getFlagsMemory(); + + usageAsCollateralEnabled = liquidationThreshold == 0; + } + + function getReserveData(address asset) + external + view + returns ( + uint256 availableLiquidity, + uint256 totalStableDebt, + uint256 totalVariableDebt, + uint256 liquidityRate, + uint256 variableBorrowRate, + uint256 stableBorrowRate, + uint256 averageStableBorrowRate, + uint256 liquidityIndex, + uint256 variableBorrowIndex, + uint40 lastUpdateTimestamp + ) + { + ReserveLogic.ReserveData memory reserve = ILendingPool(ADDRESSES_PROVIDER.getLendingPool()) + .getReserveData(asset); + + return ( + IERC20Detailed(asset).balanceOf(reserve.aTokenAddress), + IERC20Detailed(reserve.stableDebtTokenAddress).totalSupply(), + IERC20Detailed(reserve.variableDebtTokenAddress).totalSupply(), + reserve.currentLiquidityRate, + reserve.currentVariableBorrowRate, + reserve.currentStableBorrowRate, + IStableDebtToken(reserve.stableDebtTokenAddress).getAverageStableRate(), + reserve.liquidityIndex, + reserve.variableBorrowIndex, + reserve.lastUpdateTimestamp + ); + } +/* + function getUserReserveData(address asset, address user) + external + view + returns ( + uint256 currentATokenBalance, + uint256 currentStableDebt, + uint256 currentVariableDebt, + uint256 principalStableDebt, + uint256 scaledVariableDebt, + uint256 stableBorrowRate, + uint256 liquidityRate, + uint40 stableRateLastUpdated, + bool usageAsCollateralEnabled + ) + { + + ReserveLogic.ReserveData memory reserve = ILendingPool(ADDRESSES_PROVIDER.getLendingPool()) + .getReserveData(asset); + + currentATokenBalance = IERC20(reserve.aTokenAddress).balanceOf(user); + (currentStableDebt, currentVariableDebt) = Helpers.getUserCurrentDebt(user, reserve); + principalStableDebt = IStableDebtToken(reserve.stableDebtTokenAddress).principalBalanceOf(user); + scaledVariableDebt = IVariableDebtToken(reserve.variableDebtTokenAddress).scaledBalanceOf(user); + liquidityRate = reserve.currentLiquidityRate; + stableBorrowRate = IStableDebtToken(reserve.stableDebtTokenAddress).getUserStableRate(user); + stableRateLastUpdated = IStableDebtToken(reserve.stableDebtTokenAddress).getUserLastUpdated( + user + ); + usageAsCollateralEnabled = _usersConfig[user].isUsingAsCollateral(reserve.id); + + } + */ } diff --git a/contracts/misc/WalletBalanceProvider.sol b/contracts/misc/WalletBalanceProvider.sol index 1c46922a..5ddcf0bb 100644 --- a/contracts/misc/WalletBalanceProvider.sol +++ b/contracts/misc/WalletBalanceProvider.sol @@ -1,12 +1,15 @@ // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.6.8; +pragma experimental ABIEncoderV2; + import {Address} from '@openzeppelin/contracts/utils/Address.sol'; import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import {LendingPoolAddressesProvider} from '../configuration/LendingPoolAddressesProvider.sol'; import {ILendingPool} from '../interfaces/ILendingPool.sol'; import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/SafeERC20.sol'; +import {ReserveConfiguration} from '../libraries/configuration/ReserveConfiguration.sol'; /** * @title WalletBalanceProvider contract @@ -19,6 +22,7 @@ contract WalletBalanceProvider { using Address for address payable; using Address for address; using SafeERC20 for IERC20; + using ReserveConfiguration for ReserveConfiguration.Map; LendingPoolAddressesProvider internal immutable _provider; @@ -91,7 +95,9 @@ contract WalletBalanceProvider { uint256[] memory balances = new uint256[](reserves.length); for (uint256 j = 0; j < reserves.length; j++) { - (, , , , , , , , , bool isActive, ) = pool.getReserveConfigurationData(reserves[j]); + ReserveConfiguration.Map memory configuration = pool.getConfiguration(reserves[j]); + + (bool isActive, , , ) = configuration.getFlagsMemory(); if (!isActive) { balances[j] = 0;