@@ -10,9 +10,13 @@ import {HookConfigLib} from "../helpers/HookConfigLib.sol";
1010import {KnownSelectors} from "../helpers/KnownSelectors.sol " ;
1111import {ModuleEntityLib} from "../helpers/ModuleEntityLib.sol " ;
1212import {ValidationConfigLib} from "../helpers/ValidationConfigLib.sol " ;
13+ import {IExecutionHookModule} from "../interfaces/IExecutionHookModule.sol " ;
1314import {ExecutionManifest, ManifestExecutionHook} from "../interfaces/IExecutionModule.sol " ;
1415import {HookConfig, IModularAccount, ModuleEntity, ValidationConfig} from "../interfaces/IModularAccount.sol " ;
1516import {IModule} from "../interfaces/IModule.sol " ;
17+ import {IValidationHookModule} from "../interfaces/IValidationHookModule.sol " ;
18+ import {IValidationModule} from "../interfaces/IValidationModule.sol " ;
19+
1620import {
1721 AccountStorage,
1822 ExecutionData,
@@ -32,11 +36,11 @@ abstract contract ModuleManagerInternals is IModularAccount {
3236 error Erc4337FunctionNotAllowed (bytes4 selector );
3337 error ExecutionFunctionAlreadySet (bytes4 selector );
3438 error IModuleFunctionNotAllowed (bytes4 selector );
39+ error InterfaceNotSupported (address module );
3540 error NativeFunctionNotAllowed (bytes4 selector );
3641 error NullModule ();
3742 error PermissionAlreadySet (ModuleEntity validationFunction , HookConfig hookConfig );
3843 error ModuleInstallCallbackFailed (address module , bytes revertReason );
39- error ModuleInterfaceNotSupported (address module );
4044 error ModuleNotInstalled (address module );
4145 error PreValidationHookLimitExceeded ();
4246 error ValidationAlreadySet (bytes4 selector , ModuleEntity validationFunction );
@@ -125,21 +129,17 @@ abstract contract ModuleManagerInternals is IModularAccount {
125129 hooks.remove (toSetValue (hookConfig));
126130 }
127131
128- function _installExecution (address module , ExecutionManifest calldata manifest , bytes memory moduleInstallData )
129- internal
130- {
132+ function _installExecution (
133+ address module ,
134+ ExecutionManifest calldata manifest ,
135+ bytes calldata moduleInstallData
136+ ) internal {
131137 AccountStorage storage _storage = getAccountStorage ();
132138
133139 if (module == address (0 )) {
134140 revert NullModule ();
135141 }
136142
137- // TODO: do we need this check? Or switch to a non-165 checking function?
138- // Check that the module supports the IModule interface.
139- if (! ERC165Checker .supportsInterface (module, type (IModule).interfaceId)) {
140- revert ModuleInterfaceNotSupported (module);
141- }
142-
143143 // Update components according to the manifest.
144144 uint256 length = manifest.executionFunctions.length ;
145145 for (uint256 i = 0 ; i < length; ++ i) {
@@ -168,18 +168,12 @@ abstract contract ModuleManagerInternals is IModularAccount {
168168 _storage.supportedIfaces[manifest.interfaceIds[i]] += 1 ;
169169 }
170170
171- // Initialize the module storage for the account.
172- // solhint-disable-next-line no-empty-blocks
173- try IModule (module).onInstall (moduleInstallData) {}
174- catch {
175- bytes memory revertReason = collectReturnData ();
176- revert ModuleInstallCallbackFailed (module, revertReason);
177- }
171+ _onInstall (module, moduleInstallData, type (IModule).interfaceId);
178172
179173 emit ExecutionInstalled (module, manifest);
180174 }
181175
182- function _uninstallExecution (address module , ExecutionManifest calldata manifest , bytes memory uninstallData )
176+ function _uninstallExecution (address module , ExecutionManifest calldata manifest , bytes calldata uninstallData )
183177 internal
184178 {
185179 AccountStorage storage _storage = getAccountStorage ();
@@ -212,19 +206,22 @@ abstract contract ModuleManagerInternals is IModularAccount {
212206 }
213207
214208 // Clear the module storage for the account.
215- bool onUninstallSuccess = true ;
216- // solhint-disable-next-line no-empty-blocks
217- try IModule (module).onUninstall (uninstallData) {}
218- catch {
219- onUninstallSuccess = false ;
220- }
209+ bool onUninstallSuccess = _onUninstall (module, uninstallData);
221210
222211 emit ExecutionUninstalled (module, onUninstallSuccess, manifest);
223212 }
224213
225- function _onInstall (address module , bytes calldata data ) internal {
214+ function _onInstall (address module , bytes calldata data , bytes4 interfaceId ) internal {
226215 if (data.length > 0 ) {
227- IModule (module).onInstall (data);
216+ if (! ERC165Checker .supportsInterface (module, interfaceId)) {
217+ revert InterfaceNotSupported (module);
218+ }
219+ // solhint-disable-next-line no-empty-blocks
220+ try IModule (module).onInstall (data) {}
221+ catch {
222+ bytes memory revertReason = collectReturnData ();
223+ revert ModuleInstallCallbackFailed (module, revertReason);
224+ }
228225 }
229226 }
230227
@@ -261,12 +258,17 @@ abstract contract ModuleManagerInternals is IModularAccount {
261258 if (_validationData.preValidationHooks.length > MAX_PRE_VALIDATION_HOOKS) {
262259 revert PreValidationHookLimitExceeded ();
263260 }
264- } // Hook is an execution hook
265- else if (! _validationData.permissionHooks.add (toSetValue (hookConfig))) {
261+
262+ _onInstall (hookConfig.module (), hookData, type (IValidationHookModule).interfaceId);
263+
264+ continue ;
265+ }
266+ // Hook is a permission hook
267+ if (! _validationData.permissionHooks.add (toSetValue (hookConfig))) {
266268 revert PermissionAlreadySet (moduleEntity, hookConfig);
267269 }
268270
269- _onInstall (hookConfig.module (), hookData);
271+ _onInstall (hookConfig.module (), hookData, type (IExecutionHookModule).interfaceId );
270272 }
271273
272274 for (uint256 i = 0 ; i < selectors.length ; ++ i) {
@@ -279,7 +281,7 @@ abstract contract ModuleManagerInternals is IModularAccount {
279281 _validationData.isGlobal = validationConfig.isGlobal ();
280282 _validationData.isSignatureValidation = validationConfig.isSignatureValidation ();
281283
282- _onInstall (validationConfig.module (), installData);
284+ _onInstall (validationConfig.module (), installData, type (IValidationModule).interfaceId );
283285 emit ValidationInstalled (validationConfig.module (), validationConfig.entityId ());
284286 }
285287
0 commit comments