@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.
- package/CHANGELOG.md +118 -0
- package/README.md +83 -8
- package/dist/constants/mcpToolNames.d.ts +69 -11
- package/dist/constants/mcpToolNames.d.ts.map +1 -1
- package/dist/constants/mcpToolNames.js +47 -9
- package/dist/constants/mcpToolNames.js.map +1 -1
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/prompts/balances.d.ts +24 -0
- package/dist/prompts/balances.d.ts.map +1 -0
- package/dist/prompts/balances.js +191 -0
- package/dist/prompts/balances.js.map +1 -0
- package/dist/prompts/creation-utils.d.ts +20 -0
- package/dist/prompts/creation-utils.d.ts.map +1 -0
- package/dist/prompts/creation-utils.js +115 -0
- package/dist/prompts/creation-utils.js.map +1 -0
- package/dist/prompts/index.d.ts +9 -2
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +23 -2
- package/dist/prompts/index.js.map +1 -1
- package/dist/prompts/pools.d.ts +64 -0
- package/dist/prompts/pools.d.ts.map +1 -0
- package/dist/prompts/pools.js +548 -0
- package/dist/prompts/pools.js.map +1 -0
- package/dist/prompts/social.d.ts +16 -0
- package/dist/prompts/social.d.ts.map +1 -0
- package/dist/prompts/social.js +97 -0
- package/dist/prompts/social.js.map +1 -0
- package/dist/prompts/trading-calculations.d.ts +52 -0
- package/dist/prompts/trading-calculations.d.ts.map +1 -0
- package/dist/prompts/trading-calculations.js +479 -0
- package/dist/prompts/trading-calculations.js.map +1 -0
- package/dist/prompts/transfers.d.ts +16 -0
- package/dist/prompts/transfers.d.ts.map +1 -0
- package/dist/prompts/transfers.js +100 -0
- package/dist/prompts/transfers.js.map +1 -0
- package/dist/prompts/utility-tools.d.ts +56 -0
- package/dist/prompts/utility-tools.d.ts.map +1 -0
- package/dist/prompts/utility-tools.js +338 -0
- package/dist/prompts/utility-tools.js.map +1 -0
- package/docs/AI-AGENT-PATTERNS.md +555 -0
- package/docs/CONSTRAINTS-REFERENCE.md +454 -0
- package/docs/PROMPT-TOOL-MAPPING.md +352 -0
- package/docs/examples/default-values-pattern.md +240 -0
- package/docs/examples/tool-factory-pattern.md +217 -0
- package/jest.config.js +94 -0
- package/package.json +1 -1
- package/src/__tests__/integration/fetchTokenDetails.integration.test.ts +258 -0
- package/src/__tests__/integration/poolTools.integration.test.ts +185 -0
- package/src/__tests__/server.test.ts +256 -0
- package/src/constants/mcpToolNames.ts +181 -0
- package/src/index.ts +19 -0
- package/src/prompts/__tests__/promptStructure.test.ts +137 -0
- package/src/prompts/__tests__/registry.test.ts +359 -0
- package/src/prompts/analysis.ts +429 -0
- package/src/prompts/balances.ts +198 -0
- package/src/prompts/create-token.ts +123 -0
- package/src/prompts/creation-utils.ts +118 -0
- package/src/prompts/dex-trading.ts +86 -0
- package/src/prompts/discover-tokens.ts +86 -0
- package/src/prompts/index.ts +175 -0
- package/src/prompts/liquidity-positions.ts +270 -0
- package/src/prompts/pools.ts +571 -0
- package/src/prompts/portfolio.ts +242 -0
- package/src/prompts/social.ts +100 -0
- package/src/prompts/trading-calculations.ts +499 -0
- package/src/prompts/trading.ts +191 -0
- package/src/prompts/transfers.ts +103 -0
- package/src/prompts/utility-tools.ts +349 -0
- package/src/prompts/utility.ts +92 -0
- package/src/prompts/utils/workflowTemplates.ts +511 -0
- package/src/schemas/common-schemas.ts +393 -0
- package/src/scripts/test-all-prompts.ts +184 -0
- package/src/server.ts +367 -0
- package/src/tools/__tests__/dex-tools.test.ts +562 -0
- package/src/tools/__tests__/liquidity-positions.test.ts +673 -0
- package/src/tools/balance/index.ts +174 -0
- package/src/tools/creation/index.ts +182 -0
- package/src/tools/dex/index.ts +226 -0
- package/src/tools/dex/liquidity-positions.ts +547 -0
- package/src/tools/index.ts +94 -0
- package/src/tools/pools/fetchAllPools.ts +47 -0
- package/src/tools/pools/fetchAllPriceHistory.ts +119 -0
- package/src/tools/pools/fetchPoolDetails.ts +27 -0
- package/src/tools/pools/fetchPoolDetailsForCalculation.ts +22 -0
- package/src/tools/pools/fetchPools.ts +47 -0
- package/src/tools/pools/fetchPriceHistory.ts +124 -0
- package/src/tools/pools/fetchTokenDetails.ts +77 -0
- package/src/tools/pools/index.ts +284 -0
- package/src/tools/social/index.ts +64 -0
- package/src/tools/trading/index.ts +605 -0
- package/src/tools/transfers/index.ts +75 -0
- package/src/tools/utils/clearCache.ts +36 -0
- package/src/tools/utils/createWallet.ts +19 -0
- package/src/tools/utils/explainSdkUsage.ts +1446 -0
- package/src/tools/utils/getAddress.ts +12 -0
- package/src/tools/utils/getCacheInfo.ts +14 -0
- package/src/tools/utils/getConfig.ts +21 -0
- package/src/tools/utils/getEnvironment.ts +17 -0
- package/src/tools/utils/getEthereumAddress.ts +12 -0
- package/src/tools/utils/getUrlByTokenName.ts +12 -0
- package/src/tools/utils/getVersion.ts +25 -0
- package/src/tools/utils/getWallet.ts +25 -0
- package/src/tools/utils/hasWallet.ts +15 -0
- package/src/tools/utils/index.ts +37 -0
- package/src/tools/utils/isTokenGraduated.ts +16 -0
- package/src/tools/utils/setWallet.ts +41 -0
- package/src/tools/utils/switchEnvironment.ts +28 -0
- package/src/types/mcp.ts +72 -0
- package/src/utils/__tests__/validation.test.ts +147 -0
- package/src/utils/constraints.ts +155 -0
- package/src/utils/default-values.ts +208 -0
- package/src/utils/error-handler.ts +69 -0
- package/src/utils/error-templates.ts +273 -0
- package/src/utils/response-formatter.ts +51 -0
- package/src/utils/tool-factory.ts +303 -0
- package/src/utils/tool-registry.ts +296 -0
- package/src/utils/validation.ts +371 -0
- package/tests/wallet-management-integration.test.ts +284 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trading Operations Tools
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { TRADING_TYPES } from '@gala-chain/launchpad-sdk';
|
|
6
|
+
import type { MCPTool } from '../../types/mcp.js';
|
|
7
|
+
import { formatSuccess } from '../../utils/response-formatter.js';
|
|
8
|
+
import { withErrorHandling } from '../../utils/error-handler.js';
|
|
9
|
+
import {
|
|
10
|
+
TOKEN_NAME_SCHEMA,
|
|
11
|
+
DECIMAL_AMOUNT_SCHEMA,
|
|
12
|
+
PRIVATE_KEY_SCHEMA,
|
|
13
|
+
ADDRESS_SCHEMA,
|
|
14
|
+
PAGE_SCHEMA,
|
|
15
|
+
createLimitSchema,
|
|
16
|
+
TRANSACTION_ID_SCHEMA,
|
|
17
|
+
DATE_TIME_SCHEMA,
|
|
18
|
+
SORT_ORDER_SCHEMA,
|
|
19
|
+
SLIPPAGE_TOLERANCE_SCHEMA,
|
|
20
|
+
RBC_FEE_SLIPPAGE_SCHEMA,
|
|
21
|
+
CALCULATION_MODE_SCHEMA,
|
|
22
|
+
CURRENT_SUPPLY_SCHEMA,
|
|
23
|
+
} from '../../schemas/common-schemas.js';
|
|
24
|
+
import { applyOperationPaginationDefaults } from '../../utils/default-values.js';
|
|
25
|
+
|
|
26
|
+
// 1. Calculate Buy Amount
|
|
27
|
+
export const calculateBuyAmountTool: MCPTool = {
|
|
28
|
+
name: 'gala_launchpad_calculate_buy_amount',
|
|
29
|
+
description: 'Calculate token amounts for buying with fee breakdown',
|
|
30
|
+
inputSchema: {
|
|
31
|
+
type: 'object',
|
|
32
|
+
properties: {
|
|
33
|
+
tokenName: TOKEN_NAME_SCHEMA,
|
|
34
|
+
amount: {
|
|
35
|
+
...DECIMAL_AMOUNT_SCHEMA,
|
|
36
|
+
description: 'Amount in standard decimal format (e.g., "1" for 1 GALA)',
|
|
37
|
+
},
|
|
38
|
+
type: {
|
|
39
|
+
type: 'string',
|
|
40
|
+
enum: Object.values(TRADING_TYPES),
|
|
41
|
+
description: `Trade calculation type:
|
|
42
|
+
|
|
43
|
+
- 'native': You specify GALA amount to spend
|
|
44
|
+
Example: "I want to spend 10 GALA to buy tokens" → type: 'native', amount: '10'
|
|
45
|
+
|
|
46
|
+
- 'exact': You specify exact token amount to buy
|
|
47
|
+
Example: "I want to buy exactly 1000 WOO tokens" → type: 'exact', amount: '1000'
|
|
48
|
+
|
|
49
|
+
Most common: Use 'native' when you know how much GALA to spend`,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
required: ['tokenName', 'amount', 'type'],
|
|
53
|
+
},
|
|
54
|
+
handler: withErrorHandling(async (sdk, args) => {
|
|
55
|
+
const result = await sdk.calculateBuyAmount({
|
|
56
|
+
tokenName: args.tokenName,
|
|
57
|
+
amount: args.amount,
|
|
58
|
+
type: args.type,
|
|
59
|
+
});
|
|
60
|
+
return formatSuccess(result);
|
|
61
|
+
}),
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// 2. Calculate Sell Amount
|
|
65
|
+
export const calculateSellAmountTool: MCPTool = {
|
|
66
|
+
name: 'gala_launchpad_calculate_sell_amount',
|
|
67
|
+
description: 'Calculate GALA amounts for selling tokens',
|
|
68
|
+
inputSchema: {
|
|
69
|
+
type: 'object',
|
|
70
|
+
properties: {
|
|
71
|
+
tokenName: TOKEN_NAME_SCHEMA,
|
|
72
|
+
amount: DECIMAL_AMOUNT_SCHEMA,
|
|
73
|
+
type: {
|
|
74
|
+
type: 'string',
|
|
75
|
+
enum: Object.values(TRADING_TYPES),
|
|
76
|
+
description: `Trade calculation type:
|
|
77
|
+
|
|
78
|
+
- 'native': You specify GALA amount you want to receive
|
|
79
|
+
Example: "I want to receive 10 GALA from selling tokens" → type: 'native', amount: '10'
|
|
80
|
+
|
|
81
|
+
- 'exact': You specify exact token amount to sell
|
|
82
|
+
Example: "I want to sell exactly 1000 WOO tokens" → type: 'exact', amount: '1000'
|
|
83
|
+
|
|
84
|
+
Most common: Use 'native' when you know how much GALA you want to receive`,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
required: ['tokenName', 'amount', 'type'],
|
|
88
|
+
},
|
|
89
|
+
handler: withErrorHandling(async (sdk, args) => {
|
|
90
|
+
const result = await sdk.calculateSellAmount({
|
|
91
|
+
tokenName: args.tokenName,
|
|
92
|
+
amount: args.amount,
|
|
93
|
+
type: args.type,
|
|
94
|
+
});
|
|
95
|
+
return formatSuccess(result);
|
|
96
|
+
}),
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// 3. Buy Tokens
|
|
100
|
+
export const buyTokensTool: MCPTool = {
|
|
101
|
+
name: 'gala_launchpad_buy_tokens',
|
|
102
|
+
description: `Execute token purchase with slippage protection.
|
|
103
|
+
|
|
104
|
+
WORKFLOW:
|
|
105
|
+
1. calculateBuyAmount() → Get expected output (result.amount AND result.reverseBondingCurveFee)
|
|
106
|
+
2. buy() → Execute trade with BOTH expectedAmount AND maxAcceptableReverseBondingCurveFee
|
|
107
|
+
3. fetchTrades() → Verify trade completed
|
|
108
|
+
|
|
109
|
+
CRITICAL: Extract BOTH parameters from calculateBuyAmount:
|
|
110
|
+
- result.amount → expectedAmount
|
|
111
|
+
- result.reverseBondingCurveFee → maxAcceptableReverseBondingCurveFee
|
|
112
|
+
Omitting reverseBondingCurveFee may cause transaction failures!
|
|
113
|
+
|
|
114
|
+
RETURNS: Transaction details including input/output amounts and transaction ID`,
|
|
115
|
+
inputSchema: {
|
|
116
|
+
type: 'object',
|
|
117
|
+
properties: {
|
|
118
|
+
tokenName: TOKEN_NAME_SCHEMA,
|
|
119
|
+
amount: {
|
|
120
|
+
...DECIMAL_AMOUNT_SCHEMA,
|
|
121
|
+
description: 'Amount to spend/buy',
|
|
122
|
+
},
|
|
123
|
+
type: {
|
|
124
|
+
type: 'string',
|
|
125
|
+
enum: Object.values(TRADING_TYPES),
|
|
126
|
+
description: `Trade type (must match what you used in calculateBuyAmount):
|
|
127
|
+
|
|
128
|
+
- 'native': Spending GALA amount
|
|
129
|
+
- 'exact': Buying exact token amount`,
|
|
130
|
+
},
|
|
131
|
+
expectedAmount: {
|
|
132
|
+
...DECIMAL_AMOUNT_SCHEMA,
|
|
133
|
+
description: `Expected token output amount from calculateBuyAmount (REQUIRED).
|
|
134
|
+
|
|
135
|
+
CRITICAL: This is the 'amount' field from calculateBuyAmount result, NOT your input amount.
|
|
136
|
+
|
|
137
|
+
WORKFLOW:
|
|
138
|
+
1. Call calculateBuyAmount({ tokenName, amount, type })
|
|
139
|
+
2. Extract result.amount from the response
|
|
140
|
+
3. Use result.amount as this expectedAmount parameter
|
|
141
|
+
|
|
142
|
+
EXAMPLE:
|
|
143
|
+
const calc = await calculateBuyAmount({ tokenName: 'woohoo', amount: '10', type: 'native' });
|
|
144
|
+
// calc.amount = "16843.7579794843252"
|
|
145
|
+
await buy({ tokenName: 'woohoo', amount: '10', type: 'native', expectedAmount: calc.amount, ... });
|
|
146
|
+
// Use calc.amount ("16843.7579794843252"), NOT the input '10'`,
|
|
147
|
+
},
|
|
148
|
+
maxAcceptableReverseBondingCurveFee: {
|
|
149
|
+
...DECIMAL_AMOUNT_SCHEMA,
|
|
150
|
+
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.',
|
|
151
|
+
},
|
|
152
|
+
maxAcceptableReverseBondingCurveFeeSlippageFactor: RBC_FEE_SLIPPAGE_SCHEMA,
|
|
153
|
+
slippageToleranceFactor: SLIPPAGE_TOLERANCE_SCHEMA,
|
|
154
|
+
privateKey: PRIVATE_KEY_SCHEMA,
|
|
155
|
+
},
|
|
156
|
+
required: ['tokenName', 'amount', 'type', 'expectedAmount', 'slippageToleranceFactor'],
|
|
157
|
+
},
|
|
158
|
+
handler: withErrorHandling(async (sdk, args) => {
|
|
159
|
+
const result = await sdk.buy({
|
|
160
|
+
tokenName: args.tokenName,
|
|
161
|
+
amount: args.amount,
|
|
162
|
+
type: args.type,
|
|
163
|
+
expectedAmount: args.expectedAmount,
|
|
164
|
+
maxAcceptableReverseBondingCurveFee: args.maxAcceptableReverseBondingCurveFee,
|
|
165
|
+
maxAcceptableReverseBondingCurveFeeSlippageFactor: args.maxAcceptableReverseBondingCurveFeeSlippageFactor,
|
|
166
|
+
slippageToleranceFactor: args.slippageToleranceFactor,
|
|
167
|
+
privateKey: args.privateKey,
|
|
168
|
+
});
|
|
169
|
+
return formatSuccess(result);
|
|
170
|
+
}),
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// 4. Sell Tokens
|
|
174
|
+
export const sellTokensTool: MCPTool = {
|
|
175
|
+
name: 'gala_launchpad_sell_tokens',
|
|
176
|
+
description: `Execute token sale with slippage protection.
|
|
177
|
+
|
|
178
|
+
WORKFLOW:
|
|
179
|
+
1. calculateSellAmount() → Get expected output (result.amount AND result.reverseBondingCurveFee)
|
|
180
|
+
2. sell() → Execute trade with BOTH expectedAmount AND maxAcceptableReverseBondingCurveFee
|
|
181
|
+
3. fetchTrades() → Verify trade completed
|
|
182
|
+
|
|
183
|
+
CRITICAL: Extract BOTH parameters from calculateSellAmount:
|
|
184
|
+
- result.amount → expectedAmount
|
|
185
|
+
- result.reverseBondingCurveFee → maxAcceptableReverseBondingCurveFee
|
|
186
|
+
Omitting reverseBondingCurveFee may cause transaction failures!
|
|
187
|
+
|
|
188
|
+
RETURNS: Transaction details including input/output amounts and transaction ID`,
|
|
189
|
+
inputSchema: {
|
|
190
|
+
type: 'object',
|
|
191
|
+
properties: {
|
|
192
|
+
tokenName: TOKEN_NAME_SCHEMA,
|
|
193
|
+
amount: {
|
|
194
|
+
...DECIMAL_AMOUNT_SCHEMA,
|
|
195
|
+
description: 'Amount to sell/receive',
|
|
196
|
+
},
|
|
197
|
+
type: {
|
|
198
|
+
type: 'string',
|
|
199
|
+
enum: Object.values(TRADING_TYPES),
|
|
200
|
+
description: `Trade type (must match what you used in calculateSellAmount):
|
|
201
|
+
|
|
202
|
+
- 'native': Receiving GALA amount
|
|
203
|
+
- 'exact': Selling exact token amount`,
|
|
204
|
+
},
|
|
205
|
+
expectedAmount: {
|
|
206
|
+
...DECIMAL_AMOUNT_SCHEMA,
|
|
207
|
+
description: `Expected GALA output amount from calculateSellAmount (REQUIRED).
|
|
208
|
+
|
|
209
|
+
CRITICAL: This is the 'amount' field from calculateSellAmount result, NOT your input amount.
|
|
210
|
+
|
|
211
|
+
WORKFLOW:
|
|
212
|
+
1. Call calculateSellAmount({ tokenName, amount, type })
|
|
213
|
+
2. Extract result.amount from the response
|
|
214
|
+
3. Use result.amount as this expectedAmount parameter
|
|
215
|
+
|
|
216
|
+
EXAMPLE:
|
|
217
|
+
const calc = await calculateSellAmount({ tokenName: 'woohoo', amount: '10', type: 'native' });
|
|
218
|
+
// calc.amount = "16843.7579794843252"
|
|
219
|
+
await sell({ tokenName: 'woohoo', amount: '10', type: 'native', expectedAmount: calc.amount, ... });
|
|
220
|
+
// Use calc.amount ("16843.7579794843252"), NOT the input '10'`,
|
|
221
|
+
},
|
|
222
|
+
maxAcceptableReverseBondingCurveFee: {
|
|
223
|
+
...DECIMAL_AMOUNT_SCHEMA,
|
|
224
|
+
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.',
|
|
225
|
+
},
|
|
226
|
+
maxAcceptableReverseBondingCurveFeeSlippageFactor: RBC_FEE_SLIPPAGE_SCHEMA,
|
|
227
|
+
slippageToleranceFactor: SLIPPAGE_TOLERANCE_SCHEMA,
|
|
228
|
+
privateKey: PRIVATE_KEY_SCHEMA,
|
|
229
|
+
},
|
|
230
|
+
required: ['tokenName', 'amount', 'type', 'expectedAmount', 'slippageToleranceFactor'],
|
|
231
|
+
},
|
|
232
|
+
handler: withErrorHandling(async (sdk, args) => {
|
|
233
|
+
const result = await sdk.sell({
|
|
234
|
+
tokenName: args.tokenName,
|
|
235
|
+
amount: args.amount,
|
|
236
|
+
type: args.type,
|
|
237
|
+
expectedAmount: args.expectedAmount,
|
|
238
|
+
maxAcceptableReverseBondingCurveFee: args.maxAcceptableReverseBondingCurveFee,
|
|
239
|
+
maxAcceptableReverseBondingCurveFeeSlippageFactor: args.maxAcceptableReverseBondingCurveFeeSlippageFactor,
|
|
240
|
+
slippageToleranceFactor: args.slippageToleranceFactor,
|
|
241
|
+
privateKey: args.privateKey,
|
|
242
|
+
});
|
|
243
|
+
return formatSuccess(result);
|
|
244
|
+
}),
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// 5. Fetch Trades
|
|
248
|
+
export const fetchTradesTool: MCPTool = {
|
|
249
|
+
name: 'gala_launchpad_fetch_trades',
|
|
250
|
+
description: 'Get trade history with filtering',
|
|
251
|
+
inputSchema: {
|
|
252
|
+
type: 'object',
|
|
253
|
+
properties: {
|
|
254
|
+
tokenName: TOKEN_NAME_SCHEMA,
|
|
255
|
+
tradeType: {
|
|
256
|
+
type: 'string',
|
|
257
|
+
enum: ['BUY', 'SELL'],
|
|
258
|
+
description: 'Filter by trade type',
|
|
259
|
+
},
|
|
260
|
+
userAddress: {
|
|
261
|
+
...ADDRESS_SCHEMA,
|
|
262
|
+
description: 'Filter by user address',
|
|
263
|
+
},
|
|
264
|
+
page: PAGE_SCHEMA,
|
|
265
|
+
limit: createLimitSchema('trade', 20),
|
|
266
|
+
startDate: {
|
|
267
|
+
...DATE_TIME_SCHEMA,
|
|
268
|
+
description: 'Filter by start date',
|
|
269
|
+
},
|
|
270
|
+
endDate: {
|
|
271
|
+
...DATE_TIME_SCHEMA,
|
|
272
|
+
description: 'Filter by end date',
|
|
273
|
+
},
|
|
274
|
+
sortOrder: SORT_ORDER_SCHEMA,
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
handler: withErrorHandling(async (sdk, args) => {
|
|
278
|
+
const pagination = applyOperationPaginationDefaults(args, 'trade');
|
|
279
|
+
const result = await sdk.fetchTrades({
|
|
280
|
+
tokenName: args.tokenName,
|
|
281
|
+
tradeType: args.tradeType,
|
|
282
|
+
userAddress: args.userAddress,
|
|
283
|
+
...pagination,
|
|
284
|
+
startDate: args.startDate,
|
|
285
|
+
endDate: args.endDate,
|
|
286
|
+
sortOrder: args.sortOrder || 'DESC',
|
|
287
|
+
});
|
|
288
|
+
return formatSuccess(result);
|
|
289
|
+
}),
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
// 6. Calculate Initial Buy
|
|
293
|
+
export const calculateInitialBuyTool: MCPTool = {
|
|
294
|
+
name: 'gala_launchpad_calculate_initial_buy',
|
|
295
|
+
description: 'Calculate amounts for initial token purchase during creation (pre-mint phase)',
|
|
296
|
+
inputSchema: {
|
|
297
|
+
type: 'object',
|
|
298
|
+
properties: {
|
|
299
|
+
amount: {
|
|
300
|
+
...DECIMAL_AMOUNT_SCHEMA,
|
|
301
|
+
description: 'GALA amount to spend for initial buy (standard decimal format, e.g., "100" for 100 GALA)',
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
required: ['amount'],
|
|
305
|
+
},
|
|
306
|
+
handler: withErrorHandling(async (sdk, args) => {
|
|
307
|
+
const result = await sdk.calculateInitialBuyAmount(args.amount);
|
|
308
|
+
return formatSuccess(result);
|
|
309
|
+
}),
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// 7. Get Bundler Transaction Result
|
|
313
|
+
export const getBundlerTransactionResultTool: MCPTool = {
|
|
314
|
+
name: 'gala_launchpad_get_bundler_transaction_result',
|
|
315
|
+
description: `Get bundle transaction result by ID via HTTP (not WebSocket).
|
|
316
|
+
|
|
317
|
+
Returns lightweight status: { id: string, method: string, status: string }
|
|
318
|
+
|
|
319
|
+
Status values: "COMPLETED", "FAILED", "PENDING", "PROCESSING"
|
|
320
|
+
|
|
321
|
+
Use cases:
|
|
322
|
+
- Check transaction status when WebSocket times out
|
|
323
|
+
- Get definitive transaction state
|
|
324
|
+
- Verify trade/launch completion
|
|
325
|
+
|
|
326
|
+
Note: This is a synchronous HTTP call, not WebSocket monitoring.`,
|
|
327
|
+
inputSchema: {
|
|
328
|
+
type: 'object',
|
|
329
|
+
properties: {
|
|
330
|
+
transactionId: TRANSACTION_ID_SCHEMA,
|
|
331
|
+
},
|
|
332
|
+
required: ['transactionId'],
|
|
333
|
+
},
|
|
334
|
+
handler: withErrorHandling(async (sdk, args) => {
|
|
335
|
+
const result = await sdk.getBundlerTransactionResult(args.transactionId);
|
|
336
|
+
return formatSuccess(result);
|
|
337
|
+
}),
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// 8. Calculate Buy Amount for Graduation
|
|
341
|
+
export const calculateBuyAmountForGraduationTool: MCPTool = {
|
|
342
|
+
name: 'gala_launchpad_calculate_buy_amount_for_graduation',
|
|
343
|
+
description: `Calculate amount needed to graduate a token pool.
|
|
344
|
+
|
|
345
|
+
Convenience method that:
|
|
346
|
+
1. Fetches pool details to get remaining tokens
|
|
347
|
+
2. Calls calculateBuyAmount with exact remaining amount
|
|
348
|
+
3. Returns standard AmountCalculationResult
|
|
349
|
+
|
|
350
|
+
Performance optimization: Provide currentSupply to avoid fetching pool details twice.
|
|
351
|
+
|
|
352
|
+
RETURNS: Same as calculateBuyAmount - complete cost breakdown including
|
|
353
|
+
totalCost, amount, transactionFee, gasFee, reverseBondingCurveFee`,
|
|
354
|
+
inputSchema: {
|
|
355
|
+
type: 'object',
|
|
356
|
+
properties: {
|
|
357
|
+
tokenName: TOKEN_NAME_SCHEMA,
|
|
358
|
+
calculateAmountMode: CALCULATION_MODE_SCHEMA,
|
|
359
|
+
currentSupply: CURRENT_SUPPLY_SCHEMA,
|
|
360
|
+
},
|
|
361
|
+
required: ['tokenName'],
|
|
362
|
+
},
|
|
363
|
+
handler: withErrorHandling(async (sdk, args) => {
|
|
364
|
+
// Build options object only if mode or supply provided
|
|
365
|
+
const options = args.calculateAmountMode || args.currentSupply
|
|
366
|
+
? {
|
|
367
|
+
tokenName: args.tokenName,
|
|
368
|
+
calculateAmountMode: args.calculateAmountMode,
|
|
369
|
+
currentSupply: args.currentSupply,
|
|
370
|
+
}
|
|
371
|
+
: args.tokenName;
|
|
372
|
+
|
|
373
|
+
const result = await sdk.calculateBuyAmountForGraduation(options);
|
|
374
|
+
return formatSuccess(result);
|
|
375
|
+
}),
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// 9. Graduate Token
|
|
379
|
+
export const graduateTokenTool: MCPTool = {
|
|
380
|
+
name: 'gala_launchpad_graduate_token',
|
|
381
|
+
description: `Graduate a token pool by buying all remaining tokens in one transaction.
|
|
382
|
+
|
|
383
|
+
WORKFLOW (automatic):
|
|
384
|
+
1. Calls calculateBuyAmountForGraduation() internally
|
|
385
|
+
2. Executes buy() with exact remaining token amount
|
|
386
|
+
3. Returns transaction result
|
|
387
|
+
|
|
388
|
+
Performance optimization: Provide currentSupply to avoid fetching pool details twice.
|
|
389
|
+
|
|
390
|
+
CRITICAL: This is a convenience method that combines multiple operations.
|
|
391
|
+
Throws error if token is already graduated.
|
|
392
|
+
slippageToleranceFactor is optional and uses SDK defaults if not provided.
|
|
393
|
+
|
|
394
|
+
RETURNS: TradeResult with transaction details including amounts and transaction ID`,
|
|
395
|
+
inputSchema: {
|
|
396
|
+
type: 'object',
|
|
397
|
+
properties: {
|
|
398
|
+
tokenName: TOKEN_NAME_SCHEMA,
|
|
399
|
+
slippageToleranceFactor: SLIPPAGE_TOLERANCE_SCHEMA,
|
|
400
|
+
maxAcceptableReverseBondingCurveFeeSlippageFactor: RBC_FEE_SLIPPAGE_SCHEMA,
|
|
401
|
+
privateKey: PRIVATE_KEY_SCHEMA,
|
|
402
|
+
calculateAmountMode: CALCULATION_MODE_SCHEMA,
|
|
403
|
+
currentSupply: CURRENT_SUPPLY_SCHEMA,
|
|
404
|
+
},
|
|
405
|
+
required: ['tokenName'], // Only tokenName is required
|
|
406
|
+
},
|
|
407
|
+
handler: withErrorHandling(async (sdk, args) => {
|
|
408
|
+
const result = await sdk.graduateToken({
|
|
409
|
+
tokenName: args.tokenName,
|
|
410
|
+
slippageToleranceFactor: args.slippageToleranceFactor,
|
|
411
|
+
maxAcceptableReverseBondingCurveFeeSlippageFactor: args.maxAcceptableReverseBondingCurveFeeSlippageFactor,
|
|
412
|
+
privateKey: args.privateKey,
|
|
413
|
+
calculateAmountMode: args.calculateAmountMode,
|
|
414
|
+
currentSupply: args.currentSupply,
|
|
415
|
+
});
|
|
416
|
+
return formatSuccess(result);
|
|
417
|
+
}),
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
// 10. Calculate Buy Amount (Local)
|
|
421
|
+
export const calculateBuyAmountLocalTool: MCPTool = {
|
|
422
|
+
name: 'gala_launchpad_calculate_buy_amount_local',
|
|
423
|
+
description: `Calculate buy amounts using LOCAL bonding curve formulas (instant, no network call).
|
|
424
|
+
|
|
425
|
+
Uses client-side exponential bonding curve calculations for instant quotes.
|
|
426
|
+
Perfect for price discovery, UI updates, and offline scenarios.
|
|
427
|
+
|
|
428
|
+
ACCURACY: Matches external calculations with <0.01% difference.
|
|
429
|
+
|
|
430
|
+
RETURNS: { amount, reverseBondingCurveFee: "0", transactionFee, gasFee }`,
|
|
431
|
+
inputSchema: {
|
|
432
|
+
type: 'object',
|
|
433
|
+
properties: {
|
|
434
|
+
tokenName: TOKEN_NAME_SCHEMA,
|
|
435
|
+
amount: {
|
|
436
|
+
...DECIMAL_AMOUNT_SCHEMA,
|
|
437
|
+
description: 'Amount in standard decimal format (e.g., "1" for 1 GALA)',
|
|
438
|
+
},
|
|
439
|
+
type: {
|
|
440
|
+
type: 'string',
|
|
441
|
+
enum: Object.values(TRADING_TYPES),
|
|
442
|
+
description: `Trade calculation type:
|
|
443
|
+
- 'native': Spend GALA amount
|
|
444
|
+
- 'exact': Buy exact token amount`,
|
|
445
|
+
},
|
|
446
|
+
},
|
|
447
|
+
required: ['tokenName', 'amount', 'type'],
|
|
448
|
+
},
|
|
449
|
+
handler: withErrorHandling(async (sdk, args) => {
|
|
450
|
+
const result = await sdk.calculateBuyAmountLocal({
|
|
451
|
+
tokenName: args.tokenName,
|
|
452
|
+
amount: args.amount,
|
|
453
|
+
type: args.type,
|
|
454
|
+
});
|
|
455
|
+
return formatSuccess(result);
|
|
456
|
+
}),
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
// 11. Calculate Buy Amount (External)
|
|
460
|
+
export const calculateBuyAmountExternalTool: MCPTool = {
|
|
461
|
+
name: 'gala_launchpad_calculate_buy_amount_external',
|
|
462
|
+
description: `Calculate buy amounts using EXTERNAL GalaChain network call (real-time).
|
|
463
|
+
|
|
464
|
+
Explicit external calculation - queries GalaChain network for real-time pricing.
|
|
465
|
+
Identical to calculateBuyAmount but makes the network dependency explicit.
|
|
466
|
+
|
|
467
|
+
RETURNS: { amount, reverseBondingCurveFee, transactionFee, gasFee }`,
|
|
468
|
+
inputSchema: {
|
|
469
|
+
type: 'object',
|
|
470
|
+
properties: {
|
|
471
|
+
tokenName: TOKEN_NAME_SCHEMA,
|
|
472
|
+
amount: {
|
|
473
|
+
...DECIMAL_AMOUNT_SCHEMA,
|
|
474
|
+
description: 'Amount in standard decimal format',
|
|
475
|
+
},
|
|
476
|
+
type: {
|
|
477
|
+
type: 'string',
|
|
478
|
+
enum: Object.values(TRADING_TYPES),
|
|
479
|
+
description: `Trade calculation type:
|
|
480
|
+
- 'native': Spend GALA amount
|
|
481
|
+
- 'exact': Buy exact token amount`,
|
|
482
|
+
},
|
|
483
|
+
},
|
|
484
|
+
required: ['tokenName', 'amount', 'type'],
|
|
485
|
+
},
|
|
486
|
+
handler: withErrorHandling(async (sdk, args) => {
|
|
487
|
+
const result = await sdk.calculateBuyAmountExternal({
|
|
488
|
+
tokenName: args.tokenName,
|
|
489
|
+
amount: args.amount,
|
|
490
|
+
type: args.type,
|
|
491
|
+
});
|
|
492
|
+
return formatSuccess(result);
|
|
493
|
+
}),
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
// 12. Calculate Sell Amount (Local)
|
|
497
|
+
export const calculateSellAmountLocalTool: MCPTool = {
|
|
498
|
+
name: 'gala_launchpad_calculate_sell_amount_local',
|
|
499
|
+
description: `Calculate sell amounts using LOCAL bonding curve formulas (instant, no network call).
|
|
500
|
+
|
|
501
|
+
Uses client-side calculations with reverse bonding curve fee support.
|
|
502
|
+
Requires pool details (maxSupply, fee parameters) to calculate accurately.
|
|
503
|
+
|
|
504
|
+
ACCURACY: Matches external calculations with <0.01% difference.
|
|
505
|
+
|
|
506
|
+
RETURNS: { amount, reverseBondingCurveFee, transactionFee, gasFee }`,
|
|
507
|
+
inputSchema: {
|
|
508
|
+
type: 'object',
|
|
509
|
+
properties: {
|
|
510
|
+
tokenName: TOKEN_NAME_SCHEMA,
|
|
511
|
+
amount: {
|
|
512
|
+
...DECIMAL_AMOUNT_SCHEMA,
|
|
513
|
+
description: 'Amount to sell/receive',
|
|
514
|
+
},
|
|
515
|
+
type: {
|
|
516
|
+
type: 'string',
|
|
517
|
+
enum: Object.values(TRADING_TYPES),
|
|
518
|
+
description: `Trade calculation type:
|
|
519
|
+
- 'native': Receive GALA amount
|
|
520
|
+
- 'exact': Sell exact token amount`,
|
|
521
|
+
},
|
|
522
|
+
maxSupply: {
|
|
523
|
+
...DECIMAL_AMOUNT_SCHEMA,
|
|
524
|
+
description: 'Token maximum supply (get from fetchPoolDetails)',
|
|
525
|
+
},
|
|
526
|
+
reverseBondingCurveMinFeeFactor: {
|
|
527
|
+
type: 'number',
|
|
528
|
+
minimum: 0,
|
|
529
|
+
maximum: 1,
|
|
530
|
+
description: 'Min reverse bonding curve fee factor (get from poolDetails.reverseBondingCurveMinFeeFactor)',
|
|
531
|
+
},
|
|
532
|
+
reverseBondingCurveMaxFeeFactor: {
|
|
533
|
+
type: 'number',
|
|
534
|
+
minimum: 0,
|
|
535
|
+
maximum: 1,
|
|
536
|
+
description: 'Max reverse bonding curve fee factor (get from poolDetails.reverseBondingCurveMaxFeeFactor)',
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
required: ['tokenName', 'amount', 'type', 'maxSupply', 'reverseBondingCurveMinFeeFactor', 'reverseBondingCurveMaxFeeFactor'],
|
|
540
|
+
},
|
|
541
|
+
handler: withErrorHandling(async (sdk, args) => {
|
|
542
|
+
const result = await sdk.calculateSellAmountLocal({
|
|
543
|
+
tokenName: args.tokenName,
|
|
544
|
+
amount: args.amount,
|
|
545
|
+
type: args.type,
|
|
546
|
+
maxSupply: args.maxSupply,
|
|
547
|
+
reverseBondingCurveMinFeeFactor: args.reverseBondingCurveMinFeeFactor,
|
|
548
|
+
reverseBondingCurveMaxFeeFactor: args.reverseBondingCurveMaxFeeFactor,
|
|
549
|
+
});
|
|
550
|
+
return formatSuccess(result);
|
|
551
|
+
}),
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
// 13. Calculate Sell Amount (External)
|
|
555
|
+
export const calculateSellAmountExternalTool: MCPTool = {
|
|
556
|
+
name: 'gala_launchpad_calculate_sell_amount_external',
|
|
557
|
+
description: `Calculate sell amounts using EXTERNAL GalaChain network call (real-time).
|
|
558
|
+
|
|
559
|
+
Explicit external calculation - queries GalaChain network for real-time pricing.
|
|
560
|
+
Identical to calculateSellAmount but makes the network dependency explicit.
|
|
561
|
+
|
|
562
|
+
RETURNS: { amount, reverseBondingCurveFee, transactionFee, gasFee }`,
|
|
563
|
+
inputSchema: {
|
|
564
|
+
type: 'object',
|
|
565
|
+
properties: {
|
|
566
|
+
tokenName: TOKEN_NAME_SCHEMA,
|
|
567
|
+
amount: {
|
|
568
|
+
...DECIMAL_AMOUNT_SCHEMA,
|
|
569
|
+
description: 'Amount to sell/receive',
|
|
570
|
+
},
|
|
571
|
+
type: {
|
|
572
|
+
type: 'string',
|
|
573
|
+
enum: Object.values(TRADING_TYPES),
|
|
574
|
+
description: `Trade calculation type:
|
|
575
|
+
- 'native': Receive GALA amount
|
|
576
|
+
- 'exact': Sell exact token amount`,
|
|
577
|
+
},
|
|
578
|
+
},
|
|
579
|
+
required: ['tokenName', 'amount', 'type'],
|
|
580
|
+
},
|
|
581
|
+
handler: withErrorHandling(async (sdk, args) => {
|
|
582
|
+
const result = await sdk.calculateSellAmountExternal({
|
|
583
|
+
tokenName: args.tokenName,
|
|
584
|
+
amount: args.amount,
|
|
585
|
+
type: args.type,
|
|
586
|
+
});
|
|
587
|
+
return formatSuccess(result);
|
|
588
|
+
}),
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
export const tradingTools: MCPTool[] = [
|
|
592
|
+
calculateBuyAmountTool,
|
|
593
|
+
calculateSellAmountTool,
|
|
594
|
+
buyTokensTool,
|
|
595
|
+
sellTokensTool,
|
|
596
|
+
fetchTradesTool,
|
|
597
|
+
calculateInitialBuyTool,
|
|
598
|
+
getBundlerTransactionResultTool,
|
|
599
|
+
calculateBuyAmountForGraduationTool,
|
|
600
|
+
graduateTokenTool,
|
|
601
|
+
calculateBuyAmountLocalTool,
|
|
602
|
+
calculateBuyAmountExternalTool,
|
|
603
|
+
calculateSellAmountLocalTool,
|
|
604
|
+
calculateSellAmountExternalTool,
|
|
605
|
+
];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token Transfer 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 {
|
|
9
|
+
ADDRESS_SCHEMA,
|
|
10
|
+
TOKEN_NAME_SCHEMA,
|
|
11
|
+
DECIMAL_AMOUNT_SCHEMA,
|
|
12
|
+
INTEGER_AMOUNT_SCHEMA,
|
|
13
|
+
UNIQUE_KEY_SCHEMA,
|
|
14
|
+
PRIVATE_KEY_SCHEMA,
|
|
15
|
+
} from '../../schemas/common-schemas.js';
|
|
16
|
+
|
|
17
|
+
// 1. Transfer GALA
|
|
18
|
+
export const transferGalaTool: MCPTool = {
|
|
19
|
+
name: 'gala_launchpad_transfer_gala',
|
|
20
|
+
description: 'Transfer GALA tokens via GalaChain',
|
|
21
|
+
inputSchema: {
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: {
|
|
24
|
+
recipientAddress: {
|
|
25
|
+
...ADDRESS_SCHEMA,
|
|
26
|
+
description: 'Recipient wallet address',
|
|
27
|
+
},
|
|
28
|
+
amount: DECIMAL_AMOUNT_SCHEMA,
|
|
29
|
+
uniqueKey: UNIQUE_KEY_SCHEMA,
|
|
30
|
+
privateKey: PRIVATE_KEY_SCHEMA,
|
|
31
|
+
},
|
|
32
|
+
required: ['recipientAddress', 'amount'],
|
|
33
|
+
},
|
|
34
|
+
handler: withErrorHandling(async (sdk, args) => {
|
|
35
|
+
const result = await sdk.transferGala({
|
|
36
|
+
recipientAddress: args.recipientAddress,
|
|
37
|
+
amount: args.amount,
|
|
38
|
+
uniqueKey: args.uniqueKey,
|
|
39
|
+
privateKey: args.privateKey,
|
|
40
|
+
});
|
|
41
|
+
return formatSuccess(result);
|
|
42
|
+
}),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// 2. Transfer Token
|
|
46
|
+
export const transferTokenTool: MCPTool = {
|
|
47
|
+
name: 'gala_launchpad_transfer_token',
|
|
48
|
+
description: 'Transfer launchpad tokens via GalaChain',
|
|
49
|
+
inputSchema: {
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
to: {
|
|
53
|
+
...ADDRESS_SCHEMA,
|
|
54
|
+
description: 'Recipient wallet address',
|
|
55
|
+
},
|
|
56
|
+
tokenName: TOKEN_NAME_SCHEMA,
|
|
57
|
+
amount: INTEGER_AMOUNT_SCHEMA,
|
|
58
|
+
uniqueKey: UNIQUE_KEY_SCHEMA,
|
|
59
|
+
privateKey: PRIVATE_KEY_SCHEMA,
|
|
60
|
+
},
|
|
61
|
+
required: ['to', 'tokenName', 'amount'],
|
|
62
|
+
},
|
|
63
|
+
handler: withErrorHandling(async (sdk, args) => {
|
|
64
|
+
const result = await sdk.transferToken({
|
|
65
|
+
to: args.to,
|
|
66
|
+
tokenName: args.tokenName,
|
|
67
|
+
amount: args.amount,
|
|
68
|
+
uniqueKey: args.uniqueKey,
|
|
69
|
+
privateKey: args.privateKey,
|
|
70
|
+
});
|
|
71
|
+
return formatSuccess(result);
|
|
72
|
+
}),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const transferTools: MCPTool[] = [transferGalaTool, transferTokenTool];
|