Skip to content

Commit 56b8bc9

Browse files
authored
Feat/events (#120)
* events for install/uninstall * chore add even on install without init
1 parent 0e1c950 commit 56b8bc9

File tree

8 files changed

+330
-56
lines changed

8 files changed

+330
-56
lines changed

broadcast/DeployKernel.s.sol/11155111/run-1718039360.json

Lines changed: 124 additions & 0 deletions
Large diffs are not rendered by default.

broadcast/DeployKernel.s.sol/11155111/run-1718039506.json

Lines changed: 124 additions & 0 deletions
Large diffs are not rendered by default.

broadcast/DeployKernel.s.sol/11155111/run-latest.json

Lines changed: 40 additions & 40 deletions
Large diffs are not rendered by default.

src/Kernel.sol

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,18 +398,21 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
398398
// NOTE: for hook, kernel does not support independent hook install,
399399
// hook is expected to be paired with proper validator/executor/selector
400400
IHook(module).onInstall(initData);
401+
emit ModuleInstalled(moduleType, module);
401402
} else if (moduleType == MODULE_TYPE_POLICY) {
402403
// force call onInstall for policy
403404
// NOTE: for policy, kernel does not support independent policy install,
404405
// policy is expected to be paired with proper permissionId
405406
// to "ADD" permission, use "installValidations()" function
406407
IPolicy(module).onInstall(initData);
408+
emit ModuleInstalled(moduleType, module);
407409
} else if (moduleType == MODULE_TYPE_SIGNER) {
408410
// force call onInstall for signer
409411
// NOTE: for signer, kernel does not support independent signer install,
410412
// signer is expected to be paired with proper permissionId
411413
// to "ADD" permission, use "installValidations()" function
412414
ISigner(module).onInstall(initData);
415+
emit ModuleInstalled(moduleType, module);
413416
} else {
414417
revert InvalidModuleType();
415418
}
@@ -458,10 +461,11 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
458461
// remove hook on root validator to prevent kernel from being locked
459462
_validationStorage().validationConfig[vId].hook = IHook(address(1));
460463
}
461-
// force call onInstall for hook
464+
// force call onUninstall for hook
462465
// NOTE: for hook, kernel does not support independent hook install,
463466
// hook is expected to be paired with proper validator/executor/selector
464467
ModuleLib.uninstallModule(module, deInitData);
468+
emit ModuleUninstalled(moduleType, module);
465469
} else if (moduleType == 5) {
466470
ValidationId rootValidator = _validationStorage().rootValidator;
467471
bytes32 permissionId = bytes32(deInitData[0:32]);
@@ -470,11 +474,12 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
470474
revert RootValidatorCannotBeRemoved();
471475
}
472476
}
473-
// force call onInstall for policy
477+
// force call onUninstall for policy
474478
// NOTE: for policy, kernel does not support independent policy install,
475479
// policy is expected to be paired with proper permissionId
476480
// to "REMOVE" permission, use "uninstallValidation()" function
477481
ModuleLib.uninstallModule(module, deInitData);
482+
emit ModuleUninstalled(moduleType, module);
478483
} else if (moduleType == 6) {
479484
ValidationId rootValidator = _validationStorage().rootValidator;
480485
bytes32 permissionId = bytes32(deInitData[0:32]);
@@ -483,11 +488,12 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
483488
revert RootValidatorCannotBeRemoved();
484489
}
485490
}
486-
// force call onInstall for signer
491+
// force call onUninstall for signer
487492
// NOTE: for signer, kernel does not support independent signer install,
488493
// signer is expected to be paired with proper permissionId
489494
// to "REMOVE" permission, use "uninstallValidation()" function
490495
ModuleLib.uninstallModule(module, deInitData);
496+
emit ModuleUninstalled(moduleType, module);
491497
} else {
492498
revert InvalidModuleType();
493499
}

src/core/ExecutorManager.sol

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
pragma solidity ^0.8.0;
44

55
import {IHook, IExecutor} from "../interfaces/IERC7579Modules.sol";
6+
import {IERC7579Account} from "../interfaces/IERC7579Account.sol";
67
import {ModuleLib} from "../utils/ModuleLib.sol";
7-
import {EXECUTOR_MANAGER_STORAGE_SLOT} from "../types/Constants.sol";
8+
import {EXECUTOR_MANAGER_STORAGE_SLOT, MODULE_TYPE_EXECUTOR} from "../types/Constants.sol";
89

910
abstract contract ExecutorManager {
1011
struct ExecutorConfig {
@@ -29,11 +30,7 @@ abstract contract ExecutorManager {
2930
}
3031

3132
function _installExecutor(IExecutor executor, bytes calldata executorData, IHook hook) internal {
32-
if (address(hook) == address(0)) {
33-
hook = IHook(address(1));
34-
}
35-
ExecutorConfig storage config = _executorConfig(executor);
36-
config.hook = hook;
33+
_installExecutorWithoutInit(executor, hook);
3734
executor.onInstall(executorData);
3835
}
3936

@@ -43,12 +40,14 @@ abstract contract ExecutorManager {
4340
}
4441
ExecutorConfig storage config = _executorConfig(executor);
4542
config.hook = hook;
43+
emit IERC7579Account.ModuleInstalled(MODULE_TYPE_EXECUTOR, address(executor));
4644
}
4745

4846
function _uninstallExecutor(IExecutor executor, bytes calldata executorData) internal returns (IHook hook) {
4947
ExecutorConfig storage config = _executorConfig(executor);
5048
hook = config.hook;
5149
config.hook = IHook(address(0));
5250
ModuleLib.uninstallModule(address(executor), executorData);
51+
emit IERC7579Account.ModuleUninstalled(MODULE_TYPE_EXECUTOR, address(executor));
5352
}
5453
}

src/core/HookManager.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pragma solidity ^0.8.0;
44

55
import {IHook} from "../interfaces/IERC7579Modules.sol";
66
import {ModuleLib} from "../utils/ModuleLib.sol";
7+
import {IERC7579Account} from "../interfaces/IERC7579Account.sol";
8+
import {MODULE_TYPE_HOOK} from "../types/Constants.sol";
79

810
abstract contract HookManager {
911
// NOTE: currently, all install/uninstall calls onInstall/onUninstall
@@ -32,12 +34,11 @@ abstract contract HookManager {
3234
if (!hook.isInitialized(address(this))) {
3335
// if hook is not installed, it should call onInstall
3436
hook.onInstall(hookData[1:]);
35-
return;
36-
}
37-
if (bytes1(hookData[0]) == bytes1(0xff)) {
37+
} else if (bytes1(hookData[0]) == bytes1(0xff)) {
3838
// 0xff means you want to explicitly call install hook
3939
hook.onInstall(hookData[1:]);
4040
}
41+
emit IERC7579Account.ModuleInstalled(MODULE_TYPE_HOOK, address(hook));
4142
}
4243

4344
// @param hookData encoded as (1bytes flag + actual hookdata) flag is for identifying if the hook has to be initialized or not
@@ -49,5 +50,6 @@ abstract contract HookManager {
4950
// 0xff means you want to call uninstall hook
5051
ModuleLib.uninstallModule(address(hook), hookData[1:]);
5152
}
53+
emit IERC7579Account.ModuleUninstalled(MODULE_TYPE_HOOK, address(hook));
5254
}
5355
}

src/core/SelectorManager.sol

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
pragma solidity ^0.8.0;
44

55
import {IHook, IFallback, IModule} from "../interfaces/IERC7579Modules.sol";
6+
import {IERC7579Account} from "../interfaces/IERC7579Account.sol";
67
import {CallType} from "../utils/ExecLib.sol";
7-
import {SELECTOR_MANAGER_STORAGE_SLOT, CALLTYPE_DELEGATECALL, CALLTYPE_SINGLE} from "../types/Constants.sol";
8+
import {
9+
SELECTOR_MANAGER_STORAGE_SLOT,
10+
CALLTYPE_DELEGATECALL,
11+
CALLTYPE_SINGLE,
12+
MODULE_TYPE_FALLBACK
13+
} from "../types/Constants.sol";
814
import {ModuleLib} from "../utils/ModuleLib.sol";
915

1016
abstract contract SelectorManager {
@@ -44,6 +50,7 @@ abstract contract SelectorManager {
4450
CallType callType = CallType.wrap(bytes1(selectorData[0]));
4551
if (callType == CALLTYPE_SINGLE) {
4652
IModule(target).onInstall(selectorData[1:]);
53+
emit IERC7579Account.ModuleInstalled(MODULE_TYPE_FALLBACK, target);
4754
} else if (callType != CALLTYPE_DELEGATECALL) {
4855
// NOTE : we are not going to call onInstall for delegatecall, and we support only CALL & DELEGATECALL
4956
revert NotSupportedCallType();
@@ -57,8 +64,11 @@ abstract contract SelectorManager {
5764
SelectorConfig storage ss = _selectorConfig(selector);
5865
hook = ss.hook;
5966
ss.hook = IHook(address(0));
60-
ModuleLib.uninstallModule(ss.target, selectorDeinitData);
67+
if (ss.callType == CALLTYPE_SINGLE) {
68+
ModuleLib.uninstallModule(ss.target, selectorDeinitData);
69+
emit IERC7579Account.ModuleUninstalled(MODULE_TYPE_FALLBACK, ss.target);
70+
}
6171
ss.target = address(0);
62-
ss.callType = CallType.wrap(bytes1(0xff));
72+
ss.callType = CallType.wrap(bytes1(0x00));
6373
}
6474
}

src/core/ValidationManager.sol

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
pragma solidity ^0.8.0;
33

44
import {IValidator, IModule, IExecutor, IHook, IPolicy, ISigner, IFallback} from "../interfaces/IERC7579Modules.sol";
5+
import {IERC7579Account} from "../interfaces/IERC7579Account.sol";
56
import {PackedUserOperation} from "../interfaces/PackedUserOperation.sol";
67
import {SelectorManager} from "./SelectorManager.sol";
78
import {HookManager} from "./HookManager.sol";
@@ -20,7 +21,7 @@ import {
2021
} from "../utils/ValidationTypeLib.sol";
2122

2223
import {CallType} from "../utils/ExecLib.sol";
23-
import {CALLTYPE_SINGLE} from "../types/Constants.sol";
24+
import {CALLTYPE_SINGLE, MODULE_TYPE_POLICY, MODULE_TYPE_SIGNER, MODULE_TYPE_VALIDATOR} from "../types/Constants.sol";
2425

2526
import {PermissionId, getValidationResult} from "../types/Types.sol";
2627
import {_intersectValidationData} from "../utils/KernelValidationResult.sol";
@@ -173,6 +174,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
173174
if (vType == VALIDATION_TYPE_VALIDATOR) {
174175
IValidator validator = ValidatorLib.getValidator(vId);
175176
ModuleLib.uninstallModule(address(validator), validatorData);
177+
emit IERC7579Account.ModuleUninstalled(MODULE_TYPE_VALIDATOR, address(validator));
176178
} else if (vType == VALIDATION_TYPE_PERMISSION) {
177179
PermissionId permission = ValidatorLib.getPermissionId(vId);
178180
_uninstallPermission(permission, validatorData);
@@ -198,6 +200,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
198200
ModuleLib.uninstallModule(
199201
address(policy), abi.encodePacked(bytes32(PermissionId.unwrap(pId)), permissionDisableData[i])
200202
);
203+
emit IERC7579Account.ModuleUninstalled(MODULE_TYPE_POLICY, address(policy));
201204
}
202205
delete _validationStorage().permissionConfig[pId].policyData;
203206
ModuleLib.uninstallModule(
@@ -206,6 +209,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
206209
bytes32(PermissionId.unwrap(pId)), permissionDisableData[permissionDisableData.length - 1]
207210
)
208211
);
212+
emit IERC7579Account.ModuleUninstalled(MODULE_TYPE_SIGNER, address(config.signer));
209213
}
210214
config.signer = ISigner(address(0));
211215
config.permissionFlag = PassFlag.wrap(bytes2(0));
@@ -238,6 +242,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
238242
if (vType == VALIDATION_TYPE_VALIDATOR) {
239243
IValidator validator = ValidatorLib.getValidator(vId);
240244
validator.onInstall(validatorData);
245+
emit IERC7579Account.ModuleInstalled(MODULE_TYPE_VALIDATOR, address(validator));
241246
} else if (vType == VALIDATION_TYPE_PERMISSION) {
242247
PermissionId permission = ValidatorLib.getPermissionId(vId);
243248
_installPermission(permission, validatorData);
@@ -270,6 +275,9 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
270275
IPolicy(address(bytes20(permissionEnableData[i][2:22]))).onInstall(
271276
abi.encodePacked(bytes32(PermissionId.unwrap(permission)), permissionEnableData[i][22:])
272277
);
278+
emit IERC7579Account.ModuleInstalled(
279+
MODULE_TYPE_POLICY, address(bytes20(permissionEnableData[i][2:22]))
280+
);
273281
}
274282
// last permission data will be signer
275283
ISigner signer = ISigner(address(bytes20(permissionEnableData[permissionEnableData.length - 1][2:22])));
@@ -281,6 +289,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
281289
bytes32(PermissionId.unwrap(permission)), permissionEnableData[permissionEnableData.length - 1][22:]
282290
)
283291
);
292+
emit IERC7579Account.ModuleInstalled(MODULE_TYPE_SIGNER, address(signer));
284293
}
285294
}
286295

0 commit comments

Comments
 (0)