From 26b632d9101fff3aa68ae8014e46645ec798ee40 Mon Sep 17 00:00:00 2001 From: Lukas Date: Mon, 7 Oct 2024 15:08:01 +0200 Subject: [PATCH] feat: use addresses provider instead of acl (#66) umbrella should be a single address tied to the pool, so using acl is overkill, which also will be cheaper --- .../protocol/libraries/helpers/Errors.sol | 2 +- src/contracts/protocol/pool/Pool.sol | 21 +++++++------------ tests/protocol/pool/Pool.Deficit.sol | 12 +++++------ 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/contracts/protocol/libraries/helpers/Errors.sol b/src/contracts/protocol/libraries/helpers/Errors.sol index 93dd126e..f5f4e46c 100644 --- a/src/contracts/protocol/libraries/helpers/Errors.sol +++ b/src/contracts/protocol/libraries/helpers/Errors.sol @@ -101,6 +101,6 @@ library Errors { string public constant INVALID_FREEZE_STATE = '99'; // Reserve is already in the passed freeze state string public constant NOT_BORROWABLE_IN_EMODE = '100'; // Asset not borrowable in eMode string public constant USER_NOT_IN_BAD_DEBT = '101'; // The user is not in bad debt - string public constant CALLER_NOT_COVERAGE_ADMIN = '102'; // The caller of the function is not the coverage admin + string public constant CALLER_NOT_UMBRELLA = '102'; // The caller of the function is not the umbrella contract string public constant RESERVE_NOT_IN_DEFICIT = '103'; // The reserve is not in deficit } diff --git a/src/contracts/protocol/pool/Pool.sol b/src/contracts/protocol/pool/Pool.sol index c079a517..8d0c0880 100644 --- a/src/contracts/protocol/pool/Pool.sol +++ b/src/contracts/protocol/pool/Pool.sol @@ -66,10 +66,13 @@ abstract contract Pool is VersionedInitializable, PoolStorage, IPool { } /** - * @dev Only aToken Burner can call functions marked by this modifier. + * @dev Only the umbrella contract can call functions marked by this modifier. */ - modifier onlyCoverageAdmin() { - _onlyCoverageAdmin(); + modifier onlyUmbrella() { + require( + ADDRESSES_PROVIDER.getAddress(bytes32('UMBRELLA')) == msg.sender, + Errors.CALLER_NOT_UMBRELLA + ); _; } @@ -94,13 +97,6 @@ abstract contract Pool is VersionedInitializable, PoolStorage, IPool { ); } - function _onlyCoverageAdmin() internal view virtual { - require( - IAccessControl(ADDRESSES_PROVIDER.getACLManager()).hasRole('COVERAGE_ADMIN', msg.sender), - Errors.CALLER_NOT_COVERAGE_ADMIN - ); - } - /** * @dev Constructor. * @param provider The address of the PoolAddressesProvider contract @@ -864,10 +860,7 @@ abstract contract Pool is VersionedInitializable, PoolStorage, IPool { } /// @inheritdoc IPool - function eliminateReserveDeficit( - address asset, - uint256 amount - ) external override onlyCoverageAdmin { + function eliminateReserveDeficit(address asset, uint256 amount) external override onlyUmbrella { ReserveLogic.eliminateDeficit( _reserves, _reservesList, diff --git a/tests/protocol/pool/Pool.Deficit.sol b/tests/protocol/pool/Pool.Deficit.sol index 9b9a4dfc..dc98c1c4 100644 --- a/tests/protocol/pool/Pool.Deficit.sol +++ b/tests/protocol/pool/Pool.Deficit.sol @@ -25,7 +25,7 @@ contract PoolDeficitTests is TestnetProcedures { (address reserveToken, uint256 currentDeficit) = _createReserveDeficit(supplyAmount); vm.prank(poolAdmin); - IAccessControl(report.aclManager).grantRole('COVERAGE_ADMIN', coverageAdmin); + contracts.poolAddressesProvider.setAddress(bytes32('UMBRELLA'), coverageAdmin); deal(reserveToken, coverageAdmin, currentDeficit); @@ -49,7 +49,7 @@ contract PoolDeficitTests is TestnetProcedures { vm.assume(amountToCover != 0 && amountToCover < currentDeficit); vm.prank(poolAdmin); - IAccessControl(report.aclManager).grantRole('COVERAGE_ADMIN', coverageAdmin); + contracts.poolAddressesProvider.setAddress(bytes32('UMBRELLA'), coverageAdmin); deal(reserveToken, coverageAdmin, currentDeficit); @@ -73,7 +73,7 @@ contract PoolDeficitTests is TestnetProcedures { vm.assume(cAdminBorrowAmount != 0 && uint256(cAdminBorrowAmount) * 2 <= currentDeficit); vm.prank(poolAdmin); - IAccessControl(report.aclManager).grantRole('COVERAGE_ADMIN', coverageAdmin); + contracts.poolAddressesProvider.setAddress(bytes32('UMBRELLA'), coverageAdmin); deal(reserveToken, coverageAdmin, currentDeficit); @@ -93,7 +93,7 @@ contract PoolDeficitTests is TestnetProcedures { _filterAddresses(caller); (address reserveToken, uint256 currentDeficit) = _createReserveDeficit(supplyAmount); - vm.expectRevert(bytes(Errors.CALLER_NOT_COVERAGE_ADMIN)); + vm.expectRevert(bytes(Errors.CALLER_NOT_UMBRELLA)); vm.prank(caller); contracts.poolProxy.eliminateReserveDeficit(reserveToken, currentDeficit); } @@ -107,7 +107,7 @@ contract PoolDeficitTests is TestnetProcedures { (address reserveToken, ) = _createReserveDeficit(supplyAmount); vm.prank(poolAdmin); - IAccessControl(report.aclManager).grantRole('COVERAGE_ADMIN', coverageAdmin); + contracts.poolAddressesProvider.setAddress(bytes32('UMBRELLA'), coverageAdmin); vm.startPrank(coverageAdmin); vm.expectRevert(bytes(Errors.INVALID_AMOUNT)); @@ -120,7 +120,7 @@ contract PoolDeficitTests is TestnetProcedures { _filterAddresses(coverageAdmin); vm.prank(poolAdmin); - IAccessControl(report.aclManager).grantRole('COVERAGE_ADMIN', coverageAdmin); + contracts.poolAddressesProvider.setAddress(bytes32('UMBRELLA'), coverageAdmin); vm.startPrank(coverageAdmin);