@latticexyz/cli 1.34.0 → 1.36.0

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.
@@ -73,6 +73,7 @@ export type DeployOptions = {
73
73
  worldAddress?: string;
74
74
  rpc: string;
75
75
  systems?: string | string[];
76
+ reuseComponents?: boolean;
76
77
  clear?: boolean;
77
78
  gasPrice?: number;
78
79
  };
@@ -94,15 +95,11 @@ export async function generateAndDeploy(args: DeployOptions) {
94
95
  args.deployerPrivateKey,
95
96
  args.rpc,
96
97
  args.worldAddress,
97
- Boolean(args.systems),
98
+ Boolean(args.reuseComponents),
98
99
  args.gasPrice
99
100
  );
100
101
  deployedWorldAddress = result.deployedWorldAddress;
101
102
  initialBlockNumber = result.initialBlockNumber;
102
-
103
- // Extract world address from deploy script
104
- } catch (e) {
105
- console.error(e);
106
103
  } finally {
107
104
  // Remove generated LibDeploy
108
105
  console.log("Cleaning up deployment script");
@@ -0,0 +1,45 @@
1
+ import { execa } from "execa";
2
+
3
+ export interface ForgeConfig {
4
+ // project
5
+ src: string;
6
+ test: string;
7
+ out: string;
8
+ libs: string[];
9
+
10
+ // all unspecified keys (this interface is far from comprehensive)
11
+ [key: string]: unknown;
12
+ }
13
+
14
+ /**
15
+ * Get forge config as a parsed json object.
16
+ */
17
+ export async function getForgeConfig() {
18
+ const { stdout } = await execa("forge", ["config", "--json"], { stdio: ["inherit", "pipe", "pipe"] });
19
+
20
+ return JSON.parse(stdout) as ForgeConfig;
21
+ }
22
+
23
+ /**
24
+ * Get the value of "src" from forge config.
25
+ * The path to the contract sources relative to the root of the project.
26
+ */
27
+ export async function getSrcDirectory() {
28
+ return (await getForgeConfig()).src;
29
+ }
30
+
31
+ /**
32
+ * Get the value of "test" from forge config.
33
+ * The path to the test contract sources relative to the root of the project.
34
+ */
35
+ export async function getTestDirectory() {
36
+ return (await getForgeConfig()).test;
37
+ }
38
+
39
+ /**
40
+ * Get the value of "out" from forge config.
41
+ * The path to put contract artifacts in, relative to the root of the project.
42
+ */
43
+ export async function getOutDirectory() {
44
+ return (await getForgeConfig()).out;
45
+ }
@@ -5,6 +5,8 @@ import { extractIdFromFile } from "./ids";
5
5
  import { rmSync, writeFileSync } from "fs";
6
6
  import path from "path";
7
7
  import { filterAbi, forgeBuild } from "./build";
8
+ import { getOutDirectory, getSrcDirectory } from "./forgeConfig";
9
+ import { systemsDir } from "./constants";
8
10
 
9
11
  export async function generateAbiTypes(
10
12
  inputDir: string,
@@ -31,7 +33,7 @@ export async function generateAbiTypes(
31
33
  console.log(`Successfully generated ${result.filesGenerated} files`);
32
34
  }
33
35
 
34
- export async function generateSystemTypes(inputDir: string, outputDir: string, options?: { clear?: boolean }) {
36
+ export async function generateSystemTypes(outputDir: string, options?: { clear?: boolean }) {
35
37
  if (options?.clear) {
36
38
  console.log("Clearing system type output files", outputDir);
37
39
  rmSync(path.join(outputDir, "/SystemTypes.ts"), { force: true });
@@ -45,7 +47,8 @@ export async function generateSystemTypes(inputDir: string, outputDir: string, o
45
47
  let ids: string[] = [];
46
48
  let typePaths: string[] = [];
47
49
 
48
- const systemsPath = `${inputDir}/*.sol`;
50
+ const srcDir = await getSrcDirectory();
51
+ const systemsPath = path.join(srcDir, systemsDir, "*.sol");
49
52
 
50
53
  const [resolve, , promise] = deferred<void>();
51
54
  glob(systemsPath, {}, (_, matches) => {
@@ -126,12 +129,12 @@ ${systems.map((system, index) => ` "${ids[index]}": ${system}.abi,`).join("\n")
126
129
  export async function generateTypes(abiDir?: string, outputDir = "./types", options?: { clear?: boolean }) {
127
130
  if (!abiDir) {
128
131
  console.log("Compiling contracts");
129
- const buildOutput = "./out";
132
+ const buildOutput = await getOutDirectory();
130
133
  abiDir = "./abi";
131
- await forgeBuild(buildOutput, options);
134
+ await forgeBuild(options);
132
135
  filterAbi(buildOutput, abiDir);
133
136
  }
134
137
 
135
138
  await generateAbiTypes(abiDir, path.join(outputDir, "ethers-contracts"), options);
136
- await generateSystemTypes("./src/systems", outputDir, options);
139
+ await generateSystemTypes(outputDir, options);
137
140
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2022-present Lattice Labs Ltd.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,320 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity >=0.8.0;
3
-
4
- interface Cheats {
5
- // This allows us to getRecordedLogs()
6
- struct Log {
7
- bytes32[] topics;
8
- bytes data;
9
- }
10
-
11
- // Set block.timestamp (newTimestamp)
12
- function warp(uint256) external;
13
-
14
- // Set block.height (newHeight)
15
- function roll(uint256) external;
16
-
17
- // Set block.basefee (newBasefee)
18
- function fee(uint256) external;
19
-
20
- // Set block.coinbase (who)
21
- function coinbase(address) external;
22
-
23
- // Loads a storage slot from an address (who, slot)
24
- function load(address, bytes32) external returns (bytes32);
25
-
26
- // Stores a value to an address' storage slot, (who, slot, value)
27
- function store(
28
- address,
29
- bytes32,
30
- bytes32
31
- ) external;
32
-
33
- // Signs data, (privateKey, digest) => (v, r, s)
34
- function sign(uint256, bytes32)
35
- external
36
- returns (
37
- uint8,
38
- bytes32,
39
- bytes32
40
- );
41
-
42
- // Gets address for a given private key, (privateKey) => (address)
43
- function addr(uint256) external returns (address);
44
-
45
- // Derive a private key from a provided mnenomic string (or mnenomic file path) at the derivation path m/44'/60'/0'/0/{index}
46
- function deriveKey(string calldata, uint32) external returns (uint256);
47
-
48
- // Derive a private key from a provided mnenomic string (or mnenomic file path) at the derivation path {path}{index}
49
- function deriveKey(
50
- string calldata,
51
- string calldata,
52
- uint32
53
- ) external returns (uint256);
54
-
55
- // Performs a foreign function call via terminal, (stringInputs) => (result)
56
- function ffi(string[] calldata) external returns (bytes memory);
57
-
58
- // Set environment variables, (name, value)
59
- function setEnv(string calldata, string calldata) external;
60
-
61
- // Read environment variables, (name) => (value)
62
- function envBool(string calldata) external returns (bool);
63
-
64
- function envUint(string calldata) external returns (uint256);
65
-
66
- function envInt(string calldata) external returns (int256);
67
-
68
- function envAddress(string calldata) external returns (address);
69
-
70
- function envBytes32(string calldata) external returns (bytes32);
71
-
72
- function envString(string calldata) external returns (string memory);
73
-
74
- function envBytes(string calldata) external returns (bytes memory);
75
-
76
- // Read environment variables as arrays, (name, delim) => (value[])
77
- function envBool(string calldata, string calldata) external returns (bool[] memory);
78
-
79
- function envUint(string calldata, string calldata) external returns (uint256[] memory);
80
-
81
- function envInt(string calldata, string calldata) external returns (int256[] memory);
82
-
83
- function envAddress(string calldata, string calldata) external returns (address[] memory);
84
-
85
- function envBytes32(string calldata, string calldata) external returns (bytes32[] memory);
86
-
87
- function envString(string calldata, string calldata) external returns (string[] memory);
88
-
89
- function envBytes(string calldata, string calldata) external returns (bytes[] memory);
90
-
91
- // Sets the *next* call's msg.sender to be the input address
92
- function prank(address) external;
93
-
94
- // Sets all subsequent calls' msg.sender to be the input address until `stopPrank` is called
95
- function startPrank(address) external;
96
-
97
- // Sets the *next* call's msg.sender to be the input address, and the tx.origin to be the second input
98
- function prank(address, address) external;
99
-
100
- // Sets all subsequent calls' msg.sender to be the input address until `stopPrank` is called, and the tx.origin to be the second input
101
- function startPrank(address, address) external;
102
-
103
- // Resets subsequent calls' msg.sender to be `address(this)`
104
- function stopPrank() external;
105
-
106
- // Sets an address' balance, (who, newBalance)
107
- function deal(address, uint256) external;
108
-
109
- // Sets an address' code, (who, newCode)
110
- function etch(address, bytes calldata) external;
111
-
112
- // Expects an error on next call
113
- function expectRevert() external;
114
-
115
- function expectRevert(bytes calldata) external;
116
-
117
- function expectRevert(bytes4) external;
118
-
119
- // Record all storage reads and writes
120
- function record() external;
121
-
122
- // Gets all accessed reads and write slot from a recording session, for a given address
123
- function accesses(address) external returns (bytes32[] memory reads, bytes32[] memory writes);
124
-
125
- // Record all the transaction logs
126
- function recordLogs() external;
127
-
128
- // Gets all the recorded logs
129
- function getRecordedLogs() external returns (Log[] memory);
130
-
131
- // Prepare an expected log with (bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData).
132
- // Call this function, then emit an event, then call a function. Internally after the call, we check if
133
- // logs were emitted in the expected order with the expected topics and data (as specified by the booleans).
134
- // Second form also checks supplied address against emitting contract.
135
- function expectEmit(
136
- bool,
137
- bool,
138
- bool,
139
- bool
140
- ) external;
141
-
142
- function expectEmit(
143
- bool,
144
- bool,
145
- bool,
146
- bool,
147
- address
148
- ) external;
149
-
150
- // Mocks a call to an address, returning specified data.
151
- // Calldata can either be strict or a partial match, e.g. if you only
152
- // pass a Solidity selector to the expected calldata, then the entire Solidity
153
- // function will be mocked.
154
- function mockCall(
155
- address,
156
- bytes calldata,
157
- bytes calldata
158
- ) external;
159
-
160
- // Mocks a call to an address with a specific msg.value, returning specified data.
161
- // Calldata match takes precedence over msg.value in case of ambiguity.
162
- function mockCall(
163
- address,
164
- uint256,
165
- bytes calldata,
166
- bytes calldata
167
- ) external;
168
-
169
- // Clears all mocked calls
170
- function clearMockedCalls() external;
171
-
172
- // Expect a call to an address with the specified calldata.
173
- // Calldata can either be strict or a partial match
174
- function expectCall(address, bytes calldata) external;
175
-
176
- // Expect a call to an address with the specified msg.value and calldata
177
- function expectCall(
178
- address,
179
- uint256,
180
- bytes calldata
181
- ) external;
182
-
183
- // Gets the code from an artifact file. Takes in the relative path to the json file
184
- function getCode(string calldata) external returns (bytes memory);
185
-
186
- // Labels an address in call traces
187
- function label(address, string calldata) external;
188
-
189
- // If the condition is false, discard this run's fuzz inputs and generate new ones
190
- function assume(bool) external;
191
-
192
- // Set nonce for an account
193
- function setNonce(address, uint64) external;
194
-
195
- // Get nonce for an account
196
- function getNonce(address) external returns (uint64);
197
-
198
- // Set block.chainid (newChainId)
199
- function chainId(uint256) external;
200
-
201
- // Using the address that calls the test contract, has the next call (at this call depth only) create a transaction that can later be signed and sent onchain
202
- function broadcast() external;
203
-
204
- // Has the next call (at this call depth only) create a transaction with the address provided as the sender that can later be signed and sent onchain
205
- function broadcast(address) external;
206
-
207
- // Using the address that calls the test contract, has the all subsequent calls (at this call depth only) create transactions that can later be signed and sent onchain
208
- function startBroadcast() external;
209
-
210
- // Has the all subsequent calls (at this call depth only) create transactions that can later be signed and sent onchain
211
- function startBroadcast(address) external;
212
-
213
- // Stops collecting onchain transactions
214
- function stopBroadcast() external;
215
-
216
- // Reads the entire content of file to string. Path is relative to the project root. (path) => (data)
217
- function readFile(string calldata) external returns (string memory);
218
-
219
- // Reads next line of file to string, (path) => (line)
220
- function readLine(string calldata) external returns (string memory);
221
-
222
- // Writes data to file, creating a file if it does not exist, and entirely replacing its contents if it does.
223
- // Path is relative to the project root. (path, data) => ()
224
- function writeFile(string calldata, string calldata) external;
225
-
226
- // Writes line to file, creating a file if it does not exist.
227
- // Path is relative to the project root. (path, data) => ()
228
- function writeLine(string calldata, string calldata) external;
229
-
230
- // Closes file for reading, resetting the offset and allowing to read it from beginning with readLine.
231
- // Path is relative to the project root. (path) => ()
232
- function closeFile(string calldata) external;
233
-
234
- // Removes file. This cheatcode will revert in the following situations, but is not limited to just these cases:
235
- // - Path points to a directory.
236
- // - The file doesn't exist.
237
- // - The user lacks permissions to remove the file.
238
- // Path is relative to the project root. (path) => ()
239
- function removeFile(string calldata) external;
240
-
241
- function toString(address) external returns (string memory);
242
-
243
- function toString(bytes calldata) external returns (string memory);
244
-
245
- function toString(bytes32) external returns (string memory);
246
-
247
- function toString(bool) external returns (string memory);
248
-
249
- function toString(uint256) external returns (string memory);
250
-
251
- function toString(int256) external returns (string memory);
252
-
253
- // Snapshot the current state of the evm.
254
- // Returns the id of the snapshot that was created.
255
- // To revert a snapshot use `revertTo`
256
- function snapshot() external returns (uint256);
257
-
258
- // Revert the state of the evm to a previous snapshot
259
- // Takes the snapshot id to revert to.
260
- // This deletes the snapshot and all snapshots taken after the given snapshot id.
261
- function revertTo(uint256) external returns (bool);
262
-
263
- // Creates a new fork with the given endpoint and block and returns the identifier of the fork
264
- function createFork(string calldata, uint256) external returns (uint256);
265
-
266
- // Creates a new fork with the given endpoint and the _latest_ block and returns the identifier of the fork
267
- function createFork(string calldata) external returns (uint256);
268
-
269
- // Creates _and_ also selects a new fork with the given endpoint and block and returns the identifier of the fork
270
- function createSelectFork(string calldata, uint256) external returns (uint256);
271
-
272
- // Creates _and_ also selects a new fork with the given endpoint and the latest block and returns the identifier of the fork
273
- function createSelectFork(string calldata) external returns (uint256);
274
-
275
- // Takes a fork identifier created by `createFork` and sets the corresponding forked state as active.
276
- function selectFork(uint256) external;
277
-
278
- // Returns the currently active fork
279
- // Reverts if no fork is currently active
280
- function activeFork() external returns (uint256);
281
-
282
- // Marks that the account(s) should use persistent storage across fork swaps.
283
- // Meaning, changes made to the state of this account will be kept when switching forks
284
- function makePersistent(address) external;
285
-
286
- function makePersistent(address, address) external;
287
-
288
- function makePersistent(
289
- address,
290
- address,
291
- address
292
- ) external;
293
-
294
- function makePersistent(address[] calldata) external;
295
-
296
- // Revokes persistent status from the address, previously added via `makePersistent`
297
- function revokePersistent(address) external;
298
-
299
- function revokePersistent(address[] calldata) external;
300
-
301
- // Returns true if the account is marked as persistent
302
- function isPersistent(address) external returns (bool);
303
-
304
- // Updates the currently active fork to given block number
305
- // This is similar to `roll` but for the currently active fork
306
- function rollFork(uint256) external;
307
-
308
- // Updates the given fork to given block number
309
- function rollFork(uint256 forkId, uint256 blockNumber) external;
310
-
311
- /// Returns the RPC url for the given alias
312
- function rpcUrl(string calldata) external returns (string memory);
313
-
314
- /// Returns all rpc urls and their aliases `[alias, url][]`
315
- function rpcUrls() external returns (string[2][] memory);
316
-
317
- function parseJson(string calldata, string calldata) external returns (bytes memory);
318
-
319
- function parseJson(string calldata) external returns (bytes memory);
320
- }