Skip to content

Commit

Permalink
refactor(cli): adjust deploy order (#3222)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Sep 23, 2024
1 parent c7b8f01 commit 9d990b5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/tricky-chefs-care.md
Original file line number Diff line number Diff line change
@@ -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.
48 changes: 22 additions & 26 deletions packages/cli/src/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -62,9 +61,29 @@ export async function deploy({
}: DeployOptions): Promise<WorldDeploy> {
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,
Expand All @@ -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,
Expand Down

0 comments on commit 9d990b5

Please sign in to comment.