Skip to content

Commit b27092b

Browse files
committed
Merge branch 'feat/split-ui-dataprovider-logic' of github.com:aave/protocol-v2 into feat/188-avalanche-market
2 parents a000ed9 + 025a988 commit b27092b

File tree

4 files changed

+234
-7
lines changed

4 files changed

+234
-7
lines changed

contracts/interfaces/IAaveIncentivesController.sol

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ interface IAaveIncentivesController {
3030
uint256
3131
);
3232

33+
/*
34+
* LEGACY **************************
35+
* @dev Returns the configuration of the distribution for a certain asset
36+
* @param asset The address of the reference asset of the distribution
37+
* @return The asset index, the emission per second and the last updated timestamp
38+
**/
39+
function assets(address asset)
40+
external
41+
view
42+
returns (
43+
uint128,
44+
uint128,
45+
uint256
46+
);
47+
3348
/**
3449
* @dev Whitelists an address to claim the rewards on behalf of another address
3550
* @param user The address of the user

contracts/misc/UiPoolDataProvider.sol

Lines changed: 191 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
2525
using UserConfiguration for DataTypes.UserConfigurationMap;
2626

2727
address public constant MOCK_USD_ADDRESS = 0x10F7Fc1F91Ba351f9C629c5947AD69bD03C05b96;
28-
IAaveIncentivesController public immutable incentivesController;
28+
IAaveIncentivesController public immutable override incentivesController;
2929
IPriceOracleGetter public immutable oracle;
3030

3131
constructor(IAaveIncentivesController _incentivesController, IPriceOracleGetter _oracle) public {
@@ -51,6 +51,188 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
5151
);
5252
}
5353

54+
function getReservesList(ILendingPoolAddressesProvider provider)
55+
public
56+
view
57+
override
58+
returns (address[] memory)
59+
{
60+
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
61+
return lendingPool.getReservesList();
62+
}
63+
64+
function getSimpleReservesData(ILendingPoolAddressesProvider provider)
65+
public
66+
view
67+
override
68+
returns (
69+
AggregatedReserveData[] memory,
70+
uint256,
71+
uint256
72+
)
73+
{
74+
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
75+
address[] memory reserves = lendingPool.getReservesList();
76+
AggregatedReserveData[] memory reservesData = new AggregatedReserveData[](reserves.length);
77+
78+
for (uint256 i = 0; i < reserves.length; i++) {
79+
AggregatedReserveData memory reserveData = reservesData[i];
80+
reserveData.underlyingAsset = reserves[i];
81+
82+
// reserve current state
83+
DataTypes.ReserveData memory baseData =
84+
lendingPool.getReserveData(reserveData.underlyingAsset);
85+
reserveData.liquidityIndex = baseData.liquidityIndex;
86+
reserveData.variableBorrowIndex = baseData.variableBorrowIndex;
87+
reserveData.liquidityRate = baseData.currentLiquidityRate;
88+
reserveData.variableBorrowRate = baseData.currentVariableBorrowRate;
89+
reserveData.stableBorrowRate = baseData.currentStableBorrowRate;
90+
reserveData.lastUpdateTimestamp = baseData.lastUpdateTimestamp;
91+
reserveData.aTokenAddress = baseData.aTokenAddress;
92+
reserveData.stableDebtTokenAddress = baseData.stableDebtTokenAddress;
93+
reserveData.variableDebtTokenAddress = baseData.variableDebtTokenAddress;
94+
reserveData.interestRateStrategyAddress = baseData.interestRateStrategyAddress;
95+
reserveData.priceInEth = oracle.getAssetPrice(reserveData.underlyingAsset);
96+
97+
reserveData.availableLiquidity = IERC20Detailed(reserveData.underlyingAsset).balanceOf(
98+
reserveData.aTokenAddress
99+
);
100+
(
101+
reserveData.totalPrincipalStableDebt,
102+
,
103+
reserveData.averageStableRate,
104+
reserveData.stableDebtLastUpdateTimestamp
105+
) = IStableDebtToken(reserveData.stableDebtTokenAddress).getSupplyData();
106+
reserveData.totalScaledVariableDebt = IVariableDebtToken(reserveData.variableDebtTokenAddress)
107+
.scaledTotalSupply();
108+
109+
// reserve configuration
110+
111+
// we're getting this info from the aToken, because some of assets can be not compliant with ETC20Detailed
112+
reserveData.symbol = IERC20Detailed(reserveData.aTokenAddress).symbol();
113+
reserveData.name = '';
114+
115+
(
116+
reserveData.baseLTVasCollateral,
117+
reserveData.reserveLiquidationThreshold,
118+
reserveData.reserveLiquidationBonus,
119+
reserveData.decimals,
120+
reserveData.reserveFactor
121+
) = baseData.configuration.getParamsMemory();
122+
(
123+
reserveData.isActive,
124+
reserveData.isFrozen,
125+
reserveData.borrowingEnabled,
126+
reserveData.stableBorrowRateEnabled
127+
) = baseData.configuration.getFlagsMemory();
128+
reserveData.usageAsCollateralEnabled = reserveData.baseLTVasCollateral != 0;
129+
(
130+
reserveData.variableRateSlope1,
131+
reserveData.variableRateSlope2,
132+
reserveData.stableRateSlope1,
133+
reserveData.stableRateSlope2
134+
) = getInterestRateStrategySlopes(
135+
DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress)
136+
);
137+
138+
// incentives
139+
if (address(0) != address(incentivesController)) {
140+
(
141+
reserveData.aEmissionPerSecond,
142+
reserveData.aIncentivesLastUpdateTimestamp,
143+
reserveData.aTokenIncentivesIndex
144+
// ) = incentivesController.getAssetData(reserveData.aTokenAddress); TODO: temp fix
145+
) = incentivesController.assets(reserveData.aTokenAddress);
146+
147+
(
148+
reserveData.sEmissionPerSecond,
149+
reserveData.sIncentivesLastUpdateTimestamp,
150+
reserveData.sTokenIncentivesIndex
151+
// ) = incentivesController.getAssetData(reserveData.stableDebtTokenAddress); TODO: temp fix
152+
) = incentivesController.assets(reserveData.stableDebtTokenAddress);
153+
154+
(
155+
reserveData.vEmissionPerSecond,
156+
reserveData.vIncentivesLastUpdateTimestamp,
157+
reserveData.vTokenIncentivesIndex
158+
// ) = incentivesController.getAssetData(reserveData.variableDebtTokenAddress); TODO: temp fix
159+
) = incentivesController.assets(reserveData.variableDebtTokenAddress);
160+
}
161+
}
162+
163+
uint256 emissionEndTimestamp;
164+
if (address(0) != address(incentivesController)) {
165+
emissionEndTimestamp = incentivesController.DISTRIBUTION_END();
166+
}
167+
168+
return (reservesData, oracle.getAssetPrice(MOCK_USD_ADDRESS), emissionEndTimestamp);
169+
}
170+
171+
function getUserReservesData(ILendingPoolAddressesProvider provider, address user)
172+
external
173+
view
174+
override
175+
returns (UserReserveData[] memory, uint256)
176+
{
177+
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
178+
address[] memory reserves = lendingPool.getReservesList();
179+
DataTypes.UserConfigurationMap memory userConfig = lendingPool.getUserConfiguration(user);
180+
181+
UserReserveData[] memory userReservesData =
182+
new UserReserveData[](user != address(0) ? reserves.length : 0);
183+
184+
for (uint256 i = 0; i < reserves.length; i++) {
185+
DataTypes.ReserveData memory baseData = lendingPool.getReserveData(reserves[i]);
186+
// incentives
187+
if (address(0) != address(incentivesController)) {
188+
userReservesData[i].aTokenincentivesUserIndex = incentivesController.getUserAssetData(
189+
user,
190+
baseData.aTokenAddress
191+
);
192+
userReservesData[i].vTokenincentivesUserIndex = incentivesController.getUserAssetData(
193+
user,
194+
baseData.variableDebtTokenAddress
195+
);
196+
userReservesData[i].sTokenincentivesUserIndex = incentivesController.getUserAssetData(
197+
user,
198+
baseData.stableDebtTokenAddress
199+
);
200+
}
201+
// user reserve data
202+
userReservesData[i].underlyingAsset = reserves[i];
203+
userReservesData[i].scaledATokenBalance = IAToken(baseData.aTokenAddress).scaledBalanceOf(
204+
user
205+
);
206+
userReservesData[i].usageAsCollateralEnabledOnUser = userConfig.isUsingAsCollateral(i);
207+
208+
if (userConfig.isBorrowing(i)) {
209+
userReservesData[i].scaledVariableDebt = IVariableDebtToken(
210+
baseData
211+
.variableDebtTokenAddress
212+
)
213+
.scaledBalanceOf(user);
214+
userReservesData[i].principalStableDebt = IStableDebtToken(baseData.stableDebtTokenAddress)
215+
.principalBalanceOf(user);
216+
if (userReservesData[i].principalStableDebt != 0) {
217+
userReservesData[i].stableBorrowRate = IStableDebtToken(baseData.stableDebtTokenAddress)
218+
.getUserStableRate(user);
219+
userReservesData[i].stableBorrowLastUpdateTimestamp = IStableDebtToken(
220+
baseData
221+
.stableDebtTokenAddress
222+
)
223+
.getUserLastUpdated(user);
224+
}
225+
}
226+
}
227+
228+
uint256 userUnclaimedRewards;
229+
if (address(0) != address(incentivesController)) {
230+
userUnclaimedRewards = incentivesController.getUserUnclaimedRewards(user);
231+
}
232+
233+
return (userReservesData, userUnclaimedRewards);
234+
}
235+
54236
function getReservesData(ILendingPoolAddressesProvider provider, address user)
55237
external
56238
view
@@ -136,19 +318,22 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
136318
reserveData.aTokenIncentivesIndex,
137319
reserveData.aEmissionPerSecond,
138320
reserveData.aIncentivesLastUpdateTimestamp
139-
) = incentivesController.getAssetData(reserveData.aTokenAddress);
321+
// ) = incentivesController.getAssetData(reserveData.aTokenAddress); TODO: temp fix
322+
) = incentivesController.assets(reserveData.aTokenAddress);
140323

141324
(
142325
reserveData.sTokenIncentivesIndex,
143326
reserveData.sEmissionPerSecond,
144327
reserveData.sIncentivesLastUpdateTimestamp
145-
) = incentivesController.getAssetData(reserveData.stableDebtTokenAddress);
328+
// ) = incentivesController.getAssetData(reserveData.stableDebtTokenAddress); TODO: temp fix
329+
) = incentivesController.assets(reserveData.stableDebtTokenAddress);
146330

147331
(
148332
reserveData.vTokenIncentivesIndex,
149333
reserveData.vEmissionPerSecond,
150334
reserveData.vIncentivesLastUpdateTimestamp
151-
) = incentivesController.getAssetData(reserveData.variableDebtTokenAddress);
335+
// ) = incentivesController.getAssetData(reserveData.variableDebtTokenAddress); TODO: temp fix
336+
) = incentivesController.assets(reserveData.variableDebtTokenAddress);
152337
}
153338

154339
if (user != address(0)) {
@@ -200,12 +385,12 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
200385
}
201386
}
202387

203-
204388
IncentivesControllerData memory incentivesControllerData;
205389

206390
if (address(0) != address(incentivesController)) {
207391
if (user != address(0)) {
208-
incentivesControllerData.userUnclaimedRewards = incentivesController.getUserUnclaimedRewards(user);
392+
incentivesControllerData.userUnclaimedRewards = incentivesController
393+
.getUserUnclaimedRewards(user);
209394
}
210395
incentivesControllerData.emissionEndTimestamp = incentivesController.DISTRIBUTION_END();
211396
}

contracts/misc/interfaces/IUiPoolDataProvider.sol

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,31 @@ interface IUiPoolDataProvider {
7373
uint256 emissionEndTimestamp;
7474
}
7575

76+
function getReservesList(ILendingPoolAddressesProvider provider)
77+
external
78+
view
79+
returns (address[] memory);
80+
81+
function incentivesController() external view returns (IAaveIncentivesController);
82+
83+
function getSimpleReservesData(ILendingPoolAddressesProvider provider)
84+
external
85+
view
86+
returns (
87+
AggregatedReserveData[] memory,
88+
uint256, // usd price eth
89+
uint256 // emission end timestamp
90+
);
91+
92+
function getUserReservesData(ILendingPoolAddressesProvider provider, address user)
93+
external
94+
view
95+
returns (
96+
UserReserveData[] memory,
97+
uint256 // user unclaimed rewards
98+
);
7699

100+
// generic method with full data
77101
function getReservesData(ILendingPoolAddressesProvider provider, address user)
78102
external
79103
view

helper-hardhat-config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ export const NETWORKS_RPC_URL: iParamsPerNetwork<string> = {
4848
[eEthereumNetwork.buidlerevm]: 'http://localhost:8545',
4949
[eEthereumNetwork.tenderly]: `https://rpc.tenderly.co/fork/`,
5050
[ePolygonNetwork.mumbai]: 'https://rpc-mumbai.maticvigil.com',
51-
[ePolygonNetwork.matic]: 'https://rpc-mainnet.matic.network',
51+
[ePolygonNetwork.matic]:
52+
// 'https://rpc-mainnet.maticvigil.com/v1/e616b9ddc7598ffae92629f8145614d55094c722',
53+
'https://polygon-mainnet.g.alchemy.com/v2/6NUmfWDZw6lC3RPAphj0p_2vm7ElOn2U',
54+
// [ePolygonNetwork.matic]: 'https://rpc-mainnet.matic.network',
5255
[eXDaiNetwork.xdai]: 'https://rpc.xdaichain.com/',
5356
[eAvalancheNetwork.avalanche]: 'https://cchain.explorer.avax.network/',
5457
[eAvalancheNetwork.fuji]: 'https://api.avax-test.network/ext/bc/C/rpc'

0 commit comments

Comments
 (0)