@latticexyz/common 2.2.22-490159e880e2ac0e1ce8f5785873a25b99fb7668 → 2.2.22-4f57d5de39a17a180cd14e768cd2a56cfc8fd85f
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/chains.d.ts +7 -5
- package/dist/{chunk-NFWCLD5I.js → chunk-ETXWXV5T.js} +14 -1
- package/dist/chunk-ETXWXV5T.js.map +1 -0
- package/dist/codegen.d.ts +12 -9
- package/dist/codegen.js +84 -46
- package/dist/codegen.js.map +1 -1
- package/dist/internal.d.ts +8 -1
- package/dist/internal.js +380 -2
- package/dist/internal.js.map +1 -1
- package/dist/utils.js +2 -4
- package/package.json +3 -3
- package/dist/chunk-CHXZROA7.js +0 -16
- package/dist/chunk-CHXZROA7.js.map +0 -1
- package/dist/chunk-NFWCLD5I.js.map +0 -1
package/dist/chains.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as viem_chains from 'viem/chains';
|
|
2
2
|
import { Chain } from 'viem/chains';
|
|
3
3
|
import * as viem from 'viem';
|
|
4
|
-
import * as viem_experimental from 'viem/experimental';
|
|
5
4
|
import * as viem_op_stack from 'viem/op-stack';
|
|
6
5
|
|
|
7
6
|
type MUDChain = Chain & {
|
|
@@ -36,6 +35,7 @@ declare const mudFoundry: {
|
|
|
36
35
|
multicall3?: viem.ChainContract | undefined;
|
|
37
36
|
universalSignatureVerifier?: viem.ChainContract | undefined;
|
|
38
37
|
} | undefined;
|
|
38
|
+
readonly ensTlds?: readonly string[] | undefined;
|
|
39
39
|
readonly id: 31337;
|
|
40
40
|
readonly name: "Foundry";
|
|
41
41
|
readonly nativeCurrency: {
|
|
@@ -106,6 +106,7 @@ declare const redstone: {
|
|
|
106
106
|
readonly address: "0x4200000000000000000000000000000000000016";
|
|
107
107
|
};
|
|
108
108
|
};
|
|
109
|
+
readonly ensTlds?: readonly string[] | undefined;
|
|
109
110
|
readonly id: 690;
|
|
110
111
|
readonly name: "Redstone";
|
|
111
112
|
readonly nativeCurrency: {
|
|
@@ -312,7 +313,7 @@ declare const redstone: {
|
|
|
312
313
|
value: bigint;
|
|
313
314
|
yParity: number;
|
|
314
315
|
accessList: viem.AccessList;
|
|
315
|
-
authorizationList:
|
|
316
|
+
authorizationList: viem.SignedAuthorizationList<number>;
|
|
316
317
|
blobVersionedHashes?: undefined;
|
|
317
318
|
chainId: number;
|
|
318
319
|
type: "eip7702";
|
|
@@ -419,6 +420,7 @@ declare const garnet: {
|
|
|
419
420
|
readonly address: "0x4200000000000000000000000000000000000016";
|
|
420
421
|
};
|
|
421
422
|
};
|
|
423
|
+
readonly ensTlds?: readonly string[] | undefined;
|
|
422
424
|
readonly id: 17069;
|
|
423
425
|
readonly name: "Garnet Testnet";
|
|
424
426
|
readonly nativeCurrency: {
|
|
@@ -619,7 +621,7 @@ declare const garnet: {
|
|
|
619
621
|
value: bigint;
|
|
620
622
|
yParity: number;
|
|
621
623
|
accessList: viem.AccessList;
|
|
622
|
-
authorizationList:
|
|
624
|
+
authorizationList: viem.SignedAuthorizationList<number>;
|
|
623
625
|
blobVersionedHashes?: undefined;
|
|
624
626
|
chainId: number;
|
|
625
627
|
type: "eip7702";
|
|
@@ -923,7 +925,7 @@ declare const rhodolite: {
|
|
|
923
925
|
value: bigint;
|
|
924
926
|
yParity: number;
|
|
925
927
|
accessList: viem.AccessList;
|
|
926
|
-
authorizationList:
|
|
928
|
+
authorizationList: viem.SignedAuthorizationList<number>;
|
|
927
929
|
blobVersionedHashes?: undefined;
|
|
928
930
|
chainId: number;
|
|
929
931
|
type: "eip7702";
|
|
@@ -1216,7 +1218,7 @@ declare const pyrope: {
|
|
|
1216
1218
|
value: bigint;
|
|
1217
1219
|
yParity: number;
|
|
1218
1220
|
accessList: viem.AccessList;
|
|
1219
|
-
authorizationList:
|
|
1221
|
+
authorizationList: viem.SignedAuthorizationList<number>;
|
|
1220
1222
|
blobVersionedHashes?: undefined;
|
|
1221
1223
|
chainId: number;
|
|
1222
1224
|
type: "eip7702";
|
|
@@ -82,6 +82,18 @@ function unique(values) {
|
|
|
82
82
|
return Array.from(new Set(values));
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
// src/utils/uniqueBy.ts
|
|
86
|
+
function uniqueBy(values, getKey) {
|
|
87
|
+
const map = /* @__PURE__ */ new Map();
|
|
88
|
+
for (const value of values) {
|
|
89
|
+
const key = getKey(value);
|
|
90
|
+
if (!map.has(key)) {
|
|
91
|
+
map.set(key, value);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return Array.from(map.values());
|
|
95
|
+
}
|
|
96
|
+
|
|
85
97
|
// src/utils/wait.ts
|
|
86
98
|
function wait(ms) {
|
|
87
99
|
return new Promise((resolve) => setTimeout(() => resolve(), ms));
|
|
@@ -113,7 +125,8 @@ export {
|
|
|
113
125
|
iteratorToArray,
|
|
114
126
|
mapObject,
|
|
115
127
|
unique,
|
|
128
|
+
uniqueBy,
|
|
116
129
|
wait,
|
|
117
130
|
waitForIdle
|
|
118
131
|
};
|
|
119
|
-
//# sourceMappingURL=chunk-
|
|
132
|
+
//# sourceMappingURL=chunk-ETXWXV5T.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/assertExhaustive.ts","../src/utils/bigIntMax.ts","../src/utils/bigIntMin.ts","../src/utils/bigIntSort.ts","../src/utils/chunk.ts","../src/utils/groupBy.ts","../src/utils/identity.ts","../src/utils/includes.ts","../src/utils/indent.ts","../src/utils/isDefined.ts","../src/utils/isNotNull.ts","../src/utils/iteratorToArray.ts","../src/utils/mapObject.ts","../src/utils/unique.ts","../src/utils/uniqueBy.ts","../src/utils/wait.ts","../src/utils/waitForIdle.ts"],"sourcesContent":["export function assertExhaustive(value: never, message?: string): never {\n throw new Error(message ?? `Unexpected value: ${value}`);\n}\n","export function bigIntMax(...args: bigint[]): bigint {\n return args.reduce((m, e) => (e > m ? e : m));\n}\n","export function bigIntMin(...args: bigint[]): bigint {\n return args.reduce((m, e) => (e < m ? e : m));\n}\n","export function bigIntSort(a: bigint, b: bigint): -1 | 0 | 1 {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n","export function* chunk<T>(arr: readonly T[], n: number): Generator<readonly T[], void> {\n for (let i = 0; i < arr.length; i += n) {\n yield arr.slice(i, i + n);\n }\n}\n","export function groupBy<value, key>(\n values: readonly value[],\n getKey: (value: value) => key,\n): Map<key, readonly value[]> {\n const map = new Map<key, readonly value[]>();\n for (const value of values) {\n const key = getKey(value);\n if (!map.has(key)) map.set(key, []);\n (map.get(key) as value[]).push(value);\n }\n return map;\n}\n","export function identity<T>(value: T): T {\n return value;\n}\n","// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function includes<item>(items: item[], value: any): value is item {\n return items.includes(value);\n}\n","export function indent(message: string, indentation = \" \"): string {\n return message.replaceAll(/(^|\\n)/g, `$1${indentation}`);\n}\n","export function isDefined<T>(argument: T | undefined): argument is T {\n return argument !== undefined;\n}\n","export function isNotNull<T>(argument: T | null): argument is T {\n return argument !== null;\n}\n","export async function iteratorToArray<T>(iterator: AsyncIterable<T>): Promise<readonly T[]> {\n const items: T[] = [];\n for await (const item of iterator) {\n items.push(item);\n }\n return items;\n}\n","/**\n * Map each key of a source object via a given valueMap function\n */\nexport function mapObject<\n Source extends Record<string | number | symbol, unknown>,\n Target extends { [key in keyof Source]: unknown },\n>(source: Source, valueMap: (value: Source[typeof key], key: keyof Source) => Target[typeof key]): Target {\n return Object.fromEntries(\n Object.entries(source).map(([key, value]) => [key, valueMap(value as Source[keyof Source], key)]),\n ) as Target;\n}\n","export function unique<value>(values: readonly value[]): readonly value[] {\n return Array.from(new Set(values));\n}\n","export function uniqueBy<value, key>(values: readonly value[], getKey: (value: value) => key): readonly value[] {\n const map = new Map<key, value>();\n for (const value of values) {\n const key = getKey(value);\n if (!map.has(key)) {\n map.set(key, value);\n }\n }\n return Array.from(map.values());\n}\n","export function wait(ms: number): Promise<void> {\n return new Promise<void>((resolve) => setTimeout(() => resolve(), ms));\n}\n","export function waitForIdle(): Promise<void> {\n return new Promise<void>((resolve) => {\n if (typeof requestIdleCallback !== \"undefined\") {\n requestIdleCallback(() => resolve());\n } else {\n setTimeout(() => resolve(), 1);\n }\n });\n}\n"],"mappings":";AAAO,SAAS,iBAAiB,OAAc,SAAyB;AACtE,QAAM,IAAI,MAAM,WAAW,qBAAqB,KAAK,EAAE;AACzD;;;ACFO,SAAS,aAAa,MAAwB;AACnD,SAAO,KAAK,OAAO,CAAC,GAAG,MAAO,IAAI,IAAI,IAAI,CAAE;AAC9C;;;ACFO,SAAS,aAAa,MAAwB;AACnD,SAAO,KAAK,OAAO,CAAC,GAAG,MAAO,IAAI,IAAI,IAAI,CAAE;AAC9C;;;ACFO,SAAS,WAAW,GAAW,GAAuB;AAC3D,SAAO,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;AAClC;;;ACFO,UAAU,MAAS,KAAmB,GAA0C;AACrF,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK,GAAG;AACtC,UAAM,IAAI,MAAM,GAAG,IAAI,CAAC;AAAA,EAC1B;AACF;;;ACJO,SAAS,QACd,QACA,QAC4B;AAC5B,QAAM,MAAM,oBAAI,IAA2B;AAC3C,aAAW,SAAS,QAAQ;AAC1B,UAAM,MAAM,OAAO,KAAK;AACxB,QAAI,CAAC,IAAI,IAAI,GAAG,EAAG,KAAI,IAAI,KAAK,CAAC,CAAC;AAClC,IAAC,IAAI,IAAI,GAAG,EAAc,KAAK,KAAK;AAAA,EACtC;AACA,SAAO;AACT;;;ACXO,SAAS,SAAY,OAAa;AACvC,SAAO;AACT;;;ACDO,SAAS,SAAe,OAAe,OAA2B;AACvE,SAAO,MAAM,SAAS,KAAK;AAC7B;;;ACHO,SAAS,OAAO,SAAiB,cAAc,MAAc;AAClE,SAAO,QAAQ,WAAW,WAAW,KAAK,WAAW,EAAE;AACzD;;;ACFO,SAAS,UAAa,UAAwC;AACnE,SAAO,aAAa;AACtB;;;ACFO,SAAS,UAAa,UAAmC;AAC9D,SAAO,aAAa;AACtB;;;ACFA,eAAsB,gBAAmB,UAAmD;AAC1F,QAAM,QAAa,CAAC;AACpB,mBAAiB,QAAQ,UAAU;AACjC,UAAM,KAAK,IAAI;AAAA,EACjB;AACA,SAAO;AACT;;;ACHO,SAAS,UAGd,QAAgB,UAAwF;AACxG,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,SAAS,OAA+B,GAAG,CAAC,CAAC;AAAA,EAClG;AACF;;;ACVO,SAAS,OAAc,QAA4C;AACxE,SAAO,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC;AACnC;;;ACFO,SAAS,SAAqB,QAA0B,QAAiD;AAC9G,QAAM,MAAM,oBAAI,IAAgB;AAChC,aAAW,SAAS,QAAQ;AAC1B,UAAM,MAAM,OAAO,KAAK;AACxB,QAAI,CAAC,IAAI,IAAI,GAAG,GAAG;AACjB,UAAI,IAAI,KAAK,KAAK;AAAA,IACpB;AAAA,EACF;AACA,SAAO,MAAM,KAAK,IAAI,OAAO,CAAC;AAChC;;;ACTO,SAAS,KAAK,IAA2B;AAC9C,SAAO,IAAI,QAAc,CAAC,YAAY,WAAW,MAAM,QAAQ,GAAG,EAAE,CAAC;AACvE;;;ACFO,SAAS,cAA6B;AAC3C,SAAO,IAAI,QAAc,CAAC,YAAY;AACpC,QAAI,OAAO,wBAAwB,aAAa;AAC9C,0BAAoB,MAAM,QAAQ,CAAC;AAAA,IACrC,OAAO;AACL,iBAAW,MAAM,QAAQ,GAAG,CAAC;AAAA,IAC/B;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/dist/codegen.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Hex } from 'viem';
|
|
2
2
|
import { Abi } from 'abitype';
|
|
3
3
|
import { SchemaType } from '@latticexyz/schema-type/deprecated';
|
|
4
|
-
import { SourceUnit, ContractDefinition } from '@solidity-parser/parser/dist/src/ast-types';
|
|
5
4
|
|
|
6
5
|
declare module "prettier-plugin-solidity" {}
|
|
7
6
|
|
|
@@ -168,6 +167,11 @@ declare function renderTypeHelpers(options: {
|
|
|
168
167
|
|
|
169
168
|
declare const schemaTypesToRecsTypeStrings: Record<SchemaType, string>;
|
|
170
169
|
|
|
170
|
+
interface SymbolImport {
|
|
171
|
+
symbol: string;
|
|
172
|
+
path: string;
|
|
173
|
+
}
|
|
174
|
+
|
|
171
175
|
interface ContractInterfaceFunction {
|
|
172
176
|
name: string;
|
|
173
177
|
parameters: string[];
|
|
@@ -178,10 +182,6 @@ interface ContractInterfaceError {
|
|
|
178
182
|
name: string;
|
|
179
183
|
parameters: string[];
|
|
180
184
|
}
|
|
181
|
-
interface SymbolImport {
|
|
182
|
-
symbol: string;
|
|
183
|
-
path: string;
|
|
184
|
-
}
|
|
185
185
|
/**
|
|
186
186
|
* Parse the contract data to get the functions necessary to generate an interface,
|
|
187
187
|
* and symbols to import from the original contract.
|
|
@@ -194,7 +194,6 @@ declare function contractToInterface(source: string, contractName: string): {
|
|
|
194
194
|
errors: ContractInterfaceError[];
|
|
195
195
|
symbolImports: SymbolImport[];
|
|
196
196
|
};
|
|
197
|
-
declare function findContractNode(ast: SourceUnit, contractName: string): ContractDefinition | undefined;
|
|
198
197
|
|
|
199
198
|
/**
|
|
200
199
|
* Formats solidity code using prettier
|
|
@@ -212,11 +211,11 @@ declare function formatTypescript(content: string): Promise<string>;
|
|
|
212
211
|
|
|
213
212
|
/**
|
|
214
213
|
* Formats solidity code using prettier and write it to a file
|
|
215
|
-
* @param
|
|
214
|
+
* @param content solidity code
|
|
216
215
|
* @param fullOutputPath full path to the output file
|
|
217
216
|
* @param logPrefix prefix for debug logs
|
|
218
217
|
*/
|
|
219
|
-
declare function formatAndWriteSolidity(
|
|
218
|
+
declare function formatAndWriteSolidity(content: string, fullOutputPath: string, logPrefix: string): Promise<void>;
|
|
220
219
|
/**
|
|
221
220
|
* Formats typescript code using prettier and write it to a file
|
|
222
221
|
* @param output typescript code
|
|
@@ -225,4 +224,8 @@ declare function formatAndWriteSolidity(output: string, fullOutputPath: string,
|
|
|
225
224
|
*/
|
|
226
225
|
declare function formatAndWriteTypescript(output: string, fullOutputPath: string, logPrefix: string): Promise<void>;
|
|
227
226
|
|
|
228
|
-
|
|
227
|
+
declare function parseSystem(source: string, contractName: string): undefined | {
|
|
228
|
+
contractType: "contract" | "abstract";
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export { type AbiToInterfaceOptions, type ContractInterfaceError, type ContractInterfaceFunction, type ImportDatum, type RenderDynamicField, type RenderEnum, type RenderField, type RenderFieldTypeWrappingData, type RenderKeyTuple, type RenderStaticField, type RenderType, type StaticResourceData, abiToInterface, contractToInterface, formatAndWriteSolidity, formatAndWriteTypescript, formatSolidity, formatTypescript, getLeftPaddingBits, isLeftAligned, parseSystem, renderArguments, renderCommonData, renderEnums, renderImportPath, renderImports, renderList, renderTableId, renderTypeHelpers, renderValueTypeToBytes32, renderWithFieldSuffix, renderWithStore, renderedSolidityHeader, schemaTypesToRecsTypeStrings };
|
package/dist/codegen.js
CHANGED
|
@@ -10,8 +10,7 @@ import {
|
|
|
10
10
|
} from "./chunk-GRGLAPN2.js";
|
|
11
11
|
import {
|
|
12
12
|
isDefined
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-CHXZROA7.js";
|
|
13
|
+
} from "./chunk-ETXWXV5T.js";
|
|
15
14
|
|
|
16
15
|
// src/codegen/render-solidity/abiToInterface.ts
|
|
17
16
|
import { formatAbiItem, formatAbiParameter } from "abitype";
|
|
@@ -520,7 +519,47 @@ var schemaTypesToRecsTypeStrings = {
|
|
|
520
519
|
};
|
|
521
520
|
|
|
522
521
|
// src/codegen/utils/contractToInterface.ts
|
|
523
|
-
import { parse, visit } from "@solidity-parser/parser";
|
|
522
|
+
import { parse, visit as visit3 } from "@solidity-parser/parser";
|
|
523
|
+
|
|
524
|
+
// src/codegen/utils/findContractNode.ts
|
|
525
|
+
import { visit } from "@solidity-parser/parser";
|
|
526
|
+
function findContractNode(ast, contractName) {
|
|
527
|
+
let contract = void 0;
|
|
528
|
+
visit(ast, {
|
|
529
|
+
ContractDefinition(node) {
|
|
530
|
+
if (node.name === contractName) {
|
|
531
|
+
contract = node;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
return contract;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// src/codegen/utils/findSymbolImport.ts
|
|
539
|
+
import { visit as visit2 } from "@solidity-parser/parser";
|
|
540
|
+
function findSymbolImport(ast, symbol) {
|
|
541
|
+
let symbolImport;
|
|
542
|
+
visit2(ast, {
|
|
543
|
+
ImportDirective({ path: path3, symbolAliases }) {
|
|
544
|
+
if (symbolAliases) {
|
|
545
|
+
for (const symbolAndAlias of symbolAliases) {
|
|
546
|
+
const symbolAlias = symbolAndAlias[1] ?? symbolAndAlias[0];
|
|
547
|
+
if (symbol === symbolAlias) {
|
|
548
|
+
symbolImport = {
|
|
549
|
+
// always use the original symbol for interface imports
|
|
550
|
+
symbol: symbolAndAlias[0],
|
|
551
|
+
path: path3
|
|
552
|
+
};
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
return symbolImport;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// src/codegen/utils/contractToInterface.ts
|
|
524
563
|
function contractToInterface(source, contractName) {
|
|
525
564
|
const ast = parse(source);
|
|
526
565
|
const contractNode = findContractNode(ast, contractName);
|
|
@@ -530,7 +569,7 @@ function contractToInterface(source, contractName) {
|
|
|
530
569
|
if (!contractNode) {
|
|
531
570
|
throw new MUDError(`Contract not found: ${contractName}`);
|
|
532
571
|
}
|
|
533
|
-
|
|
572
|
+
visit3(contractNode, {
|
|
534
573
|
FunctionDefinition({
|
|
535
574
|
name,
|
|
536
575
|
visibility,
|
|
@@ -580,17 +619,6 @@ function contractToInterface(source, contractName) {
|
|
|
580
619
|
symbolImports
|
|
581
620
|
};
|
|
582
621
|
}
|
|
583
|
-
function findContractNode(ast, contractName) {
|
|
584
|
-
let contract = void 0;
|
|
585
|
-
visit(ast, {
|
|
586
|
-
ContractDefinition(node) {
|
|
587
|
-
if (node.name === contractName) {
|
|
588
|
-
contract = node;
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
});
|
|
592
|
-
return contract;
|
|
593
|
-
}
|
|
594
622
|
function parseParameter({ name, typeName, storageLocation }) {
|
|
595
623
|
let typedNameWithLocation = "";
|
|
596
624
|
const { name: flattenedTypeName, stateMutability } = flattenTypeName(typeName);
|
|
@@ -655,33 +683,11 @@ function typeNameToSymbols(typeName) {
|
|
|
655
683
|
}
|
|
656
684
|
}
|
|
657
685
|
function symbolsToImports(ast, symbols) {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
if (symbolAliases) {
|
|
664
|
-
for (const symbolAndAlias of symbolAliases) {
|
|
665
|
-
const symbolAlias = symbolAndAlias[1] || symbolAndAlias[0];
|
|
666
|
-
if (symbol === symbolAlias) {
|
|
667
|
-
symbolImport = {
|
|
668
|
-
// always use the original symbol for interface imports
|
|
669
|
-
symbol: symbolAndAlias[0],
|
|
670
|
-
path: path3
|
|
671
|
-
};
|
|
672
|
-
return;
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
});
|
|
678
|
-
if (symbolImport) {
|
|
679
|
-
imports.push(symbolImport);
|
|
680
|
-
} else {
|
|
681
|
-
throw new MUDError(`Symbol "${symbol}" has no explicit import`);
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
return imports;
|
|
686
|
+
return symbols.map((symbol) => {
|
|
687
|
+
const symbolImport = findSymbolImport(ast, symbol);
|
|
688
|
+
if (!symbolImport) throw new MUDError(`Symbol "${symbol}" has no explicit import`);
|
|
689
|
+
return symbolImport;
|
|
690
|
+
});
|
|
685
691
|
}
|
|
686
692
|
|
|
687
693
|
// src/codegen/utils/format.ts
|
|
@@ -731,10 +737,15 @@ debug2.log = console.debug.bind(console);
|
|
|
731
737
|
error.log = console.error.bind(console);
|
|
732
738
|
|
|
733
739
|
// src/codegen/utils/formatAndWrite.ts
|
|
734
|
-
async function formatAndWriteSolidity(
|
|
735
|
-
|
|
740
|
+
async function formatAndWriteSolidity(content, fullOutputPath, logPrefix) {
|
|
741
|
+
let output = content;
|
|
742
|
+
try {
|
|
743
|
+
output = await formatSolidity(output);
|
|
744
|
+
} catch (e) {
|
|
745
|
+
error(`Error while attempting to format ${fullOutputPath}`, e);
|
|
746
|
+
}
|
|
736
747
|
await fs.mkdir(path2.dirname(fullOutputPath), { recursive: true });
|
|
737
|
-
await fs.writeFile(fullOutputPath,
|
|
748
|
+
await fs.writeFile(fullOutputPath, output);
|
|
738
749
|
debug2(`${logPrefix}: ${fullOutputPath}`);
|
|
739
750
|
}
|
|
740
751
|
async function formatAndWriteTypescript(output, fullOutputPath, logPrefix) {
|
|
@@ -743,16 +754,43 @@ async function formatAndWriteTypescript(output, fullOutputPath, logPrefix) {
|
|
|
743
754
|
await fs.writeFile(fullOutputPath, formattedOutput);
|
|
744
755
|
debug2(`${logPrefix}: ${fullOutputPath}`);
|
|
745
756
|
}
|
|
757
|
+
|
|
758
|
+
// src/codegen/utils/parseSystem.ts
|
|
759
|
+
import { parse as parse2, visit as visit4 } from "@solidity-parser/parser";
|
|
760
|
+
var baseSystemName = "System";
|
|
761
|
+
var baseSystemPath = "@latticexyz/world/src/System.sol";
|
|
762
|
+
function parseSystem(source, contractName) {
|
|
763
|
+
const ast = parse2(source);
|
|
764
|
+
const contractNode = findContractNode(ast, contractName);
|
|
765
|
+
if (!contractNode) return;
|
|
766
|
+
const contractType = contractNode.kind;
|
|
767
|
+
if (contractType !== "contract" && contractType !== "abstract") return;
|
|
768
|
+
const isSystem = (() => {
|
|
769
|
+
if (contractName.endsWith("System") && contractName !== baseSystemName) return true;
|
|
770
|
+
let extendsBaseSystem = false;
|
|
771
|
+
visit4(contractNode, {
|
|
772
|
+
InheritanceSpecifier(node) {
|
|
773
|
+
if (node.baseName.namePath === baseSystemName) {
|
|
774
|
+
extendsBaseSystem = true;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
return extendsBaseSystem && findSymbolImport(ast, baseSystemName)?.path === baseSystemPath;
|
|
779
|
+
})();
|
|
780
|
+
if (isSystem) {
|
|
781
|
+
return { contractType };
|
|
782
|
+
}
|
|
783
|
+
}
|
|
746
784
|
export {
|
|
747
785
|
abiToInterface,
|
|
748
786
|
contractToInterface,
|
|
749
|
-
findContractNode,
|
|
750
787
|
formatAndWriteSolidity,
|
|
751
788
|
formatAndWriteTypescript,
|
|
752
789
|
formatSolidity,
|
|
753
790
|
formatTypescript,
|
|
754
791
|
getLeftPaddingBits,
|
|
755
792
|
isLeftAligned,
|
|
793
|
+
parseSystem,
|
|
756
794
|
renderArguments,
|
|
757
795
|
renderCommonData,
|
|
758
796
|
renderEnums,
|