From c404a965beaa5ecaf7a6f713c5c42b09182743b1 Mon Sep 17 00:00:00 2001 From: derekpierre Date: Fri, 11 Oct 2024 13:03:23 -0400 Subject: [PATCH] Initial code to allow human readable function abi. --- .../taco/src/conditions/schemas/contract.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/taco/src/conditions/schemas/contract.ts b/packages/taco/src/conditions/schemas/contract.ts index 59e1f831..6f0c9ac1 100644 --- a/packages/taco/src/conditions/schemas/contract.ts +++ b/packages/taco/src/conditions/schemas/contract.ts @@ -5,6 +5,7 @@ import { AbiParameter } from 'abitype/zod'; import { paramOrContextParamSchema } from './context'; import { rpcConditionSchema } from './rpc'; +import { parseAbi, parseAbiItem } from 'abitype'; const functionAbiSchema = z .object({ @@ -49,6 +50,23 @@ const functionAbiSchema = z export type FunctionAbiProps = z.infer; +export const humanReadableAbiSchema = z + .string().startsWith("function ") + .refine( + (abi) => { + try { + parseAbiItem(abi); + return true; + } catch (e) { + return false; + } + }, + { + message: 'Invalid Human-Readable ABI format', + }, + ) + .transform(parseAbiItem); + export const ContractConditionType = 'contract'; export const contractConditionSchema = rpcConditionSchema .extend({