@latticexyz/cli 2.0.0-snapshot-test-32d38619 → 2.0.0-transaction-context-af4b168c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-22IIKR4S.js +4 -0
- package/dist/chunk-22IIKR4S.js.map +1 -0
- package/dist/commands-3JV3U43E.js +27 -0
- package/dist/commands-3JV3U43E.js.map +1 -0
- package/dist/errors-XGN6V2Y3.js +2 -0
- package/dist/errors-XGN6V2Y3.js.map +1 -0
- package/dist/index.js +0 -1
- package/dist/mud.js +1 -14
- package/dist/mud.js.map +1 -1
- package/package.json +18 -13
- package/src/build.ts +44 -0
- package/src/commands/build.ts +36 -0
- package/src/commands/deploy.ts +7 -30
- package/src/commands/dev-contracts.ts +76 -138
- package/src/commands/index.ts +2 -0
- package/src/commands/set-version.ts +23 -61
- package/src/commands/test.ts +30 -36
- package/src/commands/trace.ts +8 -6
- package/src/common.ts +1 -0
- package/src/debug.ts +10 -0
- package/src/deploy/common.ts +76 -0
- package/src/deploy/configToTables.ts +68 -0
- package/src/deploy/create2/README.md +9 -0
- package/src/deploy/create2/deployment.json +7 -0
- package/src/deploy/debug.ts +10 -0
- package/src/deploy/deploy.ts +116 -0
- package/src/deploy/deployWorld.ts +37 -0
- package/src/deploy/ensureContract.ts +61 -0
- package/src/deploy/ensureContractsDeployed.ts +25 -0
- package/src/deploy/ensureDeployer.ts +36 -0
- package/src/deploy/ensureFunctions.ts +86 -0
- package/src/deploy/ensureModules.ts +73 -0
- package/src/deploy/ensureNamespaceOwner.ts +71 -0
- package/src/deploy/ensureSystems.ts +162 -0
- package/src/deploy/ensureTables.ts +65 -0
- package/src/deploy/ensureWorldFactory.ts +118 -0
- package/src/deploy/getFunctions.ts +58 -0
- package/src/deploy/getResourceAccess.ts +51 -0
- package/src/deploy/getResourceIds.ts +31 -0
- package/src/deploy/getSystems.ts +48 -0
- package/src/deploy/getTableValue.ts +30 -0
- package/src/deploy/getTables.ts +59 -0
- package/src/deploy/getWorldDeploy.ts +39 -0
- package/src/deploy/logsToWorldDeploy.ts +49 -0
- package/src/deploy/resolveConfig.ts +151 -0
- package/src/deploy/resourceLabel.ts +3 -0
- package/src/index.ts +1 -1
- package/src/mud.ts +37 -31
- package/src/mudPackages.ts +24 -0
- package/src/runDeploy.ts +131 -0
- package/src/utils/modules/constants.ts +11 -8
- package/src/utils/utils/getContractData.ts +6 -3
- package/dist/chunk-WERDORTY.js +0 -11
- package/dist/chunk-WERDORTY.js.map +0 -1
- package/src/utils/deploy.ts +0 -255
- package/src/utils/deployHandler.ts +0 -93
- package/src/utils/modules/getInstallModuleCallData.ts +0 -27
- package/src/utils/modules/getUserModules.ts +0 -5
- package/src/utils/modules/types.ts +0 -14
- package/src/utils/systems/getGrantAccessCallData.ts +0 -29
- package/src/utils/systems/getRegisterFunctionSelectorsCallData.ts +0 -57
- package/src/utils/systems/getRegisterSystemCallData.ts +0 -17
- package/src/utils/systems/types.ts +0 -9
- package/src/utils/systems/utils.ts +0 -42
- package/src/utils/tables/getRegisterTableCallData.ts +0 -49
- package/src/utils/tables/getTableIds.ts +0 -21
- package/src/utils/tables/types.ts +0 -12
- package/src/utils/utils/confirmNonce.ts +0 -24
- package/src/utils/utils/deployContract.ts +0 -33
- package/src/utils/utils/fastTxExecute.ts +0 -56
- package/src/utils/utils/getChainId.ts +0 -10
- package/src/utils/utils/setInternalFeePerGas.ts +0 -49
- package/src/utils/utils/toBytes16.ts +0 -16
- package/src/utils/utils/types.ts +0 -21
- package/src/utils/world.ts +0 -28
@@ -1,176 +1,114 @@
|
|
1
|
-
import type { CommandModule } from "yargs";
|
2
|
-
import {
|
3
|
-
anvil,
|
4
|
-
forge,
|
5
|
-
getRemappings,
|
6
|
-
getRpcUrl,
|
7
|
-
getScriptDirectory,
|
8
|
-
getSrcDirectory,
|
9
|
-
} from "@latticexyz/common/foundry";
|
1
|
+
import type { CommandModule, InferredOptionTypes } from "yargs";
|
2
|
+
import { anvil, getScriptDirectory, getSrcDirectory } from "@latticexyz/common/foundry";
|
10
3
|
import chalk from "chalk";
|
11
4
|
import chokidar from "chokidar";
|
12
5
|
import { loadConfig, resolveConfigPath } from "@latticexyz/config/node";
|
13
6
|
import { StoreConfig } from "@latticexyz/store";
|
14
|
-
import { tablegen } from "@latticexyz/store/codegen";
|
15
7
|
import path from "path";
|
16
|
-
import { debounce } from "throttle-debounce";
|
17
|
-
import { worldgenHandler } from "./worldgen";
|
18
8
|
import { WorldConfig } from "@latticexyz/world";
|
19
9
|
import { homedir } from "os";
|
20
10
|
import { rmSync } from "fs";
|
21
|
-
import {
|
22
|
-
import {
|
23
|
-
import {
|
24
|
-
import {
|
25
|
-
|
26
|
-
|
27
|
-
rpc
|
28
|
-
configPath
|
11
|
+
import { deployOptions, runDeploy } from "../runDeploy";
|
12
|
+
import { BehaviorSubject, debounceTime, exhaustMap, filter } from "rxjs";
|
13
|
+
import { Address } from "viem";
|
14
|
+
import { isDefined } from "@latticexyz/common/utils";
|
15
|
+
|
16
|
+
const devOptions = {
|
17
|
+
rpc: deployOptions.rpc,
|
18
|
+
configPath: deployOptions.configPath,
|
19
|
+
alwaysRunPostDeploy: deployOptions.alwaysRunPostDeploy,
|
20
|
+
worldAddress: deployOptions.worldAddress,
|
29
21
|
};
|
30
22
|
|
31
|
-
const commandModule: CommandModule<
|
23
|
+
const commandModule: CommandModule<typeof devOptions, InferredOptionTypes<typeof devOptions>> = {
|
32
24
|
command: "dev-contracts",
|
33
25
|
|
34
26
|
describe: "Start a development server for MUD contracts",
|
35
27
|
|
36
28
|
builder(yargs) {
|
37
|
-
return yargs.options(
|
38
|
-
rpc: {
|
39
|
-
type: "string",
|
40
|
-
decs: "RPC endpoint of the development node. If none is provided, an anvil instance is spawned in the background on port 8545.",
|
41
|
-
},
|
42
|
-
configPath: {
|
43
|
-
type: "string",
|
44
|
-
decs: "Path to MUD config",
|
45
|
-
},
|
46
|
-
});
|
29
|
+
return yargs.options(devOptions);
|
47
30
|
},
|
48
31
|
|
49
|
-
async handler(
|
50
|
-
|
51
|
-
await
|
52
|
-
|
53
|
-
const
|
54
|
-
const configPath = args.configPath ?? (await resolveConfigPath(args.configPath));
|
55
|
-
const srcDirectory = await getSrcDirectory();
|
56
|
-
const scriptDirectory = await getScriptDirectory();
|
57
|
-
const remappings = await getRemappings();
|
32
|
+
async handler(opts) {
|
33
|
+
let rpc = opts.rpc;
|
34
|
+
const configPath = opts.configPath ?? (await resolveConfigPath(opts.configPath));
|
35
|
+
const srcDir = await getSrcDirectory();
|
36
|
+
const scriptDir = await getScriptDirectory();
|
58
37
|
const initialConfig = (await loadConfig(configPath)) as StoreConfig & WorldConfig;
|
59
38
|
|
60
|
-
// Initial run of all codegen steps before starting anvil
|
61
|
-
// (so clients can wait for everything to be ready before starting)
|
62
|
-
await handleConfigChange(initialConfig);
|
63
|
-
await handleContractsChange(initialConfig);
|
64
|
-
|
65
39
|
// Start an anvil instance in the background if no RPC url is provided
|
66
|
-
if (!
|
40
|
+
if (!opts.rpc) {
|
41
|
+
// Clean anvil cache as 1s block times can fill up the disk
|
42
|
+
// - https://github.com/foundry-rs/foundry/issues/3623
|
43
|
+
// - https://github.com/foundry-rs/foundry/issues/4989
|
44
|
+
// - https://github.com/foundry-rs/foundry/issues/3699
|
45
|
+
// - https://github.com/foundry-rs/foundry/issues/3512
|
67
46
|
console.log(chalk.gray("Cleaning devnode cache"));
|
68
47
|
const userHomeDir = homedir();
|
69
48
|
rmSync(path.join(userHomeDir, ".foundry", "anvil", "tmp"), { recursive: true, force: true });
|
70
49
|
|
71
50
|
const anvilArgs = ["--block-time", "1", "--block-base-fee-per-gas", "0"];
|
72
51
|
anvil(anvilArgs);
|
52
|
+
rpc = "http://127.0.0.1:8545";
|
73
53
|
}
|
74
54
|
|
75
|
-
const changedSinceLastHandled = {
|
76
|
-
config: false,
|
77
|
-
contracts: false,
|
78
|
-
};
|
79
|
-
|
80
|
-
const changeInProgress = {
|
81
|
-
current: false,
|
82
|
-
};
|
83
|
-
|
84
55
|
// Watch for changes
|
85
|
-
const
|
86
|
-
|
56
|
+
const lastChange$ = new BehaviorSubject<number>(Date.now());
|
57
|
+
chokidar.watch([configPath, srcDir, scriptDir], { ignoreInitial: true }).on("all", async (_, updatePath) => {
|
87
58
|
if (updatePath.includes(configPath)) {
|
88
|
-
|
89
|
-
|
90
|
-
// listening to changes in the codegen directory to avoid an infinite loop
|
91
|
-
changedSinceLastHandled.contracts = true;
|
59
|
+
console.log(chalk.blue("Config changed, queuing deploy…"));
|
60
|
+
lastChange$.next(Date.now());
|
92
61
|
}
|
93
|
-
|
94
|
-
if (updatePath.includes(srcDirectory) || updatePath.includes(scriptDirectory)) {
|
62
|
+
if (updatePath.includes(srcDir) || updatePath.includes(scriptDir)) {
|
95
63
|
// Ignore changes to codegen files to avoid an infinite loop
|
96
|
-
if (updatePath.includes(initialConfig.codegenDirectory))
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
// Trigger debounced onChange
|
101
|
-
handleChange();
|
102
|
-
});
|
103
|
-
|
104
|
-
const handleChange = debounce(100, async () => {
|
105
|
-
// Avoid handling changes multiple times in parallel
|
106
|
-
if (changeInProgress.current) return;
|
107
|
-
changeInProgress.current = true;
|
108
|
-
|
109
|
-
// Reset dirty flags
|
110
|
-
const { config, contracts } = changedSinceLastHandled;
|
111
|
-
changedSinceLastHandled.config = false;
|
112
|
-
changedSinceLastHandled.contracts = false;
|
113
|
-
|
114
|
-
try {
|
115
|
-
// Load latest config
|
116
|
-
const mudConfig = (await loadConfig(configPath)) as StoreConfig & WorldConfig;
|
117
|
-
|
118
|
-
// Handle changes
|
119
|
-
if (config) await handleConfigChange(mudConfig);
|
120
|
-
if (contracts) await handleContractsChange(mudConfig);
|
121
|
-
|
122
|
-
await deploy();
|
123
|
-
} catch (error) {
|
124
|
-
console.error(chalk.red("MUD dev-contracts watcher failed to deploy config or contracts changes\n"));
|
125
|
-
logError(error);
|
126
|
-
}
|
127
|
-
|
128
|
-
changeInProgress.current = false;
|
129
|
-
if (changedSinceLastHandled.config || changedSinceLastHandled.contracts) {
|
130
|
-
console.log("Detected change while handling the previous change");
|
131
|
-
handleChange();
|
64
|
+
if (!updatePath.includes(initialConfig.codegenDirectory)) {
|
65
|
+
console.log(chalk.blue("Contracts changed, queuing deploy…"));
|
66
|
+
lastChange$.next(Date.now());
|
67
|
+
}
|
132
68
|
}
|
133
|
-
|
134
|
-
printMUD();
|
135
|
-
console.log("MUD watching for changes...");
|
136
69
|
});
|
137
70
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
//
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
71
|
+
let worldAddress = opts.worldAddress as Address | undefined;
|
72
|
+
|
73
|
+
const deploys$ = lastChange$.pipe(
|
74
|
+
// debounce so that a large batch of file changes only triggers a deploy after it settles down, rather than the first change it sees (and then redeploying immediately after)
|
75
|
+
debounceTime(200),
|
76
|
+
exhaustMap(async (lastChange) => {
|
77
|
+
if (worldAddress) {
|
78
|
+
console.log(chalk.blue("Rebuilding and upgrading world…"));
|
79
|
+
}
|
80
|
+
|
81
|
+
try {
|
82
|
+
const deploy = await runDeploy({
|
83
|
+
...opts,
|
84
|
+
configPath,
|
85
|
+
rpc,
|
86
|
+
skipBuild: false,
|
87
|
+
printConfig: false,
|
88
|
+
profile: undefined,
|
89
|
+
saveDeployment: true,
|
90
|
+
worldAddress,
|
91
|
+
srcDir,
|
92
|
+
salt: "0x",
|
93
|
+
});
|
94
|
+
worldAddress = deploy.address;
|
95
|
+
// if there were changes while we were deploying, trigger it again
|
96
|
+
if (lastChange < lastChange$.value) {
|
97
|
+
lastChange$.next(lastChange$.value);
|
98
|
+
} else {
|
99
|
+
console.log(chalk.gray("\nWaiting for file changes…\n"));
|
100
|
+
}
|
101
|
+
return deploy;
|
102
|
+
} catch (error) {
|
103
|
+
console.error(chalk.bgRed(chalk.whiteBright("\n Error while attempting deploy \n")));
|
104
|
+
console.error(error);
|
105
|
+
console.log(chalk.gray("\nWaiting for file changes…\n"));
|
106
|
+
}
|
107
|
+
}),
|
108
|
+
filter(isDefined)
|
109
|
+
);
|
110
|
+
|
111
|
+
deploys$.subscribe();
|
174
112
|
},
|
175
113
|
};
|
176
114
|
|
package/src/commands/index.ts
CHANGED
@@ -3,6 +3,7 @@ import { CommandModule } from "yargs";
|
|
3
3
|
import gasReport from "@latticexyz/gas-report";
|
4
4
|
import abiTs from "@latticexyz/abi-ts";
|
5
5
|
|
6
|
+
import build from "./build";
|
6
7
|
import devnode from "./devnode";
|
7
8
|
import faucet from "./faucet";
|
8
9
|
import hello from "./hello";
|
@@ -16,6 +17,7 @@ import devContracts from "./dev-contracts";
|
|
16
17
|
|
17
18
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Each command has different options
|
18
19
|
export const commands: CommandModule<any, any>[] = [
|
20
|
+
build,
|
19
21
|
deploy,
|
20
22
|
devnode,
|
21
23
|
faucet,
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import chalk from "chalk";
|
2
|
-
import {
|
2
|
+
import { readFileSync, writeFileSync } from "fs";
|
3
3
|
import path from "path";
|
4
4
|
import type { CommandModule } from "yargs";
|
5
5
|
import { MUDError } from "@latticexyz/common/errors";
|
6
6
|
import { logError } from "../utils/errors";
|
7
7
|
import localPackageJson from "../../package.json" assert { type: "json" };
|
8
8
|
import glob from "glob";
|
9
|
+
import { mudPackages } from "../mudPackages";
|
9
10
|
|
10
11
|
type Options = {
|
11
12
|
backup?: boolean;
|
@@ -17,9 +18,6 @@ type Options = {
|
|
17
18
|
link?: string;
|
18
19
|
};
|
19
20
|
|
20
|
-
const BACKUP_FILE = ".mudbackup";
|
21
|
-
const MUD_PREFIX = "@latticexyz";
|
22
|
-
|
23
21
|
const commandModule: CommandModule<Options, Options> = {
|
24
22
|
command: "set-version",
|
25
23
|
|
@@ -27,12 +25,6 @@ const commandModule: CommandModule<Options, Options> = {
|
|
27
25
|
|
28
26
|
builder(yargs) {
|
29
27
|
return yargs.options({
|
30
|
-
backup: { type: "boolean", description: `Back up the current MUD versions to "${BACKUP_FILE}"` },
|
31
|
-
force: {
|
32
|
-
type: "boolean",
|
33
|
-
description: `Backup fails if a "${BACKUP_FILE}" file is found, unless --force is provided`,
|
34
|
-
},
|
35
|
-
restore: { type: "boolean", description: `Restore the previous MUD versions from "${BACKUP_FILE}"` },
|
36
28
|
mudVersion: { alias: "v", type: "string", description: "Set MUD to the given version" },
|
37
29
|
tag: {
|
38
30
|
alias: "t",
|
@@ -64,8 +56,11 @@ const commandModule: CommandModule<Options, Options> = {
|
|
64
56
|
throw new MUDError(`These options are mutually exclusive: ${mutuallyExclusiveOptions.join(", ")}`);
|
65
57
|
}
|
66
58
|
|
59
|
+
// If the --link flag is not set, we call resolveVersion to get the version
|
67
60
|
// Resolve the version number from available options like `tag` or `commit`
|
68
|
-
|
61
|
+
if (!options.link) {
|
62
|
+
options.mudVersion = await resolveVersion(options);
|
63
|
+
}
|
69
64
|
|
70
65
|
// Update all package.json below the current working directory (except in node_modules)
|
71
66
|
const packageJsons = glob.sync("**/package.json").filter((p) => !p.includes("node_modules"));
|
@@ -117,63 +112,39 @@ async function resolveVersion(options: Options) {
|
|
117
112
|
}
|
118
113
|
|
119
114
|
function updatePackageJson(filePath: string, options: Options): { workspaces?: string[] } {
|
120
|
-
const {
|
121
|
-
let {
|
122
|
-
|
123
|
-
const backupFilePath = path.join(path.dirname(filePath), BACKUP_FILE);
|
124
|
-
const backupFileExists = existsSync(backupFilePath);
|
125
|
-
|
126
|
-
// Create a backup file for previous MUD versions by default if linking to local MUD
|
127
|
-
if (link && !backupFileExists) backup = true;
|
128
|
-
|
129
|
-
// If `backup` is true and force not set, check if a backup file already exists and throw an error if it does
|
130
|
-
if (backup && !force && backupFileExists) {
|
131
|
-
throw new MUDError(
|
132
|
-
`A backup file already exists at ${backupFilePath}.\nUse --force to overwrite it or --restore to restore it.`
|
133
|
-
);
|
134
|
-
}
|
115
|
+
const { link } = options;
|
116
|
+
let { mudVersion } = options;
|
135
117
|
|
136
118
|
const packageJson = readPackageJson(filePath);
|
137
|
-
|
138
|
-
// Load .mudbackup if `restore` is true
|
139
|
-
const backupJson = restore ? readPackageJson(backupFilePath) : undefined;
|
119
|
+
const mudPackageNames = Object.keys(mudPackages);
|
140
120
|
|
141
121
|
// Find all MUD dependencies
|
142
122
|
const mudDependencies: Record<string, string> = {};
|
143
|
-
for (const
|
144
|
-
if (
|
145
|
-
mudDependencies[
|
123
|
+
for (const packageName in packageJson.dependencies) {
|
124
|
+
if (mudPackageNames.includes(packageName)) {
|
125
|
+
mudDependencies[packageName] = packageJson.dependencies[packageName];
|
146
126
|
}
|
147
127
|
}
|
148
128
|
|
149
129
|
// Find all MUD devDependencies
|
150
130
|
const mudDevDependencies: Record<string, string> = {};
|
151
|
-
for (const
|
152
|
-
if (
|
153
|
-
mudDevDependencies[
|
131
|
+
for (const packageName in packageJson.devDependencies) {
|
132
|
+
if (mudPackageNames.includes(packageName)) {
|
133
|
+
mudDevDependencies[packageName] = packageJson.devDependencies[packageName];
|
154
134
|
}
|
155
135
|
}
|
156
136
|
|
157
|
-
// Back up the current dependencies if `backup` is true
|
158
|
-
if (backup) {
|
159
|
-
writeFileSync(
|
160
|
-
backupFilePath,
|
161
|
-
JSON.stringify({ dependencies: mudDependencies, devDependencies: mudDevDependencies }, null, 2)
|
162
|
-
);
|
163
|
-
console.log(chalk.green(`Backed up MUD dependencies from ${filePath} to ${backupFilePath}`));
|
164
|
-
}
|
165
|
-
|
166
137
|
// Update the dependencies
|
167
|
-
for (const
|
168
|
-
if (
|
169
|
-
packageJson.dependencies[
|
138
|
+
for (const packageName in packageJson.dependencies) {
|
139
|
+
if (mudPackageNames.includes(packageName)) {
|
140
|
+
packageJson.dependencies[packageName] = resolveMudVersion(packageName, "dependencies");
|
170
141
|
}
|
171
142
|
}
|
172
143
|
|
173
144
|
// Update the devDependencies
|
174
|
-
for (const
|
175
|
-
if (
|
176
|
-
packageJson.devDependencies[
|
145
|
+
for (const packageName in packageJson.devDependencies) {
|
146
|
+
if (mudPackageNames.includes(packageName)) {
|
147
|
+
packageJson.devDependencies[packageName] = resolveMudVersion(packageName, "devDependencies");
|
177
148
|
}
|
178
149
|
}
|
179
150
|
|
@@ -184,17 +155,9 @@ function updatePackageJson(filePath: string, options: Options): { workspaces?: s
|
|
184
155
|
logComparison(mudDependencies, packageJson.dependencies);
|
185
156
|
logComparison(mudDevDependencies, packageJson.devDependencies);
|
186
157
|
|
187
|
-
// Remove the backup file if `restore` is true and `backup` is false
|
188
|
-
// because the old backup file is no longer needed
|
189
|
-
if (restore && !backup) {
|
190
|
-
rmSync(backupFilePath);
|
191
|
-
console.log(chalk.green(`Cleaned up ${backupFilePath}`));
|
192
|
-
}
|
193
|
-
|
194
158
|
return packageJson;
|
195
159
|
|
196
160
|
function resolveMudVersion(key: string, type: "dependencies" | "devDependencies") {
|
197
|
-
if (restore && backupJson) return backupJson[type][key];
|
198
161
|
if (link) mudVersion = resolveLinkPath(filePath, link, key);
|
199
162
|
if (!mudVersion) return packageJson[type][key];
|
200
163
|
return mudVersion;
|
@@ -225,10 +188,9 @@ function logComparison(prev: Record<string, string>, curr: Record<string, string
|
|
225
188
|
/**
|
226
189
|
* Returns path of the package to link, given a path to a local MUD clone and a package
|
227
190
|
*/
|
228
|
-
function resolveLinkPath(packageJsonPath: string, mudLinkPath: string,
|
229
|
-
const pkgName = pkg.replace(MUD_PREFIX, "");
|
191
|
+
function resolveLinkPath(packageJsonPath: string, mudLinkPath: string, packageName: string) {
|
230
192
|
const packageJsonToRootPath = path.relative(path.dirname(packageJsonPath), process.cwd());
|
231
|
-
const linkPath = path.join(packageJsonToRootPath, mudLinkPath,
|
193
|
+
const linkPath = path.join(packageJsonToRootPath, mudLinkPath, mudPackages[packageName].localPath);
|
232
194
|
return "link:" + linkPath;
|
233
195
|
}
|
234
196
|
|
package/src/commands/test.ts
CHANGED
@@ -1,70 +1,64 @@
|
|
1
|
-
import type { CommandModule } from "yargs";
|
1
|
+
import type { CommandModule, InferredOptionTypes, Options } from "yargs";
|
2
2
|
import { anvil, forge, getRpcUrl } from "@latticexyz/common/foundry";
|
3
3
|
import chalk from "chalk";
|
4
|
-
import {
|
5
|
-
import { yDeployOptions } from "./deploy";
|
6
|
-
import { DeployOptions, deployHandler } from "../utils/deployHandler";
|
4
|
+
import { deployOptions, runDeploy } from "../runDeploy";
|
7
5
|
|
8
|
-
|
6
|
+
const testOptions = {
|
7
|
+
...deployOptions,
|
8
|
+
port: { type: "number", description: "Port to run internal node for fork testing on", default: 4242 },
|
9
|
+
worldAddress: {
|
10
|
+
type: "string",
|
11
|
+
description:
|
12
|
+
"Address of an existing world contract. If provided, deployment is skipped and the RPC provided in the foundry.toml is used for fork testing.",
|
13
|
+
},
|
14
|
+
forgeOptions: { type: "string", description: "Options to pass to forge test" },
|
15
|
+
} as const satisfies Record<string, Options>;
|
9
16
|
|
10
|
-
|
17
|
+
type TestOptions = InferredOptionTypes<typeof testOptions>;
|
11
18
|
|
12
|
-
const commandModule: CommandModule<
|
19
|
+
const commandModule: CommandModule<typeof testOptions, TestOptions> = {
|
13
20
|
command: "test",
|
14
21
|
|
15
22
|
describe: "Run tests in MUD contracts",
|
16
23
|
|
17
24
|
builder(yargs) {
|
18
|
-
return yargs.options(
|
19
|
-
...yDeployOptions,
|
20
|
-
port: { type: "number", description: "Port to run internal node for fork testing on", default: 4242 },
|
21
|
-
worldAddress: {
|
22
|
-
type: "string",
|
23
|
-
description:
|
24
|
-
"Address of an existing world contract. If provided, deployment is skipped and the RPC provided in the foundry.toml is used for fork testing.",
|
25
|
-
},
|
26
|
-
forgeOptions: { type: "string", description: "Options to pass to forge test" },
|
27
|
-
});
|
25
|
+
return yargs.options(testOptions);
|
28
26
|
},
|
29
27
|
|
30
|
-
async handler(
|
28
|
+
async handler(opts) {
|
31
29
|
// Start an internal anvil process if no world address is provided
|
32
|
-
if (!
|
33
|
-
const anvilArgs = ["--block-base-fee-per-gas", "0", "--port", String(
|
30
|
+
if (!opts.worldAddress) {
|
31
|
+
const anvilArgs = ["--block-base-fee-per-gas", "0", "--port", String(opts.port)];
|
34
32
|
anvil(anvilArgs);
|
35
33
|
}
|
36
34
|
|
37
|
-
const forkRpc =
|
35
|
+
const forkRpc = opts.worldAddress ? await getRpcUrl(opts.profile) : `http://127.0.0.1:${opts.port}`;
|
38
36
|
|
39
37
|
const worldAddress =
|
40
|
-
|
38
|
+
opts.worldAddress ??
|
41
39
|
(
|
42
|
-
await
|
43
|
-
...
|
40
|
+
await runDeploy({
|
41
|
+
...opts,
|
44
42
|
saveDeployment: false,
|
45
43
|
rpc: forkRpc,
|
46
44
|
})
|
47
|
-
).
|
45
|
+
).address;
|
48
46
|
|
49
47
|
console.log(chalk.blue("World address", worldAddress));
|
50
48
|
|
51
|
-
|
52
|
-
writeFileSync(WORLD_ADDRESS_FILE, worldAddress);
|
53
|
-
|
54
|
-
const userOptions = args.forgeOptions?.replaceAll("\\", "").split(" ") ?? [];
|
49
|
+
const userOptions = opts.forgeOptions?.replaceAll("\\", "").split(" ") ?? [];
|
55
50
|
try {
|
56
|
-
|
57
|
-
profile:
|
51
|
+
await forge(["test", "--fork-url", forkRpc, ...userOptions], {
|
52
|
+
profile: opts.profile,
|
53
|
+
env: {
|
54
|
+
WORLD_ADDRESS: worldAddress,
|
55
|
+
},
|
58
56
|
});
|
59
|
-
|
57
|
+
process.exit(0);
|
60
58
|
} catch (e) {
|
61
59
|
console.error(e);
|
62
|
-
rmSync(WORLD_ADDRESS_FILE);
|
63
60
|
process.exit(1);
|
64
61
|
}
|
65
|
-
|
66
|
-
rmSync(WORLD_ADDRESS_FILE);
|
67
|
-
process.exit(0);
|
68
62
|
},
|
69
63
|
};
|
70
64
|
|
package/src/commands/trace.ts
CHANGED
@@ -8,13 +8,14 @@ import { cast, getRpcUrl, getSrcDirectory } from "@latticexyz/common/foundry";
|
|
8
8
|
import { StoreConfig } from "@latticexyz/store";
|
9
9
|
import { resolveWorldConfig, WorldConfig } from "@latticexyz/world";
|
10
10
|
import IBaseWorldAbi from "@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json" assert { type: "json" };
|
11
|
-
import worldConfig from "@latticexyz/world/mud.config
|
12
|
-
import {
|
11
|
+
import worldConfig from "@latticexyz/world/mud.config";
|
12
|
+
import { resourceToHex } from "@latticexyz/common";
|
13
13
|
import { getExistingContracts } from "../utils/getExistingContracts";
|
14
|
-
import {
|
14
|
+
import { createClient, http } from "viem";
|
15
|
+
import { getChainId } from "viem/actions";
|
15
16
|
|
16
17
|
// TODO account for multiple namespaces (https://github.com/latticexyz/mud/issues/994)
|
17
|
-
const systemsTableId =
|
18
|
+
const systemsTableId = resourceToHex({
|
18
19
|
type: "system",
|
19
20
|
namespace: worldConfig.namespace,
|
20
21
|
name: worldConfig.tables.Systems.name,
|
@@ -80,7 +81,7 @@ const commandModule: CommandModule<Options, Options> = {
|
|
80
81
|
const systemTableFieldLayout = await WorldContract.getFieldLayout(systemsTableId);
|
81
82
|
const labels: { name: string; address: string }[] = [];
|
82
83
|
for (const name of names) {
|
83
|
-
const systemSelector =
|
84
|
+
const systemSelector = resourceToHex({ type: "system", namespace, name });
|
84
85
|
// Get the first field of `Systems` table (the table maps system name to its address and other data)
|
85
86
|
const address = await WorldContract.getField(systemsTableId, [systemSelector], 0, systemTableFieldLayout);
|
86
87
|
labels.push({ name, address });
|
@@ -103,7 +104,8 @@ export default commandModule;
|
|
103
104
|
|
104
105
|
async function getWorldAddress(worldsFile: string, rpc: string) {
|
105
106
|
if (existsSync(worldsFile)) {
|
106
|
-
const
|
107
|
+
const client = createClient({ transport: http(rpc) });
|
108
|
+
const chainId = await getChainId(client);
|
107
109
|
const deploys = JSON.parse(readFileSync(worldsFile, "utf-8"));
|
108
110
|
|
109
111
|
if (!deploys[chainId]) {
|
package/src/common.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export type MudPackages = Record<string, { localPath: string }>;
|
package/src/debug.ts
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
import createDebug from "debug";
|
2
|
+
|
3
|
+
export const debug = createDebug("mud:cli");
|
4
|
+
export const error = createDebug("mud:cli");
|
5
|
+
|
6
|
+
// Pipe debug output to stdout instead of stderr
|
7
|
+
debug.log = console.debug.bind(console);
|
8
|
+
|
9
|
+
// Pipe error output to stderr
|
10
|
+
error.log = console.error.bind(console);
|
@@ -0,0 +1,76 @@
|
|
1
|
+
import { Abi, Address, Hex, padHex } from "viem";
|
2
|
+
import storeConfig from "@latticexyz/store/mud.config";
|
3
|
+
import worldConfig from "@latticexyz/world/mud.config";
|
4
|
+
import IBaseWorldAbi from "@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json" assert { type: "json" };
|
5
|
+
import IModuleAbi from "@latticexyz/world-modules/out/IModule.sol/IModule.abi.json" assert { type: "json" };
|
6
|
+
import { Tables, configToTables } from "./configToTables";
|
7
|
+
import { StoreConfig, helloStoreEvent } from "@latticexyz/store";
|
8
|
+
import { WorldConfig, helloWorldEvent } from "@latticexyz/world";
|
9
|
+
|
10
|
+
export const salt = padHex("0x", { size: 32 });
|
11
|
+
|
12
|
+
// https://eips.ethereum.org/EIPS/eip-170
|
13
|
+
export const contractSizeLimit = parseInt("6000", 16);
|
14
|
+
|
15
|
+
// TODO: add `as const` to mud config so these get more strongly typed (blocked by current config parsing not using readonly)
|
16
|
+
export const storeTables = configToTables(storeConfig);
|
17
|
+
export const worldTables = configToTables(worldConfig);
|
18
|
+
|
19
|
+
export const worldDeployEvents = [helloStoreEvent, helloWorldEvent] as const;
|
20
|
+
|
21
|
+
export const worldAbi = [...IBaseWorldAbi, ...IModuleAbi] as const;
|
22
|
+
|
23
|
+
// Ideally, this should be an append-only list. Before adding more versions here, be sure to add backwards-compatible support for old Store/World versions.
|
24
|
+
export const supportedStoreVersions = ["1.0.0-unaudited"];
|
25
|
+
export const supportedWorldVersions = ["1.0.0-unaudited"];
|
26
|
+
|
27
|
+
export type WorldDeploy = {
|
28
|
+
readonly address: Address;
|
29
|
+
readonly worldVersion: string;
|
30
|
+
readonly storeVersion: string;
|
31
|
+
/** Block number where the world was deployed */
|
32
|
+
readonly deployBlock: bigint;
|
33
|
+
/**
|
34
|
+
* Block number at the time of fetching world deploy.
|
35
|
+
* We use this block number when requesting data from the chain to align chain state
|
36
|
+
* with the same block during the introspection steps of the deploy.
|
37
|
+
*/
|
38
|
+
readonly stateBlock: bigint;
|
39
|
+
};
|
40
|
+
|
41
|
+
export type WorldFunction = {
|
42
|
+
readonly signature: string;
|
43
|
+
readonly selector: Hex;
|
44
|
+
readonly systemId: Hex;
|
45
|
+
readonly systemFunctionSignature: string;
|
46
|
+
readonly systemFunctionSelector: Hex;
|
47
|
+
};
|
48
|
+
|
49
|
+
export type DeterministicContract = {
|
50
|
+
readonly address: Address;
|
51
|
+
readonly bytecode: Hex;
|
52
|
+
readonly deployedBytecodeSize: number;
|
53
|
+
readonly abi: Abi;
|
54
|
+
};
|
55
|
+
|
56
|
+
export type System = DeterministicContract & {
|
57
|
+
readonly namespace: string;
|
58
|
+
readonly name: string;
|
59
|
+
readonly systemId: Hex;
|
60
|
+
readonly allowAll: boolean;
|
61
|
+
readonly allowedAddresses: readonly Hex[];
|
62
|
+
readonly functions: readonly WorldFunction[];
|
63
|
+
};
|
64
|
+
|
65
|
+
export type Module = DeterministicContract & {
|
66
|
+
readonly name: string;
|
67
|
+
readonly installAsRoot: boolean;
|
68
|
+
readonly installData: Hex; // TODO: figure out better naming for this
|
69
|
+
};
|
70
|
+
|
71
|
+
export type ConfigInput = StoreConfig & WorldConfig;
|
72
|
+
export type Config<config extends ConfigInput> = {
|
73
|
+
readonly tables: Tables<config>;
|
74
|
+
readonly systems: readonly System[];
|
75
|
+
readonly modules: readonly Module[];
|
76
|
+
};
|