diff --git a/.changeset/tricky-chefs-care.md b/.changeset/tricky-chefs-care.md new file mode 100644 index 0000000000..ef0198bb2f --- /dev/null +++ b/.changeset/tricky-chefs-care.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/cli": patch +--- + +Adjusted deploy order so that the world deploy happens before everything else to avoid spending gas on system contract deploys, etc. if a world cannot be created first. diff --git a/packages/cli/src/deploy/deploy.ts b/packages/cli/src/deploy/deploy.ts index e0a7e3688e..4bdc29fc07 100644 --- a/packages/cli/src/deploy/deploy.ts +++ b/packages/cli/src/deploy/deploy.ts @@ -12,7 +12,6 @@ import { debug } from "./debug"; import { resourceToHex, resourceToLabel } from "@latticexyz/common"; import { ensureContractsDeployed } from "./ensureContractsDeployed"; import { randomBytes } from "crypto"; -import { ensureWorldFactory } from "./ensureWorldFactory"; import { Table } from "@latticexyz/config"; import { ensureResourceTags } from "./ensureResourceTags"; import { waitForTransactions } from "./waitForTransactions"; @@ -62,9 +61,29 @@ export async function deploy({ }: DeployOptions): Promise { const deployerAddress = initialDeployerAddress ?? (await ensureDeployer(client)); - await ensureWorldFactory(client, deployerAddress, config.deploy.upgradeableWorldImplementation); + const worldDeploy = existingWorldAddress + ? await getWorldDeploy(client, existingWorldAddress) + : config.deploy.customWorld + ? await deployCustomWorld({ + client, + deployerAddress, + artifacts, + customWorld: config.deploy.customWorld, + }) + : await deployWorld( + client, + deployerAddress, + salt ?? `0x${randomBytes(32).toString("hex")}`, + config.deploy.upgradeableWorldImplementation, + ); + + if (!supportedStoreVersions.includes(worldDeploy.storeVersion)) { + throw new Error(`Unsupported Store version: ${worldDeploy.storeVersion}`); + } + if (!supportedWorldVersions.includes(worldDeploy.worldVersion)) { + throw new Error(`Unsupported World version: ${worldDeploy.worldVersion}`); + } - // deploy all dependent contracts, because system registration, module install, etc. all expect these contracts to be callable. const libraryMap = getLibraryMap(libraries); await ensureContractsDeployed({ client, @@ -88,29 +107,6 @@ export async function deploy({ ], }); - const worldDeploy = existingWorldAddress - ? await getWorldDeploy(client, existingWorldAddress) - : config.deploy.customWorld - ? await deployCustomWorld({ - client, - deployerAddress, - artifacts, - customWorld: config.deploy.customWorld, - }) - : await deployWorld( - client, - deployerAddress, - salt ?? `0x${randomBytes(32).toString("hex")}`, - config.deploy.upgradeableWorldImplementation, - ); - - if (!supportedStoreVersions.includes(worldDeploy.storeVersion)) { - throw new Error(`Unsupported Store version: ${worldDeploy.storeVersion}`); - } - if (!supportedWorldVersions.includes(worldDeploy.worldVersion)) { - throw new Error(`Unsupported World version: ${worldDeploy.worldVersion}`); - } - const namespaceTxs = await ensureNamespaceOwner({ client, worldDeploy,