Skip to content

Commit

Permalink
Merge pull request #121 from rhinestonewtf/dev
Browse files Browse the repository at this point in the history
feature: rearchitect multi-account support
  • Loading branch information
kopy-kat authored Jun 6, 2024
2 parents c1e231e + d7eb34b commit c16639e
Show file tree
Hide file tree
Showing 22 changed files with 1,145 additions and 771 deletions.
2 changes: 1 addition & 1 deletion src/Helpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.23;

/* solhint-disable no-unused-import */
import { ERC4337Helpers } from "./test/utils/ERC4337Helpers.sol";
import { ERC7579Helpers } from "./test/utils/ERC7579Helpers.sol";
import { ERC7579Helpers } from "./test/helpers/ERC7579Helpers.sol";
import { sign as vmSign } from "./test/utils/Vm.sol";

function ecdsaSign(uint256 privKey, bytes32 digest) pure returns (bytes memory signature) {
Expand Down
96 changes: 0 additions & 96 deletions src/accounts/MultiAccountFactory.sol

This file was deleted.

12 changes: 0 additions & 12 deletions src/accounts/MultiAccountHelpers.sol

This file was deleted.

31 changes: 24 additions & 7 deletions src/accounts/erc7579/ERC7579Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,54 @@ pragma solidity ^0.8.23;

import "../../external/ERC7579.sol";
import { LibClone } from "solady/utils/LibClone.sol";
import { IAccountFactory } from "src/accounts/interface/IAccountFactory.sol";

abstract contract ERC7579Factory {
contract ERC7579Factory is IAccountFactory {
ERC7579Account internal implementation;
ERC7579Bootstrap internal bootstrapDefault;

function initERC7579() internal {
function init() public override {
implementation = new ERC7579Account();
bootstrapDefault = new ERC7579Bootstrap();
}

function createERC7579(bytes32 salt, bytes memory initCode) public returns (address account) {
function createAccount(
bytes32 salt,
bytes memory initCode
)
public
override
returns (address account)
{
bytes32 _salt = _getSalt(salt, initCode);
account = LibClone.cloneDeterministic(0, address(implementation), initCode, _salt);

IMSA(account).initializeAccount(initCode);
}

function getAddressERC7579(bytes32 salt, bytes memory initCode) public view returns (address) {
function getAddress(
bytes32 salt,
bytes memory initCode
)
public
view
override
returns (address)
{
bytes32 _salt = _getSalt(salt, initCode);
return LibClone.predictDeterministicAddress(
address(implementation), initCode, _salt, address(this)
);
}

function getInitDataERC7579(
function getInitData(
address validator,
bytes memory initData
)
public
view
returns (bytes memory init)
override
returns (bytes memory _init)
{
ERC7579BootstrapConfig[] memory _validators = new ERC7579BootstrapConfig[](1);
_validators[0].module = validator;
Expand All @@ -43,7 +60,7 @@ abstract contract ERC7579Factory {
ERC7579BootstrapConfig memory _hook;

ERC7579BootstrapConfig[] memory _fallBacks = new ERC7579BootstrapConfig[](0);
init = abi.encode(
_init = abi.encode(
address(bootstrapDefault),
abi.encodeCall(ERC7579Bootstrap.initMSA, (_validators, _executors, _hook, _fallBacks))
);
Expand Down
22 changes: 22 additions & 0 deletions src/accounts/interface/IAccountFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

interface IAccountFactory {
function init() external;

function createAccount(
bytes32 salt,
bytes memory initCode
)
external
returns (address account);

function getAddress(bytes32 salt, bytes memory initCode) external view returns (address);

function getInitData(
address validator,
bytes memory initData
)
external
returns (bytes memory init);
}
33 changes: 17 additions & 16 deletions src/accounts/kernel/KernelFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,43 @@ import { ENTRYPOINT_ADDR } from "../../test/predeploy/EntryPoint.sol";
import { ValidatorLib } from "kernel/utils/ValidationTypeLib.sol";
import { ValidationId } from "kernel/types/Types.sol";
import { IValidator, IHook } from "kernel/interfaces/IERC7579Modules.sol";
import { IAccountFactory } from "src/accounts/interface/IAccountFactory.sol";

abstract contract KernelFactory {
contract KernelFactory is IAccountFactory {
KernelAccountFactory internal factory;
Kernel internal kernalImpl;

function initKernel() internal {
function init() public override {
kernalImpl = new Kernel(IEntryPoint(ENTRYPOINT_ADDR));
factory = new KernelAccountFactory(address(kernalImpl));
}

function createKernel(bytes memory data, bytes32 salt) public returns (address account) {
account = factory.createAccount(data, salt);
}

function getAddressKernel(
bytes memory data,
bytes32 salt
function createAccount(
bytes32 salt,
bytes memory data
)
public
view
virtual
returns (address)
override
returns (address account)
{
account = factory.createAccount(data, salt);
}

function getAddress(bytes32 salt, bytes memory data) public view override returns (address) {
return factory.getAddress(data, salt);
}

function getInitDataKernel(
function getInitData(
address validator,
bytes memory initData
)
public
view
returns (bytes memory init)
pure
override
returns (bytes memory _init)
{
ValidationId rootValidator = ValidatorLib.validatorToIdentifier(IValidator(validator));

init = abi.encodeCall(Kernel.initialize, (rootValidator, IHook(address(0)), initData, ""));
_init = abi.encodeCall(Kernel.initialize, (rootValidator, IHook(address(0)), initData, ""));
}
}
25 changes: 17 additions & 8 deletions src/accounts/safe/SafeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,31 @@ import { ENTRYPOINT_ADDR } from "src/test/predeploy/EntryPoint.sol";
import { REGISTRY_ADDR } from "src/test/predeploy/Registry.sol";
import { makeAddr } from "src/test/utils/Vm.sol";
import { Solarray } from "solarray/Solarray.sol";
import { IAccountFactory } from "src/accounts/interface/IAccountFactory.sol";

abstract contract SafeFactory {
contract SafeFactory is IAccountFactory {
// singletons
Safe7579 internal safe7579;
Safe7579Launchpad internal launchpad;
Safe internal safeSingleton;
SafeProxyFactory internal safeProxyFactory;

function initSafe() internal {
function init() public override {
// Set up MSA and Factory
safe7579 = new Safe7579();
launchpad = new Safe7579Launchpad(ENTRYPOINT_ADDR, IERC7484(address(REGISTRY_ADDR)));
safeSingleton = new Safe();
safeProxyFactory = new SafeProxyFactory();
}

function createSafe(bytes32 salt, bytes calldata initCode) internal returns (address safe) {
function createAccount(
bytes32 salt,
bytes memory initCode
)
public
override
returns (address safe)
{
Safe7579Launchpad.InitData memory initData =
abi.decode(initCode, (Safe7579Launchpad.InitData));
bytes32 initHash = launchpad.hash(initData);
Expand All @@ -42,13 +50,13 @@ abstract contract SafeFactory {
);
}

function getAddressSafe(
function getAddress(
bytes32 salt,
bytes memory initCode
)
public
view
virtual
override
returns (address)
{
Safe7579Launchpad.InitData memory initData =
Expand All @@ -67,13 +75,14 @@ abstract contract SafeFactory {
});
}

function getInitDataSafe(
function getInitData(
address validator,
bytes memory initData
)
public
view
returns (bytes memory init)
override
returns (bytes memory _init)
{
ModuleInit[] memory validators = new ModuleInit[](1);
validators[0] = ModuleInit({ module: address(validator), initData: initData });
Expand Down Expand Up @@ -101,6 +110,6 @@ abstract contract SafeFactory {
validators: validators,
callData: ""
});
init = abi.encode(initDataSafe);
_init = abi.encode(initDataSafe);
}
}
5 changes: 0 additions & 5 deletions src/test/Auxiliary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import "./utils/Log.sol";
struct Auxiliary {
IEntryPoint entrypoint;
UserOpGasLog gasSimulation;
ERC7579Bootstrap bootstrap;
IERC7484 registry;
address initialTrustedAttester;
MockFactory mockFactory;
}

Expand All @@ -33,10 +31,7 @@ contract AuxiliaryFactory {
auxiliary.gasSimulation = new UserOpGasLog();
auxiliary.entrypoint = etchEntrypoint();
label(address(auxiliary.entrypoint), "EntryPoint");
auxiliary.bootstrap = new ERC7579Bootstrap();
label(address(auxiliary.bootstrap), "ERC7579Bootstrap");
auxiliary.registry = etchRegistry();
label(address(auxiliary.registry), "ERC7484Registry");
auxiliary.initialTrustedAttester = makeAddr("Trusted Attester");
}
}
Loading

0 comments on commit c16639e

Please sign in to comment.