Skip to content

Commit

Permalink
Merge pull request #76 from etherspot/add-factory-deployment-event
Browse files Browse the repository at this point in the history
Add event on smart account deployment
  • Loading branch information
cryptonoyaiba authored Aug 1, 2024
2 parents 4a880f3 + 9de4d3e commit c7c519e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import {IModularEtherspotWallet} from "../interfaces/IModularEtherspotWallet.sol
contract ModularEtherspotWalletFactory {
address public immutable implementation;

event ModularAccountDeployed(
address indexed account,
address indexed owner
);

constructor(address _implementation) {
implementation = _implementation;
}
Expand All @@ -21,6 +26,7 @@ contract ModularEtherspotWalletFactory {

if (!alreadyDeployed) {
IModularEtherspotWallet(account).initializeAccount(initCode);
emit ModularAccountDeployed(account, msg.sender);
}
return account;
}
Expand Down
57 changes: 57 additions & 0 deletions test/foundry/wallet/ModularEtherspotWalletFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ contract ModularEtherspotWalletFactoryTest is BootstrapUtil, Test {
address owner1;
uint256 owner1Key;

event ModularAccountDeployed(
address indexed account,
address indexed owner
);

function setUp() public virtual {
etchEntrypoint();
implementation = new ModularEtherspotWallet();
Expand Down Expand Up @@ -181,4 +186,56 @@ contract ModularEtherspotWalletFactoryTest is BootstrapUtil, Test {
vm.stopPrank();
assertFalse(address(account) == address(account2));
}

function test_emitEvent_createAccount() public {
// setup account init config
BootstrapConfig[] memory validators = makeBootstrapConfig(
address(defaultValidator),
""
);
BootstrapConfig[] memory executors = makeBootstrapConfig(
address(defaultExecutor),
""
);
BootstrapConfig memory hook = _makeBootstrapConfig(address(0), "");
BootstrapConfig[] memory fallbacks = makeBootstrapConfig(
address(0),
""
);

bytes memory initCode = abi.encode(
owner1,
address(bootstrapSingleton),
abi.encodeCall(
Bootstrap.initMSA,
(validators, executors, hook, fallbacks)
)
);

vm.startPrank(owner1);
address expectedAddress = factory.getAddress({
salt: SALT,
initcode: initCode
});

// emit event
vm.expectEmit(true, true, true, true);
emit ModularAccountDeployed(expectedAddress, owner1);
// create account
account = ModularEtherspotWallet(
payable(factory.createAccount({salt: SALT, initCode: initCode}))
);
assertEq(
address(account),
expectedAddress,
"Computed wallet address should always equal wallet address created"
);
// should not emit event if address already exists
// checked using -vvvv stack trace
account = ModularEtherspotWallet(
payable(factory.createAccount({salt: SALT, initCode: initCode}))
);

vm.stopPrank();
}
}

0 comments on commit c7c519e

Please sign in to comment.