@latticexyz/common 2.2.18-318924725246340b208d3fbee8793314686f1759 → 2.2.18-41fe36dd2756fe87bfe141e15b6d102f4b070ab1
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/actions.js +1 -39
- package/dist/actions.js.map +1 -1
- package/dist/chains.d.ts +6 -10
- package/dist/chains.js +1 -79
- package/dist/chains.js.map +1 -1
- package/dist/chunk-6FIKI2CG.js +2 -0
- package/dist/{chunk-5Q2OTK63.js.map → chunk-6FIKI2CG.js.map} +1 -1
- package/dist/chunk-DPUUE7NM.js +2 -0
- package/dist/{chunk-324BIDBP.js.map → chunk-DPUUE7NM.js.map} +1 -1
- package/dist/chunk-QQCZY3XJ.js +2 -0
- package/dist/{chunk-GRGLAPN2.js.map → chunk-QQCZY3XJ.js.map} +1 -1
- package/dist/chunk-TCWGPC6G.js +2 -0
- package/dist/{chunk-73UWXFXB.js.map → chunk-TCWGPC6G.js.map} +1 -1
- package/dist/chunk-ZIUX7JCQ.js +2 -0
- package/dist/{chunk-6Y3PYSE7.js.map → chunk-ZIUX7JCQ.js.map} +1 -1
- package/dist/chunk-ZV2KGJCD.js +2 -0
- package/dist/{chunk-CHXZROA7.js.map → chunk-ZV2KGJCD.js.map} +1 -1
- package/dist/codegen.js +49 -706
- package/dist/codegen.js.map +1 -1
- package/dist/errors.js +1 -6
- package/dist/foundry.js +2 -71
- package/dist/foundry.js.map +1 -1
- package/dist/index.js +1 -233
- package/dist/index.js.map +1 -1
- package/dist/internal.js +9 -205
- package/dist/internal.js.map +1 -1
- package/dist/kms.js +1 -168
- package/dist/kms.js.map +1 -1
- package/dist/utils.js +1 -122
- package/dist/utils.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-324BIDBP.js +0 -70
- package/dist/chunk-5Q2OTK63.js +0 -208
- package/dist/chunk-6Y3PYSE7.js +0 -64
- package/dist/chunk-73UWXFXB.js +0 -11
- package/dist/chunk-CHXZROA7.js +0 -16
- package/dist/chunk-GRGLAPN2.js +0 -12
package/dist/codegen.js
CHANGED
|
@@ -1,220 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
hexToResource,
|
|
3
|
-
resourceToHex
|
|
4
|
-
} from "./chunk-6Y3PYSE7.js";
|
|
5
|
-
import {
|
|
6
|
-
debug
|
|
7
|
-
} from "./chunk-73UWXFXB.js";
|
|
8
|
-
import {
|
|
9
|
-
MUDError
|
|
10
|
-
} from "./chunk-GRGLAPN2.js";
|
|
11
|
-
|
|
12
|
-
// src/codegen/render-solidity/abiToInterface.ts
|
|
13
|
-
import { formatAbiItem, formatAbiParameter } from "abitype";
|
|
14
|
-
|
|
15
|
-
// src/codegen/render-solidity/renderImportPath.ts
|
|
16
|
-
import path from "node:path";
|
|
17
|
-
function winToPosix(segment) {
|
|
18
|
-
return segment.replaceAll(path.win32.sep, path.posix.sep);
|
|
19
|
-
}
|
|
20
|
-
function renderImportPath(basePath, ...segments) {
|
|
21
|
-
const fullPath = path.posix.join(winToPosix(basePath), ...segments.map(winToPosix)).replace(/\/$/, "");
|
|
22
|
-
if (basePath.startsWith(".")) {
|
|
23
|
-
const relativePath = "./" + fullPath;
|
|
24
|
-
return relativePath.replace(/^(\.\/)+\./, ".");
|
|
25
|
-
}
|
|
26
|
-
return fullPath;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// src/codegen/render-solidity/common.ts
|
|
30
|
-
var renderedSolidityHeader = `// SPDX-License-Identifier: MIT
|
|
1
|
+
import{c as _,e as A}from"./chunk-ZIUX7JCQ.js";import{a as f}from"./chunk-TCWGPC6G.js";import{a as R}from"./chunk-QQCZY3XJ.js";import{formatAbiItem as H,formatAbiParameter as K}from"abitype";import B from"node:path";function b(t){return t.replaceAll(B.win32.sep,B.posix.sep)}function h(t,...r){let n=B.posix.join(b(t),...r.map(b)).replace(/\/$/,"");return t.startsWith(".")?("./"+n).replace(/^(\.\/)+\./,"."):n}var u=`// SPDX-License-Identifier: MIT
|
|
31
2
|
pragma solidity >=0.8.24;
|
|
32
3
|
|
|
33
|
-
/* Autogenerated file. Do not edit manually. */`;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
${
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
aggregatedImports.set(path3, /* @__PURE__ */ new Set());
|
|
62
|
-
}
|
|
63
|
-
aggregatedImports.get(path3)?.add(symbol);
|
|
64
|
-
}
|
|
65
|
-
const renderedImports = [];
|
|
66
|
-
for (const [path3, symbols] of aggregatedImports) {
|
|
67
|
-
const renderedSymbols = [...symbols].join(", ");
|
|
68
|
-
renderedImports.push(`import { ${renderedSymbols} } from "${renderImportPath(path3)}";`);
|
|
69
|
-
}
|
|
70
|
-
return renderedImports.join("\n");
|
|
71
|
-
}
|
|
72
|
-
function renderWithStore(storeArgument, callback) {
|
|
73
|
-
let result = "";
|
|
74
|
-
result += callback({ _typedStore: void 0, _store: "StoreSwitch", _commentSuffix: "", _methodNamePrefix: "" });
|
|
75
|
-
result += callback({
|
|
76
|
-
_typedStore: void 0,
|
|
77
|
-
_store: "StoreCore",
|
|
78
|
-
_commentSuffix: "",
|
|
79
|
-
_methodNamePrefix: "_",
|
|
80
|
-
_useExplicitFieldLayout: true
|
|
81
|
-
});
|
|
82
|
-
if (storeArgument) {
|
|
83
|
-
result += "\n" + callback({
|
|
84
|
-
_typedStore: "IStore _store",
|
|
85
|
-
_store: "_store",
|
|
86
|
-
_commentSuffix: " (using the specified store)",
|
|
87
|
-
_methodNamePrefix: ""
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
function renderWithFieldSuffix(withSuffixlessFieldMethods, fieldName, callback) {
|
|
93
|
-
const methodNameSuffix = `${fieldName[0].toUpperCase()}${fieldName.slice(1)}`;
|
|
94
|
-
let result = "";
|
|
95
|
-
result += callback(methodNameSuffix);
|
|
96
|
-
if (withSuffixlessFieldMethods) {
|
|
97
|
-
result += "\n" + callback("");
|
|
98
|
-
}
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
function renderTableId({
|
|
102
|
-
namespace,
|
|
103
|
-
name,
|
|
104
|
-
offchainOnly
|
|
105
|
-
}) {
|
|
106
|
-
const tableId = resourceToHex({
|
|
107
|
-
type: offchainOnly ? "offchainTable" : "table",
|
|
108
|
-
namespace,
|
|
109
|
-
name
|
|
110
|
-
});
|
|
111
|
-
const resource = hexToResource(tableId);
|
|
112
|
-
return `
|
|
113
|
-
// Hex below is the result of \`WorldResourceIdLib.encode({ namespace: ${JSON.stringify(
|
|
114
|
-
resource.namespace
|
|
115
|
-
)}, name: ${JSON.stringify(resource.name)}, typeId: ${offchainOnly ? "RESOURCE_OFFCHAIN_TABLE" : "RESOURCE_TABLE"} });\`
|
|
116
|
-
ResourceId constant _tableId = ResourceId.wrap(${tableId});
|
|
117
|
-
`;
|
|
118
|
-
}
|
|
119
|
-
function renderValueTypeToBytes32(name, { typeUnwrap, internalTypeId }) {
|
|
120
|
-
const innerText = typeUnwrap.length ? `${typeUnwrap}(${name})` : name;
|
|
121
|
-
if (internalTypeId === "bytes32") {
|
|
122
|
-
return innerText;
|
|
123
|
-
} else if (/^bytes\d{1,2}$/.test(internalTypeId)) {
|
|
124
|
-
return `bytes32(${innerText})`;
|
|
125
|
-
} else if (/^uint\d{1,3}$/.test(internalTypeId)) {
|
|
126
|
-
return `bytes32(uint256(${innerText}))`;
|
|
127
|
-
} else if (/^int\d{1,3}$/.test(internalTypeId)) {
|
|
128
|
-
return `bytes32(uint256(int256(${innerText})))`;
|
|
129
|
-
} else if (internalTypeId === "address") {
|
|
130
|
-
return `bytes32(uint256(uint160(${innerText})))`;
|
|
131
|
-
} else if (internalTypeId === "bool") {
|
|
132
|
-
return `_boolToBytes32(${innerText})`;
|
|
133
|
-
} else {
|
|
134
|
-
throw new Error(`Unknown value type id ${internalTypeId}`);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
function isLeftAligned(field) {
|
|
138
|
-
return /^bytes\d{1,2}$/.test(field.internalTypeId);
|
|
139
|
-
}
|
|
140
|
-
function getLeftPaddingBits(field) {
|
|
141
|
-
if (isLeftAligned(field)) {
|
|
142
|
-
return 0;
|
|
143
|
-
} else {
|
|
144
|
-
return 256 - field.staticByteLength * 8;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
function internalRenderList(lineTerminator, list, renderItem) {
|
|
148
|
-
return list.map((item, index) => renderItem(item, index) + (index === list.length - 1 ? "" : lineTerminator)).join("\n");
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// src/codegen/render-solidity/abiToInterface.ts
|
|
152
|
-
function formatParam(param) {
|
|
153
|
-
return formatAbiParameter(param);
|
|
154
|
-
}
|
|
155
|
-
function formatFunction(item) {
|
|
156
|
-
const params = item.inputs.map(formatParam).join(", ");
|
|
157
|
-
const returns = item.outputs.map(formatParam).join(", ");
|
|
158
|
-
return `function ${item.name}(${params}) external${returns.length ? ` returns (${returns})` : ""}`;
|
|
159
|
-
}
|
|
160
|
-
function formatSystemId(systemId) {
|
|
161
|
-
const resource = hexToResource(systemId);
|
|
162
|
-
return `
|
|
163
|
-
// equivalent to \`WorldResourceIdLib.encode({ namespace: ${JSON.stringify(
|
|
164
|
-
resource.namespace
|
|
165
|
-
)}, name: ${JSON.stringify(resource.name)}, typeId: RESOURCE_SYSTEM });\`
|
|
166
|
-
ResourceId constant systemId = ResourceId.wrap(${systemId});
|
|
167
|
-
`;
|
|
168
|
-
}
|
|
169
|
-
function abiToInterface({ name, systemId, abi }) {
|
|
170
|
-
const imports = systemId ? [`{ ResourceId } from "@latticexyz/store/src/ResourceId.sol"`] : [];
|
|
171
|
-
const errors = abi.filter((item) => item.type === "error");
|
|
172
|
-
const functions = abi.filter((item) => item.type === "function");
|
|
173
|
-
return `
|
|
174
|
-
${renderedSolidityHeader}
|
|
175
|
-
|
|
176
|
-
${imports.map((item) => `import ${item};`).join("\n")}
|
|
177
|
-
|
|
178
|
-
${systemId ? formatSystemId(systemId) : ""}
|
|
179
|
-
|
|
180
|
-
interface ${name} {
|
|
181
|
-
${errors.map((item) => `${formatAbiItem(item)};`).join("\n")}
|
|
182
|
-
|
|
183
|
-
${functions.map((item) => {
|
|
184
|
-
if ([...item.inputs, ...item.outputs].some((param) => param.type.startsWith("tuple"))) {
|
|
185
|
-
return `// TODO: replace tuple with struct
|
|
186
|
-
// ${formatFunction(item)};`;
|
|
187
|
-
}
|
|
188
|
-
return `${formatFunction(item)};`;
|
|
189
|
-
}).join("\n")}
|
|
4
|
+
/* Autogenerated file. Do not edit manually. */`;function L(t,r){return E("",t,r)}function O(t){let r=t.filter(n=>n!==void 0&&n!=="");return E(",",r,n=>n)}function se({staticResourceData:t,keyTuple:r}){let n=t?"":"ResourceId _tableId",i=O(r.map(({name:a,typeWithLocation:o})=>`${o} ${a}`)),s=`
|
|
5
|
+
bytes32[] memory _keyTuple = new bytes32[](${r.length});
|
|
6
|
+
${L(r,(a,o)=>`_keyTuple[${o}] = ${j(a.name,a)};`)}
|
|
7
|
+
`;return{_typedTableId:n,_typedKeyArgs:i,_keyTupleDefinition:s}}function oe(t){let r=new Map;for(let{symbol:i,path:s}of t)r.has(s)||r.set(s,new Set),r.get(s)?.add(i);let n=[];for(let[i,s]of r){let a=[...s].join(", ");n.push(`import { ${a} } from "${h(i)}";`)}return n.join(`
|
|
8
|
+
`)}function ae(t,r){let n="";return n+=r({_typedStore:void 0,_store:"StoreSwitch",_commentSuffix:"",_methodNamePrefix:""}),n+=r({_typedStore:void 0,_store:"StoreCore",_commentSuffix:"",_methodNamePrefix:"_",_useExplicitFieldLayout:!0}),t&&(n+=`
|
|
9
|
+
`+r({_typedStore:"IStore _store",_store:"_store",_commentSuffix:" (using the specified store)",_methodNamePrefix:""})),n}function ye(t,r,n){let i=`${r[0].toUpperCase()}${r.slice(1)}`,s="";return s+=n(i),t&&(s+=`
|
|
10
|
+
`+n("")),s}function ce({namespace:t,name:r,offchainOnly:n}){let i=_({type:n?"offchainTable":"table",namespace:t,name:r}),s=A(i);return`
|
|
11
|
+
// Hex below is the result of \`WorldResourceIdLib.encode({ namespace: ${JSON.stringify(s.namespace)}, name: ${JSON.stringify(s.name)}, typeId: ${n?"RESOURCE_OFFCHAIN_TABLE":"RESOURCE_TABLE"} });\`
|
|
12
|
+
ResourceId constant _tableId = ResourceId.wrap(${i});
|
|
13
|
+
`}function j(t,{typeUnwrap:r,internalTypeId:n}){let i=r.length?`${r}(${t})`:t;if(n==="bytes32")return i;if(/^bytes\d{1,2}$/.test(n))return`bytes32(${i})`;if(/^uint\d{1,3}$/.test(n))return`bytes32(uint256(${i}))`;if(/^int\d{1,3}$/.test(n))return`bytes32(uint256(int256(${i})))`;if(n==="address")return`bytes32(uint256(uint160(${i})))`;if(n==="bool")return`_boolToBytes32(${i})`;throw new Error(`Unknown value type id ${n}`)}function k(t){return/^bytes\d{1,2}$/.test(t.internalTypeId)}function Te(t){return k(t)?0:256-t.staticByteLength*8}function E(t,r,n){return r.map((i,s)=>n(i,s)+(s===r.length-1?"":t)).join(`
|
|
14
|
+
`)}function U(t){return K(t)}function $(t){let r=t.inputs.map(U).join(", "),n=t.outputs.map(U).join(", ");return`function ${t.name}(${r}) external${n.length?` returns (${n})`:""}`}function J(t){let r=A(t);return`
|
|
15
|
+
// equivalent to \`WorldResourceIdLib.encode({ namespace: ${JSON.stringify(r.namespace)}, name: ${JSON.stringify(r.name)}, typeId: RESOURCE_SYSTEM });\`
|
|
16
|
+
ResourceId constant systemId = ResourceId.wrap(${t});
|
|
17
|
+
`}function le({name:t,systemId:r,abi:n}){let i=r?['{ ResourceId } from "@latticexyz/store/src/ResourceId.sol"']:[],s=n.filter(o=>o.type==="error"),a=n.filter(o=>o.type==="function");return`
|
|
18
|
+
${u}
|
|
19
|
+
|
|
20
|
+
${i.map(o=>`import ${o};`).join(`
|
|
21
|
+
`)}
|
|
22
|
+
|
|
23
|
+
${r?J(r):""}
|
|
24
|
+
|
|
25
|
+
interface ${t} {
|
|
26
|
+
${s.map(o=>`${H(o)};`).join(`
|
|
27
|
+
`)}
|
|
28
|
+
|
|
29
|
+
${a.map(o=>[...o.inputs,...o.outputs].some(y=>y.type.startsWith("tuple"))?`// TODO: replace tuple with struct
|
|
30
|
+
// ${$(o)};`:`${$(o)};`).join(`
|
|
31
|
+
`)}
|
|
190
32
|
}
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// src/codegen/render-solidity/renderEnums.ts
|
|
195
|
-
function renderEnums(enums) {
|
|
196
|
-
const enumDefinitions = Object.entries(enums).map(
|
|
197
|
-
([name, values]) => `
|
|
198
|
-
enum ${name} {
|
|
199
|
-
${values.join(", ")}
|
|
33
|
+
`}function de(t){let r=Object.entries(t).map(([n,i])=>`
|
|
34
|
+
enum ${n} {
|
|
35
|
+
${i.join(", ")}
|
|
200
36
|
}
|
|
201
|
-
`
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
${enumDefinitions.join("")}
|
|
206
|
-
`;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// src/codegen/render-solidity/renderTypeHelpers.ts
|
|
210
|
-
function renderTypeHelpers(options) {
|
|
211
|
-
const { fields, keyTuple } = options;
|
|
212
|
-
let result = "";
|
|
213
|
-
for (const wrappingHelper of getWrappingHelpers([...fields, ...keyTuple])) {
|
|
214
|
-
result += wrappingHelper;
|
|
215
|
-
}
|
|
216
|
-
if (fields.some(({ internalTypeId }) => internalTypeId.match("bool"))) {
|
|
217
|
-
result += `
|
|
37
|
+
`);return`
|
|
38
|
+
${u}
|
|
39
|
+
${r.join("")}
|
|
40
|
+
`}function Ne(t){let{fields:r,keyTuple:n}=t,i="";for(let s of V([...r,...n]))i+=s;return r.some(({internalTypeId:s})=>s.match("bool"))&&(i+=`
|
|
218
41
|
/**
|
|
219
42
|
* @notice Cast a value to a bool.
|
|
220
43
|
* @dev Boolean values are encoded as uint8 (1 = true, 0 = false), but Solidity doesn't allow casting between uint8 and bool.
|
|
@@ -226,10 +49,7 @@ function renderTypeHelpers(options) {
|
|
|
226
49
|
result := value
|
|
227
50
|
}
|
|
228
51
|
}
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
if (keyTuple.some(({ internalTypeId }) => internalTypeId.match("bool"))) {
|
|
232
|
-
result += `
|
|
52
|
+
`),n.some(({internalTypeId:s})=>s.match("bool"))&&(i+=`
|
|
233
53
|
/**
|
|
234
54
|
* @notice Cast a bool to a bytes32.
|
|
235
55
|
* @dev The boolean value is casted to a bytes32 value with 0 or 1 at the least significant bit.
|
|
@@ -239,26 +59,7 @@ function renderTypeHelpers(options) {
|
|
|
239
59
|
result := value
|
|
240
60
|
}
|
|
241
61
|
}
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
return result;
|
|
245
|
-
}
|
|
246
|
-
function getWrappingHelpers(array) {
|
|
247
|
-
const wrappers = /* @__PURE__ */ new Map();
|
|
248
|
-
const unwrappers = /* @__PURE__ */ new Map();
|
|
249
|
-
for (const { typeWrappingData, typeWrap, typeUnwrap, internalTypeId } of array) {
|
|
250
|
-
if (!typeWrappingData) continue;
|
|
251
|
-
const { kind } = typeWrappingData;
|
|
252
|
-
if (kind === "staticArray") {
|
|
253
|
-
const { elementType, staticLength } = typeWrappingData;
|
|
254
|
-
wrappers.set(typeWrap, renderWrapperStaticArray(typeWrap, elementType, staticLength, internalTypeId));
|
|
255
|
-
unwrappers.set(typeUnwrap, renderUnwrapperStaticArray(typeUnwrap, elementType, staticLength, internalTypeId));
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return [...wrappers.values(), ...unwrappers.values()];
|
|
259
|
-
}
|
|
260
|
-
function renderWrapperStaticArray(functionName, elementType, staticLength, internalTypeId) {
|
|
261
|
-
return `
|
|
62
|
+
`),i}function V(t){let r=new Map,n=new Map;for(let{typeWrappingData:i,typeWrap:s,typeUnwrap:a,internalTypeId:o}of t){if(!i)continue;let{kind:y}=i;if(y==="staticArray"){let{elementType:c,staticLength:T}=i;r.set(s,z(s,c,T,o)),n.set(a,q(a,c,T,o))}}return[...r.values(),...n.values()]}function z(t,r,n,i){return`
|
|
262
63
|
/**
|
|
263
64
|
* @notice Cast a dynamic array to a static array.
|
|
264
65
|
* @dev In memory static arrays are just dynamic arrays without the 32 length bytes,
|
|
@@ -268,12 +69,12 @@ function renderWrapperStaticArray(functionName, elementType, staticLength, inter
|
|
|
268
69
|
* @param _value The dynamic array to cast.
|
|
269
70
|
* @return _result The static array.
|
|
270
71
|
*/
|
|
271
|
-
function ${
|
|
272
|
-
${
|
|
72
|
+
function ${t}(
|
|
73
|
+
${i} memory _value
|
|
273
74
|
) pure returns (
|
|
274
|
-
${
|
|
75
|
+
${r}[${n}] memory _result
|
|
275
76
|
) {
|
|
276
|
-
if (_value.length < ${
|
|
77
|
+
if (_value.length < ${n}) {
|
|
277
78
|
// return an uninitialized array if the length is smaller than the fixed length to avoid memory corruption
|
|
278
79
|
return _result;
|
|
279
80
|
} else {
|
|
@@ -284,484 +85,26 @@ function renderWrapperStaticArray(functionName, elementType, staticLength, inter
|
|
|
284
85
|
}
|
|
285
86
|
}
|
|
286
87
|
}
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
function renderUnwrapperStaticArray(functionName, elementType, staticLength, internalTypeId) {
|
|
290
|
-
const byteLength = staticLength * 32;
|
|
291
|
-
return `
|
|
88
|
+
`}function q(t,r,n,i){let s=n*32;return`
|
|
292
89
|
/**
|
|
293
90
|
* @notice Copy a static array to a dynamic array.
|
|
294
91
|
* @dev Static arrays don't have a length prefix, so this function copies the memory from the static array to a new dynamic array.
|
|
295
92
|
* @param _value The static array to copy.
|
|
296
93
|
* @return _result The dynamic array.
|
|
297
94
|
*/
|
|
298
|
-
function ${
|
|
299
|
-
${
|
|
95
|
+
function ${t}(
|
|
96
|
+
${r}[${n}] memory _value
|
|
300
97
|
) pure returns (
|
|
301
|
-
${
|
|
98
|
+
${i} memory _result
|
|
302
99
|
) {
|
|
303
|
-
_result = new ${
|
|
100
|
+
_result = new ${i}(${n});
|
|
304
101
|
uint256 fromPointer;
|
|
305
102
|
uint256 toPointer;
|
|
306
103
|
assembly {
|
|
307
104
|
fromPointer := _value
|
|
308
105
|
toPointer := add(_result, 0x20)
|
|
309
106
|
}
|
|
310
|
-
Memory.copy(fromPointer, toPointer, ${
|
|
311
|
-
}
|
|
312
|
-
`;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
// src/codegen/render-typescript/schemaTypesToRecsTypeStrings.ts
|
|
316
|
-
import { SchemaType } from "@latticexyz/schema-type/deprecated";
|
|
317
|
-
var schemaTypesToRecsTypeStrings = {
|
|
318
|
-
[SchemaType.UINT8]: "RecsType.Number",
|
|
319
|
-
[SchemaType.UINT16]: "RecsType.Number",
|
|
320
|
-
[SchemaType.UINT24]: "RecsType.Number",
|
|
321
|
-
[SchemaType.UINT32]: "RecsType.Number",
|
|
322
|
-
[SchemaType.UINT40]: "RecsType.Number",
|
|
323
|
-
[SchemaType.UINT48]: "RecsType.Number",
|
|
324
|
-
[SchemaType.UINT56]: "RecsType.BigInt",
|
|
325
|
-
[SchemaType.UINT64]: "RecsType.BigInt",
|
|
326
|
-
[SchemaType.UINT72]: "RecsType.BigInt",
|
|
327
|
-
[SchemaType.UINT80]: "RecsType.BigInt",
|
|
328
|
-
[SchemaType.UINT88]: "RecsType.BigInt",
|
|
329
|
-
[SchemaType.UINT96]: "RecsType.BigInt",
|
|
330
|
-
[SchemaType.UINT104]: "RecsType.BigInt",
|
|
331
|
-
[SchemaType.UINT112]: "RecsType.BigInt",
|
|
332
|
-
[SchemaType.UINT120]: "RecsType.BigInt",
|
|
333
|
-
[SchemaType.UINT128]: "RecsType.BigInt",
|
|
334
|
-
[SchemaType.UINT136]: "RecsType.BigInt",
|
|
335
|
-
[SchemaType.UINT144]: "RecsType.BigInt",
|
|
336
|
-
[SchemaType.UINT152]: "RecsType.BigInt",
|
|
337
|
-
[SchemaType.UINT160]: "RecsType.BigInt",
|
|
338
|
-
[SchemaType.UINT168]: "RecsType.BigInt",
|
|
339
|
-
[SchemaType.UINT176]: "RecsType.BigInt",
|
|
340
|
-
[SchemaType.UINT184]: "RecsType.BigInt",
|
|
341
|
-
[SchemaType.UINT192]: "RecsType.BigInt",
|
|
342
|
-
[SchemaType.UINT200]: "RecsType.BigInt",
|
|
343
|
-
[SchemaType.UINT208]: "RecsType.BigInt",
|
|
344
|
-
[SchemaType.UINT216]: "RecsType.BigInt",
|
|
345
|
-
[SchemaType.UINT224]: "RecsType.BigInt",
|
|
346
|
-
[SchemaType.UINT232]: "RecsType.BigInt",
|
|
347
|
-
[SchemaType.UINT240]: "RecsType.BigInt",
|
|
348
|
-
[SchemaType.UINT248]: "RecsType.BigInt",
|
|
349
|
-
[SchemaType.UINT256]: "RecsType.BigInt",
|
|
350
|
-
[SchemaType.INT8]: "RecsType.Number",
|
|
351
|
-
[SchemaType.INT16]: "RecsType.Number",
|
|
352
|
-
[SchemaType.INT24]: "RecsType.Number",
|
|
353
|
-
[SchemaType.INT32]: "RecsType.Number",
|
|
354
|
-
[SchemaType.INT40]: "RecsType.Number",
|
|
355
|
-
[SchemaType.INT48]: "RecsType.Number",
|
|
356
|
-
[SchemaType.INT56]: "RecsType.BigInt",
|
|
357
|
-
[SchemaType.INT64]: "RecsType.BigInt",
|
|
358
|
-
[SchemaType.INT72]: "RecsType.BigInt",
|
|
359
|
-
[SchemaType.INT80]: "RecsType.BigInt",
|
|
360
|
-
[SchemaType.INT88]: "RecsType.BigInt",
|
|
361
|
-
[SchemaType.INT96]: "RecsType.BigInt",
|
|
362
|
-
[SchemaType.INT104]: "RecsType.BigInt",
|
|
363
|
-
[SchemaType.INT112]: "RecsType.BigInt",
|
|
364
|
-
[SchemaType.INT120]: "RecsType.BigInt",
|
|
365
|
-
[SchemaType.INT128]: "RecsType.BigInt",
|
|
366
|
-
[SchemaType.INT136]: "RecsType.BigInt",
|
|
367
|
-
[SchemaType.INT144]: "RecsType.BigInt",
|
|
368
|
-
[SchemaType.INT152]: "RecsType.BigInt",
|
|
369
|
-
[SchemaType.INT160]: "RecsType.BigInt",
|
|
370
|
-
[SchemaType.INT168]: "RecsType.BigInt",
|
|
371
|
-
[SchemaType.INT176]: "RecsType.BigInt",
|
|
372
|
-
[SchemaType.INT184]: "RecsType.BigInt",
|
|
373
|
-
[SchemaType.INT192]: "RecsType.BigInt",
|
|
374
|
-
[SchemaType.INT200]: "RecsType.BigInt",
|
|
375
|
-
[SchemaType.INT208]: "RecsType.BigInt",
|
|
376
|
-
[SchemaType.INT216]: "RecsType.BigInt",
|
|
377
|
-
[SchemaType.INT224]: "RecsType.BigInt",
|
|
378
|
-
[SchemaType.INT232]: "RecsType.BigInt",
|
|
379
|
-
[SchemaType.INT240]: "RecsType.BigInt",
|
|
380
|
-
[SchemaType.INT248]: "RecsType.BigInt",
|
|
381
|
-
[SchemaType.INT256]: "RecsType.BigInt",
|
|
382
|
-
[SchemaType.BYTES1]: "RecsType.String",
|
|
383
|
-
[SchemaType.BYTES2]: "RecsType.String",
|
|
384
|
-
[SchemaType.BYTES3]: "RecsType.String",
|
|
385
|
-
[SchemaType.BYTES4]: "RecsType.String",
|
|
386
|
-
[SchemaType.BYTES5]: "RecsType.String",
|
|
387
|
-
[SchemaType.BYTES6]: "RecsType.String",
|
|
388
|
-
[SchemaType.BYTES7]: "RecsType.String",
|
|
389
|
-
[SchemaType.BYTES8]: "RecsType.String",
|
|
390
|
-
[SchemaType.BYTES9]: "RecsType.String",
|
|
391
|
-
[SchemaType.BYTES10]: "RecsType.String",
|
|
392
|
-
[SchemaType.BYTES11]: "RecsType.String",
|
|
393
|
-
[SchemaType.BYTES12]: "RecsType.String",
|
|
394
|
-
[SchemaType.BYTES13]: "RecsType.String",
|
|
395
|
-
[SchemaType.BYTES14]: "RecsType.String",
|
|
396
|
-
[SchemaType.BYTES15]: "RecsType.String",
|
|
397
|
-
[SchemaType.BYTES16]: "RecsType.String",
|
|
398
|
-
[SchemaType.BYTES17]: "RecsType.String",
|
|
399
|
-
[SchemaType.BYTES18]: "RecsType.String",
|
|
400
|
-
[SchemaType.BYTES19]: "RecsType.String",
|
|
401
|
-
[SchemaType.BYTES20]: "RecsType.String",
|
|
402
|
-
[SchemaType.BYTES21]: "RecsType.String",
|
|
403
|
-
[SchemaType.BYTES22]: "RecsType.String",
|
|
404
|
-
[SchemaType.BYTES23]: "RecsType.String",
|
|
405
|
-
[SchemaType.BYTES24]: "RecsType.String",
|
|
406
|
-
[SchemaType.BYTES25]: "RecsType.String",
|
|
407
|
-
[SchemaType.BYTES26]: "RecsType.String",
|
|
408
|
-
[SchemaType.BYTES27]: "RecsType.String",
|
|
409
|
-
[SchemaType.BYTES28]: "RecsType.String",
|
|
410
|
-
[SchemaType.BYTES29]: "RecsType.String",
|
|
411
|
-
[SchemaType.BYTES30]: "RecsType.String",
|
|
412
|
-
[SchemaType.BYTES31]: "RecsType.String",
|
|
413
|
-
[SchemaType.BYTES32]: "RecsType.String",
|
|
414
|
-
[SchemaType.BOOL]: "RecsType.Boolean",
|
|
415
|
-
[SchemaType.ADDRESS]: "RecsType.String",
|
|
416
|
-
[SchemaType.UINT8_ARRAY]: "RecsType.NumberArray",
|
|
417
|
-
[SchemaType.UINT16_ARRAY]: "RecsType.NumberArray",
|
|
418
|
-
[SchemaType.UINT24_ARRAY]: "RecsType.NumberArray",
|
|
419
|
-
[SchemaType.UINT32_ARRAY]: "RecsType.NumberArray",
|
|
420
|
-
[SchemaType.UINT40_ARRAY]: "RecsType.NumberArray",
|
|
421
|
-
[SchemaType.UINT48_ARRAY]: "RecsType.NumberArray",
|
|
422
|
-
[SchemaType.UINT56_ARRAY]: "RecsType.BigIntArray",
|
|
423
|
-
[SchemaType.UINT64_ARRAY]: "RecsType.BigIntArray",
|
|
424
|
-
[SchemaType.UINT72_ARRAY]: "RecsType.BigIntArray",
|
|
425
|
-
[SchemaType.UINT80_ARRAY]: "RecsType.BigIntArray",
|
|
426
|
-
[SchemaType.UINT88_ARRAY]: "RecsType.BigIntArray",
|
|
427
|
-
[SchemaType.UINT96_ARRAY]: "RecsType.BigIntArray",
|
|
428
|
-
[SchemaType.UINT104_ARRAY]: "RecsType.BigIntArray",
|
|
429
|
-
[SchemaType.UINT112_ARRAY]: "RecsType.BigIntArray",
|
|
430
|
-
[SchemaType.UINT120_ARRAY]: "RecsType.BigIntArray",
|
|
431
|
-
[SchemaType.UINT128_ARRAY]: "RecsType.BigIntArray",
|
|
432
|
-
[SchemaType.UINT136_ARRAY]: "RecsType.BigIntArray",
|
|
433
|
-
[SchemaType.UINT144_ARRAY]: "RecsType.BigIntArray",
|
|
434
|
-
[SchemaType.UINT152_ARRAY]: "RecsType.BigIntArray",
|
|
435
|
-
[SchemaType.UINT160_ARRAY]: "RecsType.BigIntArray",
|
|
436
|
-
[SchemaType.UINT168_ARRAY]: "RecsType.BigIntArray",
|
|
437
|
-
[SchemaType.UINT176_ARRAY]: "RecsType.BigIntArray",
|
|
438
|
-
[SchemaType.UINT184_ARRAY]: "RecsType.BigIntArray",
|
|
439
|
-
[SchemaType.UINT192_ARRAY]: "RecsType.BigIntArray",
|
|
440
|
-
[SchemaType.UINT200_ARRAY]: "RecsType.BigIntArray",
|
|
441
|
-
[SchemaType.UINT208_ARRAY]: "RecsType.BigIntArray",
|
|
442
|
-
[SchemaType.UINT216_ARRAY]: "RecsType.BigIntArray",
|
|
443
|
-
[SchemaType.UINT224_ARRAY]: "RecsType.BigIntArray",
|
|
444
|
-
[SchemaType.UINT232_ARRAY]: "RecsType.BigIntArray",
|
|
445
|
-
[SchemaType.UINT240_ARRAY]: "RecsType.BigIntArray",
|
|
446
|
-
[SchemaType.UINT248_ARRAY]: "RecsType.BigIntArray",
|
|
447
|
-
[SchemaType.UINT256_ARRAY]: "RecsType.BigIntArray",
|
|
448
|
-
[SchemaType.INT8_ARRAY]: "RecsType.NumberArray",
|
|
449
|
-
[SchemaType.INT16_ARRAY]: "RecsType.NumberArray",
|
|
450
|
-
[SchemaType.INT24_ARRAY]: "RecsType.NumberArray",
|
|
451
|
-
[SchemaType.INT32_ARRAY]: "RecsType.NumberArray",
|
|
452
|
-
[SchemaType.INT40_ARRAY]: "RecsType.NumberArray",
|
|
453
|
-
[SchemaType.INT48_ARRAY]: "RecsType.NumberArray",
|
|
454
|
-
[SchemaType.INT56_ARRAY]: "RecsType.BigIntArray",
|
|
455
|
-
[SchemaType.INT64_ARRAY]: "RecsType.BigIntArray",
|
|
456
|
-
[SchemaType.INT72_ARRAY]: "RecsType.BigIntArray",
|
|
457
|
-
[SchemaType.INT80_ARRAY]: "RecsType.BigIntArray",
|
|
458
|
-
[SchemaType.INT88_ARRAY]: "RecsType.BigIntArray",
|
|
459
|
-
[SchemaType.INT96_ARRAY]: "RecsType.BigIntArray",
|
|
460
|
-
[SchemaType.INT104_ARRAY]: "RecsType.BigIntArray",
|
|
461
|
-
[SchemaType.INT112_ARRAY]: "RecsType.BigIntArray",
|
|
462
|
-
[SchemaType.INT120_ARRAY]: "RecsType.BigIntArray",
|
|
463
|
-
[SchemaType.INT128_ARRAY]: "RecsType.BigIntArray",
|
|
464
|
-
[SchemaType.INT136_ARRAY]: "RecsType.BigIntArray",
|
|
465
|
-
[SchemaType.INT144_ARRAY]: "RecsType.BigIntArray",
|
|
466
|
-
[SchemaType.INT152_ARRAY]: "RecsType.BigIntArray",
|
|
467
|
-
[SchemaType.INT160_ARRAY]: "RecsType.BigIntArray",
|
|
468
|
-
[SchemaType.INT168_ARRAY]: "RecsType.BigIntArray",
|
|
469
|
-
[SchemaType.INT176_ARRAY]: "RecsType.BigIntArray",
|
|
470
|
-
[SchemaType.INT184_ARRAY]: "RecsType.BigIntArray",
|
|
471
|
-
[SchemaType.INT192_ARRAY]: "RecsType.BigIntArray",
|
|
472
|
-
[SchemaType.INT200_ARRAY]: "RecsType.BigIntArray",
|
|
473
|
-
[SchemaType.INT208_ARRAY]: "RecsType.BigIntArray",
|
|
474
|
-
[SchemaType.INT216_ARRAY]: "RecsType.BigIntArray",
|
|
475
|
-
[SchemaType.INT224_ARRAY]: "RecsType.BigIntArray",
|
|
476
|
-
[SchemaType.INT232_ARRAY]: "RecsType.BigIntArray",
|
|
477
|
-
[SchemaType.INT240_ARRAY]: "RecsType.BigIntArray",
|
|
478
|
-
[SchemaType.INT248_ARRAY]: "RecsType.BigIntArray",
|
|
479
|
-
[SchemaType.INT256_ARRAY]: "RecsType.BigIntArray",
|
|
480
|
-
[SchemaType.BYTES1_ARRAY]: "RecsType.BigIntArray",
|
|
481
|
-
[SchemaType.BYTES2_ARRAY]: "RecsType.BigIntArray",
|
|
482
|
-
[SchemaType.BYTES3_ARRAY]: "RecsType.BigIntArray",
|
|
483
|
-
[SchemaType.BYTES4_ARRAY]: "RecsType.BigIntArray",
|
|
484
|
-
[SchemaType.BYTES5_ARRAY]: "RecsType.BigIntArray",
|
|
485
|
-
[SchemaType.BYTES6_ARRAY]: "RecsType.BigIntArray",
|
|
486
|
-
[SchemaType.BYTES7_ARRAY]: "RecsType.BigIntArray",
|
|
487
|
-
[SchemaType.BYTES8_ARRAY]: "RecsType.BigIntArray",
|
|
488
|
-
[SchemaType.BYTES9_ARRAY]: "RecsType.BigIntArray",
|
|
489
|
-
[SchemaType.BYTES10_ARRAY]: "RecsType.BigIntArray",
|
|
490
|
-
[SchemaType.BYTES11_ARRAY]: "RecsType.BigIntArray",
|
|
491
|
-
[SchemaType.BYTES12_ARRAY]: "RecsType.BigIntArray",
|
|
492
|
-
[SchemaType.BYTES13_ARRAY]: "RecsType.BigIntArray",
|
|
493
|
-
[SchemaType.BYTES14_ARRAY]: "RecsType.BigIntArray",
|
|
494
|
-
[SchemaType.BYTES15_ARRAY]: "RecsType.BigIntArray",
|
|
495
|
-
[SchemaType.BYTES16_ARRAY]: "RecsType.BigIntArray",
|
|
496
|
-
[SchemaType.BYTES17_ARRAY]: "RecsType.BigIntArray",
|
|
497
|
-
[SchemaType.BYTES18_ARRAY]: "RecsType.BigIntArray",
|
|
498
|
-
[SchemaType.BYTES19_ARRAY]: "RecsType.BigIntArray",
|
|
499
|
-
[SchemaType.BYTES20_ARRAY]: "RecsType.BigIntArray",
|
|
500
|
-
[SchemaType.BYTES21_ARRAY]: "RecsType.BigIntArray",
|
|
501
|
-
[SchemaType.BYTES22_ARRAY]: "RecsType.BigIntArray",
|
|
502
|
-
[SchemaType.BYTES23_ARRAY]: "RecsType.BigIntArray",
|
|
503
|
-
[SchemaType.BYTES24_ARRAY]: "RecsType.BigIntArray",
|
|
504
|
-
[SchemaType.BYTES25_ARRAY]: "RecsType.BigIntArray",
|
|
505
|
-
[SchemaType.BYTES26_ARRAY]: "RecsType.BigIntArray",
|
|
506
|
-
[SchemaType.BYTES27_ARRAY]: "RecsType.BigIntArray",
|
|
507
|
-
[SchemaType.BYTES28_ARRAY]: "RecsType.BigIntArray",
|
|
508
|
-
[SchemaType.BYTES29_ARRAY]: "RecsType.BigIntArray",
|
|
509
|
-
[SchemaType.BYTES30_ARRAY]: "RecsType.BigIntArray",
|
|
510
|
-
[SchemaType.BYTES31_ARRAY]: "RecsType.BigIntArray",
|
|
511
|
-
[SchemaType.BYTES32_ARRAY]: "RecsType.BigIntArray",
|
|
512
|
-
[SchemaType.BOOL_ARRAY]: "RecsType.T",
|
|
513
|
-
// no boolean array
|
|
514
|
-
[SchemaType.ADDRESS_ARRAY]: "RecsType.StringArray",
|
|
515
|
-
[SchemaType.BYTES]: "RecsType.String",
|
|
516
|
-
[SchemaType.STRING]: "RecsType.String"
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
// src/codegen/utils/contractToInterface.ts
|
|
520
|
-
import { parse, visit } from "@solidity-parser/parser";
|
|
521
|
-
function contractToInterface(source, contractName) {
|
|
522
|
-
const ast = parse(source);
|
|
523
|
-
const contractNode = findContractNode(ast, contractName);
|
|
524
|
-
let symbolImports = [];
|
|
525
|
-
const functions = [];
|
|
526
|
-
const errors = [];
|
|
527
|
-
if (!contractNode) {
|
|
528
|
-
throw new MUDError(`Contract not found: ${contractName}`);
|
|
529
|
-
}
|
|
530
|
-
visit(contractNode, {
|
|
531
|
-
FunctionDefinition({
|
|
532
|
-
name,
|
|
533
|
-
visibility,
|
|
534
|
-
parameters,
|
|
535
|
-
stateMutability,
|
|
536
|
-
returnParameters,
|
|
537
|
-
isConstructor,
|
|
538
|
-
isFallback,
|
|
539
|
-
isReceiveEther
|
|
540
|
-
}) {
|
|
541
|
-
try {
|
|
542
|
-
if (isConstructor || isFallback || isReceiveEther) return;
|
|
543
|
-
if (visibility === "default") throw new MUDError(`Visibility is not specified`);
|
|
544
|
-
if (visibility === "external" || visibility === "public") {
|
|
545
|
-
functions.push({
|
|
546
|
-
name: name === null ? "" : name,
|
|
547
|
-
parameters: parameters.map(parseParameter),
|
|
548
|
-
stateMutability: stateMutability || "",
|
|
549
|
-
returnParameters: returnParameters === null ? [] : returnParameters.map(parseParameter)
|
|
550
|
-
});
|
|
551
|
-
for (const { typeName } of parameters.concat(returnParameters ?? [])) {
|
|
552
|
-
const symbols = typeNameToSymbols(typeName);
|
|
553
|
-
symbolImports = symbolImports.concat(symbolsToImports(ast, symbols));
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
} catch (error2) {
|
|
557
|
-
if (error2 instanceof MUDError) {
|
|
558
|
-
error2.message = `Function "${name}" in contract "${contractName}": ${error2.message}`;
|
|
559
|
-
}
|
|
560
|
-
throw error2;
|
|
561
|
-
}
|
|
562
|
-
},
|
|
563
|
-
CustomErrorDefinition({ name, parameters }) {
|
|
564
|
-
errors.push({
|
|
565
|
-
name,
|
|
566
|
-
parameters: parameters.map(parseParameter)
|
|
567
|
-
});
|
|
568
|
-
for (const parameter of parameters) {
|
|
569
|
-
const symbols = typeNameToSymbols(parameter.typeName);
|
|
570
|
-
symbolImports = symbolImports.concat(symbolsToImports(ast, symbols));
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
});
|
|
574
|
-
return {
|
|
575
|
-
functions,
|
|
576
|
-
errors,
|
|
577
|
-
symbolImports
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
function findContractNode(ast, contractName) {
|
|
581
|
-
let contract = void 0;
|
|
582
|
-
visit(ast, {
|
|
583
|
-
ContractDefinition(node) {
|
|
584
|
-
if (node.name === contractName) {
|
|
585
|
-
contract = node;
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
});
|
|
589
|
-
return contract;
|
|
590
|
-
}
|
|
591
|
-
function parseParameter({ name, typeName, storageLocation }) {
|
|
592
|
-
let typedNameWithLocation = "";
|
|
593
|
-
const { name: flattenedTypeName, stateMutability } = flattenTypeName(typeName);
|
|
594
|
-
typedNameWithLocation += flattenedTypeName;
|
|
595
|
-
if (stateMutability !== null) {
|
|
596
|
-
typedNameWithLocation += ` ${stateMutability}`;
|
|
597
|
-
}
|
|
598
|
-
if (storageLocation !== null) {
|
|
599
|
-
typedNameWithLocation += ` ${storageLocation}`;
|
|
600
|
-
}
|
|
601
|
-
if (name !== null) {
|
|
602
|
-
typedNameWithLocation += ` ${name}`;
|
|
603
|
-
}
|
|
604
|
-
return typedNameWithLocation;
|
|
605
|
-
}
|
|
606
|
-
function flattenTypeName(typeName) {
|
|
607
|
-
if (typeName === null) {
|
|
608
|
-
return {
|
|
609
|
-
name: "",
|
|
610
|
-
stateMutability: null
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
if (typeName.type === "ElementaryTypeName") {
|
|
614
|
-
return {
|
|
615
|
-
name: typeName.name,
|
|
616
|
-
stateMutability: typeName.stateMutability
|
|
617
|
-
};
|
|
618
|
-
} else if (typeName.type === "UserDefinedTypeName") {
|
|
619
|
-
return {
|
|
620
|
-
name: typeName.namePath,
|
|
621
|
-
stateMutability: null
|
|
622
|
-
};
|
|
623
|
-
} else if (typeName.type === "ArrayTypeName") {
|
|
624
|
-
let length = "";
|
|
625
|
-
if (typeName.length?.type === "NumberLiteral") {
|
|
626
|
-
length = typeName.length.number;
|
|
627
|
-
} else if (typeName.length?.type === "Identifier") {
|
|
628
|
-
length = typeName.length.name;
|
|
629
|
-
}
|
|
630
|
-
const { name, stateMutability } = flattenTypeName(typeName.baseTypeName);
|
|
631
|
-
return {
|
|
632
|
-
name: `${name}[${length}]`,
|
|
633
|
-
stateMutability
|
|
634
|
-
};
|
|
635
|
-
} else {
|
|
636
|
-
throw new MUDError(`Invalid typeName.type ${typeName.type}`);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
function typeNameToSymbols(typeName) {
|
|
640
|
-
if (typeName?.type === "UserDefinedTypeName") {
|
|
641
|
-
const symbol = typeName.namePath.split(".")[0];
|
|
642
|
-
return [symbol];
|
|
643
|
-
} else if (typeName?.type === "ArrayTypeName") {
|
|
644
|
-
const symbols = typeNameToSymbols(typeName.baseTypeName);
|
|
645
|
-
if (typeName.length?.type === "Identifier") {
|
|
646
|
-
const innerTypeName = typeName.length.name;
|
|
647
|
-
symbols.push(innerTypeName.split(".")[0]);
|
|
648
|
-
}
|
|
649
|
-
return symbols;
|
|
650
|
-
} else {
|
|
651
|
-
return [];
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
function symbolsToImports(ast, symbols) {
|
|
655
|
-
const imports = [];
|
|
656
|
-
for (const symbol of symbols) {
|
|
657
|
-
let symbolImport;
|
|
658
|
-
visit(ast, {
|
|
659
|
-
ImportDirective({ path: path3, symbolAliases }) {
|
|
660
|
-
if (symbolAliases) {
|
|
661
|
-
for (const symbolAndAlias of symbolAliases) {
|
|
662
|
-
const symbolAlias = symbolAndAlias[1] || symbolAndAlias[0];
|
|
663
|
-
if (symbol === symbolAlias) {
|
|
664
|
-
symbolImport = {
|
|
665
|
-
// always use the original symbol for interface imports
|
|
666
|
-
symbol: symbolAndAlias[0],
|
|
667
|
-
path: path3
|
|
668
|
-
};
|
|
669
|
-
return;
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
});
|
|
675
|
-
if (symbolImport) {
|
|
676
|
-
imports.push(symbolImport);
|
|
677
|
-
} else {
|
|
678
|
-
throw new MUDError(`Symbol "${symbol}" has no explicit import`);
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
return imports;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
// src/codegen/utils/format.ts
|
|
685
|
-
import prettier from "prettier";
|
|
686
|
-
import prettierPluginSolidity from "prettier-plugin-solidity";
|
|
687
|
-
async function formatSolidity(content, prettierConfigPath) {
|
|
688
|
-
let config;
|
|
689
|
-
if (prettierConfigPath) {
|
|
690
|
-
config = await prettier.resolveConfig(prettierConfigPath);
|
|
691
|
-
}
|
|
692
|
-
try {
|
|
693
|
-
return prettier.format(content, {
|
|
694
|
-
plugins: [prettierPluginSolidity],
|
|
695
|
-
parser: "solidity-parse",
|
|
696
|
-
printWidth: 120,
|
|
697
|
-
semi: true,
|
|
698
|
-
tabWidth: 2,
|
|
699
|
-
useTabs: false,
|
|
700
|
-
bracketSpacing: true,
|
|
701
|
-
...config
|
|
702
|
-
});
|
|
703
|
-
} catch (error2) {
|
|
704
|
-
let message;
|
|
705
|
-
if (error2 instanceof Error) {
|
|
706
|
-
message = error2.message;
|
|
707
|
-
} else {
|
|
708
|
-
message = error2;
|
|
107
|
+
Memory.copy(fromPointer, toPointer, ${s});
|
|
709
108
|
}
|
|
710
|
-
console.log(`Error during output formatting: ${message}`);
|
|
711
|
-
return content;
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
async function formatTypescript(content) {
|
|
715
|
-
return prettier.format(content, {
|
|
716
|
-
parser: "typescript"
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
// src/codegen/utils/formatAndWrite.ts
|
|
721
|
-
import fs from "node:fs/promises";
|
|
722
|
-
import path2 from "node:path";
|
|
723
|
-
|
|
724
|
-
// src/codegen/debug.ts
|
|
725
|
-
var debug2 = debug.extend("codegen");
|
|
726
|
-
var error = debug.extend("codegen");
|
|
727
|
-
debug2.log = console.debug.bind(console);
|
|
728
|
-
error.log = console.error.bind(console);
|
|
729
|
-
|
|
730
|
-
// src/codegen/utils/formatAndWrite.ts
|
|
731
|
-
async function formatAndWriteSolidity(output, fullOutputPath, logPrefix) {
|
|
732
|
-
const formattedOutput = await formatSolidity(output);
|
|
733
|
-
await fs.mkdir(path2.dirname(fullOutputPath), { recursive: true });
|
|
734
|
-
await fs.writeFile(fullOutputPath, formattedOutput);
|
|
735
|
-
debug2(`${logPrefix}: ${fullOutputPath}`);
|
|
736
|
-
}
|
|
737
|
-
async function formatAndWriteTypescript(output, fullOutputPath, logPrefix) {
|
|
738
|
-
const formattedOutput = await formatTypescript(output);
|
|
739
|
-
await fs.mkdir(path2.dirname(fullOutputPath), { recursive: true });
|
|
740
|
-
await fs.writeFile(fullOutputPath, formattedOutput);
|
|
741
|
-
debug2(`${logPrefix}: ${fullOutputPath}`);
|
|
742
|
-
}
|
|
743
|
-
export {
|
|
744
|
-
abiToInterface,
|
|
745
|
-
contractToInterface,
|
|
746
|
-
findContractNode,
|
|
747
|
-
formatAndWriteSolidity,
|
|
748
|
-
formatAndWriteTypescript,
|
|
749
|
-
formatSolidity,
|
|
750
|
-
formatTypescript,
|
|
751
|
-
getLeftPaddingBits,
|
|
752
|
-
isLeftAligned,
|
|
753
|
-
renderArguments,
|
|
754
|
-
renderCommonData,
|
|
755
|
-
renderEnums,
|
|
756
|
-
renderImportPath,
|
|
757
|
-
renderImports,
|
|
758
|
-
renderList,
|
|
759
|
-
renderTableId,
|
|
760
|
-
renderTypeHelpers,
|
|
761
|
-
renderValueTypeToBytes32,
|
|
762
|
-
renderWithFieldSuffix,
|
|
763
|
-
renderWithStore,
|
|
764
|
-
renderedSolidityHeader,
|
|
765
|
-
schemaTypesToRecsTypeStrings
|
|
766
|
-
};
|
|
109
|
+
`}import{SchemaType as e}from"@latticexyz/schema-type/deprecated";var ve={[e.UINT8]:"RecsType.Number",[e.UINT16]:"RecsType.Number",[e.UINT24]:"RecsType.Number",[e.UINT32]:"RecsType.Number",[e.UINT40]:"RecsType.Number",[e.UINT48]:"RecsType.Number",[e.UINT56]:"RecsType.BigInt",[e.UINT64]:"RecsType.BigInt",[e.UINT72]:"RecsType.BigInt",[e.UINT80]:"RecsType.BigInt",[e.UINT88]:"RecsType.BigInt",[e.UINT96]:"RecsType.BigInt",[e.UINT104]:"RecsType.BigInt",[e.UINT112]:"RecsType.BigInt",[e.UINT120]:"RecsType.BigInt",[e.UINT128]:"RecsType.BigInt",[e.UINT136]:"RecsType.BigInt",[e.UINT144]:"RecsType.BigInt",[e.UINT152]:"RecsType.BigInt",[e.UINT160]:"RecsType.BigInt",[e.UINT168]:"RecsType.BigInt",[e.UINT176]:"RecsType.BigInt",[e.UINT184]:"RecsType.BigInt",[e.UINT192]:"RecsType.BigInt",[e.UINT200]:"RecsType.BigInt",[e.UINT208]:"RecsType.BigInt",[e.UINT216]:"RecsType.BigInt",[e.UINT224]:"RecsType.BigInt",[e.UINT232]:"RecsType.BigInt",[e.UINT240]:"RecsType.BigInt",[e.UINT248]:"RecsType.BigInt",[e.UINT256]:"RecsType.BigInt",[e.INT8]:"RecsType.Number",[e.INT16]:"RecsType.Number",[e.INT24]:"RecsType.Number",[e.INT32]:"RecsType.Number",[e.INT40]:"RecsType.Number",[e.INT48]:"RecsType.Number",[e.INT56]:"RecsType.BigInt",[e.INT64]:"RecsType.BigInt",[e.INT72]:"RecsType.BigInt",[e.INT80]:"RecsType.BigInt",[e.INT88]:"RecsType.BigInt",[e.INT96]:"RecsType.BigInt",[e.INT104]:"RecsType.BigInt",[e.INT112]:"RecsType.BigInt",[e.INT120]:"RecsType.BigInt",[e.INT128]:"RecsType.BigInt",[e.INT136]:"RecsType.BigInt",[e.INT144]:"RecsType.BigInt",[e.INT152]:"RecsType.BigInt",[e.INT160]:"RecsType.BigInt",[e.INT168]:"RecsType.BigInt",[e.INT176]:"RecsType.BigInt",[e.INT184]:"RecsType.BigInt",[e.INT192]:"RecsType.BigInt",[e.INT200]:"RecsType.BigInt",[e.INT208]:"RecsType.BigInt",[e.INT216]:"RecsType.BigInt",[e.INT224]:"RecsType.BigInt",[e.INT232]:"RecsType.BigInt",[e.INT240]:"RecsType.BigInt",[e.INT248]:"RecsType.BigInt",[e.INT256]:"RecsType.BigInt",[e.BYTES1]:"RecsType.String",[e.BYTES2]:"RecsType.String",[e.BYTES3]:"RecsType.String",[e.BYTES4]:"RecsType.String",[e.BYTES5]:"RecsType.String",[e.BYTES6]:"RecsType.String",[e.BYTES7]:"RecsType.String",[e.BYTES8]:"RecsType.String",[e.BYTES9]:"RecsType.String",[e.BYTES10]:"RecsType.String",[e.BYTES11]:"RecsType.String",[e.BYTES12]:"RecsType.String",[e.BYTES13]:"RecsType.String",[e.BYTES14]:"RecsType.String",[e.BYTES15]:"RecsType.String",[e.BYTES16]:"RecsType.String",[e.BYTES17]:"RecsType.String",[e.BYTES18]:"RecsType.String",[e.BYTES19]:"RecsType.String",[e.BYTES20]:"RecsType.String",[e.BYTES21]:"RecsType.String",[e.BYTES22]:"RecsType.String",[e.BYTES23]:"RecsType.String",[e.BYTES24]:"RecsType.String",[e.BYTES25]:"RecsType.String",[e.BYTES26]:"RecsType.String",[e.BYTES27]:"RecsType.String",[e.BYTES28]:"RecsType.String",[e.BYTES29]:"RecsType.String",[e.BYTES30]:"RecsType.String",[e.BYTES31]:"RecsType.String",[e.BYTES32]:"RecsType.String",[e.BOOL]:"RecsType.Boolean",[e.ADDRESS]:"RecsType.String",[e.UINT8_ARRAY]:"RecsType.NumberArray",[e.UINT16_ARRAY]:"RecsType.NumberArray",[e.UINT24_ARRAY]:"RecsType.NumberArray",[e.UINT32_ARRAY]:"RecsType.NumberArray",[e.UINT40_ARRAY]:"RecsType.NumberArray",[e.UINT48_ARRAY]:"RecsType.NumberArray",[e.UINT56_ARRAY]:"RecsType.BigIntArray",[e.UINT64_ARRAY]:"RecsType.BigIntArray",[e.UINT72_ARRAY]:"RecsType.BigIntArray",[e.UINT80_ARRAY]:"RecsType.BigIntArray",[e.UINT88_ARRAY]:"RecsType.BigIntArray",[e.UINT96_ARRAY]:"RecsType.BigIntArray",[e.UINT104_ARRAY]:"RecsType.BigIntArray",[e.UINT112_ARRAY]:"RecsType.BigIntArray",[e.UINT120_ARRAY]:"RecsType.BigIntArray",[e.UINT128_ARRAY]:"RecsType.BigIntArray",[e.UINT136_ARRAY]:"RecsType.BigIntArray",[e.UINT144_ARRAY]:"RecsType.BigIntArray",[e.UINT152_ARRAY]:"RecsType.BigIntArray",[e.UINT160_ARRAY]:"RecsType.BigIntArray",[e.UINT168_ARRAY]:"RecsType.BigIntArray",[e.UINT176_ARRAY]:"RecsType.BigIntArray",[e.UINT184_ARRAY]:"RecsType.BigIntArray",[e.UINT192_ARRAY]:"RecsType.BigIntArray",[e.UINT200_ARRAY]:"RecsType.BigIntArray",[e.UINT208_ARRAY]:"RecsType.BigIntArray",[e.UINT216_ARRAY]:"RecsType.BigIntArray",[e.UINT224_ARRAY]:"RecsType.BigIntArray",[e.UINT232_ARRAY]:"RecsType.BigIntArray",[e.UINT240_ARRAY]:"RecsType.BigIntArray",[e.UINT248_ARRAY]:"RecsType.BigIntArray",[e.UINT256_ARRAY]:"RecsType.BigIntArray",[e.INT8_ARRAY]:"RecsType.NumberArray",[e.INT16_ARRAY]:"RecsType.NumberArray",[e.INT24_ARRAY]:"RecsType.NumberArray",[e.INT32_ARRAY]:"RecsType.NumberArray",[e.INT40_ARRAY]:"RecsType.NumberArray",[e.INT48_ARRAY]:"RecsType.NumberArray",[e.INT56_ARRAY]:"RecsType.BigIntArray",[e.INT64_ARRAY]:"RecsType.BigIntArray",[e.INT72_ARRAY]:"RecsType.BigIntArray",[e.INT80_ARRAY]:"RecsType.BigIntArray",[e.INT88_ARRAY]:"RecsType.BigIntArray",[e.INT96_ARRAY]:"RecsType.BigIntArray",[e.INT104_ARRAY]:"RecsType.BigIntArray",[e.INT112_ARRAY]:"RecsType.BigIntArray",[e.INT120_ARRAY]:"RecsType.BigIntArray",[e.INT128_ARRAY]:"RecsType.BigIntArray",[e.INT136_ARRAY]:"RecsType.BigIntArray",[e.INT144_ARRAY]:"RecsType.BigIntArray",[e.INT152_ARRAY]:"RecsType.BigIntArray",[e.INT160_ARRAY]:"RecsType.BigIntArray",[e.INT168_ARRAY]:"RecsType.BigIntArray",[e.INT176_ARRAY]:"RecsType.BigIntArray",[e.INT184_ARRAY]:"RecsType.BigIntArray",[e.INT192_ARRAY]:"RecsType.BigIntArray",[e.INT200_ARRAY]:"RecsType.BigIntArray",[e.INT208_ARRAY]:"RecsType.BigIntArray",[e.INT216_ARRAY]:"RecsType.BigIntArray",[e.INT224_ARRAY]:"RecsType.BigIntArray",[e.INT232_ARRAY]:"RecsType.BigIntArray",[e.INT240_ARRAY]:"RecsType.BigIntArray",[e.INT248_ARRAY]:"RecsType.BigIntArray",[e.INT256_ARRAY]:"RecsType.BigIntArray",[e.BYTES1_ARRAY]:"RecsType.BigIntArray",[e.BYTES2_ARRAY]:"RecsType.BigIntArray",[e.BYTES3_ARRAY]:"RecsType.BigIntArray",[e.BYTES4_ARRAY]:"RecsType.BigIntArray",[e.BYTES5_ARRAY]:"RecsType.BigIntArray",[e.BYTES6_ARRAY]:"RecsType.BigIntArray",[e.BYTES7_ARRAY]:"RecsType.BigIntArray",[e.BYTES8_ARRAY]:"RecsType.BigIntArray",[e.BYTES9_ARRAY]:"RecsType.BigIntArray",[e.BYTES10_ARRAY]:"RecsType.BigIntArray",[e.BYTES11_ARRAY]:"RecsType.BigIntArray",[e.BYTES12_ARRAY]:"RecsType.BigIntArray",[e.BYTES13_ARRAY]:"RecsType.BigIntArray",[e.BYTES14_ARRAY]:"RecsType.BigIntArray",[e.BYTES15_ARRAY]:"RecsType.BigIntArray",[e.BYTES16_ARRAY]:"RecsType.BigIntArray",[e.BYTES17_ARRAY]:"RecsType.BigIntArray",[e.BYTES18_ARRAY]:"RecsType.BigIntArray",[e.BYTES19_ARRAY]:"RecsType.BigIntArray",[e.BYTES20_ARRAY]:"RecsType.BigIntArray",[e.BYTES21_ARRAY]:"RecsType.BigIntArray",[e.BYTES22_ARRAY]:"RecsType.BigIntArray",[e.BYTES23_ARRAY]:"RecsType.BigIntArray",[e.BYTES24_ARRAY]:"RecsType.BigIntArray",[e.BYTES25_ARRAY]:"RecsType.BigIntArray",[e.BYTES26_ARRAY]:"RecsType.BigIntArray",[e.BYTES27_ARRAY]:"RecsType.BigIntArray",[e.BYTES28_ARRAY]:"RecsType.BigIntArray",[e.BYTES29_ARRAY]:"RecsType.BigIntArray",[e.BYTES30_ARRAY]:"RecsType.BigIntArray",[e.BYTES31_ARRAY]:"RecsType.BigIntArray",[e.BYTES32_ARRAY]:"RecsType.BigIntArray",[e.BOOL_ARRAY]:"RecsType.T",[e.ADDRESS_ARRAY]:"RecsType.StringArray",[e.BYTES]:"RecsType.String",[e.STRING]:"RecsType.String"};import{parse as G,visit as N}from"@solidity-parser/parser";function Me(t,r){let n=G(t),i=X(n,r),s=[],a=[],o=[];if(!i)throw new R(`Contract not found: ${r}`);return N(i,{FunctionDefinition({name:y,visibility:c,parameters:T,stateMutability:m,returnParameters:l,isConstructor:P,isFallback:F,isReceiveEther:W}){try{if(P||F||W)return;if(c==="default")throw new R("Visibility is not specified");if(c==="external"||c==="public"){a.push({name:y===null?"":y,parameters:T.map(d),stateMutability:m||"",returnParameters:l===null?[]:l.map(d)});for(let{typeName:p}of T.concat(l??[])){let M=S(p);s=s.concat(x(n,M))}}}catch(p){throw p instanceof R&&(p.message=`Function "${y}" in contract "${r}": ${p.message}`),p}},CustomErrorDefinition({name:y,parameters:c}){o.push({name:y,parameters:c.map(d)});for(let T of c){let m=S(T.typeName);s=s.concat(x(n,m))}}}),{functions:a,errors:o,symbolImports:s}}function X(t,r){let n;return N(t,{ContractDefinition(i){i.name===r&&(n=i)}}),n}function d({name:t,typeName:r,storageLocation:n}){let i="",{name:s,stateMutability:a}=w(r);return i+=s,a!==null&&(i+=` ${a}`),n!==null&&(i+=` ${n}`),t!==null&&(i+=` ${t}`),i}function w(t){if(t===null)return{name:"",stateMutability:null};if(t.type==="ElementaryTypeName")return{name:t.name,stateMutability:t.stateMutability};if(t.type==="UserDefinedTypeName")return{name:t.namePath,stateMutability:null};if(t.type==="ArrayTypeName"){let r="";t.length?.type==="NumberLiteral"?r=t.length.number:t.length?.type==="Identifier"&&(r=t.length.name);let{name:n,stateMutability:i}=w(t.baseTypeName);return{name:`${n}[${r}]`,stateMutability:i}}else throw new R(`Invalid typeName.type ${t.type}`)}function S(t){if(t?.type==="UserDefinedTypeName")return[t.namePath.split(".")[0]];if(t?.type==="ArrayTypeName"){let r=S(t.baseTypeName);if(t.length?.type==="Identifier"){let n=t.length.name;r.push(n.split(".")[0])}return r}else return[]}function x(t,r){let n=[];for(let i of r){let s;if(N(t,{ImportDirective({path:a,symbolAliases:o}){if(o)for(let y of o){let c=y[1]||y[0];if(i===c){s={symbol:y[0],path:a};return}}}}),s)n.push(s);else throw new R(`Symbol "${i}" has no explicit import`)}return n}import Y from"prettier";import Q from"prettier-plugin-solidity";async function v(t,r){let n;r&&(n=await Y.resolveConfig(r));try{return Y.format(t,{plugins:[Q],parser:"solidity-parse",printWidth:120,semi:!0,tabWidth:2,useTabs:!1,bracketSpacing:!0,...n})}catch(i){let s;return i instanceof Error?s=i.message:s=i,console.log(`Error during output formatting: ${s}`),t}}async function D(t){return Y.format(t,{parser:"typescript"})}import I from"node:fs/promises";import C from"node:path";var g=f.extend("codegen"),Z=f.extend("codegen");g.log=console.debug.bind(console);Z.log=console.error.bind(console);async function Ge(t,r,n){let i=await v(t);await I.mkdir(C.dirname(r),{recursive:!0}),await I.writeFile(r,i),g(`${n}: ${r}`)}async function Xe(t,r,n){let i=await D(t);await I.mkdir(C.dirname(r),{recursive:!0}),await I.writeFile(r,i),g(`${n}: ${r}`)}export{le as abiToInterface,Me as contractToInterface,X as findContractNode,Ge as formatAndWriteSolidity,Xe as formatAndWriteTypescript,v as formatSolidity,D as formatTypescript,Te as getLeftPaddingBits,k as isLeftAligned,O as renderArguments,se as renderCommonData,de as renderEnums,h as renderImportPath,oe as renderImports,L as renderList,ce as renderTableId,Ne as renderTypeHelpers,j as renderValueTypeToBytes32,ye as renderWithFieldSuffix,ae as renderWithStore,u as renderedSolidityHeader,ve as schemaTypesToRecsTypeStrings};
|
|
767
110
|
//# sourceMappingURL=codegen.js.map
|