@latticexyz/world 2.2.20-06e48e0239a5c7994ce73b4d2752860743fec4b0 → 2.2.20-31870811b975d44f4b5d14ae69fd623914237584

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.
@@ -10,6 +10,7 @@ var SYSTEM_DEFAULTS = {
10
10
  };
11
11
  var MODULE_DEFAULTS = {
12
12
  root: false,
13
+ useDelegation: false,
13
14
  args: [],
14
15
  artifactPath: void 0
15
16
  };
@@ -139,4 +140,4 @@ export {
139
140
  validateNamespace,
140
141
  resolveNamespace
141
142
  };
142
- //# sourceMappingURL=chunk-XSBK355I.js.map
143
+ //# sourceMappingURL=chunk-6E2JY6MZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../ts/config/v2/defaults.ts","../ts/config/v2/system.ts","../ts/config/v2/systems.ts","../ts/config/v2/namespace.ts"],"sourcesContent":["import { CodegenInput, DeployInput, ModuleInput, SystemDeployInput, SystemInput, WorldInput } from \"./input\";\n\nexport const SYSTEM_DEPLOY_DEFAULTS = {\n disabled: false,\n registerWorldFunctions: true,\n} as const satisfies Required<SystemDeployInput>;\n\nexport type SYSTEM_DEPLOY_DEFAULTS = typeof SYSTEM_DEPLOY_DEFAULTS;\n\nexport const SYSTEM_DEFAULTS = {\n namespaceLabel: \"\",\n openAccess: true,\n accessList: [],\n} as const satisfies Omit<Required<SystemInput>, \"label\" | \"namespace\" | \"name\" | \"deploy\">;\n\nexport type SYSTEM_DEFAULTS = typeof SYSTEM_DEFAULTS;\n\nexport const MODULE_DEFAULTS = {\n root: false,\n useDelegation: false,\n args: [],\n artifactPath: undefined,\n} as const satisfies Pick<ModuleInput, \"root\" | \"useDelegation\" | \"args\" | \"artifactPath\">;\n\nexport type MODULE_DEFAULTS = typeof MODULE_DEFAULTS;\n\nexport const CODEGEN_DEFAULTS = {\n worldInterfaceName: \"IWorld\",\n worldgenDirectory: \"world\",\n systemLibrariesDirectory: \"systems\",\n generateSystemLibraries: false,\n worldImportPath: \"@latticexyz/world/src\",\n} as const satisfies CodegenInput;\n\nexport type CODEGEN_DEFAULTS = typeof CODEGEN_DEFAULTS;\n\nexport const DEPLOY_DEFAULTS = {\n postDeployScript: \"PostDeploy\",\n deploysDirectory: \"./deploys\",\n worldsFile: \"./worlds.json\",\n upgradeableWorldImplementation: false,\n} as const satisfies DeployInput;\n\nexport type DEPLOY_DEFAULTS = typeof DEPLOY_DEFAULTS;\n\nexport const CONFIG_DEFAULTS = {\n systems: {},\n tables: {},\n excludeSystems: [],\n modules: [],\n codegen: CODEGEN_DEFAULTS,\n deploy: DEPLOY_DEFAULTS,\n} as const satisfies WorldInput;\n\nexport type CONFIG_DEFAULTS = typeof CONFIG_DEFAULTS;\n","import { SYSTEM_DEFAULTS, SYSTEM_DEPLOY_DEFAULTS } from \"./defaults\";\nimport { SystemInput } from \"./input\";\nimport { hasOwnKey, mergeIfUndefined } from \"@latticexyz/store/internal\";\nimport { ErrorMessage, narrow, requiredKeyOf, show } from \"@ark/util\";\nimport { Hex } from \"viem\";\nimport { resourceToHex } from \"@latticexyz/common\";\n\nexport type ValidateSystemOptions = { readonly inNamespace?: true };\n\nexport type requiredSystemKey<inNamespace extends true | undefined> = Exclude<\n requiredKeyOf<SystemInput>,\n inNamespace extends true ? \"label\" | \"namespaceLabel\" | \"namespace\" : never\n>;\n\nexport type validateSystem<input, options extends ValidateSystemOptions = {}> = {\n [key in keyof input | requiredSystemKey<options[\"inNamespace\"]>]: key extends keyof SystemInput\n ? key extends \"label\" | \"namespaceLabel\" | \"namespace\"\n ? options[\"inNamespace\"] extends true\n ? ErrorMessage<\"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for systems in this context.\">\n : key extends keyof input\n ? narrow<input[key]>\n : never\n : SystemInput[key]\n : ErrorMessage<`Key \\`${key & string}\\` does not exist in SystemInput`>;\n};\n\nexport function validateSystem<input>(\n input: input,\n options: ValidateSystemOptions = {},\n): asserts input is SystemInput & input {\n if (typeof input !== \"object\" || input == null) {\n throw new Error(`Expected full system config, got \\`${JSON.stringify(input)}\\``);\n }\n\n if (\n options.inNamespace &&\n (hasOwnKey(input, \"label\") || hasOwnKey(input, \"namespaceLabel\") || hasOwnKey(input, \"namespace\"))\n ) {\n throw new Error(\n \"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for systems in this context.\",\n );\n }\n\n if (\n hasOwnKey(input, \"namespaceLabel\") &&\n typeof input.namespaceLabel === \"string\" &&\n (!hasOwnKey(input, \"namespace\") || typeof input.namespace !== \"string\") &&\n input.namespaceLabel.length > 14\n ) {\n throw new Error(\n `System \\`namespace\\` defaults to \\`namespaceLabel\\`, but must fit into a \\`bytes14\\` and \"${input.namespaceLabel}\" is too long. Provide explicit \\`namespace\\` override.`,\n );\n }\n\n if (hasOwnKey(input, \"namespace\") && typeof input.namespace === \"string\" && input.namespace.length > 14) {\n throw new Error(`System \\`namespace\\` must fit into a \\`bytes14\\`, but \"${input.namespace}\" is too long.`);\n }\n if (hasOwnKey(input, \"name\") && typeof input.name === \"string\" && input.name.length > 16) {\n throw new Error(`System \\`name\\` must fit into a \\`bytes16\\`, but \"${input.name}\" is too long.`);\n }\n}\n\nexport type resolveSystem<input> = input extends SystemInput\n ? {\n readonly label: input[\"label\"];\n readonly namespaceLabel: undefined extends input[\"namespaceLabel\"]\n ? typeof SYSTEM_DEFAULTS.namespaceLabel\n : input[\"namespaceLabel\"];\n readonly namespace: string;\n readonly name: string;\n readonly systemId: Hex;\n readonly openAccess: undefined extends input[\"openAccess\"] ? SYSTEM_DEFAULTS[\"openAccess\"] : input[\"openAccess\"];\n readonly accessList: undefined extends input[\"accessList\"] ? SYSTEM_DEFAULTS[\"accessList\"] : input[\"accessList\"];\n readonly deploy: show<\n mergeIfUndefined<undefined extends input[\"deploy\"] ? {} : input[\"deploy\"], SYSTEM_DEPLOY_DEFAULTS>\n >;\n }\n : never;\n\nexport function resolveSystem<input extends SystemInput>(input: input): resolveSystem<input> {\n const namespaceLabel = input.namespaceLabel ?? SYSTEM_DEFAULTS.namespaceLabel;\n // validate ensures this is length constrained\n const namespace = input.namespace ?? namespaceLabel;\n\n const label = input.label;\n const name = input.name ?? label.slice(0, 16);\n const systemId = resourceToHex({ type: \"system\", namespace, name });\n\n return mergeIfUndefined(\n {\n ...input,\n label,\n namespaceLabel,\n namespace,\n name,\n systemId,\n deploy: mergeIfUndefined(input.deploy ?? {}, SYSTEM_DEPLOY_DEFAULTS),\n },\n SYSTEM_DEFAULTS,\n ) as never;\n}\n\nexport function defineSystem<input>(input: validateSystem<input>): resolveSystem<input> {\n validateSystem(input);\n return resolveSystem(input) as never;\n}\n","import { ErrorMessage } from \"@ark/util\";\nimport { isObject } from \"@latticexyz/store/internal\";\nimport { SystemsInput } from \"./input\";\nimport { resolveSystem, validateSystem } from \"./system\";\n\n// TODO: add nuance between \"in namespace\" (namespace provided in context) and \"in systems\" (label provided in context)\n\nexport type validateSystems<input> = {\n [label in keyof input]: input[label] extends object\n ? validateSystem<input[label], { inNamespace: true }>\n : ErrorMessage<`Expected a system config for ${label & string}.`>;\n};\n\nexport function validateSystems(input: unknown): asserts input is SystemsInput {\n if (isObject(input)) {\n for (const system of Object.values(input)) {\n validateSystem(system, { inNamespace: true });\n }\n return;\n }\n throw new Error(`Expected system config, received ${JSON.stringify(input)}`);\n}\n\nexport type resolveSystems<systems extends SystemsInput, namespaceLabel extends string> = {\n [label in keyof systems]: resolveSystem<\n systems[label] & { label: label; namespaceLabel: namespaceLabel; namespace: string }\n >;\n};\n\nexport function resolveSystems<systems extends SystemsInput, namespaceLabel extends string>(\n systems: systems,\n namespaceLabel: namespaceLabel,\n namespace: string,\n): resolveSystems<systems, namespaceLabel> {\n return Object.fromEntries(\n Object.entries(systems).map(([label, system]) => {\n return [label, resolveSystem({ ...system, label, namespaceLabel, namespace })];\n }),\n ) as never;\n}\n","import { NamespaceInput, SystemsInput } from \"./input\";\nimport {\n hasOwnKey,\n validateNamespace as validateStoreNamespace,\n resolveNamespace as resolveStoreNamespace,\n Scope,\n AbiTypeScope,\n} from \"@latticexyz/store/internal\";\nimport { resolveSystems, validateSystems } from \"./systems\";\nimport { show } from \"@ark/util\";\n\nexport type validateNamespace<input, scope extends Scope = AbiTypeScope> = {\n [key in keyof input]: key extends \"systems\" ? validateSystems<input[key]> : validateStoreNamespace<input, scope>[key];\n};\n\nexport function validateNamespace<scope extends Scope = AbiTypeScope>(\n input: unknown,\n scope: scope,\n): asserts input is NamespaceInput {\n if (hasOwnKey(input, \"systems\")) {\n validateSystems(input.systems);\n }\n validateStoreNamespace(input, scope);\n}\n\nexport type resolveNamespace<input, scope extends Scope = AbiTypeScope> = input extends NamespaceInput\n ? show<\n resolveStoreNamespace<input, scope> & {\n readonly systems: input[\"systems\"] extends SystemsInput\n ? show<resolveSystems<input[\"systems\"], resolveStoreNamespace<input, scope>[\"label\"]>>\n : {};\n }\n >\n : never;\n\nexport function resolveNamespace<const input extends NamespaceInput, scope extends Scope = AbiTypeScope>(\n input: input,\n scope: scope = AbiTypeScope as never,\n): resolveNamespace<input, scope> {\n const namespace = resolveStoreNamespace(input, scope);\n const systems = resolveSystems(input.systems ?? {}, namespace.label, namespace.namespace);\n return {\n ...namespace,\n systems,\n } as never;\n}\n"],"mappings":";AAEO,IAAM,yBAAyB;AAAA,EACpC,UAAU;AAAA,EACV,wBAAwB;AAC1B;AAIO,IAAM,kBAAkB;AAAA,EAC7B,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,YAAY,CAAC;AACf;AAIO,IAAM,kBAAkB;AAAA,EAC7B,MAAM;AAAA,EACN,eAAe;AAAA,EACf,MAAM,CAAC;AAAA,EACP,cAAc;AAChB;AAIO,IAAM,mBAAmB;AAAA,EAC9B,oBAAoB;AAAA,EACpB,mBAAmB;AAAA,EACnB,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA,EACzB,iBAAiB;AACnB;AAIO,IAAM,kBAAkB;AAAA,EAC7B,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,E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AAU,SAAS;AACxF,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,EACF;AACF;","names":["hasOwnKey","hasOwnKey"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defineWorld
3
- } from "./chunk-2W4TKC47.js";
3
+ } from "./chunk-NVV4GS3R.js";
4
4
 
5
5
  // mud.config.ts
6
6
  var tablesConfig = defineWorld({
@@ -116,6 +116,7 @@ var systemsConfig = defineWorld({
116
116
  generateSystemLibraries: true,
117
117
  systemLibrariesDirectory: "experimental/systems"
118
118
  },
119
+ // Keep aligned with src/modules/init/constants.sol
119
120
  systems: {
120
121
  AccessManagementSystem: {
121
122
  name: "AccessManagement"
@@ -148,4 +149,4 @@ export {
148
149
  systemsConfig,
149
150
  mud_config_default
150
151
  };
151
- //# sourceMappingURL=chunk-PZKG3J66.js.map
152
+ //# sourceMappingURL=chunk-6KRKTNJ5.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../mud.config.ts"],"sourcesContent":["import { defineWorld } from \"./ts/config/v2/world\";\n\n// Ideally we'd use a single multi-namespace config here, but we don't want\n// to break imports from this package because the source location changed.\n//\n// Once we have more nuanced control over source paths and codegen for each\n// namespace, then we could probably migrate to multi-namespace config.\n//\n// Or some way to deeply merge multiple configs while retaining strong types.\n\n/** @internal */\nexport const tablesConfig = defineWorld({\n namespace: \"world\",\n userTypes: {\n ResourceId: { filePath: \"@latticexyz/store/src/ResourceId.sol\", type: \"bytes32\" },\n },\n tables: {\n NamespaceOwner: {\n schema: {\n namespaceId: \"ResourceId\",\n owner: \"address\",\n },\n key: [\"namespaceId\"],\n },\n ResourceAccess: {\n schema: {\n resourceId: \"ResourceId\",\n caller: \"address\",\n access: \"bool\",\n },\n key: [\"resourceId\", \"caller\"],\n },\n InstalledModules: {\n schema: {\n moduleAddress: \"address\",\n argumentsHash: \"bytes32\", // Hash of the params passed to the `install` function\n isInstalled: \"bool\",\n },\n key: [\"moduleAddress\", \"argumentsHash\"],\n },\n UserDelegationControl: {\n schema: {\n delegator: \"address\",\n delegatee: \"address\",\n delegationControlId: \"ResourceId\",\n },\n key: [\"delegator\", \"delegatee\"],\n },\n NamespaceDelegationControl: {\n schema: {\n namespaceId: \"ResourceId\",\n delegationControlId: \"ResourceId\",\n },\n key: [\"namespaceId\"],\n },\n Balances: {\n schema: {\n namespaceId: \"ResourceId\",\n balance: \"uint256\",\n },\n key: [\"namespaceId\"],\n },\n Systems: {\n schema: {\n systemId: \"ResourceId\",\n system: \"address\",\n publicAccess: \"bool\",\n },\n key: [\"systemId\"],\n codegen: {\n dataStruct: false,\n },\n },\n SystemRegistry: {\n schema: {\n system: \"address\",\n systemId: \"ResourceId\",\n },\n key: [\"system\"],\n },\n SystemHooks: {\n schema: {\n systemId: \"ResourceId\",\n value: \"bytes21[]\",\n },\n key: [\"systemId\"],\n },\n FunctionSelectors: {\n schema: {\n worldFunctionSelector: \"bytes4\",\n systemId: \"ResourceId\",\n systemFunctionSelector: \"bytes4\",\n },\n key: [\"worldFunctionSelector\"],\n codegen: {\n dataStruct: false,\n },\n },\n FunctionSignatures: {\n type: \"offchainTable\",\n schema: {\n functionSelector: \"bytes4\",\n functionSignature: \"string\",\n },\n key: [\"functionSelector\"],\n },\n InitModuleAddress: {\n schema: {\n value: \"address\",\n },\n key: [],\n },\n },\n});\n\n/** @internal */\nexport const systemsConfig = defineWorld({\n namespace: \"\",\n codegen: {\n worldImportPath: \"./src\",\n worldgenDirectory: \"interfaces\",\n worldInterfaceName: \"IBaseWorld\",\n generateSystemLibraries: true,\n systemLibrariesDirectory: \"experimental/systems\",\n },\n systems: {\n AccessManagementSystem: {\n name: \"AccessManagement\",\n },\n BalanceTransferSystem: {\n name: \"BalanceTransfer\",\n },\n BatchCallSystem: {\n name: \"BatchCall\",\n },\n RegistrationSystem: {\n name: \"Registration\",\n },\n // abstract systems that are deployed as part of RegistrationSystem\n ModuleInstallationSystem: {\n name: \"Registration\",\n },\n StoreRegistrationSystem: {\n name: \"Registration\",\n },\n WorldRegistrationSystem: {\n name: \"Registration\",\n },\n },\n});\n\nexport default tablesConfig;\n"],"mappings":";;;;;AAWO,IAAM,eAAe,YAAY;AAAA,EACtC,WAAW;AAAA,EACX,WAAW;AAAA,IACT,YAAY,EAAE,UAAU,wCAAwC,MAAM,UAAU;AAAA,EAClF;AAAA,EACA,QAAQ;AAAA,IACN,gBAAgB;AAAA,MACd,QAAQ;AAAA,QACN,aAAa;AAAA,QACb,OAAO;AAAA,MACT;AAAA,MACA,KAAK,CAAC,aAAa;AAAA,IACrB;AAAA,IACA,gBAAgB;AAAA,MACd,QAAQ;AAAA,QACN,YAAY;AAAA,QACZ,QAAQ;AAAA,QACR,QAAQ;AAAA,MACV;AAAA,MACA,KAAK,CAAC,cAAc,QAAQ;AAAA,IAC9B;AAAA,IACA,kBAAkB;AAAA,MAChB,QAAQ;AAAA,QACN,eAAe;AAAA,QACf,eAAe;AAAA;AAAA,QACf,aAAa;AAAA,MACf;AAAA,MACA,KAAK,CAAC,iBAAiB,eAAe;AAAA,IACxC;AAAA,IACA,uBAAuB;AAAA,MACrB,QAAQ;AAAA,QACN,WAAW;AAAA,QACX,WAAW;AAAA,QACX,qBAAqB;AAAA,MACvB;AAAA,MACA,KAAK,CAAC,aAAa,WAAW;AAAA,IAChC;AAAA,IACA,4BAA4B;AAAA,MAC1B,QAAQ;AAAA,QACN,aAAa;AAAA,QACb,qBAAqB;AAAA,MACvB;AAAA,MACA,KAAK,CAAC,aAAa;AAAA,IACrB;AAAA,IACA,UAAU;AAAA,MACR,QAAQ;AAAA,QACN,aAAa;AAAA,QACb,SAAS;AAAA,MACX;AAAA,MACA,KAAK,CAAC,aAAa;AAAA,IACrB;AAAA,IACA,SAAS;AAAA,MACP,QAAQ;AAAA,QACN,UAAU;AAAA,QACV,QAAQ;AAAA,QACR,cAAc;AAAA,MAChB;AAAA,MACA,KAAK,CAAC,UAAU;AAAA,MAChB,SAAS;AAAA,QACP,YAAY;AAAA,MACd;AAAA,IACF;AAAA,IACA,gB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A,IACR;AAAA,EACF;AACF,CAAC;AAED,IAAO,qBAAQ;","names":[]}
1
+ {"version":3,"sources":["../mud.config.ts"],"sourcesContent":["import { defineWorld } from \"./ts/config/v2/world\";\n\n// Ideally we'd use a single multi-namespace config here, but we don't want\n// to break imports from this package because the source location changed.\n//\n// Once we have more nuanced control over source paths and codegen for each\n// namespace, then we could probably migrate to multi-namespace config.\n//\n// Or some way to deeply merge multiple configs while retaining strong types.\n\n/** @internal */\nexport const tablesConfig = defineWorld({\n namespace: \"world\",\n userTypes: {\n ResourceId: { filePath: \"@latticexyz/store/src/ResourceId.sol\", type: \"bytes32\" },\n },\n tables: {\n NamespaceOwner: {\n schema: {\n namespaceId: \"ResourceId\",\n owner: \"address\",\n },\n key: [\"namespaceId\"],\n },\n ResourceAccess: {\n schema: {\n resourceId: \"ResourceId\",\n caller: \"address\",\n access: \"bool\",\n },\n key: [\"resourceId\", \"caller\"],\n },\n InstalledModules: {\n schema: {\n moduleAddress: \"address\",\n argumentsHash: \"bytes32\", // Hash of the params passed to the `install` function\n isInstalled: \"bool\",\n },\n key: [\"moduleAddress\", \"argumentsHash\"],\n },\n UserDelegationControl: {\n schema: {\n delegator: \"address\",\n delegatee: \"address\",\n delegationControlId: \"ResourceId\",\n },\n key: [\"delegator\", \"delegatee\"],\n },\n NamespaceDelegationControl: {\n schema: {\n namespaceId: \"ResourceId\",\n delegationControlId: \"ResourceId\",\n },\n key: [\"namespaceId\"],\n },\n Balances: {\n schema: {\n namespaceId: \"ResourceId\",\n balance: \"uint256\",\n },\n key: [\"namespaceId\"],\n },\n Systems: {\n schema: {\n systemId: \"ResourceId\",\n system: \"address\",\n publicAccess: \"bool\",\n },\n key: [\"systemId\"],\n codegen: {\n dataStruct: false,\n },\n },\n SystemRegistry: {\n schema: {\n system: \"address\",\n systemId: \"ResourceId\",\n },\n key: [\"system\"],\n },\n SystemHooks: {\n schema: {\n systemId: \"ResourceId\",\n value: \"bytes21[]\",\n },\n key: [\"systemId\"],\n },\n FunctionSelectors: {\n schema: {\n worldFunctionSelector: \"bytes4\",\n systemId: \"ResourceId\",\n systemFunctionSelector: \"bytes4\",\n },\n key: [\"worldFunctionSelector\"],\n codegen: {\n dataStruct: false,\n },\n },\n FunctionSignatures: {\n type: \"offchainTable\",\n schema: {\n functionSelector: \"bytes4\",\n functionSignature: \"string\",\n },\n key: [\"functionSelector\"],\n },\n InitModuleAddress: {\n schema: {\n value: \"address\",\n },\n key: [],\n },\n },\n});\n\n/** @internal */\nexport const systemsConfig = defineWorld({\n namespace: \"\",\n codegen: {\n worldImportPath: \"./src\",\n worldgenDirectory: \"interfaces\",\n worldInterfaceName: \"IBaseWorld\",\n generateSystemLibraries: true,\n systemLibrariesDirectory: \"experimental/systems\",\n },\n // Keep aligned with src/modules/init/constants.sol\n systems: {\n AccessManagementSystem: {\n name: \"AccessManagement\",\n },\n BalanceTransferSystem: {\n name: \"BalanceTransfer\",\n },\n BatchCallSystem: {\n name: \"BatchCall\",\n },\n RegistrationSystem: {\n name: \"Registration\",\n },\n // abstract systems that are deployed as part of RegistrationSystem\n ModuleInstallationSystem: {\n name: \"Registration\",\n },\n StoreRegistrationSystem: {\n name: \"Registration\",\n },\n WorldRegistrationSystem: {\n name: \"Registration\",\n },\n },\n});\n\nexport default tablesConfig;\n"],"mappings":";;;;;AAWO,IAAM,eAAe,YAAY;AAAA,EACtC,WAAW;AAAA,EACX,WAAW;AAAA,IACT,YAAY,EAAE,UAAU,wCAAwC,MAAM,UAAU;AAAA,EAClF;AAAA,EACA,QAAQ;AAAA,IACN,gBAAgB;AAAA,MACd,QAAQ;AAAA,QACN,aAAa;AAAA,QACb,OAAO;AAAA,MACT;AAAA,MACA,KAAK,CAAC,aAAa;AAAA,IACrB;AAAA,IACA,gBAAgB;AAAA,MACd,QAAQ;AAAA,QACN,YAAY;AAAA,QACZ,QAAQ;AAAA,QACR,QAAQ;AAAA,MACV;AAAA,MACA,KAAK,CAAC,cAAc,QAAQ;AAAA,IAC9B;AAAA,I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AAA,QACN,kBAAkB;AAAA,QAClB,mBAAmB;AAAA,MACrB;AAAA,MACA,KAAK,CAAC,kBAAkB;AAAA,IAC1B;AAAA,IACA,mBAAmB;AAAA,MACjB,QAAQ;AAAA,QACN,OAAO;AAAA,MACT;AAAA,MACA,KAAK,CAAC;AAAA,IACR;AAAA,EACF;AACF,CAAC;AAGM,IAAM,gBAAgB,YAAY;AAAA,EACvC,WAAW;AAAA,EACX,SAAS;AAAA,IACP,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,oBAAoB;AAAA,IACpB,yBAAyB;AAAA,IACzB,0BAA0B;AAAA,EAC5B;AAAA;AAAA,EAEA,SAAS;AAAA,IACP,wBAAwB;AAAA,MACtB,MAAM;AAAA,IACR;AAAA,IACA,uBAAuB;AAAA,MACrB,MAAM;AAAA,IACR;AAAA,IACA,iBAAiB;AAAA,MACf,MAAM;AAAA,IACR;AAAA,IACA,oBAAoB;AAAA,MAClB,MAAM;AAAA,IACR;AAAA;AAAA,IAEA,0BAA0B;AAAA,MACxB,MAAM;AAAA,IACR;AAAA,IACA,yBAAyB;AAAA,MACvB,MAAM;AAAA,IACR;AAAA,IACA,yBAAyB;AAAA,MACvB,MAAM;AAAA,IACR;AAAA,EACF;AACF,CAAC;AAED,IAAO,qBAAQ;","names":[]}
@@ -7,7 +7,7 @@ import {
7
7
  resolveSystems,
8
8
  validateNamespace,
9
9
  validateSystems
10
- } from "./chunk-XSBK355I.js";
10
+ } from "./chunk-6E2JY6MZ.js";
11
11
 
12
12
  // ts/config/v2/namespaces.ts
13
13
  import { flatMorph } from "@ark/util";
@@ -111,4 +111,4 @@ export {
111
111
  resolveWorld,
112
112
  defineWorld
113
113
  };
114
- //# sourceMappingURL=chunk-2W4TKC47.js.map
114
+ //# sourceMappingURL=chunk-NVV4GS3R.js.map
@@ -3,13 +3,14 @@ import { Namespace as Namespace$1 } from '@latticexyz/store/internal';
3
3
  import { Hex } from 'viem';
4
4
 
5
5
  type Module = {
6
- /**
7
- * The name of the module
8
- * @deprecated
9
- */
10
- readonly name?: string;
11
6
  /** Should this module be installed as a root module? */
12
7
  readonly root: boolean;
8
+ /**
9
+ * Allow the module to call systems on your behalf.
10
+ * Useful when modules need to create namespaces or
11
+ * upgrade systems in namespaces you own.
12
+ */
13
+ readonly useDelegation: boolean;
13
14
  /** Arguments to be passed to the module's install method */
14
15
  readonly args: readonly (ValueWithType | DynamicResolution)[];
15
16
  /**
@@ -22,6 +23,11 @@ type Module = {
22
23
  * If not provided, it's assumed that this is a local module as part of the project's source and the artifact will be looked up in forge's output directory.
23
24
  */
24
25
  readonly artifactPath: string | undefined;
26
+ /**
27
+ * The name of the module
28
+ * @deprecated
29
+ */
30
+ readonly name?: string;
25
31
  };
26
32
  type SystemDeploy = {
27
33
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { W as WorldInput, d as defineWorld } from './world-Nl5BmMma.js';
2
- export { W as World } from './dynamicResolution-AmVd5Qtd.js';
1
+ export { W as WorldInput, d as defineWorld } from './world-NqdA4pfW.js';
2
+ export { W as World } from './dynamicResolution-Bul4y_B0.js';
3
3
  import '@ark/util';
4
4
  import '@latticexyz/store/internal';
5
5
  import 'viem';
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  defineWorld
3
- } from "./chunk-2W4TKC47.js";
4
- import "./chunk-XSBK355I.js";
3
+ } from "./chunk-NVV4GS3R.js";
4
+ import "./chunk-6E2JY6MZ.js";
5
5
  import "./chunk-5WRI5ZAA.js";
6
6
 
7
7
  // ts/worldEvents.ts
@@ -1,7 +1,7 @@
1
1
  import { Abi, ContractFunctionName, Hex, EncodeFunctionDataParameters, Address, Chain, Account, Client, Transport, WalletActions } from 'viem';
2
2
  import { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from 'abitype';
3
- export { C as CODEGEN_DEFAULTS, b as CONFIG_DEFAULTS, k as CodegenInput, D as DEPLOY_DEFAULTS, j as DeployInput, M as MODULE_DEFAULTS, i as ModuleInput, N as NamespaceInput, h as NamespacesInput, a as SYSTEM_DEFAULTS, S as SYSTEM_DEPLOY_DEFAULTS, e as SystemDeployInput, f as SystemInput, g as SystemsInput, V as ValidateSystemOptions, W as WorldInput, o as defineNamespaces, t as defineSystem, d as defineWorld, p as requiredSystemKey, r as resolveCodegen, c as resolveDeploy, l as resolveNamespace, y as resolveNamespaceMode, n as resolveNamespaces, s as resolveSystem, w as resolveSystems, z as resolveWorld, v as validateNamespace, m as validateNamespaces, q as validateSystem, u as validateSystems, x as validateWorld } from './world-Nl5BmMma.js';
4
- export { C as Codegen, f as Deploy, D as DynamicResolution, M as Module, N as Namespace, e as Namespaces, c as System, S as SystemDeploy, d as Systems, V as ValueWithType, W as World, i as isDynamicResolution, a as isValueWithType, r as resolveTableId, b as resolveWithContext } from './dynamicResolution-AmVd5Qtd.js';
3
+ export { C as CODEGEN_DEFAULTS, b as CONFIG_DEFAULTS, k as CodegenInput, D as DEPLOY_DEFAULTS, j as DeployInput, M as MODULE_DEFAULTS, i as ModuleInput, N as NamespaceInput, h as NamespacesInput, a as SYSTEM_DEFAULTS, S as SYSTEM_DEPLOY_DEFAULTS, e as SystemDeployInput, f as SystemInput, g as SystemsInput, V as ValidateSystemOptions, W as WorldInput, o as defineNamespaces, t as defineSystem, d as defineWorld, p as requiredSystemKey, r as resolveCodegen, c as resolveDeploy, l as resolveNamespace, y as resolveNamespaceMode, n as resolveNamespaces, s as resolveSystem, w as resolveSystems, z as resolveWorld, v as validateNamespace, m as validateNamespaces, q as validateSystem, u as validateSystems, x as validateWorld } from './world-NqdA4pfW.js';
4
+ export { C as Codegen, f as Deploy, D as DynamicResolution, M as Module, N as Namespace, e as Namespaces, c as System, S as SystemDeploy, d as Systems, V as ValueWithType, W as World, i as isDynamicResolution, a as isValueWithType, r as resolveTableId, b as resolveWithContext } from './dynamicResolution-Bul4y_B0.js';
5
5
  import '@ark/util';
6
6
  import '@latticexyz/store/internal';
7
7
  import '@latticexyz/store';
@@ -126,19 +126,21 @@ declare const worldCallAbi: readonly [{
126
126
  type worldCallAbi = typeof worldCallAbi;
127
127
 
128
128
  type SystemCall<abi extends Abi, functionName extends ContractFunctionName<abi>> = {
129
- /**
130
- * System ABI
131
- */
132
- readonly abi: abi;
133
- /**
134
- * System's resource ID
135
- */
136
- readonly systemId: Hex;
137
- /**
138
- * System function name to call
139
- */
140
- readonly functionName: functionName;
141
- } & Pick<EncodeFunctionDataParameters<abi, functionName>, "args">;
129
+ [k in ContractFunctionName<abi>]: {
130
+ /**
131
+ * System's resource ID
132
+ */
133
+ readonly systemId: Hex;
134
+ /**
135
+ * System ABI
136
+ */
137
+ readonly abi: abi;
138
+ /**
139
+ * System function name to call
140
+ */
141
+ readonly functionName: k;
142
+ } & Pick<EncodeFunctionDataParameters<abi, k>, "args">;
143
+ }[functionName];
142
144
  /** Encode a system call to be passed as arguments into `World.call` */
143
145
  declare function encodeSystemCall<abi extends Abi, functionName extends ContractFunctionName<abi>>({ abi, systemId, functionName, args, }: SystemCall<abi, functionName>): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, "call">["inputs"]>;
144
146
 
@@ -148,11 +150,14 @@ type SystemCallFrom<abi extends Abi, functionName extends ContractFunctionName<a
148
150
  /** Encode a system call to be passed as arguments into `World.callFrom` */
149
151
  declare function encodeSystemCallFrom<abi extends Abi, functionName extends ContractFunctionName<abi>>({ abi, from, systemId, functionName, args, }: SystemCallFrom<abi, functionName>): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, "callFrom">["inputs"]>;
150
152
 
153
+ type SystemCalls<abis extends readonly Abi[]> = {
154
+ [k in keyof abis]: SystemCall<abis[k], ContractFunctionName<abis[k]>>;
155
+ };
151
156
  /** Encode system calls to be passed as arguments into `World.batchCall` */
152
- declare function encodeSystemCalls<abi extends Abi, functionName extends ContractFunctionName<abi>>(abi: abi, systemCalls: readonly Omit<SystemCall<abi, functionName>, "abi">[]): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, "batchCall">["inputs"]>;
157
+ declare function encodeSystemCalls<abis extends readonly Abi[]>(systemCalls: SystemCalls<abis>): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, "batchCall">["inputs"]>;
153
158
 
154
159
  /** Encode system calls to be passed as arguments into `World.batchCallFrom` */
155
- declare function encodeSystemCallsFrom<abi extends Abi, functionName extends ContractFunctionName<abi>>(abi: abi, from: Address, systemCalls: readonly Omit<SystemCallFrom<abi, functionName>, "abi" | "from">[]): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, "batchCallFrom">["inputs"]>;
160
+ declare function encodeSystemCallsFrom<abis extends readonly Abi[]>(from: Address, systemCalls: SystemCalls<abis>): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, "batchCallFrom">["inputs"]>;
156
161
 
157
162
  type CallFromParameters = {
158
163
  worldAddress: Hex;
@@ -166,4 +171,4 @@ type SystemFunction = {
166
171
  };
167
172
  declare function callFrom(params: CallFromParameters): <chain extends Chain, account extends Account | undefined>(client: Client<Transport, chain, account>) => Pick<WalletActions<chain, account>, "writeContract">;
168
173
 
169
- export { type SystemCall, type SystemCallFrom, callFrom, encodeSystemCall, encodeSystemCallFrom, encodeSystemCalls, encodeSystemCallsFrom };
174
+ export { type SystemCall, type SystemCallFrom, type SystemCalls, callFrom, encodeSystemCall, encodeSystemCallFrom, encodeSystemCalls, encodeSystemCallsFrom };
package/dist/internal.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  mud_config_default
3
- } from "./chunk-PZKG3J66.js";
3
+ } from "./chunk-6KRKTNJ5.js";
4
4
  import {
5
5
  defineNamespaces,
6
6
  defineWorld,
@@ -10,7 +10,7 @@ import {
10
10
  resolveWorld,
11
11
  validateNamespaces,
12
12
  validateWorld
13
- } from "./chunk-2W4TKC47.js";
13
+ } from "./chunk-NVV4GS3R.js";
14
14
  import {
15
15
  CODEGEN_DEFAULTS,
16
16
  CONFIG_DEFAULTS,
@@ -25,7 +25,7 @@ import {
25
25
  validateNamespace,
26
26
  validateSystem,
27
27
  validateSystems
28
- } from "./chunk-XSBK355I.js";
28
+ } from "./chunk-6E2JY6MZ.js";
29
29
  import "./chunk-5WRI5ZAA.js";
30
30
 
31
31
  // ts/encodeSystemCall.ts
@@ -87,9 +87,9 @@ function encodeSystemCallFrom({
87
87
 
88
88
  // ts/encodeSystemCalls.ts
89
89
  import { encodeFunctionData as encodeFunctionData3 } from "viem";
90
- function encodeSystemCalls(abi, systemCalls) {
90
+ function encodeSystemCalls(systemCalls) {
91
91
  return [
92
- systemCalls.map(({ systemId, functionName, args }) => ({
92
+ systemCalls.map(({ abi, systemId, functionName, args }) => ({
93
93
  systemId,
94
94
  callData: encodeFunctionData3({
95
95
  abi,
@@ -102,9 +102,9 @@ function encodeSystemCalls(abi, systemCalls) {
102
102
 
103
103
  // ts/encodeSystemCallsFrom.ts
104
104
  import { encodeFunctionData as encodeFunctionData4 } from "viem";
105
- function encodeSystemCallsFrom(abi, from, systemCalls) {
105
+ function encodeSystemCallsFrom(from, systemCalls) {
106
106
  return [
107
- systemCalls.map(({ systemId, functionName, args }) => ({
107
+ systemCalls.map(({ abi, systemId, functionName, args }) => ({
108
108
  from,
109
109
  systemId,
110
110
  callData: encodeFunctionData4({
@@ -1 +1 @@
1
- {"version":3,"sources":["../ts/encodeSystemCall.ts","../ts/normalizeSystemFunctionName.ts","../ts/encodeSystemCallFrom.ts","../ts/encodeSystemCalls.ts","../ts/encodeSystemCallsFrom.ts","../ts/actions/callFrom.ts","../ts/config/v2/dynamicResolution.ts"],"sourcesContent":["import { Abi, EncodeFunctionDataParameters, Hex, encodeFunctionData, type ContractFunctionName } from \"viem\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\nimport { worldCallAbi } from \"./worldCallAbi\";\nimport { internal_normalizeSystemFunctionName } from \"./normalizeSystemFunctionName\";\n\nexport type SystemCall<abi extends Abi, functionName extends ContractFunctionName<abi>> = {\n /**\n * System ABI\n */\n readonly abi: abi;\n /**\n * System's resource ID\n */\n readonly systemId: Hex;\n /**\n * System function name to call\n */\n readonly functionName: functionName;\n} & Pick<EncodeFunctionDataParameters<abi, functionName>, \"args\">;\n\n/** Encode a system call to be passed as arguments into `World.call` */\nexport function encodeSystemCall<abi extends Abi, functionName extends ContractFunctionName<abi>>({\n abi,\n systemId,\n functionName,\n args,\n}: SystemCall<abi, functionName>): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, \"call\">[\"inputs\"]> {\n return [\n systemId,\n encodeFunctionData<abi, functionName>({\n abi,\n functionName: internal_normalizeSystemFunctionName(systemId, functionName),\n args,\n } as EncodeFunctionDataParameters<abi, functionName>),\n ];\n}\n","import { hexToResource, resourceToLabel } from \"@latticexyz/common\";\nimport { Hex } from \"viem\";\n\n/** @internal */\nexport function internal_normalizeSystemFunctionName(systemId: Hex, functionName: string) {\n const resource = hexToResource(systemId);\n const worldFunctionPrefix = resource.namespace !== \"\" ? `${resource.namespace}__` : null;\n if (worldFunctionPrefix != null && functionName.startsWith(worldFunctionPrefix)) {\n console.warn(\n // eslint-disable-next-line max-len\n `Detected world function name \"${functionName}\" used in call to system \"${resourceToLabel(resource)}\".\\n\\nIt's recommended to use a system ABI and system function name with these methods instead.`,\n );\n return functionName.slice(worldFunctionPrefix.length);\n }\n return functionName;\n}\n","import { Abi, EncodeFunctionDataParameters, encodeFunctionData, Address, type ContractFunctionName } from \"viem\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\nimport { SystemCall } from \"./encodeSystemCall\";\nimport { worldCallAbi } from \"./worldCallAbi\";\nimport { internal_normalizeSystemFunctionName } from \"./normalizeSystemFunctionName\";\n\nexport type SystemCallFrom<abi extends Abi, functionName extends ContractFunctionName<abi>> = SystemCall<\n abi,\n functionName\n> & {\n readonly from: Address;\n};\n\n/** Encode a system call to be passed as arguments into `World.callFrom` */\nexport function encodeSystemCallFrom<abi extends Abi, functionName extends ContractFunctionName<abi>>({\n abi,\n from,\n systemId,\n functionName,\n args,\n}: SystemCallFrom<abi, functionName>): AbiParametersToPrimitiveTypes<\n ExtractAbiFunction<worldCallAbi, \"callFrom\">[\"inputs\"]\n> {\n return [\n from,\n systemId,\n encodeFunctionData<abi, functionName>({\n abi,\n functionName: internal_normalizeSystemFunctionName(systemId, functionName),\n args,\n } as EncodeFunctionDataParameters<abi, functionName>),\n ];\n}\n","import { Abi, EncodeFunctionDataParameters, encodeFunctionData, type ContractFunctionName } from \"viem\";\nimport { SystemCall } from \"./encodeSystemCall\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\nimport { worldCallAbi } from \"./worldCallAbi\";\nimport { internal_normalizeSystemFunctionName } from \"./normalizeSystemFunctionName\";\n\n/** Encode system calls to be passed as arguments into `World.batchCall` */\nexport function encodeSystemCalls<abi extends Abi, functionName extends ContractFunctionName<abi>>(\n abi: abi,\n systemCalls: readonly Omit<SystemCall<abi, functionName>, \"abi\">[],\n): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, \"batchCall\">[\"inputs\"]> {\n return [\n systemCalls.map(({ systemId, functionName, args }) => ({\n systemId,\n callData: encodeFunctionData<abi, functionName>({\n abi,\n functionName: internal_normalizeSystemFunctionName(systemId, functionName),\n args,\n } as EncodeFunctionDataParameters<abi, functionName>),\n })),\n ];\n}\n","import { Abi, Address, EncodeFunctionDataParameters, encodeFunctionData, type ContractFunctionName } from \"viem\";\nimport { SystemCallFrom } from \"./encodeSystemCallFrom\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\nimport { worldCallAbi } from \"./worldCallAbi\";\nimport { internal_normalizeSystemFunctionName } from \"./normalizeSystemFunctionName\";\n\n/** Encode system calls to be passed as arguments into `World.batchCallFrom` */\nexport function encodeSystemCallsFrom<abi extends Abi, functionName extends ContractFunctionName<abi>>(\n abi: abi,\n from: Address,\n systemCalls: readonly Omit<SystemCallFrom<abi, functionName>, \"abi\" | \"from\">[],\n): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, \"batchCallFrom\">[\"inputs\"]> {\n return [\n systemCalls.map(({ systemId, functionName, args }) => ({\n from,\n systemId,\n callData: encodeFunctionData<abi, functionName>({\n abi,\n functionName: internal_normalizeSystemFunctionName(systemId, functionName),\n args,\n } as EncodeFunctionDataParameters<abi, functionName>),\n })),\n ];\n}\n","import {\n slice,\n concat,\n type Transport,\n type Chain,\n type Account,\n type Hex,\n type WalletActions,\n type Client,\n type PublicActions,\n type WriteContractParameters,\n type EncodeFunctionDataParameters,\n} from \"viem\";\nimport { getAction, encodeFunctionData } from \"viem/utils\";\nimport { readContract, writeContract as viem_writeContract } from \"viem/actions\";\nimport { readHex } from \"@latticexyz/common\";\nimport {\n getKeySchema,\n getValueSchema,\n getSchemaTypes,\n decodeValueArgs,\n encodeKey,\n} from \"@latticexyz/protocol-parser/internal\";\nimport worldConfig from \"../../mud.config\";\nimport { worldCallAbi } from \"../worldCallAbi\";\n\ntype CallFromParameters = {\n worldAddress: Hex;\n delegatorAddress: Hex;\n worldFunctionToSystemFunction?: (worldFunctionSelector: Hex) => Promise<SystemFunction>;\n publicClient?: Client;\n};\n\ntype SystemFunction = { systemId: Hex; systemFunctionSelector: Hex };\n\n// By extending viem clients with this function after delegation, the delegation is automatically applied to World contract writes.\n// This means that these writes are made on behalf of the delegator.\n// Internally, it transforms the write arguments to use `callFrom`.\n//\n// Accepts either `worldFunctionToSystemFunction` or `publicClient` as an argument.\n// `worldFunctionToSystemFunction` allows manually providing the mapping function, thus users can utilize their client store for the lookup.\n// If `publicClient` is provided instead, this function retrieves the corresponding system function from the World contract.\n//\n// The function mapping is cached to avoid redundant retrievals for the same World function.\nexport function callFrom(\n params: CallFromParameters,\n): <chain extends Chain, account extends Account | undefined>(\n client: Client<Transport, chain, account>,\n) => Pick<WalletActions<chain, account>, \"writeContract\"> {\n return (client) => ({\n async writeContract(writeArgs) {\n const _writeContract = getAction(client, viem_writeContract, \"writeContract\");\n\n // Skip if the contract isn't the World or the function called should not be redirected through `callFrom`.\n if (\n writeArgs.address !== params.worldAddress ||\n writeArgs.functionName === \"call\" ||\n writeArgs.functionName === \"callFrom\" ||\n writeArgs.functionName === \"batchCallFrom\" ||\n writeArgs.functionName === \"callWithSignature\"\n ) {\n return _writeContract(writeArgs);\n }\n\n // Wrap system calls from `batchCall` with delegator for a `batchCallFrom`\n // TODO: remove this specific workaround once https://github.com/latticexyz/mud/pull/3506 lands\n if (writeArgs.functionName === \"batchCall\") {\n const batchCallArgs = writeArgs as unknown as WriteContractParameters<worldCallAbi, \"batchCall\">;\n const [systemCalls] = batchCallArgs.args;\n if (!systemCalls.length) {\n throw new Error(\"`batchCall` should have at least one system call.\");\n }\n\n return _writeContract({\n ...batchCallArgs,\n functionName: \"batchCallFrom\",\n args: [systemCalls.map((systemCall) => ({ from: params.delegatorAddress, ...systemCall }))],\n });\n }\n\n // Encode the World's calldata (which includes the World's function selector).\n const worldCalldata = encodeFunctionData({\n abi: writeArgs.abi,\n functionName: writeArgs.functionName,\n args: writeArgs.args,\n } as unknown as EncodeFunctionDataParameters);\n\n // The first 4 bytes of calldata represent the function selector.\n const worldFunctionSelector = slice(worldCalldata, 0, 4);\n\n // Get the systemId and System's function selector.\n const { systemId, systemFunctionSelector } = await worldFunctionToSystemFunction({\n ...params,\n publicClient: params.publicClient ?? client,\n worldFunctionSelector,\n });\n\n // Construct the System's calldata by replacing the World's function selector with the System's.\n // Use `readHex` instead of `slice` to prevent out-of-bounds errors with calldata that has no args.\n const systemCalldata = concat([systemFunctionSelector, readHex(worldCalldata, 4)]);\n\n // Call `writeContract` with the new args.\n return _writeContract({\n ...(writeArgs as unknown as WriteContractParameters<worldCallAbi, \"callFrom\">),\n functionName: \"callFrom\",\n args: [params.delegatorAddress, systemId, systemCalldata],\n });\n },\n });\n}\n\nconst systemFunctionCache = new Map<Hex, SystemFunction>();\n\nasync function worldFunctionToSystemFunction(params: {\n worldAddress: Hex;\n delegatorAddress: Hex;\n worldFunctionSelector: Hex;\n worldFunctionToSystemFunction?: (worldFunctionSelector: Hex) => Promise<SystemFunction>;\n publicClient: Client;\n}): Promise<SystemFunction> {\n const cacheKey = concat([params.worldAddress, params.worldFunctionSelector]);\n\n // Use cache if the function has been called previously.\n const cached = systemFunctionCache.get(cacheKey);\n if (cached) return cached;\n\n // If a mapping function is provided, use it. Otherwise, call the World contract.\n const systemFunction = params.worldFunctionToSystemFunction\n ? await params.worldFunctionToSystemFunction(params.worldFunctionSelector)\n : await retrieveSystemFunctionFromContract(params.publicClient, params.worldAddress, params.worldFunctionSelector);\n\n systemFunctionCache.set(cacheKey, systemFunction);\n\n return systemFunction;\n}\n\nasync function retrieveSystemFunctionFromContract(\n publicClient: Client,\n worldAddress: Hex,\n worldFunctionSelector: Hex,\n): Promise<SystemFunction> {\n const table = worldConfig.tables.world__FunctionSelectors;\n\n const keySchema = getSchemaTypes(getKeySchema(table));\n const valueSchema = getSchemaTypes(getValueSchema(table));\n\n const _readContract = getAction(publicClient, readContract, \"readContract\") as PublicActions[\"readContract\"];\n\n const [staticData, encodedLengths, dynamicData] = await _readContract({\n address: worldAddress,\n abi: [\n {\n type: \"function\",\n name: \"getRecord\",\n inputs: [\n {\n name: \"tableId\",\n type: \"bytes32\",\n internalType: \"ResourceId\",\n },\n {\n name: \"keyTuple\",\n type: \"bytes32[]\",\n internalType: \"bytes32[]\",\n },\n ],\n outputs: [\n {\n name: \"staticData\",\n type: \"bytes\",\n internalType: \"bytes\",\n },\n {\n name: \"encodedLengths\",\n type: \"bytes32\",\n internalType: \"EncodedLengths\",\n },\n {\n name: \"dynamicData\",\n type: \"bytes\",\n internalType: \"bytes\",\n },\n ],\n stateMutability: \"view\",\n },\n ],\n functionName: \"getRecord\",\n args: [table.tableId, encodeKey(keySchema, { worldFunctionSelector })],\n });\n\n const decoded = decodeValueArgs(valueSchema, { staticData, encodedLengths, dynamicData });\n\n const systemFunction: SystemFunction = {\n systemId: decoded.systemId,\n systemFunctionSelector: decoded.systemFunctionSelector,\n };\n\n return systemFunction;\n}\n","import { World } from \"./output\";\n\nexport type DynamicResolution = {\n // TODO: add systemAddress support\n type: \"tableId\";\n input: string;\n};\n\nexport type ValueWithType = {\n value: string | number | Uint8Array;\n type: string;\n};\n\n/**\n * Dynamically resolve a table name to a table id at deploy time\n */\nexport function resolveTableId(tableName: string) {\n return {\n type: \"tableId\",\n input: tableName,\n } as const;\n}\n\n/** Type guard for DynamicResolution */\nexport function isDynamicResolution(value: unknown): value is DynamicResolution {\n return typeof value === \"object\" && value !== null && \"type\" in value && \"input\" in value;\n}\n\n/** Type guard for ValueWithType */\nexport function isValueWithType(value: unknown): value is ValueWithType {\n return typeof value === \"object\" && value !== null && \"type\" in value && \"value\" in value;\n}\n\n/**\n * Turn a DynamicResolution object into a ValueWithType based on the provided context\n */\nexport function resolveWithContext(\n input: unknown,\n context: { config: World; systemAddresses?: Record<string, Promise<string>> },\n): ValueWithType {\n if (isValueWithType(input)) return input;\n\n if (isDynamicResolution(input)) {\n if (input.type === \"tableId\") {\n const tableEntries = Object.entries(context.config.tables).filter(\n ([tableName, table]) => tableName === input.input || table.name === input.input,\n );\n\n if (tableEntries.length > 1) {\n throw new Error(\n `Found more than one table with name \"${input.input}\". Try using one of the following table names instead: ${tableEntries.map(([tableName]) => tableName).join(\", \")}`,\n );\n }\n\n if (tableEntries.length === 1) {\n const [entry] = tableEntries;\n const [, table] = entry;\n return { type: \"bytes32\", value: table.tableId };\n }\n }\n }\n\n throw new Error(`Could not resolve dynamic resolution:\\n${JSON.stringify(input, null, 2)}`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAiD,0BAAqD;;;ACAtG,SAAS,eAAe,uBAAuB;AAIxC,SAAS,qCAAqC,UAAe,cAAsB;AACxF,QAAM,WAAW,cAAc,QAAQ;AACvC,QAAM,sBAAsB,SAAS,cAAc,KAAK,GAAG,SAAS,SAAS,OAAO;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M,CAAC,EAAE,KAAK,IAAI;AAClB,eAAO,EAAE,MAAM,WAAW,OAAO,MAAM,QAAQ;AAAA,MACjD;AAAA,IACF;AAAA,EACF;AAEA,QAAM,IAAI,MAAM;AAAA,EAA0C,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC,EAAE;AAC5F;","names":["encodeFunctionData","encodeFunctionData","encodeFunctionData","encodeFunctionData","encodeFunctionData","encodeFunctionData","encodeFunctionData","encodeFunctionData"]}
1
+ {"version":3,"sources":["../ts/encodeSystemCall.ts","../ts/normalizeSystemFunctionName.ts","../ts/encodeSystemCallFrom.ts","../ts/encodeSystemCalls.ts","../ts/encodeSystemCallsFrom.ts","../ts/actions/callFrom.ts","../ts/config/v2/dynamicResolution.ts"],"sourcesContent":["import { Abi, EncodeFunctionDataParameters, Hex, encodeFunctionData, type ContractFunctionName } from \"viem\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\nimport { worldCallAbi } from \"./worldCallAbi\";\nimport { internal_normalizeSystemFunctionName } from \"./normalizeSystemFunctionName\";\n\nexport type SystemCall<abi extends Abi, functionName extends ContractFunctionName<abi>> = {\n [k in ContractFunctionName<abi>]: {\n /**\n * System's resource ID\n */\n readonly systemId: Hex;\n /**\n * System ABI\n */\n readonly abi: abi;\n /**\n * System function name to call\n */\n readonly functionName: k;\n } & Pick<EncodeFunctionDataParameters<abi, k>, \"args\">;\n}[functionName];\n\n/** Encode a system call to be passed as arguments into `World.call` */\nexport function encodeSystemCall<abi extends Abi, functionName extends ContractFunctionName<abi>>({\n abi,\n systemId,\n functionName,\n args,\n}: SystemCall<abi, functionName>): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, \"call\">[\"inputs\"]> {\n return [\n systemId,\n encodeFunctionData<abi, functionName>({\n abi,\n functionName: internal_normalizeSystemFunctionName(systemId, functionName),\n args,\n } as EncodeFunctionDataParameters<abi, functionName>),\n ];\n}\n","import { hexToResource, resourceToLabel } from \"@latticexyz/common\";\nimport { Hex } from \"viem\";\n\n/** @internal */\nexport function internal_normalizeSystemFunctionName(systemId: Hex, functionName: string) {\n const resource = hexToResource(systemId);\n const worldFunctionPrefix = resource.namespace !== \"\" ? `${resource.namespace}__` : null;\n if (worldFunctionPrefix != null && functionName.startsWith(worldFunctionPrefix)) {\n console.warn(\n // eslint-disable-next-line max-len\n `Detected world function name \"${functionName}\" used in call to system \"${resourceToLabel(resource)}\".\\n\\nIt's recommended to use a system ABI and system function name with these methods instead.`,\n );\n return functionName.slice(worldFunctionPrefix.length);\n }\n return functionName;\n}\n","import { Abi, EncodeFunctionDataParameters, encodeFunctionData, Address, type ContractFunctionName } from \"viem\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\nimport { SystemCall } from \"./encodeSystemCall\";\nimport { worldCallAbi } from \"./worldCallAbi\";\nimport { internal_normalizeSystemFunctionName } from \"./normalizeSystemFunctionName\";\n\nexport type SystemCallFrom<abi extends Abi, functionName extends ContractFunctionName<abi>> = SystemCall<\n abi,\n functionName\n> & {\n readonly from: Address;\n};\n\n/** Encode a system call to be passed as arguments into `World.callFrom` */\nexport function encodeSystemCallFrom<abi extends Abi, functionName extends ContractFunctionName<abi>>({\n abi,\n from,\n systemId,\n functionName,\n args,\n}: SystemCallFrom<abi, functionName>): AbiParametersToPrimitiveTypes<\n ExtractAbiFunction<worldCallAbi, \"callFrom\">[\"inputs\"]\n> {\n return [\n from,\n systemId,\n encodeFunctionData<abi, functionName>({\n abi,\n functionName: internal_normalizeSystemFunctionName(systemId, functionName),\n args,\n } as EncodeFunctionDataParameters<abi, functionName>),\n ];\n}\n","import { Abi, encodeFunctionData, type ContractFunctionName } from \"viem\";\nimport { SystemCall } from \"./encodeSystemCall\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\nimport { worldCallAbi } from \"./worldCallAbi\";\nimport { internal_normalizeSystemFunctionName } from \"./normalizeSystemFunctionName\";\n\nexport type SystemCalls<abis extends readonly Abi[]> = {\n [k in keyof abis]: SystemCall<abis[k], ContractFunctionName<abis[k]>>;\n};\n\n/** Encode system calls to be passed as arguments into `World.batchCall` */\nexport function encodeSystemCalls<abis extends readonly Abi[]>(\n systemCalls: SystemCalls<abis>,\n): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, \"batchCall\">[\"inputs\"]> {\n return [\n systemCalls.map(({ abi, systemId, functionName, args }) => ({\n systemId,\n callData: encodeFunctionData({\n abi,\n functionName: internal_normalizeSystemFunctionName(systemId, functionName),\n args,\n }),\n })),\n ];\n}\n","import { Abi, Address, encodeFunctionData } from \"viem\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\nimport { worldCallAbi } from \"./worldCallAbi\";\nimport { internal_normalizeSystemFunctionName } from \"./normalizeSystemFunctionName\";\nimport { SystemCalls } from \"./encodeSystemCalls\";\n\n/** Encode system calls to be passed as arguments into `World.batchCallFrom` */\nexport function encodeSystemCallsFrom<abis extends readonly Abi[]>(\n from: Address,\n systemCalls: SystemCalls<abis>,\n): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, \"batchCallFrom\">[\"inputs\"]> {\n return [\n systemCalls.map(({ abi, systemId, functionName, args }) => ({\n from,\n systemId,\n callData: encodeFunctionData({\n abi,\n functionName: internal_normalizeSystemFunctionName(systemId, functionName),\n args,\n }),\n })),\n ];\n}\n","import {\n slice,\n concat,\n type Transport,\n type Chain,\n type Account,\n type Hex,\n type WalletActions,\n type Client,\n type PublicActions,\n type WriteContractParameters,\n type EncodeFunctionDataParameters,\n} from \"viem\";\nimport { getAction, encodeFunctionData } from \"viem/utils\";\nimport { readContract, writeContract as viem_writeContract } from \"viem/actions\";\nimport { readHex } from \"@latticexyz/common\";\nimport {\n getKeySchema,\n getValueSchema,\n getSchemaTypes,\n decodeValueArgs,\n encodeKey,\n} from \"@latticexyz/protocol-parser/internal\";\nimport worldConfig from \"../../mud.config\";\nimport { worldCallAbi } from \"../worldCallAbi\";\n\ntype CallFromParameters = {\n worldAddress: Hex;\n delegatorAddress: Hex;\n worldFunctionToSystemFunction?: (worldFunctionSelector: Hex) => Promise<SystemFunction>;\n publicClient?: Client;\n};\n\ntype SystemFunction = { systemId: Hex; systemFunctionSelector: Hex };\n\n// By extending viem clients with this function after delegation, the delegation is automatically applied to World contract writes.\n// This means that these writes are made on behalf of the delegator.\n// Internally, it transforms the write arguments to use `callFrom`.\n//\n// Accepts either `worldFunctionToSystemFunction` or `publicClient` as an argument.\n// `worldFunctionToSystemFunction` allows manually providing the mapping function, thus users can utilize their client store for the lookup.\n// If `publicClient` is provided instead, this function retrieves the corresponding system function from the World contract.\n//\n// The function mapping is cached to avoid redundant retrievals for the same World function.\nexport function callFrom(\n params: CallFromParameters,\n): <chain extends Chain, account extends Account | undefined>(\n client: Client<Transport, chain, account>,\n) => Pick<WalletActions<chain, account>, \"writeContract\"> {\n return (client) => ({\n async writeContract(writeArgs) {\n const _writeContract = getAction(client, viem_writeContract, \"writeContract\");\n\n // Skip if the contract isn't the World or the function called should not be redirected through `callFrom`.\n if (\n writeArgs.address !== params.worldAddress ||\n writeArgs.functionName === \"call\" ||\n writeArgs.functionName === \"callFrom\" ||\n writeArgs.functionName === \"batchCallFrom\" ||\n writeArgs.functionName === \"callWithSignature\"\n ) {\n return _writeContract(writeArgs);\n }\n\n // Wrap system calls from `batchCall` with delegator for a `batchCallFrom`\n // TODO: remove this specific workaround once https://github.com/latticexyz/mud/pull/3506 lands\n if (writeArgs.functionName === \"batchCall\") {\n const batchCallArgs = writeArgs as unknown as WriteContractParameters<worldCallAbi, \"batchCall\">;\n const [systemCalls] = batchCallArgs.args;\n if (!systemCalls.length) {\n throw new Error(\"`batchCall` should have at least one system call.\");\n }\n\n return _writeContract({\n ...batchCallArgs,\n functionName: \"batchCallFrom\",\n args: [systemCalls.map((systemCall) => ({ from: params.delegatorAddress, ...systemCall }))],\n });\n }\n\n // Encode the World's calldata (which includes the World's function selector).\n const worldCalldata = encodeFunctionData({\n abi: writeArgs.abi,\n functionName: writeArgs.functionName,\n args: writeArgs.args,\n } as unknown as EncodeFunctionDataParameters);\n\n // The first 4 bytes of calldata represent the function selector.\n const worldFunctionSelector = slice(worldCalldata, 0, 4);\n\n // Get the systemId and System's function selector.\n const { systemId, systemFunctionSelector } = await worldFunctionToSystemFunction({\n ...params,\n publicClient: params.publicClient ?? client,\n worldFunctionSelector,\n });\n\n // Construct the System's calldata by replacing the World's function selector with the System's.\n // Use `readHex` instead of `slice` to prevent out-of-bounds errors with calldata that has no args.\n const systemCalldata = concat([systemFunctionSelector, readHex(worldCalldata, 4)]);\n\n // Call `writeContract` with the new args.\n return _writeContract({\n ...(writeArgs as unknown as WriteContractParameters<worldCallAbi, \"callFrom\">),\n functionName: \"callFrom\",\n args: [params.delegatorAddress, systemId, systemCalldata],\n });\n },\n });\n}\n\nconst systemFunctionCache = new Map<Hex, SystemFunction>();\n\nasync function worldFunctionToSystemFunction(params: {\n worldAddress: Hex;\n delegatorAddress: Hex;\n worldFunctionSelector: Hex;\n worldFunctionToSystemFunction?: (worldFunctionSelector: Hex) => Promise<SystemFunction>;\n publicClient: Client;\n}): Promise<SystemFunction> {\n const cacheKey = concat([params.worldAddress, params.worldFunctionSelector]);\n\n // Use cache if the function has been called previously.\n const cached = systemFunctionCache.get(cacheKey);\n if (cached) return cached;\n\n // If a mapping function is provided, use it. Otherwise, call the World contract.\n const systemFunction = params.worldFunctionToSystemFunction\n ? await params.worldFunctionToSystemFunction(params.worldFunctionSelector)\n : await retrieveSystemFunctionFromContract(params.publicClient, params.worldAddress, params.worldFunctionSelector);\n\n systemFunctionCache.set(cacheKey, systemFunction);\n\n return systemFunction;\n}\n\nasync function retrieveSystemFunctionFromContract(\n publicClient: Client,\n worldAddress: Hex,\n worldFunctionSelector: Hex,\n): Promise<SystemFunction> {\n const table = worldConfig.tables.world__FunctionSelectors;\n\n const keySchema = getSchemaTypes(getKeySchema(table));\n const valueSchema = getSchemaTypes(getValueSchema(table));\n\n const _readContract = getAction(publicClient, readContract, \"readContract\") as PublicActions[\"readContract\"];\n\n const [staticData, encodedLengths, dynamicData] = await _readContract({\n address: worldAddress,\n abi: [\n {\n type: \"function\",\n name: \"getRecord\",\n inputs: [\n {\n name: \"tableId\",\n type: \"bytes32\",\n internalType: \"ResourceId\",\n },\n {\n name: \"keyTuple\",\n type: \"bytes32[]\",\n internalType: \"bytes32[]\",\n },\n ],\n outputs: [\n {\n name: \"staticData\",\n type: \"bytes\",\n internalType: \"bytes\",\n },\n {\n name: \"encodedLengths\",\n type: \"bytes32\",\n internalType: \"EncodedLengths\",\n },\n {\n name: \"dynamicData\",\n type: \"bytes\",\n internalType: \"bytes\",\n },\n ],\n stateMutability: \"view\",\n },\n ],\n functionName: \"getRecord\",\n args: [table.tableId, encodeKey(keySchema, { worldFunctionSelector })],\n });\n\n const decoded = decodeValueArgs(valueSchema, { staticData, encodedLengths, dynamicData });\n\n const systemFunction: SystemFunction = {\n systemId: decoded.systemId,\n systemFunctionSelector: decoded.systemFunctionSelector,\n };\n\n return systemFunction;\n}\n","import { World } from \"./output\";\n\nexport type DynamicResolution = {\n // TODO: add systemAddress support\n type: \"tableId\";\n input: string;\n};\n\nexport type ValueWithType = {\n value: string | number | Uint8Array;\n type: string;\n};\n\n/**\n * Dynamically resolve a table name to a table id at deploy time\n */\nexport function resolveTableId(tableName: string) {\n return {\n type: \"tableId\",\n input: tableName,\n } as const;\n}\n\n/** Type guard for DynamicResolution */\nexport function isDynamicResolution(value: unknown): value is DynamicResolution {\n return typeof value === \"object\" && value !== null && \"type\" in value && \"input\" in value;\n}\n\n/** Type guard for ValueWithType */\nexport function isValueWithType(value: unknown): value is ValueWithType {\n return typeof value === \"object\" && value !== null && \"type\" in value && \"value\" in value;\n}\n\n/**\n * Turn a DynamicResolution object into a ValueWithType based on the provided context\n */\nexport function resolveWithContext(\n input: unknown,\n context: { config: World; systemAddresses?: Record<string, Promise<string>> },\n): ValueWithType {\n if (isValueWithType(input)) return input;\n\n if (isDynamicResolution(input)) {\n if (input.type === \"tableId\") {\n const tableEntries = Object.entries(context.config.tables).filter(\n ([tableName, table]) => tableName === input.input || table.name === input.input,\n );\n\n if (tableEntries.length > 1) {\n throw new Error(\n `Found more than one table with name \"${input.input}\". Try using one of the following table names instead: ${tableEntries.map(([tableName]) => tableName).join(\", \")}`,\n );\n }\n\n if (tableEntries.length === 1) {\n const [entry] = tableEntries;\n const [, table] = entry;\n return { type: \"bytes32\", value: table.tableId };\n }\n }\n }\n\n throw new Error(`Could not resolve dynamic resolution:\\n${JSON.stringify(input, null, 2)}`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAiD,0BAAqD;;;ACAtG,SAAS,eAAe,uBAAuB;AAIxC,SAAS,qCAAqC,UAAe,cAAsB;AACxF,QAAM,WAAW,cAAc,QAAQ;AACvC,QAAM,sBAAsB,SAAS,cAAc,KAAK,GAAG,SAAS,SAAS,OAAO;AACpF,MAAI,uBAAuB,QAAQ,aAAa,WAAW,mBAAmB,GAAG;AAC/E,YAAQ;AAAA;AAAA,MAEN,iCAAiC,YAAY,6BAA6B,gBAAgB,QAAQ,CAAC;AAAA;AAAA;AAAA,IACrG;AACA,WAAO,aAAa,MAAM,oBAAoB,MAAM;AAAA,EACtD;AACA,SAAO;AACT;;;ADQO,SAAS,iBAAkF;AAAA,EAChG;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAqH;AACnH,SAAO;AAAA,IACL;AAAA,IACA,mBAAsC;AAAA,MACpC;AAAA,MACA,cAAc,qCAAqC,UAAU,YAAY;AAAA,MACzE;AAAA,IACF,CAAoD;AAAA,EACtD;AACF;;;AErCA,SAA4C,sBAAAA,2BAA8D;AAcnG,SAAS,qBAAsF;AAAA,EACpG;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAEE;AACA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACAC,oBAAsC;AAAA,MACpC;A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B,OAAwC;AACtE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU,SAAS,WAAW;AACtF;AAKO,SAAS,mBACd,OACA,SACe;AACf,MAAI,gBAAgB,KAAK,EAAG,QAAO;AAEnC,MAAI,oBAAoB,KAAK,GAAG;AAC9B,QAAI,MAAM,SAAS,WAAW;AAC5B,YAAM,eAAe,OAAO,QAAQ,QAAQ,OAAO,MAAM,EAAE;AAAA,QACzD,CAAC,CAAC,WAAW,KAAK,MAAM,cAAc,MAAM,SAAS,MAAM,SAAS,MAAM;AAAA,MAC5E;AAEA,UAAI,aAAa,SAAS,GAAG;AAC3B,cAAM,IAAI;AAAA,UACR,wCAAwC,MAAM,KAAK,0DAA0D,aAAa,IAAI,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,IAAI,CAAC;AAAA,QACtK;AAAA,MACF;AAEA,UAAI,aAAa,WAAW,GAAG;AAC7B,cAAM,CAAC,KAAK,IAAI;AAChB,cAAM,CAAC,EAAE,KAAK,IAAI;AAClB,eAAO,EAAE,MAAM,WAAW,OAAO,MAAM,QAAQ;AAAA,MACjD;AAAA,IACF;AAAA,EACF;AAEA,QAAM,IAAI,MAAM;AAAA,EAA0C,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC,EAAE;AAC5F;","names":["encodeFunctionData","encodeFunctionData","encodeFunctionData","encodeFunctionData","encodeFunctionData","encodeFunctionData","encodeFunctionData","encodeFunctionData"]}
@@ -2,9 +2,9 @@ import {
2
2
  mud_config_default,
3
3
  systemsConfig,
4
4
  tablesConfig
5
- } from "./chunk-PZKG3J66.js";
6
- import "./chunk-2W4TKC47.js";
7
- import "./chunk-XSBK355I.js";
5
+ } from "./chunk-6KRKTNJ5.js";
6
+ import "./chunk-NVV4GS3R.js";
7
+ import "./chunk-6E2JY6MZ.js";
8
8
  import "./chunk-5WRI5ZAA.js";
9
9
  export {
10
10
  mud_config_default as default,
package/dist/node.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ImportDatum, ContractInterfaceFunction, ContractInterfaceError } from '@latticexyz/common/codegen';
2
- import { W as World, c as System } from './dynamicResolution-AmVd5Qtd.js';
2
+ import { W as World, c as System } from './dynamicResolution-Bul4y_B0.js';
3
3
  import { Hex, Abi } from 'viem';
4
4
  import * as arktype_internal_subtypes_object_ts from 'arktype/internal/subtypes/object.ts';
5
5
  import * as arktype_internal_ast_ts from 'arktype/internal/ast.ts';
package/dist/node.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  resolveNamespace
3
- } from "./chunk-XSBK355I.js";
3
+ } from "./chunk-6E2JY6MZ.js";
4
4
  import {
5
5
  __commonJS,
6
6
  __toESM
@@ -1,6 +1,6 @@
1
1
  import { requiredKeyOf, ErrorMessage, narrow, show, conform, withJsDoc } from '@ark/util';
2
2
  import { NamespaceInput as NamespaceInput$1, StoreInput, mergeIfUndefined, Scope, AbiTypeScope, validateNamespace as validateNamespace$1, resolveNamespace as resolveNamespace$1, extendedScope, validateStore, CONFIG_DEFAULTS as CONFIG_DEFAULTS$1, resolveStore, flattenNamespacedTables } from '@latticexyz/store/internal';
3
- import { S as SystemDeploy, V as ValueWithType, D as DynamicResolution, C as Codegen, W as World } from './dynamicResolution-AmVd5Qtd.js';
3
+ import { S as SystemDeploy, V as ValueWithType, D as DynamicResolution, C as Codegen, W as World } from './dynamicResolution-Bul4y_B0.js';
4
4
  import { Hex } from 'viem';
5
5
  import { StoreInput as StoreInput$1 } from '@latticexyz/store';
6
6
 
@@ -65,6 +65,13 @@ type ModuleInput = ModuleInputArtifactPath & {
65
65
  * @default false
66
66
  */
67
67
  readonly root?: boolean;
68
+ /**
69
+ * Allow the module to call systems on your behalf.
70
+ * Useful when modules need to create namespaces or
71
+ * upgrade systems in namespaces you own.
72
+ * @default false
73
+ */
74
+ readonly useDelegation?: boolean;
68
75
  /** Arguments to be passed to the module's install method */
69
76
  readonly args?: readonly (ValueWithType | DynamicResolution)[];
70
77
  };
@@ -127,6 +134,7 @@ declare const SYSTEM_DEFAULTS: {
127
134
  type SYSTEM_DEFAULTS = typeof SYSTEM_DEFAULTS;
128
135
  declare const MODULE_DEFAULTS: {
129
136
  readonly root: false;
137
+ readonly useDelegation: false;
130
138
  readonly args: readonly [];
131
139
  readonly artifactPath: undefined;
132
140
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/world",
3
- "version": "2.2.20-06e48e0239a5c7994ce73b4d2752860743fec4b0",
3
+ "version": "2.2.20-31870811b975d44f4b5d14ae69fd623914237584",
4
4
  "description": "World framework",
5
5
  "repository": {
6
6
  "type": "git",
@@ -43,12 +43,12 @@
43
43
  "abitype": "1.0.6",
44
44
  "arktype": "2.0.0-beta.6",
45
45
  "debug": "^4.3.4",
46
- "@latticexyz/block-logs-stream": "2.2.20-06e48e0239a5c7994ce73b4d2752860743fec4b0",
47
- "@latticexyz/common": "2.2.20-06e48e0239a5c7994ce73b4d2752860743fec4b0",
48
- "@latticexyz/config": "2.2.20-06e48e0239a5c7994ce73b4d2752860743fec4b0",
49
- "@latticexyz/protocol-parser": "2.2.20-06e48e0239a5c7994ce73b4d2752860743fec4b0",
50
- "@latticexyz/schema-type": "2.2.20-06e48e0239a5c7994ce73b4d2752860743fec4b0",
51
- "@latticexyz/store": "2.2.20-06e48e0239a5c7994ce73b4d2752860743fec4b0"
46
+ "@latticexyz/block-logs-stream": "2.2.20-31870811b975d44f4b5d14ae69fd623914237584",
47
+ "@latticexyz/common": "2.2.20-31870811b975d44f4b5d14ae69fd623914237584",
48
+ "@latticexyz/config": "2.2.20-31870811b975d44f4b5d14ae69fd623914237584",
49
+ "@latticexyz/protocol-parser": "2.2.20-31870811b975d44f4b5d14ae69fd623914237584",
50
+ "@latticexyz/schema-type": "2.2.20-31870811b975d44f4b5d14ae69fd623914237584",
51
+ "@latticexyz/store": "2.2.20-31870811b975d44f4b5d14ae69fd623914237584"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/debug": "^4.1.7",
@@ -59,8 +59,8 @@
59
59
  "glob": "^10.4.2",
60
60
  "solhint": "^3.3.7",
61
61
  "viem": "2.21.19",
62
- "@latticexyz/abi-ts": "2.2.20-06e48e0239a5c7994ce73b4d2752860743fec4b0",
63
- "@latticexyz/gas-report": "2.2.20-06e48e0239a5c7994ce73b4d2752860743fec4b0"
62
+ "@latticexyz/abi-ts": "2.2.20-31870811b975d44f4b5d14ae69fd623914237584",
63
+ "@latticexyz/gas-report": "2.2.20-31870811b975d44f4b5d14ae69fd623914237584"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "viem": "2.x"
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../ts/config/v2/defaults.ts","../ts/config/v2/system.ts","../ts/config/v2/systems.ts","../ts/config/v2/namespace.ts"],"sourcesContent":["import { CodegenInput, DeployInput, ModuleInput, SystemDeployInput, SystemInput, WorldInput } from \"./input\";\n\nexport const SYSTEM_DEPLOY_DEFAULTS = {\n disabled: false,\n registerWorldFunctions: true,\n} as const satisfies Required<SystemDeployInput>;\n\nexport type SYSTEM_DEPLOY_DEFAULTS = typeof SYSTEM_DEPLOY_DEFAULTS;\n\nexport const SYSTEM_DEFAULTS = {\n namespaceLabel: \"\",\n openAccess: true,\n accessList: [],\n} as const satisfies Omit<Required<SystemInput>, \"label\" | \"namespace\" | \"name\" | \"deploy\">;\n\nexport type SYSTEM_DEFAULTS = typeof SYSTEM_DEFAULTS;\n\nexport const MODULE_DEFAULTS = {\n root: false,\n args: [],\n artifactPath: undefined,\n} as const satisfies Pick<ModuleInput, \"root\" | \"args\" | \"artifactPath\">;\n\nexport type MODULE_DEFAULTS = typeof MODULE_DEFAULTS;\n\nexport const CODEGEN_DEFAULTS = {\n worldInterfaceName: \"IWorld\",\n worldgenDirectory: \"world\",\n systemLibrariesDirectory: \"systems\",\n generateSystemLibraries: false,\n worldImportPath: \"@latticexyz/world/src\",\n} as const satisfies CodegenInput;\n\nexport type CODEGEN_DEFAULTS = typeof CODEGEN_DEFAULTS;\n\nexport const DEPLOY_DEFAULTS = {\n postDeployScript: \"PostDeploy\",\n deploysDirectory: \"./deploys\",\n worldsFile: \"./worlds.json\",\n upgradeableWorldImplementation: false,\n} as const satisfies DeployInput;\n\nexport type DEPLOY_DEFAULTS = typeof DEPLOY_DEFAULTS;\n\nexport const CONFIG_DEFAULTS = {\n systems: {},\n tables: {},\n excludeSystems: [],\n modules: [],\n codegen: CODEGEN_DEFAULTS,\n deploy: DEPLOY_DEFAULTS,\n} as const satisfies WorldInput;\n\nexport type CONFIG_DEFAULTS = typeof CONFIG_DEFAULTS;\n","import { SYSTEM_DEFAULTS, SYSTEM_DEPLOY_DEFAULTS } from \"./defaults\";\nimport { SystemInput } from \"./input\";\nimport { hasOwnKey, mergeIfUndefined } from \"@latticexyz/store/internal\";\nimport { ErrorMessage, narrow, requiredKeyOf, show } from \"@ark/util\";\nimport { Hex } from \"viem\";\nimport { resourceToHex } from \"@latticexyz/common\";\n\nexport type ValidateSystemOptions = { readonly inNamespace?: true };\n\nexport type requiredSystemKey<inNamespace extends true | undefined> = Exclude<\n requiredKeyOf<SystemInput>,\n inNamespace extends true ? \"label\" | \"namespaceLabel\" | \"namespace\" : never\n>;\n\nexport type validateSystem<input, options extends ValidateSystemOptions = {}> = {\n [key in keyof input | requiredSystemKey<options[\"inNamespace\"]>]: key extends keyof SystemInput\n ? key extends \"label\" | \"namespaceLabel\" | \"namespace\"\n ? options[\"inNamespace\"] extends true\n ? ErrorMessage<\"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for systems in this context.\">\n : key extends keyof input\n ? narrow<input[key]>\n : never\n : SystemInput[key]\n : ErrorMessage<`Key \\`${key & string}\\` does not exist in SystemInput`>;\n};\n\nexport function validateSystem<input>(\n input: input,\n options: ValidateSystemOptions = {},\n): asserts input is SystemInput & input {\n if (typeof input !== \"object\" || input == null) {\n throw new Error(`Expected full system config, got \\`${JSON.stringify(input)}\\``);\n }\n\n if (\n options.inNamespace &&\n (hasOwnKey(input, \"label\") || hasOwnKey(input, \"namespaceLabel\") || hasOwnKey(input, \"namespace\"))\n ) {\n throw new Error(\n \"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for systems in this context.\",\n );\n }\n\n if (\n hasOwnKey(input, \"namespaceLabel\") &&\n typeof input.namespaceLabel === \"string\" &&\n (!hasOwnKey(input, \"namespace\") || typeof input.namespace !== \"string\") &&\n input.namespaceLabel.length > 14\n ) {\n throw new Error(\n `System \\`namespace\\` defaults to \\`namespaceLabel\\`, but must fit into a \\`bytes14\\` and \"${input.namespaceLabel}\" is too long. Provide explicit \\`namespace\\` override.`,\n );\n }\n\n if (hasOwnKey(input, \"namespace\") && typeof input.namespace === \"string\" && input.namespace.length > 14) {\n throw new Error(`System \\`namespace\\` must fit into a \\`bytes14\\`, but \"${input.namespace}\" is too long.`);\n }\n if (hasOwnKey(input, \"name\") && typeof input.name === \"string\" && input.name.length > 16) {\n throw new Error(`System \\`name\\` must fit into a \\`bytes16\\`, but \"${input.name}\" is too long.`);\n }\n}\n\nexport type resolveSystem<input> = input extends SystemInput\n ? {\n readonly label: input[\"label\"];\n readonly namespaceLabel: undefined extends input[\"namespaceLabel\"]\n ? typeof SYSTEM_DEFAULTS.namespaceLabel\n : input[\"namespaceLabel\"];\n readonly namespace: string;\n readonly name: string;\n readonly systemId: Hex;\n readonly openAccess: undefined extends input[\"openAccess\"] ? SYSTEM_DEFAULTS[\"openAccess\"] : input[\"openAccess\"];\n readonly accessList: undefined extends input[\"accessList\"] ? SYSTEM_DEFAULTS[\"accessList\"] : input[\"accessList\"];\n readonly deploy: show<\n mergeIfUndefined<undefined extends input[\"deploy\"] ? {} : input[\"deploy\"], SYSTEM_DEPLOY_DEFAULTS>\n >;\n }\n : never;\n\nexport function resolveSystem<input extends SystemInput>(input: input): resolveSystem<input> {\n const namespaceLabel = input.namespaceLabel ?? SYSTEM_DEFAULTS.namespaceLabel;\n // validate ensures this is length constrained\n const namespace = input.namespace ?? namespaceLabel;\n\n const label = input.label;\n const name = input.name ?? label.slice(0, 16);\n const systemId = resourceToHex({ type: \"system\", namespace, name });\n\n return mergeIfUndefined(\n {\n ...input,\n label,\n namespaceLabel,\n namespace,\n name,\n systemId,\n deploy: mergeIfUndefined(input.deploy ?? {}, SYSTEM_DEPLOY_DEFAULTS),\n },\n SYSTEM_DEFAULTS,\n ) as never;\n}\n\nexport function defineSystem<input>(input: validateSystem<input>): resolveSystem<input> {\n validateSystem(input);\n return resolveSystem(input) as never;\n}\n","import { ErrorMessage } from \"@ark/util\";\nimport { isObject } from \"@latticexyz/store/internal\";\nimport { SystemsInput } from \"./input\";\nimport { resolveSystem, validateSystem } from \"./system\";\n\n// TODO: add nuance between \"in namespace\" (namespace provided in context) and \"in systems\" (label provided in context)\n\nexport type validateSystems<input> = {\n [label in keyof input]: input[label] extends object\n ? validateSystem<input[label], { inNamespace: true }>\n : ErrorMessage<`Expected a system config for ${label & string}.`>;\n};\n\nexport function validateSystems(input: unknown): asserts input is SystemsInput {\n if (isObject(input)) {\n for (const system of Object.values(input)) {\n validateSystem(system, { inNamespace: true });\n }\n return;\n }\n throw new Error(`Expected system config, received ${JSON.stringify(input)}`);\n}\n\nexport type resolveSystems<systems extends SystemsInput, namespaceLabel extends string> = {\n [label in keyof systems]: resolveSystem<\n systems[label] & { label: label; namespaceLabel: namespaceLabel; namespace: string }\n >;\n};\n\nexport function resolveSystems<systems extends SystemsInput, namespaceLabel extends string>(\n systems: systems,\n namespaceLabel: namespaceLabel,\n namespace: string,\n): resolveSystems<systems, namespaceLabel> {\n return Object.fromEntries(\n Object.entries(systems).map(([label, system]) => {\n return [label, resolveSystem({ ...system, label, namespaceLabel, namespace })];\n }),\n ) as never;\n}\n","import { NamespaceInput, SystemsInput } from \"./input\";\nimport {\n hasOwnKey,\n validateNamespace as validateStoreNamespace,\n resolveNamespace as resolveStoreNamespace,\n Scope,\n AbiTypeScope,\n} from \"@latticexyz/store/internal\";\nimport { resolveSystems, validateSystems } from \"./systems\";\nimport { show } from \"@ark/util\";\n\nexport type validateNamespace<input, scope extends Scope = AbiTypeScope> = {\n [key in keyof input]: key extends \"systems\" ? validateSystems<input[key]> : validateStoreNamespace<input, scope>[key];\n};\n\nexport function validateNamespace<scope extends Scope = AbiTypeScope>(\n input: unknown,\n scope: scope,\n): asserts input is NamespaceInput {\n if (hasOwnKey(input, \"systems\")) {\n validateSystems(input.systems);\n }\n validateStoreNamespace(input, scope);\n}\n\nexport type resolveNamespace<input, scope extends Scope = AbiTypeScope> = input extends NamespaceInput\n ? show<\n resolveStoreNamespace<input, scope> & {\n readonly systems: input[\"systems\"] extends SystemsInput\n ? show<resolveSystems<input[\"systems\"], resolveStoreNamespace<input, scope>[\"label\"]>>\n : {};\n }\n >\n : never;\n\nexport function resolveNamespace<const input extends NamespaceInput, scope extends Scope = AbiTypeScope>(\n input: input,\n scope: scope = AbiTypeScope as never,\n): resolveNamespace<input, scope> {\n const namespace = resolveStoreNamespace(input, scope);\n const systems = resolveSystems(input.systems ?? {}, namespace.label, namespace.namespace);\n return {\n ...namespace,\n systems,\n } as never;\n}\n"],"mappings":";AAEO,IAAM,yBAAyB;AAAA,EACpC,UAAU;AAAA,EACV,wBAAwB;AAC1B;AAIO,IAAM,kBAAkB;AAAA,EAC7B,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,YAAY,CAAC;AACf;AAIO,IAAM,kBAAkB;AAAA,EAC7B,MAAM;AAAA,EACN,MAAM,CAAC;AAAA,EACP,cAAc;AAChB;AAIO,IAAM,mBAAmB;AAAA,EAC9B,oBAAoB;AAAA,EACpB,mBAAmB;AAAA,EACnB,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA,EACzB,iBAAiB;AACnB;AAIO,IAAM,kBAAkB;AAAA,EAC7B,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,YAAY;AAAA,EACZ,gCAAgC;AAClC;AAIO,IAAM,kBAAkB;AAAA,EAC7B,SAAS,CAAC;AAAA,EACV,QAAQ,CAAC;AAAA,EACT,gBA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