-
Notifications
You must be signed in to change notification settings - Fork 727
/
UiIncentiveDataProvider.sol
187 lines (156 loc) · 7.19 KB
/
UiIncentiveDataProvider.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
import {IAaveIncentivesController} from '../interfaces/IAaveIncentivesController.sol';
import {IUiIncentiveDataProvider} from './interfaces/IUiIncentiveDataProvider.sol';
import {ILendingPool} from '../interfaces/ILendingPool.sol';
import {IAToken} from '../interfaces/IAToken.sol';
import {IVariableDebtToken} from '../interfaces/IVariableDebtToken.sol';
import {IStableDebtToken} from '../interfaces/IStableDebtToken.sol';
import {UserConfiguration} from '../protocol/libraries/configuration/UserConfiguration.sol';
import {DataTypes} from '../protocol/libraries/types/DataTypes.sol';
contract UiIncentiveDataProvider is IUiIncentiveDataProvider {
using UserConfiguration for DataTypes.UserConfigurationMap;
constructor() public {}
function getFullReservesIncentiveData(ILendingPoolAddressesProvider provider, address user)
external
view
override
returns (AggregatedReserveIncentiveData[] memory, UserReserveIncentiveData[] memory)
{
return (_getReservesIncentivesData(provider), _getUserReservesIncentivesData(provider, user));
}
function getReservesIncentivesData(ILendingPoolAddressesProvider provider)
external
view
override
returns (AggregatedReserveIncentiveData[] memory)
{
return _getReservesIncentivesData(provider);
}
function _getReservesIncentivesData(ILendingPoolAddressesProvider provider)
private
view
returns (AggregatedReserveIncentiveData[] memory)
{
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
address[] memory reserves = lendingPool.getReservesList();
AggregatedReserveIncentiveData[] memory reservesIncentiveData =
new AggregatedReserveIncentiveData[](reserves.length);
for (uint256 i = 0; i < reserves.length; i++) {
AggregatedReserveIncentiveData memory reserveIncentiveData = reservesIncentiveData[i];
reserveIncentiveData.underlyingAsset = reserves[i];
DataTypes.ReserveData memory baseData = lendingPool.getReserveData(reserves[i]);
IAaveIncentivesController aTokenIncentiveController =
IAToken(baseData.aTokenAddress).getIncentivesController();
(
uint256 aEmissionPerSecond,
uint256 aIncentivesLastUpdateTimestamp,
uint256 aTokenIncentivesIndex
) = aTokenIncentiveController.assets(baseData.aTokenAddress);
reserveIncentiveData.aIncentiveData = IncentiveData(
aEmissionPerSecond,
aIncentivesLastUpdateTimestamp,
aTokenIncentivesIndex,
aTokenIncentiveController.DISTRIBUTION_END(),
baseData.aTokenAddress,
aTokenIncentiveController.REWARD_TOKEN()
);
IAaveIncentivesController sTokenIncentiveController =
IStableDebtToken(baseData.stableDebtTokenAddress).getIncentivesController();
(
uint256 sEmissionPerSecond,
uint256 sIncentivesLastUpdateTimestamp,
uint256 sTokenIncentivesIndex
) = sTokenIncentiveController.assets(baseData.stableDebtTokenAddress);
reserveIncentiveData.sIncentiveData = IncentiveData(
sEmissionPerSecond,
sIncentivesLastUpdateTimestamp,
sTokenIncentivesIndex,
sTokenIncentiveController.DISTRIBUTION_END(),
baseData.stableDebtTokenAddress,
sTokenIncentiveController.REWARD_TOKEN()
);
IAaveIncentivesController vTokenIncentiveController =
IVariableDebtToken(baseData.variableDebtTokenAddress).getIncentivesController();
(
uint256 vEmissionPerSecond,
uint256 vIncentivesLastUpdateTimestamp,
uint256 vTokenIncentivesIndex
) = vTokenIncentiveController.assets(baseData.variableDebtTokenAddress);
reserveIncentiveData.vIncentiveData = IncentiveData(
vEmissionPerSecond,
vIncentivesLastUpdateTimestamp,
vTokenIncentivesIndex,
vTokenIncentiveController.DISTRIBUTION_END(),
baseData.variableDebtTokenAddress,
vTokenIncentiveController.REWARD_TOKEN()
);
}
return (reservesIncentiveData);
}
function getUserReservesIncentivesData(ILendingPoolAddressesProvider provider, address user)
external
view
override
returns (UserReserveIncentiveData[] memory)
{
return _getUserReservesIncentivesData(provider, user);
}
function _getUserReservesIncentivesData(ILendingPoolAddressesProvider provider, address user)
private
view
returns (UserReserveIncentiveData[] memory)
{
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
address[] memory reserves = lendingPool.getReservesList();
UserReserveIncentiveData[] memory userReservesIncentivesData =
new UserReserveIncentiveData[](user != address(0) ? reserves.length : 0);
for (uint256 i = 0; i < reserves.length; i++) {
DataTypes.ReserveData memory baseData = lendingPool.getReserveData(reserves[i]);
// user reserve data
userReservesIncentivesData[i].underlyingAsset = reserves[i];
IAaveIncentivesController aTokenIncentiveController =
IAToken(baseData.aTokenAddress).getIncentivesController();
IUiIncentiveDataProvider.UserIncentiveData memory aUserIncentiveData;
aUserIncentiveData.tokenincentivesUserIndex = aTokenIncentiveController.getUserAssetData(
user,
baseData.aTokenAddress
);
aUserIncentiveData.userUnclaimedRewards = aTokenIncentiveController.getUserUnclaimedRewards(
user
);
aUserIncentiveData.tokenAddress = baseData.aTokenAddress;
aUserIncentiveData.rewardTokenAddress = aTokenIncentiveController.REWARD_TOKEN();
userReservesIncentivesData[i].aTokenIncentivesUserData = aUserIncentiveData;
IAaveIncentivesController vTokenIncentiveController =
IVariableDebtToken(baseData.variableDebtTokenAddress).getIncentivesController();
UserIncentiveData memory vUserIncentiveData;
vUserIncentiveData.tokenincentivesUserIndex = vTokenIncentiveController.getUserAssetData(
user,
baseData.variableDebtTokenAddress
);
vUserIncentiveData.userUnclaimedRewards = vTokenIncentiveController.getUserUnclaimedRewards(
user
);
vUserIncentiveData.tokenAddress = baseData.variableDebtTokenAddress;
vUserIncentiveData.rewardTokenAddress = vTokenIncentiveController.REWARD_TOKEN();
userReservesIncentivesData[i].vTokenIncentivesUserData = vUserIncentiveData;
IAaveIncentivesController sTokenIncentiveController =
IStableDebtToken(baseData.stableDebtTokenAddress).getIncentivesController();
UserIncentiveData memory sUserIncentiveData;
sUserIncentiveData.tokenincentivesUserIndex = sTokenIncentiveController.getUserAssetData(
user,
baseData.stableDebtTokenAddress
);
sUserIncentiveData.userUnclaimedRewards = sTokenIncentiveController.getUserUnclaimedRewards(
user
);
sUserIncentiveData.tokenAddress = baseData.stableDebtTokenAddress;
sUserIncentiveData.rewardTokenAddress = sTokenIncentiveController.REWARD_TOKEN();
userReservesIncentivesData[i].sTokenIncentivesUserData = sUserIncentiveData;
}
return (userReservesIncentivesData);
}
}