-
Notifications
You must be signed in to change notification settings - Fork 45
/
AaveProtocolDataProvider.sol
295 lines (258 loc) · 9.97 KB
/
AaveProtocolDataProvider.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detailed.sol';
import {ReserveConfiguration} from '../protocol/libraries/configuration/ReserveConfiguration.sol';
import {UserConfiguration} from '../protocol/libraries/configuration/UserConfiguration.sol';
import {DataTypes} from '../protocol/libraries/types/DataTypes.sol';
import {WadRayMath} from '../protocol/libraries/math/WadRayMath.sol';
import {IPoolAddressesProvider} from '../interfaces/IPoolAddressesProvider.sol';
import {IVariableDebtToken} from '../interfaces/IVariableDebtToken.sol';
import {IPool} from '../interfaces/IPool.sol';
import {IPoolDataProvider} from '../interfaces/IPoolDataProvider.sol';
/**
* @title AaveProtocolDataProvider
* @author Aave
* @notice Peripheral contract to collect and pre-process information from the Pool.
*/
contract AaveProtocolDataProvider is IPoolDataProvider {
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;
using UserConfiguration for DataTypes.UserConfigurationMap;
using WadRayMath for uint256;
address constant MKR = 0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2;
address constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
/// @inheritdoc IPoolDataProvider
IPoolAddressesProvider public immutable ADDRESSES_PROVIDER;
/**
* @notice Constructor
* @param addressesProvider The address of the PoolAddressesProvider contract
*/
constructor(IPoolAddressesProvider addressesProvider) {
ADDRESSES_PROVIDER = addressesProvider;
}
/// @inheritdoc IPoolDataProvider
function getAllReservesTokens() external view override returns (TokenData[] memory) {
IPool pool = IPool(ADDRESSES_PROVIDER.getPool());
address[] memory reserves = pool.getReservesList();
TokenData[] memory reservesTokens = new TokenData[](reserves.length);
for (uint256 i = 0; i < reserves.length; i++) {
if (reserves[i] == MKR) {
reservesTokens[i] = TokenData({symbol: 'MKR', tokenAddress: reserves[i]});
continue;
}
if (reserves[i] == ETH) {
reservesTokens[i] = TokenData({symbol: 'ETH', tokenAddress: reserves[i]});
continue;
}
reservesTokens[i] = TokenData({
symbol: IERC20Detailed(reserves[i]).symbol(),
tokenAddress: reserves[i]
});
}
return reservesTokens;
}
/// @inheritdoc IPoolDataProvider
function getAllATokens() external view override returns (TokenData[] memory) {
IPool pool = IPool(ADDRESSES_PROVIDER.getPool());
address[] memory reserves = pool.getReservesList();
TokenData[] memory aTokens = new TokenData[](reserves.length);
for (uint256 i = 0; i < reserves.length; i++) {
DataTypes.ReserveDataLegacy memory reserveData = pool.getReserveData(reserves[i]);
aTokens[i] = TokenData({
symbol: IERC20Detailed(reserveData.aTokenAddress).symbol(),
tokenAddress: reserveData.aTokenAddress
});
}
return aTokens;
}
/// @inheritdoc IPoolDataProvider
function getReserveConfigurationData(
address asset
)
external
view
override
returns (
uint256 decimals,
uint256 ltv,
uint256 liquidationThreshold,
uint256 liquidationBonus,
uint256 reserveFactor,
bool usageAsCollateralEnabled,
bool borrowingEnabled,
bool stableBorrowRateEnabled,
bool isActive,
bool isFrozen
)
{
DataTypes.ReserveConfigurationMap memory configuration = IPool(ADDRESSES_PROVIDER.getPool())
.getConfiguration(asset);
(ltv, liquidationThreshold, liquidationBonus, decimals, reserveFactor) = configuration
.getParams();
(isActive, isFrozen, borrowingEnabled, ) = configuration.getFlags();
// @notice all stable debt related parameters deprecated in v3.2.0
stableBorrowRateEnabled = false;
usageAsCollateralEnabled = liquidationThreshold != 0;
}
/// @inheritdoc IPoolDataProvider
function getReserveCaps(
address asset
) external view override returns (uint256 borrowCap, uint256 supplyCap) {
(borrowCap, supplyCap) = IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getCaps();
}
/// @inheritdoc IPoolDataProvider
function getPaused(address asset) external view override returns (bool isPaused) {
(, , , isPaused) = IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getFlags();
}
/// @inheritdoc IPoolDataProvider
function getSiloedBorrowing(address asset) external view override returns (bool) {
return IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getSiloedBorrowing();
}
/// @inheritdoc IPoolDataProvider
function getLiquidationProtocolFee(address asset) external view override returns (uint256) {
return IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getLiquidationProtocolFee();
}
/// @inheritdoc IPoolDataProvider
function getUnbackedMintCap(address asset) external view override returns (uint256) {
return IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getUnbackedMintCap();
}
/// @inheritdoc IPoolDataProvider
function getDebtCeiling(address asset) external view override returns (uint256) {
return IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getDebtCeiling();
}
/// @inheritdoc IPoolDataProvider
function getDebtCeilingDecimals() external pure override returns (uint256) {
return ReserveConfiguration.DEBT_CEILING_DECIMALS;
}
/// @inheritdoc IPoolDataProvider
function getReserveData(
address asset
)
external
view
override
returns (
uint256 unbacked,
uint256 accruedToTreasuryScaled,
uint256 totalAToken,
uint256,
uint256 totalVariableDebt,
uint256 liquidityRate,
uint256 variableBorrowRate,
uint256,
uint256,
uint256 liquidityIndex,
uint256 variableBorrowIndex,
uint40 lastUpdateTimestamp
)
{
DataTypes.ReserveDataLegacy memory reserve = IPool(ADDRESSES_PROVIDER.getPool()).getReserveData(
asset
);
// @notice all stable debt related parameters deprecated in v3.2.0
return (
reserve.unbacked,
reserve.accruedToTreasury,
IERC20Detailed(reserve.aTokenAddress).totalSupply(),
0,
IERC20Detailed(reserve.variableDebtTokenAddress).totalSupply(),
reserve.currentLiquidityRate,
reserve.currentVariableBorrowRate,
0,
0,
reserve.liquidityIndex,
reserve.variableBorrowIndex,
reserve.lastUpdateTimestamp
);
}
/// @inheritdoc IPoolDataProvider
function getATokenTotalSupply(address asset) external view override returns (uint256) {
DataTypes.ReserveDataLegacy memory reserve = IPool(ADDRESSES_PROVIDER.getPool()).getReserveData(
asset
);
return IERC20Detailed(reserve.aTokenAddress).totalSupply();
}
/// @inheritdoc IPoolDataProvider
function getTotalDebt(address asset) external view override returns (uint256) {
DataTypes.ReserveDataLegacy memory reserve = IPool(ADDRESSES_PROVIDER.getPool()).getReserveData(
asset
);
return IERC20Detailed(reserve.variableDebtTokenAddress).totalSupply();
}
/// @inheritdoc IPoolDataProvider
function getUserReserveData(
address asset,
address user
)
external
view
override
returns (
uint256 currentATokenBalance,
uint256 currentStableDebt,
uint256 currentVariableDebt,
uint256 principalStableDebt,
uint256 scaledVariableDebt,
uint256 stableBorrowRate,
uint256 liquidityRate,
uint40 stableRateLastUpdated,
bool usageAsCollateralEnabled
)
{
DataTypes.ReserveDataLegacy memory reserve = IPool(ADDRESSES_PROVIDER.getPool()).getReserveData(
asset
);
DataTypes.UserConfigurationMap memory userConfig = IPool(ADDRESSES_PROVIDER.getPool())
.getUserConfiguration(user);
currentATokenBalance = IERC20Detailed(reserve.aTokenAddress).balanceOf(user);
currentVariableDebt = IERC20Detailed(reserve.variableDebtTokenAddress).balanceOf(user);
// @notice all stable debt related parameters deprecated in v3.2.0
currentStableDebt = principalStableDebt = stableBorrowRate = stableRateLastUpdated = 0;
scaledVariableDebt = IVariableDebtToken(reserve.variableDebtTokenAddress).scaledBalanceOf(user);
liquidityRate = reserve.currentLiquidityRate;
usageAsCollateralEnabled = userConfig.isUsingAsCollateral(reserve.id);
}
/// @inheritdoc IPoolDataProvider
function getReserveTokensAddresses(
address asset
)
external
view
override
returns (
address aTokenAddress,
address stableDebtTokenAddress,
address variableDebtTokenAddress
)
{
DataTypes.ReserveDataLegacy memory reserve = IPool(ADDRESSES_PROVIDER.getPool()).getReserveData(
asset
);
// @notice all stable debt related parameters deprecated in v3.2.0
return (reserve.aTokenAddress, address(0), reserve.variableDebtTokenAddress);
}
/// @inheritdoc IPoolDataProvider
function getInterestRateStrategyAddress(
address asset
) external view override returns (address irStrategyAddress) {
DataTypes.ReserveDataLegacy memory reserve = IPool(ADDRESSES_PROVIDER.getPool()).getReserveData(
asset
);
return (reserve.interestRateStrategyAddress);
}
/// @inheritdoc IPoolDataProvider
function getFlashLoanEnabled(address asset) external view override returns (bool) {
DataTypes.ReserveConfigurationMap memory configuration = IPool(ADDRESSES_PROVIDER.getPool())
.getConfiguration(asset);
return configuration.getFlashLoanEnabled();
}
/// @inheritdoc IPoolDataProvider
function getIsVirtualAccActive(address asset) external view override returns (bool) {
DataTypes.ReserveConfigurationMap memory configuration = IPool(ADDRESSES_PROVIDER.getPool())
.getConfiguration(asset);
return configuration.getIsVirtualAccActive();
}
/// @inheritdoc IPoolDataProvider
function getVirtualUnderlyingBalance(address asset) external view override returns (uint256) {
return IPool(ADDRESSES_PROVIDER.getPool()).getVirtualUnderlyingBalance(asset);
}
}