Skip to content

Commit

Permalink
feat: support batch call
Browse files Browse the repository at this point in the history
  • Loading branch information
dhvanipa committed May 1, 2024
1 parent c8ca5f6 commit ff373cc
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/world/ts/actions/callFrom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,32 @@ export function callFrom<TChain extends Chain, TAccount extends Account>(
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,
Expand Down

0 comments on commit ff373cc

Please sign in to comment.