Skip to content

Commit

Permalink
remove table transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Jul 12, 2024
1 parent 59cede9 commit 26c8bd3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 105 deletions.
17 changes: 2 additions & 15 deletions packages/cli/src/deploy/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@ import { Abi, Address, Hex, padHex } from "viem";
import storeConfig from "@latticexyz/store/mud.config";
import worldConfig from "@latticexyz/world/mud.config";
import IBaseWorldAbi from "@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json" assert { type: "json" };
import { Tables, configToTables } from "./configToTables";
import { helloStoreEvent } from "@latticexyz/store";
import { StoreConfig } from "@latticexyz/store/internal";
import { helloWorldEvent } from "@latticexyz/world";
import { WorldConfig } from "@latticexyz/world/internal";
import { storeToV1 } from "@latticexyz/store/config/v2";
import { worldToV1 } from "@latticexyz/world/config/v2";

export const salt = padHex("0x", { size: 32 });

// https://eips.ethereum.org/EIPS/eip-170
export const contractSizeLimit = parseInt("6000", 16);

// TODO: add `as const` to mud config so these get more strongly typed (blocked by current config parsing not using readonly)
export const storeTables = configToTables(storeToV1(storeConfig));
export const worldTables = configToTables(worldToV1(worldConfig));
export const storeTables = storeConfig.tables;
export const worldTables = worldConfig.tables;

export const worldDeployEvents = [helloStoreEvent, helloWorldEvent] as const;

Expand Down Expand Up @@ -111,10 +105,3 @@ export type Module = DeterministicContract & {
readonly installAsRoot: boolean;
readonly installData: Hex; // TODO: figure out better naming for this
};

export type ConfigInput = StoreConfig & WorldConfig;
export type Config<config extends ConfigInput> = {
readonly tables: Tables<config>;
readonly systems: readonly System[];
readonly libraries: readonly Library[];
};
70 changes: 0 additions & 70 deletions packages/cli/src/deploy/configToTables.ts

This file was deleted.

40 changes: 21 additions & 19 deletions packages/cli/src/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ import { Account, Address, Chain, Client, Hex, Transport } from "viem";
import { ensureDeployer } from "./ensureDeployer";
import { deployWorld } from "./deployWorld";
import { ensureTables } from "./ensureTables";
import { Config, ConfigInput, Module, WorldDeploy, supportedStoreVersions, supportedWorldVersions } from "./common";
import { Library, Module, System, WorldDeploy, supportedStoreVersions, supportedWorldVersions } from "./common";
import { ensureSystems } from "./ensureSystems";
import { waitForTransactionReceipt } from "viem/actions";
import { getWorldDeploy } from "./getWorldDeploy";
import { ensureFunctions } from "./ensureFunctions";
import { ensureModules } from "./ensureModules";
import { Table } from "./configToTables";
import { ensureNamespaceOwner } from "./ensureNamespaceOwner";
import { debug } from "./debug";
import { resourceToLabel } from "@latticexyz/common";
import { ensureContractsDeployed } from "./ensureContractsDeployed";
import { randomBytes } from "crypto";
import { ensureWorldFactory } from "./ensureWorldFactory";
import { Table } from "@latticexyz/config";

type DeployOptions<configInput extends ConfigInput> = {
type DeployOptions = {
client: Client<Transport, Chain | undefined, Account>;
config: Config<configInput>;
tables: readonly Table[];
systems: readonly System[];
libraries: readonly Library[];
modules?: readonly Module[];
salt?: Hex;
worldAddress?: Address;
Expand All @@ -38,17 +40,17 @@ type DeployOptions<configInput extends ConfigInput> = {
* amount of work to make the world match the config (e.g. deploy new tables,
* replace systems, etc.)
*/
export async function deploy<configInput extends ConfigInput>({
export async function deploy({
client,
config,
tables,
systems,
libraries,
modules = [],
salt,
worldAddress: existingWorldAddress,
deployerAddress: initialDeployerAddress,
withWorldProxy,
}: DeployOptions<configInput>): Promise<WorldDeploy> {
const tables = Object.values(config.tables) as Table[];

}: DeployOptions): Promise<WorldDeploy> {
const deployerAddress = initialDeployerAddress ?? (await ensureDeployer(client));

await ensureWorldFactory(client, deployerAddress, withWorldProxy);
Expand All @@ -58,18 +60,18 @@ export async function deploy<configInput extends ConfigInput>({
client,
deployerAddress,
contracts: [
...config.libraries.map((library) => ({
bytecode: library.prepareDeploy(deployerAddress, config.libraries).bytecode,
...libraries.map((library) => ({
bytecode: library.prepareDeploy(deployerAddress, libraries).bytecode,
deployedBytecodeSize: library.deployedBytecodeSize,
label: `${library.path}:${library.name} library`,
})),
...config.systems.map((system) => ({
bytecode: system.prepareDeploy(deployerAddress, config.libraries).bytecode,
...systems.map((system) => ({
bytecode: system.prepareDeploy(deployerAddress, libraries).bytecode,
deployedBytecodeSize: system.deployedBytecodeSize,
label: `${resourceToLabel(system)} system`,
})),
...modules.map((mod) => ({
bytecode: mod.prepareDeploy(deployerAddress, config.libraries).bytecode,
bytecode: mod.prepareDeploy(deployerAddress, libraries).bytecode,
deployedBytecodeSize: mod.deployedBytecodeSize,
label: `${mod.name} module`,
})),
Expand All @@ -90,7 +92,7 @@ export async function deploy<configInput extends ConfigInput>({
const namespaceTxs = await ensureNamespaceOwner({
client,
worldDeploy,
resourceIds: [...tables.map((table) => table.tableId), ...config.systems.map((system) => system.systemId)],
resourceIds: [...tables.map((table) => table.tableId), ...systems.map((system) => system.systemId)],
});

debug("waiting for all namespace registration transactions to confirm");
Expand All @@ -106,19 +108,19 @@ export async function deploy<configInput extends ConfigInput>({
const systemTxs = await ensureSystems({
client,
deployerAddress,
libraries: config.libraries,
libraries,
worldDeploy,
systems: config.systems,
systems,
});
const functionTxs = await ensureFunctions({
client,
worldDeploy,
functions: config.systems.flatMap((system) => system.functions),
functions: systems.flatMap((system) => system.functions),
});
const moduleTxs = await ensureModules({
client,
deployerAddress,
libraries: config.libraries,
libraries,
worldDeploy,
modules,
});
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/runDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export async function runDeploy(opts: DeployOptions): Promise<WorldDeploy> {
salt,
worldAddress: opts.worldAddress as Hex | undefined,
client,
config: resolvedConfig,
tables: Object.values(configV2.tables),
systems: resolvedConfig.systems,
libraries: resolvedConfig.libraries,
modules,
withWorldProxy: configV2.deploy.upgradeableWorldImplementation,
});
Expand Down

0 comments on commit 26c8bd3

Please sign in to comment.