Skip to content

Commit 99e6e5d

Browse files
authored
replacing all instances of extension to module and all of it's variations (#128)
* renamed from extension to module * formatting
1 parent edcb664 commit 99e6e5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+792
-777
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<p align="center"><strong>Write smart contracts for which you can add, remove, upgrade or switch out the exact parts you want.</strong></p>
88
<br />
99

10-
A Modular Contract is built of two kinds of parts: a _Modular Core_ and its _Modular Extensions_.
10+
A Modular Contract is built of two kinds of parts: a _Modular Core_ and its _Modular Modules_.
1111

1212
![modular-contracts-analogy](./assets/readme-hero-image.png)
1313

14-
A developer writes a **_Core_** smart contract as the foundation that can be customized by adding new parts and updating or removing these parts over time. These ‘parts’ are **_Extension_** smart contracts which any third-party developer can independently develop with reference to the **_Core_** smart contract as the known foundation to build around.
14+
A developer writes a **_Core_** smart contract as the foundation that can be customized by adding new parts and updating or removing these parts over time. These ‘parts’ are **_Module_** smart contracts which any third-party developer can independently develop with reference to the **_Core_** smart contract as the known foundation to build around.
1515

1616
# Install and Use
1717

@@ -36,12 +36,12 @@ import {ERC721A} from "@erc721a/extensions/ERC721AQueryable.sol";
3636
contract ModularNFTCollection is ERC721A, ModularCore {}
3737
```
3838

39-
Import `ModularExtension` to create an Extension for your Core contract (e.g. `Soulbound`):
39+
Import `ModularModule` to create an Module for your Core contract (e.g. `Soulbound`):
4040

4141
```solidity
42-
import {ModularExtension} from "@modular-contracts/ModularExtension.sol";
42+
import {ModularModule} from "@modular-contracts/ModularModule.sol";
4343
44-
contract SoulboundERC721 is ModularExtension {}
44+
contract SoulboundERC721 is ModularModule {}
4545
```
4646

4747
# Run this repo

design-document.md

Lines changed: 104 additions & 104 deletions
Large diffs are not rendered by default.

src/ModularCore.sol

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pragma solidity ^0.8.20;
55

66
import {IInstallationCallback} from "./interface/IInstallationCallback.sol";
77
import {IModularCore} from "./interface/IModularCore.sol";
8-
import {IModularExtension} from "./interface/IModularExtension.sol";
8+
import {IModularModule} from "./interface/IModularModule.sol";
99

1010
// Utils
1111
import {Role} from "./Role.sol";
@@ -21,7 +21,7 @@ abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
2121
TYPES
2222
//////////////////////////////////////////////////////////////*/
2323

24-
/// @dev The type of function callable on extension contracts.
24+
/// @dev The type of function callable on module contracts.
2525
enum FunctionType {
2626
CALLBACK,
2727
FALLBACK
@@ -38,20 +38,20 @@ abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
3838
EVENTS
3939
//////////////////////////////////////////////////////////////*/
4040

41-
/// @notice Emitted when an extension is installed.
42-
event ExtensionInstalled(address caller, address implementation, address installedExtension);
41+
/// @notice Emitted when an module is installed.
42+
event ModuleInstalled(address caller, address implementation, address installedModule);
4343

44-
/// @notice Emitted when an extension is uninstalled.
45-
event ExtensionUninstalled(address caller, address implementation, address installedExtension);
44+
/// @notice Emitted when an module is uninstalled.
45+
event ModuleUninstalled(address caller, address implementation, address installedModule);
4646

4747
/*//////////////////////////////////////////////////////////////
4848
STORAGE
4949
//////////////////////////////////////////////////////////////*/
5050

51-
/// @dev The set of addresses of installed extensions.
52-
EnumerableSetLib.AddressSet private extensions;
51+
/// @dev The set of addresses of installed modules.
52+
EnumerableSetLib.AddressSet private modules;
5353

54-
/// @dev interface ID => counter of extensions supporting the interface.
54+
/// @dev interface ID => counter of modules supporting the interface.
5555
mapping(bytes4 => uint256) private supportedInterfaceRefCounter;
5656

5757
/// @dev function selector => function data.
@@ -61,9 +61,9 @@ abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
6161
ERRORS
6262
//////////////////////////////////////////////////////////////*/
6363

64-
error ExtensionOutOfSync();
65-
error ExtensionNotInstalled();
66-
error ExtensionAlreadyInstalled();
64+
error ModuleOutOfSync();
65+
error ModuleNotInstalled();
66+
error ModuleAlreadyInstalled();
6767

6868
error CallbackFunctionRequired();
6969
error CallbackExecutionReverted();
@@ -74,23 +74,23 @@ abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
7474
error FallbackFunctionAlreadyInstalled();
7575
error FallbackFunctionNotInstalled();
7676

77-
error ExtensionInterfaceNotCompatible(bytes4 requiredInterfaceId);
77+
error ModuleInterfaceNotCompatible(bytes4 requiredInterfaceId);
7878

7979
/*//////////////////////////////////////////////////////////////
8080
FALLBACK FUNCTION
8181
//////////////////////////////////////////////////////////////*/
8282

83-
/// @notice Routes a call to the appropriate extension contract.
83+
/// @notice Routes a call to the appropriate module contract.
8484
fallback() external payable {
85-
// Get extension function data.
85+
// Get module function data.
8686
InstalledFunction memory fn = functionData_[msg.sig];
8787

88-
// Check: extension function data exists.
88+
// Check: module function data exists.
8989
if (fn.implementation == address(0)) {
9090
revert FallbackFunctionNotInstalled();
9191
}
9292

93-
// Check: authorized to call permissioned extension function
93+
// Check: authorized to call permissioned module function
9494
if (fn.fnType == FunctionType.CALLBACK) {
9595
if (msg.sender != address(this)) {
9696
revert CallbackFunctionUnauthorizedCall();
@@ -106,19 +106,19 @@ abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
106106
VIEW FUNCTIONS
107107
//////////////////////////////////////////////////////////////*/
108108

109-
/// @notice Returns the list of all callback functions called on some extension contract.
109+
/// @notice Returns the list of all callback functions called on some module contract.
110110
function getSupportedCallbackFunctions() public pure virtual returns (SupportedCallbackFunction[] memory);
111111

112-
/// @notice Returns a list of addresess and respective extension configs of all installed extensions.
113-
function getInstalledExtensions() external view returns (InstalledExtension[] memory _installedExtensions) {
114-
uint256 totalInstalled = extensions.length();
115-
_installedExtensions = new InstalledExtension[](totalInstalled);
112+
/// @notice Returns a list of addresess and respective module configs of all installed modules.
113+
function getInstalledModules() external view returns (InstalledModule[] memory _installedModules) {
114+
uint256 totalInstalled = modules.length();
115+
_installedModules = new InstalledModule[](totalInstalled);
116116

117117
for (uint256 i = 0; i < totalInstalled; i++) {
118-
address implementation = extensions.at(i);
119-
_installedExtensions[i] = InstalledExtension({
118+
address implementation = modules.at(i);
119+
_installedModules[i] = InstalledModule({
120120
implementation: implementation,
121-
config: IModularExtension(implementation).getExtensionConfig()
121+
config: IModularModule(implementation).getModuleConfig()
122122
});
123123
}
124124
}
@@ -127,24 +127,24 @@ abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
127127
EXTERNAL FUNCTIONS
128128
//////////////////////////////////////////////////////////////*/
129129

130-
/// @notice Installs an extension contract.
131-
function installExtension(address _extension, bytes calldata _data)
130+
/// @notice Installs an module contract.
131+
function installModule(address _module, bytes calldata _data)
132132
external
133133
payable
134134
onlyOwnerOrRoles(Role._INSTALLER_ROLE)
135135
{
136-
// Install extension.
137-
_installExtension(_extension, _data);
136+
// Install module.
137+
_installModule(_module, _data);
138138
}
139139

140-
/// @notice Uninstalls an extension contract.
141-
function uninstallExtension(address _extension, bytes calldata _data)
140+
/// @notice Uninstalls an module contract.
141+
function uninstallModule(address _module, bytes calldata _data)
142142
external
143143
payable
144144
onlyOwnerOrRoles(Role._INSTALLER_ROLE)
145145
{
146-
// Uninstall extension.
147-
_uninstallExtension(_extension, _data);
146+
// Uninstall module.
147+
_uninstallModule(_module, _data);
148148
}
149149

150150
/// @notice Returns whether a given interface is implemented by the contract.
@@ -163,7 +163,7 @@ abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
163163
//////////////////////////////////////////////////////////////*/
164164

165165
/// @notice Returns whether a given interface is implemented by the contract.
166-
function _supportsInterfaceViaExtensions(bytes4 interfaceId) internal view virtual returns (bool) {
166+
function _supportsInterfaceViaModules(bytes4 interfaceId) internal view virtual returns (bool) {
167167
if (interfaceId == 0xffffffff) {
168168
return false;
169169
}
@@ -173,25 +173,25 @@ abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
173173
return false;
174174
}
175175

176-
/// @dev Installs an extension contract.
177-
function _installExtension(address _extension, bytes memory _data) internal {
178-
if (!extensions.add(_extension)) {
179-
revert ExtensionAlreadyInstalled();
176+
/// @dev Installs an module contract.
177+
function _installModule(address _module, bytes memory _data) internal {
178+
if (!modules.add(_module)) {
179+
revert ModuleAlreadyInstalled();
180180
}
181181

182-
// Get extension config.
183-
ExtensionConfig memory config = IModularExtension(_extension).getExtensionConfig();
182+
// Get module config.
183+
ModuleConfig memory config = IModularModule(_module).getModuleConfig();
184184

185-
// Check: ModularCore supports interface required by extension.
185+
// Check: ModularCore supports interface required by module.
186186
if (config.requiredInterfaces.length != 0) {
187187
for (uint256 i = 0; i < config.requiredInterfaces.length; i++) {
188188
if (!supportsInterface(config.requiredInterfaces[i])) {
189-
revert ExtensionInterfaceNotCompatible(config.requiredInterfaces[i]);
189+
revert ModuleInterfaceNotCompatible(config.requiredInterfaces[i]);
190190
}
191191
}
192192
}
193193

194-
// Store interface support inherited via extension installation.
194+
// Store interface support inherited via module installation.
195195
uint256 supportedInterfaceLength = config.supportedInterfaces.length;
196196
for (uint256 i = 0; i < supportedInterfaceLength; i++) {
197197
supportedInterfaceRefCounter[config.supportedInterfaces[i]] += 1;
@@ -223,55 +223,55 @@ abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
223223
}
224224

225225
functionData_[callbackFunction.selector] =
226-
InstalledFunction({implementation: _extension, permissionBits: 0, fnType: FunctionType.CALLBACK});
226+
InstalledFunction({implementation: _module, permissionBits: 0, fnType: FunctionType.CALLBACK});
227227
}
228228

229-
// Store extension function data.
229+
// Store module function data.
230230
uint256 functionLength = config.fallbackFunctions.length;
231231
for (uint256 i = 0; i < functionLength; i++) {
232232
FallbackFunction memory ext = config.fallbackFunctions[i];
233233

234-
// Check: extension function data not already stored.
234+
// Check: module function data not already stored.
235235
if (functionData_[ext.selector].implementation != address(0)) {
236236
revert FallbackFunctionAlreadyInstalled();
237237
}
238238

239239
functionData_[ext.selector] = InstalledFunction({
240-
implementation: _extension,
240+
implementation: _module,
241241
permissionBits: ext.permissionBits,
242242
fnType: FunctionType.FALLBACK
243243
});
244244
}
245245

246-
// Call `onInstall` callback function if extension has registered installation callback.
246+
// Call `onInstall` callback function if module has registered installation callback.
247247
if (config.registerInstallationCallback) {
248248
(bool success, bytes memory returndata) =
249-
_extension.delegatecall(abi.encodeCall(IInstallationCallback.onInstall, (_data)));
249+
_module.delegatecall(abi.encodeCall(IInstallationCallback.onInstall, (_data)));
250250
if (!success) {
251251
_revert(returndata, CallbackExecutionReverted.selector);
252252
}
253253
}
254254

255-
emit ExtensionInstalled(msg.sender, _extension, _extension);
255+
emit ModuleInstalled(msg.sender, _module, _module);
256256
}
257257

258-
/// @notice Uninstalls an extension contract.
259-
function _uninstallExtension(address _extension, bytes memory _data) internal {
260-
// Check: remove and check if the extension is installed
261-
if (!extensions.remove(_extension)) {
262-
revert ExtensionNotInstalled();
258+
/// @notice Uninstalls an module contract.
259+
function _uninstallModule(address _module, bytes memory _data) internal {
260+
// Check: remove and check if the module is installed
261+
if (!modules.remove(_module)) {
262+
revert ModuleNotInstalled();
263263
}
264264

265-
// Get extension config.
266-
ExtensionConfig memory config = IModularExtension(_extension).getExtensionConfig();
265+
// Get module config.
266+
ModuleConfig memory config = IModularModule(_module).getModuleConfig();
267267

268268
uint256 supportedInterfaceLength = config.supportedInterfaces.length;
269269
for (uint256 i = 0; i < supportedInterfaceLength; i++) {
270-
// Note: This should not underflow because extension needs to be installed before uninstalling. getExtensionConfig should returns the same value during installation and uninstallation.
270+
// Note: This should not underflow because module needs to be installed before uninstalling. getModuleConfig should returns the same value during installation and uninstallation.
271271
supportedInterfaceRefCounter[config.supportedInterfaces[i]] -= 1;
272272
}
273273

274-
// Remove extension function data
274+
// Remove module function data
275275
uint256 functionLength = config.fallbackFunctions.length;
276276
for (uint256 i = 0; i < functionLength; i++) {
277277
delete functionData_[config.fallbackFunctions[i].selector];
@@ -284,13 +284,13 @@ abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
284284
}
285285

286286
if (config.registerInstallationCallback) {
287-
_extension.delegatecall(abi.encodeCall(IInstallationCallback.onUninstall, (_data)));
287+
_module.delegatecall(abi.encodeCall(IInstallationCallback.onUninstall, (_data)));
288288
}
289289

290-
emit ExtensionUninstalled(msg.sender, _extension, _extension);
290+
emit ModuleUninstalled(msg.sender, _module, _module);
291291
}
292292

293-
/// @dev Calls an extension callback function and checks whether it is optional or required.
293+
/// @dev Calls an module callback function and checks whether it is optional or required.
294294
function _executeCallbackFunction(bytes4 _selector, bytes memory _abiEncodedCalldata)
295295
internal
296296
nonReentrant
@@ -325,7 +325,7 @@ abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
325325
}
326326
}
327327

328-
/// @dev Calls an extension callback function and checks whether it is optional or required.
328+
/// @dev Calls an module callback function and checks whether it is optional or required.
329329
function _executeCallbackFunctionView(bytes4 _selector, bytes memory _abiEncodedCalldata)
330330
internal
331331
view

src/ModularExtension.sol

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/ModularModule.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.20;
3+
4+
import {IModularModule} from "./interface/IModularModule.sol";
5+
6+
abstract contract ModularModule is IModularModule {
7+
8+
function getModuleConfig() external pure virtual returns (ModuleConfig memory);
9+
10+
}

src/core/token/ERC1155Core.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ contract ERC1155Core is ERC1155, ModularCore, Multicallable {
4949
string memory _symbol,
5050
string memory _contractURI,
5151
address _owner,
52-
address[] memory _extensions,
53-
bytes[] memory _extensionInstallData
52+
address[] memory _modules,
53+
bytes[] memory _moduleInstallData
5454
) payable {
5555
// Set contract metadata
5656
name_ = _name;
5757
symbol_ = _symbol;
5858
_setupContractURI(_contractURI);
5959
_initializeOwner(_owner);
6060

61-
// Install and initialize extensions
62-
require(_extensions.length == _extensionInstallData.length);
63-
for (uint256 i = 0; i < _extensions.length; i++) {
64-
_installExtension(_extensions[i], _extensionInstallData[i]);
61+
// Install and initialize modules
62+
require(_modules.length == _moduleInstallData.length);
63+
for (uint256 i = 0; i < _modules.length; i++) {
64+
_installModule(_modules[i], _moduleInstallData[i]);
6565
}
6666
}
6767

src/core/token/ERC1155CoreInitializable.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ contract ERC1155CoreInitializable is ERC1155, ModularCore, Multicallable, Initia
5454
string memory _symbol,
5555
string memory _contractURI,
5656
address _owner,
57-
address[] memory _extensions,
58-
bytes[] memory _extensionInstallData
57+
address[] memory _modules,
58+
bytes[] memory _moduleInstallData
5959
) external payable initializer {
6060
// Set contract metadata
6161
name_ = _name;
6262
symbol_ = _symbol;
6363
_setupContractURI(_contractURI);
6464
_initializeOwner(_owner);
6565

66-
// Install and initialize extensions
67-
require(_extensions.length == _extensionInstallData.length);
68-
for (uint256 i = 0; i < _extensions.length; i++) {
69-
_installExtension(_extensions[i], _extensionInstallData[i]);
66+
// Install and initialize modules
67+
require(_modules.length == _moduleInstallData.length);
68+
for (uint256 i = 0; i < _modules.length; i++) {
69+
_installModule(_modules[i], _moduleInstallData[i]);
7070
}
7171
}
7272

0 commit comments

Comments
 (0)