Skip to content

Commit

Permalink
feat(create): reorder code, enhance documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
andysim3d committed Aug 14, 2024
1 parent 92149cc commit fd14220
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions src/account/UpgradeableModularAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ contract UpgradeableModularAccount is
event ModularAccountInitialized(IEntryPoint indexed entryPoint);

error AlwaysDenyRule();
error CreateFailed();
error ExecFromPluginNotPermitted(address plugin, bytes4 selector);
error ExecFromPluginExternalNotPermitted(address plugin, address target, uint256 value, bytes data);
error NativeTokenSpendingNotPermitted(address plugin);
Expand All @@ -105,7 +106,6 @@ contract UpgradeableModularAccount is
error UnrecognizedFunction(bytes4 selector);
error UserOpNotFromEntryPoint();
error UserOpValidationFunctionMissing(bytes4 selector);
error CreateFailed();

constructor(IEntryPoint anEntryPoint) {
_ENTRY_POINT = anEntryPoint;
Expand Down Expand Up @@ -377,9 +377,17 @@ contract UpgradeableModularAccount is
_postNativeFunction(postExecHooks, postHookArgs);
}

///
/// @notice Create a contract.
/// @param value The value to send to the new contract constructor
/// @param initCode The initCode to deploy.
/// @return createdAddr The created contract address.
///
/// @dev Assembly procedure:
/// 1. Load the free memory pointer.
/// 2. Get the initCode length.
/// 3. Copy the initCode from callata to memory at the free memory pointer.
/// 4. Create the contract.
/// 5. If creation failed (the address returned is zero), revert with CreateFailed().
function performCreate(uint256 value, bytes calldata initCode)
external
payable
Expand All @@ -400,10 +408,18 @@ contract UpgradeableModularAccount is
}
}

///
/// @notice Creates a contract using create2 deterministic deployment.
/// @param value The value to send to the new contract constructor.
/// @param initCode The initCode to deploy.
/// @param salt The salt to use for the create2 operation.
/// @return createdAddr The created contract address.
///
/// @dev Assembly procedure:
/// 1. Load the free memory pointer.
/// 2. Get the initCode length.
/// 3. Copy the initCode from callata to memory at the free memory pointer.
/// 4. Create the contract using Create2 with the passed salt parameter.
/// 5. If creation failed (the address returned is zero), revert with CreateFailed().
function performCreate2(uint256 value, bytes calldata initCode, bytes32 salt)
external
payable
Expand Down
2 changes: 1 addition & 1 deletion test/account/UpgradeableModularAccount.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ contract UpgradeableModularAccountTest is Test {
assertEq(returnedAddr, expectedAddr);

vm.expectRevert(UpgradeableModularAccount.CreateFailed.selector);
// multi-depoly with same salt got reverted
// multi-deploy with same salt got reverted
account1.performCreate2(0, initCode, salt);
}

Expand Down

0 comments on commit fd14220

Please sign in to comment.