From 3be4deecf8bc19ebba9723237be2264997ef6292 Mon Sep 17 00:00:00 2001 From: yonada Date: Mon, 26 Feb 2024 09:44:13 +0000 Subject: [PATCH] feat(world): emit salt in WorldDeployed event (#2301) --- .changeset/forty-weeks-laugh.md | 5 +++++ docs/pages/world/reference/world-external.mdx | 9 +++++---- packages/world/gas-report.json | 4 ++-- packages/world/src/IWorldFactory.sol | 3 ++- packages/world/src/WorldFactory.sol | 2 +- packages/world/test/Factories.t.sol | 6 +++--- packages/world/ts/worldEvents.ts | 2 +- 7 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 .changeset/forty-weeks-laugh.md diff --git a/.changeset/forty-weeks-laugh.md b/.changeset/forty-weeks-laugh.md new file mode 100644 index 0000000000..138c16494f --- /dev/null +++ b/.changeset/forty-weeks-laugh.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/world": patch +--- + +Added salt to the `WorldDeployed` event. diff --git a/docs/pages/world/reference/world-external.mdx b/docs/pages/world/reference/world-external.mdx index 5a3d336c12..4e5d2dc854 100644 --- a/docs/pages/world/reference/world-external.mdx +++ b/docs/pages/world/reference/world-external.mdx @@ -933,11 +933,12 @@ function deployWorld(bytes memory salt) external returns (address worldAddress); _Emitted when a new World contract is deployed._ ```solidity -event WorldDeployed(address indexed newContract); +event WorldDeployed(address indexed newContract, uint256 salt); ``` **Parameters** -| Name | Type | Description | -| ------------- | --------- | ------------------------------------------------- | -| `newContract` | `address` | The address of the newly deployed World contract. | +| Name | Type | Description | +| ------------- | --------- | ------------------------------------------------------------------ | +| `newContract` | `address` | The address of the newly deployed World contract. | +| `salt` | `uint256` | User defined salt for deterministic world addresses across chains. | diff --git a/packages/world/gas-report.json b/packages/world/gas-report.json index aca370eb35..179cc83054 100644 --- a/packages/world/gas-report.json +++ b/packages/world/gas-report.json @@ -57,13 +57,13 @@ "file": "test/Factories.t.sol", "test": "testCreate2Factory", "name": "deploy contract via Create2", - "gasUsed": 4612103 + "gasUsed": 4615190 }, { "file": "test/Factories.t.sol", "test": "testWorldFactoryGas", "name": "deploy world via WorldFactory", - "gasUsed": 12696900 + "gasUsed": 12697195 }, { "file": "test/World.t.sol", diff --git a/packages/world/src/IWorldFactory.sol b/packages/world/src/IWorldFactory.sol index 08589dda72..af3380570d 100644 --- a/packages/world/src/IWorldFactory.sol +++ b/packages/world/src/IWorldFactory.sol @@ -10,8 +10,9 @@ interface IWorldFactory { /** * @dev Emitted when a new World contract is deployed. * @param newContract The address of the newly deployed World contract. + * @param salt User defined salt for deterministic world addresses across chains. */ - event WorldDeployed(address indexed newContract); + event WorldDeployed(address indexed newContract, uint256 salt); /** * @notice Deploys a new World contract. diff --git a/packages/world/src/WorldFactory.sol b/packages/world/src/WorldFactory.sol index 7e9028109f..75492b5843 100644 --- a/packages/world/src/WorldFactory.sol +++ b/packages/world/src/WorldFactory.sol @@ -39,6 +39,6 @@ contract WorldFactory is IWorldFactory { world.initialize(initModule); world.transferOwnership(ROOT_NAMESPACE_ID, msg.sender); - emit WorldDeployed(worldAddress); + emit WorldDeployed(worldAddress, _salt); } } diff --git a/packages/world/test/Factories.t.sol b/packages/world/test/Factories.t.sol index 33c4cda0e4..e96950dd39 100644 --- a/packages/world/test/Factories.t.sol +++ b/packages/world/test/Factories.t.sol @@ -19,7 +19,7 @@ import { createInitModule } from "./createInitModule.sol"; contract FactoriesTest is Test, GasReporter { event ContractDeployed(address addr, uint256 salt); - event WorldDeployed(address indexed newContract); + event WorldDeployed(address indexed newContract, uint256 salt); event HelloWorld(bytes32 indexed version); function calculateAddress( @@ -75,7 +75,7 @@ contract FactoriesTest is Test, GasReporter { // Check for WorldDeployed event from Factory vm.expectEmit(true, false, false, false); - emit WorldDeployed(calculatedAddress); + emit WorldDeployed(calculatedAddress, salt1); startGasReport("deploy world via WorldFactory"); worldFactory.deployWorld(_salt1); endGasReport(); @@ -108,7 +108,7 @@ contract FactoriesTest is Test, GasReporter { // Check for WorldDeployed event from Factory vm.expectEmit(true, false, false, false); - emit WorldDeployed(calculatedAddress); + emit WorldDeployed(calculatedAddress, salt2); worldFactory.deployWorld(_salt2); // Set the store address manually diff --git a/packages/world/ts/worldEvents.ts b/packages/world/ts/worldEvents.ts index 626b7cfbfd..f331f9047e 100644 --- a/packages/world/ts/worldEvents.ts +++ b/packages/world/ts/worldEvents.ts @@ -1,5 +1,5 @@ // from WorldFactory -export const worldDeployedEvent = "event WorldDeployed(address indexed newContract)"; +export const worldDeployedEvent = "event WorldDeployed(address indexed newContract, uint256 salt)"; // from World export const helloWorldEvent = "event HelloWorld(bytes32 indexed worldVersion)";