@latticexyz/world 2.2.18-90aac1d4acce19ac592d47a090732dd11c1c3e7a → 2.2.18-9fa07c8489f1fbf167d0db01cd9aaa645a29c8e2
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/IBaseWorld.abi-S745M2QE.js +2015 -0
- package/dist/{IBaseWorld.abi-SGUPOG6A.js.map → IBaseWorld.abi-S745M2QE.js.map} +1 -1
- package/dist/System.abi-UHI2DJK6.js +67 -0
- package/dist/{System.abi-D2D3OAI5.js.map → System.abi-UHI2DJK6.js.map} +1 -1
- package/dist/chunk-AAKXFFCU.js +158 -0
- package/dist/chunk-AAKXFFCU.js.map +1 -0
- package/dist/chunk-AAWFTQHP.js +35 -0
- package/dist/chunk-S5LARYWY.js +136 -0
- package/dist/{chunk-AJUHOWGE.js.map → chunk-S5LARYWY.js.map} +1 -1
- package/dist/chunk-TL2M3LZH.js +119 -0
- package/dist/{chunk-DIHBEOC2.js.map → chunk-TL2M3LZH.js.map} +1 -1
- package/dist/dynamicResolution-AmVd5Qtd.d.cts +161 -0
- package/dist/index.cjs +241 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.js +20 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.cjs +656 -0
- package/dist/internal.cjs.map +1 -0
- package/dist/internal.d.cts +169 -0
- package/dist/internal.js +318 -3
- package/dist/internal.js.map +1 -1
- package/dist/mud.config.cjs +357 -0
- package/dist/mud.config.cjs.map +1 -0
- package/dist/mud.config.d.cts +869 -0
- package/dist/mud.config.js +11 -1
- package/dist/node.cjs +9599 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +131 -0
- package/dist/node.js +7328 -102
- package/dist/node.js.map +1 -1
- package/dist/world-DUniZQxy.d.cts +266 -0
- package/package.json +49 -14
- package/dist/IBaseWorld.abi-SGUPOG6A.js +0 -2
- package/dist/System.abi-D2D3OAI5.js +0 -2
- package/dist/chunk-AJUHOWGE.js +0 -2
- package/dist/chunk-CGF3NYHC.js +0 -2
- package/dist/chunk-CGF3NYHC.js.map +0 -1
- package/dist/chunk-DIHBEOC2.js +0 -2
- package/dist/chunk-FW4363Y4.js +0 -2
- /package/dist/{chunk-FW4363Y4.js.map → chunk-AAWFTQHP.js.map} +0 -0
@@ -0,0 +1,656 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
|
20
|
+
// ts/exports/internal.ts
|
21
|
+
var internal_exports = {};
|
22
|
+
__export(internal_exports, {
|
23
|
+
CODEGEN_DEFAULTS: () => CODEGEN_DEFAULTS,
|
24
|
+
CONFIG_DEFAULTS: () => CONFIG_DEFAULTS,
|
25
|
+
DEPLOY_DEFAULTS: () => DEPLOY_DEFAULTS,
|
26
|
+
MODULE_DEFAULTS: () => MODULE_DEFAULTS,
|
27
|
+
SYSTEM_DEFAULTS: () => SYSTEM_DEFAULTS,
|
28
|
+
SYSTEM_DEPLOY_DEFAULTS: () => SYSTEM_DEPLOY_DEFAULTS,
|
29
|
+
callFrom: () => callFrom,
|
30
|
+
defineNamespaces: () => defineNamespaces,
|
31
|
+
defineSystem: () => defineSystem,
|
32
|
+
defineWorld: () => defineWorld,
|
33
|
+
encodeSystemCall: () => encodeSystemCall,
|
34
|
+
encodeSystemCallFrom: () => encodeSystemCallFrom,
|
35
|
+
encodeSystemCalls: () => encodeSystemCalls,
|
36
|
+
encodeSystemCallsFrom: () => encodeSystemCallsFrom,
|
37
|
+
isDynamicResolution: () => isDynamicResolution,
|
38
|
+
isValueWithType: () => isValueWithType,
|
39
|
+
resolveCodegen: () => resolveCodegen,
|
40
|
+
resolveDeploy: () => resolveDeploy,
|
41
|
+
resolveNamespace: () => resolveNamespace,
|
42
|
+
resolveNamespaces: () => resolveNamespaces,
|
43
|
+
resolveSystem: () => resolveSystem,
|
44
|
+
resolveSystems: () => resolveSystems,
|
45
|
+
resolveTableId: () => resolveTableId,
|
46
|
+
resolveWithContext: () => resolveWithContext,
|
47
|
+
resolveWorld: () => resolveWorld,
|
48
|
+
validateNamespace: () => validateNamespace,
|
49
|
+
validateNamespaces: () => validateNamespaces,
|
50
|
+
validateSystem: () => validateSystem,
|
51
|
+
validateSystems: () => validateSystems,
|
52
|
+
validateWorld: () => validateWorld
|
53
|
+
});
|
54
|
+
module.exports = __toCommonJS(internal_exports);
|
55
|
+
|
56
|
+
// ts/encodeSystemCall.ts
|
57
|
+
var import_viem = require("viem");
|
58
|
+
|
59
|
+
// ts/normalizeSystemFunctionName.ts
|
60
|
+
var import_common = require("@latticexyz/common");
|
61
|
+
function internal_normalizeSystemFunctionName(systemId, functionName) {
|
62
|
+
const resource = (0, import_common.hexToResource)(systemId);
|
63
|
+
const worldFunctionPrefix = resource.namespace !== "" ? `${resource.namespace}__` : null;
|
64
|
+
if (worldFunctionPrefix != null && functionName.startsWith(worldFunctionPrefix)) {
|
65
|
+
console.warn(
|
66
|
+
// eslint-disable-next-line max-len
|
67
|
+
`Detected world function name "${functionName}" used in call to system "${(0, import_common.resourceToLabel)(resource)}".
|
68
|
+
|
69
|
+
It's recommended to use a system ABI and system function name with these methods instead.`
|
70
|
+
);
|
71
|
+
return functionName.slice(worldFunctionPrefix.length);
|
72
|
+
}
|
73
|
+
return functionName;
|
74
|
+
}
|
75
|
+
|
76
|
+
// ts/encodeSystemCall.ts
|
77
|
+
function encodeSystemCall({
|
78
|
+
abi,
|
79
|
+
systemId,
|
80
|
+
functionName,
|
81
|
+
args
|
82
|
+
}) {
|
83
|
+
return [
|
84
|
+
systemId,
|
85
|
+
(0, import_viem.encodeFunctionData)({
|
86
|
+
abi,
|
87
|
+
functionName: internal_normalizeSystemFunctionName(systemId, functionName),
|
88
|
+
args
|
89
|
+
})
|
90
|
+
];
|
91
|
+
}
|
92
|
+
|
93
|
+
// ts/encodeSystemCallFrom.ts
|
94
|
+
var import_viem2 = require("viem");
|
95
|
+
function encodeSystemCallFrom({
|
96
|
+
abi,
|
97
|
+
from,
|
98
|
+
systemId,
|
99
|
+
functionName,
|
100
|
+
args
|
101
|
+
}) {
|
102
|
+
return [
|
103
|
+
from,
|
104
|
+
systemId,
|
105
|
+
(0, import_viem2.encodeFunctionData)({
|
106
|
+
abi,
|
107
|
+
functionName: internal_normalizeSystemFunctionName(systemId, functionName),
|
108
|
+
args
|
109
|
+
})
|
110
|
+
];
|
111
|
+
}
|
112
|
+
|
113
|
+
// ts/encodeSystemCalls.ts
|
114
|
+
var import_viem3 = require("viem");
|
115
|
+
function encodeSystemCalls(abi, systemCalls) {
|
116
|
+
return [
|
117
|
+
systemCalls.map(({ systemId, functionName, args }) => ({
|
118
|
+
systemId,
|
119
|
+
callData: (0, import_viem3.encodeFunctionData)({
|
120
|
+
abi,
|
121
|
+
functionName: internal_normalizeSystemFunctionName(systemId, functionName),
|
122
|
+
args
|
123
|
+
})
|
124
|
+
}))
|
125
|
+
];
|
126
|
+
}
|
127
|
+
|
128
|
+
// ts/encodeSystemCallsFrom.ts
|
129
|
+
var import_viem4 = require("viem");
|
130
|
+
function encodeSystemCallsFrom(abi, from, systemCalls) {
|
131
|
+
return [
|
132
|
+
systemCalls.map(({ systemId, functionName, args }) => ({
|
133
|
+
from,
|
134
|
+
systemId,
|
135
|
+
callData: (0, import_viem4.encodeFunctionData)({
|
136
|
+
abi,
|
137
|
+
functionName: internal_normalizeSystemFunctionName(systemId, functionName),
|
138
|
+
args
|
139
|
+
})
|
140
|
+
}))
|
141
|
+
];
|
142
|
+
}
|
143
|
+
|
144
|
+
// ts/actions/callFrom.ts
|
145
|
+
var import_viem5 = require("viem");
|
146
|
+
var import_utils2 = require("viem/utils");
|
147
|
+
var import_actions = require("viem/actions");
|
148
|
+
var import_common3 = require("@latticexyz/common");
|
149
|
+
var import_internal8 = require("@latticexyz/protocol-parser/internal");
|
150
|
+
|
151
|
+
// ts/config/v2/world.ts
|
152
|
+
var import_internal7 = require("@latticexyz/store/internal");
|
153
|
+
|
154
|
+
// ts/config/v2/defaults.ts
|
155
|
+
var SYSTEM_DEPLOY_DEFAULTS = {
|
156
|
+
disabled: false,
|
157
|
+
registerWorldFunctions: true
|
158
|
+
};
|
159
|
+
var SYSTEM_DEFAULTS = {
|
160
|
+
namespaceLabel: "",
|
161
|
+
openAccess: true,
|
162
|
+
accessList: []
|
163
|
+
};
|
164
|
+
var MODULE_DEFAULTS = {
|
165
|
+
root: false,
|
166
|
+
args: [],
|
167
|
+
artifactPath: void 0
|
168
|
+
};
|
169
|
+
var CODEGEN_DEFAULTS = {
|
170
|
+
worldInterfaceName: "IWorld",
|
171
|
+
worldgenDirectory: "world",
|
172
|
+
systemLibrariesDirectory: "systems",
|
173
|
+
generateSystemLibraries: false,
|
174
|
+
worldImportPath: "@latticexyz/world/src"
|
175
|
+
};
|
176
|
+
var DEPLOY_DEFAULTS = {
|
177
|
+
postDeployScript: "PostDeploy",
|
178
|
+
deploysDirectory: "./deploys",
|
179
|
+
worldsFile: "./worlds.json",
|
180
|
+
upgradeableWorldImplementation: false
|
181
|
+
};
|
182
|
+
var CONFIG_DEFAULTS = {
|
183
|
+
systems: {},
|
184
|
+
tables: {},
|
185
|
+
excludeSystems: [],
|
186
|
+
modules: [],
|
187
|
+
codegen: CODEGEN_DEFAULTS,
|
188
|
+
deploy: DEPLOY_DEFAULTS
|
189
|
+
};
|
190
|
+
|
191
|
+
// ts/config/v2/systems.ts
|
192
|
+
var import_internal2 = require("@latticexyz/store/internal");
|
193
|
+
|
194
|
+
// ts/config/v2/system.ts
|
195
|
+
var import_internal = require("@latticexyz/store/internal");
|
196
|
+
var import_common2 = require("@latticexyz/common");
|
197
|
+
function validateSystem(input, options = {}) {
|
198
|
+
if (typeof input !== "object" || input == null) {
|
199
|
+
throw new Error(`Expected full system config, got \`${JSON.stringify(input)}\``);
|
200
|
+
}
|
201
|
+
if (options.inNamespace && ((0, import_internal.hasOwnKey)(input, "label") || (0, import_internal.hasOwnKey)(input, "namespaceLabel") || (0, import_internal.hasOwnKey)(input, "namespace"))) {
|
202
|
+
throw new Error(
|
203
|
+
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for systems in this context."
|
204
|
+
);
|
205
|
+
}
|
206
|
+
if ((0, import_internal.hasOwnKey)(input, "namespaceLabel") && typeof input.namespaceLabel === "string" && (!(0, import_internal.hasOwnKey)(input, "namespace") || typeof input.namespace !== "string") && input.namespaceLabel.length > 14) {
|
207
|
+
throw new Error(
|
208
|
+
`System \`namespace\` defaults to \`namespaceLabel\`, but must fit into a \`bytes14\` and "${input.namespaceLabel}" is too long. Provide explicit \`namespace\` override.`
|
209
|
+
);
|
210
|
+
}
|
211
|
+
if ((0, import_internal.hasOwnKey)(input, "namespace") && typeof input.namespace === "string" && input.namespace.length > 14) {
|
212
|
+
throw new Error(`System \`namespace\` must fit into a \`bytes14\`, but "${input.namespace}" is too long.`);
|
213
|
+
}
|
214
|
+
if ((0, import_internal.hasOwnKey)(input, "name") && typeof input.name === "string" && input.name.length > 16) {
|
215
|
+
throw new Error(`System \`name\` must fit into a \`bytes16\`, but "${input.name}" is too long.`);
|
216
|
+
}
|
217
|
+
}
|
218
|
+
function resolveSystem(input) {
|
219
|
+
const namespaceLabel = input.namespaceLabel ?? SYSTEM_DEFAULTS.namespaceLabel;
|
220
|
+
const namespace = input.namespace ?? namespaceLabel;
|
221
|
+
const label = input.label;
|
222
|
+
const name = input.name ?? label.slice(0, 16);
|
223
|
+
const systemId = (0, import_common2.resourceToHex)({ type: "system", namespace, name });
|
224
|
+
return (0, import_internal.mergeIfUndefined)(
|
225
|
+
{
|
226
|
+
...input,
|
227
|
+
label,
|
228
|
+
namespaceLabel,
|
229
|
+
namespace,
|
230
|
+
name,
|
231
|
+
systemId,
|
232
|
+
deploy: (0, import_internal.mergeIfUndefined)(input.deploy ?? {}, SYSTEM_DEPLOY_DEFAULTS)
|
233
|
+
},
|
234
|
+
SYSTEM_DEFAULTS
|
235
|
+
);
|
236
|
+
}
|
237
|
+
function defineSystem(input) {
|
238
|
+
validateSystem(input);
|
239
|
+
return resolveSystem(input);
|
240
|
+
}
|
241
|
+
|
242
|
+
// ts/config/v2/systems.ts
|
243
|
+
function validateSystems(input) {
|
244
|
+
if ((0, import_internal2.isObject)(input)) {
|
245
|
+
for (const system of Object.values(input)) {
|
246
|
+
validateSystem(system, { inNamespace: true });
|
247
|
+
}
|
248
|
+
return;
|
249
|
+
}
|
250
|
+
throw new Error(`Expected system config, received ${JSON.stringify(input)}`);
|
251
|
+
}
|
252
|
+
function resolveSystems(systems, namespaceLabel, namespace) {
|
253
|
+
return Object.fromEntries(
|
254
|
+
Object.entries(systems).map(([label, system]) => {
|
255
|
+
return [label, resolveSystem({ ...system, label, namespaceLabel, namespace })];
|
256
|
+
})
|
257
|
+
);
|
258
|
+
}
|
259
|
+
|
260
|
+
// ts/config/v2/namespaces.ts
|
261
|
+
var import_util = require("@ark/util");
|
262
|
+
|
263
|
+
// ts/config/v2/namespace.ts
|
264
|
+
var import_internal3 = require("@latticexyz/store/internal");
|
265
|
+
function validateNamespace(input, scope) {
|
266
|
+
if ((0, import_internal3.hasOwnKey)(input, "systems")) {
|
267
|
+
validateSystems(input.systems);
|
268
|
+
}
|
269
|
+
(0, import_internal3.validateNamespace)(input, scope);
|
270
|
+
}
|
271
|
+
function resolveNamespace(input, scope = import_internal3.AbiTypeScope) {
|
272
|
+
const namespace = (0, import_internal3.resolveNamespace)(input, scope);
|
273
|
+
const systems = resolveSystems(input.systems ?? {}, namespace.label, namespace.namespace);
|
274
|
+
return {
|
275
|
+
...namespace,
|
276
|
+
systems
|
277
|
+
};
|
278
|
+
}
|
279
|
+
|
280
|
+
// ts/config/v2/namespaces.ts
|
281
|
+
var import_utils = require("@latticexyz/common/utils");
|
282
|
+
var import_internal4 = require("@latticexyz/store/internal");
|
283
|
+
function validateNamespaces(namespaces, scope) {
|
284
|
+
if (!(0, import_internal4.isObject)(namespaces)) {
|
285
|
+
throw new Error(`Expected namespaces, received ${JSON.stringify(namespaces)}`);
|
286
|
+
}
|
287
|
+
for (const namespace of Object.values(namespaces)) {
|
288
|
+
validateNamespace(namespace, scope);
|
289
|
+
}
|
290
|
+
}
|
291
|
+
function resolveNamespaces(input, scope) {
|
292
|
+
if (!(0, import_internal4.isObject)(input)) {
|
293
|
+
throw new Error(`Expected namespaces config, received ${JSON.stringify(input)}`);
|
294
|
+
}
|
295
|
+
const namespaces = (0, import_util.flatMorph)(input, (label, namespace) => [
|
296
|
+
label,
|
297
|
+
resolveNamespace((0, import_internal4.mergeIfUndefined)(namespace, { label }), scope)
|
298
|
+
]);
|
299
|
+
const duplicates = Array.from((0, import_utils.groupBy)(Object.values(namespaces), (namespace) => namespace.namespace).entries()).filter(([, entries]) => entries.length > 1).map(([namespace]) => namespace);
|
300
|
+
if (duplicates.length > 0) {
|
301
|
+
throw new Error(`Found namespaces defined more than once in config: ${duplicates.join(", ")}`);
|
302
|
+
}
|
303
|
+
return namespaces;
|
304
|
+
}
|
305
|
+
function defineNamespaces(input, scope = import_internal4.AbiTypeScope) {
|
306
|
+
validateNamespaces(input, scope);
|
307
|
+
return resolveNamespaces(input, scope);
|
308
|
+
}
|
309
|
+
|
310
|
+
// ts/config/v2/codegen.ts
|
311
|
+
var import_internal5 = require("@latticexyz/store/internal");
|
312
|
+
function resolveCodegen(codegen) {
|
313
|
+
return (0, import_internal5.isObject)(codegen) ? (0, import_internal5.mergeIfUndefined)(codegen, CODEGEN_DEFAULTS) : CODEGEN_DEFAULTS;
|
314
|
+
}
|
315
|
+
|
316
|
+
// ts/config/v2/deploy.ts
|
317
|
+
var import_internal6 = require("@latticexyz/store/internal");
|
318
|
+
function resolveDeploy(deploy) {
|
319
|
+
return (0, import_internal6.isObject)(deploy) ? (0, import_internal6.mergeIfUndefined)(deploy, DEPLOY_DEFAULTS) : DEPLOY_DEFAULTS;
|
320
|
+
}
|
321
|
+
|
322
|
+
// ts/config/v2/world.ts
|
323
|
+
function validateWorld(input) {
|
324
|
+
const scope = (0, import_internal7.extendedScope)(input);
|
325
|
+
if ((0, import_internal7.hasOwnKey)(input, "namespaces")) {
|
326
|
+
if ((0, import_internal7.hasOwnKey)(input, "namespace") || (0, import_internal7.hasOwnKey)(input, "tables") || (0, import_internal7.hasOwnKey)(input, "systems")) {
|
327
|
+
throw new Error("Cannot use `namespaces` with `namespace`, `tables`, or `systems` keys.");
|
328
|
+
}
|
329
|
+
validateNamespaces(input.namespaces, scope);
|
330
|
+
}
|
331
|
+
if ((0, import_internal7.hasOwnKey)(input, "systems")) {
|
332
|
+
validateSystems(input.systems);
|
333
|
+
}
|
334
|
+
(0, import_internal7.validateStore)(input);
|
335
|
+
}
|
336
|
+
function resolveWorld(input) {
|
337
|
+
const scope = (0, import_internal7.extendedScope)(input);
|
338
|
+
const store = (0, import_internal7.resolveStore)(input);
|
339
|
+
const namespaces = input.namespaces ? resolveNamespaces(input.namespaces, scope) : resolveNamespaces({ [store.namespace]: input }, scope);
|
340
|
+
const tables = (0, import_internal7.flattenNamespacedTables)({ namespaces });
|
341
|
+
const modules = (input.modules ?? CONFIG_DEFAULTS.modules).map((mod) => (0, import_internal7.mergeIfUndefined)(mod, MODULE_DEFAULTS));
|
342
|
+
return (0, import_internal7.mergeIfUndefined)(
|
343
|
+
{
|
344
|
+
...store,
|
345
|
+
namespaces,
|
346
|
+
tables,
|
347
|
+
// TODO: flatten systems from namespaces
|
348
|
+
systems: !store.multipleNamespaces && input.systems ? resolveSystems(input.systems, store.namespace, store.namespace) : CONFIG_DEFAULTS.systems,
|
349
|
+
excludeSystems: (0, import_internal7.get)(input, "excludeSystems"),
|
350
|
+
codegen: (0, import_internal7.mergeIfUndefined)(store.codegen, resolveCodegen(input.codegen)),
|
351
|
+
deploy: resolveDeploy(input.deploy),
|
352
|
+
modules
|
353
|
+
},
|
354
|
+
CONFIG_DEFAULTS
|
355
|
+
);
|
356
|
+
}
|
357
|
+
function defineWorld(input) {
|
358
|
+
validateWorld(input);
|
359
|
+
return resolveWorld(input);
|
360
|
+
}
|
361
|
+
|
362
|
+
// mud.config.ts
|
363
|
+
var configInput = {
|
364
|
+
namespace: "world",
|
365
|
+
// NOTE: this namespace is only used for tables, the core system is deployed in the root namespace.
|
366
|
+
codegen: {
|
367
|
+
worldImportPath: "./src",
|
368
|
+
worldgenDirectory: "interfaces",
|
369
|
+
worldInterfaceName: "IBaseWorld"
|
370
|
+
},
|
371
|
+
userTypes: {
|
372
|
+
ResourceId: { filePath: "@latticexyz/store/src/ResourceId.sol", type: "bytes32" }
|
373
|
+
},
|
374
|
+
tables: {
|
375
|
+
NamespaceOwner: {
|
376
|
+
schema: {
|
377
|
+
namespaceId: "ResourceId",
|
378
|
+
owner: "address"
|
379
|
+
},
|
380
|
+
key: ["namespaceId"]
|
381
|
+
},
|
382
|
+
ResourceAccess: {
|
383
|
+
schema: {
|
384
|
+
resourceId: "ResourceId",
|
385
|
+
caller: "address",
|
386
|
+
access: "bool"
|
387
|
+
},
|
388
|
+
key: ["resourceId", "caller"]
|
389
|
+
},
|
390
|
+
InstalledModules: {
|
391
|
+
schema: {
|
392
|
+
moduleAddress: "address",
|
393
|
+
argumentsHash: "bytes32",
|
394
|
+
// Hash of the params passed to the `install` function
|
395
|
+
isInstalled: "bool"
|
396
|
+
},
|
397
|
+
key: ["moduleAddress", "argumentsHash"]
|
398
|
+
},
|
399
|
+
UserDelegationControl: {
|
400
|
+
schema: {
|
401
|
+
delegator: "address",
|
402
|
+
delegatee: "address",
|
403
|
+
delegationControlId: "ResourceId"
|
404
|
+
},
|
405
|
+
key: ["delegator", "delegatee"]
|
406
|
+
},
|
407
|
+
NamespaceDelegationControl: {
|
408
|
+
schema: {
|
409
|
+
namespaceId: "ResourceId",
|
410
|
+
delegationControlId: "ResourceId"
|
411
|
+
},
|
412
|
+
key: ["namespaceId"]
|
413
|
+
},
|
414
|
+
Balances: {
|
415
|
+
schema: {
|
416
|
+
namespaceId: "ResourceId",
|
417
|
+
balance: "uint256"
|
418
|
+
},
|
419
|
+
key: ["namespaceId"]
|
420
|
+
},
|
421
|
+
Systems: {
|
422
|
+
schema: {
|
423
|
+
systemId: "ResourceId",
|
424
|
+
system: "address",
|
425
|
+
publicAccess: "bool"
|
426
|
+
},
|
427
|
+
key: ["systemId"],
|
428
|
+
codegen: {
|
429
|
+
dataStruct: false
|
430
|
+
}
|
431
|
+
},
|
432
|
+
SystemRegistry: {
|
433
|
+
schema: {
|
434
|
+
system: "address",
|
435
|
+
systemId: "ResourceId"
|
436
|
+
},
|
437
|
+
key: ["system"]
|
438
|
+
},
|
439
|
+
SystemHooks: {
|
440
|
+
schema: {
|
441
|
+
systemId: "ResourceId",
|
442
|
+
value: "bytes21[]"
|
443
|
+
},
|
444
|
+
key: ["systemId"]
|
445
|
+
},
|
446
|
+
FunctionSelectors: {
|
447
|
+
schema: {
|
448
|
+
worldFunctionSelector: "bytes4",
|
449
|
+
systemId: "ResourceId",
|
450
|
+
systemFunctionSelector: "bytes4"
|
451
|
+
},
|
452
|
+
key: ["worldFunctionSelector"],
|
453
|
+
codegen: {
|
454
|
+
dataStruct: false
|
455
|
+
}
|
456
|
+
},
|
457
|
+
FunctionSignatures: {
|
458
|
+
type: "offchainTable",
|
459
|
+
schema: {
|
460
|
+
functionSelector: "bytes4",
|
461
|
+
functionSignature: "string"
|
462
|
+
},
|
463
|
+
key: ["functionSelector"]
|
464
|
+
},
|
465
|
+
InitModuleAddress: {
|
466
|
+
schema: {
|
467
|
+
value: "address"
|
468
|
+
},
|
469
|
+
key: []
|
470
|
+
}
|
471
|
+
},
|
472
|
+
excludeSystems: [
|
473
|
+
// Worldgen currently does not support systems inheriting logic
|
474
|
+
// from other contracts, so all parts of RegistrationSystem are named
|
475
|
+
// System too to be included in the IBaseWorld interface.
|
476
|
+
// However, IStoreRegistrationSystem overlaps with IStore if
|
477
|
+
// included in IBaseWorld, so it needs to be excluded from worldgen.
|
478
|
+
// TODO: add support for inheritance to worldgen
|
479
|
+
// (see: https://github.com/latticexyz/mud/issues/631)
|
480
|
+
"StoreRegistrationSystem"
|
481
|
+
]
|
482
|
+
};
|
483
|
+
var mud_config_default = defineWorld(configInput);
|
484
|
+
|
485
|
+
// ts/actions/callFrom.ts
|
486
|
+
function callFrom(params) {
|
487
|
+
return (client) => ({
|
488
|
+
async writeContract(writeArgs) {
|
489
|
+
const _writeContract = (0, import_utils2.getAction)(client, import_actions.writeContract, "writeContract");
|
490
|
+
if (writeArgs.address !== params.worldAddress || writeArgs.functionName === "call" || writeArgs.functionName === "callFrom" || writeArgs.functionName === "batchCallFrom" || writeArgs.functionName === "callWithSignature") {
|
491
|
+
return _writeContract(writeArgs);
|
492
|
+
}
|
493
|
+
if (writeArgs.functionName === "batchCall") {
|
494
|
+
const batchCallArgs = writeArgs;
|
495
|
+
const [systemCalls] = batchCallArgs.args;
|
496
|
+
if (!systemCalls.length) {
|
497
|
+
throw new Error("`batchCall` should have at least one system call.");
|
498
|
+
}
|
499
|
+
return _writeContract({
|
500
|
+
...batchCallArgs,
|
501
|
+
functionName: "batchCallFrom",
|
502
|
+
args: [systemCalls.map((systemCall) => ({ from: params.delegatorAddress, ...systemCall }))]
|
503
|
+
});
|
504
|
+
}
|
505
|
+
const worldCalldata = (0, import_utils2.encodeFunctionData)({
|
506
|
+
abi: writeArgs.abi,
|
507
|
+
functionName: writeArgs.functionName,
|
508
|
+
args: writeArgs.args
|
509
|
+
});
|
510
|
+
const worldFunctionSelector = (0, import_viem5.slice)(worldCalldata, 0, 4);
|
511
|
+
const { systemId, systemFunctionSelector } = await worldFunctionToSystemFunction({
|
512
|
+
...params,
|
513
|
+
publicClient: params.publicClient ?? client,
|
514
|
+
worldFunctionSelector
|
515
|
+
});
|
516
|
+
const systemCalldata = (0, import_viem5.concat)([systemFunctionSelector, (0, import_common3.readHex)(worldCalldata, 4)]);
|
517
|
+
return _writeContract({
|
518
|
+
...writeArgs,
|
519
|
+
functionName: "callFrom",
|
520
|
+
args: [params.delegatorAddress, systemId, systemCalldata]
|
521
|
+
});
|
522
|
+
}
|
523
|
+
});
|
524
|
+
}
|
525
|
+
var systemFunctionCache = /* @__PURE__ */ new Map();
|
526
|
+
async function worldFunctionToSystemFunction(params) {
|
527
|
+
const cacheKey = (0, import_viem5.concat)([params.worldAddress, params.worldFunctionSelector]);
|
528
|
+
const cached = systemFunctionCache.get(cacheKey);
|
529
|
+
if (cached) return cached;
|
530
|
+
const systemFunction = params.worldFunctionToSystemFunction ? await params.worldFunctionToSystemFunction(params.worldFunctionSelector) : await retrieveSystemFunctionFromContract(params.publicClient, params.worldAddress, params.worldFunctionSelector);
|
531
|
+
systemFunctionCache.set(cacheKey, systemFunction);
|
532
|
+
return systemFunction;
|
533
|
+
}
|
534
|
+
async function retrieveSystemFunctionFromContract(publicClient, worldAddress, worldFunctionSelector) {
|
535
|
+
const table = mud_config_default.tables.world__FunctionSelectors;
|
536
|
+
const keySchema = (0, import_internal8.getSchemaTypes)((0, import_internal8.getKeySchema)(table));
|
537
|
+
const valueSchema = (0, import_internal8.getSchemaTypes)((0, import_internal8.getValueSchema)(table));
|
538
|
+
const _readContract = (0, import_utils2.getAction)(publicClient, import_actions.readContract, "readContract");
|
539
|
+
const [staticData, encodedLengths, dynamicData] = await _readContract({
|
540
|
+
address: worldAddress,
|
541
|
+
abi: [
|
542
|
+
{
|
543
|
+
type: "function",
|
544
|
+
name: "getRecord",
|
545
|
+
inputs: [
|
546
|
+
{
|
547
|
+
name: "tableId",
|
548
|
+
type: "bytes32",
|
549
|
+
internalType: "ResourceId"
|
550
|
+
},
|
551
|
+
{
|
552
|
+
name: "keyTuple",
|
553
|
+
type: "bytes32[]",
|
554
|
+
internalType: "bytes32[]"
|
555
|
+
}
|
556
|
+
],
|
557
|
+
outputs: [
|
558
|
+
{
|
559
|
+
name: "staticData",
|
560
|
+
type: "bytes",
|
561
|
+
internalType: "bytes"
|
562
|
+
},
|
563
|
+
{
|
564
|
+
name: "encodedLengths",
|
565
|
+
type: "bytes32",
|
566
|
+
internalType: "EncodedLengths"
|
567
|
+
},
|
568
|
+
{
|
569
|
+
name: "dynamicData",
|
570
|
+
type: "bytes",
|
571
|
+
internalType: "bytes"
|
572
|
+
}
|
573
|
+
],
|
574
|
+
stateMutability: "view"
|
575
|
+
}
|
576
|
+
],
|
577
|
+
functionName: "getRecord",
|
578
|
+
args: [table.tableId, (0, import_internal8.encodeKey)(keySchema, { worldFunctionSelector })]
|
579
|
+
});
|
580
|
+
const decoded = (0, import_internal8.decodeValueArgs)(valueSchema, { staticData, encodedLengths, dynamicData });
|
581
|
+
const systemFunction = {
|
582
|
+
systemId: decoded.systemId,
|
583
|
+
systemFunctionSelector: decoded.systemFunctionSelector
|
584
|
+
};
|
585
|
+
return systemFunction;
|
586
|
+
}
|
587
|
+
|
588
|
+
// ts/config/v2/dynamicResolution.ts
|
589
|
+
function resolveTableId(tableName) {
|
590
|
+
return {
|
591
|
+
type: "tableId",
|
592
|
+
input: tableName
|
593
|
+
};
|
594
|
+
}
|
595
|
+
function isDynamicResolution(value) {
|
596
|
+
return typeof value === "object" && value !== null && "type" in value && "input" in value;
|
597
|
+
}
|
598
|
+
function isValueWithType(value) {
|
599
|
+
return typeof value === "object" && value !== null && "type" in value && "value" in value;
|
600
|
+
}
|
601
|
+
function resolveWithContext(input, context) {
|
602
|
+
if (isValueWithType(input)) return input;
|
603
|
+
if (isDynamicResolution(input)) {
|
604
|
+
if (input.type === "tableId") {
|
605
|
+
const tableEntries = Object.entries(context.config.tables).filter(
|
606
|
+
([tableName, table]) => tableName === input.input || table.name === input.input
|
607
|
+
);
|
608
|
+
if (tableEntries.length > 1) {
|
609
|
+
throw new Error(
|
610
|
+
`Found more than one table with name "${input.input}". Try using one of the following table names instead: ${tableEntries.map(([tableName]) => tableName).join(", ")}`
|
611
|
+
);
|
612
|
+
}
|
613
|
+
if (tableEntries.length === 1) {
|
614
|
+
const [entry] = tableEntries;
|
615
|
+
const [, table] = entry;
|
616
|
+
return { type: "bytes32", value: table.tableId };
|
617
|
+
}
|
618
|
+
}
|
619
|
+
}
|
620
|
+
throw new Error(`Could not resolve dynamic resolution:
|
621
|
+
${JSON.stringify(input, null, 2)}`);
|
622
|
+
}
|
623
|
+
// Annotate the CommonJS export names for ESM import in node:
|
624
|
+
0 && (module.exports = {
|
625
|
+
CODEGEN_DEFAULTS,
|
626
|
+
CONFIG_DEFAULTS,
|
627
|
+
DEPLOY_DEFAULTS,
|
628
|
+
MODULE_DEFAULTS,
|
629
|
+
SYSTEM_DEFAULTS,
|
630
|
+
SYSTEM_DEPLOY_DEFAULTS,
|
631
|
+
callFrom,
|
632
|
+
defineNamespaces,
|
633
|
+
defineSystem,
|
634
|
+
defineWorld,
|
635
|
+
encodeSystemCall,
|
636
|
+
encodeSystemCallFrom,
|
637
|
+
encodeSystemCalls,
|
638
|
+
encodeSystemCallsFrom,
|
639
|
+
isDynamicResolution,
|
640
|
+
isValueWithType,
|
641
|
+
resolveCodegen,
|
642
|
+
resolveDeploy,
|
643
|
+
resolveNamespace,
|
644
|
+
resolveNamespaces,
|
645
|
+
resolveSystem,
|
646
|
+
resolveSystems,
|
647
|
+
resolveTableId,
|
648
|
+
resolveWithContext,
|
649
|
+
resolveWorld,
|
650
|
+
validateNamespace,
|
651
|
+
validateNamespaces,
|
652
|
+
validateSystem,
|
653
|
+
validateSystems,
|
654
|
+
validateWorld
|
655
|
+
});
|
656
|
+
//# sourceMappingURL=internal.cjs.map
|