mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
feat: changed behavior for the validation of depositors and borrowers in deposit() and repay()
This commit is contained in:
parent
f2e8c2337d
commit
f228a5d16a
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user