From f0fe26e90445faa805af24c0bcce8567548de1dd Mon Sep 17 00:00:00 2001 From: sendra Date: Fri, 4 Feb 2022 11:07:34 +0100 Subject: [PATCH] feat: added new rates fields --- contracts/misc/UiPoolDataProviderV2V3.sol | 49 ++++++++++--------- .../misc/interfaces/IUiPoolDataProviderV3.sol | 12 +++++ 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/contracts/misc/UiPoolDataProviderV2V3.sol b/contracts/misc/UiPoolDataProviderV2V3.sol index 31e3b556..9a6f2732 100644 --- a/contracts/misc/UiPoolDataProviderV2V3.sol +++ b/contracts/misc/UiPoolDataProviderV2V3.sol @@ -17,6 +17,7 @@ import {DataTypes} from '../protocol/libraries/types/DataTypes.sol'; import {IChainlinkAggregator} from '../interfaces/IChainlinkAggregator.sol'; import {DefaultReserveInterestRateStrategy} from '../protocol/lendingpool/DefaultReserveInterestRateStrategy.sol'; import {IERC20DetailedBytes} from './interfaces/IERC20DetailedBytes.sol'; +import {ILendingRateOracle} from '../interfaces/ILendingRateOracle.sol'; contract UiPoolDataProviderV2V3 is IUiPoolDataProviderV3 { using WadRayMath for uint256; @@ -36,24 +37,23 @@ contract UiPoolDataProviderV2V3 is IUiPoolDataProviderV3 { marketReferenceCurrencyPriceInUsdProxyAggregator = _marketReferenceCurrencyPriceInUsdProxyAggregator; } - function getInterestRateStrategySlopes(DefaultReserveInterestRateStrategy interestRateStrategy) + function getInterestRateStrategySlopes(DefaultReserveInterestRateStrategy interestRateStrategy, ILendingPoolAddressesProvider provider, address reserve) internal view - returns ( - uint256, - uint256, - uint256, - uint256, - uint256 - ) + returns(InterestRates memory) { - return ( - interestRateStrategy.variableRateSlope1(), - interestRateStrategy.variableRateSlope2(), - interestRateStrategy.stableRateSlope1(), - interestRateStrategy.stableRateSlope2(), - interestRateStrategy.OPTIMAL_UTILIZATION_RATE() - ); + InterestRates memory interestRates; + interestRates.variableRateSlope1 = interestRateStrategy.variableRateSlope1(); + interestRates.variableRateSlope2 = interestRateStrategy.variableRateSlope2(); + interestRates.stableRateSlope1 = interestRateStrategy.stableRateSlope1(); + interestRates.stableRateSlope2 = interestRateStrategy.stableRateSlope2(); + interestRates.baseVariableBorrowRate = interestRateStrategy.baseVariableBorrowRate(); + interestRates.optimalUsageRatio = interestRateStrategy.OPTIMAL_UTILIZATION_RATE(); + + interestRates.baseStableBorrowRate = ILendingRateOracle(provider.getLendingRateOracle()) + .getMarketBorrowRate(reserve); + + return interestRates; } function getReservesList(ILendingPoolAddressesProvider provider) @@ -133,15 +133,18 @@ contract UiPoolDataProviderV2V3 is IUiPoolDataProviderV3 { reserveData.stableBorrowRateEnabled ) = baseData.configuration.getFlagsMemory(); reserveData.usageAsCollateralEnabled = reserveData.baseLTVasCollateral != 0; - ( - reserveData.variableRateSlope1, - reserveData.variableRateSlope2, - reserveData.stableRateSlope1, - reserveData.stableRateSlope2, - reserveData.optimalUsageRatio - ) = getInterestRateStrategySlopes( - DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress) + + InterestRates memory interestRates = getInterestRateStrategySlopes( + DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress), provider, reserveData.underlyingAsset ); + + reserveData.variableRateSlope1 = interestRates.variableRateSlope1; + reserveData.variableRateSlope2 = interestRates.variableRateSlope2; + reserveData.stableRateSlope1 = interestRates.stableRateSlope1; + reserveData.stableRateSlope2 = interestRates.stableRateSlope2; + reserveData.baseStableBorrowRate = interestRates.baseStableBorrowRate; + reserveData.baseVariableBorrowRate = interestRates.baseVariableBorrowRate; + reserveData.optimalUsageRatio = interestRates.optimalUsageRatio; } BaseCurrencyInfo memory baseCurrencyInfo; diff --git a/contracts/misc/interfaces/IUiPoolDataProviderV3.sol b/contracts/misc/interfaces/IUiPoolDataProviderV3.sol index 55144b86..99ad8e2c 100644 --- a/contracts/misc/interfaces/IUiPoolDataProviderV3.sol +++ b/contracts/misc/interfaces/IUiPoolDataProviderV3.sol @@ -5,6 +5,16 @@ pragma experimental ABIEncoderV2; import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol'; interface IUiPoolDataProviderV3 { + struct InterestRates { + uint256 variableRateSlope1; + uint256 variableRateSlope2; + uint256 stableRateSlope1; + uint256 stableRateSlope2; + uint256 baseStableBorrowRate; + uint256 baseVariableBorrowRate; + uint256 optimalUsageRatio; + } + struct AggregatedReserveData { address underlyingAsset; string name; @@ -42,6 +52,8 @@ interface IUiPoolDataProviderV3 { uint256 variableRateSlope2; uint256 stableRateSlope1; uint256 stableRateSlope2; + uint256 baseStableBorrowRate; + uint256 baseVariableBorrowRate; uint256 optimalUsageRatio; // v3 bool isPaused;