From 0cc8ce284c2ebdab01cfdbf9ede6d24e821f9e0f Mon Sep 17 00:00:00 2001 From: Dhvani Patel Date: Wed, 1 May 2024 13:44:43 +0100 Subject: [PATCH] feat: support batch call --- packages/world/ts/actions/callFrom.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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,