Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(world): add NatSpec to IModule, Module #1631

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions packages/world/src/IModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,48 @@ pragma solidity >=0.8.21;

import { IERC165, ERC165_INTERFACE_ID } from "./IERC165.sol";

// ERC-165 Interface ID (see https://eips.ethereum.org/EIPS/eip-165)
/**
* @dev Calculation for ERC-165 interface ID for the IModule functions.
* Combines the selector for each function with the ERC165_INTERFACE_ID.
* See: https://eips.ethereum.org/EIPS/eip-165
*/
bytes4 constant MODULE_INTERFACE_ID = IModule.getName.selector ^
IModule.installRoot.selector ^
IModule.install.selector ^
ERC165_INTERFACE_ID;

/**
* @title IModule
* @dev Interface for the Module system.
* A module can be installed within the context of a world, either as a root or non-root module.
* This interface adheres to the ERC-165 standard for determining interface support.
*/
interface IModule is IERC165 {
/// @dev Errors to represent non-support of specific installation types.
error Module_RootInstallNotSupported();
error Module_NonRootInstallNotSupported();

/**
* Return the module name as a bytes16.
* @notice Return the name of the module.
* @dev Provides a way to identify the module by a unique name.
* @return name The name of the module as a bytes16.
*/
function getName() external view returns (bytes16 name);

/**
* This function is called by the World as part of `installRootModule`.
* The module expects to be called via the World contract, and therefore installs itself on the `msg.sender`.
* @notice Installs the module as a root module.
* @dev This function is invoked by the World contract during `installRootModule` process.
* The module expects to be called via the World contract and thus installs itself on the `msg.sender`.
* @param args Arguments that may be needed during the installation process.
*/
function installRoot(bytes memory args) external;

/**
* This function is called by the World as part of `installModule`.
* The module expects to be called via the World contract, and therefore installs itself on the `msg.sender`.
* This function is separate from `installRoot` because the logic might be different (eg. accepting namespace parameters,
* or using `callFrom`)
* @notice Installs the module.
* @dev This function is invoked by the World contract during `installModule` process.
* The module expects to be called via the World contract and thus installs itself on the `msg.sender`.
* Logic might differ from `installRoot`, for example, this might accept namespace parameters.
* @param args Arguments that may be needed during the installation process.
*/
function install(bytes memory args) external;
}
11 changes: 10 additions & 1 deletion packages/world/src/Module.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ import { WorldContextConsumer } from "./WorldContext.sol";
import { IModule, MODULE_INTERFACE_ID } from "./IModule.sol";
import { IERC165, ERC165_INTERFACE_ID } from "./IERC165.sol";

/**
* @title Module
* @dev Abstract contract that implements the ERC-165 supportsInterface function for IModule.
*/
abstract contract Module is IModule, WorldContextConsumer {
// ERC-165 supportsInterface (see https://eips.ethereum.org/EIPS/eip-165)
/**
* @notice Checks if the given interfaceId is supported by this contract.
* @dev Overrides the functionality from IERC165 and WorldContextConsumer to check for supported interfaces.
* @param interfaceId The bytes4 identifier for the interface.
* @return true if the interface is supported, false otherwise.
*/
function supportsInterface(
bytes4 interfaceId
) public pure virtual override(IERC165, WorldContextConsumer) returns (bool) {
Expand Down