Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add docs + cleanup MA and MABase with small opt #259

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/account/ModularAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntry

import {ModularAccountBase} from "./ModularAccountBase.sol";

/// @title Modular Account
/// @author Alchemy
/// @notice This contract allow initionalizing with a validation config (of a validation module) to be installed on
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// @notice This contract allow initionalizing with a validation config (of a validation module) to be installed on
/// @notice This contract allow initializing with a validation config (of a validation module) to be installed on

/// the account.
contract ModularAccount is ModularAccountBase {
constructor(IEntryPoint anEntryPoint) ModularAccountBase(anEntryPoint) {}

Expand Down
39 changes: 21 additions & 18 deletions src/account/ModularAccountBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ import {ModularAccountView} from "./ModularAccountView.sol";
import {ModuleManagerInternals} from "./ModuleManagerInternals.sol";
import {TokenReceiver} from "./TokenReceiver.sol";

/// @title Modular Account Base
/// @author Alchemy
/// @notice This abstract account is a modular account that is compliant with ERC-6900 standard. It supports
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// @notice This abstract account is a modular account that is compliant with ERC-6900 standard. It supports
/// @notice This abstract contract is a modular account that is compliant with ERC-6900 standard. It supports

/// deferred actions during validation.
abstract contract ModularAccountBase is
IModularAccount,
ModularAccountView,
Expand Down Expand Up @@ -100,6 +104,7 @@ abstract contract ModularAccountBase is
error ValidationFunctionMissing(bytes4 selector);
error DeferredActionNonceInvalid();
error DeferredActionSignatureInvalid();
// This error is trigged in performCreate and performCreate2
error CreateFailed();

// Wraps execution of a native function with runtime validation and hooks
Expand Down Expand Up @@ -144,13 +149,6 @@ abstract contract ModularAccountBase is
/// @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 @@ -159,15 +157,21 @@ abstract contract ModularAccountBase is
returns (address createdAddr)
{
assembly ("memory-safe") {
// Load the free memory pointer.
let fmp := mload(0x40)

// Get the initCode length.
let len := initCode.length

// Copy the initCode from callata to memory at the free memory pointer.
calldatacopy(fmp, initCode.offset, len)

// Create the contract.
createdAddr := create(value, fmp, len)

if iszero(createdAddr) {
let createFailedError := 0x7e16b8cd
mstore(0x00, createFailedError)
// If creation failed (the address returned is zero), revert with CreateFailed().
mstore(0x00, 0x7e16b8cd)
revert(0x1c, 0x04)
}
}
Expand All @@ -178,13 +182,6 @@ abstract contract ModularAccountBase is
/// @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 All @@ -193,15 +190,21 @@ abstract contract ModularAccountBase is
returns (address createdAddr)
{
assembly ("memory-safe") {
// Load the free memory pointer.
let fmp := mload(0x40)

// Get the initCode length.
let len := initCode.length

// Copy the initCode from callata to memory at the free memory pointer.
calldatacopy(fmp, initCode.offset, len)

// Create the contract using Create2 with the passed salt parameter.
createdAddr := create2(value, fmp, len, salt)

if iszero(createdAddr) {
let createFailedError := 0x7e16b8cd
mstore(0x00, createFailedError)
// If creation failed (the address returned is zero), revert with CreateFailed().
mstore(0x00, 0x7e16b8cd)
revert(0x1c, 0x04)
}
}
Expand Down
Loading