@gala-chain/launchpad-mcp-server
Version:
MCP server for Gala Launchpad - 102 tools (pool management, event watchers, GSwap DEX trading, price history, token creation, wallet management, DEX pool discovery, liquidity positions, token locks, locked token queries, composite pool data, cross-chain b
218 lines • 7.43 kB
TypeScript
/**
* Validation Utilities for MCP Prompts
*
* Input validation functions for slash command arguments.
* Prevents malformed inputs and provides clear error messages.
*/
/**
* Validation error class for better error handling
*/
export declare class ValidationError extends Error {
field: string;
constructor(field: string, message: string);
}
/**
* Validate token name format
*
* Token names must be 2-20 characters, alphanumeric with hyphens and underscores.
*
* @param name - Token name to validate
* @param fieldName - Field name for error messages (default: 'tokenName')
* @throws {ValidationError} If token name is invalid
*
* @example
* ```typescript
* validateTokenName('anime'); // ✅ Valid
* validateTokenName('test-123'); // ✅ Valid
* validateTokenName('my_token'); // ✅ Valid
* validateTokenName('a'); // ❌ Throws: too short
* validateTokenName('token@#$'); // ❌ Throws: invalid characters
* ```
*/
export declare function validateTokenName(name: string, fieldName?: string): void;
/**
* Validate numeric amount
*
* Amounts must be positive numbers (integers or decimals).
*
* @param amount - Amount to validate (string or number)
* @param fieldName - Field name for error messages
* @throws {ValidationError} If amount is invalid
*
* @example
* ```typescript
* validateNumericAmount('100', 'galaAmount'); // ✅ Valid
* validateNumericAmount('99.5', 'tokenAmount'); // ✅ Valid
* validateNumericAmount('-5', 'amount'); // ❌ Throws: negative
* validateNumericAmount('abc', 'amount'); // ❌ Throws: not a number
* ```
*/
export declare function validateNumericAmount(amount: string | number, fieldName: string): void;
/**
* Validate slippage tolerance percentage
*
* Slippage must be between 0.01% and 100%.
*
* @param slippage - Slippage percentage to validate
* @param fieldName - Field name for error messages (default: 'slippage')
* @throws {ValidationError} If slippage is invalid
*
* @example
* ```typescript
* validateSlippage('1'); // ✅ Valid (1%)
* validateSlippage('0.5'); // ✅ Valid (0.5%)
* validateSlippage('50'); // ✅ Valid (50%)
* validateSlippage('0'); // ❌ Throws: too low
* validateSlippage('150'); // ❌ Throws: too high
* ```
*/
export declare function validateSlippage(slippage: string | number, fieldName?: string): void;
/**
* Validate wallet address format
*
* Supports both GalaChain format (eth|0x...) and standard Ethereum format (0x...).
*
* @param address - Wallet address to validate
* @param fieldName - Field name for error messages (default: 'address')
* @throws {ValidationError} If address is invalid
*
* @example
* ```typescript
* validateAddress('eth|0x1234567890abcdef1234567890abcdef12345678'); // ✅ Valid
* validateAddress('0x1234567890abcdef1234567890abcdef12345678'); // ✅ Valid
* validateAddress('invalid'); // ❌ Throws: invalid format
* ```
*/
export declare function validateAddress(address: string, fieldName?: string): void;
/**
* Validate token symbol format
*
* Symbols must be 1-8 uppercase letters.
*
* @param symbol - Token symbol to validate
* @param fieldName - Field name for error messages (default: 'symbol')
* @throws {ValidationError} If symbol is invalid
*
* @example
* ```typescript
* validateTokenSymbol('GALA'); // ✅ Valid
* validateTokenSymbol('TEST'); // ✅ Valid
* validateTokenSymbol('test'); // ❌ Throws: must be uppercase
* validateTokenSymbol('TOOLONG123'); // ❌ Throws: too long
* ```
*/
export declare function validateTokenSymbol(symbol: string, fieldName?: string): void;
/**
* Validate pagination limit
*
* Limits must be positive integers within reasonable range (1-100).
*
* @param limit - Pagination limit to validate
* @param max - Maximum allowed limit (default: 100)
* @param fieldName - Field name for error messages (default: 'limit')
* @throws {ValidationError} If limit is invalid
*
* @example
* ```typescript
* validatePaginationLimit('20'); // ✅ Valid
* validatePaginationLimit('1'); // ✅ Valid
* validatePaginationLimit('0'); // ❌ Throws: too low
* validatePaginationLimit('150'); // ❌ Throws: too high
* ```
*/
export declare function validatePaginationLimit(limit: string | number, max?: number, fieldName?: string): void;
/**
* Validate comma-separated token list
*
* For batch operations that accept multiple token names.
*
* @param tokens - Comma-separated token names
* @param fieldName - Field name for error messages (default: 'tokens')
* @throws {ValidationError} If token list is invalid
*
* @example
* ```typescript
* validateTokenList('anime,test,dragon'); // ✅ Valid
* validateTokenList('token1'); // ✅ Valid (single token)
* validateTokenList(''); // ❌ Throws: empty list
* validateTokenList('token1,invalid@#$'); // ❌ Throws: invalid token name
* ```
*/
export declare function validateTokenList(tokens: string, fieldName?: string): string[];
/**
* Validate URL format
*
* URLs must be well-formed HTTP/HTTPS URLs.
*
* @param url - URL to validate
* @param fieldName - Field name for error messages (default: 'url')
* @throws {ValidationError} If URL is invalid
*
* @example
* ```typescript
* validateUrl('https://example.com'); // ✅ Valid
* validateUrl('https://twitter.com/user'); // ✅ Valid
* validateUrl('http://localhost:3000'); // ✅ Valid
* validateUrl('not-a-url'); // ❌ Throws: invalid format
* ```
*/
export declare function validateUrl(url: string, fieldName?: string): void;
/**
* Safe validation wrapper that doesn't throw
*
* Useful for non-critical validation where you want to continue with a warning.
*
* @param validationFn - Validation function to execute
* @returns Object with success flag and optional error
*
* @example
* ```typescript
* const result = safeValidate(() => validateTokenName('anime'));
* if (!result.success) {
* console.warn('Validation warning:', result.error);
* }
* ```
*/
export declare function safeValidate(validationFn: () => void): {
success: boolean;
error?: string;
};
/**
* Validate optional field if present
*
* Convenience wrapper for validating optional fields. Only runs validation
* if the value is defined and not null.
*
* @param value - Value to validate (can be undefined)
* @param validator - Validation function to run if value is present
* @throws {ValidationError} If validation fails
*
* @example
* ```typescript
* validateOptional(args.slippage, (val) => validateSlippage(val));
* ```
*/
export declare function validateOptional<T>(value: T | undefined | null, validator: (val: T) => void): void;
/**
* Validate optional slippage field
*
* @param slippage - Slippage value to validate (optional)
* @throws {ValidationError} If slippage is invalid
*/
export declare function validateOptionalSlippage(slippage?: string | number): void;
/**
* Validate optional pagination limit field
*
* @param limit - Limit value to validate (optional)
* @param max - Maximum allowed limit (default: 100)
* @throws {ValidationError} If limit is invalid
*/
export declare function validateOptionalLimit(limit?: string | number, max?: number): void;
/**
* Validate optional address field
*
* @param address - Address value to validate (optional)
* @throws {ValidationError} If address is invalid
*/
export declare function validateOptionalAddress(address?: string): void;
//# sourceMappingURL=validation.d.ts.map