Core Systems
When developing or using autonomous worlds, most of the functionality we interact with is implemented by the core systems within the Mud framework. Their main functions are as follows:
AccessManagementSystemBalanceTransferSystemBatchCallSystemModuleInstallationSystemStoreRegistrationSystemWorldRegistrationSystem
AccessManagementSystem
The Access Management System is used to manage access control for resources in the World. It handles granting and revoking access to resources, as well as transferring and renouncing namespace ownership.
grantAccess
Grants access to a resource for a specific address.
function grantAccess(ResourceId resourceId, address grantee)
Requires caller to own the namespace containing the resource
resourceId: ID of the resource to grant access tograntee: Address to grant access toResource must exist
revokeAccess
Revokes access to a resource from a specific address.
function revokeAccess(ResourceId resourceId, address grantee)
Requires caller to own the namespace containing the resource
resourceId: ID of the resource to revoke access fromgrantee: Address to revoke access from
transferOwnership
Transfers ownership of a namespace to a new owner.
function transferOwnership(ResourceId namespaceId, address newOwner)
Requires caller to own the namespace
namespaceId: ID of the namespace to transfernewOwner: Address to transfer ownership toResource must be a namespace and exist
Revokes access from old owner and grants access to new owner
renounceOwnership
Renounces ownership of a namespace, effectively abandoning it.
function renounceOwnership(ResourceId namespaceId)
Requires caller to own the namespace
namespaceId: ID of the namespace to renounceResource must be a namespace and exist
Removes namespace owner and revokes access from current owner
Important
If the original owner previously granted themselves access to individual system or table resources, changing ownership will not cause them to lose access to these resources. If the new owner wants to prevent this access, they should manually revoke these permissions.
BalanceTransferSystem
The Balance Transfer System facilitates balance transfers both within the World (between namespaces) and from the World to external addresses.
transferBalanceToNamespace
Transfers balance from one namespace to another within the World.
function transferBalanceToNamespace(
ResourceId fromNamespaceId,
ResourceId toNamespaceId,
uint256 amount
)
fromNamespaceId: Source namespace to transfer fromtoNamespaceId: Target namespace to transfer toamount: Amount to transferRequires caller to have access to source namespace
Both namespaces must exist and be valid namespace types
Source namespace must have sufficient balance
Updates balances of both namespaces
transferBalanceToAddress
Transfers balance from a namespace to an external address.
function transferBalanceToAddress(
ResourceId fromNamespaceId,
address toAddress,
uint256 amount
)
fromNamespaceId: Source namespace to transfer fromtoAddress: Target address to transfer toamount: Amount to transferRequires caller to have access to source namespace
Source namespace must have sufficient balance
Updates source namespace balance and transfers funds to target address
Reverts if external transfer fails
BatchCallSystem
The Batch Call System enables batching multiple system calls into a single transaction for efficiency. It provides two main functions:
batchCall
Makes multiple system calls in a single transaction.
function batchCall(SystemCallData[] calldata systemCalls) returns (bytes[] memory returnDatas)
systemCalls: Array of system calls containing systemId and callData for each callreturnDatas: Array of return data bytes from each system callExecutes each system call in sequence
Reverts entire batch if any call fails
batchCallFrom
Makes multiple system calls from specified addresses in a single transaction.
function batchCallFrom(SystemCallFromData[] calldata systemCalls) returns (bytes[] memory returnDatas)
systemCalls: Array of system calls containing from address, systemId and callData for each callreturnDatas: Array of return data bytes from each system callExecutes each system call in sequence using specified from address
Reverts entire batch if any call fails
ModuleInstallationSystem
The Module Installation System handles the installation of non-root modules in the World. It provides functionality to install modules under specific namespaces.
installModule
Installs a non-rootmodule into the World under a specified namespace.
function installModule(IModule module, bytes memory encodedArgs)
module: The module contract to be installedencodedArgs: ABI encoded arguments for module installationValidates that module implements IModule interface
Registers module in InstalledModules table
Important
The Module Installation System cannot install root modules. Root module installation is implemented by the World contract itself, not the Module Installation System.
StoreRegistrationSystem
The Store Registration System handles registration of tables and store hooks within the World. It provides functionality for registering tables with specific schemas and layouts, as well as managing storage hooks for tables.
registerTable
Registers a new table with specified configuration.
function registerTable(
ResourceId tableId,
FieldLayout fieldLayout,
Schema keySchema,
Schema valueSchema,
string[] calldata keyNames,
string[] calldata fieldNames
)
tableId: Resource ID of the table to registerfieldLayout: Field layout structure for the tablekeySchema: Schema for table keysvalueSchema: Schema for table valueskeyNames: Names for the table keysfieldNames: Names for the table fieldsRequires caller to own the namespace containing the table
Table name cannot be the root name(empty string)
registerStoreHook
Registers a store hook for a specified table.
function registerStoreHook(
ResourceId tableId,
IStoreHook hookAddress,
uint8 enabledHooksBitmap
)
tableId: Resource ID of the table to register the hook forhookAddress: Address of the hook contractenabledHooksBitmap: Bitmap indicating which hook functionalities are enabledRequires caller to own the namespace containing the table
Hook contract must implement the
IStoreHookinterface
unregisterStoreHook
Unregisters a store hook for a specified table.
function unregisterStoreHook(ResourceId tableId, IStoreHook hookAddress)
tableId: Resource ID of the table to unregister the hook fromhookAddress: Address of the hook contract to unregisterRequires caller to own the namespace containing the table
WorldRegistrationSystem
The World Registration System provides functions for registering resources other than tables in the World.
registerNamespace
Registers a new namespace.
function registerNamespace(ResourceId namespaceId)
namespaceId: Resource ID for the new namespaceNamespace must not already exist
Namespace name should be valid that not contain reserved characters like
__and not end with_
registerSystemHook
Registers a system hook for a specified system.
function registerSystemHook(
ResourceId systemId,
ISystemHook hookAddress,
uint8 enabledHooksBitmap
)
systemId: Resource ID of the system to register the hook forhookAddress: Address of the hook contractenabledHooksBitmap: Bitmap indicating which hook functionalities are enabledRequires caller to own the namespace containing the system
Hook contract must implement the
ISystemHookinterface
unregisterSystemHook
Unregisters a system hook for a specified system.
function unregisterSystemHook(ResourceId systemId, ISystemHook hookAddress)
systemId: Resource ID of the system to unregister the hook fromhookAddress: Address of the hook contract to unregisterRequires caller to own the namespace containing the system
registerSystem
Registers or upgrades a system at the given ID.
function registerSystem(ResourceId systemId, System system, bool publicAccess)
systemId: Resource ID for the systemsystem: The system contract being registeredpublicAccess: Flag indicating if access control check is bypassedRequires caller to own the namespace containing the system
Requires the system not registered before with different resource ID
Can upgrade existing systems
System must implement
WorldContextConsumerinterface
registerFunctionSelector
Registers a new World function selector.
function registerFunctionSelector(
ResourceId systemId,
string memory systemFunctionSignature
) returns (bytes4 worldFunctionSelector)
systemId: Resource ID of the systemsystemFunctionSignature: Signature of the system functionRequires the selector to be unique
Creates mapping between World function and system function with namespace prefix
Requires caller to own the namespace containing the system
registerRootFunctionSelector
Registers a root World function selector.
function registerRootFunctionSelector(
ResourceId systemId,
string memory worldFunctionSignature,
string memory systemFunctionSignature
) returns (bytes4 worldFunctionSelector)
systemId: Resource ID of the systemworldFunctionSignature: Signature of the World functionsystemFunctionSignature: Signature of the system functionRequires the selector to be unique
Creates mapping between World function and system function without namespace prefix
Requires caller to own the root namespace
registerDelegation
Registers a delegation for the caller.
function registerDelegation(
address delegatee,
ResourceId delegationControlId,
bytes memory initCallData
)
delegatee: Address of the delegateedelegationControlId: ID controlling the delegationinitCallData: Initialization data for the delegationCreates new delegation from caller to specified delegatee
unregisterDelegation
Unregisters a delegation.
function unregisterDelegation(address delegatee)
delegatee: Address of the delegatee to unregisterDeletes the delegation from caller to specified delegatee
registerNamespaceDelegation
Registers a delegation for a namespace.
function registerNamespaceDelegation(
ResourceId namespaceId,
ResourceId delegationControlId,
bytes memory initCallData
)
namespaceId: ID of the namespacedelegationControlId: ID controlling the delegationinitCallData: Initialization data for the delegationSets up delegation control for a specific namespace
Requires caller to own the namespace
Delegation cannot be unlimited
unregisterNamespaceDelegation
Unregisters a delegation for a namespace.
function unregisterNamespaceDelegation(ResourceId namespaceId)
namespaceId: ID of the namespaceDeletes the delegation control for a specific namespace
Requires caller to own the namespace