@latticexyz/world 2.0.2 → 2.0.3

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.
@@ -2,7 +2,7 @@ export { S as SYSTEM_DEFAULTS, W as WORLD_DEFAULTS } from './defaults-87a942d7.j
2
2
  import { StoreConfig } from '@latticexyz/store/internal';
3
3
  import { W as WorldConfig, S as SystemConfig } from './types-b088e935.js';
4
4
  export { E as ExpandSystemConfig, c as ExpandSystemsConfig, M as ModuleConfig, a as SystemUserConfig, b as SystemsUserConfig, d as WorldUserConfig, e as zPluginWorldConfig, z as zWorldConfig } from './types-b088e935.js';
5
- import { Abi, ContractFunctionName, EncodeFunctionDataParameters, Hex, Address, Chain, Account, WalletClient, Transport, WalletActions, PublicClient } from 'viem';
5
+ import { Abi, ContractFunctionName, EncodeFunctionDataParameters, Hex, Address, Chain, Account, Client, Transport, WalletActions, PublicClient } from 'viem';
6
6
  import { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from 'abitype';
7
7
  import 'zod';
8
8
  import '@latticexyz/config/library';
@@ -135,7 +135,7 @@ type SystemFunction = {
135
135
  systemId: Hex;
136
136
  systemFunctionSelector: Hex;
137
137
  };
138
- declare function callFrom<TChain extends Chain, TAccount extends Account>(params: CallFromParameters): (client: WalletClient<Transport, TChain, TAccount>) => Pick<WalletActions<TChain, TAccount>, "writeContract">;
138
+ declare function callFrom<TChain extends Chain, TAccount extends Account>(params: CallFromParameters): (client: Client<Transport, TChain, TAccount>) => Pick<WalletActions<TChain, TAccount>, "writeContract">;
139
139
 
140
140
  declare const delegationWithSignatureTypes: {
141
141
  readonly Delegation: readonly [{
package/dist/internal.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as l}from"./chunk-OS2BVN74.js";import{a as M,b as H}from"./chunk-AGPG4DQJ.js";import"./chunk-3GSLUFHC.js";import{a as R,b as E}from"./chunk-RF4HOV37.js";import{a as k,b as W}from"./chunk-YMY7QWFU.js";import{encodeFunctionData as C}from"viem";function p({abi:e,systemId:n,functionName:t,args:a}){return[n,C({abi:e,functionName:t,args:a})]}import{encodeFunctionData as x}from"viem";function c({abi:e,from:n,systemId:t,functionName:a,args:i}){return[n,t,x({abi:e,functionName:a,args:i})]}function X(e,n){return n.map(t=>p({...t,abi:e}))}function ee(e,n,t){return t.map(a=>c({...a,abi:e,from:n}))}import{slice as I,concat as f}from"viem";import{getAction as d,encodeFunctionData as S}from"viem/utils";import{writeContract as b}from"viem/actions";import{readHex as P}from"@latticexyz/common";import{getKeySchema as g,getValueSchema as w,getSchemaTypes as F,decodeValueArgs as N,encodeKey as h}from"@latticexyz/protocol-parser/internal";var u=[{type:"function",name:"getDynamicField",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"dynamicFieldIndex",type:"uint8",internalType:"uint8"}],outputs:[{name:"",type:"bytes",internalType:"bytes"}],stateMutability:"view"},{type:"function",name:"getDynamicFieldLength",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"dynamicFieldIndex",type:"uint8",internalType:"uint8"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"getDynamicFieldSlice",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"dynamicFieldIndex",type:"uint8",internalType:"uint8"},{name:"start",type:"uint256",internalType:"uint256"},{name:"end",type:"uint256",internalType:"uint256"}],outputs:[{name:"data",type:"bytes",internalType:"bytes"}],stateMutability:"view"},{type:"function",name:"getField",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"fieldIndex",type:"uint8",internalType:"uint8"},{name:"fieldLayout",type:"bytes32",internalType:"FieldLayout"}],outputs:[{name:"data",type:"bytes",internalType:"bytes"}],stateMutability:"view"},{type:"function",name:"getField",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"fieldIndex",type:"uint8",internalType:"uint8"}],outputs:[{name:"data",type:"bytes",internalType:"bytes"}],stateMutability:"view"},{type:"function",name:"getFieldLayout",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"}],outputs:[{name:"fieldLayout",type:"bytes32",internalType:"FieldLayout"}],stateMutability:"view"},{type:"function",name:"getFieldLength",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"fieldIndex",type:"uint8",internalType:"uint8"},{name:"fieldLayout",type:"bytes32",internalType:"FieldLayout"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"getFieldLength",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"fieldIndex",type:"uint8",internalType:"uint8"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"getKeySchema",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"}],outputs:[{name:"keySchema",type:"bytes32",internalType:"Schema"}],stateMutability:"view"},{type:"function",name:"getRecord",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"fieldLayout",type:"bytes32",internalType:"FieldLayout"}],outputs:[{name:"staticData",type:"bytes",internalType:"bytes"},{name:"encodedLengths",type:"bytes32",internalType:"EncodedLengths"},{name:"dynamicData",type:"bytes",internalType:"bytes"}],stateMutability:"view"},{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"},{type:"function",name:"getStaticField",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"fieldIndex",type:"uint8",internalType:"uint8"},{name:"fieldLayout",type:"bytes32",internalType:"FieldLayout"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"getValueSchema",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"}],outputs:[{name:"valueSchema",type:"bytes32",internalType:"Schema"}],stateMutability:"view"}];function le(e){return n=>({writeContract:async t=>{if(t.address!==e.worldAddress)return d(n,b,"writeContract")(t);let a=S({abi:t.abi,functionName:t.functionName,args:t.args}),i=I(a,0,4),{systemId:o,systemFunctionSelector:r}=await v(e,i),y=f([r,P(a,4)]),s={...t,functionName:"callFrom",args:[e.delegatorAddress,o,y]};return d(n,b,"writeContract")(s)}})}var T=new Map;async function v(e,n){let t=f([e.worldAddress,n]),a=T.get(t);if(a)return a;let i=e.worldFunctionToSystemFunction?await e.worldFunctionToSystemFunction(n):await D(e.publicClient,e.worldAddress,n);return T.set(t,i),i}async function D(e,n,t){let a=l.tables.world__FunctionSelectors,i=F(g(a)),o=F(w(a)),[r,y,s]=await e.readContract({address:n,abi:u,functionName:"getRecord",args:[a.tableId,h(i,{worldFunctionSelector:t})]}),m=N(o,{staticData:r,encodedLengths:y,dynamicData:s});return{systemId:m.systemId,systemFunctionSelector:m.systemFunctionSelector}}var ce={Delegation:[{name:"delegatee",type:"address"},{name:"delegationControlId",type:"bytes32"},{name:"initCallData",type:"bytes"},{name:"delegator",type:"address"},{name:"nonce",type:"uint256"}]};export{R as SYSTEM_DEFAULTS,E as WORLD_DEFAULTS,le as callFrom,ce as delegationWithSignatureTypes,p as encodeSystemCall,c as encodeSystemCallFrom,X as encodeSystemCalls,ee as encodeSystemCallsFrom,W as resolveSystemConfig,k as resolveWorldConfig,H as zPluginWorldConfig,M as zWorldConfig};
1
+ import{a as l}from"./chunk-OS2BVN74.js";import{a as W,b as H}from"./chunk-AGPG4DQJ.js";import"./chunk-3GSLUFHC.js";import{a as R,b as E}from"./chunk-RF4HOV37.js";import{a as k,b as M}from"./chunk-YMY7QWFU.js";import{encodeFunctionData as C}from"viem";function c({abi:t,systemId:n,functionName:e,args:a}){return[n,C({abi:t,functionName:e,args:a})]}import{encodeFunctionData as x}from"viem";function p({abi:t,from:n,systemId:e,functionName:a,args:i}){return[n,e,x({abi:t,functionName:a,args:i})]}function X(t,n){return n.map(e=>c({...e,abi:t}))}function ee(t,n,e){return e.map(a=>p({...a,abi:t,from:n}))}import{slice as I,concat as T}from"viem";import{getAction as d,encodeFunctionData as A}from"viem/utils";import{writeContract as b}from"viem/actions";import{readHex as P}from"@latticexyz/common";import{getKeySchema as g,getValueSchema as N,getSchemaTypes as F,decodeValueArgs as w,encodeKey as h}from"@latticexyz/protocol-parser/internal";var u=[{type:"function",name:"getDynamicField",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"dynamicFieldIndex",type:"uint8",internalType:"uint8"}],outputs:[{name:"",type:"bytes",internalType:"bytes"}],stateMutability:"view"},{type:"function",name:"getDynamicFieldLength",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"dynamicFieldIndex",type:"uint8",internalType:"uint8"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"getDynamicFieldSlice",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"dynamicFieldIndex",type:"uint8",internalType:"uint8"},{name:"start",type:"uint256",internalType:"uint256"},{name:"end",type:"uint256",internalType:"uint256"}],outputs:[{name:"data",type:"bytes",internalType:"bytes"}],stateMutability:"view"},{type:"function",name:"getField",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"fieldIndex",type:"uint8",internalType:"uint8"},{name:"fieldLayout",type:"bytes32",internalType:"FieldLayout"}],outputs:[{name:"data",type:"bytes",internalType:"bytes"}],stateMutability:"view"},{type:"function",name:"getField",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"fieldIndex",type:"uint8",internalType:"uint8"}],outputs:[{name:"data",type:"bytes",internalType:"bytes"}],stateMutability:"view"},{type:"function",name:"getFieldLayout",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"}],outputs:[{name:"fieldLayout",type:"bytes32",internalType:"FieldLayout"}],stateMutability:"view"},{type:"function",name:"getFieldLength",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"fieldIndex",type:"uint8",internalType:"uint8"},{name:"fieldLayout",type:"bytes32",internalType:"FieldLayout"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"getFieldLength",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"fieldIndex",type:"uint8",internalType:"uint8"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"getKeySchema",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"}],outputs:[{name:"keySchema",type:"bytes32",internalType:"Schema"}],stateMutability:"view"},{type:"function",name:"getRecord",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"fieldLayout",type:"bytes32",internalType:"FieldLayout"}],outputs:[{name:"staticData",type:"bytes",internalType:"bytes"},{name:"encodedLengths",type:"bytes32",internalType:"EncodedLengths"},{name:"dynamicData",type:"bytes",internalType:"bytes"}],stateMutability:"view"},{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"},{type:"function",name:"getStaticField",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"},{name:"fieldIndex",type:"uint8",internalType:"uint8"},{name:"fieldLayout",type:"bytes32",internalType:"FieldLayout"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"getValueSchema",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"}],outputs:[{name:"valueSchema",type:"bytes32",internalType:"Schema"}],stateMutability:"view"}];function ce(t){return n=>({writeContract:async e=>{if(e.address!==t.worldAddress||e.functionName==="call"||e.functionName==="callFrom"||e.functionName==="registerDelegationWithSignature")return d(n,b,"writeContract")(e);let a=A({abi:e.abi,functionName:e.functionName,args:e.args}),i=I(a,0,4),{systemId:o,systemFunctionSelector:r}=await v(t,i),y=T([r,P(a,4)]),s={...e,functionName:"callFrom",args:[t.delegatorAddress,o,y]};return d(n,b,"writeContract")(s)}})}var f=new Map;async function v(t,n){let e=T([t.worldAddress,n]),a=f.get(e);if(a)return a;let i=t.worldFunctionToSystemFunction?await t.worldFunctionToSystemFunction(n):await D(t.publicClient,t.worldAddress,n);return f.set(e,i),i}async function D(t,n,e){let a=l.tables.world__FunctionSelectors,i=F(g(a)),o=F(N(a)),[r,y,s]=await t.readContract({address:n,abi:u,functionName:"getRecord",args:[a.tableId,h(i,{worldFunctionSelector:e})]}),m=w(o,{staticData:r,encodedLengths:y,dynamicData:s});return{systemId:m.systemId,systemFunctionSelector:m.systemFunctionSelector}}var ue={Delegation:[{name:"delegatee",type:"address"},{name:"delegationControlId",type:"bytes32"},{name:"initCallData",type:"bytes"},{name:"delegator",type:"address"},{name:"nonce",type:"uint256"}]};export{R as SYSTEM_DEFAULTS,E as WORLD_DEFAULTS,ce as callFrom,ue as delegationWithSignatureTypes,c as encodeSystemCall,p as encodeSystemCallFrom,X as encodeSystemCalls,ee as encodeSystemCallsFrom,M as resolveSystemConfig,k as resolveWorldConfig,H as zPluginWorldConfig,W as zWorldConfig};
2
2
  //# sourceMappingURL=internal.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../ts/encodeSystemCall.ts","../ts/encodeSystemCallFrom.ts","../ts/encodeSystemCalls.ts","../ts/encodeSystemCallsFrom.ts","../ts/actions/callFrom.ts","../out/IStoreRead.sol/IStoreRead.abi.json","../ts/delegationWithSignatureTypes.ts"],"sourcesContent":["import { Abi, EncodeFunctionDataParameters, Hex, encodeFunctionData, type ContractFunctionName } from \"viem\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\nimport IWorldCallAbi from \"../out/IWorldKernel.sol/IWorldCall.abi.json\";\n\nexport type SystemCall<abi extends Abi, functionName extends ContractFunctionName<abi>> = EncodeFunctionDataParameters<\n abi,\n functionName\n> & {\n readonly systemId: Hex;\n};\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<\n ExtractAbiFunction<typeof IWorldCallAbi, \"call\">[\"inputs\"]\n> {\n return [\n systemId,\n encodeFunctionData<abi, functionName>({\n abi,\n functionName,\n args,\n } as unknown as EncodeFunctionDataParameters<abi, functionName>),\n ];\n}\n","import { Abi, EncodeFunctionDataParameters, encodeFunctionData, Address, type ContractFunctionName } from \"viem\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\nimport IWorldCallAbi from \"../out/IWorldKernel.sol/IWorldCall.abi.json\";\nimport { SystemCall } from \"./encodeSystemCall\";\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<typeof IWorldCallAbi, \"callFrom\">[\"inputs\"]\n> {\n return [\n from,\n systemId,\n encodeFunctionData<abi, functionName>({\n abi,\n functionName,\n args,\n } as unknown as EncodeFunctionDataParameters<abi, functionName>),\n ];\n}\n","import { Abi, type ContractFunctionName } from \"viem\";\nimport IWorldCallAbi from \"../out/IWorldKernel.sol/IWorldCall.abi.json\";\nimport { SystemCall, encodeSystemCall } from \"./encodeSystemCall\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\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<typeof IWorldCallAbi, \"call\">[\"inputs\"]>[] {\n return systemCalls.map((systemCall) => encodeSystemCall({ ...systemCall, abi } as SystemCall<abi, functionName>));\n}\n","import { Abi, Address, type ContractFunctionName } from \"viem\";\nimport IWorldCallAbi from \"../out/IWorldKernel.sol/IWorldCall.abi.json\";\nimport { SystemCallFrom, encodeSystemCallFrom } from \"./encodeSystemCallFrom\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\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<typeof IWorldCallAbi, \"callFrom\">[\"inputs\"]>[] {\n return systemCalls.map((systemCall) =>\n encodeSystemCallFrom({ ...systemCall, abi, from } as SystemCallFrom<abi, functionName>),\n );\n}\n","import {\n slice,\n concat,\n type WalletClient,\n type Transport,\n type Chain,\n type Account,\n type Hex,\n type WalletActions,\n type WriteContractReturnType,\n type EncodeFunctionDataParameters,\n type PublicClient,\n} from \"viem\";\nimport { getAction, encodeFunctionData } from \"viem/utils\";\nimport { 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 IStoreReadAbi from \"../../out/IStoreRead.sol/IStoreRead.abi.json\";\n\n// Accepts either `worldFunctionToSystemFunction` or `publicClient`, but not both.\ntype CallFromParameters = CallFromFunctionParameters | CallFromClientParameters;\ntype CallFromBaseParameters = {\n worldAddress: Hex;\n delegatorAddress: Hex;\n};\ntype CallFromFunctionParameters = CallFromBaseParameters & {\n worldFunctionToSystemFunction: (worldFunctionSelector: Hex) => Promise<SystemFunction>;\n publicClient?: never;\n};\ntype CallFromClientParameters = CallFromBaseParameters & {\n worldFunctionToSystemFunction?: never;\n publicClient: PublicClient;\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<TChain extends Chain, TAccount extends Account>(\n params: CallFromParameters,\n): (client: WalletClient<Transport, TChain, TAccount>) => Pick<WalletActions<TChain, TAccount>, \"writeContract\"> {\n return (client) => ({\n // Applies to: `client.writeContract`, `getContract(client, ...).write`\n writeContract: async (writeArgs): Promise<WriteContractReturnType> => {\n // Skip if the contract isn't the World.\n if (writeArgs.address !== params.worldAddress) {\n return getAction(client, writeContract, \"writeContract\")(writeArgs);\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(params, worldFunctionSelector);\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 // Construct args for `callFrom`.\n const callFromArgs: typeof writeArgs = {\n ...writeArgs,\n functionName: \"callFrom\",\n args: [params.delegatorAddress, systemId, systemCalldata],\n };\n\n // Call `writeContract` with the new args.\n return getAction(client, writeContract, \"writeContract\")(callFromArgs);\n },\n });\n}\n\nconst systemFunctionCache = new Map<Hex, SystemFunction>();\n\nasync function worldFunctionToSystemFunction(\n params: CallFromParameters,\n worldFunctionSelector: Hex,\n): Promise<SystemFunction> {\n const cacheKey = concat([params.worldAddress, 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(worldFunctionSelector)\n : await retrieveSystemFunctionFromContract(params.publicClient, params.worldAddress, worldFunctionSelector);\n\n systemFunctionCache.set(cacheKey, systemFunction);\n\n return systemFunction;\n}\n\nasync function retrieveSystemFunctionFromContract(\n publicClient: PublicClient,\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 [staticData, encodedLengths, dynamicData] = await publicClient.readContract({\n address: worldAddress,\n abi: IStoreReadAbi,\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","[\n {\n \"type\": \"function\",\n \"name\": \"getDynamicField\",\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 \"name\": \"dynamicFieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"\",\n \"type\": \"bytes\",\n \"internalType\": \"bytes\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getDynamicFieldLength\",\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 \"name\": \"dynamicFieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"\",\n \"type\": \"uint256\",\n \"internalType\": \"uint256\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getDynamicFieldSlice\",\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 \"name\": \"dynamicFieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n },\n {\n \"name\": \"start\",\n \"type\": \"uint256\",\n \"internalType\": \"uint256\"\n },\n {\n \"name\": \"end\",\n \"type\": \"uint256\",\n \"internalType\": \"uint256\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"data\",\n \"type\": \"bytes\",\n \"internalType\": \"bytes\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getField\",\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 \"name\": \"fieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n },\n {\n \"name\": \"fieldLayout\",\n \"type\": \"bytes32\",\n \"internalType\": \"FieldLayout\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"data\",\n \"type\": \"bytes\",\n \"internalType\": \"bytes\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getField\",\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 \"name\": \"fieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"data\",\n \"type\": \"bytes\",\n \"internalType\": \"bytes\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getFieldLayout\",\n \"inputs\": [\n {\n \"name\": \"tableId\",\n \"type\": \"bytes32\",\n \"internalType\": \"ResourceId\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"fieldLayout\",\n \"type\": \"bytes32\",\n \"internalType\": \"FieldLayout\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getFieldLength\",\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 \"name\": \"fieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n },\n {\n \"name\": \"fieldLayout\",\n \"type\": \"bytes32\",\n \"internalType\": \"FieldLayout\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"\",\n \"type\": \"uint256\",\n \"internalType\": \"uint256\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getFieldLength\",\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 \"name\": \"fieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"\",\n \"type\": \"uint256\",\n \"internalType\": \"uint256\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getKeySchema\",\n \"inputs\": [\n {\n \"name\": \"tableId\",\n \"type\": \"bytes32\",\n \"internalType\": \"ResourceId\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"keySchema\",\n \"type\": \"bytes32\",\n \"internalType\": \"Schema\"\n }\n ],\n \"stateMutability\": \"view\"\n },\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 \"name\": \"fieldLayout\",\n \"type\": \"bytes32\",\n \"internalType\": \"FieldLayout\"\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 \"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 \"type\": \"function\",\n \"name\": \"getStaticField\",\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 \"name\": \"fieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n },\n {\n \"name\": \"fieldLayout\",\n \"type\": \"bytes32\",\n \"internalType\": \"FieldLayout\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"\",\n \"type\": \"bytes32\",\n \"internalType\": \"bytes32\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getValueSchema\",\n \"inputs\": [\n {\n \"name\": \"tableId\",\n \"type\": \"bytes32\",\n \"internalType\": \"ResourceId\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"valueSchema\",\n \"type\": \"bytes32\",\n \"internalType\": \"Schema\"\n }\n ],\n \"stateMutability\": \"view\"\n }\n]","// Follows https://viem.sh/docs/actions/wallet/signTypedData#usage\n\nexport const delegationWithSignatureTypes = {\n Delegation: [\n { name: \"delegatee\", type: \"address\" },\n { name: \"delegationControlId\", type: \"bytes32\" },\n { name: \"initCallData\", type: \"bytes\" },\n { name: \"delegator\", type: \"address\" },\n { name: \"nonce\", type: \"uint256\" },\n ],\n} as const;\n"],"mappings":"iNAAA,OAAiD,sBAAAA,MAAqD,OAY/F,SAASC,EAAkF,CAChG,IAAAC,EACA,SAAAC,EACA,aAAAC,EACA,KAAAC,CACF,EAEE,CACA,MAAO,CACLF,EACAH,EAAsC,CACpC,IAAAE,EACA,aAAAE,EACA,KAAAC,CACF,CAA+D,CACjE,CACF,CC5BA,OAA4C,sBAAAC,MAA8D,OAanG,SAASC,EAAsF,CACpG,IAAAC,EACA,KAAAC,EACA,SAAAC,EACA,aAAAC,EACA,KAAAC,CACF,EAEE,CACA,MAAO,CACLH,EACAC,EACAJ,EAAsC,CACpC,IAAAE,EACA,aAAAG,EACA,KAAAC,CACF,CAA+D,CACjE,CACF,CCzBO,SAASC,EACdC,EACAC,EAC6F,CAC7F,OAAOA,EAAY,IAAKC,GAAeC,EAAiB,CAAE,GAAGD,EAAY,IAAAF,CAAI,CAAkC,CAAC,CAClH,CCLO,SAASI,GACdC,EACAC,EACAC,EACiG,CACjG,OAAOA,EAAY,IAAKC,GACtBC,EAAqB,CAAE,GAAGD,EAAY,IAAAH,EAAK,KAAAC,CAAK,CAAsC,CACxF,CACF,CCdA,OACE,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N,CAAK,CAAC,EAElD,CAACO,EAAYC,EAAgBC,CAAW,EAAI,MAAMX,EAAa,aAAa,CAChF,QAASC,EACT,IAAKW,EACL,aAAc,YACd,KAAM,CAACV,EAAM,QAASW,EAAUT,EAAW,CAAE,sBAAAlB,CAAsB,CAAC,CAAC,CACvE,CAAC,EAEK4B,EAAUC,EAAgBR,EAAa,CAAE,WAAAE,EAAY,eAAAC,EAAgB,YAAAC,CAAY,CAAC,EAOxF,MALuC,CACrC,SAAUG,EAAQ,SAClB,uBAAwBA,EAAQ,sBAClC,CAGF,CE1IO,IAAME,GAA+B,CAC1C,WAAY,CACV,CAAE,KAAM,YAAa,KAAM,SAAU,EACrC,CAAE,KAAM,sBAAuB,KAAM,SAAU,EAC/C,CAAE,KAAM,eAAgB,KAAM,OAAQ,EACtC,CAAE,KAAM,YAAa,KAAM,SAAU,EACrC,CAAE,KAAM,QAAS,KAAM,SAAU,CACnC,CACF","names":["encodeFunctionData","encodeSystemCall","abi","systemId","functionName","args","encodeFunctionData","encodeSystemCallFrom","abi","from","systemId","functionName","args","encodeSystemCalls","abi","systemCalls","systemCall","encodeSystemCall","encodeSystemCallsFrom","abi","from","systemCalls","systemCall","encodeSystemCallFrom","slice","concat","getAction","encodeFunctionData","writeContract","readHex","getKeySchema","getValueSchema","getSchemaTypes","decodeValueArgs","encodeKey","IStoreRead_abi_default","callFrom","params","client","writeArgs","getAction","writeContract","worldCalldata","encodeFunctionData","worldFunctionSelector","slice","systemId","systemFunctionSelector","worldFunctionToSystemFunction","systemCalldata","concat","readHex","callFromArgs","systemFunctionCache","cacheKey","cached","systemFunction","retrieveSystemFunctionFromContract","publicClient","worldAddress","table","mud_config_default","keySchema","getSchemaTypes","getKeySchema","valueSchema","getValueSchema","staticData","encodedLengths","dynamicData","IStoreRead_abi_default","encodeKey","decoded","decodeValueArgs","delegationWithSignatureTypes"]}
1
+ {"version":3,"sources":["../ts/encodeSystemCall.ts","../ts/encodeSystemCallFrom.ts","../ts/encodeSystemCalls.ts","../ts/encodeSystemCallsFrom.ts","../ts/actions/callFrom.ts","../out/IStoreRead.sol/IStoreRead.abi.json","../ts/delegationWithSignatureTypes.ts"],"sourcesContent":["import { Abi, EncodeFunctionDataParameters, Hex, encodeFunctionData, type ContractFunctionName } from \"viem\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\nimport IWorldCallAbi from \"../out/IWorldKernel.sol/IWorldCall.abi.json\";\n\nexport type SystemCall<abi extends Abi, functionName extends ContractFunctionName<abi>> = EncodeFunctionDataParameters<\n abi,\n functionName\n> & {\n readonly systemId: Hex;\n};\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<\n ExtractAbiFunction<typeof IWorldCallAbi, \"call\">[\"inputs\"]\n> {\n return [\n systemId,\n encodeFunctionData<abi, functionName>({\n abi,\n functionName,\n args,\n } as unknown as EncodeFunctionDataParameters<abi, functionName>),\n ];\n}\n","import { Abi, EncodeFunctionDataParameters, encodeFunctionData, Address, type ContractFunctionName } from \"viem\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\nimport IWorldCallAbi from \"../out/IWorldKernel.sol/IWorldCall.abi.json\";\nimport { SystemCall } from \"./encodeSystemCall\";\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<typeof IWorldCallAbi, \"callFrom\">[\"inputs\"]\n> {\n return [\n from,\n systemId,\n encodeFunctionData<abi, functionName>({\n abi,\n functionName,\n args,\n } as unknown as EncodeFunctionDataParameters<abi, functionName>),\n ];\n}\n","import { Abi, type ContractFunctionName } from \"viem\";\nimport IWorldCallAbi from \"../out/IWorldKernel.sol/IWorldCall.abi.json\";\nimport { SystemCall, encodeSystemCall } from \"./encodeSystemCall\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\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<typeof IWorldCallAbi, \"call\">[\"inputs\"]>[] {\n return systemCalls.map((systemCall) => encodeSystemCall({ ...systemCall, abi } as SystemCall<abi, functionName>));\n}\n","import { Abi, Address, type ContractFunctionName } from \"viem\";\nimport IWorldCallAbi from \"../out/IWorldKernel.sol/IWorldCall.abi.json\";\nimport { SystemCallFrom, encodeSystemCallFrom } from \"./encodeSystemCallFrom\";\nimport type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from \"abitype\";\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<typeof IWorldCallAbi, \"callFrom\">[\"inputs\"]>[] {\n return systemCalls.map((systemCall) =>\n encodeSystemCallFrom({ ...systemCall, abi, from } as SystemCallFrom<abi, functionName>),\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 WriteContractReturnType,\n type EncodeFunctionDataParameters,\n type PublicClient,\n Client,\n} from \"viem\";\nimport { getAction, encodeFunctionData } from \"viem/utils\";\nimport { 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 IStoreReadAbi from \"../../out/IStoreRead.sol/IStoreRead.abi.json\";\n\n// Accepts either `worldFunctionToSystemFunction` or `publicClient`, but not both.\ntype CallFromParameters = CallFromFunctionParameters | CallFromClientParameters;\ntype CallFromBaseParameters = {\n worldAddress: Hex;\n delegatorAddress: Hex;\n};\ntype CallFromFunctionParameters = CallFromBaseParameters & {\n worldFunctionToSystemFunction: (worldFunctionSelector: Hex) => Promise<SystemFunction>;\n publicClient?: never;\n};\ntype CallFromClientParameters = CallFromBaseParameters & {\n worldFunctionToSystemFunction?: never;\n publicClient: PublicClient;\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<TChain extends Chain, TAccount extends Account>(\n params: CallFromParameters,\n): (client: Client<Transport, TChain, TAccount>) => Pick<WalletActions<TChain, TAccount>, \"writeContract\"> {\n return (client) => ({\n // Applies to: `client.writeContract`, `getContract(client, ...).write`\n writeContract: async (writeArgs): Promise<WriteContractReturnType> => {\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 === \"registerDelegationWithSignature\"\n ) {\n return getAction(client, writeContract, \"writeContract\")(writeArgs);\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(params, worldFunctionSelector);\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 // Construct args for `callFrom`.\n const callFromArgs: typeof writeArgs = {\n ...writeArgs,\n functionName: \"callFrom\",\n args: [params.delegatorAddress, systemId, systemCalldata],\n };\n\n // Call `writeContract` with the new args.\n return getAction(client, writeContract, \"writeContract\")(callFromArgs);\n },\n });\n}\n\nconst systemFunctionCache = new Map<Hex, SystemFunction>();\n\nasync function worldFunctionToSystemFunction(\n params: CallFromParameters,\n worldFunctionSelector: Hex,\n): Promise<SystemFunction> {\n const cacheKey = concat([params.worldAddress, 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(worldFunctionSelector)\n : await retrieveSystemFunctionFromContract(params.publicClient, params.worldAddress, worldFunctionSelector);\n\n systemFunctionCache.set(cacheKey, systemFunction);\n\n return systemFunction;\n}\n\nasync function retrieveSystemFunctionFromContract(\n publicClient: PublicClient,\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 [staticData, encodedLengths, dynamicData] = await publicClient.readContract({\n address: worldAddress,\n abi: IStoreReadAbi,\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","[\n {\n \"type\": \"function\",\n \"name\": \"getDynamicField\",\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 \"name\": \"dynamicFieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"\",\n \"type\": \"bytes\",\n \"internalType\": \"bytes\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getDynamicFieldLength\",\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 \"name\": \"dynamicFieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"\",\n \"type\": \"uint256\",\n \"internalType\": \"uint256\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getDynamicFieldSlice\",\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 \"name\": \"dynamicFieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n },\n {\n \"name\": \"start\",\n \"type\": \"uint256\",\n \"internalType\": \"uint256\"\n },\n {\n \"name\": \"end\",\n \"type\": \"uint256\",\n \"internalType\": \"uint256\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"data\",\n \"type\": \"bytes\",\n \"internalType\": \"bytes\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getField\",\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 \"name\": \"fieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n },\n {\n \"name\": \"fieldLayout\",\n \"type\": \"bytes32\",\n \"internalType\": \"FieldLayout\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"data\",\n \"type\": \"bytes\",\n \"internalType\": \"bytes\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getField\",\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 \"name\": \"fieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"data\",\n \"type\": \"bytes\",\n \"internalType\": \"bytes\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getFieldLayout\",\n \"inputs\": [\n {\n \"name\": \"tableId\",\n \"type\": \"bytes32\",\n \"internalType\": \"ResourceId\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"fieldLayout\",\n \"type\": \"bytes32\",\n \"internalType\": \"FieldLayout\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getFieldLength\",\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 \"name\": \"fieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n },\n {\n \"name\": \"fieldLayout\",\n \"type\": \"bytes32\",\n \"internalType\": \"FieldLayout\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"\",\n \"type\": \"uint256\",\n \"internalType\": \"uint256\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getFieldLength\",\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 \"name\": \"fieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"\",\n \"type\": \"uint256\",\n \"internalType\": \"uint256\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getKeySchema\",\n \"inputs\": [\n {\n \"name\": \"tableId\",\n \"type\": \"bytes32\",\n \"internalType\": \"ResourceId\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"keySchema\",\n \"type\": \"bytes32\",\n \"internalType\": \"Schema\"\n }\n ],\n \"stateMutability\": \"view\"\n },\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 \"name\": \"fieldLayout\",\n \"type\": \"bytes32\",\n \"internalType\": \"FieldLayout\"\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 \"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 \"type\": \"function\",\n \"name\": \"getStaticField\",\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 \"name\": \"fieldIndex\",\n \"type\": \"uint8\",\n \"internalType\": \"uint8\"\n },\n {\n \"name\": \"fieldLayout\",\n \"type\": \"bytes32\",\n \"internalType\": \"FieldLayout\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"\",\n \"type\": \"bytes32\",\n \"internalType\": \"bytes32\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getValueSchema\",\n \"inputs\": [\n {\n \"name\": \"tableId\",\n \"type\": \"bytes32\",\n \"internalType\": \"ResourceId\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"valueSchema\",\n \"type\": \"bytes32\",\n \"internalType\": \"Schema\"\n }\n ],\n \"stateMutability\": \"view\"\n }\n]","// Follows https://viem.sh/docs/actions/wallet/signTypedData#usage\n\nexport const delegationWithSignatureTypes = {\n Delegation: [\n { name: \"delegatee\", type: \"address\" },\n { name: \"delegationControlId\", type: \"bytes32\" },\n { name: \"initCallData\", type: \"bytes\" },\n { name: \"delegator\", type: \"address\" },\n { name: \"nonce\", type: \"uint256\" },\n ],\n} as const;\n"],"mappings":"iNAAA,OAAiD,sBAAAA,MAAqD,OAY/F,SAASC,EAAkF,CAChG,IAAAC,EACA,SAAAC,EACA,aAAAC,EACA,KAAAC,CACF,EAEE,CACA,MAAO,CACLF,EACAH,EAAsC,CACpC,IAAAE,EACA,aAAAE,EACA,KAAAC,CACF,CAA+D,CACjE,CACF,CC5BA,OAA4C,sBAAAC,MAA8D,OAanG,SAASC,EAAsF,CACpG,IAAAC,EACA,KAAAC,EACA,SAAAC,EACA,aAAAC,EACA,KAAAC,CACF,EAEE,CACA,MAAO,CACLH,EACAC,EACAJ,EAAsC,CACpC,IAAAE,EACA,aAAAG,EACA,KAAAC,CACF,CAA+D,CACjE,CACF,CCzBO,SAASC,EACdC,EACAC,EAC6F,CAC7F,OAAOA,EAAY,IAAKC,GAAeC,EAAiB,CAAE,GAAGD,EAAY,IAAAF,CAAI,CAAkC,CAAC,CAClH,CCLO,SAASI,GACdC,EACAC,EACAC,EACiG,CACjG,OAAOA,EAAY,IAAKC,GACtBC,EAAqB,CAAE,GAAGD,EAAY,IAAAH,EAAK,KAAAC,CAAK,CAAsC,CACxF,CACF,CCdA,OACE,SAAAI,EACA,UAAAC,MAUK,OACP,OAAS,aAAAC,EAAW,sBAAAC,MAA0B,aAC9C,OAAS,iBAAAC,MAAqB,eAC9B,OAAS,WAAAC,MAAe,qBACxB,OACE,gBAAAC,EACA,kBAAAC,EACA,kBAAAC,EACA,mBAAAC,EACA,aAAAC,MACK,uCCtBP,IAAAC,EAAA,CACE,CACE,KAAQ,WACR,KAAQ,kBACR,OAAU,CACR,CACE,KAAQ,UACR,KAAQ,UACR,aAAgB,Y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,EAAY,eAAAC,EAAgB,YAAAC,CAAY,CAAC,EAOxF,MALuC,CACrC,SAAUG,EAAQ,SAClB,uBAAwBA,EAAQ,sBAClC,CAGF,CE/IO,IAAME,GAA+B,CAC1C,WAAY,CACV,CAAE,KAAM,YAAa,KAAM,SAAU,EACrC,CAAE,KAAM,sBAAuB,KAAM,SAAU,EAC/C,CAAE,KAAM,eAAgB,KAAM,OAAQ,EACtC,CAAE,KAAM,YAAa,KAAM,SAAU,EACrC,CAAE,KAAM,QAAS,KAAM,SAAU,CACnC,CACF","names":["encodeFunctionData","encodeSystemCall","abi","systemId","functionName","args","encodeFunctionData","encodeSystemCallFrom","abi","from","systemId","functionName","args","encodeSystemCalls","abi","systemCalls","systemCall","encodeSystemCall","encodeSystemCallsFrom","abi","from","systemCalls","systemCall","encodeSystemCallFrom","slice","concat","getAction","encodeFunctionData","writeContract","readHex","getKeySchema","getValueSchema","getSchemaTypes","decodeValueArgs","encodeKey","IStoreRead_abi_default","callFrom","params","client","writeArgs","getAction","writeContract","worldCalldata","encodeFunctionData","worldFunctionSelector","slice","systemId","systemFunctionSelector","worldFunctionToSystemFunction","systemCalldata","concat","readHex","callFromArgs","systemFunctionCache","cacheKey","cached","systemFunction","retrieveSystemFunctionFromContract","publicClient","worldAddress","table","mud_config_default","keySchema","getSchemaTypes","getKeySchema","valueSchema","getValueSchema","staticData","encodedLengths","dynamicData","IStoreRead_abi_default","encodeKey","decoded","decodeValueArgs","delegationWithSignatureTypes"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/world",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "World framework",
5
5
  "repository": {
6
6
  "type": "git",
@@ -43,11 +43,11 @@
43
43
  "arktype": "1.0.29-alpha",
44
44
  "viem": "2.7.12",
45
45
  "zod": "^3.21.4",
46
- "@latticexyz/common": "2.0.2",
47
- "@latticexyz/config": "2.0.2",
48
- "@latticexyz/protocol-parser": "2.0.2",
49
- "@latticexyz/schema-type": "2.0.2",
50
- "@latticexyz/store": "2.0.2"
46
+ "@latticexyz/common": "2.0.3",
47
+ "@latticexyz/config": "2.0.3",
48
+ "@latticexyz/protocol-parser": "2.0.3",
49
+ "@latticexyz/schema-type": "2.0.3",
50
+ "@latticexyz/store": "2.0.3"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/ejs": "^3.1.1",
@@ -62,8 +62,8 @@
62
62
  "tsup": "^6.7.0",
63
63
  "tsx": "^3.12.6",
64
64
  "vitest": "0.34.6",
65
- "@latticexyz/abi-ts": "2.0.2",
66
- "@latticexyz/gas-report": "2.0.2"
65
+ "@latticexyz/abi-ts": "2.0.3",
66
+ "@latticexyz/gas-report": "2.0.3"
67
67
  },
68
68
  "scripts": {
69
69
  "build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts && pnpm run build:js",
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  slice,
3
3
  concat,
4
- type WalletClient,
5
4
  type Transport,
6
5
  type Chain,
7
6
  type Account,
@@ -10,6 +9,7 @@ import {
10
9
  type WriteContractReturnType,
11
10
  type EncodeFunctionDataParameters,
12
11
  type PublicClient,
12
+ Client,
13
13
  } from "viem";
14
14
  import { getAction, encodeFunctionData } from "viem/utils";
15
15
  import { writeContract } from "viem/actions";
@@ -52,12 +52,17 @@ type SystemFunction = { systemId: Hex; systemFunctionSelector: Hex };
52
52
  // The function mapping is cached to avoid redundant retrievals for the same World function.
53
53
  export function callFrom<TChain extends Chain, TAccount extends Account>(
54
54
  params: CallFromParameters,
55
- ): (client: WalletClient<Transport, TChain, TAccount>) => Pick<WalletActions<TChain, TAccount>, "writeContract"> {
55
+ ): (client: Client<Transport, TChain, TAccount>) => Pick<WalletActions<TChain, TAccount>, "writeContract"> {
56
56
  return (client) => ({
57
57
  // Applies to: `client.writeContract`, `getContract(client, ...).write`
58
58
  writeContract: async (writeArgs): Promise<WriteContractReturnType> => {
59
- // Skip if the contract isn't the World.
60
- if (writeArgs.address !== params.worldAddress) {
59
+ // Skip if the contract isn't the World or the function called should not be redirected through `callFrom`.
60
+ if (
61
+ writeArgs.address !== params.worldAddress ||
62
+ writeArgs.functionName === "call" ||
63
+ writeArgs.functionName === "callFrom" ||
64
+ writeArgs.functionName === "registerDelegationWithSignature"
65
+ ) {
61
66
  return getAction(client, writeContract, "writeContract")(writeArgs);
62
67
  }
63
68