Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not confident in the shape of this data. I think this works when it comes from our encodeSystemCalls but doesn't seem to exactly correspond to the shape of WriteContractParameters<typeof IBaseWorldAbi, "batchCall">

(property) args: readonly [readonly {
    systemId: `0x${string}`;
    callData: `0x${string}`;
}[]] | ([readonly {
    systemId: `0x${string}`;
    callData: `0x${string}`;
}[]] & readonly [readonly {
    systemId: `0x${string}`;
    callData: `0x${string}`;
}[]])

But if I inspect the broader WriteContractParameters<typeof IBaseWorldAbi> and do an if statement, the expected args type is a bit wider and includes the array of hex values.

Not really sure how best to approach this, but might mean we need more tests here.


// 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