diff --git a/packages/world/ts/encodeSystemCall.ts b/packages/world/ts/encodeSystemCall.ts index 4c6a475d80..25841dfad8 100644 --- a/packages/world/ts/encodeSystemCall.ts +++ b/packages/world/ts/encodeSystemCall.ts @@ -4,19 +4,21 @@ import { worldCallAbi } from "./worldCallAbi"; import { internal_normalizeSystemFunctionName } from "./normalizeSystemFunctionName"; export type SystemCall> = { - /** - * System ABI - */ - readonly abi: abi; - /** - * System's resource ID - */ - readonly systemId: Hex; - /** - * System function name to call - */ - readonly functionName: functionName; -} & Pick, "args">; + [k in ContractFunctionName]: { + /** + * System's resource ID + */ + readonly systemId: Hex; + /** + * System ABI + */ + readonly abi: abi; + /** + * System function name to call + */ + readonly functionName: k; + } & Pick, "args">; +}[functionName]; /** Encode a system call to be passed as arguments into `World.call` */ export function encodeSystemCall>({ diff --git a/packages/world/ts/encodeSystemCalls.ts b/packages/world/ts/encodeSystemCalls.ts index 9e23f69aae..845c61366f 100644 --- a/packages/world/ts/encodeSystemCalls.ts +++ b/packages/world/ts/encodeSystemCalls.ts @@ -1,21 +1,25 @@ -import { Abi, EncodeFunctionDataParameters, encodeFunctionData, type ContractFunctionName } from "viem"; +import { Abi, encodeFunctionData, type ContractFunctionName } from "viem"; import { SystemCall } from "./encodeSystemCall"; import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype"; import { worldCallAbi } from "./worldCallAbi"; import { internal_normalizeSystemFunctionName } from "./normalizeSystemFunctionName"; +export type SystemCalls = { + [k in keyof abis]: SystemCall>; +}; + /** Encode system calls to be passed as arguments into `World.batchCall` */ -export function encodeSystemCalls>( - systemCalls: readonly SystemCall[], +export function encodeSystemCalls( + systemCalls: SystemCalls, ): AbiParametersToPrimitiveTypes["inputs"]> { return [ systemCalls.map(({ abi, systemId, functionName, args }) => ({ systemId, - callData: encodeFunctionData({ + callData: encodeFunctionData({ abi, functionName: internal_normalizeSystemFunctionName(systemId, functionName), args, - } as EncodeFunctionDataParameters), + }), })), ]; } diff --git a/packages/world/ts/encodeSystemCallsFrom.ts b/packages/world/ts/encodeSystemCallsFrom.ts index 2465e709f4..e220cf258d 100644 --- a/packages/world/ts/encodeSystemCallsFrom.ts +++ b/packages/world/ts/encodeSystemCallsFrom.ts @@ -1,23 +1,23 @@ -import { Abi, Address, EncodeFunctionDataParameters, encodeFunctionData, type ContractFunctionName } from "viem"; -import { SystemCallFrom } from "./encodeSystemCallFrom"; +import { Abi, Address, encodeFunctionData } from "viem"; import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype"; import { worldCallAbi } from "./worldCallAbi"; import { internal_normalizeSystemFunctionName } from "./normalizeSystemFunctionName"; +import { SystemCalls } from "./encodeSystemCalls"; /** Encode system calls to be passed as arguments into `World.batchCallFrom` */ -export function encodeSystemCallsFrom>( +export function encodeSystemCallsFrom( from: Address, - systemCalls: readonly Omit, "from">[], + systemCalls: SystemCalls, ): AbiParametersToPrimitiveTypes["inputs"]> { return [ systemCalls.map(({ abi, systemId, functionName, args }) => ({ from, systemId, - callData: encodeFunctionData({ + callData: encodeFunctionData({ abi, functionName: internal_normalizeSystemFunctionName(systemId, functionName), args, - } as EncodeFunctionDataParameters), + }), })), ]; }