UNPKG

tensaikit

Version:

An autonomous DeFi AI Agent Kit on Katana enabling AI agents to plan and execute on-chain financial operations.

29 lines (28 loc) 1.27 kB
"use strict"; /** * Common validation utilities */ Object.defineProperty(exports, "__esModule", { value: true }); exports.validateChainId = exports.validateAmount = exports.validateAddress = void 0; const errorTypes_1 = require("../errors/errorTypes"); const customErrorHandler_1 = require("../errors/customErrorHandler"); const validateAddress = (address) => { if (!address || !address.startsWith("0x") || address.length !== 42) { throw (0, customErrorHandler_1.createError)("Invalid Ethereum address", errorTypes_1.ErrorCode.INVALID_INPUT); } }; exports.validateAddress = validateAddress; const validateAmount = (amount) => { const numAmount = typeof amount === "string" ? parseFloat(amount) : amount; if (isNaN(numAmount) || numAmount <= 0) { throw (0, customErrorHandler_1.createError)("Invalid amount", errorTypes_1.ErrorCode.INVALID_INPUT); } }; exports.validateAmount = validateAmount; const validateChainId = (chainId) => { const numChainId = typeof chainId === "string" ? parseInt(chainId, 10) : chainId; if (isNaN(numChainId) || numChainId <= 0) { throw (0, customErrorHandler_1.createError)("Invalid chain ID", errorTypes_1.ErrorCode.INVALID_NETWORK); } }; exports.validateChainId = validateChainId;