-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathPool.sol
871 lines (792 loc) · 25.4 KB
/
Pool.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
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.10;
import {VersionedInitializable} from '../../misc/aave-upgradeability/VersionedInitializable.sol';
import {Errors} from '../libraries/helpers/Errors.sol';
import {ReserveConfiguration} from '../libraries/configuration/ReserveConfiguration.sol';
import {PoolLogic} from '../libraries/logic/PoolLogic.sol';
import {ReserveLogic} from '../libraries/logic/ReserveLogic.sol';
import {EModeLogic} from '../libraries/logic/EModeLogic.sol';
import {SupplyLogic} from '../libraries/logic/SupplyLogic.sol';
import {FlashLoanLogic} from '../libraries/logic/FlashLoanLogic.sol';
import {BorrowLogic} from '../libraries/logic/BorrowLogic.sol';
import {LiquidationLogic} from '../libraries/logic/LiquidationLogic.sol';
import {DataTypes} from '../libraries/types/DataTypes.sol';
import {BridgeLogic} from '../libraries/logic/BridgeLogic.sol';
import {IERC20WithPermit} from '../../interfaces/IERC20WithPermit.sol';
import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.sol';
import {IPool} from '../../interfaces/IPool.sol';
import {IACLManager} from '../../interfaces/IACLManager.sol';
import {PoolStorage} from './PoolStorage.sol';
/**
* @title Pool contract
* @author Aave
* @notice Main point of interaction with an Aave protocol's market
* - Users can:
* # Supply
* # Withdraw
* # Borrow
* # Repay
* # Enable/disable their supplied assets as collateral
* # Liquidate positions
* # Execute Flash Loans
* @dev To be covered by a proxy contract, owned by the PoolAddressesProvider of the specific market
* @dev All admin functions are callable by the PoolConfigurator contract defined also in the
* PoolAddressesProvider
*/
abstract contract Pool is VersionedInitializable, PoolStorage, IPool {
using ReserveLogic for DataTypes.ReserveData;
IPoolAddressesProvider public immutable ADDRESSES_PROVIDER;
/**
* @dev Only pool configurator can call functions marked by this modifier.
*/
modifier onlyPoolConfigurator() {
_onlyPoolConfigurator();
_;
}
/**
* @dev Only pool admin can call functions marked by this modifier.
*/
modifier onlyPoolAdmin() {
_onlyPoolAdmin();
_;
}
/**
* @dev Only bridge can call functions marked by this modifier.
*/
modifier onlyBridge() {
_onlyBridge();
_;
}
function _onlyPoolConfigurator() internal view virtual {
require(
ADDRESSES_PROVIDER.getPoolConfigurator() == msg.sender,
Errors.CALLER_NOT_POOL_CONFIGURATOR
);
}
function _onlyPoolAdmin() internal view virtual {
require(
IACLManager(ADDRESSES_PROVIDER.getACLManager()).isPoolAdmin(msg.sender),
Errors.CALLER_NOT_POOL_ADMIN
);
}
function _onlyBridge() internal view virtual {
require(
IACLManager(ADDRESSES_PROVIDER.getACLManager()).isBridge(msg.sender),
Errors.CALLER_NOT_BRIDGE
);
}
/**
* @dev Constructor.
* @param provider The address of the PoolAddressesProvider contract
*/
constructor(IPoolAddressesProvider provider) {
ADDRESSES_PROVIDER = provider;
}
/**
* @notice Initializes the Pool.
* @dev Function is invoked by the proxy contract when the Pool contract is added to the
* PoolAddressesProvider of the market.
* @dev Caching the address of the PoolAddressesProvider in order to reduce gas consumption on subsequent operations
* @param provider The address of the PoolAddressesProvider
*/
function initialize(IPoolAddressesProvider provider) external virtual;
/// @inheritdoc IPool
function mintUnbacked(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external virtual override onlyBridge {
BridgeLogic.executeMintUnbacked(
_reserves,
_reservesList,
_usersConfig[onBehalfOf],
asset,
amount,
onBehalfOf,
referralCode
);
}
/// @inheritdoc IPool
function backUnbacked(
address asset,
uint256 amount,
uint256 fee
) external virtual override onlyBridge returns (uint256) {
return
BridgeLogic.executeBackUnbacked(_reserves[asset], asset, amount, fee, _bridgeProtocolFee);
}
/// @inheritdoc IPool
function supply(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) public virtual override {
SupplyLogic.executeSupply(
_reserves,
_reservesList,
_usersConfig[onBehalfOf],
DataTypes.ExecuteSupplyParams({
asset: asset,
amount: amount,
onBehalfOf: onBehalfOf,
referralCode: referralCode
})
);
}
/// @inheritdoc IPool
function supplyWithPermit(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode,
uint256 deadline,
uint8 permitV,
bytes32 permitR,
bytes32 permitS
) public virtual override {
try
IERC20WithPermit(asset).permit(
msg.sender,
address(this),
amount,
deadline,
permitV,
permitR,
permitS
)
{} catch {}
SupplyLogic.executeSupply(
_reserves,
_reservesList,
_usersConfig[onBehalfOf],
DataTypes.ExecuteSupplyParams({
asset: asset,
amount: amount,
onBehalfOf: onBehalfOf,
referralCode: referralCode
})
);
}
/// @inheritdoc IPool
function withdraw(
address asset,
uint256 amount,
address to
) public virtual override returns (uint256) {
return
SupplyLogic.executeWithdraw(
_reserves,
_reservesList,
_eModeCategories,
_usersConfig[msg.sender],
DataTypes.ExecuteWithdrawParams({
asset: asset,
amount: amount,
to: to,
reservesCount: _reservesCount,
oracle: ADDRESSES_PROVIDER.getPriceOracle(),
userEModeCategory: _usersEModeCategory[msg.sender]
})
);
}
/// @inheritdoc IPool
function borrow(
address asset,
uint256 amount,
uint256 interestRateMode,
uint16 referralCode,
address onBehalfOf
) public virtual override {
BorrowLogic.executeBorrow(
_reserves,
_reservesList,
_eModeCategories,
_usersConfig[onBehalfOf],
DataTypes.ExecuteBorrowParams({
asset: asset,
user: msg.sender,
onBehalfOf: onBehalfOf,
amount: amount,
interestRateMode: DataTypes.InterestRateMode(interestRateMode),
referralCode: referralCode,
releaseUnderlying: true,
reservesCount: _reservesCount,
oracle: ADDRESSES_PROVIDER.getPriceOracle(),
userEModeCategory: _usersEModeCategory[onBehalfOf],
priceOracleSentinel: ADDRESSES_PROVIDER.getPriceOracleSentinel()
})
);
}
/// @inheritdoc IPool
function repay(
address asset,
uint256 amount,
uint256 interestRateMode,
address onBehalfOf
) public virtual override returns (uint256) {
return
BorrowLogic.executeRepay(
_reserves,
_reservesList,
_usersConfig[onBehalfOf],
DataTypes.ExecuteRepayParams({
asset: asset,
amount: amount,
interestRateMode: DataTypes.InterestRateMode(interestRateMode),
onBehalfOf: onBehalfOf,
useATokens: false
})
);
}
/// @inheritdoc IPool
function repayWithPermit(
address asset,
uint256 amount,
uint256 interestRateMode,
address onBehalfOf,
uint256 deadline,
uint8 permitV,
bytes32 permitR,
bytes32 permitS
) public virtual override returns (uint256) {
try
IERC20WithPermit(asset).permit(
msg.sender,
address(this),
amount,
deadline,
permitV,
permitR,
permitS
)
{} catch {}
{
DataTypes.ExecuteRepayParams memory params = DataTypes.ExecuteRepayParams({
asset: asset,
amount: amount,
interestRateMode: DataTypes.InterestRateMode(interestRateMode),
onBehalfOf: onBehalfOf,
useATokens: false
});
return BorrowLogic.executeRepay(_reserves, _reservesList, _usersConfig[onBehalfOf], params);
}
}
/// @inheritdoc IPool
function repayWithATokens(
address asset,
uint256 amount,
uint256 interestRateMode
) public virtual override returns (uint256) {
return
BorrowLogic.executeRepay(
_reserves,
_reservesList,
_usersConfig[msg.sender],
DataTypes.ExecuteRepayParams({
asset: asset,
amount: amount,
interestRateMode: DataTypes.InterestRateMode(interestRateMode),
onBehalfOf: msg.sender,
useATokens: true
})
);
}
/// @inheritdoc IPool
function setUserUseReserveAsCollateral(
address asset,
bool useAsCollateral
) public virtual override {
SupplyLogic.executeUseReserveAsCollateral(
_reserves,
_reservesList,
_eModeCategories,
_usersConfig[msg.sender],
asset,
useAsCollateral,
_reservesCount,
ADDRESSES_PROVIDER.getPriceOracle(),
_usersEModeCategory[msg.sender]
);
}
/// @inheritdoc IPool
function liquidationCall(
address collateralAsset,
address debtAsset,
address user,
uint256 debtToCover,
bool receiveAToken
) public virtual override {
LiquidationLogic.executeLiquidationCall(
_reserves,
_reservesList,
_usersConfig,
_eModeCategories,
DataTypes.ExecuteLiquidationCallParams({
reservesCount: _reservesCount,
debtToCover: debtToCover,
collateralAsset: collateralAsset,
debtAsset: debtAsset,
user: user,
receiveAToken: receiveAToken,
priceOracle: ADDRESSES_PROVIDER.getPriceOracle(),
userEModeCategory: _usersEModeCategory[user],
priceOracleSentinel: ADDRESSES_PROVIDER.getPriceOracleSentinel()
})
);
}
/// @inheritdoc IPool
function flashLoan(
address receiverAddress,
address[] calldata assets,
uint256[] calldata amounts,
uint256[] calldata interestRateModes,
address onBehalfOf,
bytes calldata params,
uint16 referralCode
) public virtual override {
DataTypes.FlashloanParams memory flashParams = DataTypes.FlashloanParams({
receiverAddress: receiverAddress,
assets: assets,
amounts: amounts,
interestRateModes: interestRateModes,
onBehalfOf: onBehalfOf,
params: params,
referralCode: referralCode,
flashLoanPremiumToProtocol: _flashLoanPremiumToProtocol,
flashLoanPremiumTotal: _flashLoanPremiumTotal,
reservesCount: _reservesCount,
addressesProvider: address(ADDRESSES_PROVIDER),
pool: address(this),
userEModeCategory: _usersEModeCategory[onBehalfOf],
isAuthorizedFlashBorrower: IACLManager(ADDRESSES_PROVIDER.getACLManager()).isFlashBorrower(
msg.sender
)
});
FlashLoanLogic.executeFlashLoan(
_reserves,
_reservesList,
_eModeCategories,
_usersConfig[onBehalfOf],
flashParams
);
}
/// @inheritdoc IPool
function flashLoanSimple(
address receiverAddress,
address asset,
uint256 amount,
bytes calldata params,
uint16 referralCode
) public virtual override {
DataTypes.FlashloanSimpleParams memory flashParams = DataTypes.FlashloanSimpleParams({
receiverAddress: receiverAddress,
asset: asset,
amount: amount,
params: params,
referralCode: referralCode,
flashLoanPremiumToProtocol: _flashLoanPremiumToProtocol,
flashLoanPremiumTotal: _flashLoanPremiumTotal
});
FlashLoanLogic.executeFlashLoanSimple(_reserves[asset], flashParams);
}
/// @inheritdoc IPool
function mintToTreasury(address[] calldata assets) external virtual override {
PoolLogic.executeMintToTreasury(_reserves, assets);
}
/// @inheritdoc IPool
function getReserveDataExtended(
address asset
) external view returns (DataTypes.ReserveData memory) {
return _reserves[asset];
}
/// @inheritdoc IPool
function getReserveData(
address asset
) external view virtual override returns (DataTypes.ReserveDataLegacy memory) {
DataTypes.ReserveData memory reserve = _reserves[asset];
DataTypes.ReserveDataLegacy memory res;
res.configuration = reserve.configuration;
res.liquidityIndex = reserve.liquidityIndex;
res.currentLiquidityRate = reserve.currentLiquidityRate;
res.variableBorrowIndex = reserve.variableBorrowIndex;
res.currentVariableBorrowRate = reserve.currentVariableBorrowRate;
res.lastUpdateTimestamp = reserve.lastUpdateTimestamp;
res.id = reserve.id;
res.aTokenAddress = reserve.aTokenAddress;
res.variableDebtTokenAddress = reserve.variableDebtTokenAddress;
res.interestRateStrategyAddress = reserve.interestRateStrategyAddress;
res.accruedToTreasury = reserve.accruedToTreasury;
res.unbacked = reserve.unbacked;
res.isolationModeTotalDebt = reserve.isolationModeTotalDebt;
// This is a temporary workaround for integrations that are broken by Aave 3.2
// While the new pool data provider is backward compatible, some integrations hard-code an old implementation
// To allow them to not have any infrastructural blocker, a mock must be configured in the Aave Pool Addresses Provider, returning zero on all required view methods, instead of reverting
res.stableDebtTokenAddress = ADDRESSES_PROVIDER.getAddress(bytes32('MOCK_STABLE_DEBT'));
return res;
}
/// @inheritdoc IPool
function getVirtualUnderlyingBalance(
address asset
) external view virtual override returns (uint128) {
return _reserves[asset].virtualUnderlyingBalance;
}
/// @inheritdoc IPool
function getUserAccountData(
address user
)
external
view
virtual
override
returns (
uint256 totalCollateralBase,
uint256 totalDebtBase,
uint256 availableBorrowsBase,
uint256 currentLiquidationThreshold,
uint256 ltv,
uint256 healthFactor
)
{
return
PoolLogic.executeGetUserAccountData(
_reserves,
_reservesList,
_eModeCategories,
DataTypes.CalculateUserAccountDataParams({
userConfig: _usersConfig[user],
reservesCount: _reservesCount,
user: user,
oracle: ADDRESSES_PROVIDER.getPriceOracle(),
userEModeCategory: _usersEModeCategory[user]
})
);
}
/// @inheritdoc IPool
function getConfiguration(
address asset
) external view virtual override returns (DataTypes.ReserveConfigurationMap memory) {
return _reserves[asset].configuration;
}
/// @inheritdoc IPool
function getUserConfiguration(
address user
) external view virtual override returns (DataTypes.UserConfigurationMap memory) {
return _usersConfig[user];
}
/// @inheritdoc IPool
function getReserveNormalizedIncome(
address asset
) external view virtual override returns (uint256) {
return _reserves[asset].getNormalizedIncome();
}
/// @inheritdoc IPool
function getReserveNormalizedVariableDebt(
address asset
) external view virtual override returns (uint256) {
return _reserves[asset].getNormalizedDebt();
}
/// @inheritdoc IPool
function getReservesList() external view virtual override returns (address[] memory) {
uint256 reservesListCount = _reservesCount;
uint256 droppedReservesCount = 0;
address[] memory reservesList = new address[](reservesListCount);
for (uint256 i = 0; i < reservesListCount; i++) {
if (_reservesList[i] != address(0)) {
reservesList[i - droppedReservesCount] = _reservesList[i];
} else {
droppedReservesCount++;
}
}
// Reduces the length of the reserves array by `droppedReservesCount`
assembly {
mstore(reservesList, sub(reservesListCount, droppedReservesCount))
}
return reservesList;
}
/// @inheritdoc IPool
function getReservesCount() external view virtual override returns (uint256) {
return _reservesCount;
}
/// @inheritdoc IPool
function getReserveAddressById(uint16 id) external view returns (address) {
return _reservesList[id];
}
/// @inheritdoc IPool
function BRIDGE_PROTOCOL_FEE() public view virtual override returns (uint256) {
return _bridgeProtocolFee;
}
/// @inheritdoc IPool
function FLASHLOAN_PREMIUM_TOTAL() public view virtual override returns (uint128) {
return _flashLoanPremiumTotal;
}
/// @inheritdoc IPool
function FLASHLOAN_PREMIUM_TO_PROTOCOL() public view virtual override returns (uint128) {
return _flashLoanPremiumToProtocol;
}
/// @inheritdoc IPool
function MAX_NUMBER_RESERVES() public view virtual override returns (uint16) {
return ReserveConfiguration.MAX_RESERVES_COUNT;
}
/// @inheritdoc IPool
function finalizeTransfer(
address asset,
address from,
address to,
uint256 amount,
uint256 balanceFromBefore,
uint256 balanceToBefore
) external virtual override {
require(msg.sender == _reserves[asset].aTokenAddress, Errors.CALLER_NOT_ATOKEN);
SupplyLogic.executeFinalizeTransfer(
_reserves,
_reservesList,
_eModeCategories,
_usersConfig,
DataTypes.FinalizeTransferParams({
asset: asset,
from: from,
to: to,
amount: amount,
balanceFromBefore: balanceFromBefore,
balanceToBefore: balanceToBefore,
reservesCount: _reservesCount,
oracle: ADDRESSES_PROVIDER.getPriceOracle(),
fromEModeCategory: _usersEModeCategory[from]
})
);
}
/// @inheritdoc IPool
function initReserve(
address asset,
address aTokenAddress,
address variableDebtAddress,
address interestRateStrategyAddress
) external virtual override onlyPoolConfigurator {
if (
PoolLogic.executeInitReserve(
_reserves,
_reservesList,
DataTypes.InitReserveParams({
asset: asset,
aTokenAddress: aTokenAddress,
variableDebtAddress: variableDebtAddress,
interestRateStrategyAddress: interestRateStrategyAddress,
reservesCount: _reservesCount,
maxNumberReserves: MAX_NUMBER_RESERVES()
})
)
) {
_reservesCount++;
}
}
/// @inheritdoc IPool
function dropReserve(address asset) external virtual override onlyPoolConfigurator {
PoolLogic.executeDropReserve(_reserves, _reservesList, asset);
}
/// @inheritdoc IPool
function setReserveInterestRateStrategyAddress(
address asset,
address rateStrategyAddress
) external virtual override onlyPoolConfigurator {
require(asset != address(0), Errors.ZERO_ADDRESS_NOT_VALID);
require(_reserves[asset].id != 0 || _reservesList[0] == asset, Errors.ASSET_NOT_LISTED);
_reserves[asset].interestRateStrategyAddress = rateStrategyAddress;
}
/// @inheritdoc IPool
function syncIndexesState(address asset) external virtual override onlyPoolConfigurator {
DataTypes.ReserveData storage reserve = _reserves[asset];
DataTypes.ReserveCache memory reserveCache = reserve.cache();
reserve.updateState(reserveCache);
}
/// @inheritdoc IPool
function syncRatesState(address asset) external virtual override onlyPoolConfigurator {
DataTypes.ReserveData storage reserve = _reserves[asset];
DataTypes.ReserveCache memory reserveCache = reserve.cache();
ReserveLogic.updateInterestRatesAndVirtualBalance(reserve, reserveCache, asset, 0, 0);
}
/// @inheritdoc IPool
function setConfiguration(
address asset,
DataTypes.ReserveConfigurationMap calldata configuration
) external virtual override onlyPoolConfigurator {
require(asset != address(0), Errors.ZERO_ADDRESS_NOT_VALID);
require(_reserves[asset].id != 0 || _reservesList[0] == asset, Errors.ASSET_NOT_LISTED);
_reserves[asset].configuration = configuration;
}
/// @inheritdoc IPool
function updateBridgeProtocolFee(
uint256 protocolFee
) external virtual override onlyPoolConfigurator {
_bridgeProtocolFee = protocolFee;
}
/// @inheritdoc IPool
function updateFlashloanPremiums(
uint128 flashLoanPremiumTotal,
uint128 flashLoanPremiumToProtocol
) external virtual override onlyPoolConfigurator {
_flashLoanPremiumTotal = flashLoanPremiumTotal;
_flashLoanPremiumToProtocol = flashLoanPremiumToProtocol;
}
/// @inheritdoc IPool
function configureEModeCategory(
uint8 id,
DataTypes.EModeCategoryBaseConfiguration memory category
) external virtual override onlyPoolConfigurator {
// category 0 is reserved for volatile heterogeneous assets and it's always disabled
require(id != 0, Errors.EMODE_CATEGORY_RESERVED);
_eModeCategories[id].ltv = category.ltv;
_eModeCategories[id].liquidationThreshold = category.liquidationThreshold;
_eModeCategories[id].liquidationBonus = category.liquidationBonus;
_eModeCategories[id].label = category.label;
}
/// @inheritdoc IPool
function configureEModeCategoryCollateralBitmap(
uint8 id,
uint128 collateralBitmap
) external virtual override onlyPoolConfigurator {
// category 0 is reserved for volatile heterogeneous assets and it's always disabled
require(id != 0, Errors.EMODE_CATEGORY_RESERVED);
_eModeCategories[id].collateralBitmap = collateralBitmap;
}
/// @inheritdoc IPool
function configureEModeCategoryBorrowableBitmap(
uint8 id,
uint128 borrowableBitmap
) external virtual override onlyPoolConfigurator {
// category 0 is reserved for volatile heterogeneous assets and it's always disabled
require(id != 0, Errors.EMODE_CATEGORY_RESERVED);
_eModeCategories[id].borrowableBitmap = borrowableBitmap;
}
/// @inheritdoc IPool
function getEModeCategoryData(
uint8 id
) external view virtual override returns (DataTypes.EModeCategoryLegacy memory) {
DataTypes.EModeCategory memory category = _eModeCategories[id];
return
DataTypes.EModeCategoryLegacy({
ltv: category.ltv,
liquidationThreshold: category.liquidationThreshold,
liquidationBonus: category.liquidationBonus,
priceSource: address(0),
label: category.label
});
}
/// @inheritdoc IPool
function getEModeCategoryCollateralConfig(
uint8 id
) external view returns (DataTypes.CollateralConfig memory) {
return
DataTypes.CollateralConfig({
ltv: _eModeCategories[id].ltv,
liquidationThreshold: _eModeCategories[id].liquidationThreshold,
liquidationBonus: _eModeCategories[id].liquidationBonus
});
}
/// @inheritdoc IPool
function getEModeCategoryLabel(uint8 id) external view returns (string memory) {
return _eModeCategories[id].label;
}
/// @inheritdoc IPool
function getEModeCategoryCollateralBitmap(uint8 id) external view returns (uint128) {
return _eModeCategories[id].collateralBitmap;
}
/// @inheritdoc IPool
function getEModeCategoryBorrowableBitmap(uint8 id) external view returns (uint128) {
return _eModeCategories[id].borrowableBitmap;
}
/// @inheritdoc IPool
function setUserEMode(uint8 categoryId) external virtual override {
EModeLogic.executeSetUserEMode(
_reserves,
_reservesList,
_eModeCategories,
_usersEModeCategory,
_usersConfig[msg.sender],
DataTypes.ExecuteSetUserEModeParams({
reservesCount: _reservesCount,
oracle: ADDRESSES_PROVIDER.getPriceOracle(),
categoryId: categoryId
})
);
}
/// @inheritdoc IPool
function getUserEMode(address user) external view virtual override returns (uint256) {
return _usersEModeCategory[user];
}
/// @inheritdoc IPool
function resetIsolationModeTotalDebt(
address asset
) external virtual override onlyPoolConfigurator {
PoolLogic.executeResetIsolationModeTotalDebt(_reserves, asset);
}
/// @inheritdoc IPool
function getLiquidationGracePeriod(address asset) external virtual override returns (uint40) {
return _reserves[asset].liquidationGracePeriodUntil;
}
/// @inheritdoc IPool
function setLiquidationGracePeriod(
address asset,
uint40 until
) external virtual override onlyPoolConfigurator {
require(_reserves[asset].id != 0 || _reservesList[0] == asset, Errors.ASSET_NOT_LISTED);
PoolLogic.executeSetLiquidationGracePeriod(_reserves, asset, until);
}
/// @inheritdoc IPool
function rescueTokens(
address token,
address to,
uint256 amount
) external virtual override onlyPoolAdmin {
PoolLogic.executeRescueTokens(token, to, amount);
}
/// @inheritdoc IPool
/// @dev Deprecated: maintained for compatibility purposes
function deposit(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external virtual override {
SupplyLogic.executeSupply(
_reserves,
_reservesList,
_usersConfig[onBehalfOf],
DataTypes.ExecuteSupplyParams({
asset: asset,
amount: amount,
onBehalfOf: onBehalfOf,
referralCode: referralCode
})
);
}
/// @inheritdoc IPool
function getFlashLoanLogic() external pure returns (address) {
return address(FlashLoanLogic);
}
/// @inheritdoc IPool
function getBorrowLogic() external pure returns (address) {
return address(BorrowLogic);
}
/// @inheritdoc IPool
function getBridgeLogic() external pure returns (address) {
return address(BridgeLogic);
}
/// @inheritdoc IPool
function getEModeLogic() external pure returns (address) {
return address(EModeLogic);
}
/// @inheritdoc IPool
function getLiquidationLogic() external pure returns (address) {
return address(LiquidationLogic);
}
/// @inheritdoc IPool
function getPoolLogic() external pure returns (address) {
return address(PoolLogic);
}
/// @inheritdoc IPool
function getSupplyLogic() external pure returns (address) {
return address(SupplyLogic);
}
}