forked from erc6900/reference-implementation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectCallModule.sol
More file actions
57 lines (46 loc) · 1.89 KB
/
DirectCallModule.sol
File metadata and controls
57 lines (46 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";
import {IERC6900Account} from "../../../src/interfaces/IERC6900Account.sol";
import {IERC6900ExecutionHookModule} from "../../../src/interfaces/IERC6900ExecutionHookModule.sol";
import {BaseModule} from "../../../src/modules/BaseModule.sol";
contract DirectCallModule is BaseModule, IERC6900ExecutionHookModule {
bool public preHookRan = false;
bool public postHookRan = false;
function onInstall(bytes calldata) external override {}
function onUninstall(bytes calldata) external override {}
function directCall() external returns (bytes memory) {
return IERC6900Account(msg.sender).execute(address(this), 0, abi.encodeCall(this.getData, ()));
}
function getData() external pure returns (bytes memory) {
return hex"04546b";
}
function moduleId() external pure returns (string memory) {
return "erc6900.direct-call-module.1.0.0";
}
function preExecutionHook(uint32, address sender, uint256, bytes calldata)
external
override
returns (bytes memory)
{
require(sender == address(this), "mock direct call pre execution hook failed");
preHookRan = true;
return abi.encode(keccak256(hex"04546b"));
}
function postExecutionHook(uint32, bytes calldata preExecHookData) external override {
require(
abi.decode(preExecHookData, (bytes32)) == keccak256(hex"04546b"),
"mock direct call post execution hook failed"
);
postHookRan = true;
}
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(BaseModule, IERC165)
returns (bool)
{
return interfaceId == type(IERC6900ExecutionHookModule).interfaceId || super.supportsInterface(interfaceId);
}
}