Skip to content

Commit

Permalink
refactor(world): add IWorldEvents with HelloWorld (#2358)
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaaa authored Mar 7, 2024
1 parent c60aa8b commit 86766ce
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-weeks-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/world": patch
---

Created an `IWorldEvents` interface with `HelloStore`, so all World events are defined in a single interface.
18 changes: 1 addition & 17 deletions docs/pages/world/reference/world-external.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ function callFrom(
[Git Source](https://github.com/latticexyz/mud/blob/main/packages/world/src/IWorldKernel.sol)

**Inherits:**
[IWorldModuleInstallation](/world/reference/world-external#iworldmoduleinstallation), [IWorldCall](/world/reference/world-external#iworldcall), [IWorldErrors](/world/reference/world-external#iworlderrors)
[IWorldModuleInstallation](/world/reference/world-external#iworldmoduleinstallation), [IWorldCall](/world/reference/world-external#iworldcall), [IWorldErrors](/world/reference/world-external#iworlderrors), [IWorldEvents](/src/IWorldEvents.sol/interface.IWorldEvents.md)

The IWorldKernel interface includes all methods that are part of the World contract's
internal bytecode. Consumers should use the `IBaseWorld` interface instead, which includes dynamically
Expand Down Expand Up @@ -643,22 +643,6 @@ function initialize(IModule initModule) external;
| ------------ | --------- | ----------------------------------------------------- |
| `initModule` | `IModule` | The InitModule to be installed during initialization. |

### Events

#### HelloWorld

_Emitted upon successful World initialization._

```solidity
event HelloWorld(bytes32 indexed worldVersion);
```

**Parameters**

| Name | Type | Description |
| -------------- | --------- | ------------------------------------------- |
| `worldVersion` | `bytes32` | The version of the World being initialized. |

## IWorldModuleInstallation

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/world/src/IWorldKernel.sol)
Expand Down
20 changes: 20 additions & 0 deletions packages/world/src/IWorldEvents.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

import { IWorldErrors } from "./IWorldErrors.sol";
import { IModule } from "./IModule.sol";
import { ResourceId } from "./WorldResourceId.sol";

/**
* @title IWorldEvents
* @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
* @dev We bundle these events in an interface (instead of at the file-level or in their corresponding library) so they can be inherited by IWorldKernel.
* This ensures that all events are included in the IWorldKernel ABI for proper decoding in the frontend.
*/
interface IWorldEvents {
/**
* @dev Emitted upon successful World initialization.
* @param worldVersion The version of the World being initialized.
*/
event HelloWorld(bytes32 indexed worldVersion);
}
9 changes: 2 additions & 7 deletions packages/world/src/IWorldKernel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity >=0.8.24;
import { IWorldErrors } from "./IWorldErrors.sol";
import { IModule } from "./IModule.sol";
import { ResourceId } from "./WorldResourceId.sol";
import { IWorldEvents } from "./IWorldEvents.sol";

/**
* @title World Module Installation Interface
Expand Down Expand Up @@ -59,13 +60,7 @@ interface IWorldCall {
* internal bytecode. Consumers should use the `IBaseWorld` interface instead, which includes dynamically
* registered functions selectors from the `InitModule`.
*/
interface IWorldKernel is IWorldModuleInstallation, IWorldCall, IWorldErrors {
/**
* @dev Emitted upon successful World initialization.
* @param worldVersion The version of the World being initialized.
*/
event HelloWorld(bytes32 indexed worldVersion);

interface IWorldKernel is IWorldModuleInstallation, IWorldCall, IWorldErrors, IWorldEvents {
/**
* @notice Retrieve the version of the World.
* @return The version identifier of the World.
Expand Down
3 changes: 2 additions & 1 deletion packages/world/src/World.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { InitModuleAddress } from "./codegen/tables/InitModuleAddress.sol";

import { IModule, IModule } from "./IModule.sol";
import { IWorldKernel } from "./IWorldKernel.sol";
import { IWorldEvents } from "./IWorldEvents.sol";

import { FunctionSelectors } from "./codegen/tables/FunctionSelectors.sol";
import { Balances } from "./codegen/tables/Balances.sol";
Expand All @@ -47,7 +48,7 @@ contract World is StoreData, IWorldKernel {
/// @dev Event emitted when the World contract is created.
constructor() {
creator = msg.sender;
emit HelloWorld(WORLD_VERSION);
emit IWorldEvents.HelloWorld(WORLD_VERSION);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/world/test/Factories.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { InitModule } from "../src/modules/init/InitModule.sol";
import { Create2Factory } from "../src/Create2Factory.sol";
import { WorldFactory } from "../src/WorldFactory.sol";
import { IWorldFactory } from "../src/IWorldFactory.sol";
import { IWorldEvents } from "../src/IWorldEvents.sol";
import { InstalledModules } from "../src/codegen/tables/InstalledModules.sol";
import { NamespaceOwner } from "../src/codegen/tables/NamespaceOwner.sol";
import { ROOT_NAMESPACE_ID } from "../src/constants.sol";
Expand All @@ -20,7 +21,6 @@ import { createInitModule } from "./createInitModule.sol";
contract FactoriesTest is Test, GasReporter {
event ContractDeployed(address addr, uint256 salt);
event WorldDeployed(address indexed newContract, uint256 salt);
event HelloWorld(bytes32 indexed version);

function calculateAddress(
address deployingAddress,
Expand Down Expand Up @@ -71,7 +71,7 @@ contract FactoriesTest is Test, GasReporter {

// Check for HelloWorld event from World
vm.expectEmit(true, true, true, true);
emit HelloWorld(WORLD_VERSION);
emit IWorldEvents.HelloWorld(WORLD_VERSION);

// Check for WorldDeployed event from Factory
vm.expectEmit(true, false, false, false);
Expand Down Expand Up @@ -104,7 +104,7 @@ contract FactoriesTest is Test, GasReporter {

// Check for HelloWorld event from World
vm.expectEmit(true, true, true, true);
emit HelloWorld(WORLD_VERSION);
emit IWorldEvents.HelloWorld(WORLD_VERSION);

// Check for WorldDeployed event from Factory
vm.expectEmit(true, false, false, false);
Expand Down
4 changes: 2 additions & 2 deletions packages/world/test/World.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { WorldContextProviderLib, IWorldContextConsumer } from "../src/WorldCont
import { SystemHook } from "../src/SystemHook.sol";
import { BEFORE_CALL_SYSTEM, AFTER_CALL_SYSTEM } from "../src/systemHookTypes.sol";
import { Module, IModule } from "../src/Module.sol";
import { IWorldEvents } from "../src/IWorldEvents.sol";

import { NamespaceOwner } from "../src/codegen/tables/NamespaceOwner.sol";
import { ResourceAccess } from "../src/codegen/tables/ResourceAccess.sol";
Expand Down Expand Up @@ -162,7 +163,6 @@ contract RevertSystemHook is SystemHook {
contract WorldTest is Test, GasReporter {
using WorldResourceIdInstance for ResourceId;

event HelloWorld(bytes32 indexed worldVersion);
event HookCalled(bytes data);
event SystemHookCalled(bytes data);
event WorldTestSystemLog(string log);
Expand Down Expand Up @@ -200,7 +200,7 @@ contract WorldTest is Test, GasReporter {
InitModule initModule = createInitModule();

vm.expectEmit(true, true, true, true);
emit HelloWorld(WORLD_VERSION);
emit IWorldEvents.HelloWorld(WORLD_VERSION);
IBaseWorld newWorld = IBaseWorld(address(new World()));
StoreSwitch.setStoreAddress(address(newWorld));

Expand Down

0 comments on commit 86766ce

Please sign in to comment.