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

553 lines 23.5 kB
"use strict"; /** * Bridge Tools * * Cross-chain bridging tools for GalaChain ↔ Ethereum and GalaChain ↔ Solana. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.bridgeTools = exports.isTokenBridgeableToSolanaTool = exports.isTokenBridgeableToEthereumTool = exports.isTokenBridgeableToNetworkTool = exports.fetchAllTokensBridgeableToSolanaTool = exports.fetchAllTokensBridgeableToEthereumTool = exports.fetchAllBridgeableTokensByNetworkTool = exports.fetchBridgeableTokensByNetworkTool = exports.fetchSolanaWalletAllBalancesTool = exports.fetchEthereumWalletAllBalancesTool = exports.fetchSolanaWalletNativeBalanceTool = exports.fetchSolanaWalletTokenBalanceTool = exports.fetchEthereumWalletNativeBalanceTool = exports.fetchEthereumWalletTokenBalanceTool = exports.getSupportedBridgeTokensTool = exports.getBridgeStatusTool = exports.bridgeInTool = exports.bridgeOutTool = exports.estimateBridgeFeeTool = void 0; 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 launchpad_sdk_1 = require("@gala-chain/launchpad-sdk"); /** * Token ID schema for bridge operations * * Accepts either: * - Pipe-delimited string: "GALA|Unit|none|none" * - TokenClassKey object: { collection: "GALA", category: "Unit", type: "none", additionalKey: "none" } */ const TOKEN_ID_SCHEMA = { description: 'Token identifier in flexible format (string or object)', oneOf: [ { type: 'string', description: 'Pipe-delimited format: "collection|category|type|additionalKey" (e.g., "GUSDC|Unit|none|eth:0x...")', }, { type: 'object', description: 'TokenClassKey object format', properties: { collection: { type: 'string', description: 'Token collection (e.g., "Token")', }, category: { type: 'string', description: 'Token category (e.g., "Unit")', }, type: { type: 'string', description: 'Token type (e.g., "GUSDC")', }, additionalKey: { type: 'string', description: 'Additional key (e.g., "eth:0x...")', }, }, required: ['collection', 'category', 'type', 'additionalKey'], }, ], }; /** * Cached BridgeService instances per wallet+environment key */ const bridgeServiceCache = new Map(); /** * External network schema */ const EXTERNAL_NETWORK_SCHEMA = { type: 'string', enum: ['Ethereum', 'Solana'], description: 'Target external blockchain network', }; /** * Get or create a BridgeService instance for the given SDK. * Uses the SDK's dexApiBaseUrl for environment-aware bridge operations. * * @param sdk - LaunchpadSDK instance * @returns BridgeService instance * @throws Error if wallet is not configured */ function getBridgeService(sdk) { const wallet = sdk.getWallet(); if (!wallet) { throw new Error('Bridge operations require a wallet. Please configure PRIVATE_KEY environment variable.'); } const walletAddress = sdk.getAddress(); const privateKey = wallet.privateKey; const sdkConfig = sdk.getConfig(); const galaConnectBaseUrl = sdkConfig.dexApiBaseUrl; if (!galaConnectBaseUrl) { throw new Error('Bridge operations require dexApiBaseUrl in SDK config.'); } // Cache key includes environment to handle environment switches const cacheKey = `${walletAddress}:${galaConnectBaseUrl}`; // Check cache if (bridgeServiceCache.has(cacheKey)) { return bridgeServiceCache.get(cacheKey); } // Create new BridgeService with environment-aware URL const config = { galaConnectBaseUrl, galaChainWalletAddress: walletAddress, ethereumPrivateKey: privateKey, // Include Solana key if available from environment ...(process.env.SOLANA_PRIVATE_KEY && { solanaPrivateKey: process.env.SOLANA_PRIVATE_KEY, }), }; const service = new launchpad_sdk_1.BridgeService(config); bridgeServiceCache.set(cacheKey, service); return service; } // 1. Estimate Bridge Fee exports.estimateBridgeFeeTool = { name: 'gala_launchpad_estimate_bridge_fee', description: 'Estimate bridge fees for transferring tokens between GalaChain and an external chain (Ethereum or Solana)', inputSchema: { type: 'object', properties: { tokenId: TOKEN_ID_SCHEMA, destinationChain: { ...EXTERNAL_NETWORK_SCHEMA, description: 'Destination chain (Ethereum or Solana)', }, amount: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: 'Amount to bridge (optional, for more accurate fee estimation)', }, }, required: ['tokenId', 'destinationChain'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const bridgeService = getBridgeService(sdk); const result = await bridgeService.estimateBridgeFee({ tokenId: args.tokenId, destinationChain: args.destinationChain, amount: args.amount, }); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 2. Bridge Out (GalaChain → External) exports.bridgeOutTool = { name: 'gala_launchpad_bridge_out', description: 'Bridge tokens from GalaChain to an external chain (Ethereum or Solana). Requires wallet configuration.', inputSchema: { type: 'object', properties: { tokenId: TOKEN_ID_SCHEMA, amount: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: 'Amount to bridge', }, destinationChain: { ...EXTERNAL_NETWORK_SCHEMA, description: 'Destination chain (Ethereum or Solana)', }, recipientAddress: { ...common_schemas_js_1.ADDRESS_SCHEMA, description: 'Recipient address on the destination chain (Ethereum: 0x... format, Solana: base58 format)', }, }, required: ['tokenId', 'amount', 'destinationChain', 'recipientAddress'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const bridgeService = getBridgeService(sdk); const result = await bridgeService.bridgeOut({ tokenId: args.tokenId, amount: args.amount, destinationChain: args.destinationChain, recipientAddress: args.recipientAddress, }); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 3. Bridge In (External → GalaChain) exports.bridgeInTool = { name: 'gala_launchpad_bridge_in', description: 'Bridge tokens from an external chain (Ethereum or Solana) to GalaChain. Requires wallet configuration.', inputSchema: { type: 'object', properties: { tokenId: TOKEN_ID_SCHEMA, amount: { ...common_schemas_js_1.DECIMAL_AMOUNT_SCHEMA, description: 'Amount to bridge', }, sourceChain: { ...EXTERNAL_NETWORK_SCHEMA, description: 'Source chain (Ethereum or Solana)', }, }, required: ['tokenId', 'amount', 'sourceChain'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const bridgeService = getBridgeService(sdk); const result = await bridgeService.bridgeIn({ tokenId: args.tokenId, amount: args.amount, sourceChain: args.sourceChain, }); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 4. Get Bridge Status exports.getBridgeStatusTool = { name: 'gala_launchpad_get_bridge_status', description: 'Get the status of a bridge transaction by transaction hash', inputSchema: { type: 'object', properties: { transactionHash: { type: 'string', description: 'Transaction hash from bridgeOut or bridgeIn operation', }, chainHint: { ...EXTERNAL_NETWORK_SCHEMA, description: 'Optional chain hint for faster lookup (Ethereum or Solana)', }, }, required: ['transactionHash'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const bridgeService = getBridgeService(sdk); const result = await bridgeService.getBridgeStatus(args.transactionHash, args.chainHint); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 5. Get Supported Bridge Tokens exports.getSupportedBridgeTokensTool = { name: 'gala_launchpad_get_supported_bridge_tokens', description: 'Get list of tokens supported for bridging, optionally filtered by chain. Returns token details including decimals, supported chains, and contract addresses.', inputSchema: { type: 'object', properties: { chain: { ...EXTERNAL_NETWORK_SCHEMA, description: 'Optional chain filter (Ethereum or Solana)', }, }, }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const bridgeService = getBridgeService(sdk); const result = bridgeService.getSupportedBridgeTokens(args.chain); return (0, response_formatter_js_1.formatSuccess)({ tokens: result, totalCount: result.length, supportedChains: bridgeService.getSupportedBridgeChains(), }); }), }; // ============================================================================ // SINGLE TOKEN BALANCE TOOLS (Fast - 1 RPC call each) // ============================================================================ // 6. Fetch Ethereum Wallet Token Balance (Single ERC-20) exports.fetchEthereumWalletTokenBalanceTool = { name: 'gala_launchpad_fetch_ethereum_wallet_token_balance', description: 'Get a single ERC-20 token balance on Ethereum (GALA, GWETH, GUSDC, GUSDT, GWTRX, GWBTC). Fast: only 1 RPC call.', inputSchema: { type: 'object', properties: { symbol: { ...common_schemas_js_1.TOKEN_SYMBOL_SCHEMA, description: 'Token symbol (GALA, GWETH, GUSDC, GUSDT, GWTRX, or GWBTC)', }, address: { ...common_schemas_js_1.ADDRESS_SCHEMA, description: 'Ethereum address (0x format). Defaults to configured wallet address.', }, }, required: ['symbol'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const bridgeService = getBridgeService(sdk); const result = await bridgeService.fetchEthereumWalletTokenBalance(args.symbol, args.address); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 7. Fetch Ethereum Wallet Native Balance (ETH only) exports.fetchEthereumWalletNativeBalanceTool = { name: 'gala_launchpad_fetch_ethereum_wallet_native_balance', description: 'Get native ETH balance on Ethereum. Fast: only 1 RPC call.', inputSchema: { type: 'object', properties: { address: { ...common_schemas_js_1.ADDRESS_SCHEMA, description: 'Ethereum address (0x format). Defaults to configured wallet address.', }, }, }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const bridgeService = getBridgeService(sdk); const result = await bridgeService.fetchEthereumWalletNativeBalance(args.address); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 8. Fetch Solana Wallet Token Balance (Single SPL) exports.fetchSolanaWalletTokenBalanceTool = { name: 'gala_launchpad_fetch_solana_wallet_token_balance', description: 'Get a single SPL token balance on Solana (GALA or GSOL). Fast: only 1 RPC call.', inputSchema: { type: 'object', properties: { symbol: { ...common_schemas_js_1.TOKEN_SYMBOL_SCHEMA, description: 'Token symbol (GALA or GSOL)', }, address: { ...common_schemas_js_1.ADDRESS_SCHEMA, description: 'Solana address (base58 format). Defaults to configured wallet address.', }, }, required: ['symbol'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const bridgeService = getBridgeService(sdk); const result = await bridgeService.fetchSolanaWalletTokenBalance(args.symbol, args.address); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 9. Fetch Solana Wallet Native Balance (SOL only) exports.fetchSolanaWalletNativeBalanceTool = { name: 'gala_launchpad_fetch_solana_wallet_native_balance', description: 'Get native SOL balance on Solana. Fast: only 1 RPC call.', inputSchema: { type: 'object', properties: { address: { ...common_schemas_js_1.ADDRESS_SCHEMA, description: 'Solana address (base58 format). Defaults to configured wallet address.', }, }, }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const bridgeService = getBridgeService(sdk); const result = await bridgeService.fetchSolanaWalletNativeBalance(args.address); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // ============================================================================ // ALL TOKENS BALANCE TOOLS (Complete portfolio view - multiple RPC calls) // ============================================================================ // 10. Fetch All Ethereum Wallet Balances exports.fetchEthereumWalletAllBalancesTool = { name: 'gala_launchpad_fetch_ethereum_wallet_all_balances', description: 'Get ALL supported token balances on Ethereum for a wallet (ETH + GALA, GWETH, GUSDC, GUSDT, GWTRX, GWBTC). Returns native ETH and all supported ERC-20 token balances. Note: Makes 7 RPC calls.', inputSchema: { type: 'object', properties: { address: { ...common_schemas_js_1.ADDRESS_SCHEMA, description: 'Ethereum address (0x format). Defaults to configured wallet address.', }, }, }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const bridgeService = getBridgeService(sdk); const result = await bridgeService.fetchEthereumWalletAllBalances(args.address); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 11. Fetch All Solana Wallet Balances exports.fetchSolanaWalletAllBalancesTool = { name: 'gala_launchpad_fetch_solana_wallet_all_balances', description: 'Get ALL supported token balances on Solana for a wallet (SOL + GALA, GSOL). Returns native SOL and all supported SPL token balances. Note: Makes 3 RPC calls.', inputSchema: { type: 'object', properties: { address: { ...common_schemas_js_1.ADDRESS_SCHEMA, description: 'Solana address (base58 format). Defaults to configured wallet address.', }, }, }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const bridgeService = getBridgeService(sdk); const result = await bridgeService.fetchSolanaWalletAllBalances(args.address); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // ============================================================================ // BRIDGEABLE TOKEN DISCOVERY TOOLS (Dynamic contract address lookups) // ============================================================================ /** * Bridgeable network schema for API params */ const BRIDGEABLE_NETWORK_SCHEMA = { type: 'string', enum: ['ETHEREUM', 'SOLANA'], description: 'Target network for bridgeable token lookup (uppercase)', }; // 12. Fetch Bridgeable Tokens By Network (paginated) exports.fetchBridgeableTokensByNetworkTool = { name: 'gala_launchpad_fetch_bridgeable_tokens_by_network', description: 'Fetch bridgeable tokens for a specific network with pagination. Queries DEX API to discover which tokens can be bridged. Results are cached permanently.', inputSchema: { type: 'object', properties: { network: { ...BRIDGEABLE_NETWORK_SCHEMA, description: "Target network ('ETHEREUM' or 'SOLANA')", }, offset: { type: 'number', minimum: 0, description: 'Pagination offset (default: 0)', }, limit: { type: 'number', minimum: 1, maximum: 1000, description: 'Results per page (max: 1000, default: 1000)', }, }, required: ['network'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.fetchBridgeableTokensByNetwork({ network: args.network, offset: args.offset, limit: args.limit, }); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 13. Fetch All Bridgeable Tokens By Network (auto-pagination) exports.fetchAllBridgeableTokensByNetworkTool = { name: 'gala_launchpad_fetch_all_bridgeable_tokens_by_network', description: 'Fetch ALL bridgeable tokens for a network with auto-pagination. Returns cached data if available. No page/limit needed.', inputSchema: { type: 'object', properties: { network: { ...BRIDGEABLE_NETWORK_SCHEMA, description: "Target network ('ETHEREUM' or 'SOLANA')", }, }, required: ['network'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.fetchAllBridgeableTokensByNetwork(args.network); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 14. Fetch All Tokens Bridgeable To Ethereum exports.fetchAllTokensBridgeableToEthereumTool = { name: 'gala_launchpad_fetch_all_tokens_bridgeable_to_ethereum', description: 'Fetch all tokens that can be bridged to Ethereum. Convenience method with auto-pagination and caching.', inputSchema: { type: 'object', properties: {}, }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk) => { const result = await sdk.fetchAllTokensBridgeableToEthereum(); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 15. Fetch All Tokens Bridgeable To Solana exports.fetchAllTokensBridgeableToSolanaTool = { name: 'gala_launchpad_fetch_all_tokens_bridgeable_to_solana', description: 'Fetch all tokens that can be bridged to Solana. Convenience method with auto-pagination and caching.', inputSchema: { type: 'object', properties: {}, }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk) => { const result = await sdk.fetchAllTokensBridgeableToSolana(); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 16. Is Token Bridgeable To Network exports.isTokenBridgeableToNetworkTool = { name: 'gala_launchpad_is_token_bridgeable_to_network', description: 'Check if a token is bridgeable to a specific network. Returns bridgeability status and contract address if available.', inputSchema: { type: 'object', properties: { tokenSymbol: { ...common_schemas_js_1.TOKEN_SYMBOL_SCHEMA, description: "Token symbol to check (e.g., 'GALA', 'GWETH', 'GUSDC')", }, network: { ...BRIDGEABLE_NETWORK_SCHEMA, description: "Target network ('ETHEREUM' or 'SOLANA')", }, }, required: ['tokenSymbol', 'network'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.isTokenBridgeableToNetwork({ tokenSymbol: args.tokenSymbol, network: args.network, }); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 17. Is Token Bridgeable To Ethereum exports.isTokenBridgeableToEthereumTool = { name: 'gala_launchpad_is_token_bridgeable_to_ethereum', description: 'Check if a token is bridgeable to Ethereum. Returns bridgeability status and contract address if bridgeable.', inputSchema: { type: 'object', properties: { tokenSymbol: { ...common_schemas_js_1.TOKEN_SYMBOL_SCHEMA, description: "Token symbol to check (e.g., 'GALA', 'GWETH', 'GUSDC')", }, }, required: ['tokenSymbol'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.isTokenBridgeableToEthereum(args.tokenSymbol); return (0, response_formatter_js_1.formatSuccess)(result); }), }; // 18. Is Token Bridgeable To Solana exports.isTokenBridgeableToSolanaTool = { name: 'gala_launchpad_is_token_bridgeable_to_solana', description: 'Check if a token is bridgeable to Solana. Returns bridgeability status and mint address if bridgeable.', inputSchema: { type: 'object', properties: { tokenSymbol: { ...common_schemas_js_1.TOKEN_SYMBOL_SCHEMA, description: "Token symbol to check (e.g., 'GALA', 'GSOL')", }, }, required: ['tokenSymbol'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await sdk.isTokenBridgeableToSolana(args.tokenSymbol); return (0, response_formatter_js_1.formatSuccess)(result); }), }; /** * All bridge tools (18 tools) */ exports.bridgeTools = [ exports.estimateBridgeFeeTool, exports.bridgeOutTool, exports.bridgeInTool, exports.getBridgeStatusTool, exports.getSupportedBridgeTokensTool, // Single token (fast - 1 RPC call) exports.fetchEthereumWalletTokenBalanceTool, exports.fetchEthereumWalletNativeBalanceTool, exports.fetchSolanaWalletTokenBalanceTool, exports.fetchSolanaWalletNativeBalanceTool, // All tokens (complete portfolio) exports.fetchEthereumWalletAllBalancesTool, exports.fetchSolanaWalletAllBalancesTool, // Bridgeable token discovery (dynamic contract lookups) exports.fetchBridgeableTokensByNetworkTool, exports.fetchAllBridgeableTokensByNetworkTool, exports.fetchAllTokensBridgeableToEthereumTool, exports.fetchAllTokensBridgeableToSolanaTool, exports.isTokenBridgeableToNetworkTool, exports.isTokenBridgeableToEthereumTool, exports.isTokenBridgeableToSolanaTool, ]; //# sourceMappingURL=index.js.map