Skip to content

Commit 637cd80

Browse files
authored
Merge pull request #272 from aave/feat/UiPoolDataProvider-optimalUtilisationRate
feat: added new fields needed for client calculations
2 parents 5df59ec + 2bbccd4 commit 637cd80

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

contracts/misc/UiPoolDataProviderV2V3.sol

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
DefaultReserveInterestRateStrategy
2020
} from '../protocol/lendingpool/DefaultReserveInterestRateStrategy.sol';
2121
import {IERC20DetailedBytes} from './interfaces/IERC20DetailedBytes.sol';
22+
import {ILendingRateOracle} from '../interfaces/ILendingRateOracle.sol';
2223

2324
contract UiPoolDataProviderV2V3 is IUiPoolDataProviderV3 {
2425
using WadRayMath for uint256;
@@ -38,22 +39,23 @@ contract UiPoolDataProviderV2V3 is IUiPoolDataProviderV3 {
3839
marketReferenceCurrencyPriceInUsdProxyAggregator = _marketReferenceCurrencyPriceInUsdProxyAggregator;
3940
}
4041

41-
function getInterestRateStrategySlopes(DefaultReserveInterestRateStrategy interestRateStrategy)
42+
function getInterestRateStrategySlopes(DefaultReserveInterestRateStrategy interestRateStrategy, ILendingPoolAddressesProvider provider, address reserve)
4243
internal
4344
view
44-
returns (
45-
uint256,
46-
uint256,
47-
uint256,
48-
uint256
49-
)
45+
returns(InterestRates memory)
5046
{
51-
return (
52-
interestRateStrategy.variableRateSlope1(),
53-
interestRateStrategy.variableRateSlope2(),
54-
interestRateStrategy.stableRateSlope1(),
55-
interestRateStrategy.stableRateSlope2()
56-
);
47+
InterestRates memory interestRates;
48+
interestRates.variableRateSlope1 = interestRateStrategy.variableRateSlope1();
49+
interestRates.variableRateSlope2 = interestRateStrategy.variableRateSlope2();
50+
interestRates.stableRateSlope1 = interestRateStrategy.stableRateSlope1();
51+
interestRates.stableRateSlope2 = interestRateStrategy.stableRateSlope2();
52+
interestRates.baseVariableBorrowRate = interestRateStrategy.baseVariableBorrowRate();
53+
interestRates.optimalUsageRatio = interestRateStrategy.OPTIMAL_UTILIZATION_RATE();
54+
55+
interestRates.baseStableBorrowRate = ILendingRateOracle(provider.getLendingRateOracle())
56+
.getMarketBorrowRate(reserve);
57+
58+
return interestRates;
5759
}
5860

5961
function getReservesList(ILendingPoolAddressesProvider provider)
@@ -97,6 +99,7 @@ contract UiPoolDataProviderV2V3 is IUiPoolDataProviderV3 {
9799
reserveData.priceInMarketReferenceCurrency = oracle.getAssetPrice(
98100
reserveData.underlyingAsset
99101
);
102+
reserveData.priceOracle = oracle.getSourceOfAsset(reserveData.underlyingAsset);
100103

101104
reserveData.availableLiquidity = IERC20Detailed(reserveData.underlyingAsset).balanceOf(
102105
reserveData.aTokenAddress
@@ -134,14 +137,18 @@ contract UiPoolDataProviderV2V3 is IUiPoolDataProviderV3 {
134137
reserveData.stableBorrowRateEnabled
135138
) = baseData.configuration.getFlagsMemory();
136139
reserveData.usageAsCollateralEnabled = reserveData.baseLTVasCollateral != 0;
137-
(
138-
reserveData.variableRateSlope1,
139-
reserveData.variableRateSlope2,
140-
reserveData.stableRateSlope1,
141-
reserveData.stableRateSlope2
142-
) = getInterestRateStrategySlopes(
143-
DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress)
140+
141+
InterestRates memory interestRates = getInterestRateStrategySlopes(
142+
DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress), provider, reserveData.underlyingAsset
144143
);
144+
145+
reserveData.variableRateSlope1 = interestRates.variableRateSlope1;
146+
reserveData.variableRateSlope2 = interestRates.variableRateSlope2;
147+
reserveData.stableRateSlope1 = interestRates.stableRateSlope1;
148+
reserveData.stableRateSlope2 = interestRates.stableRateSlope2;
149+
reserveData.baseStableBorrowRate = interestRates.baseStableBorrowRate;
150+
reserveData.baseVariableBorrowRate = interestRates.baseVariableBorrowRate;
151+
reserveData.optimalUsageRatio = interestRates.optimalUsageRatio;
145152
}
146153

147154
BaseCurrencyInfo memory baseCurrencyInfo;

contracts/misc/interfaces/IAaveOracle.sol

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ interface IAaveOracle {
1414
@dev returns the asset price in ETH
1515
*/
1616
function getAssetPrice(address asset) external view returns (uint256);
17-
}
17+
18+
/**
19+
* @notice Returns the address of the source for an asset address
20+
* @param asset The address of the asset
21+
* @return The address of the source
22+
*/
23+
function getSourceOfAsset(address asset) external view returns (address);
24+
}

contracts/misc/interfaces/IUiPoolDataProviderV3.sol

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ pragma experimental ABIEncoderV2;
55
import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
66

77
interface IUiPoolDataProviderV3 {
8+
struct InterestRates {
9+
uint256 variableRateSlope1;
10+
uint256 variableRateSlope2;
11+
uint256 stableRateSlope1;
12+
uint256 stableRateSlope2;
13+
uint256 baseStableBorrowRate;
14+
uint256 baseVariableBorrowRate;
15+
uint256 optimalUsageRatio;
16+
}
17+
818
struct AggregatedReserveData {
919
address underlyingAsset;
1020
string name;
@@ -37,10 +47,14 @@ interface IUiPoolDataProviderV3 {
3747
uint256 stableDebtLastUpdateTimestamp;
3848
uint256 totalScaledVariableDebt;
3949
uint256 priceInMarketReferenceCurrency;
50+
address priceOracle;
4051
uint256 variableRateSlope1;
4152
uint256 variableRateSlope2;
4253
uint256 stableRateSlope1;
4354
uint256 stableRateSlope2;
55+
uint256 baseStableBorrowRate;
56+
uint256 baseVariableBorrowRate;
57+
uint256 optimalUsageRatio;
4458
// v3
4559
bool isPaused;
4660
uint128 accruedToTreasury;

0 commit comments

Comments
 (0)