-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Ashitaka <[email protected]> Co-authored-by: Gas One Cent <[email protected]>
- Loading branch information
1 parent
7d7a76d
commit 822962a
Showing
44 changed files
with
943 additions
and
382 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
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
51 changes: 51 additions & 0 deletions
51
solidity/contracts/modules/access/ModuleAccessController.sol
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,51 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {CommonAccessController} from '@defi-wonderland/prophet-core/solidity/contracts/CommonAccessController.sol'; | ||
|
||
import {IModuleAccessController} from '../../../interfaces/modules/access/IModuleAccessController.sol'; | ||
import {Module} from '@defi-wonderland/prophet-core/solidity/contracts/Module.sol'; | ||
import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle.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
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
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
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
Oops, something went wrong.