@latticexyz/world 2.2.18-9fa07c8489f1fbf167d0db01cd9aaa645a29c8e2 → 2.2.18-c2ad22c7feb566e1731ff16e8be291746bdffb3e
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-SGUPOG6A.js +2 -0
- package/dist/{IBaseWorld.abi-S745M2QE.js.map → IBaseWorld.abi-SGUPOG6A.js.map} +1 -1
- package/dist/System.abi-D2D3OAI5.js +2 -0
- package/dist/{System.abi-UHI2DJK6.js.map → System.abi-D2D3OAI5.js.map} +1 -1
- package/dist/chunk-AJUHOWGE.js +2 -0
- package/dist/{chunk-S5LARYWY.js.map → chunk-AJUHOWGE.js.map} +1 -1
- package/dist/chunk-CGF3NYHC.js +2 -0
- package/dist/chunk-CGF3NYHC.js.map +1 -0
- package/dist/chunk-DIHBEOC2.js +2 -0
- package/dist/{chunk-TL2M3LZH.js.map → chunk-DIHBEOC2.js.map} +1 -1
- package/dist/chunk-FW4363Y4.js +2 -0
- package/dist/index.js +1 -20
- package/dist/index.js.map +1 -1
- package/dist/internal.js +3 -318
- package/dist/internal.js.map +1 -1
- package/dist/mud.config.js +1 -11
- package/dist/node.js +102 -7328
- package/dist/node.js.map +1 -1
- package/package.json +14 -49
- package/dist/IBaseWorld.abi-S745M2QE.js +0 -2015
- package/dist/System.abi-UHI2DJK6.js +0 -67
- package/dist/chunk-AAKXFFCU.js +0 -158
- package/dist/chunk-AAKXFFCU.js.map +0 -1
- package/dist/chunk-AAWFTQHP.js +0 -35
- package/dist/chunk-S5LARYWY.js +0 -136
- package/dist/chunk-TL2M3LZH.js +0 -119
- package/dist/dynamicResolution-AmVd5Qtd.d.cts +0 -161
- package/dist/index.cjs +0 -241
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -11
- package/dist/internal.cjs +0 -656
- package/dist/internal.cjs.map +0 -1
- package/dist/internal.d.cts +0 -169
- package/dist/mud.config.cjs +0 -357
- package/dist/mud.config.cjs.map +0 -1
- package/dist/mud.config.d.cts +0 -869
- package/dist/node.cjs +0 -9599
- package/dist/node.cjs.map +0 -1
- package/dist/node.d.cts +0 -131
- package/dist/world-DUniZQxy.d.cts +0 -266
- /package/dist/{chunk-AAWFTQHP.js.map → chunk-FW4363Y4.js.map} +0 -0
@@ -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 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,IAAMA,EAAyB,CACpC,SAAU,GACV,uBAAwB,EAC1B,EAIaC,EAAkB,CAC7B,eAAgB,GAChB,WAAY,GACZ,WAAY,CAAC,CACf,EAIaC,EAAkB,CAC7B,KAAM,GACN,KAAM,CAAC,EACP,aAAc,MAChB,EAIaC,EAAmB,CAC9B,mBAAoB,SACpB,kBAAmB,QACnB,yBAA0B,UAC1B,wBAAyB,GACzB,gBAAiB,uBACnB,EAIaC,EAAkB,CAC7B,iBAAkB,aAClB,iBAAkB,YAClB,WAAY,gBACZ,+BAAgC,EAClC,EAIaC,EAAkB,CAC7B,QAAS,CAAC,EACV,OAAQ,CAAC,EACT,eAAgB,CAAC,EACjB,QAAS,CAAC,EACV,QAASF,EACT,OAAQC,CACV,ECjDA,OAAS,aAAAE,EAAW,oBAAAC,MAAwB,6BAG5C,OAAS,iBAAAC,MAAqB,qBAqBvB,SAASC,EACdC,EACAC,EAAiC,CAAC,EACI,CACtC,GAAI,OAAOD,GAAU,UAAYA,GAAS,KACxC,MAAM,IAAI,MAAM,sCAAsC,KAAK,UAAUA,CAAK,CAAC,IAAI,EAGjF,GACEC,EAAQ,cACPL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AQ,CAAE,YAAa,EAAK,CAAC,EAE9C,MACF,CACA,MAAM,IAAI,MAAM,oCAAoC,KAAK,UAAUF,CAAK,CAAC,EAAE,CAC7E,CAQO,SAASI,EACdC,EACAC,EACAC,EACyC,CACzC,OAAO,OAAO,YACZ,OAAO,QAAQF,CAAO,EAAE,IAAI,CAAC,CAACG,EAAON,CAAM,IAClC,CAACM,EAAOC,EAAc,CAAE,GAAGP,EAAQ,MAAAM,EAAO,eAAAF,EAAgB,UAAAC,CAAU,CAAC,CAAC,CAC9E,CACH,CACF,CCtCA,OACE,aAAAG,EACA,qBAAqBC,EACrB,oBAAoBC,EAEpB,gBAAAC,MACK,6BAQA,SAASC,EACdC,EACAC,EACiC,CAC7BC,EAAUF,EAAO,SAAS,GAC5BG,EAAgBH,EAAM,OAAO,EAE/BI,EAAuBJ,EAAOC,CAAK,CACrC,CAYO,SAASI,EACdL,EACAC,EAAeK,EACiB,CAChC,IAAMC,EAAYC,EAAsBR,EAAOC,CAAK,EAC9CQ,EAAUC,EAAeV,EAAM,SAAW,CAAC,EAAGO,EAAU,MAAOA,EAAU,SAAS,EACxF,MAAO,CACL,GAAGA,EACH,QAAAE,CACF,CACF","names":["SYSTEM_DEPLOY_DEFAULTS","SYSTEM_DEFAULTS","MODULE_DEFAULTS","CODEGEN_DEFAULTS","DEPLOY_DEFAULTS","CONFIG_DEFAULTS","hasOwnKey","mergeIfUndefined","resourceToHex","validateSystem","input","options","resolveSystem","namespaceLabel","SYSTEM_DEFAULTS","namespace","label","name","systemId","SYSTEM_DEPLOY_DEFAULTS","defineSystem","isObject","validateSystems","input","isObject","system","validateSystem","resolveSystems","systems","namespaceLabel","namespace","label","resolveSystem","hasOwnKey","validateStoreNamespace","resolveStoreNamespace","AbiTypeScope","validateNamespace","input","scope","hasOwnKey","validateSystems","validateStoreNamespace","resolveNamespace","AbiTypeScope","namespace","resolveStoreNamespace","systems","resolveSystems"]}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
import{c as y,d as c,e as d,f as p,j as u,k as f,l as v,m as S}from"./chunk-CGF3NYHC.js";import{flatMorph as D}from"@ark/util";import{groupBy as I}from"@latticexyz/common/utils";import{AbiTypeScope as O,isObject as x,mergeIfUndefined as b}from"@latticexyz/store/internal";function l(e,s){if(!x(e))throw new Error(`Expected namespaces, received ${JSON.stringify(e)}`);for(let o of Object.values(e))v(o,s)}function r(e,s){if(!x(e))throw new Error(`Expected namespaces config, received ${JSON.stringify(e)}`);let o=D(e,(n,m)=>[n,S(b(m,{label:n}),s)]),t=Array.from(I(Object.values(o),n=>n.namespace).entries()).filter(([,n])=>n.length>1).map(([n])=>n);if(t.length>0)throw new Error(`Found namespaces defined more than once in config: ${t.join(", ")}`);return o}function R(e,s=O){return l(e,s),r(e,s)}import{isObject as w,mergeIfUndefined as T}from"@latticexyz/store/internal";function N(e){return w(e)?T(e,c):c}import{mergeIfUndefined as U,isObject as F}from"@latticexyz/store/internal";function g(e){return F(e)?U(e,d):d}import{extendedScope as E,get as A,mergeIfUndefined as i,resolveStore as h,hasOwnKey as a,validateStore as L,flattenNamespacedTables as _}from"@latticexyz/store/internal";function C(e){let s=E(e);if(a(e,"namespaces")){if(a(e,"namespace")||a(e,"tables")||a(e,"systems"))throw new Error("Cannot use `namespaces` with `namespace`, `tables`, or `systems` keys.");l(e.namespaces,s)}a(e,"systems")&&u(e.systems),L(e)}function W(e){let s=E(e),o=h(e),t=e.namespaces?r(e.namespaces,s):r({[o.namespace]:e},s),n=_({namespaces:t}),m=(e.modules??p.modules).map(k=>i(k,y));return i({...o,namespaces:t,tables:n,systems:!o.multipleNamespaces&&e.systems?f(e.systems,o.namespace,o.namespace):p.systems,excludeSystems:A(e,"excludeSystems"),codegen:i(o.codegen,N(e.codegen)),deploy:g(e.deploy),modules:m},p)}function te(e){return C(e),W(e)}export{l as a,r as b,R as c,N as d,g as e,C as f,W as g,te as h};
|
2
|
+
//# sourceMappingURL=chunk-DIHBEOC2.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../ts/config/v2/namespaces.ts","../ts/config/v2/codegen.ts","../ts/config/v2/deploy.ts","../ts/config/v2/world.ts"],"sourcesContent":["import { show, flatMorph } from \"@ark/util\";\nimport { NamespacesInput } from \"./input\";\nimport { validateNamespace, resolveNamespace } from \"./namespace\";\nimport { groupBy } from \"@latticexyz/common/utils\";\nimport { AbiTypeScope, Scope, isObject, mergeIfUndefined } from \"@latticexyz/store/internal\";\n\n// Copied from store/ts/config/v2/namespaces.ts but using world namespace validate/resolve methods\n// TODO: figure out how to dedupe these?\n\nexport type validateNamespaces<namespaces, scope extends Scope = AbiTypeScope> = {\n [label in keyof namespaces]: validateNamespace<namespaces[label], scope>;\n};\n\nexport function validateNamespaces<scope extends Scope = AbiTypeScope>(\n namespaces: unknown,\n scope: scope,\n): asserts namespaces is NamespacesInput {\n if (!isObject(namespaces)) {\n throw new Error(`Expected namespaces, received ${JSON.stringify(namespaces)}`);\n }\n for (const namespace of Object.values(namespaces)) {\n validateNamespace(namespace, scope);\n }\n}\n\nexport type resolveNamespaces<namespaces, scope extends Scope = AbiTypeScope> = {\n readonly [label in keyof namespaces]: resolveNamespace<mergeIfUndefined<namespaces[label], { label: label }>, scope>;\n};\n\nexport function resolveNamespaces<input extends NamespacesInput, scope extends Scope = AbiTypeScope>(\n input: input,\n scope: scope,\n): resolveNamespaces<input, scope> {\n if (!isObject(input)) {\n throw new Error(`Expected namespaces config, received ${JSON.stringify(input)}`);\n }\n\n const namespaces = flatMorph(input as NamespacesInput, (label, namespace) => [\n label,\n resolveNamespace(mergeIfUndefined(namespace, { label }), scope),\n ]);\n\n // This should probably be in `validate`, but `namespace` gets set during the resolve step above, so it's easier to validate here.\n const duplicates = Array.from(groupBy(Object.values(namespaces), (namespace) => namespace.namespace).entries())\n .filter(([, entries]) => entries.length > 1)\n .map(([namespace]) => namespace);\n if (duplicates.length > 0) {\n throw new Error(`Found namespaces defined more than once in config: ${duplicates.join(\", \")}`);\n }\n\n return namespaces as never;\n}\n\nexport function defineNamespaces<input, scope extends Scope = AbiTypeScope>(\n input: validateNamespaces<input, scope>,\n scope: scope = AbiTypeScope as never,\n): show<resolveNamespaces<input, scope>> {\n validateNamespaces(input, scope);\n return resolveNamespaces(input, scope) as never;\n}\n","import { isObject, mergeIfUndefined } from \"@latticexyz/store/internal\";\nimport { CODEGEN_DEFAULTS } from \"./defaults\";\n\nexport type resolveCodegen<codegen> = codegen extends {}\n ? mergeIfUndefined<codegen, CODEGEN_DEFAULTS>\n : CODEGEN_DEFAULTS;\n\nexport function resolveCodegen<codegen>(codegen: codegen): resolveCodegen<codegen> {\n return (isObject(codegen) ? mergeIfUndefined(codegen, CODEGEN_DEFAULTS) : CODEGEN_DEFAULTS) as never;\n}\n","import { mergeIfUndefined, isObject } from \"@latticexyz/store/internal\";\nimport { DEPLOY_DEFAULTS } from \"./defaults\";\n\nexport type resolveDeploy<deploy> = deploy extends {} ? mergeIfUndefined<deploy, DEPLOY_DEFAULTS> : DEPLOY_DEFAULTS;\n\nexport function resolveDeploy<deploy>(deploy: deploy): resolveDeploy<deploy> {\n return (isObject(deploy) ? mergeIfUndefined(deploy, DEPLOY_DEFAULTS) : DEPLOY_DEFAULTS) as never;\n}\n","import { ErrorMessage, conform, show, type withJsDoc } from \"@ark/util\";\nimport {\n extendedScope,\n get,\n mergeIfUndefined,\n resolveStore,\n hasOwnKey,\n validateStore,\n flattenNamespacedTables,\n CONFIG_DEFAULTS as STORE_CONFIG_DEFAULTS,\n} from \"@latticexyz/store/internal\";\nimport { SystemsInput, WorldInput } from \"./input\";\nimport { CONFIG_DEFAULTS, MODULE_DEFAULTS } from \"./defaults\";\nimport { resolveSystems, validateSystems } from \"./systems\";\nimport { resolveNamespaces, validateNamespaces } from \"./namespaces\";\nimport { resolveCodegen } from \"./codegen\";\nimport { resolveDeploy } from \"./deploy\";\nimport type { World } from \"./output.js\";\nimport { StoreInput } from \"@latticexyz/store\";\n\nexport type validateWorld<input> = {\n readonly [key in keyof input]: key extends \"namespaces\"\n ? input extends { namespace?: unknown; tables?: unknown; systems?: unknown }\n ? ErrorMessage<\"Cannot use `namespaces` with `namespace`, `tables`, or `systems` keys.\">\n : validateNamespaces<input[key], extendedScope<input>>\n : key extends \"systems\"\n ? validateSystems<input[key]>\n : key extends \"codegen\"\n ? conform<input[key], WorldInput[key] & StoreInput[key]>\n : key extends keyof StoreInput\n ? validateStore<input>[key]\n : key extends keyof WorldInput\n ? conform<input[key], WorldInput[key]>\n : ErrorMessage<`\\`${key & string}\\` is not a valid World config option.`>;\n};\n\nexport function validateWorld(input: unknown): asserts input is WorldInput {\n const scope = extendedScope(input);\n\n if (hasOwnKey(input, \"namespaces\")) {\n if (hasOwnKey(input, \"namespace\") || hasOwnKey(input, \"tables\") || hasOwnKey(input, \"systems\")) {\n throw new Error(\"Cannot use `namespaces` with `namespace`, `tables`, or `systems` keys.\");\n }\n validateNamespaces(input.namespaces, scope);\n }\n if (hasOwnKey(input, \"systems\")) {\n validateSystems(input.systems);\n }\n\n validateStore(input);\n}\n\nexport type resolveNamespaceMode<input> = \"namespaces\" extends keyof input\n ? {\n readonly multipleNamespaces: true;\n readonly namespace: null;\n readonly namespaces: show<resolveNamespaces<input[\"namespaces\"], extendedScope<input>>>;\n }\n : {\n readonly multipleNamespaces: false;\n readonly namespace: string;\n readonly namespaces: show<\n resolveNamespaces<\n {\n // TODO: improve this so we don't have to duplicate store behavior\n readonly [label in \"namespace\" extends keyof input\n ? input[\"namespace\"] extends string\n ? input[\"namespace\"]\n : STORE_CONFIG_DEFAULTS[\"namespace\"]\n : STORE_CONFIG_DEFAULTS[\"namespace\"]]: input;\n },\n extendedScope<input>\n >\n >;\n };\n\ntype resolveModules<input> = { [key in keyof input]: mergeIfUndefined<input[key], MODULE_DEFAULTS> };\n\nexport type resolveWorld<input> = resolveNamespaceMode<input> &\n Omit<resolveStore<input>, \"multipleNamespaces\" | \"namespace\" | \"namespaces\" | \"tables\"> & {\n readonly tables: flattenNamespacedTables<resolveNamespaceMode<input>>;\n // TODO: flatten systems from namespaces\n readonly systems: \"systems\" extends keyof input\n ? input[\"systems\"] extends SystemsInput\n ? resolveNamespaceMode<input>[\"namespace\"] extends string\n ? show<resolveSystems<input[\"systems\"], resolveNamespaceMode<input>[\"namespace\"]>>\n : {}\n : {}\n : {};\n readonly excludeSystems: \"excludeSystems\" extends keyof input\n ? input[\"excludeSystems\"]\n : CONFIG_DEFAULTS[\"excludeSystems\"];\n readonly modules: \"modules\" extends keyof input ? resolveModules<input[\"modules\"]> : CONFIG_DEFAULTS[\"modules\"];\n readonly codegen: show<resolveCodegen<\"codegen\" extends keyof input ? input[\"codegen\"] : {}>>;\n readonly deploy: show<resolveDeploy<\"deploy\" extends keyof input ? input[\"deploy\"] : {}>>;\n };\n\nexport function resolveWorld<const input extends WorldInput>(input: input): resolveWorld<input> {\n const scope = extendedScope(input);\n const store = resolveStore(input);\n\n const namespaces = input.namespaces\n ? resolveNamespaces(input.namespaces, scope)\n : resolveNamespaces({ [store.namespace!]: input }, scope);\n\n const tables = flattenNamespacedTables({ namespaces });\n const modules = (input.modules ?? CONFIG_DEFAULTS.modules).map((mod) => mergeIfUndefined(mod, MODULE_DEFAULTS));\n\n return mergeIfUndefined(\n {\n ...store,\n namespaces,\n tables,\n // TODO: flatten systems from namespaces\n systems:\n !store.multipleNamespaces && input.systems\n ? resolveSystems(input.systems, store.namespace, store.namespace)\n : CONFIG_DEFAULTS.systems,\n excludeSystems: get(input, \"excludeSystems\"),\n codegen: mergeIfUndefined(store.codegen, resolveCodegen(input.codegen)),\n deploy: resolveDeploy(input.deploy),\n modules,\n },\n CONFIG_DEFAULTS,\n ) as never;\n}\n\nexport function defineWorld<const input>(input: validateWorld<input>): withJsDoc<resolveWorld<input>, World> {\n validateWorld(input);\n return resolveWorld(input) as never;\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;AAAA,SAAe,iBAAiB;AAGhC,SAAS,eAAe;AACxB,SAAS,cAAqB,UAAU,wBAAwB;AASzD,SAAS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AAc,KAAK;AACnB,SAAO,aAAa,KAAK;AAC3B;","names":["isObject","mergeIfUndefined","isObject","mergeIfUndefined","mergeIfUndefined","isObject","isObject","mergeIfUndefined","mergeIfUndefined","mergeIfUndefined"]}
|
1
|
+
{"version":3,"sources":["../ts/config/v2/namespaces.ts","../ts/config/v2/codegen.ts","../ts/config/v2/deploy.ts","../ts/config/v2/world.ts"],"sourcesContent":["import { show, flatMorph } from \"@ark/util\";\nimport { NamespacesInput } from \"./input\";\nimport { validateNamespace, resolveNamespace } from \"./namespace\";\nimport { groupBy } from \"@latticexyz/common/utils\";\nimport { AbiTypeScope, Scope, isObject, mergeIfUndefined } from \"@latticexyz/store/internal\";\n\n// Copied from store/ts/config/v2/namespaces.ts but using world namespace validate/resolve methods\n// TODO: figure out how to dedupe these?\n\nexport type validateNamespaces<namespaces, scope extends Scope = AbiTypeScope> = {\n [label in keyof namespaces]: validateNamespace<namespaces[label], scope>;\n};\n\nexport function validateNamespaces<scope extends Scope = AbiTypeScope>(\n namespaces: unknown,\n scope: scope,\n): asserts namespaces is NamespacesInput {\n if (!isObject(namespaces)) {\n throw new Error(`Expected namespaces, received ${JSON.stringify(namespaces)}`);\n }\n for (const namespace of Object.values(namespaces)) {\n validateNamespace(namespace, scope);\n }\n}\n\nexport type resolveNamespaces<namespaces, scope extends Scope = AbiTypeScope> = {\n readonly [label in keyof namespaces]: resolveNamespace<mergeIfUndefined<namespaces[label], { label: label }>, scope>;\n};\n\nexport function resolveNamespaces<input extends NamespacesInput, scope extends Scope = AbiTypeScope>(\n input: input,\n scope: scope,\n): resolveNamespaces<input, scope> {\n if (!isObject(input)) {\n throw new Error(`Expected namespaces config, received ${JSON.stringify(input)}`);\n }\n\n const namespaces = flatMorph(input as NamespacesInput, (label, namespace) => [\n label,\n resolveNamespace(mergeIfUndefined(namespace, { label }), scope),\n ]);\n\n // This should probably be in `validate`, but `namespace` gets set during the resolve step above, so it's easier to validate here.\n const duplicates = Array.from(groupBy(Object.values(namespaces), (namespace) => namespace.namespace).entries())\n .filter(([, entries]) => entries.length > 1)\n .map(([namespace]) => namespace);\n if (duplicates.length > 0) {\n throw new Error(`Found namespaces defined more than once in config: ${duplicates.join(\", \")}`);\n }\n\n return namespaces as never;\n}\n\nexport function defineNamespaces<input, scope extends Scope = AbiTypeScope>(\n input: validateNamespaces<input, scope>,\n scope: scope = AbiTypeScope as never,\n): show<resolveNamespaces<input, scope>> {\n validateNamespaces(input, scope);\n return resolveNamespaces(input, scope) as never;\n}\n","import { isObject, mergeIfUndefined } from \"@latticexyz/store/internal\";\nimport { CODEGEN_DEFAULTS } from \"./defaults\";\n\nexport type resolveCodegen<codegen> = codegen extends {}\n ? mergeIfUndefined<codegen, CODEGEN_DEFAULTS>\n : CODEGEN_DEFAULTS;\n\nexport function resolveCodegen<codegen>(codegen: codegen): resolveCodegen<codegen> {\n return (isObject(codegen) ? mergeIfUndefined(codegen, CODEGEN_DEFAULTS) : CODEGEN_DEFAULTS) as never;\n}\n","import { mergeIfUndefined, isObject } from \"@latticexyz/store/internal\";\nimport { DEPLOY_DEFAULTS } from \"./defaults\";\n\nexport type resolveDeploy<deploy> = deploy extends {} ? mergeIfUndefined<deploy, DEPLOY_DEFAULTS> : DEPLOY_DEFAULTS;\n\nexport function resolveDeploy<deploy>(deploy: deploy): resolveDeploy<deploy> {\n return (isObject(deploy) ? mergeIfUndefined(deploy, DEPLOY_DEFAULTS) : DEPLOY_DEFAULTS) as never;\n}\n","import { ErrorMessage, conform, show, type withJsDoc } from \"@ark/util\";\nimport {\n extendedScope,\n get,\n mergeIfUndefined,\n resolveStore,\n hasOwnKey,\n validateStore,\n flattenNamespacedTables,\n CONFIG_DEFAULTS as STORE_CONFIG_DEFAULTS,\n} from \"@latticexyz/store/internal\";\nimport { SystemsInput, WorldInput } from \"./input\";\nimport { CONFIG_DEFAULTS, MODULE_DEFAULTS } from \"./defaults\";\nimport { resolveSystems, validateSystems } from \"./systems\";\nimport { resolveNamespaces, validateNamespaces } from \"./namespaces\";\nimport { resolveCodegen } from \"./codegen\";\nimport { resolveDeploy } from \"./deploy\";\nimport type { World } from \"./output.js\";\nimport { StoreInput } from \"@latticexyz/store\";\n\nexport type validateWorld<input> = {\n readonly [key in keyof input]: key extends \"namespaces\"\n ? input extends { namespace?: unknown; tables?: unknown; systems?: unknown }\n ? ErrorMessage<\"Cannot use `namespaces` with `namespace`, `tables`, or `systems` keys.\">\n : validateNamespaces<input[key], extendedScope<input>>\n : key extends \"systems\"\n ? validateSystems<input[key]>\n : key extends \"codegen\"\n ? conform<input[key], WorldInput[key] & StoreInput[key]>\n : key extends keyof StoreInput\n ? validateStore<input>[key]\n : key extends keyof WorldInput\n ? conform<input[key], WorldInput[key]>\n : ErrorMessage<`\\`${key & string}\\` is not a valid World config option.`>;\n};\n\nexport function validateWorld(input: unknown): asserts input is WorldInput {\n const scope = extendedScope(input);\n\n if (hasOwnKey(input, \"namespaces\")) {\n if (hasOwnKey(input, \"namespace\") || hasOwnKey(input, \"tables\") || hasOwnKey(input, \"systems\")) {\n throw new Error(\"Cannot use `namespaces` with `namespace`, `tables`, or `systems` keys.\");\n }\n validateNamespaces(input.namespaces, scope);\n }\n if (hasOwnKey(input, \"systems\")) {\n validateSystems(input.systems);\n }\n\n validateStore(input);\n}\n\nexport type resolveNamespaceMode<input> = \"namespaces\" extends keyof input\n ? {\n readonly multipleNamespaces: true;\n readonly namespace: null;\n readonly namespaces: show<resolveNamespaces<input[\"namespaces\"], extendedScope<input>>>;\n }\n : {\n readonly multipleNamespaces: false;\n readonly namespace: string;\n readonly namespaces: show<\n resolveNamespaces<\n {\n // TODO: improve this so we don't have to duplicate store behavior\n readonly [label in \"namespace\" extends keyof input\n ? input[\"namespace\"] extends string\n ? input[\"namespace\"]\n : STORE_CONFIG_DEFAULTS[\"namespace\"]\n : STORE_CONFIG_DEFAULTS[\"namespace\"]]: input;\n },\n extendedScope<input>\n >\n >;\n };\n\ntype resolveModules<input> = { [key in keyof input]: mergeIfUndefined<input[key], MODULE_DEFAULTS> };\n\nexport type resolveWorld<input> = resolveNamespaceMode<input> &\n Omit<resolveStore<input>, \"multipleNamespaces\" | \"namespace\" | \"namespaces\" | \"tables\"> & {\n readonly tables: flattenNamespacedTables<resolveNamespaceMode<input>>;\n // TODO: flatten systems from namespaces\n readonly systems: \"systems\" extends keyof input\n ? input[\"systems\"] extends SystemsInput\n ? resolveNamespaceMode<input>[\"namespace\"] extends string\n ? show<resolveSystems<input[\"systems\"], resolveNamespaceMode<input>[\"namespace\"]>>\n : {}\n : {}\n : {};\n readonly excludeSystems: \"excludeSystems\" extends keyof input\n ? input[\"excludeSystems\"]\n : CONFIG_DEFAULTS[\"excludeSystems\"];\n readonly modules: \"modules\" extends keyof input ? resolveModules<input[\"modules\"]> : CONFIG_DEFAULTS[\"modules\"];\n readonly codegen: show<resolveCodegen<\"codegen\" extends keyof input ? input[\"codegen\"] : {}>>;\n readonly deploy: show<resolveDeploy<\"deploy\" extends keyof input ? input[\"deploy\"] : {}>>;\n };\n\nexport function resolveWorld<const input extends WorldInput>(input: input): resolveWorld<input> {\n const scope = extendedScope(input);\n const store = resolveStore(input);\n\n const namespaces = input.namespaces\n ? resolveNamespaces(input.namespaces, scope)\n : resolveNamespaces({ [store.namespace!]: input }, scope);\n\n const tables = flattenNamespacedTables({ namespaces });\n const modules = (input.modules ?? CONFIG_DEFAULTS.modules).map((mod) => mergeIfUndefined(mod, MODULE_DEFAULTS));\n\n return mergeIfUndefined(\n {\n ...store,\n namespaces,\n tables,\n // TODO: flatten systems from namespaces\n systems:\n !store.multipleNamespaces && input.systems\n ? resolveSystems(input.systems, store.namespace, store.namespace)\n : CONFIG_DEFAULTS.systems,\n excludeSystems: get(input, \"excludeSystems\"),\n codegen: mergeIfUndefined(store.codegen, resolveCodegen(input.codegen)),\n deploy: resolveDeploy(input.deploy),\n modules,\n },\n CONFIG_DEFAULTS,\n ) as never;\n}\n\nexport function defineWorld<const input>(input: validateWorld<input>): withJsDoc<resolveWorld<input>, World> {\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ACF,CAEO,SAASQ,GAAyBvB,EAAoE,CAC3G,OAAAD,EAAcC,CAAK,EACZO,EAAaP,CAAK,CAC3B","names":["flatMorph","groupBy","AbiTypeScope","isObject","mergeIfUndefined","validateNamespaces","namespaces","scope","namespace","validateNamespace","resolveNamespaces","input","flatMorph","label","resolveNamespace","duplicates","entries","defineNamespaces","isObject","mergeIfUndefined","resolveCodegen","codegen","isObject","mergeIfUndefined","CODEGEN_DEFAULTS","mergeIfUndefined","isObject","resolveDeploy","deploy","isObject","mergeIfUndefined","DEPLOY_DEFAULTS","extendedScope","get","mergeIfUndefined","resolveStore","hasOwnKey","validateStore","flattenNamespacedTables","validateWorld","input","scope","extendedScope","hasOwnKey","validateNamespaces","validateSystems","validateStore","resolveWorld","store","resolveStore","namespaces","resolveNamespaces","tables","flattenNamespacedTables","modules","CONFIG_DEFAULTS","mod","mergeIfUndefined","MODULE_DEFAULTS","resolveSystems","get","resolveCodegen","resolveDeploy","defineWorld"]}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
var g=Object.create;var f=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var m=(b,a)=>()=>(a||b((a={exports:{}}).exports,a),a.exports);var l=(b,a,c,e)=>{if(a&&typeof a=="object"||typeof a=="function")for(let d of i(a))!k.call(b,d)&&d!==c&&f(b,d,{get:()=>a[d],enumerable:!(e=h(a,d))||e.enumerable});return b};var n=(b,a,c)=>(c=b!=null?g(j(b)):{},l(a||!b||!b.__esModule?f(c,"default",{value:b,enumerable:!0}):c,b));export{m as a,n as b};
|
2
|
+
//# sourceMappingURL=chunk-FW4363Y4.js.map
|
package/dist/index.js
CHANGED
@@ -1,21 +1,2 @@
|
|
1
|
-
import {
|
2
|
-
defineWorld
|
3
|
-
} from "./chunk-TL2M3LZH.js";
|
4
|
-
import {
|
5
|
-
init_esm_shims
|
6
|
-
} from "./chunk-AAKXFFCU.js";
|
7
|
-
import "./chunk-AAWFTQHP.js";
|
8
|
-
|
9
|
-
// ts/exports/index.ts
|
10
|
-
init_esm_shims();
|
11
|
-
|
12
|
-
// ts/worldEvents.ts
|
13
|
-
init_esm_shims();
|
14
|
-
var worldDeployedEvent = "event WorldDeployed(address indexed newContract, uint256 salt)";
|
15
|
-
var helloWorldEvent = "event HelloWorld(bytes32 indexed worldVersion)";
|
16
|
-
export {
|
17
|
-
defineWorld,
|
18
|
-
helloWorldEvent,
|
19
|
-
worldDeployedEvent
|
20
|
-
};
|
1
|
+
import{h as e}from"./chunk-DIHBEOC2.js";import"./chunk-CGF3NYHC.js";import"./chunk-FW4363Y4.js";var o="event WorldDeployed(address indexed newContract, uint256 salt)",t="event HelloWorld(bytes32 indexed worldVersion)";export{e as defineWorld,t as helloWorldEvent,o as worldDeployedEvent};
|
21
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../ts/
|
1
|
+
{"version":3,"sources":["../ts/worldEvents.ts"],"sourcesContent":["// from WorldFactory\nexport const worldDeployedEvent = \"event WorldDeployed(address indexed newContract, uint256 salt)\";\n\n// from World\nexport const helloWorldEvent = \"event HelloWorld(bytes32 indexed worldVersion)\";\n"],"mappings":"gGACO,IAAMA,EAAqB,iEAGrBC,EAAkB","names":["worldDeployedEvent","helloWorldEvent"]}
|
package/dist/internal.js
CHANGED
@@ -1,320 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
mud_config_default
|
3
|
-
} from "./chunk-S5LARYWY.js";
|
4
|
-
import {
|
5
|
-
defineNamespaces,
|
6
|
-
defineWorld,
|
7
|
-
resolveCodegen,
|
8
|
-
resolveDeploy,
|
9
|
-
resolveNamespaces,
|
10
|
-
resolveWorld,
|
11
|
-
validateNamespaces,
|
12
|
-
validateWorld
|
13
|
-
} from "./chunk-TL2M3LZH.js";
|
14
|
-
import {
|
15
|
-
CODEGEN_DEFAULTS,
|
16
|
-
CONFIG_DEFAULTS,
|
17
|
-
DEPLOY_DEFAULTS,
|
18
|
-
MODULE_DEFAULTS,
|
19
|
-
SYSTEM_DEFAULTS,
|
20
|
-
SYSTEM_DEPLOY_DEFAULTS,
|
21
|
-
defineSystem,
|
22
|
-
init_esm_shims,
|
23
|
-
resolveNamespace,
|
24
|
-
resolveSystem,
|
25
|
-
resolveSystems,
|
26
|
-
validateNamespace,
|
27
|
-
validateSystem,
|
28
|
-
validateSystems
|
29
|
-
} from "./chunk-AAKXFFCU.js";
|
30
|
-
import "./chunk-AAWFTQHP.js";
|
1
|
+
import{b as y}from"./chunk-AJUHOWGE.js";import{a as Q,b as X,c as Y,d as Z,e as tt,f as et,g as nt,h as ot}from"./chunk-DIHBEOC2.js";import{a as V,b as $,c as z,d as j,e as L,f as O,g as K,h as M,i as B,j as J,k as U,l as q,m as G}from"./chunk-CGF3NYHC.js";import"./chunk-FW4363Y4.js";import{encodeFunctionData as A}from"viem";import{hexToResource as C,resourceToLabel as x}from"@latticexyz/common";function r(t,o){let e=C(t),n=e.namespace!==""?`${e.namespace}__`:null;return n!=null&&o.startsWith(n)?(console.warn(`Detected world function name "${o}" used in call to system "${x(e)}".
|
31
2
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
// ts/encodeSystemCall.ts
|
36
|
-
init_esm_shims();
|
37
|
-
import { encodeFunctionData } from "viem";
|
38
|
-
|
39
|
-
// ts/normalizeSystemFunctionName.ts
|
40
|
-
init_esm_shims();
|
41
|
-
import { hexToResource, resourceToLabel } from "@latticexyz/common";
|
42
|
-
function internal_normalizeSystemFunctionName(systemId, functionName) {
|
43
|
-
const resource = hexToResource(systemId);
|
44
|
-
const worldFunctionPrefix = resource.namespace !== "" ? `${resource.namespace}__` : null;
|
45
|
-
if (worldFunctionPrefix != null && functionName.startsWith(worldFunctionPrefix)) {
|
46
|
-
console.warn(
|
47
|
-
// eslint-disable-next-line max-len
|
48
|
-
`Detected world function name "${functionName}" used in call to system "${resourceToLabel(resource)}".
|
49
|
-
|
50
|
-
It's recommended to use a system ABI and system function name with these methods instead.`
|
51
|
-
);
|
52
|
-
return functionName.slice(worldFunctionPrefix.length);
|
53
|
-
}
|
54
|
-
return functionName;
|
55
|
-
}
|
56
|
-
|
57
|
-
// ts/encodeSystemCall.ts
|
58
|
-
function encodeSystemCall({
|
59
|
-
abi,
|
60
|
-
systemId,
|
61
|
-
functionName,
|
62
|
-
args
|
63
|
-
}) {
|
64
|
-
return [
|
65
|
-
systemId,
|
66
|
-
encodeFunctionData({
|
67
|
-
abi,
|
68
|
-
functionName: internal_normalizeSystemFunctionName(systemId, functionName),
|
69
|
-
args
|
70
|
-
})
|
71
|
-
];
|
72
|
-
}
|
73
|
-
|
74
|
-
// ts/encodeSystemCallFrom.ts
|
75
|
-
init_esm_shims();
|
76
|
-
import { encodeFunctionData as encodeFunctionData2 } from "viem";
|
77
|
-
function encodeSystemCallFrom({
|
78
|
-
abi,
|
79
|
-
from,
|
80
|
-
systemId,
|
81
|
-
functionName,
|
82
|
-
args
|
83
|
-
}) {
|
84
|
-
return [
|
85
|
-
from,
|
86
|
-
systemId,
|
87
|
-
encodeFunctionData2({
|
88
|
-
abi,
|
89
|
-
functionName: internal_normalizeSystemFunctionName(systemId, functionName),
|
90
|
-
args
|
91
|
-
})
|
92
|
-
];
|
93
|
-
}
|
94
|
-
|
95
|
-
// ts/encodeSystemCalls.ts
|
96
|
-
init_esm_shims();
|
97
|
-
import { encodeFunctionData as encodeFunctionData3 } from "viem";
|
98
|
-
function encodeSystemCalls(abi, systemCalls) {
|
99
|
-
return [
|
100
|
-
systemCalls.map(({ systemId, functionName, args }) => ({
|
101
|
-
systemId,
|
102
|
-
callData: encodeFunctionData3({
|
103
|
-
abi,
|
104
|
-
functionName: internal_normalizeSystemFunctionName(systemId, functionName),
|
105
|
-
args
|
106
|
-
})
|
107
|
-
}))
|
108
|
-
];
|
109
|
-
}
|
110
|
-
|
111
|
-
// ts/encodeSystemCallsFrom.ts
|
112
|
-
init_esm_shims();
|
113
|
-
import { encodeFunctionData as encodeFunctionData4 } from "viem";
|
114
|
-
function encodeSystemCallsFrom(abi, from, systemCalls) {
|
115
|
-
return [
|
116
|
-
systemCalls.map(({ systemId, functionName, args }) => ({
|
117
|
-
from,
|
118
|
-
systemId,
|
119
|
-
callData: encodeFunctionData4({
|
120
|
-
abi,
|
121
|
-
functionName: internal_normalizeSystemFunctionName(systemId, functionName),
|
122
|
-
args
|
123
|
-
})
|
124
|
-
}))
|
125
|
-
];
|
126
|
-
}
|
127
|
-
|
128
|
-
// ts/actions/callFrom.ts
|
129
|
-
init_esm_shims();
|
130
|
-
import {
|
131
|
-
slice,
|
132
|
-
concat
|
133
|
-
} from "viem";
|
134
|
-
import { getAction, encodeFunctionData as encodeFunctionData5 } from "viem/utils";
|
135
|
-
import { readContract, writeContract as viem_writeContract } from "viem/actions";
|
136
|
-
import { readHex } from "@latticexyz/common";
|
137
|
-
import {
|
138
|
-
getKeySchema,
|
139
|
-
getValueSchema,
|
140
|
-
getSchemaTypes,
|
141
|
-
decodeValueArgs,
|
142
|
-
encodeKey
|
143
|
-
} from "@latticexyz/protocol-parser/internal";
|
144
|
-
function callFrom(params) {
|
145
|
-
return (client) => ({
|
146
|
-
async writeContract(writeArgs) {
|
147
|
-
const _writeContract = getAction(client, viem_writeContract, "writeContract");
|
148
|
-
if (writeArgs.address !== params.worldAddress || writeArgs.functionName === "call" || writeArgs.functionName === "callFrom" || writeArgs.functionName === "batchCallFrom" || writeArgs.functionName === "callWithSignature") {
|
149
|
-
return _writeContract(writeArgs);
|
150
|
-
}
|
151
|
-
if (writeArgs.functionName === "batchCall") {
|
152
|
-
const batchCallArgs = writeArgs;
|
153
|
-
const [systemCalls] = batchCallArgs.args;
|
154
|
-
if (!systemCalls.length) {
|
155
|
-
throw new Error("`batchCall` should have at least one system call.");
|
156
|
-
}
|
157
|
-
return _writeContract({
|
158
|
-
...batchCallArgs,
|
159
|
-
functionName: "batchCallFrom",
|
160
|
-
args: [systemCalls.map((systemCall) => ({ from: params.delegatorAddress, ...systemCall }))]
|
161
|
-
});
|
162
|
-
}
|
163
|
-
const worldCalldata = encodeFunctionData5({
|
164
|
-
abi: writeArgs.abi,
|
165
|
-
functionName: writeArgs.functionName,
|
166
|
-
args: writeArgs.args
|
167
|
-
});
|
168
|
-
const worldFunctionSelector = slice(worldCalldata, 0, 4);
|
169
|
-
const { systemId, systemFunctionSelector } = await worldFunctionToSystemFunction({
|
170
|
-
...params,
|
171
|
-
publicClient: params.publicClient ?? client,
|
172
|
-
worldFunctionSelector
|
173
|
-
});
|
174
|
-
const systemCalldata = concat([systemFunctionSelector, readHex(worldCalldata, 4)]);
|
175
|
-
return _writeContract({
|
176
|
-
...writeArgs,
|
177
|
-
functionName: "callFrom",
|
178
|
-
args: [params.delegatorAddress, systemId, systemCalldata]
|
179
|
-
});
|
180
|
-
}
|
181
|
-
});
|
182
|
-
}
|
183
|
-
var systemFunctionCache = /* @__PURE__ */ new Map();
|
184
|
-
async function worldFunctionToSystemFunction(params) {
|
185
|
-
const cacheKey = concat([params.worldAddress, params.worldFunctionSelector]);
|
186
|
-
const cached = systemFunctionCache.get(cacheKey);
|
187
|
-
if (cached) return cached;
|
188
|
-
const systemFunction = params.worldFunctionToSystemFunction ? await params.worldFunctionToSystemFunction(params.worldFunctionSelector) : await retrieveSystemFunctionFromContract(params.publicClient, params.worldAddress, params.worldFunctionSelector);
|
189
|
-
systemFunctionCache.set(cacheKey, systemFunction);
|
190
|
-
return systemFunction;
|
191
|
-
}
|
192
|
-
async function retrieveSystemFunctionFromContract(publicClient, worldAddress, worldFunctionSelector) {
|
193
|
-
const table = mud_config_default.tables.world__FunctionSelectors;
|
194
|
-
const keySchema = getSchemaTypes(getKeySchema(table));
|
195
|
-
const valueSchema = getSchemaTypes(getValueSchema(table));
|
196
|
-
const _readContract = getAction(publicClient, readContract, "readContract");
|
197
|
-
const [staticData, encodedLengths, dynamicData] = await _readContract({
|
198
|
-
address: worldAddress,
|
199
|
-
abi: [
|
200
|
-
{
|
201
|
-
type: "function",
|
202
|
-
name: "getRecord",
|
203
|
-
inputs: [
|
204
|
-
{
|
205
|
-
name: "tableId",
|
206
|
-
type: "bytes32",
|
207
|
-
internalType: "ResourceId"
|
208
|
-
},
|
209
|
-
{
|
210
|
-
name: "keyTuple",
|
211
|
-
type: "bytes32[]",
|
212
|
-
internalType: "bytes32[]"
|
213
|
-
}
|
214
|
-
],
|
215
|
-
outputs: [
|
216
|
-
{
|
217
|
-
name: "staticData",
|
218
|
-
type: "bytes",
|
219
|
-
internalType: "bytes"
|
220
|
-
},
|
221
|
-
{
|
222
|
-
name: "encodedLengths",
|
223
|
-
type: "bytes32",
|
224
|
-
internalType: "EncodedLengths"
|
225
|
-
},
|
226
|
-
{
|
227
|
-
name: "dynamicData",
|
228
|
-
type: "bytes",
|
229
|
-
internalType: "bytes"
|
230
|
-
}
|
231
|
-
],
|
232
|
-
stateMutability: "view"
|
233
|
-
}
|
234
|
-
],
|
235
|
-
functionName: "getRecord",
|
236
|
-
args: [table.tableId, encodeKey(keySchema, { worldFunctionSelector })]
|
237
|
-
});
|
238
|
-
const decoded = decodeValueArgs(valueSchema, { staticData, encodedLengths, dynamicData });
|
239
|
-
const systemFunction = {
|
240
|
-
systemId: decoded.systemId,
|
241
|
-
systemFunctionSelector: decoded.systemFunctionSelector
|
242
|
-
};
|
243
|
-
return systemFunction;
|
244
|
-
}
|
245
|
-
|
246
|
-
// ts/config/v2/dynamicResolution.ts
|
247
|
-
init_esm_shims();
|
248
|
-
function resolveTableId(tableName) {
|
249
|
-
return {
|
250
|
-
type: "tableId",
|
251
|
-
input: tableName
|
252
|
-
};
|
253
|
-
}
|
254
|
-
function isDynamicResolution(value) {
|
255
|
-
return typeof value === "object" && value !== null && "type" in value && "input" in value;
|
256
|
-
}
|
257
|
-
function isValueWithType(value) {
|
258
|
-
return typeof value === "object" && value !== null && "type" in value && "value" in value;
|
259
|
-
}
|
260
|
-
function resolveWithContext(input, context) {
|
261
|
-
if (isValueWithType(input)) return input;
|
262
|
-
if (isDynamicResolution(input)) {
|
263
|
-
if (input.type === "tableId") {
|
264
|
-
const tableEntries = Object.entries(context.config.tables).filter(
|
265
|
-
([tableName, table]) => tableName === input.input || table.name === input.input
|
266
|
-
);
|
267
|
-
if (tableEntries.length > 1) {
|
268
|
-
throw new Error(
|
269
|
-
`Found more than one table with name "${input.input}". Try using one of the following table names instead: ${tableEntries.map(([tableName]) => tableName).join(", ")}`
|
270
|
-
);
|
271
|
-
}
|
272
|
-
if (tableEntries.length === 1) {
|
273
|
-
const [entry] = tableEntries;
|
274
|
-
const [, table] = entry;
|
275
|
-
return { type: "bytes32", value: table.tableId };
|
276
|
-
}
|
277
|
-
}
|
278
|
-
}
|
279
|
-
throw new Error(`Could not resolve dynamic resolution:
|
280
|
-
${JSON.stringify(input, null, 2)}`);
|
281
|
-
}
|
282
|
-
|
283
|
-
// ts/config/v2/input.ts
|
284
|
-
init_esm_shims();
|
285
|
-
|
286
|
-
// ts/config/v2/output.ts
|
287
|
-
init_esm_shims();
|
288
|
-
export {
|
289
|
-
CODEGEN_DEFAULTS,
|
290
|
-
CONFIG_DEFAULTS,
|
291
|
-
DEPLOY_DEFAULTS,
|
292
|
-
MODULE_DEFAULTS,
|
293
|
-
SYSTEM_DEFAULTS,
|
294
|
-
SYSTEM_DEPLOY_DEFAULTS,
|
295
|
-
callFrom,
|
296
|
-
defineNamespaces,
|
297
|
-
defineSystem,
|
298
|
-
defineWorld,
|
299
|
-
encodeSystemCall,
|
300
|
-
encodeSystemCallFrom,
|
301
|
-
encodeSystemCalls,
|
302
|
-
encodeSystemCallsFrom,
|
303
|
-
isDynamicResolution,
|
304
|
-
isValueWithType,
|
305
|
-
resolveCodegen,
|
306
|
-
resolveDeploy,
|
307
|
-
resolveNamespace,
|
308
|
-
resolveNamespaces,
|
309
|
-
resolveSystem,
|
310
|
-
resolveSystems,
|
311
|
-
resolveTableId,
|
312
|
-
resolveWithContext,
|
313
|
-
resolveWorld,
|
314
|
-
validateNamespace,
|
315
|
-
validateNamespaces,
|
316
|
-
validateSystem,
|
317
|
-
validateSystems,
|
318
|
-
validateWorld
|
319
|
-
};
|
3
|
+
It's recommended to use a system ABI and system function name with these methods instead.`),o.slice(n.length)):o}function ut({abi:t,systemId:o,functionName:e,args:n}){return[o,A({abi:t,functionName:r(o,e),args:n})]}import{encodeFunctionData as S}from"viem";function Ct({abi:t,from:o,systemId:e,functionName:n,args:a}){return[o,e,S({abi:t,functionName:r(e,n),args:a})]}import{encodeFunctionData as w}from"viem";function ht(t,o){return[o.map(({systemId:e,functionName:n,args:a})=>({systemId:e,callData:w({abi:t,functionName:r(e,n),args:a})}))]}import{encodeFunctionData as N}from"viem";function vt(t,o,e){return[e.map(({systemId:n,functionName:a,args:i})=>({from:o,systemId:n,callData:N({abi:t,functionName:r(n,a),args:i})}))]}import{slice as h,concat as f}from"viem";import{getAction as F,encodeFunctionData as P}from"viem/utils";import{readContract as T,writeContract as g}from"viem/actions";import{readHex as D}from"@latticexyz/common";import{getKeySchema as E,getValueSchema as H,getSchemaTypes as p,decodeValueArgs as v,encodeKey as W}from"@latticexyz/protocol-parser/internal";function zt(t){return o=>({async writeContract(e){let n=F(o,g,"writeContract");if(e.address!==t.worldAddress||e.functionName==="call"||e.functionName==="callFrom"||e.functionName==="batchCallFrom"||e.functionName==="callWithSignature")return n(e);if(e.functionName==="batchCall"){let m=e,[c]=m.args;if(!c.length)throw new Error("`batchCall` should have at least one system call.");return n({...m,functionName:"batchCallFrom",args:[c.map(d=>({from:t.delegatorAddress,...d}))]})}let a=P({abi:e.abi,functionName:e.functionName,args:e.args}),i=h(a,0,4),{systemId:s,systemFunctionSelector:l}=await _({...t,publicClient:t.publicClient??o,worldFunctionSelector:i}),u=f([l,D(a,4)]);return n({...e,functionName:"callFrom",args:[t.delegatorAddress,s,u]})}})}var b=new Map;async function _(t){let o=f([t.worldAddress,t.worldFunctionSelector]),e=b.get(o);if(e)return e;let n=t.worldFunctionToSystemFunction?await t.worldFunctionToSystemFunction(t.worldFunctionSelector):await I(t.publicClient,t.worldAddress,t.worldFunctionSelector);return b.set(o,n),n}async function I(t,o,e){let n=y.tables.world__FunctionSelectors,a=p(E(n)),i=p(H(n)),s=F(t,T,"readContract"),[l,u,m]=await s({address:o,abi:[{type:"function",name:"getRecord",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"}],outputs:[{name:"staticData",type:"bytes",internalType:"bytes"},{name:"encodedLengths",type:"bytes32",internalType:"EncodedLengths"},{name:"dynamicData",type:"bytes",internalType:"bytes"}],stateMutability:"view"}],functionName:"getRecord",args:[n.tableId,W(a,{worldFunctionSelector:e})]}),c=v(i,{staticData:l,encodedLengths:u,dynamicData:m});return{systemId:c.systemId,systemFunctionSelector:c.systemFunctionSelector}}function Lt(t){return{type:"tableId",input:t}}function k(t){return typeof t=="object"&&t!==null&&"type"in t&&"input"in t}function R(t){return typeof t=="object"&&t!==null&&"type"in t&&"value"in t}function Ot(t,o){if(R(t))return t;if(k(t)&&t.type==="tableId"){let e=Object.entries(o.config.tables).filter(([n,a])=>n===t.input||a.name===t.input);if(e.length>1)throw new Error(`Found more than one table with name "${t.input}". Try using one of the following table names instead: ${e.map(([n])=>n).join(", ")}`);if(e.length===1){let[n]=e,[,a]=n;return{type:"bytes32",value:a.tableId}}}throw new Error(`Could not resolve dynamic resolution:
|
4
|
+
${JSON.stringify(t,null,2)}`)}export{j as CODEGEN_DEFAULTS,O as CONFIG_DEFAULTS,L as DEPLOY_DEFAULTS,z as MODULE_DEFAULTS,$ as SYSTEM_DEFAULTS,V as SYSTEM_DEPLOY_DEFAULTS,zt as callFrom,Y as defineNamespaces,B as defineSystem,ot as defineWorld,ut as encodeSystemCall,Ct as encodeSystemCallFrom,ht as encodeSystemCalls,vt as encodeSystemCallsFrom,k as isDynamicResolution,R as isValueWithType,Z as resolveCodegen,tt as resolveDeploy,G as resolveNamespace,X as resolveNamespaces,M as resolveSystem,U as resolveSystems,Lt as resolveTableId,Ot as resolveWithContext,nt as resolveWorld,q as validateNamespace,Q as validateNamespaces,K as validateSystem,J as validateSystems,et as validateWorld};
|
320
5
|
//# sourceMappingURL=internal.js.map
|
package/dist/internal.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../ts/exports/internal.ts","../ts/encodeSystemCall.ts","../ts/normalizeSystemFunctionName.ts","../ts/encodeSystemCallFrom.ts","../ts/encodeSystemCalls.ts","../ts/encodeSystemCallsFrom.ts","../ts/actions/callFrom.ts","../ts/config/v2/dynamicResolution.ts","../ts/config/v2/input.ts","../ts/config/v2/output.ts"],"sourcesContent":["export * from \"../encodeSystemCall\";\nexport * from \"../encodeSystemCallFrom\";\nexport * from \"../encodeSystemCalls\";\nexport * from \"../encodeSystemCallsFrom\";\n\nexport * from \"../actions/callFrom\";\n\nexport * from \"../config/v2/codegen\";\nexport * from \"../config/v2/defaults\";\nexport * from \"../config/v2/deploy\";\nexport * from \"../config/v2/dynamicResolution\";\nexport * from \"../config/v2/input\";\nexport * from \"../config/v2/namespace\";\nexport * from \"../config/v2/namespaces\";\nexport * from \"../config/v2/output\";\nexport * from \"../config/v2/system\";\nexport * from \"../config/v2/systems\";\nexport * from \"../config/v2/world\";\n","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","import { StoreInput, NamespaceInput as StoreNamespaceInput } from \"@latticexyz/store/internal\";\nimport { DynamicResolution, ValueWithType } from \"./dynamicResolution\";\nimport { Codegen, SystemDeploy } from \"./output\";\n\nexport type SystemDeployInput = Partial<SystemDeploy>;\n\nexport type SystemInput = {\n /**\n * Human-readable system label. Used as config keys, interface names, and filenames.\n * Labels are not length constrained like resource names, but special characters should be avoided to be compatible with the filesystem, Solidity compiler, etc.\n */\n readonly label: string;\n /**\n * Human-readable label for this system's namespace. Used for namespace config keys and directory names.\n * Defaults to the nearest namespace in the config or root namespace if not set.\n */\n readonly namespaceLabel?: string;\n /**\n * System namespace used in systems's resource ID and determines access control.\n * Defaults to the nearest namespace in the config or root namespace if not set.\n */\n readonly namespace?: string;\n /**\n * System name used in systems's resource ID.\n * Defaults to the first 16 characters of `label` if not set.\n */\n readonly name?: string;\n /** If openAccess is true, any address can call the system */\n readonly openAccess?: boolean;\n /** An array of addresses or system names that can access the system */\n readonly accessList?: readonly string[];\n readonly deploy?: SystemDeployInput;\n};\n\nexport type SystemsInput = {\n readonly [label: string]: Omit<SystemInput, \"label\" | \"namespaceLabel\" | \"namespace\">;\n};\n\nexport type NamespaceInput = StoreNamespaceInput & {\n readonly systems?: SystemsInput;\n};\n\nexport type NamespacesInput = {\n readonly [label: string]: Omit<NamespaceInput, \"label\">;\n};\n\ntype ModuleInputArtifactPath =\n | {\n /**\n * Import path to module's forge/solc JSON artifact with the module's compiled bytecode. This is used to create consistent, deterministic deploys for already-built modules\n * like those installed and imported from npm.\n *\n * This path is resolved using node's module resolution, so this supports both relative file paths (`../path/to/MyModule.json`) as well as JS import paths\n * (`@latticexyz/world-modules/out/CallWithSignatureModule.sol/CallWithSignatureModule.json`).\n */\n readonly artifactPath: string;\n readonly name?: never;\n }\n | {\n /**\n * The name of the module, used to construct the import path relative to the project directory.\n * @deprecated Use `artifactPath` instead.\n */\n readonly name: string;\n readonly artifactPath?: never;\n };\n\nexport type ModuleInput = ModuleInputArtifactPath & {\n /**\n * Should this module be installed as a root module?\n * @default false\n */\n readonly root?: boolean;\n /** Arguments to be passed to the module's install method */\n // TODO: make more strongly typed by taking in tables input\n readonly args?: readonly (ValueWithType | DynamicResolution)[];\n};\n\nexport type DeployInput = {\n /**\n * Script to execute after the deployment is complete (Default \"PostDeploy\").\n * Script must be placed in the forge scripts directory (see foundry.toml) and have a \".s.sol\" extension.\n */\n readonly postDeployScript?: string;\n /** Directory to write the deployment info to (Default \"./deploys\") */\n readonly deploysDirectory?: string;\n /** JSON file to write to with chain -> latest world deploy address (Default \"./worlds.json\") */\n readonly worldsFile?: string;\n /** Deploy the World as an upgradeable proxy */\n readonly upgradeableWorldImplementation?: boolean;\n /**\n * Deploy the World using a custom implementation. This world must implement the same interface as `World.sol` so that it can initialize core modules, etc.\n * If you want to extend the world with new functions or override existing registered functions, we recommend using [root systems](https://mud.dev/world/systems#root-systems).\n * However, there are rare cases where this may not be enough to modify the native/internal World behavior.\n * Note that deploying a custom World opts out of the world factory, deterministic world deploys, and upgradeable implementation proxy.\n */\n // TODO: enforce that this can't be used with `upgradeableWorldImplementation` (https://github.com/latticexyz/mud/issues/3151)\n readonly customWorld?: {\n /** Path to custom world source file relative to project root dir. */\n sourcePath: string;\n /** Contract name in custom world source file. */\n name: string;\n // TODO: constructor calldata (https://github.com/latticexyz/mud/issues/3150)\n };\n};\n\nexport type CodegenInput = Partial<Codegen>;\n\nexport type WorldInput = Omit<StoreInput, \"namespaces\"> & {\n readonly namespaces?: NamespacesInput;\n /**\n * Contracts named *System will be deployed by default\n * as public systems at `namespace/ContractName`, unless overridden\n *\n * The key is the system name (capitalized).\n * The value is a SystemConfig object.\n */\n readonly systems?: SystemsInput;\n /** System names to exclude from codegen and deployment */\n readonly excludeSystems?: readonly string[];\n /** Modules to install in the World */\n readonly modules?: readonly ModuleInput[];\n /** Deploy config */\n readonly deploy?: DeployInput;\n /** Codegen config */\n readonly codegen?: CodegenInput;\n};\n","import { Store } from \"@latticexyz/store\";\nimport { Namespace as StoreNamespace } from \"@latticexyz/store/internal\";\nimport { DynamicResolution, ValueWithType } from \"./dynamicResolution\";\nimport { Hex } from \"viem\";\n\nexport type Module = {\n /**\n * The name of the module\n * @deprecated\n */\n readonly name?: string;\n /** Should this module be installed as a root module? */\n readonly root: boolean;\n /** Arguments to be passed to the module's install method */\n readonly args: readonly (ValueWithType | DynamicResolution)[];\n /**\n * Import path to module's forge/solc JSON artifact with the module's compiled bytecode. This is used to create consistent, deterministic deploys for already-built modules\n * like those installed and imported from npm.\n *\n * This path is resolved using node's module resolution, so this supports both relative file paths (`../path/to/MyModule.json`) as well as JS import paths\n * (`@latticexyz/world-modules/out/CallWithSignatureModule.sol/CallWithSignatureModule.json`).\n *\n * 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.\n */\n readonly artifactPath: string | undefined;\n};\n\nexport type SystemDeploy = {\n /**\n * Whether or not to deploy the system.\n * Defaults to `false`.\n */\n readonly disabled: boolean;\n /**\n * Whether or not to register system functions on the world.\n * System functions are prefixed with the system namespace when registering on the world, so system function names must be unique within their namespace.\n * Defaults to `true`.\n */\n readonly registerWorldFunctions: boolean;\n};\n\nexport type System = {\n /**\n * Human-readable label for this system. Used as config keys, interface names, and filenames.\n * Labels are not length constrained like resource names, but special characters should be avoided to be compatible with the filesystem, Solidity compiler, etc.\n */\n readonly label: string;\n /**\n * Human-readable label for this system's namespace. Used for namespace config keys and directory names.\n */\n readonly namespaceLabel: string;\n /**\n * System namespace used in system's resource ID and determines access control.\n */\n readonly namespace: string;\n /**\n * System name used in system's resource ID.\n */\n readonly name: string;\n /**\n * System's resource ID.\n */\n readonly systemId: Hex;\n /** If openAccess is true, any address can call the system */\n readonly openAccess: boolean;\n /** An array of addresses or system names that can access the system */\n readonly accessList: readonly string[];\n readonly deploy: SystemDeploy;\n};\n\nexport type Systems = {\n readonly [label: string]: System;\n};\n\n// TODO: should we make Namespace an interface that we can extend here instead of overriding?\nexport type Namespace = StoreNamespace & { readonly systems: Systems };\n\nexport type Namespaces = {\n readonly [label: string]: Namespace;\n};\n\nexport type Deploy = {\n /**\n * Script to execute after the deployment is complete (Default \"PostDeploy\").\n * Script must be placed in the forge scripts directory (see foundry.toml) and have a \".s.sol\" extension.\n */\n readonly postDeployScript: string;\n /** Directory to write the deployment info to (Default \"./deploys\") */\n readonly deploysDirectory: string;\n /** JSON file to write to with chain -> latest world deploy address (Default \"./worlds.json\") */\n readonly worldsFile: string;\n /** Deploy the World as an upgradeable proxy */\n readonly upgradeableWorldImplementation: boolean;\n /**\n * Deploy the World using a custom implementation. This world must implement the same interface as `World.sol` so that it can initialize core modules, etc.\n * If you want to extend the world with new functions or override existing registered functions, we recommend using [root systems](https://mud.dev/world/systems#root-systems).\n * However, there are rare cases where this may not be enough to modify the native/internal World behavior.\n * Note that deploying a custom World opts out of the world factory, deterministic world deploys, and upgradeable implementation proxy.\n */\n readonly customWorld?: {\n /** Path to custom world source file relative to project root dir. */\n sourcePath: string;\n /** Contract name in custom world source file. */\n name: string;\n };\n};\n\nexport type Codegen = {\n /**\n * @internal\n * The name of the World interface to generate. (Default `IWorld`)\n */\n readonly worldInterfaceName: string;\n /** Directory to output system and world interfaces of `worldgen` (Default \"world\") */\n readonly worldgenDirectory: string;\n /** Directory to output system libraries (Default \"libraries\") */\n readonly systemLibrariesDirectory: string;\n /** Generate libraries for each system (Default false) */\n readonly generateSystemLibraries: boolean;\n /**\n * @internal\n * Absolute import path for a package import or starting with `.` for an import relative to project root dir.\n *\n * Defaults to `@latticexyz/world/src` if not set.\n */\n readonly worldImportPath: string;\n};\n\nexport type World = Omit<Store, \"namespaces\"> & {\n readonly namespaces: Namespaces;\n readonly systems: Systems;\n /** Systems to exclude from automatic deployment */\n readonly excludeSystems: readonly string[];\n /** Modules to in the World */\n readonly modules: readonly Module[];\n /** Deploy config */\n readonly deploy: Deploy;\n /** Codegen config */\n readonly codegen: Codegen;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;ACAA;AAAA,SAAiD,0BAAqD;;;ACAtG;AAAA,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;AAC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E;AAC5F;;;AC/DA;;;ACAA;","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 /**\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":"6RAAA,OAAiD,sBAAAA,MAAqD,OCAtG,OAAS,iBAAAC,EAAe,mBAAAC,MAAuB,qBAIxC,SAASC,EAAqCC,EAAeC,EAAsB,CACxF,IAAMC,EAAWL,EAAcG,CAAQ,EACjCG,EAAsBD,EAAS,YAAc,GAAK,GAAGA,EAAS,SAAS,KAAO,KACpF,OAAIC,GAAuB,MAAQF,EAAa,WAAWE,CAAmB,GAC5E,QAAQ,KAEN,iCAAiCF,CAAY,6BAA6BH,EAAgBI,CAAQ,CAAC;AAAA;AAAA,0FACrG,EACOD,EAAa,MAAME,EAAoB,MAAM,GAE/CF,CACT,CDMO,SAASG,GAAkF,CAChG,IAAAC,EACA,SAAAC,EACA,aAAAC,EACA,KAAAC,CACF,EAAqH,CACnH,MAAO,CACLF,EACAG,EAAsC,CACpC,IAAAJ,EACA,aAAcK,EAAqCJ,EAAUC,CAAY,EACzE,KAAAC,CACF,CAAoD,CACtD,CACF,CEnCA,OAA4C,sBAAAG,MAA8D,OAcnG,SAASC,GAAsF,CACpG,IAAAC,EACA,KAAAC,EACA,SAAAC,EACA,aAAAC,EACA,KAAAC,CACF,EAEE,CACA,MAAO,CACLH,EACAC,EACAG,EAAsC,CACpC,IAAAL,EACA,aAAcM,EAAqCJ,EAAUC,CAAY,EACzE,KAAAC,CACF,CAAoD,CACtD,CACF,CChCA,OAA4C,sBAAAG,MAAqD,OAO1F,SAASC,GACdC,EACAC,EACwF,CACxF,MAAO,CACL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AAG,CAC7B,GAAM,CAACE,CAAK,EAAIF,EACV,CAAC,CAAEC,CAAK,EAAIC,EAClB,MAAO,CAAE,KAAM,UAAW,MAAOD,EAAM,OAAQ,CACjD,CACF,CAGF,MAAM,IAAI,MAAM;AAAA,EAA0C,KAAK,UAAUH,EAAO,KAAM,CAAC,CAAC,EAAE,CAC5F","names":["encodeFunctionData","hexToResource","resourceToLabel","internal_normalizeSystemFunctionName","systemId","functionName","resource","worldFunctionPrefix","encodeSystemCall","abi","systemId","functionName","args","encodeFunctionData","internal_normalizeSystemFunctionName","encodeFunctionData","encodeSystemCallFrom","abi","from","systemId","functionName","args","encodeFunctionData","internal_normalizeSystemFunctionName","encodeFunctionData","encodeSystemCalls","abi","systemCalls","systemId","functionName","args","encodeFunctionData","internal_normalizeSystemFunctionName","encodeFunctionData","encodeSystemCallsFrom","abi","from","systemCalls","systemId","functionName","args","encodeFunctionData","internal_normalizeSystemFunctionName","slice","concat","getAction","encodeFunctionData","readContract","viem_writeContract","readHex","getKeySchema","getValueSchema","getSchemaTypes","decodeValueArgs","encodeKey","callFrom","params","client","writeArgs","_writeContract","getAction","viem_writeContract","batchCallArgs","systemCalls","systemCall","worldCalldata","encodeFunctionData","worldFunctionSelector","slice","systemId","systemFunctionSelector","worldFunctionToSystemFunction","systemCalldata","concat","readHex","systemFunctionCache","cacheKey","cached","systemFunction","retrieveSystemFunctionFromContract","publicClient","worldAddress","table","mud_config_default","keySchema","getSchemaTypes","getKeySchema","valueSchema","getValueSchema","_readContract","readContract","staticData","encodedLengths","dynamicData","encodeKey","decoded","decodeValueArgs","resolveTableId","tableName","isDynamicResolution","value","isValueWithType","resolveWithContext","input","context","tableEntries","table","entry"]}
|
package/dist/mud.config.js
CHANGED
@@ -1,12 +1,2 @@
|
|
1
|
-
import
|
2
|
-
configInput,
|
3
|
-
mud_config_default
|
4
|
-
} from "./chunk-S5LARYWY.js";
|
5
|
-
import "./chunk-TL2M3LZH.js";
|
6
|
-
import "./chunk-AAKXFFCU.js";
|
7
|
-
import "./chunk-AAWFTQHP.js";
|
8
|
-
export {
|
9
|
-
configInput,
|
10
|
-
mud_config_default as default
|
11
|
-
};
|
1
|
+
import{a,b}from"./chunk-AJUHOWGE.js";import"./chunk-DIHBEOC2.js";import"./chunk-CGF3NYHC.js";import"./chunk-FW4363Y4.js";export{a as configInput,b as default};
|
12
2
|
//# sourceMappingURL=mud.config.js.map
|