Skip to content

Commit

Permalink
feat: add accountId
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypaik committed Aug 22, 2024
1 parent bd33993 commit 9b68e45
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/account/SemiModularAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interface

import {ModuleEntityLib} from "../helpers/ModuleEntityLib.sol";

import {ModuleEntity, ValidationConfig} from "../interfaces/IModularAccount.sol";
import {IModularAccount, ModuleEntity, ValidationConfig} from "../interfaces/IModularAccount.sol";

import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
Expand Down Expand Up @@ -83,6 +83,11 @@ contract SemiModularAccount is UpgradeableModularAccount {
revert InitializerDisabled();
}

/// @inheritdoc IModularAccount
function accountId() external pure override returns (string memory) {
return "erc6900/reference-semi-modular-account/0.8.0";
}

function _execUserOpValidation(
ModuleEntity userOpValidationFunction,
PackedUserOperation memory userOp,
Expand Down
5 changes: 5 additions & 0 deletions src/account/UpgradeableModularAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ contract UpgradeableModularAccount is
return getAccountStorage().supportedIfaces[interfaceId] > 0;
}

/// @inheritdoc IModularAccount
function accountId() external pure virtual returns (string memory) {
return "erc6900/reference-modular-account/0.8.0";
}

/// @inheritdoc UUPSUpgradeable
/// @notice May be validated by a global validation.
function upgradeToAndCall(address newImplementation, bytes memory data)
Expand Down
12 changes: 7 additions & 5 deletions src/helpers/KnownSelectors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ library KnownSelectors {
return
// check against IAccount methods
selector == IAccount.validateUserOp.selector
// check against module manager methods
// check against IModularAccount methods
|| selector == IModularAccount.installExecution.selector
|| selector == IModularAccount.uninstallExecution.selector
|| selector == IModularAccount.installValidation.selector
|| selector == IModularAccount.uninstallValidation.selector || selector == IModularAccount.execute.selector
|| selector == IModularAccount.executeBatch.selector
|| selector == IModularAccount.executeWithAuthorization.selector
|| selector == IModularAccount.accountId.selector
// check against IERC165 methods
|| selector == IERC165.supportsInterface.selector
// check against UUPSUpgradeable methods
|| selector == UUPSUpgradeable.proxiableUUID.selector
|| selector == UUPSUpgradeable.upgradeToAndCall.selector
// check against IModularAccount methods
|| selector == IModularAccount.execute.selector || selector == IModularAccount.executeBatch.selector
|| selector == IModularAccount.executeWithAuthorization.selector
// check against account loupe methods
// check against IAccountLoupe methods
|| selector == IAccountLoupe.getExecutionData.selector
|| selector == IAccountLoupe.getValidationData.selector;
}
Expand Down
5 changes: 5 additions & 0 deletions src/interfaces/IModularAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,9 @@ interface IModularAccount {
ExecutionManifest calldata manifest,
bytes calldata moduleUninstallData
) external;

/// @notice Return a unique identifier for the account implementation.
/// @dev This function MUST return a string in the format "vendor/account/semver".
/// @return The account ID.
function accountId() external view returns (string memory);
}
10 changes: 10 additions & 0 deletions test/account/UpgradeableModularAccount.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@ contract UpgradeableModularAccountTest is AccountTestBase {
_printStorageReadsAndWrites(address(account2));
}

function test_accountId() public {
string memory accountId = account1.accountId();
assertEq(
accountId,
vm.envOr("SMA_TEST", false)
? "erc6900/reference-semi-modular-account/0.8.0"
: "erc6900/reference-modular-account/0.8.0"
);
}

function test_contractInteraction() public {
PackedUserOperation memory userOp = PackedUserOperation({
sender: address(account1),
Expand Down

0 comments on commit 9b68e45

Please sign in to comment.