diff --git a/packages/world/ts/actions/callFrom.ts b/packages/world/ts/actions/callFrom.ts index 3659c4ca85..c4b266d6e5 100644 --- a/packages/world/ts/actions/callFrom.ts +++ b/packages/world/ts/actions/callFrom.ts @@ -63,11 +63,32 @@ export function callFrom( writeArgs.address !== params.worldAddress || writeArgs.functionName === "call" || writeArgs.functionName === "callFrom" || + writeArgs.functionName === "batchCallFrom" || writeArgs.functionName === "callWithSignature" ) { return getAction(client, writeContract, "writeContract")(writeArgs); } + if (writeArgs.functionName === "batchCall") { + if (!writeArgs.args || !Array.isArray(writeArgs.args) || writeArgs.args.length === 0) { + throw new Error("batchCall args should be an array with at least one element"); + } + + const systemCallFromData = writeArgs.args[0].map((systemCallData: Hex[]) => { + return [params.delegatorAddress, ...systemCallData]; + }); + + // Construct args for `batchCallFrom`. + const batchCallFromArgs: typeof writeArgs = { + ...writeArgs, + functionName: "batchCallFrom", + args: [systemCallFromData], + }; + + // Call `writeContract` with the new args. + return getAction(client, writeContract, "writeContract")(batchCallFromArgs); + } + // Encode the World's calldata (which includes the World's function selector). const worldCalldata = encodeFunctionData({ abi: writeArgs.abi,