Skip to content

Commit

Permalink
#3 Document that RegistryFactory.createAccount is only compatible wit…
Browse files Browse the repository at this point in the history
…h an inner Bootstrap.initNexus
  • Loading branch information
Aboudjem committed Aug 15, 2024
1 parent dbe28dd commit 884b652
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions contracts/factory/RegistryFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,27 @@ contract RegistryFactory is Stakeable, INexusFactory {
threshold = newThreshold;
}


/// @notice Creates a new Nexus account with the provided initialization data.
/// @param initData Initialization data to be called on the new Smart Account.
/// @param salt Unique salt for the Smart Account creation.
/// @return The address of the newly created Nexus.
/// @param initData Initialization data that is expected to be compatible with a `Bootstrap` contract's initialization method.
/// @param salt Unique salt used for deterministic deployment of the Nexus smart account.
/// @return The address of the newly created Nexus account.
function createAccount(bytes calldata initData, bytes32 salt) external payable override returns (address payable) {
// Decode the initData to extract the call target and call data
// Decode the initialization data to extract the target bootstrap contract and the data to be used for initialization.
(, bytes memory callData) = abi.decode(initData, (address, bytes));

// Extract the inner data by removing the first 4 bytes (the function selector)
// Ensure that the initData is structured for the expected Bootstrap.initNexus or similar method.
// This step is crucial for ensuring the proper initialization of the Nexus smart account.
bytes memory innerData = BytesLib.slice(callData, 4, callData.length - 4);

// Decode the call data to extract the parameters passed to initNexus
(
BootstrapConfig[] memory validators,
BootstrapConfig[] memory executors,
BootstrapConfig memory hook,
BootstrapConfig[] memory fallbacks,
,
,

, ,
) = abi.decode(innerData, (BootstrapConfig[], BootstrapConfig[], BootstrapConfig, BootstrapConfig[], address, address[], uint8));

// Ensure all modules are whitelisted
// Ensure that all specified modules are whitelisted and allowed for the account.
for (uint256 i = 0; i < validators.length; i++) {
require(isModuleAllowed(validators[i].module, MODULE_TYPE_VALIDATOR), ModuleNotWhitelisted(validators[i].module));
}
Expand Down Expand Up @@ -153,12 +151,15 @@ contract RegistryFactory is Stakeable, INexusFactory {
(bool alreadyDeployed, address account) = LibClone.createDeterministicERC1967(msg.value, ACCOUNT_IMPLEMENTATION, actualSalt);

if (!alreadyDeployed) {
// Initialize the Nexus account using the provided initialization data
INexus(account).initializeAccount(initData);
emit AccountCreated(account, initData, salt);
}

return payable(account);
}


/// @notice Computes the expected address of a Nexus contract using the factory's deterministic deployment algorithm.
/// @param - Initialization data to be called on the new Smart Account.
/// @param - Unique salt for the Smart Account creation.
Expand Down

0 comments on commit 884b652

Please sign in to comment.