-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Filipp Makarov
authored and
Filipp Makarov
committed
Dec 23, 2024
1 parent
45d738a
commit 779d85d
Showing
4 changed files
with
49 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ pragma solidity ^0.8.27; | |
// Nexus: A suite of contracts for Modular Smart Accounts compliant with ERC-7579 and ERC-4337, developed by Biconomy. | ||
// Learn more at https://biconomy.io. To report security issues, please contact us at: [email protected] | ||
|
||
import { SentinelListLib } from "sentinellist/SentinelList.sol"; | ||
import { SentinelListLib, SENTINEL } from "sentinellist/SentinelList.sol"; | ||
import { Storage } from "./Storage.sol"; | ||
import { IHook } from "../interfaces/modules/IHook.sol"; | ||
import { IModule } from "../interfaces/modules/IModule.sol"; | ||
|
@@ -194,6 +194,21 @@ abstract contract ModuleManager is Storage, EIP712, IModuleManagerEventsAndError | |
validator.excessivelySafeCall(gasleft(), 0, 0, abi.encodeWithSelector(IModule.onUninstall.selector, disableModuleData)); | ||
} | ||
|
||
/// @dev Uninstalls all validators and emits an event if any validator fails to uninstall. | ||
function _tryUninstallValidators() internal { | ||
SentinelListLib.SentinelList storage validators = _getAccountStorage().validators; | ||
address validator = validators.getNext(SENTINEL); | ||
// we do not need excessivelySafeCall here as it prevents reversion | ||
// we want to know if there's revert and emit the event | ||
while (validator != SENTINEL) { | ||
try IValidator(validator).onUninstall("") {} catch (bytes memory reason) { | ||
emit ValidatorUninstallFailed(validator, "", reason); | ||
} | ||
validator = validators.getNext(validator); | ||
} | ||
validators.popAll(); | ||
} | ||
|
||
/// @dev Installs a new executor module after checking if it matches the required module type. | ||
/// @param executor The address of the executor module to be installed. | ||
/// @param data Initialization data to configure the executor upon installation. | ||
|
@@ -212,6 +227,19 @@ abstract contract ModuleManager is Storage, EIP712, IModuleManagerEventsAndError | |
executor.excessivelySafeCall(gasleft(), 0, 0, abi.encodeWithSelector(IModule.onUninstall.selector, disableModuleData)); | ||
} | ||
|
||
/// @dev Uninstalls all executors and emits an event if any executor fails to uninstall. | ||
function _tryUninstallExecutors() internal { | ||
SentinelListLib.SentinelList storage executors = _getAccountStorage().executors; | ||
address executor = executors.getNext(SENTINEL); | ||
while (executor != SENTINEL) { | ||
try IExecutor(executor).onUninstall("") {} catch (bytes memory reason) { | ||
emit ExecutorUninstallFailed(executor, "", reason); | ||
} | ||
executor = executors.getNext(executor); | ||
} | ||
executors.popAll(); | ||
} | ||
|
||
/// @dev Installs a hook module, ensuring no other hooks are installed before proceeding. | ||
/// @param hook The address of the hook to be installed. | ||
/// @param data Initialization data to configure the hook upon installation. | ||
|
@@ -231,6 +259,17 @@ abstract contract ModuleManager is Storage, EIP712, IModuleManagerEventsAndError | |
hook.excessivelySafeCall(gasleft(), 0, 0, abi.encodeWithSelector(IModule.onUninstall.selector, data)); | ||
} | ||
|
||
/// @dev Uninstalls the hook and emits an event if the hook fails to uninstall. | ||
function _tryUninstallHook() internal { | ||
address hook = _getHook(); | ||
if (hook != address(0)) { | ||
try IHook(hook).onUninstall("") {} catch (bytes memory reason) { | ||
emit HookUninstallFailed(hook, "", reason); | ||
} | ||
_setHook(address(0)); | ||
} | ||
} | ||
|
||
/// @dev Sets the current hook in the storage to the specified address. | ||
/// @param hook The new hook address. | ||
function _setHook(address hook) internal virtual { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters