@gala-chain/launchpad-mcp-server 1.22.4 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/README.md +83 -8
  3. package/dist/constants/mcpToolNames.d.ts +69 -11
  4. package/dist/constants/mcpToolNames.d.ts.map +1 -1
  5. package/dist/constants/mcpToolNames.js +47 -9
  6. package/dist/constants/mcpToolNames.js.map +1 -1
  7. package/dist/generated/version.d.ts +1 -1
  8. package/dist/generated/version.js +1 -1
  9. package/dist/prompts/balances.d.ts +24 -0
  10. package/dist/prompts/balances.d.ts.map +1 -0
  11. package/dist/prompts/balances.js +191 -0
  12. package/dist/prompts/balances.js.map +1 -0
  13. package/dist/prompts/creation-utils.d.ts +20 -0
  14. package/dist/prompts/creation-utils.d.ts.map +1 -0
  15. package/dist/prompts/creation-utils.js +115 -0
  16. package/dist/prompts/creation-utils.js.map +1 -0
  17. package/dist/prompts/index.d.ts +9 -2
  18. package/dist/prompts/index.d.ts.map +1 -1
  19. package/dist/prompts/index.js +23 -2
  20. package/dist/prompts/index.js.map +1 -1
  21. package/dist/prompts/pools.d.ts +64 -0
  22. package/dist/prompts/pools.d.ts.map +1 -0
  23. package/dist/prompts/pools.js +548 -0
  24. package/dist/prompts/pools.js.map +1 -0
  25. package/dist/prompts/social.d.ts +16 -0
  26. package/dist/prompts/social.d.ts.map +1 -0
  27. package/dist/prompts/social.js +97 -0
  28. package/dist/prompts/social.js.map +1 -0
  29. package/dist/prompts/trading-calculations.d.ts +52 -0
  30. package/dist/prompts/trading-calculations.d.ts.map +1 -0
  31. package/dist/prompts/trading-calculations.js +479 -0
  32. package/dist/prompts/trading-calculations.js.map +1 -0
  33. package/dist/prompts/transfers.d.ts +16 -0
  34. package/dist/prompts/transfers.d.ts.map +1 -0
  35. package/dist/prompts/transfers.js +100 -0
  36. package/dist/prompts/transfers.js.map +1 -0
  37. package/dist/prompts/utility-tools.d.ts +56 -0
  38. package/dist/prompts/utility-tools.d.ts.map +1 -0
  39. package/dist/prompts/utility-tools.js +338 -0
  40. package/dist/prompts/utility-tools.js.map +1 -0
  41. package/docs/AI-AGENT-PATTERNS.md +555 -0
  42. package/docs/CONSTRAINTS-REFERENCE.md +454 -0
  43. package/docs/PROMPT-TOOL-MAPPING.md +352 -0
  44. package/docs/examples/default-values-pattern.md +240 -0
  45. package/docs/examples/tool-factory-pattern.md +217 -0
  46. package/jest.config.js +94 -0
  47. package/package.json +1 -1
  48. package/src/__tests__/integration/fetchTokenDetails.integration.test.ts +258 -0
  49. package/src/__tests__/integration/poolTools.integration.test.ts +185 -0
  50. package/src/__tests__/server.test.ts +256 -0
  51. package/src/constants/mcpToolNames.ts +181 -0
  52. package/src/index.ts +19 -0
  53. package/src/prompts/__tests__/promptStructure.test.ts +137 -0
  54. package/src/prompts/__tests__/registry.test.ts +359 -0
  55. package/src/prompts/analysis.ts +429 -0
  56. package/src/prompts/balances.ts +198 -0
  57. package/src/prompts/create-token.ts +123 -0
  58. package/src/prompts/creation-utils.ts +118 -0
  59. package/src/prompts/dex-trading.ts +86 -0
  60. package/src/prompts/discover-tokens.ts +86 -0
  61. package/src/prompts/index.ts +175 -0
  62. package/src/prompts/liquidity-positions.ts +270 -0
  63. package/src/prompts/pools.ts +571 -0
  64. package/src/prompts/portfolio.ts +242 -0
  65. package/src/prompts/social.ts +100 -0
  66. package/src/prompts/trading-calculations.ts +499 -0
  67. package/src/prompts/trading.ts +191 -0
  68. package/src/prompts/transfers.ts +103 -0
  69. package/src/prompts/utility-tools.ts +349 -0
  70. package/src/prompts/utility.ts +92 -0
  71. package/src/prompts/utils/workflowTemplates.ts +511 -0
  72. package/src/schemas/common-schemas.ts +393 -0
  73. package/src/scripts/test-all-prompts.ts +184 -0
  74. package/src/server.ts +367 -0
  75. package/src/tools/__tests__/dex-tools.test.ts +562 -0
  76. package/src/tools/__tests__/liquidity-positions.test.ts +673 -0
  77. package/src/tools/balance/index.ts +174 -0
  78. package/src/tools/creation/index.ts +182 -0
  79. package/src/tools/dex/index.ts +226 -0
  80. package/src/tools/dex/liquidity-positions.ts +547 -0
  81. package/src/tools/index.ts +94 -0
  82. package/src/tools/pools/fetchAllPools.ts +47 -0
  83. package/src/tools/pools/fetchAllPriceHistory.ts +119 -0
  84. package/src/tools/pools/fetchPoolDetails.ts +27 -0
  85. package/src/tools/pools/fetchPoolDetailsForCalculation.ts +22 -0
  86. package/src/tools/pools/fetchPools.ts +47 -0
  87. package/src/tools/pools/fetchPriceHistory.ts +124 -0
  88. package/src/tools/pools/fetchTokenDetails.ts +77 -0
  89. package/src/tools/pools/index.ts +284 -0
  90. package/src/tools/social/index.ts +64 -0
  91. package/src/tools/trading/index.ts +605 -0
  92. package/src/tools/transfers/index.ts +75 -0
  93. package/src/tools/utils/clearCache.ts +36 -0
  94. package/src/tools/utils/createWallet.ts +19 -0
  95. package/src/tools/utils/explainSdkUsage.ts +1446 -0
  96. package/src/tools/utils/getAddress.ts +12 -0
  97. package/src/tools/utils/getCacheInfo.ts +14 -0
  98. package/src/tools/utils/getConfig.ts +21 -0
  99. package/src/tools/utils/getEnvironment.ts +17 -0
  100. package/src/tools/utils/getEthereumAddress.ts +12 -0
  101. package/src/tools/utils/getUrlByTokenName.ts +12 -0
  102. package/src/tools/utils/getVersion.ts +25 -0
  103. package/src/tools/utils/getWallet.ts +25 -0
  104. package/src/tools/utils/hasWallet.ts +15 -0
  105. package/src/tools/utils/index.ts +37 -0
  106. package/src/tools/utils/isTokenGraduated.ts +16 -0
  107. package/src/tools/utils/setWallet.ts +41 -0
  108. package/src/tools/utils/switchEnvironment.ts +28 -0
  109. package/src/types/mcp.ts +72 -0
  110. package/src/utils/__tests__/validation.test.ts +147 -0
  111. package/src/utils/constraints.ts +155 -0
  112. package/src/utils/default-values.ts +208 -0
  113. package/src/utils/error-handler.ts +69 -0
  114. package/src/utils/error-templates.ts +273 -0
  115. package/src/utils/response-formatter.ts +51 -0
  116. package/src/utils/tool-factory.ts +303 -0
  117. package/src/utils/tool-registry.ts +296 -0
  118. package/src/utils/validation.ts +371 -0
  119. package/tests/wallet-management-integration.test.ts +284 -0
  120. package/tsconfig.json +23 -0
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Balance & Portfolio Tools
3
+ */
4
+
5
+ import type { MCPTool } from '../../types/mcp.js';
6
+ import { formatSuccess, formatBoolean } from '../../utils/response-formatter.js';
7
+ import { withErrorHandling } from '../../utils/error-handler.js';
8
+ import {
9
+ TOKEN_NAME_SCHEMA,
10
+ ADDRESS_SCHEMA,
11
+ PAGE_SCHEMA,
12
+ createLimitSchema,
13
+ SEARCH_SCHEMA,
14
+ FULL_NAME_SCHEMA,
15
+ PRIVATE_KEY_SCHEMA,
16
+ } from '../../schemas/common-schemas.js';
17
+ import { applyOperationPaginationDefaults } from '../../utils/default-values.js';
18
+
19
+ // 1. Fetch GALA Balance
20
+ export const fetchGalaBalanceTool: MCPTool = {
21
+ name: 'gala_launchpad_fetch_gala_balance',
22
+ description: 'Get GALA balance for a wallet',
23
+ inputSchema: {
24
+ type: 'object',
25
+ properties: {
26
+ address: {
27
+ ...ADDRESS_SCHEMA,
28
+ description: 'Wallet address (optional, defaults to SDK wallet)',
29
+ },
30
+ },
31
+ },
32
+ handler: withErrorHandling(async (sdk, args) => {
33
+ const result = await sdk.fetchGalaBalance(args.address);
34
+ return formatSuccess(result);
35
+ }),
36
+ };
37
+
38
+ // 2. Fetch Token Balance (Optimized Single-Token Lookup)
39
+ export const fetchTokenBalanceTool: MCPTool = {
40
+ name: 'gala_launchpad_fetch_token_balance',
41
+ description: 'Get token balance for a specific token. Automatically routes to the correct backend: GalaChain for standard tokens (GALA, GUSDC) or launchpad backend for launchpad tokens (anime, etc.).',
42
+ inputSchema: {
43
+ type: 'object',
44
+ properties: {
45
+ tokenName: TOKEN_NAME_SCHEMA,
46
+ address: ADDRESS_SCHEMA,
47
+ },
48
+ required: ['tokenName', 'address'],
49
+ },
50
+ handler: withErrorHandling(async (sdk, args) => {
51
+ // SDK now handles routing: tokenId → GalaChain, tokenName → launchpad backend
52
+ const result = await sdk.fetchTokenBalance({
53
+ tokenName: args.tokenName,
54
+ address: args.address
55
+ });
56
+ return formatSuccess(result);
57
+ }),
58
+ };
59
+
60
+ // 3. Fetch Tokens Held (with Filtering Support)
61
+ export const fetchTokensHeldTool: MCPTool = {
62
+ name: 'gala_launchpad_fetch_tokens_held',
63
+ description: 'Get tokens held by a wallet with optional filtering. Supports exact match (tokenName) and fuzzy search (search) for efficient backend filtering.',
64
+ inputSchema: {
65
+ type: 'object',
66
+ properties: {
67
+ address: ADDRESS_SCHEMA,
68
+ page: PAGE_SCHEMA,
69
+ limit: createLimitSchema('user', 20),
70
+ tokenName: {
71
+ ...TOKEN_NAME_SCHEMA,
72
+ description: 'Optional token name (exact match filter)',
73
+ },
74
+ search: SEARCH_SCHEMA,
75
+ },
76
+ required: ['address'],
77
+ },
78
+ handler: withErrorHandling(async (sdk, args) => {
79
+ const pagination = applyOperationPaginationDefaults(args, 'user');
80
+ const result = await sdk.fetchTokensHeld({
81
+ ...pagination,
82
+ tokenName: args.tokenName,
83
+ search: args.search,
84
+ address: args.address,
85
+ });
86
+ return formatSuccess(result);
87
+ }),
88
+ };
89
+
90
+ // 4. Fetch Tokens Created (with Filtering Support)
91
+ export const fetchTokensCreatedTool: MCPTool = {
92
+ name: 'gala_launchpad_fetch_tokens_created',
93
+ description: 'Get tokens created by a wallet with optional filtering. Supports exact match (tokenName) and fuzzy search (search) for efficient backend filtering.',
94
+ inputSchema: {
95
+ type: 'object',
96
+ properties: {
97
+ address: ADDRESS_SCHEMA,
98
+ page: PAGE_SCHEMA,
99
+ limit: createLimitSchema('user', 20),
100
+ tokenName: {
101
+ ...TOKEN_NAME_SCHEMA,
102
+ description: 'Optional token name (exact match filter)',
103
+ },
104
+ search: SEARCH_SCHEMA,
105
+ },
106
+ required: ['address'],
107
+ },
108
+ handler: withErrorHandling(async (sdk, args) => {
109
+ const pagination = applyOperationPaginationDefaults(args, 'user');
110
+ const result = await sdk.fetchTokensCreated({
111
+ ...pagination,
112
+ tokenName: args.tokenName,
113
+ search: args.search,
114
+ address: args.address,
115
+ });
116
+ return formatSuccess(result);
117
+ }),
118
+ };
119
+
120
+ // 5. Fetch Profile
121
+ export const fetchProfileTool: MCPTool = {
122
+ name: 'gala_launchpad_fetch_profile',
123
+ description: 'Get user profile data',
124
+ inputSchema: {
125
+ type: 'object',
126
+ properties: {
127
+ address: {
128
+ ...ADDRESS_SCHEMA,
129
+ description: 'Wallet address (optional, defaults to SDK wallet)',
130
+ },
131
+ },
132
+ },
133
+ handler: withErrorHandling(async (sdk, args) => {
134
+ const result = await sdk.fetchProfile(args.address);
135
+ return formatSuccess(result);
136
+ }),
137
+ };
138
+
139
+ // 6. Update Profile
140
+ export const updateProfileTool: MCPTool = {
141
+ name: 'gala_launchpad_update_profile',
142
+ description: 'Update user profile',
143
+ inputSchema: {
144
+ type: 'object',
145
+ properties: {
146
+ fullName: FULL_NAME_SCHEMA,
147
+ profileImage: {
148
+ type: 'string',
149
+ description: 'Profile image URL or empty string',
150
+ },
151
+ address: ADDRESS_SCHEMA,
152
+ privateKey: PRIVATE_KEY_SCHEMA,
153
+ },
154
+ required: ['fullName', 'profileImage', 'address'],
155
+ },
156
+ handler: withErrorHandling(async (sdk, args) => {
157
+ await sdk.updateProfile({
158
+ fullName: args.fullName,
159
+ profileImage: args.profileImage,
160
+ address: args.address,
161
+ privateKey: args.privateKey,
162
+ });
163
+ return formatBoolean(true, 'Profile updated successfully');
164
+ }),
165
+ };
166
+
167
+ export const balanceTools: MCPTool[] = [
168
+ fetchGalaBalanceTool,
169
+ fetchTokenBalanceTool,
170
+ fetchTokensHeldTool,
171
+ fetchTokensCreatedTool,
172
+ fetchProfileTool,
173
+ updateProfileTool,
174
+ ];
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Token Creation Tools
3
+ */
4
+
5
+ import type { MCPTool } from '../../types/mcp.js';
6
+ import { formatSuccess } from '../../utils/response-formatter.js';
7
+ import { withErrorHandling } from '../../utils/error-handler.js';
8
+ import { createNoParamTool } from '../../utils/tool-factory.js';
9
+ import {
10
+ TOKEN_NAME_SCHEMA,
11
+ TOKEN_SYMBOL_SCHEMA,
12
+ TOKEN_DESCRIPTION_SCHEMA,
13
+ PRE_BUY_QUANTITY_SCHEMA,
14
+ URL_SCHEMA,
15
+ PRIVATE_KEY_SCHEMA,
16
+ ADDRESS_SCHEMA,
17
+ } from '../../schemas/common-schemas.js';
18
+
19
+ // 1. Launch Token
20
+ export const launchTokenTool: MCPTool = {
21
+ name: 'gala_launchpad_launch_token',
22
+ description: `Create a new token on the launchpad.
23
+
24
+ WORKFLOW:
25
+ 1. checkTokenName() → Verify name is available
26
+ 2. checkTokenSymbol() → Verify symbol is available
27
+ 3. launchToken() → Create token with validated name/symbol
28
+ 4. getUrlByTokenName() → Get frontend URL for the new token
29
+
30
+ REQUIREMENT: At least one social URL (websiteUrl, twitterUrl, or telegramUrl) is required.
31
+
32
+ RETURNS: Transaction details including token name, symbol, creator address, and transaction ID`,
33
+ inputSchema: {
34
+ type: 'object',
35
+ properties: {
36
+ tokenName: TOKEN_NAME_SCHEMA,
37
+ tokenSymbol: TOKEN_SYMBOL_SCHEMA,
38
+ tokenDescription: TOKEN_DESCRIPTION_SCHEMA,
39
+ tokenImage: {
40
+ ...URL_SCHEMA,
41
+ description: 'Token image URL',
42
+ },
43
+ preBuyQuantity: PRE_BUY_QUANTITY_SCHEMA,
44
+ websiteUrl: {
45
+ ...URL_SCHEMA,
46
+ description: 'Website URL (optional)',
47
+ },
48
+ telegramUrl: {
49
+ ...URL_SCHEMA,
50
+ description: 'Telegram channel URL (optional)',
51
+ },
52
+ twitterUrl: {
53
+ ...URL_SCHEMA,
54
+ description: 'Twitter profile URL (optional)',
55
+ },
56
+ tokenCategory: {
57
+ type: 'string',
58
+ description: 'Token category (defaults to "Unit")',
59
+ },
60
+ tokenCollection: {
61
+ type: 'string',
62
+ description: 'Token collection (defaults to "Token")',
63
+ },
64
+ reverseBondingCurveConfiguration: {
65
+ type: 'object',
66
+ properties: {
67
+ minFeePortion: {
68
+ type: 'string',
69
+ description: 'Minimum fee portion',
70
+ },
71
+ maxFeePortion: {
72
+ type: 'string',
73
+ description: 'Maximum fee portion',
74
+ },
75
+ },
76
+ description: 'Reverse bonding curve configuration (optional, uses defaults)',
77
+ },
78
+ privateKey: PRIVATE_KEY_SCHEMA,
79
+ },
80
+ required: [
81
+ 'tokenName',
82
+ 'tokenSymbol',
83
+ 'tokenDescription',
84
+ 'tokenImage',
85
+ ],
86
+ },
87
+ handler: withErrorHandling(async (sdk, args) => {
88
+ const result = await sdk.launchToken(args);
89
+ return formatSuccess(result);
90
+ }),
91
+ };
92
+
93
+ // 2. Upload Token Image
94
+ export const uploadTokenImageTool: MCPTool = {
95
+ name: 'gala_launchpad_upload_token_image',
96
+ description: 'Upload token image from filesystem (Node.js only)',
97
+ inputSchema: {
98
+ type: 'object',
99
+ properties: {
100
+ tokenName: {
101
+ ...TOKEN_NAME_SCHEMA,
102
+ description: 'Token name (2-20 lowercase alphanumeric)',
103
+ },
104
+ imagePath: {
105
+ type: 'string',
106
+ description: 'Absolute file path to image file',
107
+ },
108
+ privateKey: PRIVATE_KEY_SCHEMA,
109
+ },
110
+ required: ['tokenName', 'imagePath'],
111
+ },
112
+ handler: withErrorHandling(async (sdk, args) => {
113
+ const fs = await import('fs/promises');
114
+ const fileBuffer = await fs.readFile(args.imagePath);
115
+
116
+ const result = await sdk.uploadTokenImage({
117
+ tokenName: args.tokenName,
118
+ options: {
119
+ file: fileBuffer,
120
+ tokenName: args.tokenName,
121
+ },
122
+ privateKey: args.privateKey,
123
+ });
124
+ return formatSuccess(result);
125
+ }),
126
+ };
127
+
128
+ // 3. Upload Profile Image
129
+ export const uploadProfileImageTool: MCPTool = {
130
+ name: 'gala_launchpad_upload_profile_image',
131
+ description: 'Upload profile image from filesystem (Node.js only)',
132
+ inputSchema: {
133
+ type: 'object',
134
+ properties: {
135
+ imagePath: {
136
+ type: 'string',
137
+ description: 'Absolute file path to image file',
138
+ },
139
+ address: {
140
+ ...ADDRESS_SCHEMA,
141
+ description: 'Optional wallet address (defaults to authenticated user)',
142
+ },
143
+ privateKey: PRIVATE_KEY_SCHEMA,
144
+ },
145
+ required: ['imagePath'],
146
+ },
147
+ handler: withErrorHandling(async (sdk, args) => {
148
+ const fs = await import('fs/promises');
149
+ const fileBuffer = await fs.readFile(args.imagePath);
150
+
151
+ const imageUrl = await sdk.uploadProfileImage({
152
+ file: fileBuffer,
153
+ address: args.address,
154
+ privateKey: args.privateKey,
155
+ });
156
+
157
+ // If no imageUrl returned but upload succeeded, provide helpful message
158
+ if (!imageUrl) {
159
+ return formatSuccess({
160
+ success: true,
161
+ message: 'Profile image uploaded successfully (image stored with wallet address)',
162
+ });
163
+ }
164
+
165
+ return formatSuccess({ success: true, imageUrl });
166
+ }),
167
+ };
168
+
169
+ // 4. Fetch Launch Token Fee (45% code reduction via factory pattern)
170
+ export const fetchLaunchTokenFeeTool = createNoParamTool({
171
+ name: 'gala_launchpad_fetch_launch_token_fee',
172
+ description: 'Fetch the current GALA fee required to launch a new token on the launchpad. Returns a number (e.g., 0.001). This is a dynamic value that may change. Check this before launching a token to ensure sufficient balance.',
173
+ handler: (sdk) => sdk.fetchLaunchTokenFee(),
174
+ resultKey: 'feeAmount',
175
+ });
176
+
177
+ export const creationTools: MCPTool[] = [
178
+ launchTokenTool,
179
+ uploadTokenImageTool,
180
+ uploadProfileImageTool,
181
+ fetchLaunchTokenFeeTool,
182
+ ];
@@ -0,0 +1,226 @@
1
+ /**
2
+ * DEX/GalaSwap Trading Operations Tools
3
+ *
4
+ * Tools for trading on GalaSwap DEX after tokens graduate from bonding curves.
5
+ * These tools provide quote generation, swap execution, liquidity management, and asset management.
6
+ */
7
+
8
+ import type { MCPTool } from '../../types/mcp.js';
9
+ import { liquidityPositionTools } from './liquidity-positions.js';
10
+ import { formatSuccess } from '../../utils/response-formatter.js';
11
+ import { withErrorHandling } from '../../utils/error-handler.js';
12
+ import {
13
+ DECIMAL_AMOUNT_SCHEMA,
14
+ ADDRESS_SCHEMA,
15
+ } from '../../schemas/common-schemas.js';
16
+
17
+ // Token symbol for DEX trading
18
+ const TOKEN_SYMBOL_SCHEMA = {
19
+ type: 'string',
20
+ minLength: 1,
21
+ maxLength: 20,
22
+ description: 'Token symbol (e.g., "GALA", "GUSDC")',
23
+ };
24
+
25
+ // Fee tier for GalaSwap (in basis points)
26
+ const FEE_TIER_SCHEMA = {
27
+ type: 'number',
28
+ enum: [500, 3000, 10000],
29
+ description: 'Fee tier in basis points: 500 (0.05%), 3000 (0.30%), 10000 (1.00%)',
30
+ };
31
+
32
+ // Slippage tolerance
33
+ const SLIPPAGE_TOLERANCE_SCHEMA = {
34
+ type: 'number',
35
+ minimum: 0,
36
+ maximum: 1,
37
+ description: 'Slippage tolerance as decimal (e.g., 0.01 for 1%)',
38
+ };
39
+
40
+ // 1. Get Swap Quote (Exact Input)
41
+ export const getSwapQuoteExactInputTool: MCPTool = {
42
+ name: 'gala_launchpad_get_swap_quote_exact_input',
43
+ description:
44
+ 'Get swap quote for exact input amount - specify how much you want to spend',
45
+ inputSchema: {
46
+ type: 'object',
47
+ properties: {
48
+ fromToken: TOKEN_SYMBOL_SCHEMA,
49
+ toToken: TOKEN_SYMBOL_SCHEMA,
50
+ amount: {
51
+ ...DECIMAL_AMOUNT_SCHEMA,
52
+ description: 'Amount of source token to spend',
53
+ },
54
+ },
55
+ required: ['fromToken', 'toToken', 'amount'],
56
+ },
57
+ handler: withErrorHandling(async (sdk, args) => {
58
+ const quote = await sdk.getSwapQuoteExactInput(args.fromToken, args.toToken, args.amount);
59
+ return formatSuccess({
60
+ fromToken: quote.fromToken,
61
+ toToken: quote.toToken,
62
+ inputAmount: quote.inputAmount,
63
+ estimatedOutput: quote.estimatedOutput,
64
+ feeTier: quote.feeTier,
65
+ priceImpact: quote.priceImpact,
66
+ executionPrice: quote.executionPrice,
67
+ message: `Spending ${quote.inputAmount} ${quote.fromToken}, receiving ~${quote.estimatedOutput} ${quote.toToken}`,
68
+ });
69
+ }),
70
+ };
71
+
72
+ // 2. Get Swap Quote (Exact Output)
73
+ export const getSwapQuoteExactOutputTool: MCPTool = {
74
+ name: 'gala_launchpad_get_swap_quote_exact_output',
75
+ description:
76
+ 'Get swap quote for exact output amount - specify how much you want to receive',
77
+ inputSchema: {
78
+ type: 'object',
79
+ properties: {
80
+ fromToken: TOKEN_SYMBOL_SCHEMA,
81
+ toToken: TOKEN_SYMBOL_SCHEMA,
82
+ amount: {
83
+ ...DECIMAL_AMOUNT_SCHEMA,
84
+ description: 'Desired amount of destination token to receive',
85
+ },
86
+ },
87
+ required: ['fromToken', 'toToken', 'amount'],
88
+ },
89
+ handler: withErrorHandling(async (sdk, args) => {
90
+ const quote = await sdk.getSwapQuoteExactOutput(args.fromToken, args.toToken, args.amount);
91
+ return formatSuccess({
92
+ fromToken: quote.fromToken,
93
+ toToken: quote.toToken,
94
+ inputAmount: quote.inputAmount,
95
+ estimatedOutput: quote.estimatedOutput,
96
+ feeTier: quote.feeTier,
97
+ priceImpact: quote.priceImpact,
98
+ executionPrice: quote.executionPrice,
99
+ message: `Spending ~${quote.inputAmount} ${quote.fromToken}, receiving ${quote.estimatedOutput} ${quote.toToken}`,
100
+ });
101
+ }),
102
+ };
103
+
104
+ // 3. Execute Swap
105
+ export const executeSwapTool: MCPTool = {
106
+ name: 'gala_launchpad_execute_swap',
107
+ description:
108
+ 'Execute a token swap on GalaSwap DEX with slippage protection. Get a quote first using getSwapQuote tools.',
109
+ inputSchema: {
110
+ type: 'object',
111
+ properties: {
112
+ fromToken: TOKEN_SYMBOL_SCHEMA,
113
+ toToken: TOKEN_SYMBOL_SCHEMA,
114
+ inputAmount: {
115
+ ...DECIMAL_AMOUNT_SCHEMA,
116
+ description: 'Amount of source token to spend',
117
+ },
118
+ estimatedOutput: {
119
+ ...DECIMAL_AMOUNT_SCHEMA,
120
+ description: 'Expected output amount from quote (for slippage calculation)',
121
+ },
122
+ feeTier: FEE_TIER_SCHEMA,
123
+ slippageTolerance: {
124
+ ...SLIPPAGE_TOLERANCE_SCHEMA,
125
+ default: 0.01,
126
+ },
127
+ },
128
+ required: ['fromToken', 'toToken', 'inputAmount', 'estimatedOutput', 'feeTier'],
129
+ },
130
+ handler: withErrorHandling(async (sdk, args) => {
131
+ // Validate wallet before execution by trying to get address
132
+ try {
133
+ sdk.getAddress();
134
+ } catch {
135
+ throw new Error('Wallet not configured - required for swap execution');
136
+ }
137
+
138
+ const result = await sdk.executeSwap(
139
+ args.fromToken,
140
+ args.toToken,
141
+ args.inputAmount,
142
+ args.estimatedOutput,
143
+ args.feeTier,
144
+ args.slippageTolerance || 0.01
145
+ );
146
+
147
+ return formatSuccess({
148
+ transactionId: result.transactionId,
149
+ status: result.status,
150
+ fromToken: result.fromToken,
151
+ toToken: result.toToken,
152
+ inputAmount: result.inputAmount,
153
+ outputAmount: result.outputAmount,
154
+ feeTier: result.feeTier,
155
+ slippageTolerance: result.slippageTolerance,
156
+ timestamp: result.timestamp.toISOString(),
157
+ message: `Swap completed! Sent ${result.inputAmount} ${result.fromToken}, received ${result.outputAmount} ${result.toToken}`,
158
+ });
159
+ }),
160
+ };
161
+
162
+ // 4. Get User Assets
163
+ export const getSwapUserAssetsTool: MCPTool = {
164
+ name: 'gala_launchpad_get_swap_user_assets',
165
+ description: 'Get all token assets and balances for a wallet address',
166
+ inputSchema: {
167
+ type: 'object',
168
+ properties: {
169
+ walletAddress: {
170
+ ...ADDRESS_SCHEMA,
171
+ description: 'Wallet address to query (e.g., "0x1234..." or "eth|1234...")',
172
+ },
173
+ },
174
+ required: ['walletAddress'],
175
+ },
176
+ handler: withErrorHandling(async (sdk, args) => {
177
+ const assets = await sdk.getSwapUserAssets(args.walletAddress);
178
+ return formatSuccess({
179
+ walletAddress: args.walletAddress,
180
+ assetCount: assets.length,
181
+ assets: assets.map((asset) => ({
182
+ symbol: asset.symbol,
183
+ balance: asset.balance,
184
+ decimals: asset.decimals,
185
+ })),
186
+ message: `${assets.length} assets found for wallet ${args.walletAddress}`,
187
+ });
188
+ }),
189
+ };
190
+
191
+ // 5. Get Pool Info
192
+ export const getSwapPoolInfoTool: MCPTool = {
193
+ name: 'gala_launchpad_get_swap_pool_info',
194
+ description:
195
+ 'Get liquidity and fee tier information for a token pair on GalaSwap DEX',
196
+ inputSchema: {
197
+ type: 'object',
198
+ properties: {
199
+ tokenA: TOKEN_SYMBOL_SCHEMA,
200
+ tokenB: TOKEN_SYMBOL_SCHEMA,
201
+ },
202
+ required: ['tokenA', 'tokenB'],
203
+ },
204
+ handler: withErrorHandling(async (sdk, args) => {
205
+ const poolInfo = await sdk.getSwapPoolInfo(args.tokenA, args.tokenB);
206
+ return formatSuccess({
207
+ tokenA: poolInfo.tokenA,
208
+ tokenB: poolInfo.tokenB,
209
+ liquidity: poolInfo.liquidity,
210
+ feeTiers: poolInfo.feeTiers,
211
+ feeTiersFormatted: poolInfo.feeTiers.map((tier) => `${tier / 100}%`),
212
+ swapCount: poolInfo.swapCount,
213
+ message: `Pool ${args.tokenA}/${args.tokenB} has ${poolInfo.liquidity} liquidity with ${poolInfo.feeTiers.length} fee tiers`,
214
+ });
215
+ }),
216
+ };
217
+
218
+ // Export all DEX tools (5 swap tools + 8 liquidity position tools = 13 tools)
219
+ export const dexTools: MCPTool[] = [
220
+ getSwapQuoteExactInputTool,
221
+ getSwapQuoteExactOutputTool,
222
+ executeSwapTool,
223
+ getSwapUserAssetsTool,
224
+ getSwapPoolInfoTool,
225
+ ...liquidityPositionTools,
226
+ ];