Skip to content

Commit

Permalink
⚡ optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipp Makarov authored and Filipp Makarov committed Oct 17, 2023
1 parent b6b179a commit f7b956e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 8 additions & 2 deletions contracts/smart-account/modules/MultiOwnedECDSAModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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);
}

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check failure on line 247 in test/bundler-integration/module/MultiOwnedECDSA.Module.specs.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Replace `await·multiOwnedECDSAModule.getNumberOfOwners(userSA.address)` with `⏎········await·multiOwnedECDSAModule.getNumberOfOwners(userSA.address)⏎······`
});
});
});

0 comments on commit f7b956e

Please sign in to comment.