UniversalDeFi AI
Official
by McpCrypto
import { z } from "zod";
// Ethereum address validation
const ethAddressSchema = z
.string()
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address");
// Hexadecimal string validation (for compiled bytecode, bytes32, etc.)
const hexStringSchema = z
.string()
.regex(/^0x[a-fA-F0-9]+$/, "Invalid hex string");
// Unsigned integer (uint256), supports both BigInt and numeric strings
const uint256Schema = z.union([
z.string().regex(/^\d+$/, "Must be a numeric string"),
z.bigint()
]);
// General Ethereum contract argument schema (supports lists and nested arrays)
const contractArgSchema: z.ZodType<any> = z.lazy(() =>
z.union([
ethAddressSchema,
uint256Schema,
hexStringSchema,
z.string(), // Normal string
z.boolean(), // Boolean
z.array(contractArgSchema) // Support nested arrays
])
);
// Schema for deploying a contract
export const DeployContractSchema = z
.object({
sourceCode: z.string().describe("Solidity source code of the contract"),
contractName: z.string().describe("Name of the contract to deploy"),
constructorArgs: z.array(contractArgSchema)
.optional()
.describe("Constructor arguments for the contract"),
})
.strip()
.describe("Schema for deploying an Ethereum contract");
export const GetWalletDetailsSchema = z
.object({
})
.strip()
.describe("Get the details of the pre-configured wallet including the chain, address, and balance");
export const TransferNativeTokenSchema = z
.object({
toAddress: z.string().describe("Address to transfer the native token to"),
amount: z.string().describe("Amount of native token to transfer"),
})
.strip()
.describe("Transfer a native token to a specified address");
export const Erc20BalanceSchema = z
.object({
contractAddress: z.string().describe("Address of the ERC20 contract"),
})
.strip()
.describe("Get the balance of an ERC20 token for the pre-configured wallet");
export const Erc20TransferSchema = z
.object({
contractAddress: z.string().describe("Address of the ERC20 contract"),
toAddress: z.string().describe("Address to transfer the ERC20 token to"),
amount: z.string().describe("Amount of ERC20 token to transfer"),
})
.strip()
.describe("Transfer an ERC20 token to a specified address");
export const CallContractSchema = z
.object({
contractAddress: z.string().describe("Address of the contract to call"),
functionName: z.string().describe("Name of the function to call"),
abi: z.string().describe("ABI of the contract"),
args: z.array(contractArgSchema).describe("Arguments for the function"),
})
.strip()
.describe("Call a function on a contract");