{"version":3,"file":"transformer-0vQSxsqD-92GTAInQ.cjs","names":["formatMethodName","formatInputName"],"sources":["../../adapter-evm-core/dist/transformer-0vQSxsqD.mjs"],"sourcesContent":["import { i as formatMethodName, r as formatInputName } from \"./utils-C2QdbtNI.mjs\";\nimport { logger } from \"@openzeppelin/ui-utils\";\n\n//#region src/abi/transformer.ts\n/**\n* Transforms a standard ABI array (typically from an EVM-compatible chain)\n* into the project's internal `ContractSchema` format.\n* This schema is used by the builder app and renderer to represent contract interactions\n* in a chain-agnostic way (though this specific transformer is for EVM ABIs).\n*\n* @param abi The raw ABI array (e.g., parsed from a JSON ABI file or fetched from Etherscan).\n*            It's expected to be an array of `AbiItem` (from viem types or a compatible structure).\n* @param contractName A name to assign to the contract within the schema. This might be derived\n*                     from a file name, user input, or a default if not otherwise available.\n* @param address Optional address of the deployed contract. If provided, it's included in the schema.\n* @returns A `ContractSchema` object representing the contract's interface.\n*/\nfunction transformAbiToSchema(abi, contractName, address) {\n\tlogger.info(\"transformAbiToSchema\", `Transforming ABI to ContractSchema for: ${contractName}`);\n\tconst functions = [];\n\tfor (const item of abi) if (item.type === \"function\") {\n\t\tconst abiFunctionItem = item;\n\t\tfunctions.push({\n\t\t\tid: `${abiFunctionItem.name}_${abiFunctionItem.inputs?.map((i) => i.type).join(\"_\") || \"\"}`,\n\t\t\tname: abiFunctionItem.name || \"\",\n\t\t\tdisplayName: formatMethodName(abiFunctionItem.name || \"\"),\n\t\t\tinputs: mapAbiParametersToSchemaParameters(abiFunctionItem.inputs),\n\t\t\toutputs: mapAbiParametersToSchemaParameters(abiFunctionItem.outputs),\n\t\t\ttype: \"function\",\n\t\t\tstateMutability: abiFunctionItem.stateMutability,\n\t\t\tmodifiesState: !abiFunctionItem.stateMutability || ![\"view\", \"pure\"].includes(abiFunctionItem.stateMutability)\n\t\t});\n\t}\n\tconst contractSchema = {\n\t\tecosystem: \"evm\",\n\t\tname: contractName,\n\t\taddress,\n\t\tfunctions\n\t};\n\tlogger.info(\"transformAbiToSchema\", `Transformation complete. Found ${contractSchema.functions.length} functions.`);\n\treturn contractSchema;\n}\n/**\n* Recursively maps an array of ABI parameters (from viem's `AbiParameter` type or compatible)\n* to an array of `FunctionParameter` objects, which is our internal representation.\n* This function is crucial for stripping any properties not defined in `FunctionParameter`\n* (e.g., `internalType` from the raw ABI) and for handling nested components (structs/tuples).\n*\n* @param abiParams An array of ABI parameter objects. Can be undefined (e.g., if a function has no inputs/outputs).\n* @returns An array of `FunctionParameter` objects, or an empty array if `abiParams` is undefined.\n*/\nfunction mapAbiParametersToSchemaParameters(abiParams) {\n\tif (!abiParams) return [];\n\treturn abiParams.map((param) => {\n\t\tconst schemaParam = {\n\t\t\tname: param.name || \"\",\n\t\t\ttype: param.type,\n\t\t\tdisplayName: formatInputName(param.name || \"\", param.type)\n\t\t};\n\t\tif (param.type.startsWith(\"tuple\") && \"components\" in param && param.components && param.components.length > 0) schemaParam.components = mapAbiParametersToSchemaParameters(param.components);\n\t\treturn schemaParam;\n\t});\n}\n/**\n* Helper function to convert one of our internal `FunctionParameter` objects\n* back into a format compatible with viem's `AbiParameter` type.\n* This is primarily used by `createAbiFunctionItem` when constructing an `AbiFunction`\n* for interactions with viem or other ABI-consuming libraries.\n* It ensures that only properties expected by `AbiParameter` are included.\n*\n* @param param The internal `FunctionParameter` object.\n* @returns An `AbiParameter` object compatible with viem.\n*/\nfunction mapSchemaParameterToAbiParameter(param) {\n\tif (param.type.startsWith(\"tuple\") && param.components && param.components.length > 0) return {\n\t\tname: param.name || void 0,\n\t\ttype: param.type,\n\t\tcomponents: param.components.map(mapSchemaParameterToAbiParameter)\n\t};\n\treturn {\n\t\tname: param.name || void 0,\n\t\ttype: param.type\n\t};\n}\n/**\n* Private helper to convert internal `ContractFunction` details (our model)\n* back into a viem `AbiFunction` object.\n* This is useful when interacting with libraries like viem that expect a standard ABI format.\n* Ensures that the generated AbiFunction conforms to viem's type definitions.\n*\n* @param functionDetails The `ContractFunction` object from our internal schema.\n* @returns An `AbiFunction` object.\n*/\nfunction createAbiFunctionItem(functionDetails) {\n\treturn {\n\t\tname: functionDetails.name,\n\t\ttype: \"function\",\n\t\tinputs: functionDetails.inputs.map(mapSchemaParameterToAbiParameter),\n\t\toutputs: functionDetails.outputs?.map(mapSchemaParameterToAbiParameter) || [],\n\t\tstateMutability: functionDetails.stateMutability ?? \"view\"\n\t};\n}\n\n//#endregion\nexport { transformAbiToSchema as n, createAbiFunctionItem as t };\n//# sourceMappingURL=transformer-0vQSxsqD.mjs.map"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,SAAS,qBAAqB,KAAK,cAAc,SAAS;AACzD,+BAAO,KAAK,wBAAwB,2CAA2C,eAAe;CAC9F,MAAM,YAAY,EAAE;AACpB,MAAK,MAAM,QAAQ,IAAK,KAAI,KAAK,SAAS,YAAY;EACrD,MAAM,kBAAkB;AACxB,YAAU,KAAK;GACd,IAAI,GAAG,gBAAgB,KAAK,GAAG,gBAAgB,QAAQ,KAAK,MAAM,EAAE,KAAK,CAAC,KAAK,IAAI,IAAI;GACvF,MAAM,gBAAgB,QAAQ;GAC9B,aAAaA,wCAAiB,gBAAgB,QAAQ,GAAG;GACzD,QAAQ,mCAAmC,gBAAgB,OAAO;GAClE,SAAS,mCAAmC,gBAAgB,QAAQ;GACpE,MAAM;GACN,iBAAiB,gBAAgB;GACjC,eAAe,CAAC,gBAAgB,mBAAmB,CAAC,CAAC,QAAQ,OAAO,CAAC,SAAS,gBAAgB,gBAAgB;GAC9G,CAAC;;CAEH,MAAM,iBAAiB;EACtB,WAAW;EACX,MAAM;EACN;EACA;EACA;AACD,+BAAO,KAAK,wBAAwB,kCAAkC,eAAe,UAAU,OAAO,aAAa;AACnH,QAAO;;;;;;;;;;;AAWR,SAAS,mCAAmC,WAAW;AACtD,KAAI,CAAC,UAAW,QAAO,EAAE;AACzB,QAAO,UAAU,KAAK,UAAU;EAC/B,MAAM,cAAc;GACnB,MAAM,MAAM,QAAQ;GACpB,MAAM,MAAM;G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