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

578 lines (537 loc) 24.9 kB
"use strict"; /** * Trading Operations Tools */ Object.defineProperty(exports, "__esModule", { value: true }); exports.tradingTools = exports.calculateSellAmountExternalTool = exports.calculateSellAmountLocalTool = exports.calculateBuyAmountExternalTool = exports.calculateBuyAmountLocalTool = exports.graduateTokenTool = exports.calculateBuyAmountForGraduationTool = exports.getBundlerTransactionResultTool = exports.calculateInitialBuyTool = exports.fetchTradesTool = exports.sellTokensTool = exports.buyTokensTool = exports.calculateSellAmountTool = exports.calculateBuyAmountTool = void 0; const launchpad_sdk_1 = require("@gala-chain/launchpad-sdk"); const response_formatter_js_1 = require("../../utils/response-formatter.js"); const error_handler_js_1 = require("../../utils/error-handler.js"); const common_schemas_js_1 = require("../../schemas/common-schemas.js"); const default_values_js_1 = require("../../utils/default-values.js"); // 1. Calculate Buy Amount exports.calculateBuyAmountTool = { name: 'gala_launchpad_calculate_buy_amount', description: 'Calculate token amounts for buying with fee breakdown', inputSchema: { type: 'object', properties: { tokenName: common_schemas_js_1.TOKEN_NAME_SCHEMA, amount: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: 'Amount in standard decimal format (e.g., "1" for 1 GALA)', }, type: { type: 'string', enum: Object.values(launchpad_sdk_1.TRADING_TYPES), description: `Trade calculation type: - 'native': You specify GALA amount to spend Example: "I want to spend 10 GALA to buy tokens" type: 'native', amount: '10' - 'exact': You specify exact token amount to buy Example: "I want to buy exactly 1000 WOO tokens" type: 'exact', amount: '1000' Most common: Use 'native' when you know how much GALA to spend`, }, }, required: ['tokenName', 'amount', 'type'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.calculateBuyAmount({ tokenName: args.tokenName, amount: args.amount, type: args.type, }); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 2. Calculate Sell Amount exports.calculateSellAmountTool = { name: 'gala_launchpad_calculate_sell_amount', description: 'Calculate GALA amounts for selling tokens', inputSchema: { type: 'object', properties: { tokenName: common_schemas_js_1.TOKEN_NAME_SCHEMA, amount: common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, type: { type: 'string', enum: Object.values(launchpad_sdk_1.TRADING_TYPES), description: `Trade calculation type: - 'native': You specify GALA amount you want to receive Example: "I want to receive 10 GALA from selling tokens" type: 'native', amount: '10' - 'exact': You specify exact token amount to sell Example: "I want to sell exactly 1000 WOO tokens" type: 'exact', amount: '1000' Most common: Use 'native' when you know how much GALA you want to receive`, }, }, required: ['tokenName', 'amount', 'type'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.calculateSellAmount({ tokenName: args.tokenName, amount: args.amount, type: args.type, }); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 3. Buy Tokens exports.buyTokensTool = { name: 'gala_launchpad_buy_tokens', description: `Execute token purchase with slippage protection. WORKFLOW: 1. calculateBuyAmount() Get expected output (result.amount AND result.reverseBondingCurveFee) 2. buy() Execute trade with BOTH expectedAmount AND maxAcceptableReverseBondingCurveFee 3. fetchTrades() Verify trade completed CRITICAL: Extract BOTH parameters from calculateBuyAmount: - result.amount expectedAmount - result.reverseBondingCurveFee maxAcceptableReverseBondingCurveFee Omitting reverseBondingCurveFee may cause transaction failures! RETURNS: Transaction details including input/output amounts and transaction ID`, inputSchema: { type: 'object', properties: { tokenName: common_schemas_js_1.TOKEN_NAME_SCHEMA, amount: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: 'Amount to spend/buy', }, type: { type: 'string', enum: Object.values(launchpad_sdk_1.TRADING_TYPES), description: `Trade type (must match what you used in calculateBuyAmount): - 'native': Spending GALA amount - 'exact': Buying exact token amount`, }, expectedAmount: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: `Expected token output amount from calculateBuyAmount (REQUIRED). CRITICAL: This is the 'amount' field from calculateBuyAmount result, NOT your input amount. WORKFLOW: 1. Call calculateBuyAmount({ tokenName, amount, type }) 2. Extract result.amount from the response 3. Use result.amount as this expectedAmount parameter EXAMPLE: const calc = await calculateBuyAmount({ tokenName: 'woohoo', amount: '10', type: 'native' }); // calc.amount = "16843.7579794843252" await buy({ tokenName: 'woohoo', amount: '10', type: 'native', expectedAmount: calc.amount, ... }); // Use calc.amount ("16843.7579794843252"), NOT the input '10'`, }, maxAcceptableReverseBondingCurveFee: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: 'RECOMMENDED: Base reverse bonding curve fee from calculateBuyAmount (GALA). Use result.reverseBondingCurveFee. Omitting this may cause transaction failures. Works with maxAcceptableReverseBondingCurveFeeSlippageFactor for automatic slippage adjustment.', }, maxAcceptableReverseBondingCurveFeeSlippageFactor: common_schemas_js_1.RBC_FEE_SLIPPAGE_SCHEMA, slippageToleranceFactor: common_schemas_js_1.SLIPPAGE_TOLERANCE_SCHEMA, privateKey: common_schemas_js_1.PRIVATE_KEY_SCHEMA, }, required: ['tokenName', 'amount', 'type', 'expectedAmount', 'slippageToleranceFactor'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.buy({ tokenName: args.tokenName, amount: args.amount, type: args.type, expectedAmount: args.expectedAmount, maxAcceptableReverseBondingCurveFee: args.maxAcceptableReverseBondingCurveFee, maxAcceptableReverseBondingCurveFeeSlippageFactor: args.maxAcceptableReverseBondingCurveFeeSlippageFactor, slippageToleranceFactor: args.slippageToleranceFactor, privateKey: args.privateKey, }); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 4. Sell Tokens exports.sellTokensTool = { name: 'gala_launchpad_sell_tokens', description: `Execute token sale with slippage protection. WORKFLOW: 1. calculateSellAmount() Get expected output (result.amount AND result.reverseBondingCurveFee) 2. sell() Execute trade with BOTH expectedAmount AND maxAcceptableReverseBondingCurveFee 3. fetchTrades() Verify trade completed CRITICAL: Extract BOTH parameters from calculateSellAmount: - result.amount expectedAmount - result.reverseBondingCurveFee maxAcceptableReverseBondingCurveFee Omitting reverseBondingCurveFee may cause transaction failures! RETURNS: Transaction details including input/output amounts and transaction ID`, inputSchema: { type: 'object', properties: { tokenName: common_schemas_js_1.TOKEN_NAME_SCHEMA, amount: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: 'Amount to sell/receive', }, type: { type: 'string', enum: Object.values(launchpad_sdk_1.TRADING_TYPES), description: `Trade type (must match what you used in calculateSellAmount): - 'native': Receiving GALA amount - 'exact': Selling exact token amount`, }, expectedAmount: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: `Expected GALA output amount from calculateSellAmount (REQUIRED). CRITICAL: This is the 'amount' field from calculateSellAmount result, NOT your input amount. WORKFLOW: 1. Call calculateSellAmount({ tokenName, amount, type }) 2. Extract result.amount from the response 3. Use result.amount as this expectedAmount parameter EXAMPLE: const calc = await calculateSellAmount({ tokenName: 'woohoo', amount: '10', type: 'native' }); // calc.amount = "16843.7579794843252" await sell({ tokenName: 'woohoo', amount: '10', type: 'native', expectedAmount: calc.amount, ... }); // Use calc.amount ("16843.7579794843252"), NOT the input '10'`, }, maxAcceptableReverseBondingCurveFee: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: 'RECOMMENDED: Base reverse bonding curve fee from calculateSellAmount (GALA). Use result.reverseBondingCurveFee. Omitting this may cause transaction failures. Works with maxAcceptableReverseBondingCurveFeeSlippageFactor for automatic slippage adjustment.', }, maxAcceptableReverseBondingCurveFeeSlippageFactor: common_schemas_js_1.RBC_FEE_SLIPPAGE_SCHEMA, slippageToleranceFactor: common_schemas_js_1.SLIPPAGE_TOLERANCE_SCHEMA, privateKey: common_schemas_js_1.PRIVATE_KEY_SCHEMA, }, required: ['tokenName', 'amount', 'type', 'expectedAmount', 'slippageToleranceFactor'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.sell({ tokenName: args.tokenName, amount: args.amount, type: args.type, expectedAmount: args.expectedAmount, maxAcceptableReverseBondingCurveFee: args.maxAcceptableReverseBondingCurveFee, maxAcceptableReverseBondingCurveFeeSlippageFactor: args.maxAcceptableReverseBondingCurveFeeSlippageFactor, slippageToleranceFactor: args.slippageToleranceFactor, privateKey: args.privateKey, }); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 5. Fetch Trades exports.fetchTradesTool = { name: 'gala_launchpad_fetch_trades', description: 'Get trade history with filtering', inputSchema: { type: 'object', properties: { tokenName: common_schemas_js_1.TOKEN_NAME_SCHEMA, tradeType: { type: 'string', enum: ['buy', 'sell'], description: 'Filter by trade type', }, userAddress: { ...common_schemas_js_1.ADDRESS_SCHEMA, description: 'Filter by user address', }, page: common_schemas_js_1.PAGE_SCHEMA, limit: (0, common_schemas_js_1.createLimitSchema)('trade', 20), startDate: { ...common_schemas_js_1.DATE_TIME_SCHEMA, description: 'Filter by start date', }, endDate: { ...common_schemas_js_1.DATE_TIME_SCHEMA, description: 'Filter by end date', }, sortOrder: common_schemas_js_1.SORT_ORDER_SCHEMA, }, }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const pagination = (0, default_values_js_1.applyOperationPaginationDefaults)(args, 'trade'); const result = await sdk.fetchTrades({ tokenName: args.tokenName, tradeType: args.tradeType, userAddress: args.userAddress, ...pagination, startDate: args.startDate, endDate: args.endDate, sortOrder: args.sortOrder || 'desc', }); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 6. Calculate Initial Buy exports.calculateInitialBuyTool = { name: 'gala_launchpad_calculate_initial_buy', description: 'Calculate amounts for initial token purchase during creation (pre-mint phase)', inputSchema: { type: 'object', properties: { amount: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: 'GALA amount to spend for initial buy (standard decimal format, e.g., "100" for 100 GALA)', }, }, required: ['amount'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.calculateInitialBuyAmount(args.amount); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 7. Get Bundler Transaction Result exports.getBundlerTransactionResultTool = { name: 'gala_launchpad_get_bundler_transaction_result', description: `Get bundle transaction result by ID via HTTP (not WebSocket). Returns lightweight status: { id: string, method: string, status: string } Status values: "COMPLETED", "FAILED", "PENDING", "PROCESSING" Use cases: - Check transaction status when WebSocket times out - Get definitive transaction state - Verify trade/launch completion Note: This is a synchronous HTTP call, not WebSocket monitoring.`, inputSchema: { type: 'object', properties: { transactionId: common_schemas_js_1.TRANSACTION_ID_SCHEMA, }, required: ['transactionId'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.getBundlerTransactionResult(args.transactionId); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 8. Calculate Buy Amount for Graduation exports.calculateBuyAmountForGraduationTool = { name: 'gala_launchpad_calculate_buy_amount_for_graduation', description: `Calculate amount needed to graduate a token pool. Convenience method that: 1. Fetches pool details to get remaining tokens 2. Calls calculateBuyAmount with exact remaining amount 3. Returns standard AmountCalculationResult Performance optimization: Provide currentSupply to avoid fetching pool details twice. RETURNS: Same as calculateBuyAmount - complete cost breakdown including totalCost, amount, transactionFee, gasFee, reverseBondingCurveFee`, inputSchema: { type: 'object', properties: { tokenName: common_schemas_js_1.TOKEN_NAME_SCHEMA, calculateAmountMode: common_schemas_js_1.CALCULATION_MODE_SCHEMA, currentSupply: common_schemas_js_1.CURRENT_SUPPLY_SCHEMA, }, required: ['tokenName'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { // Build options object only if mode or supply provided const options = args.calculateAmountMode || args.currentSupply ? { tokenName: args.tokenName, calculateAmountMode: args.calculateAmountMode, currentSupply: args.currentSupply, } : args.tokenName; const result = await sdk.calculateBuyAmountForGraduation(options); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 9. Graduate Token exports.graduateTokenTool = { name: 'gala_launchpad_graduate_token', description: `Graduate a token pool by buying all remaining tokens in one transaction. WORKFLOW (automatic): 1. Calls calculateBuyAmountForGraduation() internally 2. Executes buy() with exact remaining token amount 3. Returns transaction result Performance optimization: Provide currentSupply to avoid fetching pool details twice. CRITICAL: This is a convenience method that combines multiple operations. Throws error if token is already graduated. slippageToleranceFactor is optional and uses SDK defaults if not provided. RETURNS: TradeResult with transaction details including amounts and transaction ID`, inputSchema: { type: 'object', properties: { tokenName: common_schemas_js_1.TOKEN_NAME_SCHEMA, slippageToleranceFactor: common_schemas_js_1.SLIPPAGE_TOLERANCE_SCHEMA, maxAcceptableReverseBondingCurveFeeSlippageFactor: common_schemas_js_1.RBC_FEE_SLIPPAGE_SCHEMA, privateKey: common_schemas_js_1.PRIVATE_KEY_SCHEMA, calculateAmountMode: common_schemas_js_1.CALCULATION_MODE_SCHEMA, currentSupply: common_schemas_js_1.CURRENT_SUPPLY_SCHEMA, }, required: ['tokenName'], // Only tokenName is required }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.graduateToken({ tokenName: args.tokenName, slippageToleranceFactor: args.slippageToleranceFactor, maxAcceptableReverseBondingCurveFeeSlippageFactor: args.maxAcceptableReverseBondingCurveFeeSlippageFactor, privateKey: args.privateKey, calculateAmountMode: args.calculateAmountMode, currentSupply: args.currentSupply, }); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 10. Calculate Buy Amount (Local) exports.calculateBuyAmountLocalTool = { name: 'gala_launchpad_calculate_buy_amount_local', description: `Calculate buy amounts using LOCAL bonding curve formulas (instant, no network call). Uses client-side exponential bonding curve calculations for instant quotes. Perfect for price discovery, UI updates, and offline scenarios. ACCURACY: Matches external calculations with <0.01% difference. RETURNS: { amount, reverseBondingCurveFee: "0", transactionFee, gasFee }`, inputSchema: { type: 'object', properties: { tokenName: common_schemas_js_1.TOKEN_NAME_SCHEMA, amount: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: 'Amount in standard decimal format (e.g., "1" for 1 GALA)', }, type: { type: 'string', enum: Object.values(launchpad_sdk_1.TRADING_TYPES), description: `Trade calculation type: - 'native': Spend GALA amount - 'exact': Buy exact token amount`, }, }, required: ['tokenName', 'amount', 'type'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.calculateBuyAmountLocal({ tokenName: args.tokenName, amount: args.amount, type: args.type, }); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 11. Calculate Buy Amount (External) exports.calculateBuyAmountExternalTool = { name: 'gala_launchpad_calculate_buy_amount_external', description: `Calculate buy amounts using EXTERNAL GalaChain network call (real-time). Explicit external calculation - queries GalaChain network for real-time pricing. Identical to calculateBuyAmount but makes the network dependency explicit. RETURNS: { amount, reverseBondingCurveFee, transactionFee, gasFee }`, inputSchema: { type: 'object', properties: { tokenName: common_schemas_js_1.TOKEN_NAME_SCHEMA, amount: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: 'Amount in standard decimal format', }, type: { type: 'string', enum: Object.values(launchpad_sdk_1.TRADING_TYPES), description: `Trade calculation type: - 'native': Spend GALA amount - 'exact': Buy exact token amount`, }, }, required: ['tokenName', 'amount', 'type'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.calculateBuyAmountExternal({ tokenName: args.tokenName, amount: args.amount, type: args.type, }); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 12. Calculate Sell Amount (Local) exports.calculateSellAmountLocalTool = { name: 'gala_launchpad_calculate_sell_amount_local', description: `Calculate sell amounts using LOCAL bonding curve formulas (instant, no network call). Uses client-side calculations with reverse bonding curve fee support. Requires pool details (maxSupply, fee parameters) to calculate accurately. ACCURACY: Matches external calculations with <0.01% difference. RETURNS: { amount, reverseBondingCurveFee, transactionFee, gasFee }`, inputSchema: { type: 'object', properties: { tokenName: common_schemas_js_1.TOKEN_NAME_SCHEMA, amount: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: 'Amount to sell/receive', }, type: { type: 'string', enum: Object.values(launchpad_sdk_1.TRADING_TYPES), description: `Trade calculation type: - 'native': Receive GALA amount - 'exact': Sell exact token amount`, }, maxSupply: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: 'Token maximum supply (get from fetchPoolDetails)', }, reverseBondingCurveMinFeeFactor: { type: 'number', minimum: 0, maximum: 1, description: 'Min reverse bonding curve fee factor (get from poolDetails.reverseBondingCurveMinFeeFactor)', }, reverseBondingCurveMaxFeeFactor: { type: 'number', minimum: 0, maximum: 1, description: 'Max reverse bonding curve fee factor (get from poolDetails.reverseBondingCurveMaxFeeFactor)', }, }, required: ['tokenName', 'amount', 'type', 'maxSupply', 'reverseBondingCurveMinFeeFactor', 'reverseBondingCurveMaxFeeFactor'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.calculateSellAmountLocal({ tokenName: args.tokenName, amount: args.amount, type: args.type, maxSupply: args.maxSupply, reverseBondingCurveMinFeeFactor: args.reverseBondingCurveMinFeeFactor, reverseBondingCurveMaxFeeFactor: args.reverseBondingCurveMaxFeeFactor, }); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 13. Calculate Sell Amount (External) exports.calculateSellAmountExternalTool = { name: 'gala_launchpad_calculate_sell_amount_external', description: `Calculate sell amounts using EXTERNAL GalaChain network call (real-time). Explicit external calculation - queries GalaChain network for real-time pricing. Identical to calculateSellAmount but makes the network dependency explicit. RETURNS: { amount, reverseBondingCurveFee, transactionFee, gasFee }`, inputSchema: { type: 'object', properties: { tokenName: common_schemas_js_1.TOKEN_NAME_SCHEMA, amount: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: 'Amount to sell/receive', }, type: { type: 'string', enum: Object.values(launchpad_sdk_1.TRADING_TYPES), description: `Trade calculation type: - 'native': Receive GALA amount - 'exact': Sell exact token amount`, }, }, required: ['tokenName', 'amount', 'type'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.calculateSellAmountExternal({ tokenName: args.tokenName, amount: args.amount, type: args.type, }); return (0, response_formatter_js_1.formatSuccess)(result); }), }; exports.tradingTools = [ exports.calculateBuyAmountTool, exports.calculateSellAmountTool, exports.buyTokensTool, exports.sellTokensTool, exports.fetchTradesTool, exports.calculateInitialBuyTool, exports.getBundlerTransactionResultTool, exports.calculateBuyAmountForGraduationTool, exports.graduateTokenTool, exports.calculateBuyAmountLocalTool, exports.calculateBuyAmountExternalTool, exports.calculateSellAmountLocalTool, exports.calculateSellAmountExternalTool, ]; //# sourceMappingURL=index.js.map