import { Interface } from "ethers"; import { EnhancedClause } from "./hooks"; // Define a type to infer method names from the function definition type MethodName = T extends (nameOrSignature: infer U) => any ? U : never; /** * Parameters for building a clause. */ export type BuildClauseParams = { contractInterface: T; // The contract interface method: MethodName; // The method name args?: unknown[]; // Optional arguments for the method value?: number; // The value to be sent with the transaction } & Omit; /** * Builds a clause for sending a transaction. * @param contractInterface The contract interface. * @param method The method name. * @param args Optional arguments for the method. * @param value The value to be sent with the transaction. * @returns The built clause. */ export const buildClause = ({ value = 0, contractInterface, args = [], method, ...others }: BuildClauseParams): EnhancedClause => { return { value, data: contractInterface.encodeFunctionData(method, args), abi: JSON.parse(JSON.stringify(contractInterface.getFunction(method))), ...others, }; };