1
1
// SPDX-License-Identifier: BUSL-1.1
2
2
pragma solidity 0.8.10 ;
3
3
4
- import {IERC20 } from '../../dependencies/openzeppelin/contracts/IERC20.sol ' ;
5
- import {GPv2SafeERC20} from '../../dependencies/gnosis/contracts/GPv2SafeERC20.sol ' ;
6
- import {Address} from '../../dependencies/openzeppelin/contracts/Address.sol ' ;
7
4
import {VersionedInitializable} from '../libraries/aave-upgradeability/VersionedInitializable.sol ' ;
8
5
import {Errors} from '../libraries/helpers/Errors.sol ' ;
9
- import {WadRayMath} from '../libraries/math/WadRayMath.sol ' ;
6
+ import {ReserveConfiguration} from '../libraries/configuration/ReserveConfiguration.sol ' ;
7
+ import {PoolLogic} from '../libraries/logic/PoolLogic.sol ' ;
10
8
import {ReserveLogic} from '../libraries/logic/ReserveLogic.sol ' ;
11
9
import {GenericLogic} from '../libraries/logic/GenericLogic.sol ' ;
12
- import {ValidationLogic} from '../libraries/logic/ValidationLogic.sol ' ;
13
10
import {EModeLogic} from '../libraries/logic/EModeLogic.sol ' ;
14
11
import {SupplyLogic} from '../libraries/logic/SupplyLogic.sol ' ;
15
12
import {FlashLoanLogic} from '../libraries/logic/FlashLoanLogic.sol ' ;
16
13
import {BorrowLogic} from '../libraries/logic/BorrowLogic.sol ' ;
17
14
import {LiquidationLogic} from '../libraries/logic/LiquidationLogic.sol ' ;
18
- import {ReserveConfiguration} from '../libraries/configuration/ReserveConfiguration.sol ' ;
19
15
import {DataTypes} from '../libraries/types/DataTypes.sol ' ;
20
16
import {BridgeLogic} from '../libraries/logic/BridgeLogic.sol ' ;
21
17
import {IERC20WithPermit } from '../../interfaces/IERC20WithPermit.sol ' ;
22
18
import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.sol ' ;
23
- import {IAToken} from '../../interfaces/IAToken.sol ' ;
24
19
import {IPool} from '../../interfaces/IPool.sol ' ;
25
20
import {IACLManager} from '../../interfaces/IACLManager.sol ' ;
26
21
import {PoolStorage} from './PoolStorage.sol ' ;
@@ -43,10 +38,7 @@ import {PoolStorage} from './PoolStorage.sol';
43
38
* PoolAddressesProvider
44
39
**/
45
40
contract Pool is VersionedInitializable , IPool , PoolStorage {
46
- using WadRayMath for uint256 ;
47
- using GPv2SafeERC20 for IERC20 ;
48
41
using ReserveLogic for DataTypes.ReserveData;
49
- using ReserveConfiguration for DataTypes.ReserveConfigurationMap;
50
42
51
43
uint256 public constant POOL_REVISION = 0x1 ;
52
44
IPoolAddressesProvider public immutable ADDRESSES_PROVIDER;
@@ -449,27 +441,7 @@ contract Pool is VersionedInitializable, IPool, PoolStorage {
449
441
450
442
/// @inheritdoc IPool
451
443
function mintToTreasury (address [] calldata assets ) external override {
452
- for (uint256 i = 0 ; i < assets.length ; i++ ) {
453
- address assetAddress = assets[i];
454
-
455
- DataTypes.ReserveData storage reserve = _reserves[assetAddress];
456
-
457
- // this cover both inactive reserves and invalid reserves since the flag will be 0 for both
458
- if (! reserve.configuration.getActive ()) {
459
- continue ;
460
- }
461
-
462
- uint256 accruedToTreasury = reserve.accruedToTreasury;
463
-
464
- if (accruedToTreasury != 0 ) {
465
- reserve.accruedToTreasury = 0 ;
466
- uint256 normalizedIncome = reserve.getNormalizedIncome ();
467
- uint256 amountToMint = accruedToTreasury.rayMul (normalizedIncome);
468
- IAToken (reserve.aTokenAddress).mintToTreasury (amountToMint, normalizedIncome);
469
-
470
- emit MintedToTreasury (assetAddress, amountToMint);
471
- }
472
- }
444
+ PoolLogic.executeMintToTreasury (_reserves, assets);
473
445
}
474
446
475
447
/// @inheritdoc IPool
@@ -566,23 +538,23 @@ contract Pool is VersionedInitializable, IPool, PoolStorage {
566
538
567
539
/// @inheritdoc IPool
568
540
function getReservesList () external view override returns (address [] memory ) {
569
- uint256 reserveListCount = _reservesCount;
541
+ uint256 reservesListCount = _reservesCount;
570
542
uint256 droppedReservesCount = 0 ;
571
- address [] memory reserves = new address [](reserveListCount );
543
+ address [] memory reservesList = new address [](reservesListCount );
572
544
573
- for (uint256 i = 0 ; i < reserveListCount ; i++ ) {
545
+ for (uint256 i = 0 ; i < reservesListCount ; i++ ) {
574
546
if (_reservesList[i] != address (0 )) {
575
- reserves [i - droppedReservesCount] = _reservesList[i];
547
+ reservesList [i - droppedReservesCount] = _reservesList[i];
576
548
} else {
577
549
droppedReservesCount++ ;
578
550
}
579
551
}
580
552
581
553
// Reduces the length of the reserves array by `droppedReservesCount`
582
554
assembly {
583
- mstore (reserves , sub (reserveListCount , droppedReservesCount))
555
+ mstore (reservesList , sub (reservesListCount , droppedReservesCount))
584
556
}
585
- return reserves ;
557
+ return reservesList ;
586
558
}
587
559
588
560
/// @inheritdoc IPool
@@ -606,7 +578,7 @@ contract Pool is VersionedInitializable, IPool, PoolStorage {
606
578
}
607
579
608
580
/// @inheritdoc IPool
609
- function MAX_NUMBER_RESERVES () public view virtual override returns (uint256 ) {
581
+ function MAX_NUMBER_RESERVES () public view virtual override returns (uint16 ) {
610
582
return ReserveConfiguration.MAX_RESERVES_COUNT;
611
583
}
612
584
@@ -647,22 +619,28 @@ contract Pool is VersionedInitializable, IPool, PoolStorage {
647
619
address variableDebtAddress ,
648
620
address interestRateStrategyAddress
649
621
) external override onlyPoolConfigurator {
650
- require (Address.isContract (asset), Errors.NOT_CONTRACT);
651
- _reserves[asset].init (
652
- aTokenAddress,
653
- stableDebtAddress,
654
- variableDebtAddress,
655
- interestRateStrategyAddress
656
- );
657
- _addReserveToList (asset);
622
+ if (
623
+ PoolLogic.executeInitReserve (
624
+ _reserves,
625
+ _reservesList,
626
+ DataTypes.InitReserveParams ({
627
+ asset: asset,
628
+ aTokenAddress: aTokenAddress,
629
+ stableDebtAddress: stableDebtAddress,
630
+ variableDebtAddress: variableDebtAddress,
631
+ interestRateStrategyAddress: interestRateStrategyAddress,
632
+ reservesCount: _reservesCount,
633
+ maxNumberReserves: MAX_NUMBER_RESERVES ()
634
+ })
635
+ )
636
+ ) {
637
+ _reservesCount++ ;
638
+ }
658
639
}
659
640
660
641
/// @inheritdoc IPool
661
642
function dropReserve (address asset ) external virtual override onlyPoolConfigurator {
662
- DataTypes.ReserveData storage reserve = _reserves[asset];
663
- ValidationLogic.validateDropReserve (_reservesList, reserve, asset);
664
- _reservesList[_reserves[asset].id] = address (0 );
665
- delete _reserves[asset];
643
+ PoolLogic.executeDropReserve (_reserves, _reservesList, asset);
666
644
}
667
645
668
646
/// @inheritdoc IPool
@@ -745,9 +723,7 @@ contract Pool is VersionedInitializable, IPool, PoolStorage {
745
723
746
724
/// @inheritdoc IPool
747
725
function resetIsolationModeTotalDebt (address asset ) external override onlyPoolConfigurator {
748
- require (_reserves[asset].configuration.getDebtCeiling () == 0 , Errors.DEBT_CEILING_NOT_ZERO);
749
- _reserves[asset].isolationModeTotalDebt = 0 ;
750
- emit IsolationModeTotalDebtUpdated (asset, 0 );
726
+ PoolLogic.executeResetIsolationModeTotalDebt (_reserves, asset);
751
727
}
752
728
753
729
/// @inheritdoc IPool
@@ -756,31 +732,7 @@ contract Pool is VersionedInitializable, IPool, PoolStorage {
756
732
address to ,
757
733
uint256 amount
758
734
) external override onlyPoolAdmin {
759
- IERC20 (token).safeTransfer (to, amount);
760
- }
761
-
762
- /**
763
- * @notice Add an asset to the reserve list
764
- * @param asset The address of the underlying asset
765
- */
766
- function _addReserveToList (address asset ) internal {
767
- bool reserveAlreadyAdded = _reserves[asset].id != 0 || _reservesList[0 ] == asset;
768
- require (! reserveAlreadyAdded, Errors.RESERVE_ALREADY_ADDED);
769
-
770
- uint16 reservesCount = _reservesCount;
771
-
772
- for (uint16 i = 0 ; i < reservesCount; i++ ) {
773
- if (_reservesList[i] == address (0 )) {
774
- _reserves[asset].id = i;
775
- _reservesList[i] = asset;
776
- return ;
777
- }
778
- }
779
- require (reservesCount < MAX_NUMBER_RESERVES (), Errors.NO_MORE_RESERVES_ALLOWED);
780
- _reserves[asset].id = reservesCount;
781
- _reservesList[reservesCount] = asset;
782
- // no need to check for overflow - the require above must ensure that max number of reserves < type(uint16).max
783
- _reservesCount = reservesCount + 1 ;
735
+ PoolLogic.executeRescueTokens (token, to, amount);
784
736
}
785
737
786
738
/// @inheritdoc IPool
0 commit comments