Skip to content

Commit f475848

Browse files
authored
feat: add moduleId (#153)
1 parent c2072a1 commit f475848

15 files changed

+46
-112
lines changed

src/helpers/KnownSelectors.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ library KnownSelectors {
4949

5050
function isIModuleFunction(bytes4 selector) internal pure returns (bool) {
5151
return selector == IModule.onInstall.selector || selector == IModule.onUninstall.selector
52-
|| selector == IExecutionModule.executionManifest.selector || selector == IModule.moduleMetadata.selector
52+
|| selector == IModule.moduleId.selector || selector == IExecutionModule.executionManifest.selector
5353
|| selector == IExecutionHookModule.preExecutionHook.selector
5454
|| selector == IExecutionHookModule.postExecutionHook.selector
5555
|| selector == IValidationModule.validateUserOp.selector

src/interfaces/IModule.sol

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,6 @@ pragma solidity ^0.8.25;
33

44
import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";
55

6-
struct SelectorPermission {
7-
bytes4 functionSelector;
8-
string permissionDescription;
9-
}
10-
11-
/// @dev A struct holding fields to describe the module in a purely view context. Intended for front end clients.
12-
struct ModuleMetadata {
13-
// A human-readable name of the module.
14-
string name;
15-
// The version of the module, following the semantic versioning scheme.
16-
string version;
17-
// The author field SHOULD be a username representing the identity of the user or organization
18-
// that created this module.
19-
string author;
20-
// String desciptions of the relative sensitivity of specific functions. The selectors MUST be selectors for
21-
// functions implemented by this module.
22-
SelectorPermission[] permissionDescriptors;
23-
// A list of all ERC-7715 permission strings that the module could possibly use
24-
string[] permissionRequest;
25-
}
26-
276
interface IModule is IERC165 {
287
/// @notice Initialize module data for the modular account.
298
/// @dev Called by the modular account during `installExecution`.
@@ -37,8 +16,8 @@ interface IModule is IERC165 {
3716
/// account.
3817
function onUninstall(bytes calldata data) external;
3918

40-
/// @notice Describe the metadata of the module.
41-
/// @dev This metadata MUST stay constant over time.
42-
/// @return A metadata struct describing the module.
43-
function moduleMetadata() external pure returns (ModuleMetadata memory);
19+
/// @notice Return a unique identifier for the module.
20+
/// @dev This function MUST return a string in the format "vendor/module/semver".
21+
/// @return The module ID.
22+
function moduleId() external view returns (string memory);
4423
}

src/modules/ERC20TokenLimitModule.sol

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet
1414

1515
import {IExecutionHookModule} from "../interfaces/IExecutionHookModule.sol";
1616
import {Call, IModularAccount} from "../interfaces/IModularAccount.sol";
17-
import {IModule, ModuleMetadata} from "../interfaces/IModule.sol";
17+
import {IModule} from "../interfaces/IModule.sol";
1818

1919
import {BaseModule, IERC165} from "./BaseModule.sol";
2020

@@ -114,15 +114,8 @@ contract ERC20TokenLimitModule is BaseModule, IExecutionHookModule {
114114
}
115115

116116
/// @inheritdoc IModule
117-
function moduleMetadata() external pure virtual override returns (ModuleMetadata memory) {
118-
ModuleMetadata memory metadata;
119-
metadata.name = _NAME;
120-
metadata.version = _VERSION;
121-
metadata.author = _AUTHOR;
122-
123-
metadata.permissionRequest = new string[](1);
124-
metadata.permissionRequest[0] = "erc20-token-limit";
125-
return metadata;
117+
function moduleId() external pure returns (string memory) {
118+
return "erc6900/erc20-token-limit-module/1.0.0";
126119
}
127120

128121
/// @inheritdoc BaseModule

src/modules/NativeTokenLimitModule.sol

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet
77

88
import {IExecutionHookModule} from "../interfaces/IExecutionHookModule.sol";
99
import {Call, IModularAccount} from "../interfaces/IModularAccount.sol";
10-
import {IModule, ModuleMetadata} from "../interfaces/IModule.sol";
10+
import {IModule} from "../interfaces/IModule.sol";
1111
import {IValidationHookModule} from "../interfaces/IValidationHookModule.sol";
1212
import {BaseModule, IERC165} from "./BaseModule.sol";
1313

@@ -21,10 +21,6 @@ contract NativeTokenLimitModule is BaseModule, IExecutionHookModule, IValidation
2121
using UserOperationLib for PackedUserOperation;
2222
using EnumerableSet for EnumerableSet.Bytes32Set;
2323

24-
string internal constant _NAME = "Native Token Limit";
25-
string internal constant _VERSION = "1.0.0";
26-
string internal constant _AUTHOR = "ERC-6900 Authors";
27-
2824
mapping(uint256 funcIds => mapping(address account => uint256 limit)) public limits;
2925
// Accounts should add paymasters that still use the accounts tokens here
3026
// E.g. ERC20 paymasters that pull funds from the account
@@ -119,16 +115,8 @@ contract NativeTokenLimitModule is BaseModule, IExecutionHookModule, IValidation
119115
function preSignatureValidationHook(uint32, address, bytes32, bytes calldata) external pure override {}
120116

121117
/// @inheritdoc IModule
122-
function moduleMetadata() external pure virtual override returns (ModuleMetadata memory) {
123-
ModuleMetadata memory metadata;
124-
metadata.name = _NAME;
125-
metadata.version = _VERSION;
126-
metadata.author = _AUTHOR;
127-
128-
metadata.permissionRequest = new string[](2);
129-
metadata.permissionRequest[0] = "native-token-limit";
130-
metadata.permissionRequest[1] = "gas-limit";
131-
return metadata;
118+
function moduleId() external pure returns (string memory) {
119+
return "erc6900/native-token-limit-module/1.0.0";
132120
}
133121

134122
// ┏━━━━━━━━━━━━━━━┓

src/modules/TokenReceiverModule.sol

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@ import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Recei
66

77
import {ExecutionManifest, ManifestExecutionFunction} from "../interfaces/IExecutionModule.sol";
88
import {ExecutionManifest, IExecutionModule} from "../interfaces/IExecutionModule.sol";
9-
import {IModule, ModuleMetadata} from "../interfaces/IModule.sol";
9+
import {IModule} from "../interfaces/IModule.sol";
1010
import {BaseModule} from "./BaseModule.sol";
1111

1212
/// @title Token Receiver Module
1313
/// @author ERC-6900 Authors
1414
/// @notice This module allows modular accounts to receive various types of tokens by implementing
1515
/// required token receiver interfaces.
1616
contract TokenReceiverModule is BaseModule, IExecutionModule, IERC721Receiver, IERC1155Receiver {
17-
string internal constant _NAME = "Token Receiver Module";
18-
string internal constant _VERSION = "1.0.0";
19-
string internal constant _AUTHOR = "ERC-6900 Authors";
20-
2117
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2218
// ┃ Execution functions ┃
2319
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
@@ -85,11 +81,7 @@ contract TokenReceiverModule is BaseModule, IExecutionModule, IERC721Receiver, I
8581
}
8682

8783
/// @inheritdoc IModule
88-
function moduleMetadata() external pure virtual override returns (ModuleMetadata memory) {
89-
ModuleMetadata memory metadata;
90-
metadata.name = _NAME;
91-
metadata.version = _VERSION;
92-
metadata.author = _AUTHOR;
93-
return metadata;
84+
function moduleId() external pure returns (string memory) {
85+
return "erc6900/token-receiver-module/1.0.0";
9486
}
9587
}

src/modules/permissionhooks/AllowlistModule.sol

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity ^0.8.25;
33

44
import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol";
55

6-
import {ModuleMetadata} from "../../interfaces/IModule.sol";
6+
import {IModule} from "../../interfaces/IModule.sol";
77

88
import {Call, IModularAccount} from "../../interfaces/IModularAccount.sol";
99
import {IValidationHookModule} from "../../interfaces/IValidationHookModule.sol";
@@ -88,13 +88,9 @@ contract AllowlistModule is IValidationHookModule, BaseModule {
8888
// solhint-disable-next-line no-empty-blocks
8989
function preSignatureValidationHook(uint32, address, bytes32, bytes calldata) external pure override {}
9090

91-
function moduleMetadata() external pure override returns (ModuleMetadata memory) {
92-
ModuleMetadata memory metadata;
93-
metadata.name = "Allowlist Module";
94-
metadata.version = "v0.0.1";
95-
metadata.author = "ERC-6900 Working Group";
96-
97-
return metadata;
91+
/// @inheritdoc IModule
92+
function moduleId() external pure returns (string memory) {
93+
return "erc6900/allowlist-module/0.0.1";
9894
}
9995

10096
function setAllowlistTarget(uint32 entityId, address target, bool allowed, bool hasSelectorAllowlist) public {

src/modules/validation/SingleSignerValidationModule.sol

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-3.0
22
pragma solidity ^0.8.25;
33

4-
import {IModule, ModuleMetadata} from "../../interfaces/IModule.sol";
4+
import {IModule} from "../../interfaces/IModule.sol";
55
import {IValidationModule} from "../../interfaces/IValidationModule.sol";
66
import {BaseModule} from "../BaseModule.sol";
77

@@ -26,10 +26,6 @@ import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/Signa
2626
contract SingleSignerValidationModule is ISingleSignerValidationModule, ReplaySafeWrapper, BaseModule {
2727
using MessageHashUtils for bytes32;
2828

29-
string internal constant _NAME = "SingleSigner Validation";
30-
string internal constant _VERSION = "1.0.0";
31-
string internal constant _AUTHOR = "ERC-6900 Authors";
32-
3329
uint256 internal constant _SIG_VALIDATION_PASSED = 0;
3430
uint256 internal constant _SIG_VALIDATION_FAILED = 1;
3531

@@ -115,12 +111,8 @@ contract SingleSignerValidationModule is ISingleSignerValidationModule, ReplaySa
115111
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
116112

117113
/// @inheritdoc IModule
118-
function moduleMetadata() external pure virtual override returns (ModuleMetadata memory) {
119-
ModuleMetadata memory metadata;
120-
metadata.name = _NAME;
121-
metadata.version = _VERSION;
122-
metadata.author = _AUTHOR;
123-
return metadata;
114+
function moduleId() external pure returns (string memory) {
115+
return "erc6900/single-signer-validation-module/1.0.0";
124116
}
125117

126118
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓

test/libraries/KnowSelectors.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ contract KnownSelectorsTest is Test {
1818
}
1919

2020
function test_isIModuleFunction() public {
21-
assertTrue(KnownSelectors.isIModuleFunction(IModule.moduleMetadata.selector));
21+
assertTrue(KnownSelectors.isIModuleFunction(IModule.moduleId.selector));
2222
}
2323
}

test/mocks/MockModule.sol

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
55

66
import {IExecutionHookModule} from "../../src/interfaces/IExecutionHookModule.sol";
77
import {ExecutionManifest} from "../../src/interfaces/IExecutionModule.sol";
8-
import {IModule, ModuleMetadata} from "../../src/interfaces/IModule.sol";
8+
import {IModule} from "../../src/interfaces/IModule.sol";
99
import {IValidationModule} from "../../src/interfaces/IValidationModule.sol";
1010

1111
contract MockModule is ERC165 {
@@ -18,10 +18,6 @@ contract MockModule is ERC165 {
1818
// struct ManifestAssociatedFunction memory[] memory to storage not yet supported.
1919
bytes internal _manifest;
2020

21-
string internal constant _NAME = "Mock Module Modifiable";
22-
string internal constant _VERSION = "1.0.0";
23-
string internal constant _AUTHOR = "ERC-6900 Authors";
24-
2521
event ReceivedCall(bytes msgData, uint256 msgValue);
2622

2723
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
@@ -51,12 +47,8 @@ contract MockModule is ERC165 {
5147
return _castToPure(_getManifest)();
5248
}
5349

54-
function moduleMetadata() external pure returns (ModuleMetadata memory) {
55-
ModuleMetadata memory metadata;
56-
metadata.name = _NAME;
57-
metadata.version = _VERSION;
58-
metadata.author = _AUTHOR;
59-
return metadata;
50+
function moduleId() external pure returns (string memory) {
51+
return "erc6900/mock-module/1.0.0";
6052
}
6153

6254
/// @dev Returns true if this contract implements the interface defined by

test/mocks/modules/ComprehensiveModule.sol

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212

1313
import {IExecutionHookModule} from "../../../src/interfaces/IExecutionHookModule.sol";
1414
import {IExecutionModule} from "../../../src/interfaces/IExecutionModule.sol";
15-
import {ModuleMetadata} from "../../../src/interfaces/IModule.sol";
1615

1716
import {IValidationHookModule} from "../../../src/interfaces/IValidationHookModule.sol";
1817
import {IValidationModule} from "../../../src/interfaces/IValidationModule.sol";
@@ -175,11 +174,7 @@ contract ComprehensiveModule is
175174
return manifest;
176175
}
177176

178-
function moduleMetadata() external pure virtual override returns (ModuleMetadata memory) {
179-
ModuleMetadata memory metadata;
180-
metadata.name = _NAME;
181-
metadata.version = _VERSION;
182-
metadata.author = _AUTHOR;
183-
return metadata;
177+
function moduleId() external pure returns (string memory) {
178+
return "erc6900/comprehensive-module/1.0.0";
184179
}
185180
}

0 commit comments

Comments
 (0)