@latticexyz/cli 2.0.0-alpha.49 → 2.0.0-alpha.5
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-6V563IAZ.js +283 -0
- package/dist/{chunk-ATAWDHWC.js → chunk-FPG73MVN.js} +5 -1
- package/dist/chunk-KJTPZOUH.js +3864 -0
- package/dist/{chunk-O6HOO6WA.js → chunk-L4YLJHLJ.js} +1 -9
- package/dist/{chunk-KPBNUPK6.js → chunk-SKNB74MT.js} +155 -159
- package/dist/chunk-VQTZJIFF.js +353 -0
- package/dist/{chunk-MXDV47JM.js → chunk-WZFXLDPK.js} +75 -24
- package/dist/chunk-YL4GJLLL.js +26139 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.js +0 -22
- package/dist/mud.d.ts +1 -1
- package/dist/mud.js +319 -3971
- package/dist/mud2.d.ts +1 -0
- package/dist/mud2.js +25 -0
- package/dist/render-solidity/index.d.ts +3 -3
- package/dist/render-solidity/index.js +3 -4
- package/dist/render-ts/index.d.ts +2 -3
- package/dist/render-ts/index.js +3 -4
- package/dist/utils/deprecated/index.js +3 -3
- package/dist/utils/index.d.ts +9 -19
- package/dist/utils/index.js +7 -18
- package/package.json +19 -20
- package/src/commands/deploy-v2.ts +80 -64
- package/src/commands/deprecated/index.ts +22 -0
- package/src/commands/deprecated/test.ts +1 -1
- package/src/commands/gas-report.ts +54 -55
- package/src/commands/index.ts +2 -17
- package/src/commands/set-version.ts +39 -10
- package/src/commands/tablegen.ts +5 -5
- package/src/commands/test-v2.ts +71 -0
- package/src/commands/tsgen.ts +1 -1
- package/src/commands/worldgen.ts +5 -4
- package/src/contracts/BulkUpload.sol +13 -20
- package/src/contracts/Deploy.sol +3 -3
- package/src/contracts/LibDeploy.sol +1 -1
- package/src/contracts/LibDeployStub.sol +1 -1
- package/src/index.ts +1 -15
- package/src/mud.ts +4 -3
- package/src/mud2.ts +29 -0
- package/src/render-solidity/common.ts +4 -4
- package/src/render-solidity/field.ts +25 -2
- package/src/render-solidity/record.ts +14 -10
- package/src/render-solidity/renderSystemInterface.ts +4 -4
- package/src/render-solidity/renderTableIndex.ts +15 -0
- package/src/render-solidity/renderTypesFromConfig.ts +1 -1
- package/src/render-solidity/tableOptions.ts +2 -2
- package/src/render-solidity/tablegen.ts +13 -1
- package/src/render-solidity/types.ts +2 -1
- package/src/render-solidity/userType.ts +1 -2
- package/src/render-solidity/worldgen.ts +3 -3
- package/src/render-ts/recsV1TableOptions.ts +2 -2
- package/src/render-ts/renderRecsV1Tables.ts +2 -2
- package/src/render-ts/schemaTypesToRecsTypeStrings.ts +136 -136
- package/src/render-ts/tsgen.ts +1 -1
- package/src/render-ts/types.ts +1 -1
- package/src/utils/contractToInterface.ts +5 -3
- package/src/utils/deploy-v2.ts +85 -78
- package/src/utils/errors.ts +3 -34
- package/src/utils/foundry.ts +9 -0
- package/dist/chunk-5NC2OON2.js +0 -164
- package/dist/chunk-7GA2K5A6.js +0 -283
- package/dist/chunk-LPWKZQUI.js +0 -454
- package/dist/chunk-Q7D3SKYJ.js +0 -22908
- package/dist/chunk-SLIMIO4Z.js +0 -14358
- package/dist/config/index.d.ts +0 -408
- package/dist/config/index.js +0 -85
- package/dist/parseStoreConfig-899f574e.d.ts +0 -369
- package/src/config/commonSchemas.ts +0 -34
- package/src/config/dynamicResolution.ts +0 -49
- package/src/config/index.ts +0 -24
- package/src/config/loadConfig.ts +0 -39
- package/src/config/loadStoreConfig.ts +0 -18
- package/src/config/parseStoreConfig.test-d.ts +0 -40
- package/src/config/parseStoreConfig.ts +0 -314
- package/src/config/validation.ts +0 -163
- package/src/config/world/index.ts +0 -4
- package/src/config/world/loadWorldConfig.test-d.ts +0 -11
- package/src/config/world/loadWorldConfig.ts +0 -26
- package/src/config/world/parseWorldConfig.ts +0 -56
- package/src/config/world/resolveWorldConfig.ts +0 -80
- package/src/config/world/userTypes.ts +0 -74
- package/src/utils/typeUtils.ts +0 -17
package/src/utils/deploy-v2.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { MUDConfig, resolveWithContext } from "
|
|
4
|
-
import { MUDError } from "
|
|
3
|
+
import { MUDConfig, resolveWithContext } from "@latticexyz/config";
|
|
4
|
+
import { MUDError } from "@latticexyz/config";
|
|
5
5
|
import { getOutDirectory, getScriptDirectory, cast, forge } from "./foundry.js";
|
|
6
6
|
import { BigNumber, ContractInterface, ethers } from "ethers";
|
|
7
7
|
import { IBaseWorld } from "@latticexyz/world/types/ethers-contracts/IBaseWorld.js";
|
|
@@ -15,6 +15,7 @@ import IBaseWorldData from "@latticexyz/world/abi/IBaseWorld.json" assert { type
|
|
|
15
15
|
import CoreModuleData from "@latticexyz/world/abi/CoreModule.json" assert { type: "json" };
|
|
16
16
|
import RegistrationModuleData from "@latticexyz/world/abi/RegistrationModule.json" assert { type: "json" };
|
|
17
17
|
import KeysWithValueModuleData from "@latticexyz/world/abi/KeysWithValueModule.json" assert { type: "json" };
|
|
18
|
+
import UniqueEntityModuleData from "@latticexyz/world/abi/UniqueEntityModule.json" assert { type: "json" };
|
|
18
19
|
|
|
19
20
|
export interface DeployConfig {
|
|
20
21
|
profile?: string;
|
|
@@ -22,6 +23,7 @@ export interface DeployConfig {
|
|
|
22
23
|
privateKey: string;
|
|
23
24
|
priorityFeeMultiplier: number;
|
|
24
25
|
debug?: boolean;
|
|
26
|
+
worldAddress?: string;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export interface DeploymentInfo {
|
|
@@ -32,7 +34,7 @@ export interface DeploymentInfo {
|
|
|
32
34
|
export async function deploy(mudConfig: MUDConfig, deployConfig: DeployConfig): Promise<DeploymentInfo> {
|
|
33
35
|
const startTime = Date.now();
|
|
34
36
|
const { worldContractName, namespace, postDeployScript } = mudConfig;
|
|
35
|
-
const { profile, rpc, privateKey, priorityFeeMultiplier, debug } = deployConfig;
|
|
37
|
+
const { profile, rpc, privateKey, priorityFeeMultiplier, debug, worldAddress } = deployConfig;
|
|
36
38
|
const forgeOutDirectory = await getOutDirectory(profile);
|
|
37
39
|
|
|
38
40
|
// Set up signer for deployment
|
|
@@ -57,7 +59,9 @@ export async function deploy(mudConfig: MUDConfig, deployConfig: DeployConfig):
|
|
|
57
59
|
|
|
58
60
|
// Deploy World
|
|
59
61
|
const worldPromise = {
|
|
60
|
-
World:
|
|
62
|
+
World: worldAddress
|
|
63
|
+
? Promise.resolve(worldAddress)
|
|
64
|
+
: worldContractName
|
|
61
65
|
? deployContractByName(worldContractName)
|
|
62
66
|
: deployContract(IBaseWorldData.abi, WorldData.bytecode, "World"),
|
|
63
67
|
};
|
|
@@ -82,6 +86,11 @@ export async function deploy(mudConfig: MUDConfig, deployConfig: DeployConfig):
|
|
|
82
86
|
KeysWithValueModuleData.bytecode,
|
|
83
87
|
"KeysWithValueModule"
|
|
84
88
|
),
|
|
89
|
+
UniqueEntityModule: deployContract(
|
|
90
|
+
UniqueEntityModuleData.abi,
|
|
91
|
+
UniqueEntityModuleData.bytecode,
|
|
92
|
+
"UniqueEntityModule"
|
|
93
|
+
),
|
|
85
94
|
};
|
|
86
95
|
|
|
87
96
|
// Deploy user Modules
|
|
@@ -99,10 +108,12 @@ export async function deploy(mudConfig: MUDConfig, deployConfig: DeployConfig):
|
|
|
99
108
|
const WorldContract = new ethers.Contract(await contractPromises.World, IBaseWorldData.abi, signer) as IBaseWorld;
|
|
100
109
|
|
|
101
110
|
// Install core Modules
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
111
|
+
if (!worldAddress) {
|
|
112
|
+
console.log(chalk.blue("Installing core World modules"));
|
|
113
|
+
await fastTxExecute(WorldContract, "installRootModule", [await modulePromises.CoreModule, "0x"]);
|
|
114
|
+
await fastTxExecute(WorldContract, "installRootModule", [await modulePromises.RegistrationModule, "0x"]);
|
|
115
|
+
console.log(chalk.green("Installed core World modules"));
|
|
116
|
+
}
|
|
106
117
|
|
|
107
118
|
// Register namespace
|
|
108
119
|
if (namespace) await fastTxExecute(WorldContract, "registerNamespace", [toBytes16(namespace)]);
|
|
@@ -111,11 +122,11 @@ export async function deploy(mudConfig: MUDConfig, deployConfig: DeployConfig):
|
|
|
111
122
|
const tableIds: { [tableName: string]: Uint8Array } = {};
|
|
112
123
|
promises = [
|
|
113
124
|
...promises,
|
|
114
|
-
...Object.entries(mudConfig.tables).map(async ([tableName, {
|
|
115
|
-
console.log(chalk.blue(`Registering table ${tableName} at ${namespace}/${
|
|
125
|
+
...Object.entries(mudConfig.tables).map(async ([tableName, { name, schema, primaryKeys }]) => {
|
|
126
|
+
console.log(chalk.blue(`Registering table ${tableName} at ${namespace}/${name}`));
|
|
116
127
|
|
|
117
128
|
// Store the tableId for later use
|
|
118
|
-
tableIds[tableName] = toResourceSelector(namespace,
|
|
129
|
+
tableIds[tableName] = toResourceSelector(namespace, name);
|
|
119
130
|
|
|
120
131
|
// Register table
|
|
121
132
|
const schemaTypes = Object.values(schema).map((abiOrUserType) => {
|
|
@@ -130,7 +141,7 @@ export async function deploy(mudConfig: MUDConfig, deployConfig: DeployConfig):
|
|
|
130
141
|
|
|
131
142
|
await fastTxExecute(WorldContract, "registerTable", [
|
|
132
143
|
toBytes16(namespace),
|
|
133
|
-
toBytes16(
|
|
144
|
+
toBytes16(name),
|
|
134
145
|
encodeSchema(schemaTypes),
|
|
135
146
|
encodeSchema(keyTypes),
|
|
136
147
|
]);
|
|
@@ -138,69 +149,67 @@ export async function deploy(mudConfig: MUDConfig, deployConfig: DeployConfig):
|
|
|
138
149
|
// Register table metadata
|
|
139
150
|
await fastTxExecute(WorldContract, "setMetadata(bytes16,bytes16,string,string[])", [
|
|
140
151
|
toBytes16(namespace),
|
|
141
|
-
toBytes16(
|
|
152
|
+
toBytes16(name),
|
|
142
153
|
tableName,
|
|
143
154
|
Object.keys(schema),
|
|
144
155
|
]);
|
|
145
156
|
|
|
146
|
-
console.log(chalk.green(`Registered table ${tableName} at ${
|
|
157
|
+
console.log(chalk.green(`Registered table ${tableName} at ${name}`));
|
|
147
158
|
}),
|
|
148
159
|
];
|
|
149
160
|
|
|
150
161
|
// Register systems (using forEach instead of for..of to avoid blocking on async calls)
|
|
151
162
|
promises = [
|
|
152
163
|
...promises,
|
|
153
|
-
...Object.entries(mudConfig.systems).map(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
);
|
|
201
|
-
}
|
|
164
|
+
...Object.entries(mudConfig.systems).map(async ([systemName, { name, openAccess, registerFunctionSelectors }]) => {
|
|
165
|
+
// Register system at route
|
|
166
|
+
console.log(chalk.blue(`Registering system ${systemName} at ${namespace}/${name}`));
|
|
167
|
+
await fastTxExecute(WorldContract, "registerSystem", [
|
|
168
|
+
toBytes16(namespace),
|
|
169
|
+
toBytes16(name),
|
|
170
|
+
await contractPromises[systemName],
|
|
171
|
+
openAccess,
|
|
172
|
+
]);
|
|
173
|
+
console.log(chalk.green(`Registered system ${systemName} at ${namespace}/${name}`));
|
|
174
|
+
|
|
175
|
+
// Register function selectors for the system
|
|
176
|
+
if (registerFunctionSelectors) {
|
|
177
|
+
const functionSignatures: FunctionSignature[] = await loadFunctionSignatures(systemName);
|
|
178
|
+
const isRoot = namespace === "";
|
|
179
|
+
// Using Promise.all to avoid blocking on async calls
|
|
180
|
+
await Promise.all(
|
|
181
|
+
functionSignatures.map(async ({ functionName, functionArgs }) => {
|
|
182
|
+
const functionSignature = isRoot
|
|
183
|
+
? functionName + functionArgs
|
|
184
|
+
: `${namespace}_${name}_${functionName}${functionArgs}`;
|
|
185
|
+
|
|
186
|
+
console.log(chalk.blue(`Registering function "${functionSignature}"`));
|
|
187
|
+
if (isRoot) {
|
|
188
|
+
const worldFunctionSelector = toFunctionSelector(
|
|
189
|
+
functionSignature === ""
|
|
190
|
+
? { functionName: systemName, functionArgs } // Register the system's fallback function as `<systemName>(<args>)`
|
|
191
|
+
: { functionName, functionArgs }
|
|
192
|
+
);
|
|
193
|
+
const systemFunctionSelector = toFunctionSelector({ functionName, functionArgs });
|
|
194
|
+
await fastTxExecute(WorldContract, "registerRootFunctionSelector", [
|
|
195
|
+
toBytes16(namespace),
|
|
196
|
+
toBytes16(name),
|
|
197
|
+
worldFunctionSelector,
|
|
198
|
+
systemFunctionSelector,
|
|
199
|
+
]);
|
|
200
|
+
} else {
|
|
201
|
+
await fastTxExecute(WorldContract, "registerFunctionSelector", [
|
|
202
|
+
toBytes16(namespace),
|
|
203
|
+
toBytes16(name),
|
|
204
|
+
functionName,
|
|
205
|
+
functionArgs,
|
|
206
|
+
]);
|
|
207
|
+
}
|
|
208
|
+
console.log(chalk.green(`Registered function "${functionSignature}"`));
|
|
209
|
+
})
|
|
210
|
+
);
|
|
202
211
|
}
|
|
203
|
-
),
|
|
212
|
+
}),
|
|
204
213
|
];
|
|
205
214
|
|
|
206
215
|
// Wait for resources to be registered before granting access to them
|
|
@@ -208,10 +217,8 @@ export async function deploy(mudConfig: MUDConfig, deployConfig: DeployConfig):
|
|
|
208
217
|
promises = [];
|
|
209
218
|
|
|
210
219
|
// Grant access to systems
|
|
211
|
-
for (const [systemName, {
|
|
212
|
-
|
|
213
|
-
)) {
|
|
214
|
-
const resourceSelector = `${namespace}/${fileSelector}`;
|
|
220
|
+
for (const [systemName, { name, accessListAddresses, accessListSystems }] of Object.entries(mudConfig.systems)) {
|
|
221
|
+
const resourceSelector = `${namespace}/${name}`;
|
|
215
222
|
|
|
216
223
|
// Grant access to addresses
|
|
217
224
|
promises = [
|
|
@@ -220,10 +227,10 @@ export async function deploy(mudConfig: MUDConfig, deployConfig: DeployConfig):
|
|
|
220
227
|
console.log(chalk.blue(`Grant ${address} access to ${systemName} (${resourceSelector})`));
|
|
221
228
|
await fastTxExecute(WorldContract, "grantAccess(bytes16,bytes16,address)", [
|
|
222
229
|
toBytes16(namespace),
|
|
223
|
-
toBytes16(
|
|
230
|
+
toBytes16(name),
|
|
224
231
|
address,
|
|
225
232
|
]);
|
|
226
|
-
console.log(chalk.green(`Granted ${address} access to ${systemName} (${namespace}/${
|
|
233
|
+
console.log(chalk.green(`Granted ${address} access to ${systemName} (${namespace}/${name})`));
|
|
227
234
|
}),
|
|
228
235
|
];
|
|
229
236
|
|
|
@@ -234,7 +241,7 @@ export async function deploy(mudConfig: MUDConfig, deployConfig: DeployConfig):
|
|
|
234
241
|
console.log(chalk.blue(`Grant ${granteeSystem} access to ${systemName} (${resourceSelector})`));
|
|
235
242
|
await fastTxExecute(WorldContract, "grantAccess(bytes16,bytes16,address)", [
|
|
236
243
|
toBytes16(namespace),
|
|
237
|
-
toBytes16(
|
|
244
|
+
toBytes16(name),
|
|
238
245
|
await contractPromises[granteeSystem],
|
|
239
246
|
]);
|
|
240
247
|
console.log(chalk.green(`Granted ${granteeSystem} access to ${systemName} (${resourceSelector})`));
|
|
@@ -402,16 +409,16 @@ export async function deploy(mudConfig: MUDConfig, deployConfig: DeployConfig):
|
|
|
402
409
|
contract: C,
|
|
403
410
|
func: F,
|
|
404
411
|
args: Parameters<C[F]>,
|
|
405
|
-
retryCount = 0
|
|
406
|
-
|
|
412
|
+
retryCount = 0,
|
|
413
|
+
confirmations = 1
|
|
414
|
+
): Promise<Awaited<ReturnType<Awaited<ReturnType<C[F]>>["wait"]>>> {
|
|
407
415
|
const functionName = `${func as string}(${args.map((arg) => `'${arg}'`).join(",")})`;
|
|
408
416
|
try {
|
|
409
417
|
const gasLimit = await contract.estimateGas[func].apply(null, args);
|
|
410
418
|
console.log(chalk.gray(`executing transaction: ${functionName} with nonce ${nonce}`));
|
|
411
|
-
const txPromise = contract[func]
|
|
412
|
-
...args,
|
|
413
|
-
|
|
414
|
-
]);
|
|
419
|
+
const txPromise = contract[func]
|
|
420
|
+
.apply(null, [...args, { gasLimit, nonce: nonce++, maxPriorityFeePerGas, maxFeePerGas }])
|
|
421
|
+
.then((tx: any) => tx.wait(confirmations));
|
|
415
422
|
promises.push(txPromise);
|
|
416
423
|
return txPromise;
|
|
417
424
|
} catch (error: any) {
|
|
@@ -420,7 +427,7 @@ export async function deploy(mudConfig: MUDConfig, deployConfig: DeployConfig):
|
|
|
420
427
|
// If the deployment failed because the transaction was already imported,
|
|
421
428
|
// retry with a higher priority fee
|
|
422
429
|
setInternalFeePerGas(priorityFeeMultiplier * 1.1);
|
|
423
|
-
return fastTxExecute(contract, func, args, retryCount
|
|
430
|
+
return fastTxExecute(contract, func, args, retryCount++, confirmations);
|
|
424
431
|
} else throw new MUDError(`Gas estimation error for ${functionName}: ${error?.reason}`);
|
|
425
432
|
}
|
|
426
433
|
}
|
package/src/utils/errors.ts
CHANGED
|
@@ -1,33 +1,8 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import {
|
|
2
|
+
import { ZodError } from "zod";
|
|
3
3
|
import { fromZodError, ValidationError } from "zod-validation-error";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export function fromZodErrorCustom(error: ZodError, prefix: string) {
|
|
7
|
-
return fromZodError(error, {
|
|
8
|
-
prefix: chalk.red(prefix),
|
|
9
|
-
prefixSeparator: "\n- ",
|
|
10
|
-
issueSeparator: "\n- ",
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class NotInsideProjectError extends Error {
|
|
15
|
-
name = "NotInsideProjectError";
|
|
16
|
-
message = "You are not inside a MUD project";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class NotESMConfigError extends Error {
|
|
20
|
-
name = "NotESMConfigError";
|
|
21
|
-
message = "MUD config must be an ES module";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class MUDError extends Error {
|
|
25
|
-
name = "MUDError";
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function UnrecognizedSystemErrorFactory(path: string[], systemName: string) {
|
|
29
|
-
return new z.ZodError([{ code: ZodIssueCode.custom, path: path, message: `Unrecognized system: "${systemName}"` }]);
|
|
30
|
-
}
|
|
4
|
+
import { NotInsideProjectError } from "@latticexyz/config";
|
|
5
|
+
import { MUDError } from "@latticexyz/config";
|
|
31
6
|
|
|
32
7
|
export function logError(error: unknown) {
|
|
33
8
|
if (error instanceof ValidationError) {
|
|
@@ -46,12 +21,6 @@ export function logError(error: unknown) {
|
|
|
46
21
|
// TODO add docs to the website and update the link to the specific page
|
|
47
22
|
// (see https://github.com/latticexyz/mud/issues/445)
|
|
48
23
|
console.log(chalk.blue(`To learn more about MUD's configuration, please go to https://mud.dev/packages/cli/`));
|
|
49
|
-
} else if (error instanceof NotESMConfigError) {
|
|
50
|
-
console.log(chalk.red(error.message));
|
|
51
|
-
console.log("");
|
|
52
|
-
console.log(
|
|
53
|
-
chalk.blue(`Please name your config file \`mud.config.mts\`, or use \`type: "module"\` in package.json`)
|
|
54
|
-
);
|
|
55
24
|
} else if (error instanceof MUDError) {
|
|
56
25
|
console.log(chalk.red(error));
|
|
57
26
|
} else {
|
package/src/utils/foundry.ts
CHANGED
|
@@ -92,3 +92,12 @@ export async function cast(args: string[], options?: { profile?: string }): Prom
|
|
|
92
92
|
env: { FOUNDRY_PROFILE: options?.profile },
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Start an anvil chain
|
|
98
|
+
* @param args The arguments to pass to anvil
|
|
99
|
+
* @returns Stdout of the command
|
|
100
|
+
*/
|
|
101
|
+
export async function anvil(args: string[]): Promise<string> {
|
|
102
|
+
return execLog("anvil", args);
|
|
103
|
+
}
|
package/dist/chunk-5NC2OON2.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AbiTypeToSchemaType,
|
|
3
|
-
SchemaType,
|
|
4
|
-
SchemaTypeToAbiType,
|
|
5
|
-
getStaticByteLength,
|
|
6
|
-
parseStaticArray
|
|
7
|
-
} from "./chunk-KPBNUPK6.js";
|
|
8
|
-
|
|
9
|
-
// src/render-solidity/userType.ts
|
|
10
|
-
function resolveAbiOrUserType(abiOrUserType, config) {
|
|
11
|
-
if (abiOrUserType in AbiTypeToSchemaType) {
|
|
12
|
-
const schemaType = AbiTypeToSchemaType[abiOrUserType];
|
|
13
|
-
return {
|
|
14
|
-
schemaType,
|
|
15
|
-
renderTableType: getSchemaTypeInfo(schemaType)
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
const staticArray = parseStaticArray(abiOrUserType);
|
|
19
|
-
if (staticArray) {
|
|
20
|
-
if (staticArray.elementType in AbiTypeToSchemaType) {
|
|
21
|
-
return getStaticArrayTypeInfo(abiOrUserType, staticArray.elementType, staticArray.staticLength);
|
|
22
|
-
} else {
|
|
23
|
-
throw new Error("Static arrays of user types are not supported");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return getUserTypeInfo(abiOrUserType, config);
|
|
27
|
-
}
|
|
28
|
-
function importForAbiOrUserType(abiOrUserType, usedInDirectory, config) {
|
|
29
|
-
if (abiOrUserType in AbiTypeToSchemaType) {
|
|
30
|
-
return void 0;
|
|
31
|
-
}
|
|
32
|
-
const staticArray = parseStaticArray(abiOrUserType);
|
|
33
|
-
if (staticArray) {
|
|
34
|
-
return void 0;
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
symbol: abiOrUserType,
|
|
38
|
-
fromPath: config.userTypesPath + ".sol",
|
|
39
|
-
usedInPath: usedInDirectory
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function getSchemaTypeInfo(schemaType) {
|
|
43
|
-
const staticByteLength = getStaticByteLength(schemaType);
|
|
44
|
-
const isDynamic = staticByteLength === 0;
|
|
45
|
-
const typeId = SchemaTypeToAbiType[schemaType];
|
|
46
|
-
return {
|
|
47
|
-
typeId,
|
|
48
|
-
typeWithLocation: isDynamic ? typeId + " memory" : typeId,
|
|
49
|
-
enumName: SchemaType[schemaType],
|
|
50
|
-
staticByteLength,
|
|
51
|
-
isDynamic,
|
|
52
|
-
typeWrap: "",
|
|
53
|
-
typeUnwrap: "",
|
|
54
|
-
internalTypeId: typeId
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function getUserTypeInfo(userType, config) {
|
|
58
|
-
if (userType in config.enums) {
|
|
59
|
-
const schemaType = 0 /* UINT8 */;
|
|
60
|
-
const staticByteLength = getStaticByteLength(schemaType);
|
|
61
|
-
const isDynamic = staticByteLength === 0;
|
|
62
|
-
const typeId = userType;
|
|
63
|
-
return {
|
|
64
|
-
schemaType,
|
|
65
|
-
renderTableType: {
|
|
66
|
-
typeId,
|
|
67
|
-
typeWithLocation: typeId,
|
|
68
|
-
enumName: SchemaType[schemaType],
|
|
69
|
-
staticByteLength,
|
|
70
|
-
isDynamic,
|
|
71
|
-
typeWrap: `${userType}`,
|
|
72
|
-
typeUnwrap: `uint8`,
|
|
73
|
-
internalTypeId: `${SchemaTypeToAbiType[schemaType]}`
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
throw new Error(`User type "${userType}" does not exist`);
|
|
78
|
-
}
|
|
79
|
-
function getStaticArrayTypeInfo(abiType, elementType, staticLength) {
|
|
80
|
-
const internalTypeId = elementType + "[]";
|
|
81
|
-
const schemaType = AbiTypeToSchemaType[internalTypeId];
|
|
82
|
-
return {
|
|
83
|
-
schemaType,
|
|
84
|
-
renderTableType: {
|
|
85
|
-
typeId: abiType,
|
|
86
|
-
typeWithLocation: `${abiType} memory`,
|
|
87
|
-
enumName: SchemaType[schemaType],
|
|
88
|
-
staticByteLength: 0,
|
|
89
|
-
isDynamic: true,
|
|
90
|
-
typeWrap: `toStaticArray_${elementType}_${staticLength}`,
|
|
91
|
-
typeUnwrap: `fromStaticArray_${elementType}_${staticLength}`,
|
|
92
|
-
typeWrappingData: {
|
|
93
|
-
kind: "staticArray",
|
|
94
|
-
elementType,
|
|
95
|
-
staticLength
|
|
96
|
-
},
|
|
97
|
-
internalTypeId
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// src/utils/format.ts
|
|
103
|
-
import chalk from "chalk";
|
|
104
|
-
import prettier from "prettier";
|
|
105
|
-
import prettierPluginSolidity from "prettier-plugin-solidity";
|
|
106
|
-
async function formatSolidity(content, prettierConfigPath) {
|
|
107
|
-
let config;
|
|
108
|
-
if (prettierConfigPath) {
|
|
109
|
-
config = await prettier.resolveConfig(prettierConfigPath);
|
|
110
|
-
}
|
|
111
|
-
try {
|
|
112
|
-
return prettier.format(content, {
|
|
113
|
-
plugins: [prettierPluginSolidity],
|
|
114
|
-
parser: "solidity-parse",
|
|
115
|
-
printWidth: 120,
|
|
116
|
-
semi: true,
|
|
117
|
-
tabWidth: 2,
|
|
118
|
-
useTabs: false,
|
|
119
|
-
bracketSpacing: true,
|
|
120
|
-
...config
|
|
121
|
-
});
|
|
122
|
-
} catch (error) {
|
|
123
|
-
let message;
|
|
124
|
-
if (error instanceof Error) {
|
|
125
|
-
message = error.message;
|
|
126
|
-
} else {
|
|
127
|
-
message = error;
|
|
128
|
-
}
|
|
129
|
-
console.log(chalk.yellow(`Error during output formatting: ${message}`));
|
|
130
|
-
return content;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
async function formatTypescript(content) {
|
|
134
|
-
return prettier.format(content, {
|
|
135
|
-
parser: "typescript"
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// src/utils/formatAndWrite.ts
|
|
140
|
-
import { mkdirSync, writeFileSync } from "fs";
|
|
141
|
-
import { dirname } from "path";
|
|
142
|
-
async function formatAndWriteSolidity(output, fullOutputPath, logPrefix) {
|
|
143
|
-
const formattedOutput = await formatSolidity(output);
|
|
144
|
-
mkdirSync(dirname(fullOutputPath), { recursive: true });
|
|
145
|
-
writeFileSync(fullOutputPath, formattedOutput);
|
|
146
|
-
console.log(`${logPrefix}: ${fullOutputPath}`);
|
|
147
|
-
}
|
|
148
|
-
async function formatAndWriteTypescript(output, fullOutputPath, logPrefix) {
|
|
149
|
-
const formattedOutput = await formatTypescript(output);
|
|
150
|
-
mkdirSync(dirname(fullOutputPath), { recursive: true });
|
|
151
|
-
writeFileSync(fullOutputPath, formattedOutput);
|
|
152
|
-
console.log(`${logPrefix}: ${fullOutputPath}`);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export {
|
|
156
|
-
resolveAbiOrUserType,
|
|
157
|
-
importForAbiOrUserType,
|
|
158
|
-
getSchemaTypeInfo,
|
|
159
|
-
getUserTypeInfo,
|
|
160
|
-
formatSolidity,
|
|
161
|
-
formatTypescript,
|
|
162
|
-
formatAndWriteSolidity,
|
|
163
|
-
formatAndWriteTypescript
|
|
164
|
-
};
|