diff --git a/src/modular-etherspot-wallet/wallet/ModularEtherspotWalletFactory.sol b/src/modular-etherspot-wallet/wallet/ModularEtherspotWalletFactory.sol index cc95ad5e..ae0b5bd3 100644 --- a/src/modular-etherspot-wallet/wallet/ModularEtherspotWalletFactory.sol +++ b/src/modular-etherspot-wallet/wallet/ModularEtherspotWalletFactory.sol @@ -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; } @@ -21,6 +26,7 @@ contract ModularEtherspotWalletFactory { if (!alreadyDeployed) { IModularEtherspotWallet(account).initializeAccount(initCode); + emit ModularAccountDeployed(account, msg.sender); } return account; } diff --git a/test/foundry/wallet/ModularEtherspotWalletFactory.t.sol b/test/foundry/wallet/ModularEtherspotWalletFactory.t.sol index 9795554d..30850796 100644 --- a/test/foundry/wallet/ModularEtherspotWalletFactory.t.sol +++ b/test/foundry/wallet/ModularEtherspotWalletFactory.t.sol @@ -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(); @@ -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(); + } }