diff --git a/contracts/misc/PermissionedWETHGateway.sol b/contracts/misc/PermissionedWETHGateway.sol index 648d5f68..782e3a0b 100644 --- a/contracts/misc/PermissionedWETHGateway.sol +++ b/contracts/misc/PermissionedWETHGateway.sol @@ -37,7 +37,7 @@ contract PermissionedWETHGateway is WETHGateway { ) public payable override { ILendingPool pool = ILendingPool(lendingPool); - require(_isDepositorOrBorrowerOrLiquidator(msg.sender, pool), Errors.USER_UNAUTHORIZED); + require(_isInRole(msg.sender, DataTypes.Roles.DEPOSITOR, pool), Errors.USER_UNAUTHORIZED); super.depositETH(lendingPool, onBehalfOf, referralCode); } @@ -57,12 +57,12 @@ contract PermissionedWETHGateway is WETHGateway { ) public payable override { ILendingPool pool = ILendingPool(lendingPool); - require(_isDepositorOrBorrowerOrLiquidator(msg.sender, pool), Errors.USER_UNAUTHORIZED); + require(_isInRole(msg.sender, DataTypes.Roles.BORROWER, pool), Errors.USER_UNAUTHORIZED); super.repayETH(lendingPool, amount, rateMode, onBehalfOf); } - function _isDepositorOrBorrowerOrLiquidator(address user, ILendingPool pool) + function _isInRole(address user, DataTypes.Roles role, ILendingPool pool) internal view returns (bool) @@ -72,12 +72,6 @@ contract PermissionedWETHGateway is WETHGateway { IPermissionManager manager = IPermissionManager(provider.getAddress(keccak256('PERMISSION_MANAGER'))); - uint256[] memory roles = new uint256[](3); - - roles[0] = uint256(DataTypes.Roles.DEPOSITOR); - roles[1] = uint256(DataTypes.Roles.BORROWER); - roles[2] = uint256(DataTypes.Roles.LIQUIDATOR); - - return manager.isInAnyRole(msg.sender, roles); + return manager.isInRole(user, uint256(role)); } } diff --git a/contracts/protocol/lendingpool/PermissionedLendingPool.sol b/contracts/protocol/lendingpool/PermissionedLendingPool.sol index 0de1664c..6b8fa64b 100644 --- a/contracts/protocol/lendingpool/PermissionedLendingPool.sol +++ b/contracts/protocol/lendingpool/PermissionedLendingPool.sol @@ -18,15 +18,19 @@ contract PermissionedLendingPool is LendingPool { modifier onlyDepositors(address user) { require( - _isDepositorOrBorrowerOrLiquidator(msg.sender) && - ((user == msg.sender) || _isInRole(user, DataTypes.Roles.DEPOSITOR)), + _isInRole(user, DataTypes.Roles.DEPOSITOR) && + ((user == msg.sender) || _isInRole(msg.sender, DataTypes.Roles.DEPOSITOR)), Errors.DEPOSITOR_UNAUTHORIZED ); _; } modifier onlyBorrowers(address user) { - require(_isInRole(user, DataTypes.Roles.BORROWER), Errors.BORROWER_UNAUTHORIZED); + require( + _isInRole(user, DataTypes.Roles.BORROWER) && + ((user == msg.sender) || _isInRole(msg.sender, DataTypes.Roles.BORROWER)), + Errors.BORROWER_UNAUTHORIZED + ); _; } @@ -35,11 +39,6 @@ contract PermissionedLendingPool is LendingPool { _; } - modifier onlyDepositorsOrBorrowersOrLiquidators { - require(_isDepositorOrBorrowerOrLiquidator(msg.sender), Errors.USER_UNAUTHORIZED); - _; - } - modifier onlyStableRateManagers { require( _isInRole(msg.sender, DataTypes.Roles.STABLE_RATE_MANAGER), @@ -129,7 +128,7 @@ contract PermissionedLendingPool is LendingPool { uint256 amount, uint256 rateMode, address onBehalfOf - ) public virtual override onlyDepositorsOrBorrowersOrLiquidators returns (uint256) { + ) public virtual override onlyBorrowers(onBehalfOf) returns (uint256) { return super.repay(asset, amount, rateMode, onBehalfOf); } @@ -268,18 +267,4 @@ contract PermissionedLendingPool is LendingPool { uint256(role) ); } - - function _isDepositorOrBorrowerOrLiquidator(address user) internal view returns (bool) { - uint256[] memory roles = new uint256[](3); - - roles[0] = uint256(DataTypes.Roles.DEPOSITOR); - roles[1] = uint256(DataTypes.Roles.BORROWER); - roles[2] = uint256(DataTypes.Roles.LIQUIDATOR); - - return - IPermissionManager(_addressesProvider.getAddress(PERMISSION_MANAGER)).isInAnyRole( - user, - roles - ); - } }