Skip to content

Commit

Permalink
docs(world): add NatSpec to IModule, Module (#1631)
Browse files Browse the repository at this point in the history
Co-authored-by: alvarius <[email protected]>
  • Loading branch information
qbzzt and alvrs authored Sep 29, 2023
1 parent 759eca2 commit fd10cff
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
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

0 comments on commit fd10cff

Please sign in to comment.