-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: copy module access controller from the modules repo
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {IOracle} from '../../interfaces/IOracle.sol'; | ||
import {IModuleAccessController} from '../../interfaces/access/IModuleAccessController.sol'; | ||
import {Module} from '../Module.sol'; | ||
import {CommonAccessController} from './CommonAccessController.sol'; | ||
|
||
abstract contract ModuleAccessController is IModuleAccessController, CommonAccessController, Module { | ||
constructor(IOracle _oracle) Module(_oracle) {} | ||
|
||
/** | ||
* @notice Returns an access control object using the contract address as user and the given data | ||
* @dev should only be used by modules as the self-access-control object | ||
* @param _data Arbitrary data | ||
* @return _accessControl The self access control for this contract. | ||
*/ | ||
function _defaultAccessControl(bytes memory _data) internal view returns (AccessControl memory _accessControl) { | ||
_accessControl = AccessControl({user: address(this), data: _data}); | ||
} | ||
|
||
/** | ||
* @notice Returns an access control object using the contract address as user, and empty data | ||
* | ||
* @dev should only be used by modules as the self-access-control object | ||
* @return _accessControl The self access control for this contract. | ||
*/ | ||
function _defaultAccessControl() internal view returns (AccessControl memory _accessControl) { | ||
_accessControl = _defaultAccessControl(bytes('')); | ||
} | ||
|
||
modifier hasAccess( | ||
address _accessModule, | ||
bytes32 _typehash, | ||
bytes memory _params, | ||
AccessControl memory _accessControl | ||
) { | ||
if (_accessControl.user != msg.sender) { | ||
if (_accessModule == address(0)) { | ||
revert AccessController_NoAccess(); | ||
} else { | ||
if (!ORACLE.isAccessModuleApproved(_accessControl.user, _accessModule)) { | ||
revert ModuleAccessController_AccessModuleNotApproved(); | ||
} | ||
_hasAccess(_accessModule, _typehash, _params, _accessControl); | ||
} | ||
} | ||
_; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {IAccessController} from './IAccessController.sol'; | ||
|
||
/** | ||
* @title Module Access Controller Interface | ||
* @notice Interface for the module access controller | ||
*/ | ||
interface IModuleAccessController is IAccessController { | ||
/** | ||
* @notice Thrown when user has not approved the access module | ||
*/ | ||
error ModuleAccessController_AccessModuleNotApproved(); | ||
} |