@zerodev/sdk
Version:
A utility library for working with ERC-4337
32 lines • 1.24 kB
JavaScript
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, execType = EXEC_TYPE.DEFAULT) => {
if (calls.length > 1) {
if (callType === "delegatecall") {
throw new Error("Cannot batch delegatecall");
}
// Encode a batched call
return encodeExecuteBatchCall(calls, {
execType
}, 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
}, includeHooks);
}
if (callType === "delegatecall") {
return encodeExecuteDelegateCall({ to: call.to, data: call.data }, {
execType
}, includeHooks);
}
throw new Error("Invalid call type");
};
//# sourceMappingURL=encodeCallData.js.map