From f7b956e8514e62339c981fc4d0443d752e32dcd6 Mon Sep 17 00:00:00 2001 From: Filipp Makarov Date: Tue, 17 Oct 2023 14:45:50 +0300 Subject: [PATCH] :zap: optimize --- .../interfaces/modules/IMultiOwnedECDSAModule.sol | 7 +++++++ .../smart-account/modules/MultiOwnedECDSAModule.sol | 10 ++++++++-- .../module/MultiOwnedECDSA.Module.specs.ts | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/contracts/smart-account/interfaces/modules/IMultiOwnedECDSAModule.sol b/contracts/smart-account/interfaces/modules/IMultiOwnedECDSAModule.sol index 41f03bd3..aa94120b 100644 --- a/contracts/smart-account/interfaces/modules/IMultiOwnedECDSAModule.sol +++ b/contracts/smart-account/interfaces/modules/IMultiOwnedECDSAModule.sol @@ -67,6 +67,13 @@ interface IMultiOwnedECDSAModule { address eoaAddress ) external view returns (bool); + /** + * @dev Returns the number of owners of the Smart Account. + * @param smartAccount Smart Account address. + * @return The number of owners of the Smart Account. + */ + function getNumberOfOwners(address smartAccount) external view returns (uint256); + /** * @dev Validates a signature for a message signed by address. * @dev Also try dataHash.toEthSignedMessageHash() diff --git a/contracts/smart-account/modules/MultiOwnedECDSAModule.sol b/contracts/smart-account/modules/MultiOwnedECDSAModule.sol index efa522bc..b5522513 100644 --- a/contracts/smart-account/modules/MultiOwnedECDSAModule.sol +++ b/contracts/smart-account/modules/MultiOwnedECDSAModule.sol @@ -44,7 +44,8 @@ contract MultiOwnedECDSAModule is if (numberOfOwners[msg.sender] != 0) { revert AlreadyInitedForSmartAccount(msg.sender); } - for (uint256 i; i < eoaOwners.length; ) { + uint256 ownersToAdd = eoaOwners.length; + for (uint256 i; i < ownersToAdd; ) { if (eoaOwners[i] == address(0)) revert ZeroAddressNotAllowedAsOwner(); if (_smartAccountOwners[eoaOwners[i]][msg.sender]) @@ -54,11 +55,11 @@ contract MultiOwnedECDSAModule is ); _smartAccountOwners[eoaOwners[i]][msg.sender] = true; - numberOfOwners[msg.sender]++; unchecked { ++i; } } + numberOfOwners[msg.sender] = ownersToAdd; return address(this); } @@ -143,6 +144,11 @@ contract MultiOwnedECDSAModule is return bytes4(0xffffffff); } + /// @inheritdoc IMultiOwnedECDSAModule + function getNumberOfOwners(address smartAccount) public view returns (uint256) { + return numberOfOwners[smartAccount]; + } + /** * @dev Transfers ownership for smartAccount and emits an event * @param newOwner Smart Account address. diff --git a/test/bundler-integration/module/MultiOwnedECDSA.Module.specs.ts b/test/bundler-integration/module/MultiOwnedECDSA.Module.specs.ts index bbff3f98..2c5cf465 100644 --- a/test/bundler-integration/module/MultiOwnedECDSA.Module.specs.ts +++ b/test/bundler-integration/module/MultiOwnedECDSA.Module.specs.ts @@ -244,6 +244,7 @@ describe("MultiOwned ECDSA Module (with Bundler):", async () => { expect(await mockToken.balanceOf(userSA.address)).to.equal( userSABalanceBefore.sub(tokenAmountToTransfer) ); + expect(await multiOwnedECDSAModule.getNumberOfOwners(userSA.address)).to.equal(3); }); }); });