UNPKG

@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

235 lines (226 loc) • 8.45 kB
"use strict"; /** * Error Message Templates * * Centralized error messages with AI-friendly tips for common error patterns. * Eliminates duplication and ensures consistent error messaging. * * @see Phase 3.3 of refactoring plan */ Object.defineProperty(exports, "__esModule", { value: true }); exports.errorTemplates = exports.ERROR_TEMPLATES = exports.GENERIC_VALIDATION_ERROR = exports.SOCIAL_URL_ERROR = exports.TRADE_TYPE_ERROR = exports.SLIPPAGE_ERROR = exports.TRADE_TIMEOUT_ERROR = exports.ADDRESS_FORMAT_ERROR = exports.TOKEN_SYMBOL_ERROR = exports.TOKEN_NAME_ERROR = exports.LIMIT_ERRORS = void 0; exports.findErrorTemplate = findErrorTemplate; exports.getErrorTip = getErrorTip; exports.enhanceErrorMessage = enhanceErrorMessage; exports.getErrorCategory = getErrorCategory; // ============================================================================= // Validation Error Templates // ============================================================================= /** * Limit validation errors */ exports.LIMIT_ERRORS = { trade: { pattern: /Limit must be.*20/, tip: `šŸ’” AI TIP: Trade and user operations have a maximum limit of 20. Use: - gala_launchpad_fetch_trades: limit ≤ 20 - gala_launchpad_fetch_tokens_held: limit ≤ 20 - gala_launchpad_fetch_tokens_created: limit ≤ 20 See docs/CONSTRAINTS-REFERENCE.md for details.`, category: 'validation', }, pool: { pattern: /Limit must be.*100/, tip: `šŸ’” AI TIP: Pool operations have a maximum limit of 100. Use: - gala_launchpad_fetch_pools: limit ≤ 100 See docs/CONSTRAINTS-REFERENCE.md for details.`, category: 'validation', }, }; /** * Token name validation errors */ exports.TOKEN_NAME_ERROR = { pattern: /token name.*(invalid|validation)/i, tip: `šŸ’” AI TIP: Token names must match pattern ^[a-z0-9_-]{2,20}$: - Lowercase letters and numbers only - Dashes and underscores allowed - Length: 2-20 characters - Valid examples: 'mytoken', 'test-token', 'token_123' - Invalid: 'MyToken' (uppercase), 'a' (too short), 'my token' (space)`, category: 'validation', }; /** * Token symbol validation errors */ exports.TOKEN_SYMBOL_ERROR = { pattern: /token symbol.*(invalid|validation)/i, tip: `šŸ’” AI TIP: Token symbols must match pattern ^[A-Z0-9]{2,10}$: - Uppercase letters and numbers only - No special characters - Length: 2-10 characters - Valid examples: 'MTK', 'TEST123', 'ABC' - Invalid: 'mtk' (lowercase), 'A' (too short), 'MY-TOKEN' (dash)`, category: 'validation', }; /** * Wallet address format errors */ exports.ADDRESS_FORMAT_ERROR = { pattern: /address.*(format|validation)/i, tip: `šŸ’” AI TIP: Wallet addresses must use format: - Backend API: 'eth|{40-hex-chars}' (e.g., 'eth|abc123...') - Convert from standard: address.startsWith('0x') ? \`eth|\${address.slice(2)}\` : address - Most MCP tools expect 'eth|...' format`, category: 'format', }; // ============================================================================= // Trading Error Templates // ============================================================================= /** * WebSocket/trade timeout errors */ exports.TRADE_TIMEOUT_ERROR = { pattern: /(timeout|WebSocket)/i, tip: `šŸ’” AI TIP: Trade execution timeouts often indicate incorrect expectedAmount parameter. āœ… CORRECT WORKFLOW: 1. Call calculate_buy_amount() or calculate_sell_amount() 2. Extract result.amount from response (e.g., "16843.7579794843252") 3. Use result.amount as expectedAmount in buy() or sell() āŒ WRONG: Using your input amount as expectedAmount āœ… RIGHT: Using calculated result.amount as expectedAmount See docs/AI-AGENT-PATTERNS.md section "Gotcha #1" for examples.`, category: 'timeout', }; /** * Slippage/amount errors */ exports.SLIPPAGE_ERROR = { pattern: /(slippage|amount.*expected)/i, tip: `šŸ’” AI TIP: expectedAmount must be the calculated output from calculate functions, NOT your input amount. Example: const calc = await calculateBuyAmount({ amount: '10', type: 'native', ... }); // calc.amount = "16843.7579794843252" <- Use THIS as expectedAmount await buy({ amount: '10', expectedAmount: calc.amount, ... }); See docs/AI-AGENT-PATTERNS.md for complete trading workflow.`, category: 'business-logic', }; /** * Type parameter confusion */ exports.TRADE_TYPE_ERROR = { pattern: /type.*(native|token)/i, tip: `šŸ’” AI TIP: Trading type parameter: - 'native': You specify GALA amount (most common) Example: "I want to spend 10 GALA" → type: 'native', amount: '10' - 'exact': You specify exact token amount Example: "I want to buy exactly 1000 tokens" → type: 'exact', amount: '1000' See docs/AI-AGENT-PATTERNS.md section "Gotcha #3" for details.`, category: 'validation', }; // ============================================================================= // Token Creation Error Templates // ============================================================================= /** * Social URL requirement errors */ exports.SOCIAL_URL_ERROR = { pattern: /(social|URL.*required)/i, tip: `šŸ’” AI TIP: Token launch requires at least ONE social URL: - websiteUrl (e.g., 'https://mytoken.com') - twitterUrl (e.g., 'https://twitter.com/mytoken') - telegramUrl (e.g., 'https://t.me/mytoken') Provide at least one in launchToken() call.`, category: 'validation', }; // ============================================================================= // Generic Error Templates // ============================================================================= /** * Generic validation error */ exports.GENERIC_VALIDATION_ERROR = { pattern: /(validation|invalid)/i, tip: `šŸ’” AI TIP: Check parameter formats in docs/AI-AGENT-PATTERNS.md Common validation rules: - tokenName: ^[a-z0-9_-]{2,20}$ (lowercase, 2-20 chars) - tokenSymbol: ^[A-Z0-9]{2,10}$ (uppercase, 2-10 chars) - address: 'eth|...' or '0x...' format (auto-normalized) - amount: ^[0-9.]+$ (decimal string) - limits: See CONSTRAINTS-REFERENCE.md`, category: 'validation', }; // ============================================================================= // Error Template Registry // ============================================================================= /** * All error templates in priority order (checked sequentially) */ exports.ERROR_TEMPLATES = [ // Specific errors first (higher priority) exports.LIMIT_ERRORS.trade, exports.LIMIT_ERRORS.pool, exports.TOKEN_NAME_ERROR, exports.TOKEN_SYMBOL_ERROR, exports.ADDRESS_FORMAT_ERROR, exports.TRADE_TIMEOUT_ERROR, exports.SLIPPAGE_ERROR, exports.TRADE_TYPE_ERROR, exports.SOCIAL_URL_ERROR, // Generic errors last (lower priority) exports.GENERIC_VALIDATION_ERROR, ]; // ============================================================================= // Template Matching Functions // ============================================================================= /** * Finds the best matching error template for a message */ function findErrorTemplate(message) { for (const template of exports.ERROR_TEMPLATES) { const pattern = template.pattern; if (typeof pattern === 'string') { if (message.includes(pattern)) { return template; } } else if (pattern instanceof RegExp) { if (pattern.test(message)) { return template; } } } return null; } /** * Gets the AI-friendly tip for an error message */ function getErrorTip(message) { const template = findErrorTemplate(message); return template ? template.tip : null; } /** * Applies AI-friendly tip to error message */ function enhanceErrorMessage(message) { const tip = getErrorTip(message); return tip ? `${message}\n\n${tip}` : message; } /** * Gets error category for an error message */ function getErrorCategory(message) { const template = findErrorTemplate(message); return template ? template.category : 'unknown'; } // ============================================================================= // Export All // ============================================================================= exports.errorTemplates = { templates: exports.ERROR_TEMPLATES, findTemplate: findErrorTemplate, getTip: getErrorTip, enhance: enhanceErrorMessage, getCategory: getErrorCategory, }; //# sourceMappingURL=error-templates.js.map