feat: new ui pool data provider working, returning base currenci information

This commit is contained in:
sendra 2021-10-08 17:38:17 +02:00
parent 9ab111f92b
commit de95ca55b9
3 changed files with 154 additions and 124 deletions

View File

@ -24,6 +24,8 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
using UserConfiguration for DataTypes.UserConfigurationMap; using UserConfiguration for DataTypes.UserConfigurationMap;
address public constant MOCK_USD_ADDRESS = 0x10F7Fc1F91Ba351f9C629c5947AD69bD03C05b96; address public constant MOCK_USD_ADDRESS = 0x10F7Fc1F91Ba351f9C629c5947AD69bD03C05b96;
uint256 public constant USD_PRICE = 100000000;
uint256 public constant ETH_CURRENCY_DECIMALS = 18;
constructor() public { constructor() public {
} }
@ -62,7 +64,7 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
override override
returns ( returns (
AggregatedReserveData[] memory, AggregatedReserveData[] memory,
uint256 BaseCurrencyInfo memory
) )
{ {
IAaveOracle oracle = IAaveOracle(provider.getPriceOracle()); IAaveOracle oracle = IAaveOracle(provider.getPriceOracle());
@ -102,8 +104,6 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
reserveData.totalScaledVariableDebt = IVariableDebtToken(reserveData.variableDebtTokenAddress) reserveData.totalScaledVariableDebt = IVariableDebtToken(reserveData.variableDebtTokenAddress)
.scaledTotalSupply(); .scaledTotalSupply();
// reserve configuration
// we're getting this info from the aToken, because some of assets can be not compliant with ETC20Detailed // we're getting this info from the aToken, because some of assets can be not compliant with ETC20Detailed
reserveData.symbol = IERC20Detailed(reserveData.underlyingAsset).symbol(); reserveData.symbol = IERC20Detailed(reserveData.underlyingAsset).symbol();
reserveData.name = ''; reserveData.name = '';
@ -132,7 +132,20 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
); );
} }
return (reservesData, oracle.getAssetPrice(MOCK_USD_ADDRESS)); BaseCurrencyInfo memory baseCurrencyInfo;
try oracle.BASE_CURRENCY_UNIT() returns (uint256 baseCurrencyUnit) {
baseCurrencyInfo.baseCurrencyDecimals = baseCurrencyUnit;
if (address(0) == oracle.BASE_CURRENCY()) {
baseCurrencyInfo.baseCurrencyPriceInUsd = USD_PRICE;
} else {
baseCurrencyInfo.baseCurrencyPriceInUsd = oracle.getAssetPrice(MOCK_USD_ADDRESS);
}
} catch (bytes memory /*lowLevelData*/) {
baseCurrencyInfo.baseCurrencyDecimals = ETH_CURRENCY_DECIMALS;
baseCurrencyInfo.baseCurrencyPriceInUsd = oracle.getAssetPrice(MOCK_USD_ADDRESS);
}
return (reservesData, baseCurrencyInfo);
} }
function getUserReservesData(ILendingPoolAddressesProvider provider, address user) function getUserReservesData(ILendingPoolAddressesProvider provider, address user)
@ -181,123 +194,135 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
return (userReservesData); return (userReservesData);
} }
// function getReservesData(ILendingPoolAddressesProvider provider, address user) function getReservesData(ILendingPoolAddressesProvider provider, address user)
// external external
// view view
// override override
// returns ( returns (
// AggregatedReserveData[] memory, AggregatedReserveData[] memory,
// UserReserveData[] memory, UserReserveData[] memory,
// uint256 BaseCurrencyInfo memory
// ) )
// { {
// IAaveOracle oracle = IAaveOracle(provider.getPriceOracle()); IAaveOracle oracle = IAaveOracle(provider.getPriceOracle());
// ILendingPool lendingPool = ILendingPool(provider.getLendingPool()); ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
// address[] memory reserves = lendingPool.getReservesList(); address[] memory reserves = lendingPool.getReservesList();
// DataTypes.UserConfigurationMap memory userConfig = lendingPool.getUserConfiguration(user); DataTypes.UserConfigurationMap memory userConfig = lendingPool.getUserConfiguration(user);
// AggregatedReserveData[] memory reservesData = new AggregatedReserveData[](reserves.length); AggregatedReserveData[] memory reservesData = new AggregatedReserveData[](reserves.length);
// UserReserveData[] memory userReservesData = UserReserveData[] memory userReservesData =
// new UserReserveData[](user != address(0) ? reserves.length : 0); new UserReserveData[](user != address(0) ? reserves.length : 0);
// for (uint256 i = 0; i < reserves.length; i++) { for (uint256 i = 0; i < reserves.length; i++) {
// AggregatedReserveData memory reserveData = reservesData[i]; AggregatedReserveData memory reserveData = reservesData[i];
// reserveData.underlyingAsset = reserves[i]; reserveData.underlyingAsset = reserves[i];
// // reserve current state // reserve current state
// DataTypes.ReserveData memory baseData = DataTypes.ReserveData memory baseData =
// lendingPool.getReserveData(reserveData.underlyingAsset); lendingPool.getReserveData(reserveData.underlyingAsset);
// reserveData.liquidityIndex = baseData.liquidityIndex; reserveData.liquidityIndex = baseData.liquidityIndex;
// reserveData.variableBorrowIndex = baseData.variableBorrowIndex; reserveData.variableBorrowIndex = baseData.variableBorrowIndex;
// reserveData.liquidityRate = baseData.currentLiquidityRate; reserveData.liquidityRate = baseData.currentLiquidityRate;
// reserveData.variableBorrowRate = baseData.currentVariableBorrowRate; reserveData.variableBorrowRate = baseData.currentVariableBorrowRate;
// reserveData.stableBorrowRate = baseData.currentStableBorrowRate; reserveData.stableBorrowRate = baseData.currentStableBorrowRate;
// reserveData.lastUpdateTimestamp = baseData.lastUpdateTimestamp; reserveData.lastUpdateTimestamp = baseData.lastUpdateTimestamp;
// reserveData.aTokenAddress = baseData.aTokenAddress; reserveData.aTokenAddress = baseData.aTokenAddress;
// reserveData.stableDebtTokenAddress = baseData.stableDebtTokenAddress; reserveData.stableDebtTokenAddress = baseData.stableDebtTokenAddress;
// reserveData.variableDebtTokenAddress = baseData.variableDebtTokenAddress; reserveData.variableDebtTokenAddress = baseData.variableDebtTokenAddress;
// reserveData.interestRateStrategyAddress = baseData.interestRateStrategyAddress; reserveData.interestRateStrategyAddress = baseData.interestRateStrategyAddress;
// reserveData.priceInEth = oracle.getAssetPrice(reserveData.underlyingAsset); reserveData.priceInEth = oracle.getAssetPrice(reserveData.underlyingAsset);
// reserveData.availableLiquidity = IERC20Detailed(reserveData.underlyingAsset).balanceOf( reserveData.availableLiquidity = IERC20Detailed(reserveData.underlyingAsset).balanceOf(
// reserveData.aTokenAddress reserveData.aTokenAddress
// ); );
// ( (
// reserveData.totalPrincipalStableDebt, reserveData.totalPrincipalStableDebt,
// , ,
// reserveData.averageStableRate, reserveData.averageStableRate,
// reserveData.stableDebtLastUpdateTimestamp reserveData.stableDebtLastUpdateTimestamp
// ) = IStableDebtToken(reserveData.stableDebtTokenAddress).getSupplyData(); ) = IStableDebtToken(reserveData.stableDebtTokenAddress).getSupplyData();
// reserveData.totalScaledVariableDebt = IVariableDebtToken(reserveData.variableDebtTokenAddress) reserveData.totalScaledVariableDebt = IVariableDebtToken(reserveData.variableDebtTokenAddress)
// .scaledTotalSupply(); .scaledTotalSupply();
// // reserve configuration // we're getting this info from the aToken, because some of assets can be not compliant with ETC20Detailed
reserveData.symbol = IERC20Detailed(reserveData.underlyingAsset).symbol();
reserveData.name = '';
// // we're getting this info from the aToken, because some of assets can be not compliant with ETC20Detailed (
// reserveData.symbol = IERC20Detailed(reserveData.underlyingAsset).symbol(); reserveData.baseLTVasCollateral,
// reserveData.name = ''; reserveData.reserveLiquidationThreshold,
reserveData.reserveLiquidationBonus,
reserveData.decimals,
reserveData.reserveFactor
) = baseData.configuration.getParamsMemory();
(
reserveData.isActive,
reserveData.isFrozen,
reserveData.borrowingEnabled,
reserveData.stableBorrowRateEnabled
) = baseData.configuration.getFlagsMemory();
reserveData.usageAsCollateralEnabled = reserveData.baseLTVasCollateral != 0;
(
reserveData.variableRateSlope1,
reserveData.variableRateSlope2,
reserveData.stableRateSlope1,
reserveData.stableRateSlope2
) = getInterestRateStrategySlopes(
DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress)
);
// ( if (user != address(0)) {
// reserveData.baseLTVasCollateral, // user reserve data
// reserveData.reserveLiquidationThreshold, userReservesData[i].underlyingAsset = reserveData.underlyingAsset;
// reserveData.reserveLiquidationBonus, userReservesData[i].scaledATokenBalance = IAToken(reserveData.aTokenAddress)
// reserveData.decimals, .scaledBalanceOf(user);
// reserveData.reserveFactor userReservesData[i].usageAsCollateralEnabledOnUser = userConfig.isUsingAsCollateral(i);
// ) = baseData.configuration.getParamsMemory();
// ( if (userConfig.isBorrowing(i)) {
// reserveData.isActive, userReservesData[i].scaledVariableDebt = IVariableDebtToken(
// reserveData.isFrozen, reserveData
// reserveData.borrowingEnabled, .variableDebtTokenAddress
// reserveData.stableBorrowRateEnabled )
// ) = baseData.configuration.getFlagsMemory(); .scaledBalanceOf(user);
// reserveData.usageAsCollateralEnabled = reserveData.baseLTVasCollateral != 0; userReservesData[i].principalStableDebt = IStableDebtToken(
// ( reserveData
// reserveData.variableRateSlope1, .stableDebtTokenAddress
// reserveData.variableRateSlope2, )
// reserveData.stableRateSlope1, .principalBalanceOf(user);
// reserveData.stableRateSlope2 if (userReservesData[i].principalStableDebt != 0) {
// ) = getInterestRateStrategySlopes( userReservesData[i].stableBorrowRate = IStableDebtToken(
// DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress) reserveData
// ); .stableDebtTokenAddress
)
.getUserStableRate(user);
userReservesData[i].stableBorrowLastUpdateTimestamp = IStableDebtToken(
reserveData
.stableDebtTokenAddress
)
.getUserLastUpdated(user);
}
}
}
}
BaseCurrencyInfo memory baseCurrencyInfo;
try oracle.BASE_CURRENCY_UNIT() returns (uint256 baseCurrencyUnit) {
baseCurrencyInfo.baseCurrencyDecimals = baseCurrencyUnit;
if (address(0) == oracle.BASE_CURRENCY()) {
baseCurrencyInfo.baseCurrencyPriceInUsd = USD_PRICE;
} else {
baseCurrencyInfo.baseCurrencyPriceInUsd = oracle.getAssetPrice(MOCK_USD_ADDRESS);
}
} catch (bytes memory /*lowLevelData*/) {
baseCurrencyInfo.baseCurrencyDecimals = ETH_CURRENCY_DECIMALS;
baseCurrencyInfo.baseCurrencyPriceInUsd = oracle.getAssetPrice(MOCK_USD_ADDRESS);
}
return (
reservesData,
userReservesData,
baseCurrencyInfo
);
}
// if (user != address(0)) {
// // user reserve data
// userReservesData[i].underlyingAsset = reserveData.underlyingAsset;
// userReservesData[i].scaledATokenBalance = IAToken(reserveData.aTokenAddress)
// .scaledBalanceOf(user);
// userReservesData[i].usageAsCollateralEnabledOnUser = userConfig.isUsingAsCollateral(i);
// if (userConfig.isBorrowing(i)) {
// userReservesData[i].scaledVariableDebt = IVariableDebtToken(
// reserveData
// .variableDebtTokenAddress
// )
// .scaledBalanceOf(user);
// userReservesData[i].principalStableDebt = IStableDebtToken(
// reserveData
// .stableDebtTokenAddress
// )
// .principalBalanceOf(user);
// if (userReservesData[i].principalStableDebt != 0) {
// userReservesData[i].stableBorrowRate = IStableDebtToken(
// reserveData
// .stableDebtTokenAddress
// )
// .getUserStableRate(user);
// userReservesData[i].stableBorrowLastUpdateTimestamp = IStableDebtToken(
// reserveData
// .stableDebtTokenAddress
// )
// .getUserLastUpdated(user);
// }
// }
// }
// }
// return (
// reservesData,
// userReservesData,
// oracle.getAssetPrice(MOCK_USD_ADDRESS),
// );
// }
} }

View File

@ -7,8 +7,8 @@ pragma solidity 0.6.12;
**/ **/
interface IAaveOracle { interface IAaveOracle {
function BASE_CURRENCY() external view returns (address); function BASE_CURRENCY() external view returns (address); // if usd returns 0x0, if eth returns weth address
function BASE_CURRENCY_UNIT() external view returns (address); function BASE_CURRENCY_UNIT() external view returns (uint256); // if usd 8
function WETH() external view returns (address); function WETH() external view returns (address);
/*********** /***********

View File

@ -53,6 +53,11 @@ interface IUiPoolDataProvider {
uint256 stableBorrowLastUpdateTimestamp; uint256 stableBorrowLastUpdateTimestamp;
} }
struct BaseCurrencyInfo {
uint256 baseCurrencyDecimals;
uint256 baseCurrencyPriceInUsd;
}
function getReservesList(ILendingPoolAddressesProvider provider) function getReservesList(ILendingPoolAddressesProvider provider)
external external
view view
@ -63,7 +68,7 @@ interface IUiPoolDataProvider {
view view
returns ( returns (
AggregatedReserveData[] memory, AggregatedReserveData[] memory,
uint256 // usd price eth BaseCurrencyInfo memory
); );
function getUserReservesData(ILendingPoolAddressesProvider provider, address user) function getUserReservesData(ILendingPoolAddressesProvider provider, address user)
@ -74,12 +79,12 @@ interface IUiPoolDataProvider {
); );
// generic method with full data // generic method with full data
// function getReservesData(ILendingPoolAddressesProvider provider, address user) function getReservesData(ILendingPoolAddressesProvider provider, address user)
// external external
// view view
// returns ( returns (
// AggregatedReserveData[] memory, AggregatedReserveData[] memory,
// UserReserveData[] memory, UserReserveData[] memory,
// uint256 BaseCurrencyInfo memory
// ); );
} }