UNPKG

@zerodev/sdk

Version:

A utility library for working with ERC-4337

32 lines 1.26 kB
import { EXEC_TYPE } from "../../../../../constants.js"; import { encodeExecuteBatchCall } from "../../ep0_7/encodeExecuteBatchCall.js"; import { encodeExecuteDelegateCall } from "../../ep0_7/encodeExecuteDelegateCall.js"; import { encodeExecuteSingleCall } from "../../ep0_7/encodeExecuteSingleCall.js"; export const encodeCallData = async (calls, callType, includeHooks) => { if (calls.length > 1) { if (callType === "delegatecall") { throw new Error("Cannot batch delegatecall"); } // Encode a batched call return encodeExecuteBatchCall(calls, { execType: EXEC_TYPE.DEFAULT }, includeHooks); } const call = calls.length === 0 ? undefined : calls[0]; if (!call) { throw new Error("No calls to encode"); } // Default to `call` if (!callType || callType === "call") { return encodeExecuteSingleCall(call, { execType: EXEC_TYPE.DEFAULT }, includeHooks); } if (callType === "delegatecall") { return encodeExecuteDelegateCall({ to: call.to, data: call.data }, { execType: EXEC_TYPE.DEFAULT }, includeHooks); } throw new Error("Invalid call type"); }; //# sourceMappingURL=encodeCallData.js.map