1+ // SPDX-License-Identifier: agpl-3.0
2+ pragma solidity 0.6.12 ;
3+ pragma experimental ABIEncoderV2;
4+
5+ import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol ' ;
6+ import {IAaveIncentivesController} from '../interfaces/IAaveIncentivesController.sol ' ;
7+ import {IUiIncentiveDataProviderV2} from './interfaces/IUiIncentiveDataProviderV2.sol ' ;
8+ import {ILendingPool} from '../interfaces/ILendingPool.sol ' ;
9+ import {IAToken} from '../interfaces/IAToken.sol ' ;
10+ import {IVariableDebtToken} from '../interfaces/IVariableDebtToken.sol ' ;
11+ import {IStableDebtToken} from '../interfaces/IStableDebtToken.sol ' ;
12+ import {UserConfiguration} from '../protocol/libraries/configuration/UserConfiguration.sol ' ;
13+ import {DataTypes} from '../protocol/libraries/types/DataTypes.sol ' ;
14+ import {IERC20Detailed } from '../dependencies/openzeppelin/contracts/IERC20Detailed.sol ' ;
15+
16+ contract UiIncentiveDataProviderV2 is IUiIncentiveDataProviderV2 {
17+ using UserConfiguration for DataTypes.UserConfigurationMap;
18+
19+ constructor () public {}
20+
21+ function getFullReservesIncentiveData (ILendingPoolAddressesProvider provider , address user )
22+ external
23+ view
24+ override
25+ returns (AggregatedReserveIncentiveData[] memory , UserReserveIncentiveData[] memory )
26+ {
27+ return (_getReservesIncentivesData (provider), _getUserReservesIncentivesData (provider, user));
28+ }
29+
30+ function getReservesIncentivesData (ILendingPoolAddressesProvider provider )
31+ external
32+ view
33+ override
34+ returns (AggregatedReserveIncentiveData[] memory )
35+ {
36+ return _getReservesIncentivesData (provider);
37+ }
38+
39+ function _getReservesIncentivesData (ILendingPoolAddressesProvider provider )
40+ private
41+ view
42+ returns (AggregatedReserveIncentiveData[] memory )
43+ {
44+ ILendingPool lendingPool = ILendingPool (provider.getLendingPool ());
45+ address [] memory reserves = lendingPool.getReservesList ();
46+ AggregatedReserveIncentiveData[] memory reservesIncentiveData =
47+ new AggregatedReserveIncentiveData [](reserves.length );
48+
49+ for (uint256 i = 0 ; i < reserves.length ; i++ ) {
50+ AggregatedReserveIncentiveData memory reserveIncentiveData = reservesIncentiveData[i];
51+ reserveIncentiveData.underlyingAsset = reserves[i];
52+
53+ DataTypes.ReserveData memory baseData = lendingPool.getReserveData (reserves[i]);
54+
55+ try IStableDebtToken (baseData.aTokenAddress).getIncentivesController () returns (IAaveIncentivesController aTokenIncentiveController ) {
56+ if (address (aTokenIncentiveController) != address (0 )) {
57+ address aRewardToken = aTokenIncentiveController.REWARD_TOKEN ();
58+
59+ try aTokenIncentiveController.getAssetData (baseData.aTokenAddress) returns (
60+ uint256 aTokenIncentivesIndex ,
61+ uint256 aEmissionPerSecond ,
62+ uint256 aIncentivesLastUpdateTimestamp
63+ ) {
64+ reserveIncentiveData.aIncentiveData = IncentiveData (
65+ aEmissionPerSecond,
66+ aIncentivesLastUpdateTimestamp,
67+ aTokenIncentivesIndex,
68+ aTokenIncentiveController.DISTRIBUTION_END (),
69+ baseData.aTokenAddress,
70+ aRewardToken,
71+ address (aTokenIncentiveController),
72+ IERC20Detailed (aRewardToken).decimals (),
73+ aTokenIncentiveController.PRECISION ()
74+ );
75+ } catch (bytes memory /*lowLevelData*/ ) {
76+ (
77+ uint256 aEmissionPerSecond ,
78+ uint256 aIncentivesLastUpdateTimestamp ,
79+ uint256 aTokenIncentivesIndex
80+ ) = aTokenIncentiveController.assets (baseData.aTokenAddress);
81+
82+ reserveIncentiveData.aIncentiveData = IncentiveData (
83+ aEmissionPerSecond,
84+ aIncentivesLastUpdateTimestamp,
85+ aTokenIncentivesIndex,
86+ aTokenIncentiveController.DISTRIBUTION_END (),
87+ baseData.aTokenAddress,
88+ aRewardToken,
89+ address (aTokenIncentiveController),
90+ IERC20Detailed (aRewardToken).decimals (),
91+ aTokenIncentiveController.PRECISION ()
92+ );
93+ }
94+ }
95+ } catch (bytes memory /*lowLevelData*/ ) {
96+ // Will not get here
97+ }
98+
99+ try IStableDebtToken (baseData.stableDebtTokenAddress).getIncentivesController () returns (IAaveIncentivesController sTokenIncentiveController ) {
100+ if (address (sTokenIncentiveController) != address (0 )) {
101+
102+ address sRewardToken = sTokenIncentiveController.REWARD_TOKEN ();
103+ try sTokenIncentiveController.getAssetData (baseData.stableDebtTokenAddress) returns (
104+ uint256 sTokenIncentivesIndex ,
105+ uint256 sEmissionPerSecond ,
106+ uint256 sIncentivesLastUpdateTimestamp
107+ ) {
108+ reserveIncentiveData.sIncentiveData = IncentiveData (
109+ sEmissionPerSecond,
110+ sIncentivesLastUpdateTimestamp,
111+ sTokenIncentivesIndex,
112+ sTokenIncentiveController.DISTRIBUTION_END (),
113+ baseData.stableDebtTokenAddress,
114+ sRewardToken,
115+ address (sTokenIncentiveController),
116+ IERC20Detailed (sRewardToken).decimals (),
117+ sTokenIncentiveController.PRECISION ()
118+ );
119+ } catch (bytes memory /*lowLevelData*/ ) {
120+ (
121+ uint256 sEmissionPerSecond ,
122+ uint256 sIncentivesLastUpdateTimestamp ,
123+ uint256 sTokenIncentivesIndex
124+ ) = sTokenIncentiveController.assets (baseData.stableDebtTokenAddress);
125+
126+ reserveIncentiveData.sIncentiveData = IncentiveData (
127+ sEmissionPerSecond,
128+ sIncentivesLastUpdateTimestamp,
129+ sTokenIncentivesIndex,
130+ sTokenIncentiveController.DISTRIBUTION_END (),
131+ baseData.stableDebtTokenAddress,
132+ sRewardToken,
133+ address (sTokenIncentiveController),
134+ IERC20Detailed (sRewardToken).decimals (),
135+ sTokenIncentiveController.PRECISION ()
136+ );
137+ }
138+ }
139+ } catch (bytes memory /*lowLevelData*/ ) {
140+ // Will not get here
141+ }
142+
143+ try IStableDebtToken (baseData.variableDebtTokenAddress).getIncentivesController () returns (IAaveIncentivesController vTokenIncentiveController ) {
144+ if (address (vTokenIncentiveController) != address (0 )) {
145+ address vRewardToken = vTokenIncentiveController.REWARD_TOKEN ();
146+
147+ try vTokenIncentiveController.getAssetData (baseData.variableDebtTokenAddress) returns (
148+ uint256 vTokenIncentivesIndex ,
149+ uint256 vEmissionPerSecond ,
150+ uint256 vIncentivesLastUpdateTimestamp
151+ ) {
152+ reserveIncentiveData.vIncentiveData = IncentiveData (
153+ vEmissionPerSecond,
154+ vIncentivesLastUpdateTimestamp,
155+ vTokenIncentivesIndex,
156+ vTokenIncentiveController.DISTRIBUTION_END (),
157+ baseData.variableDebtTokenAddress,
158+ vRewardToken,
159+ address (vTokenIncentiveController),
160+ IERC20Detailed (vRewardToken).decimals (),
161+ vTokenIncentiveController.PRECISION ()
162+ );
163+ } catch (bytes memory /*lowLevelData*/ ) {
164+ (
165+ uint256 vEmissionPerSecond ,
166+ uint256 vIncentivesLastUpdateTimestamp ,
167+ uint256 vTokenIncentivesIndex
168+ ) = vTokenIncentiveController.assets (baseData.variableDebtTokenAddress);
169+
170+ reserveIncentiveData.vIncentiveData = IncentiveData (
171+ vEmissionPerSecond,
172+ vIncentivesLastUpdateTimestamp,
173+ vTokenIncentivesIndex,
174+ vTokenIncentiveController.DISTRIBUTION_END (),
175+ baseData.variableDebtTokenAddress,
176+ vRewardToken,
177+ address (vTokenIncentiveController),
178+ IERC20Detailed (vRewardToken).decimals (),
179+ vTokenIncentiveController.PRECISION ()
180+ );
181+ }
182+ }
183+ } catch (bytes memory /*lowLevelData*/ ) {
184+ // Will not get here
185+ }
186+ }
187+ return (reservesIncentiveData);
188+ }
189+
190+ function getUserReservesIncentivesData (ILendingPoolAddressesProvider provider , address user )
191+ external
192+ view
193+ override
194+ returns (UserReserveIncentiveData[] memory )
195+ {
196+ return _getUserReservesIncentivesData (provider, user);
197+ }
198+
199+ function _getUserReservesIncentivesData (ILendingPoolAddressesProvider provider , address user )
200+ private
201+ view
202+ returns (UserReserveIncentiveData[] memory )
203+ {
204+ ILendingPool lendingPool = ILendingPool (provider.getLendingPool ());
205+ address [] memory reserves = lendingPool.getReservesList ();
206+
207+ UserReserveIncentiveData[] memory userReservesIncentivesData =
208+ new UserReserveIncentiveData [](user != address (0 ) ? reserves.length : 0 );
209+
210+ for (uint256 i = 0 ; i < reserves.length ; i++ ) {
211+ DataTypes.ReserveData memory baseData = lendingPool.getReserveData (reserves[i]);
212+
213+ // user reserve data
214+ userReservesIncentivesData[i].underlyingAsset = reserves[i];
215+
216+ IUiIncentiveDataProviderV2.UserIncentiveData memory aUserIncentiveData;
217+
218+ try IAToken (baseData.aTokenAddress).getIncentivesController () returns (IAaveIncentivesController aTokenIncentiveController ) {
219+ if (address (aTokenIncentiveController) != address (0 )) {
220+ address aRewardToken = aTokenIncentiveController.REWARD_TOKEN ();
221+ aUserIncentiveData.tokenincentivesUserIndex = aTokenIncentiveController.getUserAssetData (
222+ user,
223+ baseData.aTokenAddress
224+ );
225+ aUserIncentiveData.userUnclaimedRewards = aTokenIncentiveController.getUserUnclaimedRewards (
226+ user
227+ );
228+ aUserIncentiveData.tokenAddress = baseData.aTokenAddress;
229+ aUserIncentiveData.rewardTokenAddress = aRewardToken;
230+ aUserIncentiveData.incentiveControllerAddress = address (aTokenIncentiveController);
231+ aUserIncentiveData.rewardTokenDecimals = IERC20Detailed (aRewardToken).decimals ();
232+ }
233+ } catch (bytes memory /*lowLevelData*/ ) {
234+
235+ }
236+
237+ userReservesIncentivesData[i].aTokenIncentivesUserData = aUserIncentiveData;
238+
239+ UserIncentiveData memory vUserIncentiveData;
240+
241+ try IVariableDebtToken (baseData.variableDebtTokenAddress).getIncentivesController () returns (IAaveIncentivesController vTokenIncentiveController ) {
242+ if (address (vTokenIncentiveController) != address (0 )) {
243+ address vRewardToken = vTokenIncentiveController.REWARD_TOKEN ();
244+ vUserIncentiveData.tokenincentivesUserIndex = vTokenIncentiveController.getUserAssetData (
245+ user,
246+ baseData.variableDebtTokenAddress
247+ );
248+ vUserIncentiveData.userUnclaimedRewards = vTokenIncentiveController.getUserUnclaimedRewards (
249+ user
250+ );
251+ vUserIncentiveData.tokenAddress = baseData.variableDebtTokenAddress;
252+ vUserIncentiveData.rewardTokenAddress = vRewardToken;
253+ vUserIncentiveData.incentiveControllerAddress = address (vTokenIncentiveController);
254+ vUserIncentiveData.rewardTokenDecimals = IERC20Detailed (vRewardToken).decimals ();
255+ }
256+ } catch (bytes memory /*lowLevelData*/ ) {
257+
258+ }
259+
260+ userReservesIncentivesData[i].vTokenIncentivesUserData = vUserIncentiveData;
261+
262+ UserIncentiveData memory sUserIncentiveData;
263+
264+ try IStableDebtToken (baseData.stableDebtTokenAddress).getIncentivesController () returns (IAaveIncentivesController sTokenIncentiveController ) {
265+ if (address (sTokenIncentiveController) != address (0 )) {
266+ address sRewardToken = sTokenIncentiveController.REWARD_TOKEN ();
267+ sUserIncentiveData.tokenincentivesUserIndex = sTokenIncentiveController.getUserAssetData (
268+ user,
269+ baseData.stableDebtTokenAddress
270+ );
271+ sUserIncentiveData.userUnclaimedRewards = sTokenIncentiveController.getUserUnclaimedRewards (
272+ user
273+ );
274+ sUserIncentiveData.tokenAddress = baseData.stableDebtTokenAddress;
275+ sUserIncentiveData.rewardTokenAddress = sRewardToken;
276+ sUserIncentiveData.incentiveControllerAddress = address (sTokenIncentiveController);
277+ sUserIncentiveData.rewardTokenDecimals = IERC20Detailed (sRewardToken).decimals ();
278+ }
279+ } catch (bytes memory /*lowLevelData*/ ) {
280+
281+ }
282+
283+ userReservesIncentivesData[i].sTokenIncentivesUserData = sUserIncentiveData;
284+ }
285+
286+ return (userReservesIncentivesData);
287+ }
288+ }
0 commit comments