@latticexyz/cli 2.0.0-alpha.93 → 2.0.0-foundry-js-c7b0289b
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-UYAATBY6.js +27 -0
- package/dist/commands-UYAATBY6.js.map +1 -0
- package/dist/errors-XGN6V2Y3.js +2 -0
- package/dist/errors-XGN6V2Y3.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/mud.js +2 -8340
- package/dist/mud.js.map +1 -0
- package/package.json +54 -46
- package/src/commands/deploy.ts +26 -0
- package/src/commands/dev-contracts.ts +114 -0
- package/src/commands/devnode.ts +7 -2
- package/src/commands/faucet.ts +1 -1
- package/src/commands/index.ts +19 -14
- package/src/commands/set-version.ts +103 -81
- package/src/commands/tablegen.ts +7 -5
- package/src/commands/test.ts +65 -0
- package/src/commands/trace.ts +118 -0
- package/src/commands/worldgen.ts +29 -28
- package/src/common.ts +1 -0
- package/src/debug.ts +3 -0
- package/src/deploy/assertNamespaceOwner.ts +42 -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 +3 -0
- package/src/deploy/deploy.ts +108 -0
- package/src/deploy/deployWorld.ts +33 -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/ensureSystems.ts +162 -0
- package/src/deploy/ensureTables.ts +65 -0
- package/src/deploy/ensureWorldFactory.ts +47 -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/modules.d.ts +11 -0
- package/src/mud.ts +38 -23
- package/src/mudPackages.ts +24 -0
- package/src/runDeploy.ts +128 -0
- package/src/utils/errors.ts +1 -1
- package/src/utils/getExistingContracts.ts +12 -0
- package/src/utils/modules/constants.ts +26 -0
- package/src/utils/printMUD.ts +14 -0
- package/src/utils/utils/getContractData.ts +32 -0
- package/src/utils/utils/postDeploy.ts +25 -0
- package/dist/chunk-6V563IAZ.js +0 -283
- package/dist/chunk-FPG73MVN.js +0 -71
- package/dist/chunk-L4YLJHLJ.js +0 -30
- package/dist/chunk-P5YXGXRI.js +0 -3842
- package/dist/chunk-SKNB74MT.js +0 -726
- package/dist/chunk-VQTZJIFF.js +0 -353
- package/dist/chunk-WZFXLDPK.js +0 -761
- package/dist/chunk-YL4GJLLL.js +0 -26139
- package/dist/index.d.ts +0 -2
- package/dist/mud.d.ts +0 -1
- package/dist/mud2.d.ts +0 -1
- package/dist/mud2.js +0 -25
- package/dist/render-solidity/index.d.ts +0 -171
- package/dist/render-solidity/index.js +0 -49
- package/dist/render-ts/index.d.ts +0 -26
- package/dist/render-ts/index.js +0 -14
- package/dist/utils/deprecated/index.d.ts +0 -76
- package/dist/utils/deprecated/index.js +0 -36
- package/dist/utils/index.d.ts +0 -88
- package/dist/utils/index.js +0 -39
- package/src/commands/deploy-v2.ts +0 -112
- package/src/commands/deprecated/bulkupload.ts +0 -50
- package/src/commands/deprecated/call-system.ts +0 -70
- package/src/commands/deprecated/codegen-libdeploy.ts +0 -29
- package/src/commands/deprecated/deploy-contracts.ts +0 -120
- package/src/commands/deprecated/index.ts +0 -22
- package/src/commands/deprecated/system-types.ts +0 -29
- package/src/commands/deprecated/test.ts +0 -53
- package/src/commands/deprecated/trace.ts +0 -81
- package/src/commands/deprecated/types.ts +0 -33
- package/src/commands/gas-report.ts +0 -219
- package/src/commands/test-v2.ts +0 -71
- package/src/commands/tsgen.ts +0 -33
- package/src/contracts/BulkUpload.sol +0 -174
- package/src/contracts/Deploy.sol +0 -23
- package/src/contracts/LibDeploy.ejs +0 -121
- package/src/contracts/LibDeploy.sol +0 -23
- package/src/contracts/LibDeployStub.sol +0 -23
- package/src/mud2.ts +0 -29
- package/src/render-solidity/common.ts +0 -138
- package/src/render-solidity/field.ts +0 -160
- package/src/render-solidity/index.ts +0 -10
- package/src/render-solidity/record.ts +0 -158
- package/src/render-solidity/renderSystemInterface.ts +0 -31
- package/src/render-solidity/renderTable.ts +0 -164
- package/src/render-solidity/renderTableIndex.ts +0 -15
- package/src/render-solidity/renderTypeHelpers.ts +0 -99
- package/src/render-solidity/renderTypes.ts +0 -19
- package/src/render-solidity/renderTypesFromConfig.ts +0 -13
- package/src/render-solidity/renderWorld.ts +0 -24
- package/src/render-solidity/tableOptions.ts +0 -107
- package/src/render-solidity/tablegen.ts +0 -35
- package/src/render-solidity/types.ts +0 -111
- package/src/render-solidity/userType.ts +0 -131
- package/src/render-solidity/worldgen.ts +0 -59
- package/src/render-ts/index.ts +0 -5
- package/src/render-ts/recsV1TableOptions.ts +0 -39
- package/src/render-ts/renderRecsV1Tables.ts +0 -31
- package/src/render-ts/schemaTypesToRecsTypeStrings.ts +0 -202
- package/src/render-ts/tsgen.ts +0 -12
- package/src/render-ts/types.ts +0 -13
- package/src/utils/contractToInterface.ts +0 -132
- package/src/utils/deploy-v2.ts +0 -518
- package/src/utils/deprecated/build.ts +0 -55
- package/src/utils/deprecated/codegen.ts +0 -42
- package/src/utils/deprecated/constants.ts +0 -2
- package/src/utils/deprecated/deploy.ts +0 -111
- package/src/utils/deprecated/exec.ts +0 -18
- package/src/utils/deprecated/findLog.ts +0 -8
- package/src/utils/deprecated/hsr.ts +0 -71
- package/src/utils/deprecated/ids.ts +0 -14
- package/src/utils/deprecated/index.ts +0 -8
- package/src/utils/deprecated/typegen.ts +0 -133
- package/src/utils/execLog.ts +0 -22
- package/src/utils/format.ts +0 -39
- package/src/utils/formatAndWrite.ts +0 -21
- package/src/utils/foundry.ts +0 -103
- package/src/utils/getChainId.ts +0 -10
- package/src/utils/index.ts +0 -5
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { renderList, renderedSolidityHeader } from "./common.js";
|
|
2
|
-
import { TableOptions } from "./tableOptions.js";
|
|
3
|
-
|
|
4
|
-
export function renderTableIndex(options: TableOptions[]) {
|
|
5
|
-
return `${renderedSolidityHeader}
|
|
6
|
-
|
|
7
|
-
${renderList(options, ({ outputPath, tableName, renderOptions: { structName, staticResourceData } }) => {
|
|
8
|
-
const imports = [tableName];
|
|
9
|
-
if (structName) imports.push(structName);
|
|
10
|
-
if (staticResourceData) imports.push(`${tableName}TableId`);
|
|
11
|
-
|
|
12
|
-
return `import { ${imports.join(", ")} } from "./${outputPath}";`;
|
|
13
|
-
})}
|
|
14
|
-
`;
|
|
15
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { RenderTableOptions, RenderTableType } from "./types.js";
|
|
2
|
-
|
|
3
|
-
export function renderTypeHelpers(options: RenderTableOptions) {
|
|
4
|
-
const { fields, primaryKeys } = options;
|
|
5
|
-
|
|
6
|
-
let result = "";
|
|
7
|
-
|
|
8
|
-
for (const wrappingHelper of getWrappingHelpers([...fields, ...primaryKeys])) {
|
|
9
|
-
result += wrappingHelper;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// bool is special - it's the only primitive value type that can't be typecasted to/from
|
|
13
|
-
if (fields.some(({ typeId }) => typeId === "bool")) {
|
|
14
|
-
result += `
|
|
15
|
-
function _toBool(uint8 value) pure returns (bool result) {
|
|
16
|
-
assembly {
|
|
17
|
-
result := value
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
`;
|
|
21
|
-
}
|
|
22
|
-
if (primaryKeys.some(({ typeId }) => typeId === "bool")) {
|
|
23
|
-
result += `
|
|
24
|
-
function _boolToBytes32(bool value) pure returns (bytes32 result) {
|
|
25
|
-
assembly {
|
|
26
|
-
result := value
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function getWrappingHelpers(array: RenderTableType[]) {
|
|
36
|
-
const wrappers = new Map();
|
|
37
|
-
const unwrappers = new Map();
|
|
38
|
-
for (const { typeWrappingData, typeWrap, typeUnwrap, internalTypeId } of array) {
|
|
39
|
-
if (!typeWrappingData) continue;
|
|
40
|
-
const { kind } = typeWrappingData;
|
|
41
|
-
|
|
42
|
-
if (kind === "staticArray") {
|
|
43
|
-
const { elementType, staticLength } = typeWrappingData;
|
|
44
|
-
wrappers.set(typeWrap, renderWrapperStaticArray(typeWrap, elementType, staticLength, internalTypeId));
|
|
45
|
-
unwrappers.set(typeUnwrap, renderUnwrapperStaticArray(typeUnwrap, elementType, staticLength, internalTypeId));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return [...wrappers.values(), ...unwrappers.values()];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function renderWrapperStaticArray(
|
|
53
|
-
functionName: string,
|
|
54
|
-
elementType: string,
|
|
55
|
-
staticLength: number,
|
|
56
|
-
internalTypeId: string
|
|
57
|
-
) {
|
|
58
|
-
// WARNING: ensure this still works if changing major solidity versions!
|
|
59
|
-
// (the memory layout for static arrays may change)
|
|
60
|
-
return `
|
|
61
|
-
function ${functionName}(
|
|
62
|
-
${internalTypeId} memory _value
|
|
63
|
-
) pure returns (
|
|
64
|
-
${elementType}[${staticLength}] memory _result
|
|
65
|
-
) {
|
|
66
|
-
// in memory static arrays are just dynamic arrays without the length byte
|
|
67
|
-
assembly {
|
|
68
|
-
_result := add(_value, 0x20)
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
`;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function renderUnwrapperStaticArray(
|
|
75
|
-
functionName: string,
|
|
76
|
-
elementType: string,
|
|
77
|
-
staticLength: number,
|
|
78
|
-
internalTypeId: string
|
|
79
|
-
) {
|
|
80
|
-
// byte length for memory copying (more efficient than a loop)
|
|
81
|
-
const byteLength = staticLength * 32;
|
|
82
|
-
// TODO to optimize memory usage consider generalizing TightEncoder to a render-time utility
|
|
83
|
-
return `
|
|
84
|
-
function ${functionName}(
|
|
85
|
-
${elementType}[${staticLength}] memory _value
|
|
86
|
-
) view returns (
|
|
87
|
-
${internalTypeId} memory _result
|
|
88
|
-
) {
|
|
89
|
-
_result = new ${internalTypeId}(${staticLength});
|
|
90
|
-
uint256 fromPointer;
|
|
91
|
-
uint256 toPointer;
|
|
92
|
-
assembly {
|
|
93
|
-
fromPointer := _value
|
|
94
|
-
toPointer := add(_result, 0x20)
|
|
95
|
-
}
|
|
96
|
-
Memory.copy(fromPointer, toPointer, ${byteLength});
|
|
97
|
-
}
|
|
98
|
-
`;
|
|
99
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { renderArguments, renderList, renderedSolidityHeader } from "./common.js";
|
|
2
|
-
import { RenderTypesOptions } from "./types.js";
|
|
3
|
-
|
|
4
|
-
export function renderTypes(options: RenderTypesOptions) {
|
|
5
|
-
const { enums } = options;
|
|
6
|
-
|
|
7
|
-
return `${renderedSolidityHeader}
|
|
8
|
-
|
|
9
|
-
${renderList(
|
|
10
|
-
enums,
|
|
11
|
-
({ name, memberNames }) => `
|
|
12
|
-
enum ${name} {
|
|
13
|
-
${renderArguments(memberNames)}
|
|
14
|
-
}
|
|
15
|
-
`
|
|
16
|
-
)}
|
|
17
|
-
|
|
18
|
-
`;
|
|
19
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { StoreConfig } from "@latticexyz/config";
|
|
2
|
-
import { renderTypes } from "./renderTypes.js";
|
|
3
|
-
|
|
4
|
-
export function renderTypesFromConfig(config: StoreConfig) {
|
|
5
|
-
const enums = Object.keys(config.enums).map((name) => ({
|
|
6
|
-
name,
|
|
7
|
-
memberNames: config.enums[name],
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
return renderTypes({
|
|
11
|
-
enums,
|
|
12
|
-
});
|
|
13
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { renderArguments, renderedSolidityHeader, renderImports } from "./common.js";
|
|
2
|
-
import { RenderWorldOptions } from "./types.js";
|
|
3
|
-
|
|
4
|
-
export function renderWorld(options: RenderWorldOptions) {
|
|
5
|
-
const { interfaceName, storeImportPath, worldImportPath, imports } = options;
|
|
6
|
-
|
|
7
|
-
return `${renderedSolidityHeader}
|
|
8
|
-
|
|
9
|
-
import { IStore } from "${storeImportPath}IStore.sol";
|
|
10
|
-
|
|
11
|
-
import { IWorldCore } from "${worldImportPath}interfaces/IWorldCore.sol";
|
|
12
|
-
|
|
13
|
-
${renderImports(imports)}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The ${interfaceName} interface includes all systems dynamically added to the World
|
|
17
|
-
* during the deploy process.
|
|
18
|
-
*/
|
|
19
|
-
interface ${interfaceName} is ${renderArguments(["IStore", "IWorldCore", ...imports.map(({ symbol }) => symbol)])} {
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
`;
|
|
24
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { SchemaTypeArrayToElement } from "@latticexyz/schema-type";
|
|
3
|
-
import { StoreConfig } from "@latticexyz/config";
|
|
4
|
-
import {
|
|
5
|
-
ImportDatum,
|
|
6
|
-
RenderTableDynamicField,
|
|
7
|
-
RenderTableField,
|
|
8
|
-
RenderTableOptions,
|
|
9
|
-
RenderTablePrimaryKey,
|
|
10
|
-
RenderTableStaticField,
|
|
11
|
-
} from "./types.js";
|
|
12
|
-
import { getSchemaTypeInfo, importForAbiOrUserType, resolveAbiOrUserType } from "./userType.js";
|
|
13
|
-
|
|
14
|
-
export interface TableOptions {
|
|
15
|
-
outputPath: string;
|
|
16
|
-
tableName: string;
|
|
17
|
-
renderOptions: RenderTableOptions;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function getTableOptions(config: StoreConfig): TableOptions[] {
|
|
21
|
-
const storeImportPath = config.storeImportPath;
|
|
22
|
-
|
|
23
|
-
const options = [];
|
|
24
|
-
for (const tableName of Object.keys(config.tables)) {
|
|
25
|
-
const tableData = config.tables[tableName];
|
|
26
|
-
|
|
27
|
-
// struct adds methods to get/set all values at once
|
|
28
|
-
const withStruct = tableData.dataStruct;
|
|
29
|
-
// operate on all fields at once; for only 1 field keep them only if struct is also kept
|
|
30
|
-
const withRecordMethods = withStruct || Object.keys(tableData.schema).length > 1;
|
|
31
|
-
// field methods can be simply get/set if there's only 1 field and no record methods
|
|
32
|
-
const noFieldMethodSuffix = !withRecordMethods && Object.keys(tableData.schema).length === 1;
|
|
33
|
-
// list of any symbols that need to be imported
|
|
34
|
-
const imports: ImportDatum[] = [];
|
|
35
|
-
|
|
36
|
-
const primaryKeys = Object.keys(tableData.primaryKeys).map((name) => {
|
|
37
|
-
const abiOrUserType = tableData.primaryKeys[name];
|
|
38
|
-
const { renderTableType } = resolveAbiOrUserType(abiOrUserType, config);
|
|
39
|
-
|
|
40
|
-
const importDatum = importForAbiOrUserType(abiOrUserType, tableData.directory, config);
|
|
41
|
-
if (importDatum) imports.push(importDatum);
|
|
42
|
-
|
|
43
|
-
if (renderTableType.isDynamic)
|
|
44
|
-
throw new Error(`Parsing error: found dynamic primary key ${name} in table ${tableName}`);
|
|
45
|
-
|
|
46
|
-
const primaryKey: RenderTablePrimaryKey = {
|
|
47
|
-
...renderTableType,
|
|
48
|
-
name,
|
|
49
|
-
isDynamic: false,
|
|
50
|
-
};
|
|
51
|
-
return primaryKey;
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const fields = Object.keys(tableData.schema).map((name) => {
|
|
55
|
-
const abiOrUserType = tableData.schema[name];
|
|
56
|
-
const { renderTableType, schemaType } = resolveAbiOrUserType(abiOrUserType, config);
|
|
57
|
-
|
|
58
|
-
const importDatum = importForAbiOrUserType(abiOrUserType, tableData.directory, config);
|
|
59
|
-
if (importDatum) imports.push(importDatum);
|
|
60
|
-
|
|
61
|
-
const elementType = SchemaTypeArrayToElement[schemaType];
|
|
62
|
-
const field: RenderTableField = {
|
|
63
|
-
...renderTableType,
|
|
64
|
-
arrayElement: elementType !== undefined ? getSchemaTypeInfo(elementType) : undefined,
|
|
65
|
-
name,
|
|
66
|
-
methodNameSuffix: noFieldMethodSuffix ? "" : `${name[0].toUpperCase()}${name.slice(1)}`,
|
|
67
|
-
};
|
|
68
|
-
return field;
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const staticFields = fields.filter(({ isDynamic }) => !isDynamic) as RenderTableStaticField[];
|
|
72
|
-
const dynamicFields = fields.filter(({ isDynamic }) => isDynamic) as RenderTableDynamicField[];
|
|
73
|
-
|
|
74
|
-
// With tableIdArgument: tableId is a dynamic argument for each method
|
|
75
|
-
// Without tableIdArgument: tableId is a file-level constant generated from `staticResourceData`
|
|
76
|
-
const staticResourceData = (() => {
|
|
77
|
-
if (tableData.tableIdArgument) {
|
|
78
|
-
return;
|
|
79
|
-
} else {
|
|
80
|
-
return {
|
|
81
|
-
tableIdName: tableName + "TableId",
|
|
82
|
-
namespace: config.namespace,
|
|
83
|
-
name: tableData.name,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
})();
|
|
87
|
-
|
|
88
|
-
options.push({
|
|
89
|
-
outputPath: path.join(tableData.directory, `${tableName}.sol`),
|
|
90
|
-
tableName,
|
|
91
|
-
renderOptions: {
|
|
92
|
-
imports,
|
|
93
|
-
libraryName: tableName,
|
|
94
|
-
structName: withStruct ? tableName + "Data" : undefined,
|
|
95
|
-
staticResourceData,
|
|
96
|
-
storeImportPath,
|
|
97
|
-
primaryKeys,
|
|
98
|
-
fields,
|
|
99
|
-
staticFields,
|
|
100
|
-
dynamicFields,
|
|
101
|
-
withRecordMethods,
|
|
102
|
-
storeArgument: tableData.storeArgument,
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return options;
|
|
107
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { StoreConfig } from "@latticexyz/config";
|
|
3
|
-
import { getTableOptions } from "./tableOptions.js";
|
|
4
|
-
import { renderTable } from "./renderTable.js";
|
|
5
|
-
import { renderTypesFromConfig } from "./renderTypesFromConfig.js";
|
|
6
|
-
import { formatAndWriteSolidity } from "../utils/formatAndWrite.js";
|
|
7
|
-
import { renderTableIndex } from "./renderTableIndex.js";
|
|
8
|
-
import { rmSync } from "fs";
|
|
9
|
-
|
|
10
|
-
export async function tablegen(config: StoreConfig, outputBaseDirectory: string) {
|
|
11
|
-
const allTableOptions = getTableOptions(config);
|
|
12
|
-
|
|
13
|
-
const uniqueTableDirectories = new Set(allTableOptions.map(({ outputPath }) => path.dirname(outputPath)));
|
|
14
|
-
for (const tableDir of uniqueTableDirectories) {
|
|
15
|
-
rmSync(path.join(outputBaseDirectory, tableDir), { recursive: true, force: true });
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// write tables to files
|
|
19
|
-
for (const { outputPath, renderOptions } of allTableOptions) {
|
|
20
|
-
const fullOutputPath = path.join(outputBaseDirectory, outputPath);
|
|
21
|
-
const output = renderTable(renderOptions);
|
|
22
|
-
formatAndWriteSolidity(output, fullOutputPath, "Generated table");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// write types to file
|
|
26
|
-
if (Object.keys(config.enums).length > 0) {
|
|
27
|
-
const fullOutputPath = path.join(outputBaseDirectory, `${config.userTypesPath}.sol`);
|
|
28
|
-
const output = renderTypesFromConfig(config);
|
|
29
|
-
formatAndWriteSolidity(output, fullOutputPath, "Generated types file");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const fullOutputPath = path.join(outputBaseDirectory, `Tables.sol`);
|
|
33
|
-
const output = renderTableIndex(allTableOptions);
|
|
34
|
-
formatAndWriteSolidity(output, fullOutputPath, "Generated table index");
|
|
35
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
export interface RenderTableOptions {
|
|
2
|
-
/** List of symbols to import, and their file paths */
|
|
3
|
-
imports: ImportDatum[];
|
|
4
|
-
/** Name of the library to render. */
|
|
5
|
-
libraryName: string;
|
|
6
|
-
/** Name of the struct to render. If undefined, struct and its methods aren't rendered. */
|
|
7
|
-
structName?: string;
|
|
8
|
-
/** Data used to statically registed the table. If undefined, all methods receive `_tableId` as an argument. */
|
|
9
|
-
staticResourceData?: StaticResourceData;
|
|
10
|
-
/** Path for store package imports */
|
|
11
|
-
storeImportPath: string;
|
|
12
|
-
primaryKeys: RenderTablePrimaryKey[];
|
|
13
|
-
fields: RenderTableField[];
|
|
14
|
-
staticFields: RenderTableStaticField[];
|
|
15
|
-
dynamicFields: RenderTableDynamicField[];
|
|
16
|
-
/** Whether to render get/set methods for the whole record */
|
|
17
|
-
withRecordMethods: boolean;
|
|
18
|
-
/** Whether to render additional methods that accept a manual `IStore` argument */
|
|
19
|
-
storeArgument: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface ImportDatum {
|
|
23
|
-
symbol: string;
|
|
24
|
-
fromPath: string;
|
|
25
|
-
usedInPath: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface StaticResourceData {
|
|
29
|
-
/** Name of the table id constant to render. */
|
|
30
|
-
tableIdName: string;
|
|
31
|
-
namespace: string;
|
|
32
|
-
name: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface RenderTableType {
|
|
36
|
-
typeId: string;
|
|
37
|
-
typeWithLocation: string;
|
|
38
|
-
/** The name of the enum element in SchemaType to use for schema registration (e.g. "UINT256_ARRAY") */
|
|
39
|
-
enumName: string;
|
|
40
|
-
staticByteLength: number;
|
|
41
|
-
isDynamic: boolean;
|
|
42
|
-
/** Empty for internal types. Custom `wrap` method for user defined types. */
|
|
43
|
-
typeWrap: string;
|
|
44
|
-
/** Empty for internal types. Custom `unwrap` method for user defined types. */
|
|
45
|
-
typeUnwrap: string;
|
|
46
|
-
/** Data to generate the custom wrapper and unwrapper if necessary. */
|
|
47
|
-
typeWrappingData?: RenderTableTypeWrappingData;
|
|
48
|
-
/** Same as typeId for internal types. The underlying `typeId` for user defined types. */
|
|
49
|
-
internalTypeId: string;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export type RenderTableTypeWrappingData = {
|
|
53
|
-
kind: "staticArray";
|
|
54
|
-
elementType: string;
|
|
55
|
-
staticLength: number;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export interface RenderTablePrimaryKey extends RenderTableType {
|
|
59
|
-
name: string;
|
|
60
|
-
isDynamic: false;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface RenderTableStaticField extends RenderTableField {
|
|
64
|
-
isDynamic: false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface RenderTableDynamicField extends RenderTableField {
|
|
68
|
-
isDynamic: true;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface RenderTableField extends RenderTableType {
|
|
72
|
-
arrayElement: RenderTableType | undefined;
|
|
73
|
-
name: string;
|
|
74
|
-
methodNameSuffix: string;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface RenderTypesOptions {
|
|
78
|
-
/** List of enums to render */
|
|
79
|
-
enums: RenderTypesEnum[];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface RenderTypesEnum {
|
|
83
|
-
name: string;
|
|
84
|
-
memberNames: string[];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export interface RenderSystemInterfaceOptions {
|
|
88
|
-
/** List of symbols to import, and their file paths */
|
|
89
|
-
imports: ImportDatum[];
|
|
90
|
-
name: string;
|
|
91
|
-
functionPrefix: string;
|
|
92
|
-
functions: RenderSystemInterfaceFunction[];
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export interface RenderSystemInterfaceFunction {
|
|
96
|
-
name: string;
|
|
97
|
-
parameters: string[];
|
|
98
|
-
stateMutability: string;
|
|
99
|
-
returnParameters: string[];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface RenderWorldOptions {
|
|
103
|
-
/** List of symbols to import, and their file paths */
|
|
104
|
-
imports: ImportDatum[];
|
|
105
|
-
/** Name of the interface to render */
|
|
106
|
-
interfaceName: string;
|
|
107
|
-
/** Path for store package imports */
|
|
108
|
-
storeImportPath: string;
|
|
109
|
-
/** Path for world package imports */
|
|
110
|
-
worldImportPath: string;
|
|
111
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { AbiTypeToSchemaType, getStaticByteLength, SchemaType, SchemaTypeToAbiType } from "@latticexyz/schema-type";
|
|
2
|
-
import { StoreConfig, parseStaticArray } from "@latticexyz/config";
|
|
3
|
-
import { ImportDatum, RenderTableType } from "./types.js";
|
|
4
|
-
|
|
5
|
-
export type UserTypeInfo = ReturnType<typeof getUserTypeInfo>;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Resolve an abi or user type into a SchemaType
|
|
9
|
-
*/
|
|
10
|
-
export function resolveAbiOrUserType(
|
|
11
|
-
abiOrUserType: string,
|
|
12
|
-
config: StoreConfig
|
|
13
|
-
): {
|
|
14
|
-
schemaType: SchemaType;
|
|
15
|
-
renderTableType: RenderTableType;
|
|
16
|
-
} {
|
|
17
|
-
// abi types which directly mirror a SchemaType
|
|
18
|
-
if (abiOrUserType in AbiTypeToSchemaType) {
|
|
19
|
-
const schemaType = AbiTypeToSchemaType[abiOrUserType];
|
|
20
|
-
return {
|
|
21
|
-
schemaType,
|
|
22
|
-
renderTableType: getSchemaTypeInfo(schemaType),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
// static arrays
|
|
26
|
-
const staticArray = parseStaticArray(abiOrUserType);
|
|
27
|
-
if (staticArray) {
|
|
28
|
-
if (staticArray.elementType in AbiTypeToSchemaType) {
|
|
29
|
-
return getStaticArrayTypeInfo(abiOrUserType, staticArray.elementType, staticArray.staticLength);
|
|
30
|
-
} else {
|
|
31
|
-
throw new Error("Static arrays of user types are not supported");
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
// user types
|
|
35
|
-
return getUserTypeInfo(abiOrUserType, config);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Get the required import for SchemaType|userType (`undefined` means that no import is required)
|
|
40
|
-
*/
|
|
41
|
-
export function importForAbiOrUserType(
|
|
42
|
-
abiOrUserType: string,
|
|
43
|
-
usedInDirectory: string,
|
|
44
|
-
config: StoreConfig
|
|
45
|
-
): ImportDatum | undefined {
|
|
46
|
-
// abi types which directly mirror a SchemaType
|
|
47
|
-
if (abiOrUserType in AbiTypeToSchemaType) {
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
// static arrays
|
|
51
|
-
const staticArray = parseStaticArray(abiOrUserType);
|
|
52
|
-
if (staticArray) {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
// user types
|
|
56
|
-
return {
|
|
57
|
-
symbol: abiOrUserType,
|
|
58
|
-
fromPath: config.userTypesPath + ".sol",
|
|
59
|
-
usedInPath: usedInDirectory,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function getSchemaTypeInfo(schemaType: SchemaType): RenderTableType {
|
|
64
|
-
const staticByteLength = getStaticByteLength(schemaType);
|
|
65
|
-
const isDynamic = staticByteLength === 0;
|
|
66
|
-
const typeId = SchemaTypeToAbiType[schemaType];
|
|
67
|
-
return {
|
|
68
|
-
typeId,
|
|
69
|
-
typeWithLocation: isDynamic ? typeId + " memory" : typeId,
|
|
70
|
-
enumName: SchemaType[schemaType],
|
|
71
|
-
staticByteLength,
|
|
72
|
-
isDynamic,
|
|
73
|
-
typeWrap: "",
|
|
74
|
-
typeUnwrap: "",
|
|
75
|
-
internalTypeId: typeId,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function getUserTypeInfo(
|
|
80
|
-
userType: string,
|
|
81
|
-
config: StoreConfig
|
|
82
|
-
): {
|
|
83
|
-
schemaType: SchemaType;
|
|
84
|
-
renderTableType: RenderTableType;
|
|
85
|
-
} {
|
|
86
|
-
// enums
|
|
87
|
-
if (userType in config.enums) {
|
|
88
|
-
const schemaType = SchemaType.UINT8;
|
|
89
|
-
const staticByteLength = getStaticByteLength(schemaType);
|
|
90
|
-
const isDynamic = staticByteLength === 0;
|
|
91
|
-
const typeId = userType;
|
|
92
|
-
return {
|
|
93
|
-
schemaType,
|
|
94
|
-
renderTableType: {
|
|
95
|
-
typeId,
|
|
96
|
-
typeWithLocation: typeId,
|
|
97
|
-
enumName: SchemaType[schemaType],
|
|
98
|
-
staticByteLength,
|
|
99
|
-
isDynamic,
|
|
100
|
-
typeWrap: `${userType}`,
|
|
101
|
-
typeUnwrap: `uint8`,
|
|
102
|
-
internalTypeId: `${SchemaTypeToAbiType[schemaType]}`,
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
// invalid
|
|
107
|
-
throw new Error(`User type "${userType}" does not exist`);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function getStaticArrayTypeInfo(abiType: string, elementType: string, staticLength: number) {
|
|
111
|
-
const internalTypeId = elementType + "[]";
|
|
112
|
-
const schemaType = AbiTypeToSchemaType[internalTypeId];
|
|
113
|
-
return {
|
|
114
|
-
schemaType,
|
|
115
|
-
renderTableType: {
|
|
116
|
-
typeId: abiType,
|
|
117
|
-
typeWithLocation: `${abiType} memory`,
|
|
118
|
-
enumName: SchemaType[schemaType],
|
|
119
|
-
staticByteLength: 0,
|
|
120
|
-
isDynamic: true,
|
|
121
|
-
typeWrap: `toStaticArray_${elementType}_${staticLength}`,
|
|
122
|
-
typeUnwrap: `fromStaticArray_${elementType}_${staticLength}`,
|
|
123
|
-
typeWrappingData: {
|
|
124
|
-
kind: "staticArray",
|
|
125
|
-
elementType,
|
|
126
|
-
staticLength,
|
|
127
|
-
},
|
|
128
|
-
internalTypeId,
|
|
129
|
-
},
|
|
130
|
-
} as const;
|
|
131
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { MUDConfig } from "@latticexyz/config";
|
|
4
|
-
import { contractToInterface } from "../utils/contractToInterface.js";
|
|
5
|
-
import { formatAndWriteSolidity } from "../utils/formatAndWrite.js";
|
|
6
|
-
import { renderSystemInterface } from "./renderSystemInterface.js";
|
|
7
|
-
import { renderWorld } from "./renderWorld.js";
|
|
8
|
-
import { ImportDatum } from "./types.js";
|
|
9
|
-
|
|
10
|
-
export async function worldgen(
|
|
11
|
-
config: MUDConfig,
|
|
12
|
-
existingContracts: { path: string; basename: string }[],
|
|
13
|
-
outputBaseDirectory: string
|
|
14
|
-
) {
|
|
15
|
-
const worldgenBaseDirectory = path.join(outputBaseDirectory, config.worldgenDirectory);
|
|
16
|
-
const systems = existingContracts.filter(({ basename }) => Object.keys(config.systems).includes(basename));
|
|
17
|
-
|
|
18
|
-
const systemInterfaceImports: ImportDatum[] = [];
|
|
19
|
-
for (const system of systems) {
|
|
20
|
-
const data = readFileSync(system.path, "utf8");
|
|
21
|
-
// get external funcions from a contract
|
|
22
|
-
const { functions, symbols } = contractToInterface(data, system.basename);
|
|
23
|
-
const imports = symbols.map((symbol) => ({
|
|
24
|
-
symbol,
|
|
25
|
-
fromPath: system.path,
|
|
26
|
-
usedInPath: worldgenBaseDirectory,
|
|
27
|
-
}));
|
|
28
|
-
const systemInterfaceName = `I${system.basename}`;
|
|
29
|
-
// create an interface using the external functions and imports
|
|
30
|
-
const { name } = config.systems[system.basename];
|
|
31
|
-
const output = renderSystemInterface({
|
|
32
|
-
name: systemInterfaceName,
|
|
33
|
-
functionPrefix: config.namespace === "" ? "" : `${config.namespace}_${name}_`,
|
|
34
|
-
functions,
|
|
35
|
-
imports,
|
|
36
|
-
});
|
|
37
|
-
// write to file
|
|
38
|
-
const fullOutputPath = path.join(worldgenBaseDirectory, systemInterfaceName + ".sol");
|
|
39
|
-
await formatAndWriteSolidity(output, fullOutputPath, "Generated system interface");
|
|
40
|
-
|
|
41
|
-
// prepare imports for IWorld
|
|
42
|
-
systemInterfaceImports.push({
|
|
43
|
-
symbol: systemInterfaceName,
|
|
44
|
-
fromPath: `${systemInterfaceName}.sol`,
|
|
45
|
-
usedInPath: "./",
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// render IWorld
|
|
50
|
-
const output = renderWorld({
|
|
51
|
-
interfaceName: config.worldInterfaceName,
|
|
52
|
-
imports: systemInterfaceImports,
|
|
53
|
-
storeImportPath: config.storeImportPath,
|
|
54
|
-
worldImportPath: config.worldImportPath,
|
|
55
|
-
});
|
|
56
|
-
// write to file
|
|
57
|
-
const fullOutputPath = path.join(worldgenBaseDirectory, config.worldInterfaceName + ".sol");
|
|
58
|
-
await formatAndWriteSolidity(output, fullOutputPath, "Generated system interface");
|
|
59
|
-
}
|
package/src/render-ts/index.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { StoreConfig } from "@latticexyz/config";
|
|
2
|
-
import { resolveAbiOrUserType } from "../render-solidity/userType.js";
|
|
3
|
-
import { schemaTypesToRecsTypeStrings } from "./schemaTypesToRecsTypeStrings.js";
|
|
4
|
-
import { RecsV1TableOptions } from "./types.js";
|
|
5
|
-
|
|
6
|
-
export function getRecsV1TableOptions(config: StoreConfig): RecsV1TableOptions {
|
|
7
|
-
const tableOptions = [];
|
|
8
|
-
for (const tableName of Object.keys(config.tables)) {
|
|
9
|
-
const tableData = config.tables[tableName];
|
|
10
|
-
|
|
11
|
-
const fields = Object.keys(tableData.schema).map((name) => {
|
|
12
|
-
const abiOrUserType = tableData.schema[name];
|
|
13
|
-
const { schemaType } = resolveAbiOrUserType(abiOrUserType, config);
|
|
14
|
-
|
|
15
|
-
const recsTypeString = schemaTypesToRecsTypeStrings[schemaType];
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
recsTypeString,
|
|
19
|
-
name,
|
|
20
|
-
};
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// WARNING: skip tables without a static tableId
|
|
24
|
-
if (tableData.tableIdArgument) continue;
|
|
25
|
-
const staticResourceData = {
|
|
26
|
-
namespace: config.namespace,
|
|
27
|
-
name: tableData.name,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
tableOptions.push({
|
|
31
|
-
tableName,
|
|
32
|
-
fields,
|
|
33
|
-
staticResourceData,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
tables: tableOptions,
|
|
38
|
-
};
|
|
39
|
-
}
|