@gala-chain/launchpad-mcp-server 1.24.1 → 1.27.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 (106) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +103 -3
  3. package/dist/constants/mcpToolNames.d.ts +6 -2
  4. package/dist/constants/mcpToolNames.d.ts.map +1 -1
  5. package/dist/constants/mcpToolNames.js +4 -2
  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/tools/index.d.ts +2 -2
  10. package/dist/tools/index.js +3 -3
  11. package/dist/tools/pools/index.d.ts.map +1 -1
  12. package/dist/tools/pools/index.js +4 -0
  13. package/dist/tools/pools/index.js.map +1 -1
  14. package/dist/tools/pools/onDexPoolCreation.d.ts +6 -0
  15. package/dist/tools/pools/onDexPoolCreation.d.ts.map +1 -0
  16. package/dist/tools/pools/onDexPoolCreation.js +58 -0
  17. package/dist/tools/pools/onDexPoolCreation.js.map +1 -0
  18. package/dist/tools/pools/onLaunchpadTokenCreation.d.ts +6 -0
  19. package/dist/tools/pools/onLaunchpadTokenCreation.d.ts.map +1 -0
  20. package/dist/tools/pools/onLaunchpadTokenCreation.js +52 -0
  21. package/dist/tools/pools/onLaunchpadTokenCreation.js.map +1 -0
  22. package/package.json +3 -3
  23. package/docs/AI-AGENT-PATTERNS.md +0 -555
  24. package/docs/CONSTRAINTS-REFERENCE.md +0 -454
  25. package/docs/PROMPT-TOOL-MAPPING.md +0 -352
  26. package/docs/examples/default-values-pattern.md +0 -240
  27. package/docs/examples/tool-factory-pattern.md +0 -217
  28. package/jest.config.js +0 -94
  29. package/src/__tests__/integration/fetchTokenDetails.integration.test.ts +0 -258
  30. package/src/__tests__/integration/poolTools.integration.test.ts +0 -185
  31. package/src/__tests__/server.test.ts +0 -255
  32. package/src/constants/mcpToolNames.ts +0 -183
  33. package/src/index.ts +0 -19
  34. package/src/prompts/__tests__/promptStructure.test.ts +0 -187
  35. package/src/prompts/__tests__/registry.test.ts +0 -349
  36. package/src/prompts/analysis.ts +0 -380
  37. package/src/prompts/balances.ts +0 -182
  38. package/src/prompts/create-token.ts +0 -123
  39. package/src/prompts/creation-utils.ts +0 -103
  40. package/src/prompts/dex-trading.ts +0 -86
  41. package/src/prompts/discover-tokens.ts +0 -86
  42. package/src/prompts/explore-dex-pools.ts +0 -138
  43. package/src/prompts/index.ts +0 -178
  44. package/src/prompts/liquidity-positions.ts +0 -237
  45. package/src/prompts/pools.ts +0 -496
  46. package/src/prompts/portfolio.ts +0 -208
  47. package/src/prompts/social.ts +0 -94
  48. package/src/prompts/trading-calculations.ts +0 -414
  49. package/src/prompts/trading.ts +0 -160
  50. package/src/prompts/transfers.ts +0 -97
  51. package/src/prompts/utility-tools.ts +0 -266
  52. package/src/prompts/utility.ts +0 -77
  53. package/src/prompts/utils/handlerHelpers.ts +0 -55
  54. package/src/prompts/utils/textTemplates.ts +0 -73
  55. package/src/prompts/utils/workflowTemplates.ts +0 -511
  56. package/src/schemas/common-schemas.ts +0 -393
  57. package/src/scripts/test-all-prompts.ts +0 -184
  58. package/src/server.ts +0 -367
  59. package/src/tools/__tests__/dex-tools.test.ts +0 -562
  60. package/src/tools/__tests__/liquidity-positions.test.ts +0 -673
  61. package/src/tools/balance/index.ts +0 -174
  62. package/src/tools/creation/index.ts +0 -182
  63. package/src/tools/dex/fetchAllDexPools.ts +0 -45
  64. package/src/tools/dex/fetchDexPools.ts +0 -58
  65. package/src/tools/dex/index.ts +0 -231
  66. package/src/tools/dex/liquidity-positions.ts +0 -547
  67. package/src/tools/index.ts +0 -94
  68. package/src/tools/pools/fetchAllPools.ts +0 -47
  69. package/src/tools/pools/fetchAllPriceHistory.ts +0 -119
  70. package/src/tools/pools/fetchPoolDetails.ts +0 -27
  71. package/src/tools/pools/fetchPoolDetailsForCalculation.ts +0 -22
  72. package/src/tools/pools/fetchPools.ts +0 -47
  73. package/src/tools/pools/fetchPriceHistory.ts +0 -124
  74. package/src/tools/pools/fetchTokenDetails.ts +0 -77
  75. package/src/tools/pools/index.ts +0 -284
  76. package/src/tools/social/index.ts +0 -64
  77. package/src/tools/trading/index.ts +0 -605
  78. package/src/tools/transfers/index.ts +0 -75
  79. package/src/tools/utils/clearCache.ts +0 -36
  80. package/src/tools/utils/createWallet.ts +0 -19
  81. package/src/tools/utils/explainSdkUsage.ts +0 -1446
  82. package/src/tools/utils/getAddress.ts +0 -12
  83. package/src/tools/utils/getCacheInfo.ts +0 -14
  84. package/src/tools/utils/getConfig.ts +0 -21
  85. package/src/tools/utils/getEnvironment.ts +0 -17
  86. package/src/tools/utils/getEthereumAddress.ts +0 -12
  87. package/src/tools/utils/getUrlByTokenName.ts +0 -12
  88. package/src/tools/utils/getVersion.ts +0 -25
  89. package/src/tools/utils/getWallet.ts +0 -25
  90. package/src/tools/utils/hasWallet.ts +0 -15
  91. package/src/tools/utils/index.ts +0 -37
  92. package/src/tools/utils/isTokenGraduated.ts +0 -16
  93. package/src/tools/utils/setWallet.ts +0 -41
  94. package/src/tools/utils/switchEnvironment.ts +0 -28
  95. package/src/types/mcp.ts +0 -72
  96. package/src/utils/__tests__/validation.test.ts +0 -147
  97. package/src/utils/constraints.ts +0 -155
  98. package/src/utils/default-values.ts +0 -208
  99. package/src/utils/error-handler.ts +0 -69
  100. package/src/utils/error-templates.ts +0 -273
  101. package/src/utils/response-formatter.ts +0 -51
  102. package/src/utils/tool-factory.ts +0 -303
  103. package/src/utils/tool-registry.ts +0 -296
  104. package/src/utils/validation.ts +0 -429
  105. package/tests/wallet-management-integration.test.ts +0 -284
  106. package/tsconfig.json +0 -23
@@ -1,673 +0,0 @@
1
- /**
2
- * Unit Tests for Liquidity Position Management MCP Tools
3
- *
4
- * Tests the MCP tools for managing GalaSwap liquidity positions including:
5
- * - Fetching user positions (all, by ID, by token pair)
6
- * - Creating liquidity positions (by price or tick)
7
- * - Estimating and removing liquidity
8
- * - Collecting accumulated fees
9
- */
10
-
11
- import {
12
- getUserLiquidityPositionsTool,
13
- getLiquidityPositionByIdTool,
14
- getLiquidityPositionTool,
15
- addLiquidityByPriceTool,
16
- addLiquidityByTicksTool,
17
- estimateRemoveLiquidityTool,
18
- removeLiquidityTool,
19
- collectPositionFeesTool,
20
- } from '../dex/liquidity-positions';
21
-
22
- /**
23
- * Mock LaunchpadSDK with all liquidity position methods
24
- */
25
- const mockSdk = {
26
- getSwapUserLiquidityPositions: jest.fn(),
27
- getSwapLiquidityPositionById: jest.fn(),
28
- getSwapLiquidityPosition: jest.fn(),
29
- addSwapLiquidityByPrice: jest.fn(),
30
- addSwapLiquidityByTicks: jest.fn(),
31
- getSwapEstimateRemoveLiquidity: jest.fn(),
32
- removeSwapLiquidity: jest.fn(),
33
- collectSwapPositionFees: jest.fn(),
34
- getAddress: jest.fn(() => 'eth|0x1234567890abcdef1234567890abcdef12345678'),
35
- };
36
-
37
- describe('Liquidity Position Management MCP Tools', () => {
38
- beforeEach(() => {
39
- jest.clearAllMocks();
40
- });
41
-
42
- describe('getUserLiquidityPositionsTool', () => {
43
- it('should be properly configured tool', () => {
44
- expect(getUserLiquidityPositionsTool).toBeDefined();
45
- expect(getUserLiquidityPositionsTool.name).toBe('gala_launchpad_get_user_liquidity_positions');
46
- expect(getUserLiquidityPositionsTool.description).toContain('liquidity positions');
47
- });
48
-
49
- it('should have correct input schema', () => {
50
- const schema = getUserLiquidityPositionsTool.inputSchema as any;
51
- expect(schema.type).toBe('object');
52
- expect(schema.properties).toHaveProperty('ownerAddress');
53
- expect(schema.required).toContain('ownerAddress');
54
- });
55
-
56
- it('should return formatted positions response', async () => {
57
- const mockPositions = [
58
- {
59
- positionId: 'pos-1',
60
- ownerAddress: 'eth|0x1234567890abcdef1234567890abcdef12345678',
61
- token0: 'GALA|Unit|none|none',
62
- token1: 'GUSDC|Unit|none|none',
63
- feeTier: 3000,
64
- liquidity: '1000000000',
65
- amount0: '5000',
66
- amount1: '5000',
67
- tickLower: -276320,
68
- tickUpper: -276000,
69
- feeAmount0: '50',
70
- feeAmount1: '50',
71
- },
72
- ];
73
-
74
- mockSdk.getSwapUserLiquidityPositions.mockResolvedValueOnce(mockPositions);
75
-
76
- const handler = getUserLiquidityPositionsTool.handler as any;
77
- const result = await handler(mockSdk, {
78
- ownerAddress: 'eth|0x1234567890abcdef1234567890abcdef12345678',
79
- limit: 10,
80
- });
81
-
82
- expect(result).toBeDefined();
83
- expect(result.content).toBeDefined();
84
- expect(result.content[0].type).toBe('text');
85
- expect(result.content[0].text).toContain('1');
86
- });
87
-
88
- it('should handle empty positions list', async () => {
89
- mockSdk.getSwapUserLiquidityPositions.mockResolvedValueOnce([]);
90
-
91
- const handler = getUserLiquidityPositionsTool.handler as any;
92
- const result = await handler(mockSdk, {
93
- ownerAddress: 'eth|0x1234567890abcdef1234567890abcdef12345678',
94
- });
95
-
96
- expect(result).toBeDefined();
97
- expect(result.content[0].text).toContain('0');
98
- });
99
-
100
- it('should handle position query errors', async () => {
101
- mockSdk.getSwapUserLiquidityPositions.mockRejectedValueOnce(
102
- new Error('Network error')
103
- );
104
-
105
- const handler = getUserLiquidityPositionsTool.handler as any;
106
-
107
- try {
108
- await handler(mockSdk, {
109
- ownerAddress: 'eth|0x1234567890abcdef1234567890abcdef12345678',
110
- });
111
- throw new Error('Should have thrown error');
112
- } catch (error) {
113
- expect(error).toBeDefined();
114
- }
115
- });
116
- });
117
-
118
- describe('getLiquidityPositionByIdTool', () => {
119
- it('should be properly configured tool', () => {
120
- expect(getLiquidityPositionByIdTool).toBeDefined();
121
- expect(getLiquidityPositionByIdTool.name).toBe('gala_launchpad_get_liquidity_position_by_id');
122
- expect(getLiquidityPositionByIdTool.description).toContain('position');
123
- });
124
-
125
- it('should have correct input schema with ownerAddress and positionId', () => {
126
- const schema = getLiquidityPositionByIdTool.inputSchema as any;
127
- expect(schema.properties).toHaveProperty('ownerAddress');
128
- expect(schema.properties).toHaveProperty('positionId');
129
- expect(schema.required).toEqual(['ownerAddress', 'positionId']);
130
- });
131
-
132
- it('should return specific position by ID', async () => {
133
- const mockPosition = {
134
- positionId: 'pos-123',
135
- ownerAddress: 'eth|0x1234567890abcdef1234567890abcdef12345678',
136
- token0: 'GALA|Unit|none|none',
137
- token1: 'GUSDC|Unit|none|none',
138
- feeTier: 3000,
139
- liquidity: '1000000000',
140
- amount0: '5000',
141
- amount1: '5000',
142
- tickLower: -276320,
143
- tickUpper: -276000,
144
- feeAmount0: '50',
145
- feeAmount1: '50',
146
- };
147
-
148
- mockSdk.getSwapLiquidityPositionById.mockResolvedValueOnce(mockPosition);
149
-
150
- const handler = getLiquidityPositionByIdTool.handler as any;
151
- const result = await handler(mockSdk, {
152
- ownerAddress: 'eth|0x1234567890abcdef1234567890abcdef12345678',
153
- positionId: 'pos-123',
154
- });
155
-
156
- expect(result).toBeDefined();
157
- expect(result.content[0].text).toContain('pos-123');
158
- });
159
-
160
- it('should handle position not found error', async () => {
161
- mockSdk.getSwapLiquidityPositionById.mockRejectedValueOnce(
162
- new Error('Position not found')
163
- );
164
-
165
- const handler = getLiquidityPositionByIdTool.handler as any;
166
-
167
- try {
168
- await handler(mockSdk, {
169
- ownerAddress: 'eth|0x1234567890abcdef1234567890abcdef12345678',
170
- positionId: 'invalid-id',
171
- });
172
- throw new Error('Should have thrown error');
173
- } catch (error) {
174
- expect(error).toBeDefined();
175
- }
176
- });
177
- });
178
-
179
- describe('getLiquidityPositionTool', () => {
180
- it('should be properly configured tool', () => {
181
- expect(getLiquidityPositionTool).toBeDefined();
182
- expect(getLiquidityPositionTool.name).toBe('gala_launchpad_get_liquidity_position');
183
- });
184
-
185
- it('should have correct input schema with position details', () => {
186
- const schema = getLiquidityPositionTool.inputSchema as any;
187
- expect(schema.properties).toHaveProperty('ownerAddress');
188
- expect(schema.properties).toHaveProperty('token0');
189
- expect(schema.properties).toHaveProperty('token1');
190
- expect(schema.properties).toHaveProperty('fee');
191
- expect(schema.properties).toHaveProperty('tickLower');
192
- expect(schema.properties).toHaveProperty('tickUpper');
193
- });
194
-
195
- it('should return position by token pair and tick range', async () => {
196
- const mockPosition = {
197
- positionId: 'pos-456',
198
- token0: 'GALA|Unit|none|none',
199
- token1: 'GUSDC|Unit|none|none',
200
- feeTier: 3000,
201
- liquidity: '1000000000',
202
- };
203
-
204
- mockSdk.getSwapLiquidityPosition.mockResolvedValueOnce(mockPosition);
205
-
206
- const handler = getLiquidityPositionTool.handler as any;
207
- const result = await handler(mockSdk, {
208
- ownerAddress: 'eth|0x1234567890abcdef1234567890abcdef12345678',
209
- token0: 'GALA',
210
- token1: 'GUSDC',
211
- fee: 3000,
212
- tickLower: -276320,
213
- tickUpper: -276000,
214
- });
215
-
216
- expect(result).toBeDefined();
217
- expect(result.content[0].text).toContain('GALA');
218
- });
219
- });
220
-
221
- describe('estimateRemoveLiquidityTool', () => {
222
- it('should be properly configured tool', () => {
223
- expect(estimateRemoveLiquidityTool).toBeDefined();
224
- expect(estimateRemoveLiquidityTool.name).toBe('gala_launchpad_estimate_remove_liquidity');
225
- expect(estimateRemoveLiquidityTool.description).toMatch(/[Ee]stimate/);
226
- });
227
-
228
- it('should have correct input schema', () => {
229
- const schema = estimateRemoveLiquidityTool.inputSchema as any;
230
- expect(schema.properties).toHaveProperty('token0');
231
- expect(schema.properties).toHaveProperty('token1');
232
- expect(schema.properties).toHaveProperty('fee');
233
- expect(schema.properties).toHaveProperty('liquidity');
234
- expect(schema.properties).toHaveProperty('tickLower');
235
- expect(schema.properties).toHaveProperty('tickUpper');
236
- });
237
-
238
- it('should return estimated removal amounts', async () => {
239
- const mockEstimate = {
240
- amount0: '5000',
241
- amount1: '5000',
242
- fee0: '50',
243
- fee1: '50',
244
- };
245
-
246
- mockSdk.getSwapEstimateRemoveLiquidity.mockResolvedValueOnce(mockEstimate);
247
-
248
- const handler = estimateRemoveLiquidityTool.handler as any;
249
- const result = await handler(mockSdk, {
250
- token0: 'GALA',
251
- token1: 'GUSDC',
252
- fee: 3000,
253
- liquidity: '1000000000',
254
- tickLower: -276320,
255
- tickUpper: -276000,
256
- });
257
-
258
- expect(result).toBeDefined();
259
- expect(result.content[0].text).toContain('5000');
260
- });
261
-
262
- it('should handle estimation with partial removal', async () => {
263
- const mockEstimate = {
264
- amount0: '2500',
265
- amount1: '2500',
266
- fee0: '25',
267
- fee1: '25',
268
- };
269
-
270
- mockSdk.getSwapEstimateRemoveLiquidity.mockResolvedValueOnce(mockEstimate);
271
-
272
- const handler = estimateRemoveLiquidityTool.handler as any;
273
- const result = await handler(mockSdk, {
274
- token0: 'GALA',
275
- token1: 'GUSDC',
276
- fee: 3000,
277
- liquidity: '500000000', // Half the original
278
- tickLower: -276320,
279
- tickUpper: -276000,
280
- });
281
-
282
- expect(result).toBeDefined();
283
- expect(result.content[0].text).toContain('2500');
284
- });
285
-
286
- it('should handle estimation errors', async () => {
287
- mockSdk.getSwapEstimateRemoveLiquidity.mockRejectedValueOnce(
288
- new Error('Invalid position')
289
- );
290
-
291
- const handler = estimateRemoveLiquidityTool.handler as any;
292
-
293
- try {
294
- await handler(mockSdk, {
295
- token0: 'INVALID',
296
- token1: 'INVALID',
297
- fee: 3000,
298
- liquidity: '1000000000',
299
- tickLower: -276320,
300
- tickUpper: -276000,
301
- });
302
- throw new Error('Should have thrown error');
303
- } catch (error) {
304
- expect(error).toBeDefined();
305
- }
306
- });
307
- });
308
-
309
- describe('addLiquidityByPriceTool', () => {
310
- it('should be properly configured tool', () => {
311
- expect(addLiquidityByPriceTool).toBeDefined();
312
- expect(addLiquidityByPriceTool.name).toBe('gala_launchpad_add_liquidity_by_price');
313
- expect(addLiquidityByPriceTool.description).toContain('price');
314
- });
315
-
316
- it('should have correct input schema with price range parameters', () => {
317
- const schema = addLiquidityByPriceTool.inputSchema as any;
318
- expect(schema.properties).toHaveProperty('token0');
319
- expect(schema.properties).toHaveProperty('token1');
320
- expect(schema.properties).toHaveProperty('fee');
321
- expect(schema.properties).toHaveProperty('minPrice');
322
- expect(schema.properties).toHaveProperty('maxPrice');
323
- expect(schema.properties).toHaveProperty('amount0Desired');
324
- expect(schema.properties).toHaveProperty('amount1Desired');
325
- });
326
-
327
- it('should create liquidity position using price range', async () => {
328
- const mockResult = {
329
- transactionId: 'tx-123',
330
- positionId: 'pos-789',
331
- token0: 'GALA',
332
- token1: 'GUSDC',
333
- amount0: '5000',
334
- amount1: '5000',
335
- };
336
-
337
- mockSdk.addSwapLiquidityByPrice.mockResolvedValueOnce(mockResult);
338
-
339
- const handler = addLiquidityByPriceTool.handler as any;
340
- const result = await handler(mockSdk, {
341
- token0: 'GALA',
342
- token1: 'GUSDC',
343
- fee: 3000,
344
- minPrice: '0.95',
345
- maxPrice: '1.05',
346
- amount0Desired: '5000',
347
- amount1Desired: '5000',
348
- });
349
-
350
- expect(result).toBeDefined();
351
- expect(result.content[0].text).toContain('tx-123');
352
- });
353
-
354
- it('should handle slippage protection in liquidity creation', async () => {
355
- const mockResult = {
356
- transactionId: 'tx-456',
357
- positionId: 'pos-101112',
358
- };
359
-
360
- mockSdk.addSwapLiquidityByPrice.mockResolvedValueOnce(mockResult);
361
-
362
- const handler = addLiquidityByPriceTool.handler as any;
363
- const result = await handler(mockSdk, {
364
- token0: 'GALA',
365
- token1: 'GUSDC',
366
- fee: 3000,
367
- minPrice: '0.90',
368
- maxPrice: '1.10',
369
- amount0Desired: '10000',
370
- amount1Desired: '10000',
371
- amount0Min: '9000',
372
- amount1Min: '9000',
373
- });
374
-
375
- expect(result).toBeDefined();
376
- expect(result.content[0].text).toContain('tx-456');
377
- });
378
-
379
- it('should handle liquidity creation errors', async () => {
380
- mockSdk.addSwapLiquidityByPrice.mockRejectedValueOnce(
381
- new Error('Insufficient balance')
382
- );
383
-
384
- const handler = addLiquidityByPriceTool.handler as any;
385
-
386
- try {
387
- await handler(mockSdk, {
388
- token0: 'GALA',
389
- token1: 'GUSDC',
390
- fee: 3000,
391
- minPrice: '0.95',
392
- maxPrice: '1.05',
393
- amount0Desired: '1000000000', // Too large
394
- amount1Desired: '1000000000',
395
- });
396
- throw new Error('Should have thrown error');
397
- } catch (error) {
398
- expect(error).toBeDefined();
399
- }
400
- });
401
- });
402
-
403
- describe('addLiquidityByTicksTool', () => {
404
- it('should be properly configured tool', () => {
405
- expect(addLiquidityByTicksTool).toBeDefined();
406
- expect(addLiquidityByTicksTool.name).toBe('gala_launchpad_add_liquidity_by_ticks');
407
- expect(addLiquidityByTicksTool.description).toContain('tick');
408
- });
409
-
410
- it('should have correct input schema with tick parameters', () => {
411
- const schema = addLiquidityByTicksTool.inputSchema as any;
412
- expect(schema.properties).toHaveProperty('token0');
413
- expect(schema.properties).toHaveProperty('token1');
414
- expect(schema.properties).toHaveProperty('feeTier');
415
- expect(schema.properties).toHaveProperty('tickLower');
416
- expect(schema.properties).toHaveProperty('tickUpper');
417
- expect(schema.properties).toHaveProperty('amount0Desired');
418
- expect(schema.properties).toHaveProperty('amount1Desired');
419
- });
420
-
421
- it('should create liquidity position using precise tick boundaries', async () => {
422
- const mockResult = {
423
- transactionId: 'tx-789',
424
- positionId: 'pos-131415',
425
- token0: 'GALA',
426
- token1: 'GUSDC',
427
- };
428
-
429
- mockSdk.addSwapLiquidityByTicks.mockResolvedValueOnce(mockResult);
430
-
431
- const handler = addLiquidityByTicksTool.handler as any;
432
- const result = await handler(mockSdk, {
433
- token0: 'GALA',
434
- token1: 'GUSDC',
435
- feeTier: 3000,
436
- tickLower: -276320,
437
- tickUpper: -276000,
438
- amount0Desired: '5000',
439
- amount1Desired: '5000',
440
- });
441
-
442
- expect(result).toBeDefined();
443
- expect(result.content[0].text).toContain('tx-789');
444
- });
445
- });
446
-
447
- describe('removeLiquidityTool', () => {
448
- it('should be properly configured tool', () => {
449
- expect(removeLiquidityTool).toBeDefined();
450
- expect(removeLiquidityTool.name).toBe('gala_launchpad_remove_liquidity');
451
- expect(removeLiquidityTool.description).toMatch(/[Rr]emove/);
452
- });
453
-
454
- it('should have correct input schema with removal parameters', () => {
455
- const schema = removeLiquidityTool.inputSchema as any;
456
- expect(schema.properties).toHaveProperty('ownerAddress');
457
- expect(schema.properties).toHaveProperty('positionId');
458
- expect(schema.properties).toHaveProperty('liquidity');
459
- expect(schema.properties).toHaveProperty('amount0Min');
460
- expect(schema.properties).toHaveProperty('amount1Min');
461
- expect(schema.properties).toHaveProperty('deadline');
462
- });
463
-
464
- it('should remove liquidity from position', async () => {
465
- const mockResult = {
466
- transactionId: 'tx-remove-1',
467
- amount0: '5000',
468
- amount1: '5000',
469
- fee0: '50',
470
- fee1: '50',
471
- };
472
-
473
- mockSdk.removeSwapLiquidity.mockResolvedValueOnce(mockResult);
474
-
475
- const handler = removeLiquidityTool.handler as any;
476
- const result = await handler(mockSdk, {
477
- ownerAddress: 'eth|0x1234567890abcdef1234567890abcdef12345678',
478
- positionId: 'pos-789',
479
- liquidity: '1000000000',
480
- amount0Min: '0',
481
- amount1Min: '0',
482
- deadline: Math.floor(Date.now() / 1000) + 3600,
483
- });
484
-
485
- expect(result).toBeDefined();
486
- expect(result.content[0].text).toContain('tx-remove-1');
487
- });
488
-
489
- it('should handle partial liquidity removal', async () => {
490
- const mockResult = {
491
- transactionId: 'tx-remove-2',
492
- amount0: '2500',
493
- amount1: '2500',
494
- };
495
-
496
- mockSdk.removeSwapLiquidity.mockResolvedValueOnce(mockResult);
497
-
498
- const handler = removeLiquidityTool.handler as any;
499
- const result = await handler(mockSdk, {
500
- ownerAddress: 'eth|0x1234567890abcdef1234567890abcdef12345678',
501
- positionId: 'pos-789',
502
- liquidity: '500000000', // Half
503
- amount0Min: '0',
504
- amount1Min: '0',
505
- deadline: Math.floor(Date.now() / 1000) + 3600,
506
- });
507
-
508
- expect(result).toBeDefined();
509
- expect(result.content[0].text).toContain('2500');
510
- });
511
-
512
- it('should handle removal errors', async () => {
513
- mockSdk.removeSwapLiquidity.mockRejectedValueOnce(
514
- new Error('Position not found')
515
- );
516
-
517
- const handler = removeLiquidityTool.handler as any;
518
-
519
- try {
520
- await handler(mockSdk, {
521
- ownerAddress: 'eth|0x1234567890abcdef1234567890abcdef12345678',
522
- positionId: 'invalid',
523
- liquidity: '1000000000',
524
- amount0Min: '0',
525
- amount1Min: '0',
526
- deadline: Math.floor(Date.now() / 1000) + 3600,
527
- });
528
- throw new Error('Should have thrown error');
529
- } catch (error) {
530
- expect(error).toBeDefined();
531
- }
532
- });
533
- });
534
-
535
- describe('collectPositionFeesTool', () => {
536
- it('should be properly configured tool', () => {
537
- expect(collectPositionFeesTool).toBeDefined();
538
- expect(collectPositionFeesTool.name).toBe('gala_launchpad_collect_position_fees');
539
- expect(collectPositionFeesTool.description).toContain('fees');
540
- });
541
-
542
- it('should have correct input schema with position identification', () => {
543
- const schema = collectPositionFeesTool.inputSchema as any;
544
- expect(schema.properties).toHaveProperty('ownerAddress');
545
- expect(schema.properties).toHaveProperty('positionId');
546
- expect(schema.required).toEqual(['ownerAddress', 'positionId']);
547
- });
548
-
549
- it('should collect accumulated trading fees from position', async () => {
550
- const mockResult = {
551
- transactionId: 'tx-collect-1',
552
- feeAmount0: '50',
553
- feeAmount1: '50',
554
- };
555
-
556
- mockSdk.collectSwapPositionFees.mockResolvedValueOnce(mockResult);
557
-
558
- const handler = collectPositionFeesTool.handler as any;
559
- const result = await handler(mockSdk, {
560
- ownerAddress: 'eth|0x1234567890abcdef1234567890abcdef12345678',
561
- positionId: 'pos-789',
562
- });
563
-
564
- expect(result).toBeDefined();
565
- expect(result.content[0].text).toContain('tx-collect-1');
566
- });
567
-
568
- it('should handle fee collection when no fees accumulated', async () => {
569
- const mockResult = {
570
- transactionId: 'tx-collect-2',
571
- feeAmount0: '0',
572
- feeAmount1: '0',
573
- };
574
-
575
- mockSdk.collectSwapPositionFees.mockResolvedValueOnce(mockResult);
576
-
577
- const handler = collectPositionFeesTool.handler as any;
578
- const result = await handler(mockSdk, {
579
- ownerAddress: 'eth|0x1234567890abcdef1234567890abcdef12345678',
580
- positionId: 'pos-no-fees',
581
- });
582
-
583
- expect(result).toBeDefined();
584
- expect(result.content[0].text).toContain('0');
585
- });
586
-
587
- it('should handle fee collection errors', async () => {
588
- mockSdk.collectSwapPositionFees.mockRejectedValueOnce(
589
- new Error('Cannot collect from closed position')
590
- );
591
-
592
- const handler = collectPositionFeesTool.handler as any;
593
-
594
- try {
595
- await handler(mockSdk, {
596
- ownerAddress: 'eth|0x1234567890abcdef1234567890abcdef12345678',
597
- positionId: 'closed-position',
598
- });
599
- throw new Error('Should have thrown error');
600
- } catch (error) {
601
- expect(error).toBeDefined();
602
- }
603
- });
604
- });
605
-
606
- describe('Tool Integration', () => {
607
- it('should export all 8 liquidity position tools', () => {
608
- expect(getUserLiquidityPositionsTool).toBeDefined();
609
- expect(getLiquidityPositionByIdTool).toBeDefined();
610
- expect(getLiquidityPositionTool).toBeDefined();
611
- expect(addLiquidityByPriceTool).toBeDefined();
612
- expect(addLiquidityByTicksTool).toBeDefined();
613
- expect(estimateRemoveLiquidityTool).toBeDefined();
614
- expect(removeLiquidityTool).toBeDefined();
615
- expect(collectPositionFeesTool).toBeDefined();
616
- });
617
-
618
- it('should have unique tool names', () => {
619
- const tools = [
620
- getUserLiquidityPositionsTool,
621
- getLiquidityPositionByIdTool,
622
- getLiquidityPositionTool,
623
- addLiquidityByPriceTool,
624
- addLiquidityByTicksTool,
625
- estimateRemoveLiquidityTool,
626
- removeLiquidityTool,
627
- collectPositionFeesTool,
628
- ];
629
-
630
- const names = tools.map((t) => t.name);
631
- const uniqueNames = new Set(names);
632
- expect(uniqueNames.size).toBe(8);
633
- });
634
-
635
- it('should have descriptions for all tools', () => {
636
- const tools = [
637
- getUserLiquidityPositionsTool,
638
- getLiquidityPositionByIdTool,
639
- getLiquidityPositionTool,
640
- addLiquidityByPriceTool,
641
- addLiquidityByTicksTool,
642
- estimateRemoveLiquidityTool,
643
- removeLiquidityTool,
644
- collectPositionFeesTool,
645
- ];
646
-
647
- tools.forEach((tool) => {
648
- expect(tool.description).toBeDefined();
649
- expect(tool.description.length).toBeGreaterThan(0);
650
- });
651
- });
652
-
653
- it('should have input schemas for all tools', () => {
654
- const tools = [
655
- getUserLiquidityPositionsTool,
656
- getLiquidityPositionByIdTool,
657
- getLiquidityPositionTool,
658
- addLiquidityByPriceTool,
659
- addLiquidityByTicksTool,
660
- estimateRemoveLiquidityTool,
661
- removeLiquidityTool,
662
- collectPositionFeesTool,
663
- ];
664
-
665
- tools.forEach((tool) => {
666
- expect(tool.inputSchema).toBeDefined();
667
- const schema = tool.inputSchema as any;
668
- expect(schema.type).toBe('object');
669
- expect(schema.properties).toBeDefined();
670
- });
671
- });
672
- });
673
- });