World
Reference
World

World

Git Source (opens in a new tab)

Inherits: StoreKernel, IWorldKernel

This contract is the core "World" contract containing various methods for data manipulation, system calls, and dynamic function selector handling.

World doesn't inherit Store because the IStoreRegistration methods are added via the InitModule.

State Variables

creator

Address of the contract's creator.

address public immutable creator;

Functions

worldVersion

function worldVersion() public pure returns (bytes32);

Returns

NameTypeDescription
<none>bytes32The current version of the world contract.

constructor

Event emitted when the World contract is created.

constructor();

prohibitDirectCallback

Prevents the World contract from calling itself. If the World is able to call itself via delegatecall from a system, the system would have root access to context like internal tables, causing a potential vulnerability. Ideally this should not happen because all operations to internal tables happen as internal library calls, and all calls to root systems happen as a delegatecall to the system. However, since this is an important invariant, we make it explicit by reverting if msg.sender is address(this) in all World methods.

modifier prohibitDirectCallback();

initialize

Initializes the World by installing the core module.

Only the initial creator can initialize. This can be done only once.

function initialize(IModule initModule) public prohibitDirectCallback;

Parameters

NameTypeDescription
initModuleIModuleThe core module to initialize the World with.

installRootModule

Installs a given root module in the World.

The caller must own the root namespace.

function installRootModule(IModule module, bytes memory encodedArgs) public prohibitDirectCallback;

Parameters

NameTypeDescription
moduleIModuleThe module to be installed.
encodedArgsbytesThe ABI encoded arguments for module installation.

setRecord

WORLD STORE METHODS

Writes a record in the table identified by tableId.

Requires the caller to have access to the table's namespace or name (encoded in the tableId).

function setRecord(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  bytes calldata staticData,
  EncodedLengths encodedLengths,
  bytes calldata dynamicData
) public virtual prohibitDirectCallback;

Parameters

NameTypeDescription
tableIdResourceIdThe unique identifier for the table.
keyTuplebytes32[]Array of keys identifying the record.
staticDatabytesStatic data (fixed length fields) of the record.
encodedLengthsEncodedLengthsEncoded lengths of data.
dynamicDatabytesDynamic data (variable length fields) of the record.

spliceStaticData

Modifies static (fixed length) data in a record at the specified position.

function spliceStaticData(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint48 start,
  bytes calldata data
) public virtual prohibitDirectCallback;

Parameters

NameTypeDescription
tableIdResourceIdThe unique identifier for the table.
keyTuplebytes32[]Array of keys identifying the record.
startuint48Position from where the static data modification should start.
databytesData to splice into the static data of the record.

spliceDynamicData

Modifies dynamic (variable length) data in a record for a specified field.

function spliceDynamicData(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint8 dynamicFieldIndex,
  uint40 startWithinField,
  uint40 deleteCount,
  bytes calldata data
) public virtual prohibitDirectCallback;

Parameters

NameTypeDescription
tableIdResourceIdThe unique identifier for the table.
keyTuplebytes32[]Array of keys identifying the record.
dynamicFieldIndexuint8Index of the dynamic field to modify.
startWithinFielduint40Start position within the specified dynamic field.
deleteCountuint40Number of bytes to delete starting from the startWithinField.
databytesData to splice into the dynamic data of the field.

setField

Writes data into a specified field in the table identified by tableId.

function setField(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint8 fieldIndex,
  bytes calldata data
) public virtual prohibitDirectCallback;

Parameters

NameTypeDescription
tableIdResourceIdThe unique identifier for the table.
keyTuplebytes32[]Array of keys identifying the record.
fieldIndexuint8Index of the field to modify.
databytesData to write into the specified field.

setField

Writes data into a specified field in the table, adhering to a specific layout.

function setField(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint8 fieldIndex,
  bytes calldata data,
  FieldLayout fieldLayout
) public virtual prohibitDirectCallback;

Parameters

NameTypeDescription
tableIdResourceIdThe unique identifier for the table.
keyTuplebytes32[]Array of keys identifying the record.
fieldIndexuint8Index of the field to modify.
databytesData to write into the specified field.
fieldLayoutFieldLayoutThe layout to adhere to when modifying the field.

setStaticField

Writes data into a static (fixed length) field in the table identified by tableId.

Requires the caller to have access to the table's namespace or name (encoded in the tableId).

function setStaticField(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint8 fieldIndex,
  bytes calldata data,
  FieldLayout fieldLayout
) public virtual prohibitDirectCallback;

Parameters

NameTypeDescription
tableIdResourceIdThe unique identifier for the table.
keyTuplebytes32[]Array of keys identifying the record.
fieldIndexuint8Index of the static field to modify.
databytesData to write into the specified static field.
fieldLayoutFieldLayoutThe layout to adhere to when modifying the field.

setDynamicField

Writes data into a dynamic (varible length) field in the table identified by tableId.

function setDynamicField(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint8 dynamicFieldIndex,
  bytes calldata data
) public virtual prohibitDirectCallback;

Parameters

NameTypeDescription
tableIdResourceIdThe unique identifier for the table.
keyTuplebytes32[]Array of keys identifying the record.
dynamicFieldIndexuint8Index of the dynamic field to modify.
databytesData to write into the specified dynamic field.

pushToDynamicField

Appends data to the end of a dynamic (variable length) field in the table identified by tableId.

function pushToDynamicField(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint8 dynamicFieldIndex,
  bytes calldata dataToPush
) public virtual prohibitDirectCallback;

Parameters

NameTypeDescription
tableIdResourceIdThe unique identifier for the table.
keyTuplebytes32[]Array of keys identifying the record.
dynamicFieldIndexuint8Index of the dynamic field to append to.
dataToPushbytesData to append to the specified dynamic field.

popFromDynamicField

Removes a specified amount of data from the end of a dynamic (variable length) field in the table identified by tableId.

function popFromDynamicField(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint8 dynamicFieldIndex,
  uint256 byteLengthToPop
) public virtual prohibitDirectCallback;

Parameters

NameTypeDescription
tableIdResourceIdThe unique identifier for the table.
keyTuplebytes32[]Array of keys identifying the record.
dynamicFieldIndexuint8Index of the dynamic field to remove data from.
byteLengthToPopuint256The number of bytes to remove from the end of the dynamic field.

deleteRecord

Deletes a record from the table identified by tableId.

Requires the caller to have access to the table's namespace or name.

function deleteRecord(ResourceId tableId, bytes32[] calldata keyTuple) public virtual prohibitDirectCallback;

Parameters

NameTypeDescription
tableIdResourceIdThe unique identifier for the table.
keyTuplebytes32[]Array of keys identifying the record to delete.

call

Usage Sample

SYSTEM CALLS

Calls a system with a given system ID.

If system is private, caller must have appropriate access.

function call(
  ResourceId systemId,
  bytes memory callData
) external payable virtual prohibitDirectCallback returns (bytes memory);

Parameters

NameTypeDescription
systemIdResourceIdThe ID of the system to be called.
callDatabytesThe data for the system call.

Returns

NameTypeDescription
<none>bytesReturn data from the system call.

callFrom

Calls a system with a given system ID on behalf of the given delegator.

If system is private, caller must have appropriate access.

function callFrom(
  address delegator,
  ResourceId systemId,
  bytes memory callData
) external payable virtual prohibitDirectCallback returns (bytes memory);

Parameters

NameTypeDescription
delegatoraddressThe address on whose behalf the system is called.
systemIdResourceIdThe ID of the system to be called.
callDatabytesThe ABI data for the system call.

Returns

NameTypeDescription
<none>bytesReturn data from the system call.

receive

DYNAMIC FUNCTION SELECTORS

Accepts ETH and adds to the root namespace's balance.

receive() external payable;

fallback

Fallback function to call registered function selectors.

fallback() external payable prohibitDirectCallback;

WorldFactory

Git Source (opens in a new tab)

Inherits: IWorldFactory

A factory contract to deploy new World instances.

This contract allows users to deploy a new World, install the InitModule, and transfer the ownership.

State Variables

initModule

Address of the init module to be set in the World instances.

IModule public immutable initModule;

Functions

constructor

constructor(IModule _initModule);

Parameters

NameTypeDescription
_initModuleIModuleThe address of the init module.

deployWorld

Deploys a new World instance, installs the InitModule and transfers ownership to the caller.

Uses the Create2 for deterministic deployment.

function deployWorld(bytes memory salt) public returns (address worldAddress);

Parameters

NameTypeDescription
saltbytesUser defined salt for deterministic world addresses across chains

Returns

NameTypeDescription
worldAddressaddressThe address of the newly deployed World contract.