-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli,world): add user defined salt in WorldFactory.deployWorld() #2219
Changes from 20 commits
c3de232
785fad6
7f5fe04
33959d2
e898b5f
5d6a95c
ce5ed96
5a07e43
0bc3703
e3dd8c5
0bb5e91
148e2f0
e15b57a
b35ecb4
f297afd
d930d2f
fb0fc34
7d2e8a7
59df327
3a70a1e
eb7db5d
0806e53
c98bd03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@latticexyz/cli": minor | ||
"@latticexyz/world": major | ||
--- | ||
|
||
`WorldFactory` now expects a user-provided `salt` when calling `deployWorld(...)` (instead of the previous globally incrementing counter). This enables deterministic world addresses across different chains. | ||
|
||
When using `mud deploy`, you can provide a `bytes32` hex-encoded salt using the `--salt` option, otherwise it defaults to a random hex value. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Account, Address, Chain, Client, Transport, getAddress } from "viem"; | ||
import { Account, Address, Chain, Client, Hex, Transport, getAddress } from "viem"; | ||
import { ensureDeployer } from "./ensureDeployer"; | ||
import { deployWorld } from "./deployWorld"; | ||
import { ensureTables } from "./ensureTables"; | ||
|
@@ -15,10 +15,12 @@ import { resourceLabel } from "./resourceLabel"; | |
import { uniqueBy } from "@latticexyz/common/utils"; | ||
import { ensureContractsDeployed } from "./ensureContractsDeployed"; | ||
import { worldFactoryContracts } from "./ensureWorldFactory"; | ||
import { randomBytes } from "crypto"; | ||
|
||
type DeployOptions<configInput extends ConfigInput> = { | ||
client: Client<Transport, Chain | undefined, Account>; | ||
config: Config<configInput>; | ||
salt?: Hex; | ||
worldAddress?: Address; | ||
}; | ||
|
||
|
@@ -31,6 +33,7 @@ type DeployOptions<configInput extends ConfigInput> = { | |
export async function deploy<configInput extends ConfigInput>({ | ||
client, | ||
config, | ||
salt, | ||
worldAddress: existingWorldAddress, | ||
}: DeployOptions<configInput>): Promise<WorldDeploy> { | ||
const tables = Object.values(config.tables) as Table[]; | ||
|
@@ -58,7 +61,7 @@ export async function deploy<configInput extends ConfigInput>({ | |
|
||
const worldDeploy = existingWorldAddress | ||
? await getWorldDeploy(client, existingWorldAddress) | ||
: await deployWorld(client); | ||
: await deployWorld(client, salt ? salt : `0x${randomBytes(32).toString("hex")}`); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we might want to check |
||
if (!supportedStoreVersions.includes(worldDeploy.storeVersion)) { | ||
throw new Error(`Unsupported Store version: ${worldDeploy.storeVersion}`); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we sort of do in that our e2e tests lean on deploying a world with the mud cli (I think) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be nice to do our own internally incrementing counter for this process here, so that restarting the dev process always results in the same contract address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, this might be harder than I initially thought it would be. Since we already pass the
worldAddress
in to upgrade worlds, this should be fine.Just a note that this means that our tests that generate data, snapshots, etc. will be non-deterministic for now (unless we update them to pass in a consistent salt)