Skip to content

Commit

Permalink
feat(world): emit salt in WorldDeployed event (#2301)
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaaa committed Feb 26, 2024
1 parent 5a8dfc8 commit 3be4dee
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-weeks-laugh.md
@@ -0,0 +1,5 @@
---
"@latticexyz/world": patch
---

Added salt to the `WorldDeployed` event.
9 changes: 5 additions & 4 deletions docs/pages/world/reference/world-external.mdx
Expand Up @@ -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. |
4 changes: 2 additions & 2 deletions packages/world/gas-report.json
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/world/src/IWorldFactory.sol
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/world/src/WorldFactory.sol
Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions packages/world/test/Factories.t.sol
Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion 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)";

0 comments on commit 3be4dee

Please sign in to comment.