Skip to content

Commit

Permalink
add configure to module
Browse files Browse the repository at this point in the history
  • Loading branch information
Raul committed Oct 23, 2023
1 parent 2612014 commit 132e366
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
7 changes: 7 additions & 0 deletions contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ library Errors {
/// @notice The amount specified may not be zero.
error ZeroAmount();

////////////////////////////////////////////////////////////////////////////
// BaseModule //
////////////////////////////////////////////////////////////////////////////

/// @notice The caller to base module is not the module registry.
error BaseModule_CallerNotModuleRegistry();

////////////////////////////////////////////////////////////////////////////
// HookRegistry //
////////////////////////////////////////////////////////////////////////////
Expand Down
27 changes: 22 additions & 5 deletions contracts/modules/base/BaseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IModule } from "contracts/interfaces/modules/base/IModule.sol";
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import { FranchiseRegistry } from "contracts/FranchiseRegistry.sol";
import { HookRegistry } from "./HookRegistry.sol";
import { Errors } from "contracts/lib/Errors.sol";

abstract contract BaseModule is IModule, HookRegistry {

Expand All @@ -16,24 +17,40 @@ abstract contract BaseModule is IModule, HookRegistry {
address public immutable IPA_REGISTRY;
address public immutable MODULE_REGISTRY;

modifier onlyModuleRegistry() {
// TODO: Enforce this
// if (msg.sender != MODULE_REGISTRY)
// revert Errors.BaseModule_CallerNotModuleRegistry();
_;
}

constructor(ModuleConstruction memory params) {
IPA_REGISTRY = params.ipaRegistry;
MODULE_REGISTRY = params.moduleRegistry;
}

function execute(bytes calldata selfParams, bytes[] calldata preHookParams, bytes[] calldata postHookParams) external {
// Should we include a request Id?
_verifyExecution(msg.sender, selfParams);
function execute(
address caller,
bytes calldata selfParams,
bytes[] calldata preHookParams,
bytes[] calldata postHookParams
) external onlyModuleRegistry {
_verifyExecution(caller, selfParams);
if (!_executePreHooks(preHookParams)) {
emit RequestPending(msg.sender);
emit RequestPending(caller);
return;
}
_performAction(selfParams);
_executePostHooks(postHookParams);
emit RequestCompleted(msg.sender);
emit RequestCompleted(caller);
}

function configure(bytes calldata params) external onlyModuleRegistry {
_configure(msg.sender, params);
}

function _hookRegistryAdmin() virtual override internal view returns (address);
function _configure(address caller, bytes calldata params) virtual internal;
function _verifyExecution(address caller, bytes calldata selfParams) virtual internal {}
function _executePreHooks(bytes[] calldata params) virtual internal returns (bool) {}
function _performAction(bytes calldata params) virtual internal {}
Expand Down

0 comments on commit 132e366

Please sign in to comment.