Skip to content

Commit

Permalink
fix(cli): wait for world init before transferring ownership (#3220)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs authored Sep 23, 2024
1 parent 0f5b291 commit b071198
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-llamas-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/cli": patch
---

If the project is using a custom world, the deployer now waits for the init transaction to be confirmed before transferring ownership of the world.
37 changes: 18 additions & 19 deletions packages/cli/src/deploy/deployCustomWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,25 @@ export async function deployCustomWorld({
const deploy = logsToWorldDeploy(receipt.logs);
debug("deployed custom world to", deploy.address, "at block", deploy.deployBlock);

const initTxs = await Promise.all([
// initialize world via init module
writeContract(client, {
chain: client.chain ?? null,
address: deploy.address,
abi: worldAbi,
functionName: "initialize",
args: [contracts.InitModule.address],
}),
// transfer root namespace to deployer
writeContract(client, {
chain: client.chain ?? null,
address: deploy.address,
abi: worldAbi,
functionName: "transferOwnership",
args: [resourceToHex({ type: "namespace", namespace: "", name: "" }), client.account.address],
}),
]);
// initialize world via init module
const initTx = await writeContract(client, {
chain: client.chain ?? null,
address: deploy.address,
abi: worldAbi,
functionName: "initialize",
args: [contracts.InitModule.address],
});
await waitForTransactions({ client, hashes: [initTx], debugLabel: "world init" });

await waitForTransactions({ client, hashes: initTxs, debugLabel: "world init" });
// transfer root namespace to deployer after init module is installed so `transferOwnership` method is available
const transferOwnershipTx = await writeContract(client, {
chain: client.chain ?? null,
address: deploy.address,
abi: worldAbi,
functionName: "transferOwnership",
args: [resourceToHex({ type: "namespace", namespace: "", name: "" }), client.account.address],
});
await waitForTransactions({ client, hashes: [transferOwnershipTx], debugLabel: "world ownership transfer" });

return { ...deploy, stateBlock: deploy.deployBlock };
}

0 comments on commit b071198

Please sign in to comment.