@gala-chain/launchpad-mcp-server 1.7.2 → 1.7.4
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 +40 -4
- 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 +2 -2
- package/src/__tests__/integration/poolTools.integration.test.ts +185 -0
- package/src/constants/mcpToolNames.ts +141 -0
- package/src/index.ts +19 -0
- package/src/prompts/__tests__/promptStructure.test.ts +114 -0
- package/src/prompts/__tests__/registry.test.ts +143 -0
- package/src/prompts/analysis.ts +429 -0
- package/src/prompts/index.ts +123 -0
- package/src/prompts/portfolio.ts +242 -0
- package/src/prompts/trading.ts +191 -0
- package/src/prompts/utils/workflowTemplates.ts +344 -0
- package/src/schemas/common-schemas.ts +392 -0
- package/src/scripts/test-all-prompts.ts +184 -0
- package/src/server.ts +241 -0
- package/src/tools/balance/index.ts +174 -0
- package/src/tools/creation/index.ts +182 -0
- package/src/tools/index.ts +80 -0
- package/src/tools/pools/fetchAllPools.ts +47 -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/index.ts +240 -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 +765 -0
- package/src/tools/utils/getAddress.ts +12 -0
- package/src/tools/utils/getCacheInfo.ts +14 -0
- package/src/tools/utils/getConfig.ts +11 -0
- package/src/tools/utils/getEthereumAddress.ts +12 -0
- package/src/tools/utils/getUrlByTokenName.ts +12 -0
- package/src/tools/utils/index.ts +25 -0
- package/src/tools/utils/isTokenGraduated.ts +16 -0
- package/src/types/mcp.ts +72 -0
- package/src/utils/__tests__/validation.test.ts +147 -0
- package/src/utils/constraints.ts +146 -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 +257 -0
- package/src/utils/tool-registry.ts +296 -0
- package/src/utils/validation.ts +336 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,765 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Usage Explanation Tool
|
|
3
|
+
*
|
|
4
|
+
* Provides detailed explanations and code examples for using the Gala Launchpad SDK directly.
|
|
5
|
+
* Acts as a development reference showing how MCP tools map to SDK methods.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { MCPTool } from '../../types/mcp.js';
|
|
9
|
+
import { withErrorHandling } from '../../utils/error-handler.js';
|
|
10
|
+
import { formatSuccess } from '../../utils/response-formatter.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* SDK code examples organized by topic
|
|
14
|
+
*/
|
|
15
|
+
const SDK_EXAMPLES = {
|
|
16
|
+
// Trading workflows
|
|
17
|
+
'buy-tokens': `
|
|
18
|
+
## Buying Tokens with SDK
|
|
19
|
+
|
|
20
|
+
\`\`\`typescript
|
|
21
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
22
|
+
|
|
23
|
+
async function buyTokens() {
|
|
24
|
+
// 1. Create SDK instance
|
|
25
|
+
const sdk = createLaunchpadSDK({
|
|
26
|
+
wallet: 'your-private-key-or-mnemonic'
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// 2. Calculate expected amounts FIRST (REQUIRED)
|
|
30
|
+
const calculation = await sdk.calculateBuyAmount({
|
|
31
|
+
tokenName: 'dragnrkti',
|
|
32
|
+
amount: '100', // Spending 100 GALA
|
|
33
|
+
type: 'native' // 'native' = GALA amount, 'exact' = token amount
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
console.log('Expected tokens:', calculation.amount);
|
|
37
|
+
console.log('RBC Fee:', calculation.reverseBondingCurveFee);
|
|
38
|
+
console.log('Transaction fee:', calculation.transactionFee);
|
|
39
|
+
|
|
40
|
+
// 3. Execute buy with slippage protection
|
|
41
|
+
const result = await sdk.buy({
|
|
42
|
+
tokenName: 'dragnrkti',
|
|
43
|
+
amount: '100',
|
|
44
|
+
type: 'native',
|
|
45
|
+
expectedAmount: calculation.amount, // REQUIRED: from step 2
|
|
46
|
+
maxAcceptableReverseBondingCurveFee: calculation.reverseBondingCurveFee, // RECOMMENDED
|
|
47
|
+
slippageToleranceFactor: 0.01 // 1% slippage tolerance (REQUIRED)
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
console.log('Transaction ID:', result.transactionId);
|
|
51
|
+
console.log('GALA spent:', result.inputAmount);
|
|
52
|
+
console.log('Tokens received:', result.outputAmount);
|
|
53
|
+
console.log('Total fees:', result.totalFees);
|
|
54
|
+
}
|
|
55
|
+
\`\`\`
|
|
56
|
+
|
|
57
|
+
**MCP Tool Equivalent:** \`gala_launchpad_buy_tokens\`
|
|
58
|
+
`,
|
|
59
|
+
|
|
60
|
+
'sell-tokens': `
|
|
61
|
+
## Selling Tokens with SDK
|
|
62
|
+
|
|
63
|
+
\`\`\`typescript
|
|
64
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
65
|
+
|
|
66
|
+
async function sellTokens() {
|
|
67
|
+
// 1. Create SDK instance
|
|
68
|
+
const sdk = createLaunchpadSDK({
|
|
69
|
+
wallet: 'your-private-key'
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// 2. Calculate expected GALA FIRST (REQUIRED)
|
|
73
|
+
const calculation = await sdk.calculateSellAmount({
|
|
74
|
+
tokenName: 'dragnrkti',
|
|
75
|
+
amount: '1000', // Selling 1000 tokens
|
|
76
|
+
type: 'exact' // 'exact' = exact tokens, 'native' = target GALA amount
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
console.log('Expected GALA:', calculation.amount);
|
|
80
|
+
console.log('RBC Fee:', calculation.reverseBondingCurveFee);
|
|
81
|
+
|
|
82
|
+
// 3. Execute sell with slippage protection
|
|
83
|
+
const result = await sdk.sell({
|
|
84
|
+
tokenName: 'dragnrkti',
|
|
85
|
+
amount: '1000',
|
|
86
|
+
type: 'exact',
|
|
87
|
+
expectedAmount: calculation.amount, // REQUIRED: from step 2
|
|
88
|
+
maxAcceptableReverseBondingCurveFee: calculation.reverseBondingCurveFee, // RECOMMENDED
|
|
89
|
+
slippageToleranceFactor: 0.01 // 1% slippage
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
console.log('Tokens sold:', result.inputAmount);
|
|
93
|
+
console.log('GALA received:', result.outputAmount);
|
|
94
|
+
}
|
|
95
|
+
\`\`\`
|
|
96
|
+
|
|
97
|
+
**MCP Tool Equivalent:** \`gala_launchpad_sell_tokens\`
|
|
98
|
+
`,
|
|
99
|
+
|
|
100
|
+
'pool-graduation': `
|
|
101
|
+
## Pool Graduation with SDK
|
|
102
|
+
|
|
103
|
+
\`\`\`typescript
|
|
104
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
105
|
+
|
|
106
|
+
async function graduatePool() {
|
|
107
|
+
const sdk = createLaunchpadSDK({
|
|
108
|
+
wallet: 'your-private-key'
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Option 1: Calculate graduation cost first (recommended)
|
|
112
|
+
const calculation = await sdk.calculateBuyAmountForGraduation('dragnrkti');
|
|
113
|
+
|
|
114
|
+
console.log('GALA cost to graduate:', calculation.amount);
|
|
115
|
+
console.log('RBC Fee:', calculation.reverseBondingCurveFee);
|
|
116
|
+
console.log('Transaction fee:', calculation.transactionFee);
|
|
117
|
+
|
|
118
|
+
// Check if you have enough balance
|
|
119
|
+
const balance = await sdk.fetchGalaBalance();
|
|
120
|
+
if (parseFloat(balance.balance) < parseFloat(calculation.amount)) {
|
|
121
|
+
throw new Error('Insufficient GALA balance');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Option 2: One-step graduation (convenience method)
|
|
125
|
+
const result = await sdk.graduateToken({
|
|
126
|
+
tokenName: 'dragnrkti',
|
|
127
|
+
slippageToleranceFactor: 0.01 // Optional: defaults to SDK config
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
console.log('Pool graduated!');
|
|
131
|
+
console.log('Transaction ID:', result.transactionId);
|
|
132
|
+
console.log('Total GALA spent:', result.inputAmount);
|
|
133
|
+
console.log('Tokens received:', result.outputAmount);
|
|
134
|
+
}
|
|
135
|
+
\`\`\`
|
|
136
|
+
|
|
137
|
+
**MCP Tool Equivalents:**
|
|
138
|
+
- \`gala_launchpad_calculate_buy_amount_for_graduation\`
|
|
139
|
+
- \`gala_launchpad_graduate_token\`
|
|
140
|
+
`,
|
|
141
|
+
|
|
142
|
+
'fetch-pools': `
|
|
143
|
+
## Fetching Pool Data with SDK
|
|
144
|
+
|
|
145
|
+
\`\`\`typescript
|
|
146
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
147
|
+
|
|
148
|
+
async function fetchPools() {
|
|
149
|
+
const sdk = createLaunchpadSDK({
|
|
150
|
+
wallet: 'your-private-key'
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Fetch recent pools with pagination
|
|
154
|
+
const pools = await sdk.fetchPools({
|
|
155
|
+
type: 'recent',
|
|
156
|
+
limit: 10,
|
|
157
|
+
page: 1
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
console.log(\`Found \${pools.total} pools\`);
|
|
161
|
+
console.log(\`Page \${pools.page} of \${pools.totalPages}\`);
|
|
162
|
+
console.log(\`Has next page: \${pools.hasNext}\`);
|
|
163
|
+
|
|
164
|
+
pools.pools.forEach(pool => {
|
|
165
|
+
console.log(\`\${pool.tokenName}: \${pool.tokenSymbol}\`);
|
|
166
|
+
console.log(\`Creator: \${pool.creatorAddress}\`);
|
|
167
|
+
console.log(\`Created: \${pool.createdAt}\`);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Fetch specific pool details
|
|
171
|
+
const details = await sdk.fetchPoolDetails('dragnrkti');
|
|
172
|
+
|
|
173
|
+
console.log('Sale status:', details.saleStatus);
|
|
174
|
+
console.log('Base price:', details.basePrice);
|
|
175
|
+
console.log('Max supply:', details.maxSupply);
|
|
176
|
+
console.log('Native token quantity:', details.nativeTokenQuantity);
|
|
177
|
+
}
|
|
178
|
+
\`\`\`
|
|
179
|
+
|
|
180
|
+
**MCP Tool Equivalents:**
|
|
181
|
+
- \`gala_launchpad_fetch_pools\`
|
|
182
|
+
- \`gala_launchpad_fetch_pool_details\`
|
|
183
|
+
`,
|
|
184
|
+
|
|
185
|
+
'balances': `
|
|
186
|
+
## Checking Balances with SDK
|
|
187
|
+
|
|
188
|
+
\`\`\`typescript
|
|
189
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
190
|
+
|
|
191
|
+
async function checkBalances() {
|
|
192
|
+
const sdk = createLaunchpadSDK({
|
|
193
|
+
wallet: 'your-private-key'
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Check GALA balance
|
|
197
|
+
const galaBalance = await sdk.fetchGalaBalance();
|
|
198
|
+
console.log(\`GALA: \${galaBalance.balance}\`);
|
|
199
|
+
console.log(\`Decimals: \${galaBalance.decimals}\`);
|
|
200
|
+
console.log(\`Last updated: \${galaBalance.lastUpdated.toISOString()}\`);
|
|
201
|
+
|
|
202
|
+
// Check specific token balance
|
|
203
|
+
const tokenBalance = await sdk.fetchTokenBalance({
|
|
204
|
+
tokenName: 'dragnrkti',
|
|
205
|
+
address: sdk.getAddress()
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
console.log(\`Token: \${tokenBalance.quantity}\`);
|
|
209
|
+
console.log(\`USD value: $\${tokenBalance.holdingPriceUsd}\`);
|
|
210
|
+
console.log(\`GALA value: \${tokenBalance.holdingPriceGala}\`);
|
|
211
|
+
|
|
212
|
+
// Check all tokens held
|
|
213
|
+
const portfolio = await sdk.fetchTokensHeld({
|
|
214
|
+
address: sdk.getAddress(),
|
|
215
|
+
limit: 20
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
console.log(\`Holding \${portfolio.total} different tokens\`);
|
|
219
|
+
portfolio.tokens.forEach(token => {
|
|
220
|
+
console.log(\`\${token.name}: \${token.quantity}\`);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
\`\`\`
|
|
224
|
+
|
|
225
|
+
**MCP Tool Equivalents:**
|
|
226
|
+
- \`gala_launchpad_fetch_gala_balance\`
|
|
227
|
+
- \`gala_launchpad_fetch_token_balance\`
|
|
228
|
+
- \`gala_launchpad_fetch_tokens_held\`
|
|
229
|
+
`,
|
|
230
|
+
|
|
231
|
+
'token-creation': `
|
|
232
|
+
## Creating Tokens with SDK
|
|
233
|
+
|
|
234
|
+
\`\`\`typescript
|
|
235
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
236
|
+
|
|
237
|
+
async function launchToken() {
|
|
238
|
+
const sdk = createLaunchpadSDK({
|
|
239
|
+
wallet: 'your-private-key'
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// 1. Check if name/symbol available
|
|
243
|
+
const nameAvailable = await sdk.isTokenNameAvailable('mytoken');
|
|
244
|
+
const symbolAvailable = await sdk.isTokenSymbolAvailable('MTK');
|
|
245
|
+
|
|
246
|
+
if (!nameAvailable || !symbolAvailable) {
|
|
247
|
+
throw new Error('Name or symbol already taken');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// 2. Check launch fee
|
|
251
|
+
const launchFee = await sdk.fetchLaunchTokenFee();
|
|
252
|
+
console.log(\`Launch fee: \${launchFee} GALA\`);
|
|
253
|
+
|
|
254
|
+
// 3. Upload token image (Node.js only)
|
|
255
|
+
const imageUpload = await sdk.uploadTokenImage({
|
|
256
|
+
tokenName: 'mytoken',
|
|
257
|
+
imagePath: '/path/to/image.png'
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// 4. Launch the token
|
|
261
|
+
const result = await sdk.launchToken({
|
|
262
|
+
tokenName: 'mytoken',
|
|
263
|
+
tokenSymbol: 'MTK',
|
|
264
|
+
tokenDescription: 'My awesome token',
|
|
265
|
+
tokenImage: imageUpload.imageUrl,
|
|
266
|
+
websiteUrl: 'https://mytoken.com',
|
|
267
|
+
twitterUrl: 'https://twitter.com/mytoken',
|
|
268
|
+
preBuyQuantity: '100' // Optional: pre-buy with GALA
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
console.log('Token launched!');
|
|
272
|
+
console.log('Transaction ID:', result.transactionId);
|
|
273
|
+
|
|
274
|
+
// Get frontend URL
|
|
275
|
+
const url = sdk.getUrlByTokenName('mytoken');
|
|
276
|
+
console.log(\`View at: \${url}\`);
|
|
277
|
+
}
|
|
278
|
+
\`\`\`
|
|
279
|
+
|
|
280
|
+
**MCP Tool Equivalents:**
|
|
281
|
+
- \`gala_launchpad_check_token_name\`
|
|
282
|
+
- \`gala_launchpad_check_token_symbol\`
|
|
283
|
+
- \`gala_launchpad_fetch_launch_token_fee\`
|
|
284
|
+
- \`gala_launchpad_upload_token_image\`
|
|
285
|
+
- \`gala_launchpad_launch_token\`
|
|
286
|
+
- \`gala_launchpad_get_url_by_token_name\`
|
|
287
|
+
`,
|
|
288
|
+
|
|
289
|
+
'multi-wallet': `
|
|
290
|
+
## Multi-Wallet Support with SDK
|
|
291
|
+
|
|
292
|
+
\`\`\`typescript
|
|
293
|
+
import { createLaunchpadSDK, createWallet } from '@gala-chain/launchpad-sdk';
|
|
294
|
+
|
|
295
|
+
async function multiWalletExample() {
|
|
296
|
+
// Main SDK with your wallet
|
|
297
|
+
const sdk = createLaunchpadSDK({
|
|
298
|
+
wallet: 'your-main-private-key'
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// Create a test wallet
|
|
302
|
+
const testWallet = createWallet();
|
|
303
|
+
console.log('Test wallet:', testWallet.address);
|
|
304
|
+
|
|
305
|
+
// 1. Fund test wallet from main wallet
|
|
306
|
+
await sdk.transferGala({
|
|
307
|
+
recipientAddress: testWallet.address,
|
|
308
|
+
amount: '1000'
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// 2. Have test wallet buy tokens (using privateKey override)
|
|
312
|
+
const buyCalc = await sdk.calculateBuyAmount({
|
|
313
|
+
tokenName: 'dragnrkti',
|
|
314
|
+
amount: '100',
|
|
315
|
+
type: 'native'
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
const buyResult = await sdk.buy({
|
|
319
|
+
tokenName: 'dragnrkti',
|
|
320
|
+
amount: '100',
|
|
321
|
+
type: 'native',
|
|
322
|
+
expectedAmount: buyCalc.amount,
|
|
323
|
+
slippageToleranceFactor: 0.01,
|
|
324
|
+
privateKey: testWallet.privateKey // Override to use test wallet
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
console.log('Test wallet bought tokens');
|
|
328
|
+
|
|
329
|
+
// 3. Have test wallet post comment
|
|
330
|
+
await sdk.postComment({
|
|
331
|
+
tokenName: 'dragnrkti',
|
|
332
|
+
content: 'Great project!',
|
|
333
|
+
privateKey: testWallet.privateKey // Test wallet posts
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// 4. Check balances for both wallets
|
|
337
|
+
const mainBalance = await sdk.fetchGalaBalance(); // Main wallet
|
|
338
|
+
const testBalance = await sdk.fetchGalaBalance(testWallet.address); // Test wallet
|
|
339
|
+
|
|
340
|
+
console.log(\`Main wallet: \${mainBalance.balance} GALA\`);
|
|
341
|
+
console.log(\`Test wallet: \${testBalance.balance} GALA\`);
|
|
342
|
+
}
|
|
343
|
+
\`\`\`
|
|
344
|
+
|
|
345
|
+
**Key Points:**
|
|
346
|
+
- All signing operations support \`privateKey\` parameter
|
|
347
|
+
- Creates temporary SDK instance internally
|
|
348
|
+
- Supports: buy, sell, launchToken, transfers, comments, profile updates
|
|
349
|
+
`,
|
|
350
|
+
|
|
351
|
+
'transfers': `
|
|
352
|
+
## Token Transfers with SDK
|
|
353
|
+
|
|
354
|
+
\`\`\`typescript
|
|
355
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
356
|
+
|
|
357
|
+
async function transferTokens() {
|
|
358
|
+
const sdk = createLaunchpadSDK({
|
|
359
|
+
wallet: 'your-private-key'
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
// Transfer GALA tokens
|
|
363
|
+
const galaTransfer = await sdk.transferGala({
|
|
364
|
+
recipientAddress: '0x1234...', // or 'eth|1234...'
|
|
365
|
+
amount: '100',
|
|
366
|
+
uniqueKey: 'galaconnect-operation-my-transfer-123' // Optional idempotency
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
console.log('GALA transfer ID:', galaTransfer.transactionId);
|
|
370
|
+
console.log('Status:', galaTransfer.status);
|
|
371
|
+
|
|
372
|
+
// Transfer launchpad tokens
|
|
373
|
+
const tokenTransfer = await sdk.transferToken({
|
|
374
|
+
to: 'eth|5678...',
|
|
375
|
+
tokenName: 'dragnrkti',
|
|
376
|
+
amount: '1000', // Token amount
|
|
377
|
+
uniqueKey: 'galaconnect-operation-token-456'
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
console.log('Token transfer ID:', tokenTransfer.transactionId);
|
|
381
|
+
}
|
|
382
|
+
\`\`\`
|
|
383
|
+
|
|
384
|
+
**Features:**
|
|
385
|
+
- EIP-712 signatures for security
|
|
386
|
+
- Supports both \`0x\` and \`eth|\` address formats
|
|
387
|
+
- Optional idempotency keys prevent duplicates
|
|
388
|
+
- Comprehensive validation
|
|
389
|
+
|
|
390
|
+
**MCP Tool Equivalents:**
|
|
391
|
+
- \`gala_launchpad_transfer_gala\`
|
|
392
|
+
- \`gala_launchpad_transfer_token\`
|
|
393
|
+
`,
|
|
394
|
+
|
|
395
|
+
'error-handling': `
|
|
396
|
+
## Error Handling with SDK
|
|
397
|
+
|
|
398
|
+
\`\`\`typescript
|
|
399
|
+
import {
|
|
400
|
+
createLaunchpadSDK,
|
|
401
|
+
ValidationError,
|
|
402
|
+
NetworkError,
|
|
403
|
+
TransactionError,
|
|
404
|
+
TokenNotFoundError
|
|
405
|
+
} from '@gala-chain/launchpad-sdk';
|
|
406
|
+
|
|
407
|
+
async function errorHandlingExample() {
|
|
408
|
+
const sdk = createLaunchpadSDK({
|
|
409
|
+
wallet: 'your-private-key'
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
try {
|
|
413
|
+
// Attempt trade
|
|
414
|
+
const result = await sdk.buy({
|
|
415
|
+
tokenName: 'dragnrkti',
|
|
416
|
+
amount: '100',
|
|
417
|
+
type: 'native',
|
|
418
|
+
expectedAmount: '5000',
|
|
419
|
+
slippageToleranceFactor: 0.01
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
console.log('Success:', result.transactionId);
|
|
423
|
+
|
|
424
|
+
} catch (error) {
|
|
425
|
+
if (error instanceof ValidationError) {
|
|
426
|
+
console.error('Invalid input:', error.message);
|
|
427
|
+
console.error('Field:', error.field);
|
|
428
|
+
console.error('Code:', error.code);
|
|
429
|
+
|
|
430
|
+
} else if (error instanceof TokenNotFoundError) {
|
|
431
|
+
console.error('Token does not exist:', error.tokenName);
|
|
432
|
+
|
|
433
|
+
} catch if (error instanceof NetworkError) {
|
|
434
|
+
console.error('Network issue:', error.message);
|
|
435
|
+
console.error('Status code:', error.statusCode);
|
|
436
|
+
|
|
437
|
+
} else if (error instanceof TransactionError) {
|
|
438
|
+
console.error('Transaction failed:', error.message);
|
|
439
|
+
console.error('Transaction ID:', error.transactionId);
|
|
440
|
+
|
|
441
|
+
} else {
|
|
442
|
+
console.error('Unexpected error:', error);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
\`\`\`
|
|
447
|
+
|
|
448
|
+
**Error Types:**
|
|
449
|
+
- \`ValidationError\` - Invalid input parameters
|
|
450
|
+
- \`NetworkError\` - HTTP/network failures
|
|
451
|
+
- \`TransactionError\` - Blockchain transaction failures
|
|
452
|
+
- \`TokenNotFoundError\` - Token doesn't exist
|
|
453
|
+
- \`ConfigurationError\` - SDK misconfiguration
|
|
454
|
+
- \`WebSocketError\` - Real-time connection issues
|
|
455
|
+
`,
|
|
456
|
+
|
|
457
|
+
'installation': `
|
|
458
|
+
## Installing and Importing SDK
|
|
459
|
+
|
|
460
|
+
### NPM Installation
|
|
461
|
+
|
|
462
|
+
\`\`\`bash
|
|
463
|
+
# Install SDK
|
|
464
|
+
npm install @gala-chain/launchpad-sdk
|
|
465
|
+
|
|
466
|
+
# Install peer dependencies
|
|
467
|
+
npm install ethers@^6.15.0 @gala-chain/api@^2.4.3 @gala-chain/connect@^2.4.3 \\
|
|
468
|
+
socket.io-client@^4.8.1 axios@^1.12.2 bignumber.js@^9.1.2 zod@^3.25.76
|
|
469
|
+
\`\`\`
|
|
470
|
+
|
|
471
|
+
### Import Patterns
|
|
472
|
+
|
|
473
|
+
\`\`\`typescript
|
|
474
|
+
// Main SDK class
|
|
475
|
+
import { LaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
476
|
+
|
|
477
|
+
// Helper functions (recommended)
|
|
478
|
+
import {
|
|
479
|
+
createLaunchpadSDK,
|
|
480
|
+
createTestLaunchpadSDK,
|
|
481
|
+
createWallet,
|
|
482
|
+
validateWalletInput
|
|
483
|
+
} from '@gala-chain/launchpad-sdk';
|
|
484
|
+
|
|
485
|
+
// Error types
|
|
486
|
+
import {
|
|
487
|
+
ValidationError,
|
|
488
|
+
NetworkError,
|
|
489
|
+
TransactionError,
|
|
490
|
+
TokenNotFoundError
|
|
491
|
+
} from '@gala-chain/launchpad-sdk';
|
|
492
|
+
|
|
493
|
+
// Type definitions
|
|
494
|
+
import type {
|
|
495
|
+
PoolData,
|
|
496
|
+
TradeResult,
|
|
497
|
+
TokenBalanceInfo,
|
|
498
|
+
BuyTokenOptions,
|
|
499
|
+
SellTokenOptions
|
|
500
|
+
} from '@gala-chain/launchpad-sdk';
|
|
501
|
+
\`\`\`
|
|
502
|
+
|
|
503
|
+
### Environment Configuration
|
|
504
|
+
|
|
505
|
+
\`\`\`typescript
|
|
506
|
+
// Development (default)
|
|
507
|
+
const sdk = createLaunchpadSDK({
|
|
508
|
+
wallet: 'your-private-key',
|
|
509
|
+
config: {
|
|
510
|
+
baseUrl: 'https://lpad-backend-dev1.defi.gala.com',
|
|
511
|
+
debug: true
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
// Production
|
|
516
|
+
const sdk = createLaunchpadSDK({
|
|
517
|
+
wallet: 'your-private-key',
|
|
518
|
+
config: {
|
|
519
|
+
baseUrl: 'https://lpad-backend-prod1.defi.gala.com',
|
|
520
|
+
debug: false,
|
|
521
|
+
timeout: 60000
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
\`\`\`
|
|
525
|
+
`,
|
|
526
|
+
|
|
527
|
+
'local-calculations': `
|
|
528
|
+
## Local Bonding Curve Calculations with SDK
|
|
529
|
+
|
|
530
|
+
\`\`\`typescript
|
|
531
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
532
|
+
|
|
533
|
+
async function localCalculationsExample() {
|
|
534
|
+
const sdk = createLaunchpadSDK({
|
|
535
|
+
wallet: 'your-private-key'
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
// ============================================================================
|
|
539
|
+
// LOCAL CALCULATIONS - Instant quotes without network calls
|
|
540
|
+
// ============================================================================
|
|
541
|
+
|
|
542
|
+
// 1. Buy calculation (local, instant)
|
|
543
|
+
const localBuy = await sdk.calculateBuyAmountLocal({
|
|
544
|
+
tokenName: 'dragnrkti',
|
|
545
|
+
amount: '100', // Spending 100 GALA
|
|
546
|
+
type: 'native' // 'native' = GALA amount, 'exact' = token amount
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
console.log('LOCAL Buy Quote (instant):');
|
|
550
|
+
console.log(' Tokens received:', localBuy.amount);
|
|
551
|
+
console.log(' Transaction fee:', localBuy.transactionFee);
|
|
552
|
+
console.log(' RBC Fee:', localBuy.reverseBondingCurveFee); // Always "0" for buys
|
|
553
|
+
console.log(' Gas fee:', localBuy.gasFee);
|
|
554
|
+
|
|
555
|
+
// 2. Sell calculation (local, requires pool details)
|
|
556
|
+
const poolDetails = await sdk.fetchPoolDetails('dragnrkti');
|
|
557
|
+
|
|
558
|
+
const localSell = await sdk.calculateSellAmountLocal({
|
|
559
|
+
tokenName: 'dragnrkti',
|
|
560
|
+
amount: '1000', // Selling 1000 tokens
|
|
561
|
+
type: 'exact',
|
|
562
|
+
// Required parameters from pool details:
|
|
563
|
+
maxSupply: poolDetails.maxSupply.toString(),
|
|
564
|
+
minFeePortion: poolDetails.reverseBondingCurveMinFeeFactor || 0,
|
|
565
|
+
maxFeePortion: poolDetails.reverseBondingCurveMaxFeeFactor || 0
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
console.log('LOCAL Sell Quote (instant):');
|
|
569
|
+
console.log(' GALA received:', localSell.amount);
|
|
570
|
+
console.log(' RBC Fee:', localSell.reverseBondingCurveFee);
|
|
571
|
+
console.log(' Transaction fee:', localSell.transactionFee);
|
|
572
|
+
|
|
573
|
+
// ============================================================================
|
|
574
|
+
// EXTERNAL CALCULATIONS - Real-time network queries (explicit)
|
|
575
|
+
// ============================================================================
|
|
576
|
+
|
|
577
|
+
// 3. External buy (explicit network call)
|
|
578
|
+
const externalBuy = await sdk.calculateBuyAmountExternal({
|
|
579
|
+
tokenName: 'dragnrkti',
|
|
580
|
+
amount: '100',
|
|
581
|
+
type: 'native'
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
console.log('EXTERNAL Buy Quote (network):');
|
|
585
|
+
console.log(' Tokens received:', externalBuy.amount);
|
|
586
|
+
|
|
587
|
+
// 4. External sell (explicit network call)
|
|
588
|
+
const externalSell = await sdk.calculateSellAmountExternal({
|
|
589
|
+
tokenName: 'dragnrkti',
|
|
590
|
+
amount: '1000',
|
|
591
|
+
type: 'exact'
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
console.log('EXTERNAL Sell Quote (network):');
|
|
595
|
+
console.log(' GALA received:', externalSell.amount);
|
|
596
|
+
|
|
597
|
+
// ============================================================================
|
|
598
|
+
// A/B COMPARISON - Verify local accuracy
|
|
599
|
+
// ============================================================================
|
|
600
|
+
|
|
601
|
+
const buyDiff = Math.abs(parseFloat(localBuy.amount) - parseFloat(externalBuy.amount));
|
|
602
|
+
const buyPct = (buyDiff / parseFloat(externalBuy.amount)) * 100;
|
|
603
|
+
|
|
604
|
+
console.log('Local vs External Accuracy:');
|
|
605
|
+
console.log(\` Buy difference: \${buyPct.toFixed(4)}% (should be <0.01%)\`);
|
|
606
|
+
|
|
607
|
+
// ============================================================================
|
|
608
|
+
// PERFORMANCE BENEFIT - Local is instant
|
|
609
|
+
// ============================================================================
|
|
610
|
+
|
|
611
|
+
console.time('Local calculation');
|
|
612
|
+
await sdk.calculateBuyAmountLocal({ tokenName: 'dragnrkti', amount: '100', type: 'native' });
|
|
613
|
+
console.timeEnd('Local calculation'); // ~0ms (instant)
|
|
614
|
+
|
|
615
|
+
console.time('External calculation');
|
|
616
|
+
await sdk.calculateBuyAmountExternal({ tokenName: 'dragnrkti', amount: '100', type: 'native' });
|
|
617
|
+
console.timeEnd('External calculation'); // ~200-500ms (network roundtrip)
|
|
618
|
+
}
|
|
619
|
+
\`\`\`
|
|
620
|
+
|
|
621
|
+
**Benefits of Local Calculations:**
|
|
622
|
+
- ✅ Instant quotes (no network delay)
|
|
623
|
+
- ✅ Offline support (no internet required)
|
|
624
|
+
- ✅ No API rate limits
|
|
625
|
+
- ✅ Perfect accuracy (<0.01% difference)
|
|
626
|
+
- ✅ Reduced server load
|
|
627
|
+
|
|
628
|
+
**When to Use:**
|
|
629
|
+
- Local: Price discovery, UI updates, offline scenarios
|
|
630
|
+
- External: Production trades (always verify before executing)
|
|
631
|
+
|
|
632
|
+
**MCP Tool Equivalents:**
|
|
633
|
+
- \`gala_launchpad_calculate_buy_amount_local\`
|
|
634
|
+
- \`gala_launchpad_calculate_buy_amount_external\`
|
|
635
|
+
- \`gala_launchpad_calculate_sell_amount_local\`
|
|
636
|
+
- \`gala_launchpad_calculate_sell_amount_external\`
|
|
637
|
+
`,
|
|
638
|
+
|
|
639
|
+
'mcp-to-sdk-mapping': `
|
|
640
|
+
## MCP Tool to SDK Method Mapping
|
|
641
|
+
|
|
642
|
+
### Trading Operations
|
|
643
|
+
| MCP Tool | SDK Method | Notes |
|
|
644
|
+
|----------|------------|-------|
|
|
645
|
+
| \`gala_launchpad_calculate_buy_amount\` | \`sdk.calculateBuyAmount(options)\` | Get quote before buying |
|
|
646
|
+
| \`gala_launchpad_calculate_buy_amount_local\` | \`sdk.calculateBuyAmountLocal(options)\` | Local instant quote (buy) |
|
|
647
|
+
| \`gala_launchpad_calculate_buy_amount_external\` | \`sdk.calculateBuyAmountExternal(options)\` | Explicit network quote (buy) |
|
|
648
|
+
| \`gala_launchpad_calculate_sell_amount\` | \`sdk.calculateSellAmount(options)\` | Get quote before selling |
|
|
649
|
+
| \`gala_launchpad_calculate_sell_amount_local\` | \`sdk.calculateSellAmountLocal(options)\` | Local instant quote (sell) |
|
|
650
|
+
| \`gala_launchpad_calculate_sell_amount_external\` | \`sdk.calculateSellAmountExternal(options)\` | Explicit network quote (sell) |
|
|
651
|
+
| \`gala_launchpad_buy_tokens\` | \`sdk.buy(options)\` | Execute token purchase |
|
|
652
|
+
| \`gala_launchpad_sell_tokens\` | \`sdk.sell(options)\` | Execute token sale |
|
|
653
|
+
| \`gala_launchpad_graduate_token\` | \`sdk.graduateToken(options)\` | One-step pool graduation |
|
|
654
|
+
|
|
655
|
+
### Pool Management
|
|
656
|
+
| MCP Tool | SDK Method | Notes |
|
|
657
|
+
|----------|------------|-------|
|
|
658
|
+
| \`gala_launchpad_fetch_pools\` | \`sdk.fetchPools(options)\` | List pools with filtering |
|
|
659
|
+
| \`gala_launchpad_fetch_pool_details\` | \`sdk.fetchPoolDetails(tokenName)\` | Get specific pool data |
|
|
660
|
+
| \`gala_launchpad_fetch_token_distribution\` | \`sdk.fetchTokenDistribution(tokenName)\` | Holder distribution |
|
|
661
|
+
| \`gala_launchpad_fetch_token_badges\` | \`sdk.fetchTokenBadges(tokenName)\` | Achievement badges |
|
|
662
|
+
|
|
663
|
+
### Balance & Portfolio
|
|
664
|
+
| MCP Tool | SDK Method | Notes |
|
|
665
|
+
|----------|------------|-------|
|
|
666
|
+
| \`gala_launchpad_fetch_gala_balance\` | \`sdk.fetchGalaBalance(address?)\` | GALA balance |
|
|
667
|
+
| \`gala_launchpad_fetch_token_balance\` | \`sdk.fetchTokenBalance(options)\` | Specific token balance |
|
|
668
|
+
| \`gala_launchpad_fetch_tokens_held\` | \`sdk.fetchTokensHeld(options)\` | Portfolio holdings |
|
|
669
|
+
| \`gala_launchpad_fetch_tokens_created\` | \`sdk.fetchTokensCreated(options)\` | Created tokens |
|
|
670
|
+
|
|
671
|
+
### Token Creation
|
|
672
|
+
| MCP Tool | SDK Method | Notes |
|
|
673
|
+
|----------|------------|-------|
|
|
674
|
+
| \`gala_launchpad_fetch_launch_token_fee\` | \`sdk.fetchLaunchTokenFee()\` | Get launch cost |
|
|
675
|
+
| \`gala_launchpad_check_token_name\` | \`sdk.isTokenNameAvailable(name)\` | Check name |
|
|
676
|
+
| \`gala_launchpad_check_token_symbol\` | \`sdk.isTokenSymbolAvailable(symbol)\` | Check symbol |
|
|
677
|
+
| \`gala_launchpad_launch_token\` | \`sdk.launchToken(data)\` | Create token |
|
|
678
|
+
| \`gala_launchpad_upload_token_image\` | \`sdk.uploadTokenImage(options)\` | Upload image |
|
|
679
|
+
|
|
680
|
+
### Transfers & Social
|
|
681
|
+
| MCP Tool | SDK Method | Notes |
|
|
682
|
+
|----------|------------|-------|
|
|
683
|
+
| \`gala_launchpad_transfer_gala\` | \`sdk.transferGala(options)\` | Transfer GALA |
|
|
684
|
+
| \`gala_launchpad_transfer_token\` | \`sdk.transferToken(options)\` | Transfer tokens |
|
|
685
|
+
| \`gala_launchpad_post_comment\` | \`sdk.postComment(options)\` | Post comment |
|
|
686
|
+
| \`gala_launchpad_fetch_comments\` | \`sdk.fetchComments(options)\` | Get comments |
|
|
687
|
+
|
|
688
|
+
### Utilities
|
|
689
|
+
| MCP Tool | SDK Method | Notes |
|
|
690
|
+
|----------|------------|-------|
|
|
691
|
+
| \`gala_launchpad_create_wallet\` | \`createWallet()\` | Generate wallet |
|
|
692
|
+
| \`gala_launchpad_get_address\` | \`sdk.getAddress()\` | Get backend format |
|
|
693
|
+
| \`gala_launchpad_get_ethereum_address\` | \`sdk.getEthereumAddress()\` | Get 0x format |
|
|
694
|
+
| \`gala_launchpad_get_url_by_token_name\` | \`sdk.getUrlByTokenName(name)\` | Frontend URL |
|
|
695
|
+
| \`gala_launchpad_is_token_graduated\` | \`sdk.isTokenGraduated(tokenName)\` | Check if pool completed |
|
|
696
|
+
|
|
697
|
+
**Key Difference:** MCP tools return \`{ success: true, data: {...} }\`, SDK methods return direct result objects.
|
|
698
|
+
`,
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* SDK Usage Explanation Tool
|
|
703
|
+
*/
|
|
704
|
+
export const explainSdkUsageTool: MCPTool = {
|
|
705
|
+
name: 'gala_launchpad_explain_sdk_usage',
|
|
706
|
+
description: `Get detailed SDK code examples and explanations for using the Gala Launchpad SDK directly.
|
|
707
|
+
|
|
708
|
+
This tool provides complete, working code examples showing how to use the SDK instead of MCP tools.
|
|
709
|
+
Perfect for developers who want to integrate the SDK into their applications.
|
|
710
|
+
|
|
711
|
+
Available topics:
|
|
712
|
+
- 'buy-tokens' - Complete buying workflow with calculation and execution
|
|
713
|
+
- 'sell-tokens' - Complete selling workflow with slippage protection
|
|
714
|
+
- 'pool-graduation' - Graduate a bonding curve pool
|
|
715
|
+
- 'fetch-pools' - Query pool data and details
|
|
716
|
+
- 'balances' - Check GALA and token balances
|
|
717
|
+
- 'token-creation' - Launch new tokens
|
|
718
|
+
- 'multi-wallet' - Use multiple wallets (privateKey override pattern)
|
|
719
|
+
- 'transfers' - Transfer GALA and tokens between wallets
|
|
720
|
+
- 'error-handling' - Handle errors and exceptions
|
|
721
|
+
- 'installation' - Install and configure SDK
|
|
722
|
+
- 'local-calculations' - Local vs external bonding curve calculations
|
|
723
|
+
- 'mcp-to-sdk-mapping' - Complete mapping of MCP tools to SDK methods
|
|
724
|
+
|
|
725
|
+
Returns runnable TypeScript code examples with explanations.`,
|
|
726
|
+
inputSchema: {
|
|
727
|
+
type: 'object',
|
|
728
|
+
properties: {
|
|
729
|
+
topic: {
|
|
730
|
+
type: 'string',
|
|
731
|
+
enum: [
|
|
732
|
+
'buy-tokens',
|
|
733
|
+
'sell-tokens',
|
|
734
|
+
'pool-graduation',
|
|
735
|
+
'fetch-pools',
|
|
736
|
+
'balances',
|
|
737
|
+
'token-creation',
|
|
738
|
+
'multi-wallet',
|
|
739
|
+
'transfers',
|
|
740
|
+
'error-handling',
|
|
741
|
+
'installation',
|
|
742
|
+
'local-calculations',
|
|
743
|
+
'mcp-to-sdk-mapping',
|
|
744
|
+
],
|
|
745
|
+
description: 'The SDK usage topic to explain',
|
|
746
|
+
},
|
|
747
|
+
},
|
|
748
|
+
required: ['topic'],
|
|
749
|
+
},
|
|
750
|
+
handler: withErrorHandling(async (_sdk, args) => {
|
|
751
|
+
const example = SDK_EXAMPLES[args.topic as keyof typeof SDK_EXAMPLES];
|
|
752
|
+
|
|
753
|
+
if (!example) {
|
|
754
|
+
throw new Error(`Unknown topic: ${args.topic}`);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
return formatSuccess({
|
|
758
|
+
topic: args.topic,
|
|
759
|
+
explanation: example,
|
|
760
|
+
sdkVersion: '3.8.0',
|
|
761
|
+
packageName: '@gala-chain/launchpad-sdk',
|
|
762
|
+
documentation: 'https://www.npmjs.com/package/@gala-chain/launchpad-sdk',
|
|
763
|
+
});
|
|
764
|
+
}),
|
|
765
|
+
};
|