forked from aave-dao/aave-proposals-v3
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHorizonConfigAssertionHelper.sol
More file actions
603 lines (544 loc) · 24.4 KB
/
Copy pathHorizonConfigAssertionHelper.sol
File metadata and controls
603 lines (544 loc) · 24.4 KB
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Test} from 'forge-std/Test.sol';
import {AggregatorInterface} from 'aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src/contracts/dependencies/chainlink/AggregatorInterface.sol';
import {IERC20} from 'aave-helpers/lib/aave-address-book/lib/aave-v3-origin/lib/forge-std/src/interfaces/IERC20.sol';
import {IERC20Metadata} from 'aave-helpers/lib/aave-address-book/lib/aave-v3-origin/lib/solidity-utils/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol';
import {IPool} from 'aave-v3-origin/contracts/interfaces/IPool.sol';
import {IAaveOracle} from 'aave-v3-origin/contracts/interfaces/IAaveOracle.sol';
import {IPriceOracleGetter} from 'aave-v3-origin/contracts/interfaces/IPriceOracleGetter.sol';
import {IACLManager} from 'aave-v3-origin/contracts/interfaces/IACLManager.sol';
import {IPoolAddressesProvider} from 'aave-v3-origin/contracts/interfaces/IPoolAddressesProvider.sol';
import {IDefaultInterestRateStrategyV2} from 'aave-v3-origin/contracts/interfaces/IDefaultInterestRateStrategyV2.sol';
import {DataTypes} from 'aave-v3-origin/contracts/protocol/libraries/types/DataTypes.sol';
import {ReserveConfiguration} from 'aave-v3-origin/contracts/protocol/libraries/configuration/ReserveConfiguration.sol';
import {EModeConfiguration} from 'aave-v3-origin/contracts/protocol/libraries/configuration/EModeConfiguration.sol';
import {IncentivizedERC20} from 'aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src/contracts/protocol/tokenization/base/IncentivizedERC20.sol';
import {ReserveConfig} from 'aave-helpers/src/ProtocolV3TestBase.sol';
import {IRwaOracleParameterRegistry} from 'src/interfaces/IRwaOracleParameterRegistry.sol';
import {AaveV3EthereumHorizonCustom} from 'src/utils/AaveV3EthereumHorizonCustom.sol';
import {AaveV3EthereumHorizon, AaveV3EthereumHorizonAssets} from 'aave-address-book-latest/AaveV3EthereumHorizon.sol';
import {Errors} from 'src/dependencies/Errors.sol';
/**
* @dev Config assertion helpers for Horizon proposals. Verifies that a payload
* set the exact intended parameter values for newly listed assets and eModes.
*
* Also provides pool-wide validations (oracle prices, aToken implementations,
* config sanity) that run automatically on every proposal test.
*/
abstract contract HorizonConfigAssertionHelper is Test {
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;
using EModeConfiguration for uint128;
struct ExpectedAssetConfig {
address underlying;
bool isRwa;
address oracle;
string aTokenName;
string aTokenSymbol;
string variableDebtTokenName;
string variableDebtTokenSymbol;
uint256 supplyCap;
uint256 borrowCap;
uint256 reserveFactor;
bool borrowingEnabled;
bool flashloanable;
uint256 ltv;
uint256 liquidationThreshold;
uint256 liquidationBonus;
uint256 debtCeiling;
uint256 liqProtocolFee;
// interest rate strategy params (in bps)
IDefaultInterestRateStrategyV2.InterestRateData rateData;
}
struct ExpectedEModeConfig {
uint8 eModeCategory;
uint256 ltv;
uint256 liquidationThreshold;
uint256 liquidationBonus;
string label;
address[] collateralAssets;
address[] borrowableAssets;
}
bytes32 internal constant EIP1967_IMPL_SLOT =
bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1);
// ─── Per-asset config assertions ───────────────────────────────────
function _assertAssetConfig(IPool pool, ExpectedAssetConfig memory expected) internal {
_assertReserveConfiguration(pool, expected);
_assertAToken(pool, expected);
_assertVariableDebtToken(pool, expected);
_assertPriceFeed(pool, expected);
_assertInterestRateStrategy(expected);
if (expected.isRwa) {
_assertRwaConfig(pool, expected.underlying);
}
// full struct encode comparison sanity check
ExpectedAssetConfig memory actual = _readAssetConfig(pool, expected.underlying);
assertEq(abi.encode(actual), abi.encode(expected), 'asset config: full struct mismatch');
}
function _assertRwaConfig(IPool pool, address underlying) internal {
_assertRwaOracleRegistry(underlying);
_assertRwaATokenApproveReverts(pool, underlying);
_assertRwaATokenTransferReverts(pool, underlying);
_assertRwaReserveConfigurationSanityCheck(pool, underlying);
}
function _assertRwaReserveConfigurationSanityCheck(IPool pool, address underlying) internal view {
DataTypes.ReserveConfigurationMap memory config = pool.getConfiguration(underlying);
assertEq(config.getBorrowingEnabled(), false, 'borrowingEnabled');
assertEq(config.getFlashLoanEnabled(), false, 'flashloanable');
assertEq(config.getLiquidationProtocolFee(), 0, 'liquidationProtocolFee');
}
function _assertReserveConfiguration(
IPool pool,
ExpectedAssetConfig memory expected
) internal view {
DataTypes.ReserveConfigurationMap memory config = pool.getConfiguration(expected.underlying);
assertEq(config.getSupplyCap(), expected.supplyCap, 'supplyCap');
assertEq(config.getBorrowCap(), expected.borrowCap, 'borrowCap');
assertEq(config.getBorrowingEnabled(), expected.borrowingEnabled, 'borrowingEnabled');
assertEq(config.getFlashLoanEnabled(), expected.flashloanable, 'flashloanable');
assertEq(config.getReserveFactor(), expected.reserveFactor, 'reserveFactor');
assertEq(config.getLtv(), expected.ltv, 'ltv');
assertEq(
config.getLiquidationThreshold(),
expected.liquidationThreshold,
'liquidationThreshold'
);
assertEq(config.getLiquidationBonus(), expected.liquidationBonus, 'liquidationBonus');
assertEq(config.getDebtCeiling(), expected.debtCeiling, 'debtCeiling');
assertEq(config.getLiquidationProtocolFee(), expected.liqProtocolFee, 'liqProtocolFee');
assertEq(config.getPaused(), false, 'paused');
assertEq(
abi.encode(config),
abi.encode(_toConfigMap(pool, expected)),
'reserve config bitmap mismatch'
);
}
function _assertAToken(IPool pool, ExpectedAssetConfig memory expected) internal view {
address aToken = pool.getReserveAToken(expected.underlying);
assertEq(IERC20Metadata(aToken).name(), expected.aTokenName, 'aTokenName');
assertEq(IERC20Metadata(aToken).symbol(), expected.aTokenSymbol, 'aTokenSymbol');
address impl = _getProxyImplementation(aToken);
if (expected.isRwa) {
assertTrue(_isRwaATokenImpl(impl), 'rwaATokenImpl');
} else {
assertTrue(_isStandardATokenImpl(impl), 'aTokenImpl');
}
assertEq(
address(IncentivizedERC20(aToken).getIncentivesController()),
AaveV3EthereumHorizon.DEFAULT_INCENTIVES_CONTROLLER,
'aToken incentivesController'
);
}
function _assertVariableDebtToken(IPool pool, ExpectedAssetConfig memory expected) internal view {
address variableDebtToken = pool.getReserveVariableDebtToken(expected.underlying);
assertEq(
IERC20Metadata(variableDebtToken).name(),
expected.variableDebtTokenName,
'variableDebtTokenName'
);
assertEq(
IERC20Metadata(variableDebtToken).symbol(),
expected.variableDebtTokenSymbol,
'variableDebtTokenSymbol'
);
address impl = address(uint160(uint256(vm.load(variableDebtToken, EIP1967_IMPL_SLOT))));
assertEq(
impl,
AaveV3EthereumHorizonCustom.DEFAULT_VARIABLE_DEBT_TOKEN_IMPL,
'variableDebtTokenImpl'
);
assertEq(
address(IncentivizedERC20(variableDebtToken).getIncentivesController()),
AaveV3EthereumHorizon.DEFAULT_INCENTIVES_CONTROLLER,
'variableDebtToken incentivesController'
);
}
function _assertPriceFeed(IPool pool, ExpectedAssetConfig memory expected) internal view {
IAaveOracle oracle = IAaveOracle(
IPoolAddressesProvider(pool.ADDRESSES_PROVIDER()).getPriceOracle()
);
address source = oracle.getSourceOfAsset(expected.underlying);
assertEq(source, expected.oracle, 'oracleSource');
uint256 price = oracle.getAssetPrice(expected.underlying);
assertGt(price, 0, 'oraclePrice');
assertEq(AggregatorInterface(source).decimals(), 8, 'oracleDecimals');
}
function _assertInterestRateStrategy(ExpectedAssetConfig memory expected) internal view {
IDefaultInterestRateStrategyV2 strategy = IDefaultInterestRateStrategyV2(
AaveV3EthereumHorizonCustom.DEFAULT_INTEREST_RATE_STRATEGY
);
IDefaultInterestRateStrategyV2.InterestRateData memory rateData = strategy
.getInterestRateDataBps(expected.underlying);
assertEq(rateData.optimalUsageRatio, expected.rateData.optimalUsageRatio, 'optimalUsageRatio');
assertEq(
rateData.baseVariableBorrowRate,
expected.rateData.baseVariableBorrowRate,
'baseVariableBorrowRate'
);
assertEq(
rateData.variableRateSlope1,
expected.rateData.variableRateSlope1,
'variableRateSlope1'
);
assertEq(
rateData.variableRateSlope2,
expected.rateData.variableRateSlope2,
'variableRateSlope2'
);
assertEq(
abi.encode(rateData),
abi.encode(expected.rateData),
'interestRateData: struct mismatch'
);
}
function _assertRwaOracleRegistry(address underlying) internal view {
assertTrue(
IRwaOracleParameterRegistry(AaveV3EthereumHorizonCustom.RWA_ORACLE_PARAMS_REGISTRY)
.assetExists(underlying),
'rwaOracleRegistry: asset not registered'
);
}
function _assertRwaATokenApproveReverts(IPool pool, address underlying) internal {
address aToken = pool.getReserveAToken(underlying);
// rwa aTokens do not support approve
vm.expectRevert(bytes(Errors.OPERATION_NOT_SUPPORTED));
IERC20(aToken).approve(makeAddr('tmpUser'), 0);
}
function _assertRwaATokenTransferReverts(IPool pool, address underlying) internal virtual {
address aToken = pool.getReserveAToken(underlying);
// rwa aTokens do not support transfers
vm.prank(makeAddr('rwaTransferSender'));
vm.expectRevert(bytes(Errors.OPERATION_NOT_SUPPORTED));
IERC20(aToken).transfer(makeAddr('nonWhitelistedUser'), 0);
}
// ─── eMode config assertions ──────────────────────────────────────
function _assertEModeConfig(IPool pool, ExpectedEModeConfig memory expected) internal view {
DataTypes.CollateralConfig memory cc = pool.getEModeCategoryCollateralConfig(
expected.eModeCategory
);
assertEq(cc.ltv, expected.ltv, 'emode.ltv');
assertEq(cc.liquidationThreshold, expected.liquidationThreshold, 'emode.liquidationThreshold');
assertEq(cc.liquidationBonus, expected.liquidationBonus, 'emode.liquidationBonus');
assertEq(pool.getEModeCategoryLabel(expected.eModeCategory), expected.label, 'emode.label');
// verify collateral bitmap
uint128 collateralBitmap = pool.getEModeCategoryCollateralBitmap(expected.eModeCategory);
uint128 expectedCollateralBitmap;
for (uint256 i; i < expected.collateralAssets.length; i++) {
uint256 reserveId = pool.getReserveData(expected.collateralAssets[i]).id;
assertTrue(
collateralBitmap.isReserveEnabledOnBitmap(reserveId),
string.concat('emode.collateral missing ', vm.toString(expected.collateralAssets[i]))
);
expectedCollateralBitmap = expectedCollateralBitmap.setReserveBitmapBit(reserveId, true);
}
assertEq(collateralBitmap, expectedCollateralBitmap, 'emode.collateralBitmap');
// verify borrowable bitmap
uint128 borrowableBitmap = pool.getEModeCategoryBorrowableBitmap(expected.eModeCategory);
uint128 expectedBorrowableBitmap;
for (uint256 i; i < expected.borrowableAssets.length; i++) {
uint256 reserveId = pool.getReserveData(expected.borrowableAssets[i]).id;
assertTrue(
borrowableBitmap.isReserveEnabledOnBitmap(reserveId),
string.concat('emode.borrowable missing ', vm.toString(expected.borrowableAssets[i]))
);
expectedBorrowableBitmap = expectedBorrowableBitmap.setReserveBitmapBit(reserveId, true);
}
assertEq(borrowableBitmap, expectedBorrowableBitmap, 'emode.borrowableBitmap');
// encode comparison for scalar eMode fields
DataTypes.CollateralConfig memory expectedCC = DataTypes.CollateralConfig({
ltv: uint16(expected.ltv),
liquidationThreshold: uint16(expected.liquidationThreshold),
liquidationBonus: uint16(expected.liquidationBonus)
});
assertEq(abi.encode(cc), abi.encode(expectedCC), 'emode: collateral config struct mismatch');
}
// ─── Pool-wide validations ────────────────────────────────────────
function _runHorizonValidations(IPool pool, ReserveConfig[] memory configs) internal {
_validateAccessControl(pool);
_validateOracles(pool, configs);
_validateATokenImplementations(configs);
_validateRwaOracleRegistrations(configs);
_validateInterestRateStrategies(configs);
_validateConfigSanity(configs);
}
function _validateAccessControl(IPool pool) internal view {
IACLManager aclManager = IACLManager(
IPoolAddressesProvider(pool.ADDRESSES_PROVIDER()).getACLManager()
);
// HORIZON_EXECUTOR: AssetListingAdmin + RiskAdmin only (listing executor)
assertFalse(
aclManager.isPoolAdmin(AaveV3EthereumHorizonCustom.HORIZON_EXECUTOR),
'VALIDATION: executor should not be pool admin'
);
assertFalse(
aclManager.isEmergencyAdmin(AaveV3EthereumHorizonCustom.HORIZON_EXECUTOR),
'VALIDATION: executor should not be emergency admin'
);
assertTrue(
aclManager.isAssetListingAdmin(AaveV3EthereumHorizonCustom.HORIZON_EXECUTOR),
'VALIDATION: executor should be asset listing admin'
);
assertTrue(
aclManager.isRiskAdmin(AaveV3EthereumHorizonCustom.HORIZON_EXECUTOR),
'VALIDATION: executor should be risk admin'
);
// HORIZON_EMERGENCY: PoolAdmin + EmergencyAdmin only
assertTrue(
aclManager.isPoolAdmin(AaveV3EthereumHorizonCustom.HORIZON_EMERGENCY),
'VALIDATION: emergency should be pool admin'
);
assertTrue(
aclManager.isEmergencyAdmin(AaveV3EthereumHorizonCustom.HORIZON_EMERGENCY),
'VALIDATION: emergency should be emergency admin'
);
assertFalse(
aclManager.isAssetListingAdmin(AaveV3EthereumHorizonCustom.HORIZON_EMERGENCY),
'VALIDATION: emergency should not be asset listing admin'
);
assertFalse(
aclManager.isRiskAdmin(AaveV3EthereumHorizonCustom.HORIZON_EMERGENCY),
'VALIDATION: emergency should not be risk admin'
);
// HORIZON_OPS: RiskAdmin only (operational multisig)
assertFalse(
aclManager.isPoolAdmin(AaveV3EthereumHorizonCustom.HORIZON_OPS),
'VALIDATION: ops should not be pool admin'
);
assertFalse(
aclManager.isEmergencyAdmin(AaveV3EthereumHorizonCustom.HORIZON_OPS),
'VALIDATION: ops should not be emergency admin'
);
assertFalse(
aclManager.isAssetListingAdmin(AaveV3EthereumHorizonCustom.HORIZON_OPS),
'VALIDATION: ops should not be asset listing admin'
);
assertTrue(
aclManager.isRiskAdmin(AaveV3EthereumHorizonCustom.HORIZON_OPS),
'VALIDATION: ops should be risk admin'
);
}
function _validateOracles(IPool pool, ReserveConfig[] memory configs) internal view {
IAaveOracle oracle = IAaveOracle(
IPoolAddressesProvider(pool.ADDRESSES_PROVIDER()).getPriceOracle()
);
for (uint256 i; i < configs.length; i++) {
uint256 price = oracle.getAssetPrice(configs[i].underlying);
assertTrue(price > 0, string.concat('VALIDATION: zero oracle price for ', configs[i].symbol));
address source = oracle.getSourceOfAsset(configs[i].underlying);
assertEq(
AggregatorInterface(source).decimals(),
8,
string.concat('VALIDATION: unexpected oracle decimals for ', configs[i].symbol)
);
address expectedFeed = _expectedPriceFeed(configs[i].underlying);
assertEq(
source,
expectedFeed,
string.concat('VALIDATION: oracle source mismatch for ', configs[i].symbol)
);
}
}
function _expectedPriceFeed(address underlying) internal pure virtual returns (address) {
if (underlying == AaveV3EthereumHorizonAssets.USTB_UNDERLYING) {
return AaveV3EthereumHorizonAssets.USTB_ORACLE;
}
if (underlying == AaveV3EthereumHorizonAssets.USCC_UNDERLYING) {
return AaveV3EthereumHorizonAssets.USCC_ORACLE;
}
if (underlying == AaveV3EthereumHorizonAssets.USYC_UNDERLYING) {
return AaveV3EthereumHorizonAssets.USYC_ORACLE;
}
if (underlying == AaveV3EthereumHorizonAssets.JTRSY_UNDERLYING) {
return AaveV3EthereumHorizonAssets.JTRSY_ORACLE;
}
if (underlying == AaveV3EthereumHorizonAssets.JAAA_UNDERLYING) {
return AaveV3EthereumHorizonAssets.JAAA_ORACLE;
}
if (underlying == AaveV3EthereumHorizonAssets.VBILL_UNDERLYING) {
return AaveV3EthereumHorizonAssets.VBILL_ORACLE;
}
if (underlying == AaveV3EthereumHorizonAssets.GHO_UNDERLYING) {
return AaveV3EthereumHorizonAssets.GHO_ORACLE;
}
if (underlying == AaveV3EthereumHorizonAssets.USDC_UNDERLYING) {
return AaveV3EthereumHorizonAssets.USDC_ORACLE;
}
if (underlying == AaveV3EthereumHorizonAssets.RLUSD_UNDERLYING) {
return AaveV3EthereumHorizonAssets.RLUSD_ORACLE;
}
if (underlying == AaveV3EthereumHorizonCustom.ACRED_UNDERLYING) {
return AaveV3EthereumHorizonCustom.ACRED_PRICE_FEED;
}
if (underlying == AaveV3EthereumHorizonCustom.MGLOBAL_UNDERLYING) {
return AaveV3EthereumHorizonCustom.MGLOBAL_PRICE_FEED;
}
revert('_expectedPriceFeed: unknown underlying');
}
function _validateATokenImplementations(ReserveConfig[] memory configs) internal {
for (uint256 i; i < configs.length; i++) {
address impl = _getProxyImplementation(configs[i].aToken);
bool isRwa = _isRwaATokenImpl(impl);
bool isStandard = _isStandardATokenImpl(impl);
assertTrue(
isRwa || isStandard,
string.concat('VALIDATION: unknown aToken impl for ', configs[i].symbol)
);
if (isRwa) {
// rwa aTokens do not support approve
vm.expectRevert(bytes(Errors.OPERATION_NOT_SUPPORTED));
IERC20(configs[i].aToken).approve(address(1), 0);
}
// verify incentives controller on aToken
assertEq(
address(IncentivizedERC20(configs[i].aToken).getIncentivesController()),
AaveV3EthereumHorizon.DEFAULT_INCENTIVES_CONTROLLER,
string.concat('VALIDATION: unexpected aToken incentivesController for ', configs[i].symbol)
);
// verify incentives controller on variable debt token
assertEq(
address(IncentivizedERC20(configs[i].variableDebtToken).getIncentivesController()),
AaveV3EthereumHorizon.DEFAULT_INCENTIVES_CONTROLLER,
string.concat(
'VALIDATION: unexpected variableDebtToken incentivesController for ',
configs[i].symbol
)
);
}
}
function _validateRwaOracleRegistrations(ReserveConfig[] memory configs) internal view {
for (uint256 i; i < configs.length; i++) {
if (_isRwaAToken(configs[i].aToken)) {
assertTrue(
IRwaOracleParameterRegistry(AaveV3EthereumHorizonCustom.RWA_ORACLE_PARAMS_REGISTRY)
.assetExists(configs[i].underlying),
string.concat('VALIDATION: RWA not in oracle registry for ', configs[i].symbol)
);
}
}
}
function _validateInterestRateStrategies(ReserveConfig[] memory configs) internal view {
IDefaultInterestRateStrategyV2 strategy = IDefaultInterestRateStrategyV2(
AaveV3EthereumHorizonCustom.DEFAULT_INTEREST_RATE_STRATEGY
);
for (uint256 i; i < configs.length; i++) {
assertEq(
configs[i].interestRateStrategy,
address(strategy),
string.concat('VALIDATION: unexpected IR strategy for ', configs[i].symbol)
);
IDefaultInterestRateStrategyV2.InterestRateData memory rateData = strategy
.getInterestRateDataBps(configs[i].underlying);
assertTrue(
rateData.optimalUsageRatio > 0,
string.concat('VALIDATION: zero optimalUsageRatio for ', configs[i].symbol)
);
}
}
function _validateConfigSanity(ReserveConfig[] memory configs) internal pure {
for (uint256 i; i < configs.length; i++) {
if (configs[i].usageAsCollateralEnabled) {
assertTrue(
configs[i].ltv <= configs[i].liquidationThreshold,
string.concat('VALIDATION: ltv > liquidationThreshold for ', configs[i].symbol)
);
}
}
}
// ─── Read on-chain config into struct ────────────────────────────
function _readAssetConfig(
IPool pool,
address underlying
) internal view returns (ExpectedAssetConfig memory c) {
c.underlying = underlying;
// aToken
address aToken = pool.getReserveAToken(underlying);
c.aTokenName = IERC20Metadata(aToken).name();
c.aTokenSymbol = IERC20Metadata(aToken).symbol();
c.isRwa = _isRwaAToken(aToken);
// variable debt token
address vDebt = pool.getReserveVariableDebtToken(underlying);
c.variableDebtTokenName = IERC20Metadata(vDebt).name();
c.variableDebtTokenSymbol = IERC20Metadata(vDebt).symbol();
// oracle
IAaveOracle oracle = IAaveOracle(
IPoolAddressesProvider(pool.ADDRESSES_PROVIDER()).getPriceOracle()
);
c.oracle = oracle.getSourceOfAsset(underlying);
// config map
DataTypes.ReserveConfigurationMap memory config = pool.getConfiguration(underlying);
c.supplyCap = config.getSupplyCap();
c.borrowCap = config.getBorrowCap();
c.borrowingEnabled = config.getBorrowingEnabled();
c.flashloanable = config.getFlashLoanEnabled();
c.reserveFactor = config.getReserveFactor();
c.ltv = config.getLtv();
c.liquidationThreshold = config.getLiquidationThreshold();
c.liquidationBonus = config.getLiquidationBonus();
c.debtCeiling = config.getDebtCeiling();
c.liqProtocolFee = config.getLiquidationProtocolFee();
// rate data
IDefaultInterestRateStrategyV2 strategy = IDefaultInterestRateStrategyV2(
AaveV3EthereumHorizonCustom.DEFAULT_INTEREST_RATE_STRATEGY
);
c.rateData = strategy.getInterestRateDataBps(underlying);
}
/**
* @dev Reconstructs a ReserveConfigurationMap from expected values.
* Protocol-set fields (decimals, active, frozen, etc.) are copied from on-chain
* so the comparison isolates proposal-controlled fields.
*/
function _toConfigMap(
IPool pool,
ExpectedAssetConfig memory expected
) internal view returns (DataTypes.ReserveConfigurationMap memory map) {
map = pool.getConfiguration(expected.underlying);
map.setLtv(expected.ltv);
map.setLiquidationThreshold(expected.liquidationThreshold);
map.setLiquidationBonus(expected.liquidationBonus);
map.setBorrowingEnabled(expected.borrowingEnabled);
map.setFlashLoanEnabled(expected.flashloanable);
map.setReserveFactor(expected.reserveFactor);
map.setBorrowCap(expected.borrowCap);
map.setSupplyCap(expected.supplyCap);
map.setDebtCeiling(expected.debtCeiling);
map.setLiquidationProtocolFee(expected.liqProtocolFee);
}
function _getProxyImplementation(address proxy) internal view returns (address) {
return address(uint160(uint256(vm.load(proxy, EIP1967_IMPL_SLOT))));
}
function _isKnownATokenImpl(address impl) internal pure returns (bool) {
return _isRwaATokenImpl(impl) || _isStandardATokenImpl(impl);
}
function _isRwaAToken(address aToken) internal view returns (bool) {
return _isRwaATokenImpl(_getProxyImplementation(aToken));
}
function _isRwaATokenImpl(address impl) internal pure returns (bool) {
return
impl == AaveV3EthereumHorizonCustom.RWA_A_TOKEN_IMPL ||
impl == AaveV3EthereumHorizonCustom.RWA_A_TOKEN_IMPL_PREV;
}
function _isStandardATokenImpl(address impl) internal pure returns (bool) {
return
impl == AaveV3EthereumHorizonCustom.DEFAULT_A_TOKEN_IMPL ||
impl == AaveV3EthereumHorizonCustom.DEFAULT_A_TOKEN_IMPL_PREV;
}
function _toAddressArray(address a) internal pure returns (address[] memory arr) {
arr = new address[](1);
arr[0] = a;
}
function _toAddressArray(address a, address b) internal pure returns (address[] memory arr) {
arr = new address[](2);
arr[0] = a;
arr[1] = b;
}
function _toAddressArray(
address a,
address b,
address c
) internal pure returns (address[] memory arr) {
arr = new address[](3);
arr[0] = a;
arr[1] = b;
arr[2] = c;
}
}