-
-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathCaveatEnforcer.sol
More file actions
70 lines (59 loc) · 2.38 KB
/
CaveatEnforcer.sol
File metadata and controls
70 lines (59 loc) · 2.38 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
58
59
60
61
62
63
64
65
66
67
68
69
70
// SPDX-License-Identifier: MIT AND Apache-2.0
pragma solidity ^0.8.23;
import { ModeLib } from "@erc7579/lib/ModeLib.sol";
import { ICaveatEnforcer } from "../interfaces/ICaveatEnforcer.sol";
import { ModeCode, ExecType } from "../utils/Types.sol";
import { CALLTYPE_SINGLE, CALLTYPE_BATCH, EXECTYPE_DEFAULT, EXECTYPE_TRY } from "../utils/Constants.sol";
/**
* @title CaveatEnforcer
* @dev This abstract contract enforces caveats before and after the execution of an execution.
*/
abstract contract CaveatEnforcer is ICaveatEnforcer {
using ModeLib for ModeCode;
/// @inheritdoc ICaveatEnforcer
function beforeAllHook(bytes calldata, bytes calldata, ModeCode, bytes calldata, bytes32, address, address) public virtual { }
/// @inheritdoc ICaveatEnforcer
function beforeHook(bytes calldata, bytes calldata, ModeCode, bytes calldata, bytes32, address, address) public virtual { }
/// @inheritdoc ICaveatEnforcer
function afterHook(bytes calldata, bytes calldata, ModeCode, bytes calldata, bytes32, address, address) public virtual { }
/// @inheritdoc ICaveatEnforcer
function afterAllHook(bytes calldata, bytes calldata, ModeCode, bytes calldata, bytes32, address, address) public virtual { }
/**
* @dev Require the function call to be in single call type
*/
modifier onlySingleCallTypeMode(ModeCode _mode) {
{
require(ModeLib.getCallType(_mode) == CALLTYPE_SINGLE, "CaveatEnforcer:invalid-call-type");
}
_;
}
/**
* @dev Require the function call to be in batch call type
*/
modifier onlyBatchCallTypeMode(ModeCode _mode) {
{
require(ModeLib.getCallType(_mode) == CALLTYPE_BATCH, "CaveatEnforcer:invalid-call-type");
}
_;
}
/**
* @dev Require the function call to be in default execution mode
*/
modifier onlyDefaultExecutionMode(ModeCode _mode) {
{
(, ExecType _execType,,) = _mode.decode();
require(_execType == EXECTYPE_DEFAULT, "CaveatEnforcer:invalid-execution-type");
}
_;
}
/**
* @dev Require the function call to be in try execution mode
*/
modifier onlyTryExecutionMode(ModeCode _mode) {
{
(, ExecType _execType,,) = _mode.decode();
require(_execType == EXECTYPE_TRY, "CaveatEnforcer:invalid-execution-type");
}
_;
}
}