forked from bgd-labs/example-aave-v2-listing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAaveV2Helpers.sol
672 lines (605 loc) · 23 KB
/
AaveV2Helpers.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
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
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
// SPDX-License-Identifier: MIT
pragma solidity 0.8.11;
import "forge-std/Vm.sol";
import "forge-std/console.sol";
import { AaveAddressBookV2 } from 'aave-address-book/AaveAddressBook.sol';
import { TokenData } from 'aave-address-book/AaveV2.sol';
import {IERC20} from "../../interfaces/IERC20.sol";
struct ReserveTokens {
address aToken;
address stableDebtToken;
address variableDebtToken;
}
struct ReserveConfig {
string symbol;
address underlying;
address aToken;
address stableDebtToken;
address variableDebtToken;
uint256 decimals;
uint256 ltv;
uint256 liquidationThreshold;
uint256 liquidationBonus;
uint256 reserveFactor;
bool usageAsCollateralEnabled;
bool borrowingEnabled;
address interestRateStrategy;
bool stableBorrowRateEnabled;
bool isActive;
bool isFrozen;
}
struct ReserveConfigurationMap {
//bit 0-15: LTV
//bit 16-31: Liq. threshold
//bit 32-47: Liq. bonus
//bit 48-55: Decimals
//bit 56: Reserve is active
//bit 57: reserve is frozen
//bit 58: borrowing is enabled
//bit 59: stable rate borrowing enabled
//bit 60-63: reserved
//bit 64-79: reserve factor
uint256 data;
}
struct ReserveData {
//stores the reserve configuration
ReserveConfigurationMap configuration;
//the liquidity index. Expressed in ray
uint128 liquidityIndex;
//variable borrow index. Expressed in ray
uint128 variableBorrowIndex;
//the current supply rate. Expressed in ray
uint128 currentLiquidityRate;
//the current variable borrow rate. Expressed in ray
uint128 currentVariableBorrowRate;
//the current stable borrow rate. Expressed in ray
uint128 currentStableBorrowRate;
uint40 lastUpdateTimestamp;
//tokens addresses
address aTokenAddress;
address stableDebtTokenAddress;
address variableDebtTokenAddress;
//address of the interest rate strategy
address interestRateStrategyAddress;
//the id of the reserve. Represents the position in the list of the active reserves
uint8 id;
}
struct InterestStrategyValues {
uint256 excessUtilization;
uint256 optimalUtilization;
uint256 baseVariableBorrowRate;
uint256 stableRateSlope1;
uint256 stableRateSlope2;
uint256 variableRateSlope1;
uint256 variableRateSlope2;
}
interface IAddressesProvider {
function getPriceOracle() external returns (address);
}
interface IAaveOracle {
function getSourceOfAsset(address asset) external returns (address);
function getAssetPrice(address asset) external returns (address);
}
interface IReserveInterestRateStrategy {
function getMaxVariableBorrowRate() external view returns (uint256);
function EXCESS_UTILIZATION_RATE() external view returns (uint256);
function OPTIMAL_UTILIZATION_RATE() external view returns (uint256);
function addressesProvider() external view returns (address);
function baseVariableBorrowRate() external view returns (uint256);
function stableRateSlope1() external view returns (uint256);
function stableRateSlope2() external view returns (uint256);
function variableRateSlope1() external view returns (uint256);
function variableRateSlope2() external view returns (uint256);
}
interface IProtocolDataProvider {
function getReserveConfigurationData(address asset)
external
view
returns (
uint256 decimals,
uint256 ltv,
uint256 liquidationThreshold,
uint256 liquidationBonus,
uint256 reserveFactor,
bool usageAsCollateralEnabled,
bool borrowingEnabled,
bool stableBorrowRateEnabled,
bool isActive,
bool isFrozen
);
function getAllReservesTokens() external view returns (TokenData[] memory);
function getReserveTokensAddresses(address asset)
external
view
returns (
address aTokenAddress,
address stableDebtTokenAddress,
address variableDebtTokenAddress
);
}
interface IAavePool {
function deposit(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external;
function borrow(
address asset,
uint256 amount,
uint256 interestRateMode,
uint16 referralCode,
address onBehalfOf
) external;
function repay(
address asset,
uint256 amount,
uint256 rateMode,
address onBehalfOf
) external returns (uint256);
function withdraw(
address asset,
uint256 amount,
address to
) external returns (uint256);
function getReserveData(address asset)
external
view
returns (ReserveData memory);
}
interface IInitializableAdminUpgradeabilityProxy {
function upgradeTo(address newImplementation) external;
function upgradeToAndCall(address newImplementation, bytes calldata data)
external
payable;
function admin() external returns (address);
function implementation() external returns (address);
}
library AaveV2Helpers {
uint256 internal constant RAY = 1e27;
struct LocalVars {
TokenData[] reserves;
ReserveConfig[] configs;
}
function _getReservesConfigs(bool withLogs, string memory marketName)
internal
view
returns (ReserveConfig[] memory)
{
AaveAddressBookV2.Market memory market = AaveAddressBookV2.getMarket(marketName);
LocalVars memory vars;
vars.reserves = market.AAVE_PROTOCOL_DATA_PROVIDER.getAllReservesTokens();
vars.configs = new ReserveConfig[](vars.reserves.length);
for (uint256 i = 0; i < vars.reserves.length; i++) {
vars.configs[i] = _getStructReserveConfig(IProtocolDataProvider(address(market.AAVE_PROTOCOL_DATA_PROVIDER)), vars.reserves[i].tokenAddress);
vars.configs[i].symbol = vars.reserves[i].symbol;
vars.configs[i].underlying = vars.reserves[i].tokenAddress;
vars.configs[i].interestRateStrategy = market.POOL
.getReserveData(vars.reserves[i].tokenAddress)
.interestRateStrategyAddress;
ReserveTokens memory reserveTokens = _getStructReserveTokens(
vars.configs[i].underlying,
marketName
);
vars.configs[i].aToken = reserveTokens.aToken;
vars.configs[i].variableDebtToken = reserveTokens.variableDebtToken;
vars.configs[i].stableDebtToken = reserveTokens.stableDebtToken;
if (withLogs) {
_logReserveConfig(vars.configs[i]);
}
}
return vars.configs;
}
/// @dev Ugly, but necessary to avoid Stack Too Deep
//function _getStructReserveConfig(AaveAddressBookV2.Market.IAaveProtocolDataProvider dataProvider, address tokenAddress)
function _getStructReserveConfig(IProtocolDataProvider dataProvider, address tokenAddress)
internal
view
returns (ReserveConfig memory)
{
(
uint256 decimals,
uint256 ltv,
uint256 liquidationThreshold,
uint256 liquidationBonus,
uint256 reserveFactor,
bool usageAsCollateralEnabled,
bool borrowingEnabled,
bool stableBorrowRateEnabled,
bool isActive,
bool isFrozen
) = dataProvider.getReserveConfigurationData(tokenAddress);
ReserveConfig memory localConfig;
localConfig.decimals = decimals;
localConfig.ltv = ltv;
localConfig.liquidationThreshold = liquidationThreshold;
localConfig.liquidationBonus = liquidationBonus;
localConfig.reserveFactor = reserveFactor;
localConfig.usageAsCollateralEnabled = usageAsCollateralEnabled;
localConfig.borrowingEnabled = borrowingEnabled;
localConfig.stableBorrowRateEnabled = stableBorrowRateEnabled;
localConfig.isActive = isActive;
localConfig.isFrozen = isFrozen;
return localConfig;
}
/// @dev Ugly, but necessary to avoid Stack Too Deep
function _getStructReserveTokens(address underlyingAddress, string memory marketName)
internal
view
returns (ReserveTokens memory)
{
AaveAddressBookV2.Market memory market = AaveAddressBookV2.getMarket(marketName);
ReserveTokens memory reserveTokens;
(
reserveTokens.aToken,
reserveTokens.stableDebtToken,
reserveTokens.variableDebtToken
) = market.AAVE_PROTOCOL_DATA_PROVIDER.getReserveTokensAddresses(underlyingAddress);
return reserveTokens;
}
function _findReserveConfig(
ReserveConfig[] memory configs,
string memory symbolOfUnderlying,
bool withLogs
) internal view returns (ReserveConfig memory) {
for (uint256 i = 0; i < configs.length; i++) {
if (
keccak256(abi.encodePacked(configs[i].symbol)) ==
keccak256(abi.encodePacked(symbolOfUnderlying))
) {
if (withLogs) {
_logReserveConfig(configs[i]);
}
return configs[i];
}
}
revert("RESERVE_CONFIG_NOT_FOUND");
}
function _logReserveConfig(ReserveConfig memory config) internal view {
console.log("Symbol ", config.symbol);
console.log("Underlying address ", config.underlying);
console.log("AToken address ", config.aToken);
console.log("Stable debt token address ", config.stableDebtToken);
console.log("Variable debt token address ", config.variableDebtToken);
console.log("Decimals ", config.decimals);
console.log("LTV ", config.ltv);
console.log("Liquidation Threshold ", config.liquidationThreshold);
console.log("Liquidation Bonnus", config.liquidationBonus);
console.log("Reserve Factor ", config.reserveFactor);
console.log(
"Usage as collateral enabled ",
(config.usageAsCollateralEnabled) ? "Yes" : "No"
);
console.log(
"Borrowing enabled ",
(config.borrowingEnabled) ? "Yes" : "No"
);
console.log(
"Stable borrow rate enabled ",
(config.stableBorrowRateEnabled) ? "Yes" : "No"
);
console.log("Interest rate strategy ", config.interestRateStrategy);
console.log("Is active ", (config.isActive) ? "Yes" : "No");
console.log("Is frozen ", (config.isFrozen) ? "Yes" : "No");
console.log("-----");
console.log("-----");
}
function _validateReserveConfig(
ReserveConfig memory expectedConfig,
ReserveConfig[] memory allConfigs
) internal view {
ReserveConfig memory config = _findReserveConfig(
allConfigs,
expectedConfig.symbol,
false
);
require(
config.underlying == expectedConfig.underlying,
"_validateLusdConfigsInAave() : INVALID_UNDERLYING"
);
require(
config.decimals == expectedConfig.decimals,
"_validateLusdConfigsInAave: INVALID_DECIMALS"
);
require(
config.ltv == expectedConfig.ltv,
"_validateLusdConfigsInAave: INVALID_LTV"
);
require(
config.liquidationThreshold == expectedConfig.liquidationThreshold,
"_validateLusdConfigsInAave: INVALID_LIQ_THRESHOLD"
);
require(
config.liquidationBonus == expectedConfig.liquidationBonus,
"_validateLusdConfigsInAave: INVALID_LIQ_BONUS"
);
require(
config.reserveFactor == expectedConfig.reserveFactor,
"_validateLusdConfigsInAave: INVALID_RESERVE_FACTOR"
);
require(
config.usageAsCollateralEnabled ==
expectedConfig.usageAsCollateralEnabled,
"_validateLusdConfigsInAave: INVALID_USAGE_AS_COLLATERAL"
);
require(
config.borrowingEnabled == expectedConfig.borrowingEnabled,
"_validateLusdConfigsInAave: INVALID_BORROWING_ENABLED"
);
require(
config.stableBorrowRateEnabled ==
expectedConfig.stableBorrowRateEnabled,
"_validateLusdConfigsInAave: INVALID_STABLE_BORROW_ENABLED"
);
require(
config.isActive == expectedConfig.isActive,
"_validateLusdConfigsInAave: INVALID_IS_ACTIVE"
);
require(
config.isFrozen == expectedConfig.isFrozen,
"_validateLusdConfigsInAave: INVALID_IS_FROZEN"
);
}
function _validateInterestRateStrategy(
address asset,
address expectedStrategy,
InterestStrategyValues memory expectedStrategyValues,
string memory marketName
) internal view {
AaveAddressBookV2.Market memory market = AaveAddressBookV2.getMarket(marketName);
IReserveInterestRateStrategy strategy = IReserveInterestRateStrategy(
market.POOL.getReserveData(asset).interestRateStrategyAddress
);
require(
address(strategy) == expectedStrategy,
"_validateInterestRateStrategy() : INVALID_STRATEGY_ADDRESS"
);
require(
strategy.EXCESS_UTILIZATION_RATE() ==
expectedStrategyValues.excessUtilization,
"_validateInterestRateStrategy() : INVALID_EXCESS_RATE"
);
require(
strategy.OPTIMAL_UTILIZATION_RATE() ==
expectedStrategyValues.optimalUtilization,
"_validateInterestRateStrategy() : INVALID_OPTIMAL_RATE"
);
require(
strategy.addressesProvider() ==
address(market.POOL_ADDRESSES_PROVIDER),
"_validateInterestRateStrategy() : INVALID_ADDRESSES_PROVIDER"
);
require(
strategy.baseVariableBorrowRate() ==
expectedStrategyValues.baseVariableBorrowRate,
"_validateInterestRateStrategy() : INVALID_BASE_VARIABLE_BORROW"
);
require(
strategy.stableRateSlope1() ==
expectedStrategyValues.stableRateSlope1,
"_validateInterestRateStrategy() : INVALID_STABLE_SLOPE_1"
);
require(
strategy.stableRateSlope2() ==
expectedStrategyValues.stableRateSlope2,
"_validateInterestRateStrategy() : INVALID_STABLE_SLOPE_2"
);
require(
strategy.variableRateSlope1() ==
expectedStrategyValues.variableRateSlope1,
"_validateInterestRateStrategy() : INVALID_VARIABLE_SLOPE_1"
);
require(
strategy.variableRateSlope2() ==
expectedStrategyValues.variableRateSlope2,
"_validateInterestRateStrategy() : INVALID_VARIABLE_SLOPE_2"
);
require(
strategy.getMaxVariableBorrowRate() ==
expectedStrategyValues.baseVariableBorrowRate +
expectedStrategyValues.variableRateSlope1 +
expectedStrategyValues.variableRateSlope2,
"_validateInterestRateStrategy() : INVALID_VARIABLE_SLOPE_2"
);
}
function _noReservesConfigsChangesApartNewListings(
ReserveConfig[] memory allConfigsBefore,
ReserveConfig[] memory allConfigsAfter
) internal pure {
for (uint256 i = 0; i < allConfigsBefore.length; i++) {
require(
keccak256(abi.encodePacked(allConfigsBefore[i].symbol)) ==
keccak256(abi.encodePacked(allConfigsAfter[i].symbol)),
"_noReservesConfigsChangesApartNewListings() : UNEXPECTED_SYMBOL_CHANGED"
);
require(
allConfigsBefore[i].underlying == allConfigsAfter[i].underlying,
"_noReservesConfigsChangesApartNewListings() : UNEXPECTED_UNDERLYING_CHANGED"
);
require(
allConfigsBefore[i].decimals == allConfigsAfter[i].decimals,
"_noReservesConfigsChangesApartNewListings() : UNEXPECTED_DECIMALS_CHANGED"
);
require(
allConfigsBefore[i].ltv == allConfigsAfter[i].ltv,
"_noReservesConfigsChangesApartNewListings() : UNEXPECTED_LTV_CHANGED"
);
require(
allConfigsBefore[i].liquidationThreshold ==
allConfigsAfter[i].liquidationThreshold,
"_noReservesConfigsChangesApartNewListings() : UNEXPECTED_LIQ_THRESHOLD_CHANGED"
);
require(
allConfigsBefore[i].liquidationBonus ==
allConfigsAfter[i].liquidationBonus,
"_noReservesConfigsChangesApartNewListings() : UNEXPECTED_LIQ_BONUS_CHANGED"
);
require(
allConfigsBefore[i].reserveFactor ==
allConfigsAfter[i].reserveFactor,
"_noReservesConfigsChangesApartNewListings() : UNEXPECTED_RESERVE_FACTOR_CHANGED"
);
require(
allConfigsBefore[i].usageAsCollateralEnabled ==
allConfigsAfter[i].usageAsCollateralEnabled,
"_noReservesConfigsChangesApartNewListings() : UNEXPECTED_USAGE_AS_COLLATERAL_ENABLED_CHANGED"
);
require(
allConfigsBefore[i].borrowingEnabled ==
allConfigsAfter[i].borrowingEnabled,
"_noReservesConfigsChangesApartNewListings() : UNEXPECTED_BORROWING_ENABLED_CHANGED"
);
require(
allConfigsBefore[i].stableBorrowRateEnabled ==
allConfigsAfter[i].stableBorrowRateEnabled,
"_noReservesConfigsChangesApartNewListings() : UNEXPECTED_STABLE_BORROWING_CHANGED"
);
require(
allConfigsBefore[i].isActive == allConfigsAfter[i].isActive,
"_noReservesConfigsChangesApartNewListings() : UNEXPECTED_IS_ACTIVE_CHANGED"
);
require(
allConfigsBefore[i].isFrozen == allConfigsAfter[i].isFrozen,
"_noReservesConfigsChangesApartNewListings() : UNEXPECTED_IS_FROZEN_CHANGED"
);
}
}
function _validateCountOfListings(
uint256 count,
ReserveConfig[] memory allConfigsBefore,
ReserveConfig[] memory allConfigsAfter
) internal pure {
require(
allConfigsBefore.length == allConfigsAfter.length - count,
"_validateCountOfListings() : INVALID_COUNT_OF_LISTINGS"
);
}
function _validateReserveTokensImpls(
Vm vm,
ReserveConfig memory config,
ReserveTokens memory expectedImpls,
string memory marketName
) internal {
AaveAddressBookV2.Market memory market = AaveAddressBookV2.getMarket(marketName);
vm.startPrank(address(market.POOL_CONFIGURATOR));
require(
IInitializableAdminUpgradeabilityProxy(config.aToken)
.implementation() == expectedImpls.aToken,
"_validateReserveTokensImpls() : INVALID_ATOKEN_IMPL"
);
vm.stopPrank();
}
function _deposit(
Vm vm,
address depositor,
address onBehalfOf,
address asset,
uint256 amount,
bool approve,
address aToken,
string memory marketName
) internal {
AaveAddressBookV2.Market memory market = AaveAddressBookV2.getMarket(marketName);
uint256 aTokenBefore = IERC20(aToken).balanceOf(onBehalfOf);
vm.deal(depositor, 1 ether);
vm.startPrank(depositor);
if (approve) {
IERC20(asset).approve(address(market.POOL), amount);
}
market.POOL.deposit(asset, amount, onBehalfOf, 0);
vm.stopPrank();
uint256 aTokenAfter = IERC20(aToken).balanceOf(onBehalfOf);
require(
_almostEqual(aTokenAfter, aTokenBefore + amount),
"_deposit() : ERROR"
);
}
function _borrow(
Vm vm,
address borrower,
address onBehalfOf,
address asset,
uint256 amount,
uint256 interestRateMode,
address debtToken,
string memory marketName
) public {
AaveAddressBookV2.Market memory market = AaveAddressBookV2.getMarket(marketName);
uint256 debtBefore = IERC20(debtToken).balanceOf(onBehalfOf);
vm.deal(borrower, 1 ether);
vm.startPrank(borrower);
market.POOL.borrow(asset, amount, interestRateMode, 0, onBehalfOf);
vm.stopPrank();
uint256 debtAfter = IERC20(debtToken).balanceOf(onBehalfOf);
require(
_almostEqual(debtAfter, debtBefore + amount),
"_borrow() : ERROR"
);
}
function _repay(
Vm vm,
address whoRepays,
address debtor,
address asset,
uint256 amount,
uint256 interestRateMode,
address debtToken,
bool approve,
string memory marketName
) internal {
AaveAddressBookV2.Market memory market = AaveAddressBookV2.getMarket(marketName);
uint256 debtBefore = IERC20(debtToken).balanceOf(debtor);
vm.deal(whoRepays, 1 ether);
vm.startPrank(whoRepays);
if (approve) {
IERC20(asset).approve(address(market.POOL), amount);
}
market.POOL.repay(asset, amount, interestRateMode, debtor);
vm.stopPrank();
uint256 debtAfter = IERC20(debtToken).balanceOf(debtor);
require(
debtAfter == ((debtBefore > amount) ? debtBefore - amount : 0),
"_repay() : INCONSISTENT_DEBT_AFTER"
);
}
function _withdraw(
Vm vm,
address whoWithdraws,
address to,
address asset,
uint256 amount,
address aToken,
string memory marketName
) internal {
AaveAddressBookV2.Market memory market = AaveAddressBookV2.getMarket(marketName);
uint256 aTokenBefore = IERC20(aToken).balanceOf(whoWithdraws);
vm.deal(whoWithdraws, 1 ether);
vm.startPrank(whoWithdraws);
market.POOL.withdraw(asset, amount, to);
vm.stopPrank();
uint256 aTokenAfter = IERC20(aToken).balanceOf(whoWithdraws);
require(
aTokenAfter ==
((aTokenBefore > amount) ? aTokenBefore - amount : 0),
"_withdraw() : INCONSISTENT_ATOKEN_BALANCE_AFTER"
);
}
function _validateAssetSourceOnOracle(address asset, address expectedSource, string memory marketName)
external
view
{
AaveAddressBookV2.Market memory market = AaveAddressBookV2.getMarket(marketName);
require(
market.ORACLE.getSourceOfAsset(asset) == expectedSource,
"_validateAssetSourceOnOracle() : INVALID_PRICE_SOURCE"
);
}
/// @dev To contemplate +1/-1 precision issues when rounding, mainly on aTokens
function _almostEqual(uint256 a, uint256 b) internal pure returns (bool) {
if (b == 0) {
return (a == b) || (a == (b + 1));
} else {
return (a == b) || (a == (b + 1)) || (a == (b - 1));
}
}
}