mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Moved accessors to AaveProtocolTestHelpers
This commit is contained in:
parent
be517ad960
commit
645ea913b0
|
@ -579,7 +579,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor
|
||||||
vars.collateralPrice = oracle.getAssetPrice(collateralAddress);
|
vars.collateralPrice = oracle.getAssetPrice(collateralAddress);
|
||||||
vars.principalCurrencyPrice = oracle.getAssetPrice(principalAddress);
|
vars.principalCurrencyPrice = oracle.getAssetPrice(principalAddress);
|
||||||
|
|
||||||
(, , vars.liquidationBonus, vars.collateralDecimals) = collateralReserve
|
(, , vars.liquidationBonus, vars.collateralDecimals, ) = collateralReserve
|
||||||
.configuration
|
.configuration
|
||||||
.getParams();
|
.getParams();
|
||||||
vars.principalDecimals = principalReserve.configuration.getDecimals();
|
vars.principalDecimals = principalReserve.configuration.getDecimals();
|
||||||
|
|
|
@ -578,9 +578,11 @@ contract LendingPoolConfigurator is VersionedInitializable {
|
||||||
|
|
||||||
ReserveConfiguration.Map memory configuration = pool.getConfiguration(asset);
|
ReserveConfiguration.Map memory configuration = pool.getConfiguration(asset);
|
||||||
|
|
||||||
|
(, , , uint256 decimals, ) = configuration.getParamsMemory();
|
||||||
|
|
||||||
bytes memory params = abi.encodeWithSignature(
|
bytes memory params = abi.encodeWithSignature(
|
||||||
'initialize(uint8,string,string)',
|
'initialize(uint8,string,string)',
|
||||||
uint8(configuration.getDecimals()),
|
uint8(decimals),
|
||||||
IERC20Detailed(implementation).name(),
|
IERC20Detailed(implementation).name(),
|
||||||
IERC20Detailed(implementation).symbol()
|
IERC20Detailed(implementation).symbol()
|
||||||
);
|
);
|
||||||
|
|
|
@ -313,14 +313,12 @@ library ReserveConfiguration {
|
||||||
uint256
|
uint256
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
uint256 dataLocal = self.data;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
dataLocal & ~LTV_MASK,
|
self.data & ~LTV_MASK,
|
||||||
(dataLocal & ~LIQUIDATION_THRESHOLD_MASK) >> LIQUIDATION_THRESHOLD_START_BIT_POSITION,
|
(self.data & ~LIQUIDATION_THRESHOLD_MASK) >> LIQUIDATION_THRESHOLD_START_BIT_POSITION,
|
||||||
(dataLocal & ~LIQUIDATION_BONUS_MASK) >> LIQUIDATION_BONUS_START_BIT_POSITION,
|
(self.data & ~LIQUIDATION_BONUS_MASK) >> LIQUIDATION_BONUS_START_BIT_POSITION,
|
||||||
(dataLocal & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION,
|
(self.data & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION,
|
||||||
(dataLocal & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION
|
(self.data & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,13 +338,11 @@ library ReserveConfiguration {
|
||||||
bool
|
bool
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
uint256 dataLocal = self.data;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(dataLocal & ~ACTIVE_MASK) >> IS_ACTIVE_START_BIT_POSITION != 0,
|
(self.data & ~ACTIVE_MASK) >> IS_ACTIVE_START_BIT_POSITION != 0,
|
||||||
(dataLocal & ~FROZEN_MASK) >> IS_FROZEN_START_BIT_POSITION != 0,
|
(self.data & ~FROZEN_MASK) >> IS_FROZEN_START_BIT_POSITION != 0,
|
||||||
(dataLocal & ~BORROWING_MASK) >> BORROWING_ENABLED_START_BIT_POSITION != 0,
|
(self.data & ~BORROWING_MASK) >> BORROWING_ENABLED_START_BIT_POSITION != 0,
|
||||||
(dataLocal & ~STABLE_BORROWING_MASK) >> STABLE_BORROWING_ENABLED_START_BIT_POSITION != 0
|
(self.data & ~STABLE_BORROWING_MASK) >> STABLE_BORROWING_ENABLED_START_BIT_POSITION != 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,13 @@ pragma experimental ABIEncoderV2;
|
||||||
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
|
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
|
||||||
import {IERC20Detailed} from '../interfaces/IERC20Detailed.sol';
|
import {IERC20Detailed} from '../interfaces/IERC20Detailed.sol';
|
||||||
import {ILendingPool} from '../interfaces/ILendingPool.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 {
|
contract AaveProtocolTestHelpers {
|
||||||
|
using ReserveConfiguration for ReserveConfiguration.Map;
|
||||||
|
|
||||||
struct TokenData {
|
struct TokenData {
|
||||||
string symbol;
|
string symbol;
|
||||||
address tokenAddress;
|
address tokenAddress;
|
||||||
|
@ -38,12 +43,108 @@ contract AaveProtocolTestHelpers {
|
||||||
address[] memory reserves = pool.getReservesList();
|
address[] memory reserves = pool.getReservesList();
|
||||||
TokenData[] memory aTokens = new TokenData[](reserves.length);
|
TokenData[] memory aTokens = new TokenData[](reserves.length);
|
||||||
for (uint256 i = 0; i < reserves.length; i++) {
|
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({
|
aTokens[i] = TokenData({
|
||||||
symbol: IERC20Detailed(aTokenAddress).symbol(),
|
symbol: IERC20Detailed(reserveData.aTokenAddress).symbol(),
|
||||||
tokenAddress: aTokenAddress
|
tokenAddress: reserveData.aTokenAddress
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return aTokens;
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
// SPDX-License-Identifier: agpl-3.0
|
// SPDX-License-Identifier: agpl-3.0
|
||||||
pragma solidity ^0.6.8;
|
pragma solidity ^0.6.8;
|
||||||
|
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
import {Address} from '@openzeppelin/contracts/utils/Address.sol';
|
import {Address} from '@openzeppelin/contracts/utils/Address.sol';
|
||||||
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
|
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
|
||||||
|
|
||||||
import {LendingPoolAddressesProvider} from '../configuration/LendingPoolAddressesProvider.sol';
|
import {LendingPoolAddressesProvider} from '../configuration/LendingPoolAddressesProvider.sol';
|
||||||
import {ILendingPool} from '../interfaces/ILendingPool.sol';
|
import {ILendingPool} from '../interfaces/ILendingPool.sol';
|
||||||
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/SafeERC20.sol';
|
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/SafeERC20.sol';
|
||||||
|
import {ReserveConfiguration} from '../libraries/configuration/ReserveConfiguration.sol';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @title WalletBalanceProvider contract
|
* @title WalletBalanceProvider contract
|
||||||
|
@ -19,6 +22,7 @@ contract WalletBalanceProvider {
|
||||||
using Address for address payable;
|
using Address for address payable;
|
||||||
using Address for address;
|
using Address for address;
|
||||||
using SafeERC20 for IERC20;
|
using SafeERC20 for IERC20;
|
||||||
|
using ReserveConfiguration for ReserveConfiguration.Map;
|
||||||
|
|
||||||
LendingPoolAddressesProvider internal immutable _provider;
|
LendingPoolAddressesProvider internal immutable _provider;
|
||||||
|
|
||||||
|
@ -91,7 +95,9 @@ contract WalletBalanceProvider {
|
||||||
uint256[] memory balances = new uint256[](reserves.length);
|
uint256[] memory balances = new uint256[](reserves.length);
|
||||||
|
|
||||||
for (uint256 j = 0; j < reserves.length; j++) {
|
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) {
|
if (!isActive) {
|
||||||
balances[j] = 0;
|
balances[j] = 0;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user