refactor: refactored modifiers

This commit is contained in:
The3D 2021-08-04 13:49:09 +02:00
parent 7ebd95e22e
commit 261bf737ea

View File

@ -19,11 +19,7 @@ contract PermissionedLendingPool is IPermissionedLendingPool, LendingPool {
bytes32 public constant PERMISSION_MANAGER = keccak256('PERMISSION_MANAGER'); bytes32 public constant PERMISSION_MANAGER = keccak256('PERMISSION_MANAGER');
modifier onlyDepositors(address user) { modifier onlyDepositors(address user) {
require( _onlyDepositors(user);
_isInRole(user, DataTypes.Roles.DEPOSITOR) &&
((user == msg.sender) || _isInRole(msg.sender, DataTypes.Roles.DEPOSITOR)),
Errors.PLP_DEPOSITOR_UNAUTHORIZED
);
_; _;
} }
@ -33,16 +29,12 @@ contract PermissionedLendingPool is IPermissionedLendingPool, LendingPool {
} }
modifier onlyValidPermissionAdmin(address user) { modifier onlyValidPermissionAdmin(address user) {
require(_permissionAdminValid(user), Errors.PLP_INVALID_PERMISSION_ADMIN); _onlyValidPermissionAdmin(user);
_; _;
} }
modifier onlyBorrowers(address user) { modifier onlyBorrowers(address user) {
require( _onlyBorrowers(user);
_isInRole(user, DataTypes.Roles.BORROWER) &&
((user == msg.sender) || _isInRole(msg.sender, DataTypes.Roles.BORROWER)),
Errors.PLP_BORROWER_UNAUTHORIZED
);
_; _;
} }
@ -352,4 +344,24 @@ contract PermissionedLendingPool is IPermissionedLendingPool, LendingPool {
IPermissionManager(_addressesProvider.getAddress(PERMISSION_MANAGER)) IPermissionManager(_addressesProvider.getAddress(PERMISSION_MANAGER))
.isUserPermissionAdminValid(user); .isUserPermissionAdminValid(user);
} }
function _onlyDepositors(address user) internal view {
require(
_isInRole(user, DataTypes.Roles.DEPOSITOR) &&
((user == msg.sender) || _isInRole(msg.sender, DataTypes.Roles.DEPOSITOR)),
Errors.PLP_DEPOSITOR_UNAUTHORIZED
);
}
function _onlyBorrowers(address user) internal view {
require(
_isInRole(user, DataTypes.Roles.BORROWER) &&
((user == msg.sender) || _isInRole(msg.sender, DataTypes.Roles.BORROWER)),
Errors.PLP_BORROWER_UNAUTHORIZED
);
}
function _onlyValidPermissionAdmin(address user) internal view {
require(_permissionAdminValid(user), Errors.PLP_INVALID_PERMISSION_ADMIN);
}
} }