-
Notifications
You must be signed in to change notification settings - Fork 4
refactor: access module #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
52d9b38
refactor: rename AccessControlModule to AccessModule
xorsal f76894f
refactor: quick refactor to work in prophet-modules
xorsal e5a9a57
fix: update function's name
xorsal 17b27bf
docs: update natspec
xorsal 1bc8bb9
feat: eoa
ashitakah 5a0a725
feat: eoa
ashitakah 14f565e
feat: address comments
xorsal 823459f
refactor: rename modules/accessControl to modules/access
xorsal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,41 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {IAccessController} from '../interfaces/IAccessController.sol'; | ||
import {IAccessModule} from '../interfaces/modules/accessControl/IAccessModule.sol'; | ||
|
||
abstract contract CommonAccessController is IAccessController { | ||
/** | ||
* @notice Modifier to check if the caller has access to the user | ||
* @dev The return value of this function must always be `true`, | ||
* otherwise it would revert. | ||
* @param _accessModule The access module | ||
* @param _typehash The typehash | ||
* @param _params The params passed to the typehash | ||
* @param _accessControl The access control struct | ||
*/ | ||
function _hasAccess( | ||
address _accessModule, | ||
bytes32 _typehash, | ||
bytes memory _params, | ||
AccessControl memory _accessControl | ||
) internal returns (bool _granted) { | ||
// todo: if _accessModule == address(0) we should skip this check. | ||
_granted = msg.sender == _accessControl.user | ||
|| ( | ||
_accessModule != address(0) | ||
0xJabberwock marked this conversation as resolved.
Show resolved
Hide resolved
|
||
&& IAccessModule(_accessModule).hasAccess( | ||
abi.encode( | ||
IAccessModule.AccessControlParameters({ | ||
0xJabberwock marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sender: msg.sender, | ||
accessControl: _accessControl, | ||
typehash: _typehash, | ||
params: _params | ||
}) | ||
) | ||
) | ||
); | ||
|
||
if (!_granted) revert AccessController_NoAccess(); | ||
} | ||
} |
This file contains hidden or 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
This file contains hidden or 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,43 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {IOracleAccessController} from '../interfaces/IOracleAccessController.sol'; | ||
import {CommonAccessController} from './CommonAccessController.sol'; | ||
|
||
abstract contract OracleAccessController is IOracleAccessController, CommonAccessController { | ||
/// @inheritdoc IOracleAccessController | ||
mapping(address _user => mapping(address _accessModule => bool _approved)) public isAccessModuleApproved; | ||
|
||
modifier hasAccess( | ||
address _accessModule, | ||
bytes32 _typehash, | ||
bytes memory _params, | ||
AccessControl memory _accessControl | ||
) { | ||
// we do not care about `_hasAccess` return value, check function's @notice | ||
_hasAccess(_accessModule, _typehash, _params, _accessControl); | ||
xorsal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_; | ||
} | ||
|
||
/** | ||
* @notice Modifier to check if the user approved to the access module | ||
* @param _user The address of setAccessModulethe user | ||
* @param _accessModule The access module to check if approved | ||
*/ | ||
modifier isApproved(address _user, address _accessModule) { | ||
if (_accessModule != address(0) && !isAccessModuleApproved[_user][_accessModule]) { | ||
revert OracleAccessController_AccessModuleNotApproved(); | ||
} | ||
_; | ||
} | ||
|
||
/// @inheritdoc IOracleAccessController | ||
function setAccessModule(address _accessModule, bool _approved) external { | ||
if (isAccessModuleApproved[msg.sender][_accessModule] == _approved) { | ||
revert OracleAccessController_AccessModuleAlreadySet(); | ||
} | ||
isAccessModuleApproved[msg.sender][_accessModule] = _approved; | ||
|
||
emit AccessModuleSet(msg.sender, _accessModule, _approved); | ||
} | ||
} |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.