@gala-chain/launchpad-mcp-server 1.23.1 → 1.24.1
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 +20 -0
- package/README.md +34 -6
- package/dist/constants/mcpToolNames.d.ts +6 -2
- package/dist/constants/mcpToolNames.d.ts.map +1 -1
- package/dist/constants/mcpToolNames.js +4 -2
- 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/explore-dex-pools.d.ts +20 -0
- package/dist/prompts/explore-dex-pools.d.ts.map +1 -0
- package/dist/prompts/explore-dex-pools.js +132 -0
- package/dist/prompts/explore-dex-pools.js.map +1 -0
- package/dist/prompts/index.d.ts +3 -2
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +6 -3
- package/dist/prompts/index.js.map +1 -1
- package/dist/prompts/pools.js.map +1 -1
- package/dist/tools/dex/fetchAllDexPools.d.ts +9 -0
- package/dist/tools/dex/fetchAllDexPools.d.ts.map +1 -0
- package/dist/tools/dex/fetchAllDexPools.js +45 -0
- package/dist/tools/dex/fetchAllDexPools.js.map +1 -0
- package/dist/tools/dex/fetchDexPools.d.ts +9 -0
- package/dist/tools/dex/fetchDexPools.d.ts.map +1 -0
- package/dist/tools/dex/fetchDexPools.js +58 -0
- package/dist/tools/dex/fetchDexPools.js.map +1 -0
- package/dist/tools/dex/index.d.ts +4 -3
- package/dist/tools/dex/index.d.ts.map +1 -1
- package/dist/tools/dex/index.js +9 -4
- package/dist/tools/dex/index.js.map +1 -1
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.js +3 -3
- 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 +3 -3
- 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 +255 -0
- package/src/constants/mcpToolNames.ts +183 -0
- package/src/index.ts +19 -0
- package/src/prompts/__tests__/promptStructure.test.ts +187 -0
- package/src/prompts/__tests__/registry.test.ts +349 -0
- package/src/prompts/analysis.ts +380 -0
- package/src/prompts/balances.ts +182 -0
- package/src/prompts/create-token.ts +123 -0
- package/src/prompts/creation-utils.ts +103 -0
- package/src/prompts/dex-trading.ts +86 -0
- package/src/prompts/discover-tokens.ts +86 -0
- package/src/prompts/explore-dex-pools.ts +138 -0
- package/src/prompts/index.ts +178 -0
- package/src/prompts/liquidity-positions.ts +237 -0
- package/src/prompts/pools.ts +496 -0
- package/src/prompts/portfolio.ts +208 -0
- package/src/prompts/social.ts +94 -0
- package/src/prompts/trading-calculations.ts +414 -0
- package/src/prompts/trading.ts +160 -0
- package/src/prompts/transfers.ts +97 -0
- package/src/prompts/utility-tools.ts +266 -0
- package/src/prompts/utility.ts +77 -0
- package/src/prompts/utils/handlerHelpers.ts +55 -0
- package/src/prompts/utils/textTemplates.ts +73 -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/fetchAllDexPools.ts +45 -0
- package/src/tools/dex/fetchDexPools.ts +58 -0
- package/src/tools/dex/index.ts +231 -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 +429 -0
- package/tests/wallet-management-integration.test.ts +284 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,1446 @@
|
|
|
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 Advanced Methods
|
|
144
|
+
|
|
145
|
+
\`\`\`typescript
|
|
146
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
147
|
+
|
|
148
|
+
// 1. BASIC POOL FETCHING - With Pagination
|
|
149
|
+
async function basicPoolFetching() {
|
|
150
|
+
const sdk = createLaunchpadSDK({ wallet: 'your-private-key' });
|
|
151
|
+
|
|
152
|
+
// Fetch recent pools with pagination
|
|
153
|
+
const pools = await sdk.fetchPools({
|
|
154
|
+
type: 'recent',
|
|
155
|
+
limit: 10,
|
|
156
|
+
page: 1
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
console.log(\`Found \${pools.total} pools, page \${pools.page} of \${pools.totalPages}\`);
|
|
160
|
+
pools.pools.forEach(pool => {
|
|
161
|
+
console.log(\`\${pool.tokenName}: \${pool.tokenSymbol}\`);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 2. AUTO-PAGINATED FETCHING - Get ALL Pools
|
|
166
|
+
async function fetchAllPools() {
|
|
167
|
+
const sdk = createLaunchpadSDK({ wallet: 'your-private-key' });
|
|
168
|
+
|
|
169
|
+
// Auto-paginated - returns all pools without manual pagination
|
|
170
|
+
const allPools = await sdk.fetchAllPools({
|
|
171
|
+
type: 'recent'
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
console.log(\`Total pools: \${allPools.pools.length}\`);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// 3. POOL DETAILS - Complete information
|
|
178
|
+
async function getPoolDetails(tokenName) {
|
|
179
|
+
const sdk = createLaunchpadSDK({ wallet: 'your-private-key' });
|
|
180
|
+
|
|
181
|
+
const details = await sdk.fetchPoolDetails(tokenName);
|
|
182
|
+
|
|
183
|
+
console.log('Sale status:', details.saleStatus); // 'Ongoing' or 'Completed'
|
|
184
|
+
console.log('Base price:', details.basePrice);
|
|
185
|
+
console.log('Max supply:', details.maxSupply);
|
|
186
|
+
console.log('Remaining tokens:', details.sellingTokenQuantity);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// 4. POOL DETAILS FOR CALCULATIONS - Optimized for math
|
|
190
|
+
async function getOptimizedPoolDetails(tokenName) {
|
|
191
|
+
const sdk = createLaunchpadSDK({ wallet: 'your-private-key' });
|
|
192
|
+
|
|
193
|
+
// Returns only fields needed for bonding curve calculations
|
|
194
|
+
const poolData = await sdk.fetchPoolDetailsForCalculation(tokenName);
|
|
195
|
+
|
|
196
|
+
console.log('Current supply:', poolData.currentSupply);
|
|
197
|
+
console.log('Remaining tokens:', poolData.remainingTokens);
|
|
198
|
+
console.log('Max supply:', poolData.maxSupply);
|
|
199
|
+
console.log('Reverse bonding curve max fee:', poolData.reverseBondingCurveMaxFeeFactor);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// 5. VOLUME & OHLCV DATA - Historical candlestick data
|
|
203
|
+
async function getVolumeData(tokenName) {
|
|
204
|
+
const sdk = createLaunchpadSDK({ wallet: 'your-private-key' });
|
|
205
|
+
|
|
206
|
+
// Different resolutions: '1m', '5m', '15m', '1h', '4h', '1d'
|
|
207
|
+
const volumeData = await sdk.fetchVolumeData({
|
|
208
|
+
tokenName: tokenName,
|
|
209
|
+
from: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000), // Last 7 days
|
|
210
|
+
to: new Date(),
|
|
211
|
+
resolution: '1h' // 1-hour candlesticks
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
volumeData.forEach(candle => {
|
|
215
|
+
console.log(\`\${candle.time}: O:\${candle.open} H:\${candle.high} L:\${candle.low} C:\${candle.close} V:\${candle.volume}\`);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// 6. SPOT PRICES - DEX tokens (GALA, SILK, MUSIC)
|
|
220
|
+
async function getDexTokenPrices() {
|
|
221
|
+
const sdk = createLaunchpadSDK({ wallet: 'your-private-key' });
|
|
222
|
+
|
|
223
|
+
// Fetch prices for multiple DEX tokens
|
|
224
|
+
const prices = await sdk.fetchTokenPrice(['GALA', 'SILK', 'MUSIC']);
|
|
225
|
+
|
|
226
|
+
console.log(\`GALA: $\${prices.GALA}\`);
|
|
227
|
+
console.log(\`SILK: $\${prices.SILK}\`);
|
|
228
|
+
console.log(\`MUSIC: $\${prices.MUSIC}\`);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// 7. LAUNCHPAD TOKEN SPOT PRICES
|
|
232
|
+
async function getLaunchpadTokenPrice(tokenName) {
|
|
233
|
+
const sdk = createLaunchpadSDK({ wallet: 'your-private-key' });
|
|
234
|
+
|
|
235
|
+
// Get USD spot price for a launchpad token (anime, woohoo, etc.)
|
|
236
|
+
const price = await sdk.fetchLaunchpadTokenSpotPrice(tokenName);
|
|
237
|
+
|
|
238
|
+
console.log(\`\${tokenName} price: $\${price}\`);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// 8. RESOLVE UTILITY ADDRESSES
|
|
242
|
+
async function resolveAddresses(tokenName) {
|
|
243
|
+
const sdk = createLaunchpadSDK({ wallet: 'your-private-key' });
|
|
244
|
+
|
|
245
|
+
// Get GalaChain vault address for token
|
|
246
|
+
const vaultAddress = await sdk.resolveVaultAddress(tokenName);
|
|
247
|
+
console.log(\`Vault address: \${vaultAddress}\`);
|
|
248
|
+
|
|
249
|
+
// Get TokenClassKey for token
|
|
250
|
+
const tokenClassKey = await sdk.resolveTokenClassKey(tokenName);
|
|
251
|
+
console.log(\`TokenClassKey: \${tokenClassKey}\`);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// 9. COMPLETE INVESTMENT ANALYSIS WORKFLOW
|
|
255
|
+
async function analyzeToken(tokenName) {
|
|
256
|
+
const sdk = createLaunchpadSDK({ wallet: 'your-private-key' });
|
|
257
|
+
|
|
258
|
+
// Get all token data in parallel
|
|
259
|
+
const [details, volumeData, distribution, badges] = await Promise.all([
|
|
260
|
+
sdk.fetchPoolDetails(tokenName),
|
|
261
|
+
sdk.fetchVolumeData({ tokenName, resolution: '1d' }),
|
|
262
|
+
sdk.fetchTokenDistribution(tokenName),
|
|
263
|
+
sdk.fetchTokenBadges(tokenName)
|
|
264
|
+
]);
|
|
265
|
+
|
|
266
|
+
// Analyze status
|
|
267
|
+
console.log(\`Pool Status: \${details.saleStatus}\`);
|
|
268
|
+
console.log(\`Supply: \${details.currentSupply} / \${details.maxSupply}\`);
|
|
269
|
+
|
|
270
|
+
// Analyze volume trend
|
|
271
|
+
const volumes = volumeData.map(v => parseFloat(v.volume));
|
|
272
|
+
const avgVolume = volumes.reduce((a, b) => a + b, 0) / volumes.length;
|
|
273
|
+
console.log(\`Avg daily volume: $\${avgVolume.toFixed(2)}\`);
|
|
274
|
+
|
|
275
|
+
// Analyze distribution
|
|
276
|
+
const top5Ownership = distribution.holders
|
|
277
|
+
.sort((a, b) => parseFloat(b.balance) - parseFloat(a.balance))
|
|
278
|
+
.slice(0, 5)
|
|
279
|
+
.reduce((sum, h) => sum + h.percentage, 0);
|
|
280
|
+
console.log(\`Top 5 holders: \${top5Ownership.toFixed(2)}%\`);
|
|
281
|
+
|
|
282
|
+
// Check badges
|
|
283
|
+
console.log(\`Badges: \${badges.join(', ')}\`);
|
|
284
|
+
}
|
|
285
|
+
\`\`\`
|
|
286
|
+
|
|
287
|
+
**MCP Tool Equivalents:**
|
|
288
|
+
- \`gala_launchpad_fetch_pools\` - Paginated pool list
|
|
289
|
+
- \`gala_launchpad_fetch_all_pools\` - Auto-paginated all pools
|
|
290
|
+
- \`gala_launchpad_fetch_pool_details\` - Complete pool information
|
|
291
|
+
- \`gala_launchpad_fetch_pool_details_for_calculation\` - Optimized for calculations
|
|
292
|
+
- \`gala_launchpad_fetch_volume_data\` - OHLCV candlestick data
|
|
293
|
+
- \`gala_launchpad_fetch_token_spot_price\` - DEX token prices (GALA, SILK, MUSIC)
|
|
294
|
+
- \`gala_launchpad_fetch_launchpad_token_spot_price\` - Launchpad token USD prices
|
|
295
|
+
- \`gala_launchpad_fetch_token_distribution\` - Token holder analysis
|
|
296
|
+
- \`gala_launchpad_fetch_token_badges\` - Achievement badges
|
|
297
|
+
- \`gala_launchpad_resolve_vault_address\` - Get vault address
|
|
298
|
+
- \`gala_launchpad_resolve_token_class_key\` - Get TokenClassKey
|
|
299
|
+
`,
|
|
300
|
+
|
|
301
|
+
'balances': `
|
|
302
|
+
## Checking Balances with SDK
|
|
303
|
+
|
|
304
|
+
\`\`\`typescript
|
|
305
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
306
|
+
|
|
307
|
+
async function checkBalances() {
|
|
308
|
+
const sdk = createLaunchpadSDK({
|
|
309
|
+
wallet: 'your-private-key'
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
// Check GALA balance
|
|
313
|
+
const galaBalance = await sdk.fetchGalaBalance();
|
|
314
|
+
console.log(\`GALA: \${galaBalance.balance}\`);
|
|
315
|
+
console.log(\`Decimals: \${galaBalance.decimals}\`);
|
|
316
|
+
console.log(\`Last updated: \${galaBalance.lastUpdated.toISOString()}\`);
|
|
317
|
+
|
|
318
|
+
// Check specific token balance
|
|
319
|
+
const tokenBalance = await sdk.fetchTokenBalance({
|
|
320
|
+
tokenName: 'dragnrkti',
|
|
321
|
+
address: sdk.getAddress()
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
console.log(\`Token: \${tokenBalance.quantity}\`);
|
|
325
|
+
console.log(\`USD value: $\${tokenBalance.holdingPriceUsd}\`);
|
|
326
|
+
console.log(\`GALA value: \${tokenBalance.holdingPriceGala}\`);
|
|
327
|
+
|
|
328
|
+
// Check all tokens held
|
|
329
|
+
const portfolio = await sdk.fetchTokensHeld({
|
|
330
|
+
address: sdk.getAddress(),
|
|
331
|
+
limit: 20
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
console.log(\`Holding \${portfolio.total} different tokens\`);
|
|
335
|
+
portfolio.tokens.forEach(token => {
|
|
336
|
+
console.log(\`\${token.name}: \${token.quantity}\`);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
// Check tokens created by this wallet
|
|
340
|
+
const createdTokens = await sdk.fetchTokensCreated({
|
|
341
|
+
address: sdk.getAddress(),
|
|
342
|
+
limit: 10
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
console.log(\`Created \${createdTokens.total} tokens\`);
|
|
346
|
+
createdTokens.tokens.forEach(token => {
|
|
347
|
+
console.log(\` \${token.symbol}: \${token.name}\`);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// Get user profile
|
|
351
|
+
const profile = await sdk.fetchProfile();
|
|
352
|
+
console.log(\`Profile: \${profile.fullName}\`);
|
|
353
|
+
|
|
354
|
+
// Check profile of another user
|
|
355
|
+
const otherProfile = await sdk.fetchProfile('eth|0x...');
|
|
356
|
+
console.log(\`Other user: \${otherProfile.fullName}\`);
|
|
357
|
+
}
|
|
358
|
+
\`\`\`
|
|
359
|
+
|
|
360
|
+
**MCP Tool Equivalents:**
|
|
361
|
+
- \`gala_launchpad_fetch_gala_balance\`
|
|
362
|
+
- \`gala_launchpad_fetch_token_balance\`
|
|
363
|
+
- \`gala_launchpad_fetch_tokens_held\`
|
|
364
|
+
- \`gala_launchpad_fetch_tokens_created\`
|
|
365
|
+
- \`gala_launchpad_fetch_profile\`
|
|
366
|
+
`,
|
|
367
|
+
|
|
368
|
+
'token-creation': `
|
|
369
|
+
## Creating Tokens with SDK
|
|
370
|
+
|
|
371
|
+
\`\`\`typescript
|
|
372
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
373
|
+
|
|
374
|
+
async function launchToken() {
|
|
375
|
+
const sdk = createLaunchpadSDK({
|
|
376
|
+
wallet: 'your-private-key'
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// 1. Check if name/symbol available
|
|
380
|
+
const nameAvailable = await sdk.isTokenNameAvailable('mytoken');
|
|
381
|
+
const symbolAvailable = await sdk.isTokenSymbolAvailable('MTK');
|
|
382
|
+
|
|
383
|
+
if (!nameAvailable || !symbolAvailable) {
|
|
384
|
+
throw new Error('Name or symbol already taken');
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// 2. Check launch fee
|
|
388
|
+
const launchFee = await sdk.fetchLaunchTokenFee();
|
|
389
|
+
console.log(\`Launch fee: \${launchFee} GALA\`);
|
|
390
|
+
|
|
391
|
+
// 3. Upload token image (Node.js only)
|
|
392
|
+
const imageUpload = await sdk.uploadTokenImage({
|
|
393
|
+
tokenName: 'mytoken',
|
|
394
|
+
imagePath: '/path/to/image.png'
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// 4. Launch the token
|
|
398
|
+
const result = await sdk.launchToken({
|
|
399
|
+
tokenName: 'mytoken',
|
|
400
|
+
tokenSymbol: 'MTK',
|
|
401
|
+
tokenDescription: 'My awesome token',
|
|
402
|
+
tokenImage: imageUpload.imageUrl,
|
|
403
|
+
websiteUrl: 'https://mytoken.com',
|
|
404
|
+
twitterUrl: 'https://twitter.com/mytoken',
|
|
405
|
+
preBuyQuantity: '100' // Optional: pre-buy with GALA
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
console.log('Token launched!');
|
|
409
|
+
console.log('Transaction ID:', result.transactionId);
|
|
410
|
+
|
|
411
|
+
// Get frontend URL
|
|
412
|
+
const url = sdk.getUrlByTokenName('mytoken');
|
|
413
|
+
console.log(\`View at: \${url}\`);
|
|
414
|
+
}
|
|
415
|
+
\`\`\`
|
|
416
|
+
|
|
417
|
+
**MCP Tool Equivalents:**
|
|
418
|
+
- \`gala_launchpad_check_token_name\`
|
|
419
|
+
- \`gala_launchpad_check_token_symbol\`
|
|
420
|
+
- \`gala_launchpad_fetch_launch_token_fee\`
|
|
421
|
+
- \`gala_launchpad_upload_token_image\`
|
|
422
|
+
- \`gala_launchpad_launch_token\`
|
|
423
|
+
- \`gala_launchpad_get_url_by_token_name\`
|
|
424
|
+
`,
|
|
425
|
+
|
|
426
|
+
'multi-wallet': `
|
|
427
|
+
## Multi-Wallet Support with SDK
|
|
428
|
+
|
|
429
|
+
\`\`\`typescript
|
|
430
|
+
import { createLaunchpadSDK, createWallet } from '@gala-chain/launchpad-sdk';
|
|
431
|
+
|
|
432
|
+
async function multiWalletExample() {
|
|
433
|
+
// Main SDK with your wallet
|
|
434
|
+
const sdk = createLaunchpadSDK({
|
|
435
|
+
wallet: 'your-main-private-key'
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
// Create a test wallet
|
|
439
|
+
const testWallet = createWallet();
|
|
440
|
+
console.log('Test wallet:', testWallet.address);
|
|
441
|
+
|
|
442
|
+
// 1. Fund test wallet from main wallet
|
|
443
|
+
await sdk.transferGala({
|
|
444
|
+
recipientAddress: testWallet.address,
|
|
445
|
+
amount: '1000'
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
// 2. Have test wallet buy tokens (using privateKey override)
|
|
449
|
+
const buyCalc = await sdk.calculateBuyAmount({
|
|
450
|
+
tokenName: 'dragnrkti',
|
|
451
|
+
amount: '100',
|
|
452
|
+
type: 'native'
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
const buyResult = await sdk.buy({
|
|
456
|
+
tokenName: 'dragnrkti',
|
|
457
|
+
amount: '100',
|
|
458
|
+
type: 'native',
|
|
459
|
+
expectedAmount: buyCalc.amount,
|
|
460
|
+
slippageToleranceFactor: 0.01,
|
|
461
|
+
privateKey: testWallet.privateKey // Override to use test wallet
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
console.log('Test wallet bought tokens');
|
|
465
|
+
|
|
466
|
+
// 3. Have test wallet post comment
|
|
467
|
+
await sdk.postComment({
|
|
468
|
+
tokenName: 'dragnrkti',
|
|
469
|
+
content: 'Great project!',
|
|
470
|
+
privateKey: testWallet.privateKey // Test wallet posts
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
// 4. Check balances for both wallets
|
|
474
|
+
const mainBalance = await sdk.fetchGalaBalance(); // Main wallet
|
|
475
|
+
const testBalance = await sdk.fetchGalaBalance(testWallet.address); // Test wallet
|
|
476
|
+
|
|
477
|
+
console.log(\`Main wallet: \${mainBalance.balance} GALA\`);
|
|
478
|
+
console.log(\`Test wallet: \${testBalance.balance} GALA\`);
|
|
479
|
+
}
|
|
480
|
+
\`\`\`
|
|
481
|
+
|
|
482
|
+
**Key Points:**
|
|
483
|
+
- All signing operations support \`privateKey\` parameter
|
|
484
|
+
- Creates temporary SDK instance internally
|
|
485
|
+
- Supports: buy, sell, launchToken, transfers, comments, profile updates
|
|
486
|
+
`,
|
|
487
|
+
|
|
488
|
+
'transfers': `
|
|
489
|
+
## Token Transfers with SDK
|
|
490
|
+
|
|
491
|
+
\`\`\`typescript
|
|
492
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
493
|
+
|
|
494
|
+
async function transferTokens() {
|
|
495
|
+
const sdk = createLaunchpadSDK({
|
|
496
|
+
wallet: 'your-private-key'
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
// Transfer GALA tokens
|
|
500
|
+
const galaTransfer = await sdk.transferGala({
|
|
501
|
+
recipientAddress: '0x1234...', // or 'eth|1234...'
|
|
502
|
+
amount: '100',
|
|
503
|
+
uniqueKey: 'galaconnect-operation-my-transfer-123' // Optional idempotency
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
console.log('GALA transfer ID:', galaTransfer.transactionId);
|
|
507
|
+
console.log('Status:', galaTransfer.status);
|
|
508
|
+
|
|
509
|
+
// Transfer launchpad tokens
|
|
510
|
+
const tokenTransfer = await sdk.transferToken({
|
|
511
|
+
to: 'eth|5678...',
|
|
512
|
+
tokenName: 'dragnrkti',
|
|
513
|
+
amount: '1000', // Token amount
|
|
514
|
+
uniqueKey: 'galaconnect-operation-token-456'
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
console.log('Token transfer ID:', tokenTransfer.transactionId);
|
|
518
|
+
}
|
|
519
|
+
\`\`\`
|
|
520
|
+
|
|
521
|
+
**Features:**
|
|
522
|
+
- EIP-712 signatures for security
|
|
523
|
+
- Supports both \`0x\` and \`eth|\` address formats
|
|
524
|
+
- Optional idempotency keys prevent duplicates
|
|
525
|
+
- Comprehensive validation
|
|
526
|
+
|
|
527
|
+
**MCP Tool Equivalents:**
|
|
528
|
+
- \`gala_launchpad_transfer_gala\`
|
|
529
|
+
- \`gala_launchpad_transfer_token\`
|
|
530
|
+
`,
|
|
531
|
+
|
|
532
|
+
'dex-trading': `
|
|
533
|
+
## DEX Trading with SDK - GalaSwap Integration
|
|
534
|
+
|
|
535
|
+
Trade graduated tokens on the GalaSwap DEX with real-time WebSocket monitoring:
|
|
536
|
+
|
|
537
|
+
\`\`\`typescript
|
|
538
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
539
|
+
|
|
540
|
+
async function dexTradingExample() {
|
|
541
|
+
// 1. Initialize SDK with wallet
|
|
542
|
+
const sdk = createLaunchpadSDK({
|
|
543
|
+
wallet: 'your-private-key',
|
|
544
|
+
env: 'production'
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
// ============================================================================
|
|
548
|
+
// QUOTES: Get pricing information (read-only operations)
|
|
549
|
+
// ============================================================================
|
|
550
|
+
|
|
551
|
+
// Quote 1: Exact input (spend known GALA amount)
|
|
552
|
+
const quoteIn = await sdk.getSwapQuoteExactInput('GALA', 'GUSDC', '100');
|
|
553
|
+
console.log('Spend 100 GALA → get ~' + quoteIn.estimatedOutput + ' GUSDC');
|
|
554
|
+
console.log('Price impact: ' + quoteIn.priceImpact + '%');
|
|
555
|
+
console.log('Fee tier: ' + quoteIn.feeTier + ' bps');
|
|
556
|
+
|
|
557
|
+
// Quote 2: Exact output (get known token amount)
|
|
558
|
+
const quoteOut = await sdk.getSwapQuoteExactOutput('GALA', 'GUSDC', '100');
|
|
559
|
+
console.log('Get exactly 100 GUSDC → need ~' + quoteOut.inputAmount + ' GALA');
|
|
560
|
+
|
|
561
|
+
// ============================================================================
|
|
562
|
+
// EXECUTE: Perform the swap with slippage protection
|
|
563
|
+
// ============================================================================
|
|
564
|
+
|
|
565
|
+
const result = await sdk.executeSwap(
|
|
566
|
+
'GALA', // from token
|
|
567
|
+
'GUSDC', // to token
|
|
568
|
+
'100', // input amount (100 GALA)
|
|
569
|
+
quoteIn.estimatedOutput, // Use quote's output!
|
|
570
|
+
quoteIn.feeTier, // Use quote's fee tier!
|
|
571
|
+
0.01 // 1% slippage tolerance
|
|
572
|
+
);
|
|
573
|
+
|
|
574
|
+
console.log('Transaction ID: ' + result.transactionId);
|
|
575
|
+
console.log('Status: ' + result.status);
|
|
576
|
+
console.log('Received: ' + result.outputAmount + ' ' + result.toToken);
|
|
577
|
+
|
|
578
|
+
// ============================================================================
|
|
579
|
+
// PORTFOLIO: Check balances and assets
|
|
580
|
+
// ============================================================================
|
|
581
|
+
|
|
582
|
+
const assets = await sdk.getSwapUserAssets(sdk.getEthereumAddress());
|
|
583
|
+
console.log('Assets in wallet:');
|
|
584
|
+
assets.forEach(asset => {
|
|
585
|
+
console.log(' ' + asset.symbol + ': ' + asset.balance);
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
// ============================================================================
|
|
589
|
+
// POOL INFO: Check liquidity before trading
|
|
590
|
+
// ============================================================================
|
|
591
|
+
|
|
592
|
+
const pool = await sdk.getSwapPoolInfo('GALA', 'GUSDC');
|
|
593
|
+
console.log('GALA↔GUSDC Pool Info:');
|
|
594
|
+
console.log(' Liquidity: ' + pool.liquidity);
|
|
595
|
+
console.log(' Available fee tiers: ' + pool.feeTiers.join(', ') + ' bps');
|
|
596
|
+
console.log(' 24h swaps: ' + pool.swapCount);
|
|
597
|
+
}
|
|
598
|
+
\`\`\`
|
|
599
|
+
|
|
600
|
+
**Key Architecture:**
|
|
601
|
+
- **Unified WebSocket**: Uses LaunchpadSDK's unified WebSocket for transaction monitoring
|
|
602
|
+
- **Environment Alignment**: STAGE/PROD URLs must match between LaunchpadSDK and GSwapService
|
|
603
|
+
- **Token Formats**: Supports simple names ('GALA') or full IDs ('GALA|Unit|none|none')
|
|
604
|
+
- **Slippage Protection**: Always use quote values for execution
|
|
605
|
+
- **Fee Tiers**: 500 (0.05%), 3000 (0.30%), 10000 (1.00%)
|
|
606
|
+
|
|
607
|
+
**MCP Tool Equivalents:**
|
|
608
|
+
- \`gala_launchpad_get_swap_quote_exact_input\`
|
|
609
|
+
- \`gala_launchpad_get_swap_quote_exact_output\`
|
|
610
|
+
- \`gala_launchpad_execute_swap\`
|
|
611
|
+
- \`gala_launchpad_get_swap_user_assets\`
|
|
612
|
+
- \`gala_launchpad_get_swap_pool_info\`
|
|
613
|
+
`,
|
|
614
|
+
|
|
615
|
+
'error-handling': `
|
|
616
|
+
## Error Handling with SDK
|
|
617
|
+
|
|
618
|
+
\`\`\`typescript
|
|
619
|
+
import {
|
|
620
|
+
createLaunchpadSDK,
|
|
621
|
+
ValidationError,
|
|
622
|
+
NetworkError,
|
|
623
|
+
TransactionError,
|
|
624
|
+
TokenNotFoundError
|
|
625
|
+
} from '@gala-chain/launchpad-sdk';
|
|
626
|
+
|
|
627
|
+
async function errorHandlingExample() {
|
|
628
|
+
const sdk = createLaunchpadSDK({
|
|
629
|
+
wallet: 'your-private-key'
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
try {
|
|
633
|
+
// Attempt trade
|
|
634
|
+
const result = await sdk.buy({
|
|
635
|
+
tokenName: 'dragnrkti',
|
|
636
|
+
amount: '100',
|
|
637
|
+
type: 'native',
|
|
638
|
+
expectedAmount: '5000',
|
|
639
|
+
slippageToleranceFactor: 0.01
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
console.log('Success:', result.transactionId);
|
|
643
|
+
|
|
644
|
+
} catch (error) {
|
|
645
|
+
if (error instanceof ValidationError) {
|
|
646
|
+
console.error('Invalid input:', error.message);
|
|
647
|
+
console.error('Field:', error.field);
|
|
648
|
+
console.error('Code:', error.code);
|
|
649
|
+
|
|
650
|
+
} else if (error instanceof TokenNotFoundError) {
|
|
651
|
+
console.error('Token does not exist:', error.tokenName);
|
|
652
|
+
|
|
653
|
+
} else if (error instanceof NetworkError) {
|
|
654
|
+
console.error('Network issue:', error.message);
|
|
655
|
+
console.error('Status code:', error.statusCode);
|
|
656
|
+
|
|
657
|
+
} else if (error instanceof TransactionError) {
|
|
658
|
+
console.error('Transaction failed:', error.message);
|
|
659
|
+
console.error('Transaction ID:', error.transactionId);
|
|
660
|
+
|
|
661
|
+
} else {
|
|
662
|
+
console.error('Unexpected error:', error);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
\`\`\`
|
|
667
|
+
|
|
668
|
+
**Error Types:**
|
|
669
|
+
- \`ValidationError\` - Invalid input parameters
|
|
670
|
+
- \`NetworkError\` - HTTP/network failures
|
|
671
|
+
- \`TransactionError\` - Blockchain transaction failures
|
|
672
|
+
- \`TokenNotFoundError\` - Token doesn't exist
|
|
673
|
+
- \`ConfigurationError\` - SDK misconfiguration
|
|
674
|
+
- \`WebSocketError\` - Real-time connection issues
|
|
675
|
+
`,
|
|
676
|
+
|
|
677
|
+
'installation': `
|
|
678
|
+
## Installing and Importing SDK
|
|
679
|
+
|
|
680
|
+
### NPM Installation
|
|
681
|
+
|
|
682
|
+
\`\`\`bash
|
|
683
|
+
# Install SDK
|
|
684
|
+
npm install @gala-chain/launchpad-sdk
|
|
685
|
+
|
|
686
|
+
# Install peer dependencies
|
|
687
|
+
npm install ethers@^6.15.0 @gala-chain/api@^2.4.3 @gala-chain/connect@^2.4.3 \\
|
|
688
|
+
socket.io-client@^4.8.1 axios@^1.12.2 bignumber.js@^9.1.2 zod@^3.25.76
|
|
689
|
+
\`\`\`
|
|
690
|
+
|
|
691
|
+
### Import Patterns
|
|
692
|
+
|
|
693
|
+
\`\`\`typescript
|
|
694
|
+
// Main SDK class
|
|
695
|
+
import { LaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
696
|
+
|
|
697
|
+
// Helper functions (recommended)
|
|
698
|
+
import {
|
|
699
|
+
createLaunchpadSDK,
|
|
700
|
+
createTestLaunchpadSDK,
|
|
701
|
+
createWallet,
|
|
702
|
+
validateWalletInput
|
|
703
|
+
} from '@gala-chain/launchpad-sdk';
|
|
704
|
+
|
|
705
|
+
// Error types
|
|
706
|
+
import {
|
|
707
|
+
ValidationError,
|
|
708
|
+
NetworkError,
|
|
709
|
+
TransactionError,
|
|
710
|
+
TokenNotFoundError
|
|
711
|
+
} from '@gala-chain/launchpad-sdk';
|
|
712
|
+
|
|
713
|
+
// Type definitions
|
|
714
|
+
import type {
|
|
715
|
+
PoolData,
|
|
716
|
+
TradeResult,
|
|
717
|
+
TokenBalanceInfo,
|
|
718
|
+
BuyTokenOptions,
|
|
719
|
+
SellTokenOptions
|
|
720
|
+
} from '@gala-chain/launchpad-sdk';
|
|
721
|
+
\`\`\`
|
|
722
|
+
|
|
723
|
+
### Environment Configuration
|
|
724
|
+
|
|
725
|
+
\`\`\`typescript
|
|
726
|
+
// Production (default)
|
|
727
|
+
const sdk = createLaunchpadSDK({
|
|
728
|
+
wallet: 'your-private-key',
|
|
729
|
+
config: {
|
|
730
|
+
baseUrl: 'https://lpad-backend-prod1.defi.gala.com',
|
|
731
|
+
debug: false,
|
|
732
|
+
timeout: 60000
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
// Development
|
|
737
|
+
const sdk = createLaunchpadSDK({
|
|
738
|
+
wallet: 'your-private-key',
|
|
739
|
+
config: {
|
|
740
|
+
baseUrl: 'https://lpad-backend-dev1.defi.gala.com',
|
|
741
|
+
debug: true
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
\`\`\`
|
|
745
|
+
`,
|
|
746
|
+
|
|
747
|
+
'local-calculations': `
|
|
748
|
+
## Local Bonding Curve Calculations with SDK
|
|
749
|
+
|
|
750
|
+
\`\`\`typescript
|
|
751
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
752
|
+
|
|
753
|
+
async function localCalculationsExample() {
|
|
754
|
+
const sdk = createLaunchpadSDK({
|
|
755
|
+
wallet: 'your-private-key'
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
// ============================================================================
|
|
759
|
+
// LOCAL CALCULATIONS - Instant quotes without network calls
|
|
760
|
+
// ============================================================================
|
|
761
|
+
|
|
762
|
+
// 1. Buy calculation (local, instant)
|
|
763
|
+
const localBuy = await sdk.calculateBuyAmountLocal({
|
|
764
|
+
tokenName: 'dragnrkti',
|
|
765
|
+
amount: '100', // Spending 100 GALA
|
|
766
|
+
type: 'native' // 'native' = GALA amount, 'exact' = token amount
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
console.log('LOCAL Buy Quote (instant):');
|
|
770
|
+
console.log(' Tokens received:', localBuy.amount);
|
|
771
|
+
console.log(' Transaction fee:', localBuy.transactionFee);
|
|
772
|
+
console.log(' RBC Fee:', localBuy.reverseBondingCurveFee); // Always "0" for buys
|
|
773
|
+
console.log(' Gas fee:', localBuy.gasFee);
|
|
774
|
+
|
|
775
|
+
// 2. Sell calculation (local, requires pool details)
|
|
776
|
+
const poolDetails = await sdk.fetchPoolDetails('dragnrkti');
|
|
777
|
+
|
|
778
|
+
const localSell = await sdk.calculateSellAmountLocal({
|
|
779
|
+
tokenName: 'dragnrkti',
|
|
780
|
+
amount: '1000', // Selling 1000 tokens
|
|
781
|
+
type: 'exact',
|
|
782
|
+
// Required parameters from pool details:
|
|
783
|
+
maxSupply: poolDetails.maxSupply.toString(),
|
|
784
|
+
minFeePortion: poolDetails.reverseBondingCurveMinFeeFactor || 0,
|
|
785
|
+
maxFeePortion: poolDetails.reverseBondingCurveMaxFeeFactor || 0
|
|
786
|
+
});
|
|
787
|
+
|
|
788
|
+
console.log('LOCAL Sell Quote (instant):');
|
|
789
|
+
console.log(' GALA received:', localSell.amount);
|
|
790
|
+
console.log(' RBC Fee:', localSell.reverseBondingCurveFee);
|
|
791
|
+
console.log(' Transaction fee:', localSell.transactionFee);
|
|
792
|
+
|
|
793
|
+
// ============================================================================
|
|
794
|
+
// EXTERNAL CALCULATIONS - Real-time network queries (explicit)
|
|
795
|
+
// ============================================================================
|
|
796
|
+
|
|
797
|
+
// 3. External buy (explicit network call)
|
|
798
|
+
const externalBuy = await sdk.calculateBuyAmountExternal({
|
|
799
|
+
tokenName: 'dragnrkti',
|
|
800
|
+
amount: '100',
|
|
801
|
+
type: 'native'
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
console.log('EXTERNAL Buy Quote (network):');
|
|
805
|
+
console.log(' Tokens received:', externalBuy.amount);
|
|
806
|
+
|
|
807
|
+
// 4. External sell (explicit network call)
|
|
808
|
+
const externalSell = await sdk.calculateSellAmountExternal({
|
|
809
|
+
tokenName: 'dragnrkti',
|
|
810
|
+
amount: '1000',
|
|
811
|
+
type: 'exact'
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
console.log('EXTERNAL Sell Quote (network):');
|
|
815
|
+
console.log(' GALA received:', externalSell.amount);
|
|
816
|
+
|
|
817
|
+
// ============================================================================
|
|
818
|
+
// A/B COMPARISON - Verify local accuracy
|
|
819
|
+
// ============================================================================
|
|
820
|
+
|
|
821
|
+
const buyDiff = Math.abs(parseFloat(localBuy.amount) - parseFloat(externalBuy.amount));
|
|
822
|
+
const buyPct = (buyDiff / parseFloat(externalBuy.amount)) * 100;
|
|
823
|
+
|
|
824
|
+
console.log('Local vs External Accuracy:');
|
|
825
|
+
console.log(\` Buy difference: \${buyPct.toFixed(4)}% (should be <0.01%)\`);
|
|
826
|
+
|
|
827
|
+
// ============================================================================
|
|
828
|
+
// PERFORMANCE BENEFIT - Local is instant
|
|
829
|
+
// ============================================================================
|
|
830
|
+
|
|
831
|
+
console.time('Local calculation');
|
|
832
|
+
await sdk.calculateBuyAmountLocal({ tokenName: 'dragnrkti', amount: '100', type: 'native' });
|
|
833
|
+
console.timeEnd('Local calculation'); // ~0ms (instant)
|
|
834
|
+
|
|
835
|
+
console.time('External calculation');
|
|
836
|
+
await sdk.calculateBuyAmountExternal({ tokenName: 'dragnrkti', amount: '100', type: 'native' });
|
|
837
|
+
console.timeEnd('External calculation'); // ~200-500ms (network roundtrip)
|
|
838
|
+
}
|
|
839
|
+
\`\`\`
|
|
840
|
+
|
|
841
|
+
**Benefits of Local Calculations:**
|
|
842
|
+
- ✅ Instant quotes (no network delay)
|
|
843
|
+
- ✅ Offline support (no internet required)
|
|
844
|
+
- ✅ No API rate limits
|
|
845
|
+
- ✅ Perfect accuracy (<0.01% difference)
|
|
846
|
+
- ✅ Reduced server load
|
|
847
|
+
|
|
848
|
+
**When to Use:**
|
|
849
|
+
- Local: Price discovery, UI updates, offline scenarios
|
|
850
|
+
- External: Production trades (always verify before executing)
|
|
851
|
+
|
|
852
|
+
**MCP Tool Equivalents:**
|
|
853
|
+
- \`gala_launchpad_calculate_buy_amount_local\`
|
|
854
|
+
- \`gala_launchpad_calculate_buy_amount_external\`
|
|
855
|
+
- \`gala_launchpad_calculate_sell_amount_local\`
|
|
856
|
+
- \`gala_launchpad_calculate_sell_amount_external\`
|
|
857
|
+
`,
|
|
858
|
+
|
|
859
|
+
'price-history': `
|
|
860
|
+
## Historical Price Analysis with SDK
|
|
861
|
+
|
|
862
|
+
\`\`\`typescript
|
|
863
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
864
|
+
|
|
865
|
+
async function analyzePriceHistory() {
|
|
866
|
+
const sdk = createLaunchpadSDK({
|
|
867
|
+
wallet: 'your-private-key-or-mnemonic'
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
// Paginated price history
|
|
871
|
+
const history = await sdk.fetchPriceHistory({
|
|
872
|
+
tokenId: 'Token|Unit|GUSDC|eth:0x...',
|
|
873
|
+
from: new Date('2025-01-01'),
|
|
874
|
+
to: new Date('2025-01-31'),
|
|
875
|
+
sortOrder: 'DESC',
|
|
876
|
+
page: 1,
|
|
877
|
+
limit: 50
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
console.log(\`Found \${history.snapshots.length} snapshots\`);
|
|
881
|
+
console.log(\`Total available: \${history.total} (page \${history.page} of \${history.totalPages})\`);
|
|
882
|
+
|
|
883
|
+
// Auto-paginated complete history
|
|
884
|
+
const allHistory = await sdk.fetchAllPriceHistory({
|
|
885
|
+
tokenId: 'GWETH|Unit|none|none',
|
|
886
|
+
from: new Date('2024-01-01'),
|
|
887
|
+
sortOrder: 'ASC'
|
|
888
|
+
});
|
|
889
|
+
|
|
890
|
+
// Price analysis
|
|
891
|
+
const prices = allHistory.snapshots.map(s => parseFloat(s.price));
|
|
892
|
+
const avg = prices.reduce((a, b) => a + b, 0) / prices.length;
|
|
893
|
+
const variance = prices.reduce((sum, p) => sum + Math.pow(p - avg, 2), 0) / prices.length;
|
|
894
|
+
const volatility = Math.sqrt(variance);
|
|
895
|
+
|
|
896
|
+
console.log(\`Average: $\${avg.toFixed(4)}, Volatility: $\${volatility.toFixed(4)}\`);
|
|
897
|
+
|
|
898
|
+
// Data export (CSV)
|
|
899
|
+
const csv = ['timestamp,price'].concat(
|
|
900
|
+
allHistory.snapshots.map(s => \`\${s.timestamp.toISOString()},\${s.price}\`)
|
|
901
|
+
).join('\\n');
|
|
902
|
+
|
|
903
|
+
console.log('CSV export:', csv.split('\\n').slice(0, 3).join('\\n'));
|
|
904
|
+
}
|
|
905
|
+
\`\`\`
|
|
906
|
+
|
|
907
|
+
**Key Methods:**
|
|
908
|
+
- \`fetchPriceHistory()\` - Paginated historical prices (max 50 per page)
|
|
909
|
+
- \`fetchAllPriceHistory()\` - Auto-paginated complete history (all snapshots)
|
|
910
|
+
|
|
911
|
+
**Response Fields:**
|
|
912
|
+
- \`price\` - Token price as decimal string
|
|
913
|
+
- \`timestamp\` - ISO 8601 timestamp
|
|
914
|
+
- \`tokenId\` - Token identifier (pipe-delimited)
|
|
915
|
+
|
|
916
|
+
**Use Cases:**
|
|
917
|
+
- Technical analysis and charting
|
|
918
|
+
- Volatility assessment
|
|
919
|
+
- Price trend identification
|
|
920
|
+
- Data export for analytics
|
|
921
|
+
- Backtesting strategies
|
|
922
|
+
|
|
923
|
+
**Token ID Formats:**
|
|
924
|
+
- String: \`Token|Unit|GUSDC|eth:0x...\`
|
|
925
|
+
- Object: \`{ collection, category, type, additionalKey }\`
|
|
926
|
+
|
|
927
|
+
**MCP Tool Equivalents:**
|
|
928
|
+
- \`gala_launchpad_fetch_price_history\` - Paginated
|
|
929
|
+
- \`gala_launchpad_fetch_all_price_history\` - Auto-paginated
|
|
930
|
+
`,
|
|
931
|
+
|
|
932
|
+
'token-details': `
|
|
933
|
+
## Token Details and Metadata with SDK
|
|
934
|
+
|
|
935
|
+
\`\`\`typescript
|
|
936
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
937
|
+
|
|
938
|
+
async function analyzeTokenDetails() {
|
|
939
|
+
const sdk = createLaunchpadSDK({
|
|
940
|
+
wallet: 'your-private-key-or-mnemonic'
|
|
941
|
+
});
|
|
942
|
+
|
|
943
|
+
// Fetch token metadata
|
|
944
|
+
const details = await sdk.fetchTokenDetails('Token|Unit|GUSDC|eth:0x...');
|
|
945
|
+
|
|
946
|
+
console.log('Token Information:');
|
|
947
|
+
console.log(\` Name: \${details.name}\`);
|
|
948
|
+
console.log(\` Symbol: \${details.symbol}\`);
|
|
949
|
+
console.log(\` Decimals: \${details.decimals}\`);
|
|
950
|
+
console.log(\` Verified: \${details.verified}\`);
|
|
951
|
+
console.log(\` Trading: \${details.tradingEnabled}\`);
|
|
952
|
+
console.log(\` Network: \${details.network}\`);
|
|
953
|
+
console.log(\` Image: \${details.image}\`);
|
|
954
|
+
|
|
955
|
+
// Pre-trading validation
|
|
956
|
+
async function validateBeforeTrade(tokenId: string) {
|
|
957
|
+
const token = await sdk.fetchTokenDetails(tokenId);
|
|
958
|
+
|
|
959
|
+
if (!token.verified) {
|
|
960
|
+
console.warn(\`⚠️ \${token.symbol} is NOT verified\`);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
if (!token.tradingEnabled) {
|
|
964
|
+
throw new Error(\`Trading disabled for \${token.symbol}\`);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
if (token.network !== 'ethereum') {
|
|
968
|
+
throw new Error(\`Wrong network: got \${token.network}\`);
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
return token;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
// Batch token comparison
|
|
975
|
+
const tokens = ['GALA|Unit|none|none', 'Token|Unit|GUSDC|eth:0x...'];
|
|
976
|
+
const details_list = await Promise.all(
|
|
977
|
+
tokens.map(id => sdk.fetchTokenDetails(id).catch(() => null))
|
|
978
|
+
);
|
|
979
|
+
|
|
980
|
+
const verified = details_list.filter(t => t?.verified).length;
|
|
981
|
+
console.log(\`Verified tokens: \${verified}/\${tokens.length}\`);
|
|
982
|
+
}
|
|
983
|
+
\`\`\`
|
|
984
|
+
|
|
985
|
+
**Response Fields:**
|
|
986
|
+
- \`symbol\` - Token symbol (e.g., 'GUSDC')
|
|
987
|
+
- \`name\` - Full token name
|
|
988
|
+
- \`decimals\` - Decimal places
|
|
989
|
+
- \`verified\` - Verification status
|
|
990
|
+
- \`tradingEnabled\` - Trading availability
|
|
991
|
+
- \`network\` - Network name (e.g., 'ethereum')
|
|
992
|
+
- \`contractAddress\` - Smart contract address
|
|
993
|
+
- \`image\` - Token image URL
|
|
994
|
+
- \`chainId\` - Blockchain chain ID
|
|
995
|
+
|
|
996
|
+
**Use Cases:**
|
|
997
|
+
- Pre-trading validation and safety checks
|
|
998
|
+
- Display token metadata in UI
|
|
999
|
+
- Verify token authenticity
|
|
1000
|
+
- Network compatibility checking
|
|
1001
|
+
|
|
1002
|
+
**Token ID Formats:**
|
|
1003
|
+
- String: \`Token|Unit|GUSDC|eth:0x...\`
|
|
1004
|
+
- Object: \`{ collection, category, type, additionalKey }\`
|
|
1005
|
+
|
|
1006
|
+
**MCP Tool Equivalent:** \`gala_launchpad_fetch_token_details\`
|
|
1007
|
+
`,
|
|
1008
|
+
|
|
1009
|
+
'spot-prices-smart-routing': `
|
|
1010
|
+
## Smart Spot Price Routing with DEX Fallback
|
|
1011
|
+
|
|
1012
|
+
The SDK intelligently routes pricing requests between DEX and Launchpad backends based on token graduation status - no need to know which backend a token uses!
|
|
1013
|
+
|
|
1014
|
+
\`\`\`typescript
|
|
1015
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
1016
|
+
|
|
1017
|
+
async function tokenPricing() {
|
|
1018
|
+
const sdk = createLaunchpadSDK({
|
|
1019
|
+
wallet: 'your-private-key'
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
// OPTION 1: SMART ROUTING (Recommended) - Automatic backend selection
|
|
1023
|
+
// Use tokenId for ANY token (graduated or ungraduated)
|
|
1024
|
+
// SDK automatically detects and routes to correct backend
|
|
1025
|
+
console.log('=== Smart Routing (Recommended) ===');
|
|
1026
|
+
const smartPrice = await sdk.fetchTokenPrice({
|
|
1027
|
+
tokenId: 'Token|Unit|ANIME|eth:0x...' // Works for ANY token!
|
|
1028
|
+
});
|
|
1029
|
+
console.log(\`Token price: $\${smartPrice}\`);
|
|
1030
|
+
// ✅ Handles graduated tokens (DEX) automatically
|
|
1031
|
+
// ✅ Handles ungraduated tokens (Launchpad) automatically
|
|
1032
|
+
// ✅ No need to know token status beforehand
|
|
1033
|
+
|
|
1034
|
+
// OPTION 2: EXPLICIT DEX PRICING - Graduated tokens only
|
|
1035
|
+
// Use tokenId directly for DEX tokens
|
|
1036
|
+
console.log('\\n=== Explicit DEX Pricing ===');
|
|
1037
|
+
const dexPrices = await sdk.fetchTokenPrice({
|
|
1038
|
+
tokenId: 'GALA|Unit|none|none' // Or other DEX token
|
|
1039
|
+
});
|
|
1040
|
+
console.log(\`DEX Token GALA: $\${dexPrices}\`);
|
|
1041
|
+
|
|
1042
|
+
// OPTION 3: EXPLICIT LAUNCHPAD PRICING - Ungraduated tokens
|
|
1043
|
+
// Use tokenName for launchpad bonding curve tokens
|
|
1044
|
+
console.log('\\n=== Explicit Launchpad Pricing ===');
|
|
1045
|
+
const launchpadPrice = await sdk.fetchLaunchpadTokenSpotPrice('anime');
|
|
1046
|
+
console.log(\`Launchpad token anime: $\${launchpadPrice}\`);
|
|
1047
|
+
|
|
1048
|
+
// ADVANCED: Handle both pricing methods with error recovery
|
|
1049
|
+
console.log('\\n=== Fallback Pricing Strategy ===');
|
|
1050
|
+
async function getPriceWithFallback(tokenId: string, tokenName?: string) {
|
|
1051
|
+
try {
|
|
1052
|
+
// Try DEX pricing first
|
|
1053
|
+
return await sdk.fetchTokenPrice({ tokenId });
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
// If not on DEX, try launchpad pricing
|
|
1056
|
+
if (tokenName) {
|
|
1057
|
+
try {
|
|
1058
|
+
return await sdk.fetchLaunchpadTokenSpotPrice(tokenName);
|
|
1059
|
+
} catch (fallbackError) {
|
|
1060
|
+
throw new Error(\`Could not fetch price for \${tokenName}\`);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
throw error;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
const fallbackPrice = await getPriceWithFallback(
|
|
1068
|
+
'Token|Unit|ANIME|eth:0x...',
|
|
1069
|
+
'anime'
|
|
1070
|
+
);
|
|
1071
|
+
console.log(\`Fallback price: $\${fallbackPrice}\`);
|
|
1072
|
+
|
|
1073
|
+
// USECASE: Price comparison and discovery
|
|
1074
|
+
console.log('\\n=== Price Discovery ===');
|
|
1075
|
+
async function comparePrices(tokenName: string) {
|
|
1076
|
+
const launchpadPrice = await sdk.fetchLaunchpadTokenSpotPrice(tokenName);
|
|
1077
|
+
|
|
1078
|
+
// Check if graduated (on DEX)
|
|
1079
|
+
const isGraduated = await sdk.isTokenGraduated(tokenName);
|
|
1080
|
+
|
|
1081
|
+
if (isGraduated) {
|
|
1082
|
+
const dexPrice = await sdk.fetchTokenPrice({
|
|
1083
|
+
tokenId: \`Token|Unit|\${tokenName.toUpperCase()}|eth:0x...\`
|
|
1084
|
+
});
|
|
1085
|
+
console.log(\`Launchpad: $\${launchpadPrice}, DEX: $\${dexPrice}\`);
|
|
1086
|
+
return { launchpadPrice, dexPrice, graduated: true };
|
|
1087
|
+
} else {
|
|
1088
|
+
console.log(\`Launchpad: $\${launchpadPrice} (not on DEX yet)\`);
|
|
1089
|
+
return { launchpadPrice, graduated: false };
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
const priceComparison = await comparePrices('anime');
|
|
1094
|
+
}
|
|
1095
|
+
\`\`\`
|
|
1096
|
+
|
|
1097
|
+
**Smart Routing Benefits:**
|
|
1098
|
+
- ✅ **Seamless Transitions** - Works before and after token graduation
|
|
1099
|
+
- ✅ **No Backend Knowledge** - SDK handles routing automatically
|
|
1100
|
+
- ✅ **Error Handling** - Automatic fallback if needed
|
|
1101
|
+
- ✅ **Single API** - Use same method for all tokens
|
|
1102
|
+
|
|
1103
|
+
**When to Use Each Method:**
|
|
1104
|
+
|
|
1105
|
+
| Method | Use Case | Token Status |
|
|
1106
|
+
|--------|----------|--------------|
|
|
1107
|
+
| \`fetchTokenPrice({ tokenId })\` | Smart routing (recommended) | Any (DEX or Launchpad) |
|
|
1108
|
+
| \`fetchLaunchpadTokenSpotPrice(name)\` | Launchpad-only pricing | Ungraduated tokens |
|
|
1109
|
+
| \`isTokenGraduated(name)\` | Check token status | Any |
|
|
1110
|
+
|
|
1111
|
+
**Key Differences:**
|
|
1112
|
+
|
|
1113
|
+
**Ungraduated Tokens (Launchpad):**
|
|
1114
|
+
- Priced on exponential bonding curve
|
|
1115
|
+
- Token name parameter works: \`fetchLaunchpadTokenSpotPrice('anime')\`
|
|
1116
|
+
- Price affected by supply/demand
|
|
1117
|
+
|
|
1118
|
+
**Graduated Tokens (DEX):**
|
|
1119
|
+
- Priced on DEX via order books
|
|
1120
|
+
- Token ID format needed: \`Token|Unit|SYMBOL|eth:0x...\`
|
|
1121
|
+
- Market-driven pricing
|
|
1122
|
+
|
|
1123
|
+
**Graduation Impact:**
|
|
1124
|
+
When a token graduates from launchpad to DEX:
|
|
1125
|
+
- Bonding curve closes
|
|
1126
|
+
- Trading moves to DEX order books
|
|
1127
|
+
- Smart routing automatically switches backends
|
|
1128
|
+
- Old launchpad queries will fail (use DEX pricing instead)
|
|
1129
|
+
|
|
1130
|
+
**Error Handling:**
|
|
1131
|
+
\`\`\`typescript
|
|
1132
|
+
async function safePriceQuery(tokenId: string) {
|
|
1133
|
+
try {
|
|
1134
|
+
// Always try smart routing first
|
|
1135
|
+
return await sdk.fetchTokenPrice({ tokenId });
|
|
1136
|
+
} catch (error) {
|
|
1137
|
+
if (error.message.includes('not found')) {
|
|
1138
|
+
console.log('Token not available on DEX');
|
|
1139
|
+
// Could try fallback to launchpad pricing here
|
|
1140
|
+
}
|
|
1141
|
+
throw error;
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
\`\`\`
|
|
1145
|
+
|
|
1146
|
+
**MCP Tool Equivalents:**
|
|
1147
|
+
- \`gala_launchpad_fetch_token_spot_price\` - Smart routing
|
|
1148
|
+
- \`gala_launchpad_fetch_launchpad_token_spot_price\` - Launchpad-only
|
|
1149
|
+
- \`gala_launchpad_is_token_graduated\` - Check graduation status
|
|
1150
|
+
`,
|
|
1151
|
+
|
|
1152
|
+
'profile-management': `
|
|
1153
|
+
## User Profile Management with SDK
|
|
1154
|
+
|
|
1155
|
+
\`\`\`typescript
|
|
1156
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
1157
|
+
|
|
1158
|
+
async function manageUserProfiles() {
|
|
1159
|
+
const sdk = createLaunchpadSDK({
|
|
1160
|
+
wallet: 'your-private-key-or-mnemonic'
|
|
1161
|
+
});
|
|
1162
|
+
|
|
1163
|
+
// Fetch current user profile
|
|
1164
|
+
const myProfile = await sdk.fetchProfile();
|
|
1165
|
+
console.log(\`Name: \${myProfile.fullName}\`);
|
|
1166
|
+
console.log(\`Avatar: \${myProfile.profileImage}\`);
|
|
1167
|
+
|
|
1168
|
+
// Fetch another user's profile
|
|
1169
|
+
const other = await sdk.fetchProfile('eth|0x...');
|
|
1170
|
+
console.log(\`Other user: \${other.fullName}\`);
|
|
1171
|
+
|
|
1172
|
+
// Update profile
|
|
1173
|
+
const updated = await sdk.updateProfile({
|
|
1174
|
+
fullName: 'Satoshi Nakamoto',
|
|
1175
|
+
profileImage: 'https://example.com/avatar.png',
|
|
1176
|
+
address: sdk.getAddress()
|
|
1177
|
+
});
|
|
1178
|
+
|
|
1179
|
+
console.log(\`Updated: \${updated.fullName}\`);
|
|
1180
|
+
|
|
1181
|
+
// Upload profile image (Node.js only)
|
|
1182
|
+
const imgResult = await sdk.uploadProfileImage({
|
|
1183
|
+
imagePath: '/path/to/avatar.png'
|
|
1184
|
+
});
|
|
1185
|
+
|
|
1186
|
+
// Update with uploaded image
|
|
1187
|
+
await sdk.updateProfile({
|
|
1188
|
+
fullName: 'My Name',
|
|
1189
|
+
profileImage: imgResult.imageUrl,
|
|
1190
|
+
address: sdk.getAddress()
|
|
1191
|
+
});
|
|
1192
|
+
|
|
1193
|
+
// Complete workflow: Update profile, then launch token
|
|
1194
|
+
async function createTokenWithProfile() {
|
|
1195
|
+
const avatar = await sdk.uploadProfileImage({
|
|
1196
|
+
imagePath: '/path/to/pic.png'
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
await sdk.updateProfile({
|
|
1200
|
+
fullName: 'Token Creator',
|
|
1201
|
+
profileImage: avatar.imageUrl,
|
|
1202
|
+
address: sdk.getAddress()
|
|
1203
|
+
});
|
|
1204
|
+
|
|
1205
|
+
const logo = await sdk.uploadTokenImage({
|
|
1206
|
+
tokenName: 'mytoken',
|
|
1207
|
+
imagePath: '/path/to/logo.png'
|
|
1208
|
+
});
|
|
1209
|
+
|
|
1210
|
+
const result = await sdk.launchToken({
|
|
1211
|
+
tokenName: 'mytoken',
|
|
1212
|
+
tokenSymbol: 'MTK',
|
|
1213
|
+
tokenDescription: 'Awesome token',
|
|
1214
|
+
tokenImage: logo.imageUrl,
|
|
1215
|
+
websiteUrl: 'https://mytoken.com'
|
|
1216
|
+
});
|
|
1217
|
+
|
|
1218
|
+
return result;
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
// Batch profile fetching
|
|
1222
|
+
const addresses = ['eth|0xaddress1', 'eth|0xaddress2'];
|
|
1223
|
+
const profiles = await Promise.all(
|
|
1224
|
+
addresses.map(addr => sdk.fetchProfile(addr).catch(() => null))
|
|
1225
|
+
);
|
|
1226
|
+
|
|
1227
|
+
console.log('Profiles:', profiles.filter(p => p).map(p => p.fullName));
|
|
1228
|
+
}
|
|
1229
|
+
\`\`\`
|
|
1230
|
+
|
|
1231
|
+
**Profile Methods:**
|
|
1232
|
+
- \`fetchProfile(address?)\` - Get user profile
|
|
1233
|
+
- \`updateProfile(data)\` - Update profile info
|
|
1234
|
+
- \`uploadProfileImage(options)\` - Upload avatar (Node.js)
|
|
1235
|
+
|
|
1236
|
+
**Profile Fields:**
|
|
1237
|
+
- \`fullName\` - Display name (max 100 chars)
|
|
1238
|
+
- \`profileImage\` - Avatar image URL
|
|
1239
|
+
- \`address\` - Wallet address
|
|
1240
|
+
- \`createdAt\` - Creation date
|
|
1241
|
+
- \`updatedAt\` - Update timestamp
|
|
1242
|
+
|
|
1243
|
+
**Use Cases:**
|
|
1244
|
+
- Display user profiles
|
|
1245
|
+
- Allow profile customization
|
|
1246
|
+
- Manage profile images
|
|
1247
|
+
- Token creator attribution
|
|
1248
|
+
- Multi-wallet profiles
|
|
1249
|
+
|
|
1250
|
+
**MCP Tool Equivalents:**
|
|
1251
|
+
- \`gala_launchpad_fetch_profile\`
|
|
1252
|
+
- \`gala_launchpad_update_profile\`
|
|
1253
|
+
- \`gala_launchpad_upload_profile_image\`
|
|
1254
|
+
`,
|
|
1255
|
+
|
|
1256
|
+
'token-distribution': `
|
|
1257
|
+
## Token Holder Distribution with SDK
|
|
1258
|
+
|
|
1259
|
+
\`\`\`typescript
|
|
1260
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
1261
|
+
|
|
1262
|
+
async function analyzeTokenDistribution() {
|
|
1263
|
+
const sdk = createLaunchpadSDK({
|
|
1264
|
+
wallet: 'your-private-key-or-mnemonic'
|
|
1265
|
+
});
|
|
1266
|
+
|
|
1267
|
+
// Fetch complete token distribution (all holders, non-paginated)
|
|
1268
|
+
const distribution = await sdk.fetchTokenDistribution('anime');
|
|
1269
|
+
|
|
1270
|
+
console.log(\`Total holders: \${distribution.totalHolders}\`);
|
|
1271
|
+
console.log(\`Total supply: \${distribution.totalSupply}\`);
|
|
1272
|
+
console.log(\`Last updated: \${distribution.lastUpdated.toISOString()}\`);
|
|
1273
|
+
|
|
1274
|
+
// Analyze top holders
|
|
1275
|
+
distribution.holders
|
|
1276
|
+
.sort((a, b) => parseFloat(b.balance) - parseFloat(a.balance))
|
|
1277
|
+
.slice(0, 5)
|
|
1278
|
+
.forEach((holder, index) => {
|
|
1279
|
+
console.log(\`#\${index + 1}: \${holder.address}\`);
|
|
1280
|
+
console.log(\` Balance: \${holder.balance}\`);
|
|
1281
|
+
console.log(\` Ownership: \${holder.percentage.toFixed(2)}%\`);
|
|
1282
|
+
});
|
|
1283
|
+
|
|
1284
|
+
// Check concentration risk (e.g., top 5 holders own >80%)
|
|
1285
|
+
const top5Ownership = distribution.holders
|
|
1286
|
+
.sort((a, b) => parseFloat(b.balance) - parseFloat(a.balance))
|
|
1287
|
+
.slice(0, 5)
|
|
1288
|
+
.reduce((sum, holder) => sum + holder.percentage, 0);
|
|
1289
|
+
|
|
1290
|
+
console.log(\`Top 5 holders control: \${top5Ownership.toFixed(2)}%\`);
|
|
1291
|
+
|
|
1292
|
+
// Find specific holder
|
|
1293
|
+
const myAddress = sdk.getAddress();
|
|
1294
|
+
const myHolding = distribution.holders.find(h => h.address === myAddress);
|
|
1295
|
+
|
|
1296
|
+
if (myHolding) {
|
|
1297
|
+
console.log(\`Your ownership: \${myHolding.percentage.toFixed(4)}%\`);
|
|
1298
|
+
console.log(\`Your balance: \${myHolding.balance}\`);
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
// Calculate concentration metrics
|
|
1302
|
+
const giniCoefficient = calculateGini(distribution.holders);
|
|
1303
|
+
console.log(\`Gini coefficient: \${giniCoefficient.toFixed(4)}\`);
|
|
1304
|
+
|
|
1305
|
+
// Count whales (holders with >5%)
|
|
1306
|
+
const whales = distribution.holders.filter(h => h.percentage > 5);
|
|
1307
|
+
console.log(\`Whales (>5%): \${whales.length}\`);
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
// Helper: Calculate Gini coefficient for wealth distribution
|
|
1311
|
+
function calculateGini(holders: Array<{balance: string}>) {
|
|
1312
|
+
const balances = holders.map(h => parseFloat(h.balance)).sort((a, b) => a - b);
|
|
1313
|
+
const n = balances.length;
|
|
1314
|
+
const sum = balances.reduce((a, b) => a + b, 0);
|
|
1315
|
+
|
|
1316
|
+
let numerator = 0;
|
|
1317
|
+
for (let i = 0; i < n; i++) {
|
|
1318
|
+
numerator += (2 * (i + 1) - n - 1) * balances[i];
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
return numerator / (n * sum);
|
|
1322
|
+
}
|
|
1323
|
+
\`\`\`
|
|
1324
|
+
|
|
1325
|
+
**Key Characteristics:**
|
|
1326
|
+
- **Non-Paginated**: Returns ALL token holders in single response (no pagination)
|
|
1327
|
+
- **Complete Distribution**: Full holder list with addresses, balances, and ownership percentages
|
|
1328
|
+
- **BigNumber Precision**: Uses BigNumber.js for accurate percentage calculations
|
|
1329
|
+
- **Total Supply**: Computed from holder balances (sum of all holdings)
|
|
1330
|
+
- **Service Account Included**: Vault/service accounts appear in holder list
|
|
1331
|
+
|
|
1332
|
+
**Use Cases:**
|
|
1333
|
+
- Analyze token concentration risk
|
|
1334
|
+
- Identify whale holders
|
|
1335
|
+
- Track ownership changes over time
|
|
1336
|
+
- Generate holder reports
|
|
1337
|
+
- Calculate distribution metrics (Gini coefficient, etc.)
|
|
1338
|
+
|
|
1339
|
+
**MCP Tool Equivalent:** \`gala_launchpad_fetch_token_distribution\`
|
|
1340
|
+
`,
|
|
1341
|
+
|
|
1342
|
+
'liquidity-positions': `
|
|
1343
|
+
## GSwap Liquidity Position Management
|
|
1344
|
+
|
|
1345
|
+
Provide liquidity on GalaSwap DEX and earn passive trading fees from swaps.
|
|
1346
|
+
|
|
1347
|
+
**Overview:** Concentrated liquidity allows capital deployment within specific price ranges. Liquidity providers earn fees when trades occur within their price range, making it an attractive passive income strategy.
|
|
1348
|
+
|
|
1349
|
+
**8 Core SDK Methods:**
|
|
1350
|
+
|
|
1351
|
+
1. **getSwapUserLiquidityPositions(ownerAddress, limit?, bookmark?)** - View all open positions for wallet
|
|
1352
|
+
- Returns: Array of positions with token pairs, amounts, accumulated fees
|
|
1353
|
+
|
|
1354
|
+
2. **getSwapLiquidityPositionById(ownerAddress, positionId)** - Get specific position by UUID
|
|
1355
|
+
|
|
1356
|
+
3. **getSwapLiquidityPosition(ownerAddress, position)** - Get position by token pair and tick range
|
|
1357
|
+
|
|
1358
|
+
4. **addSwapLiquidityByPrice(args)** - Create position using user-friendly price ranges
|
|
1359
|
+
- params: token0, token1, fee, minPrice, maxPrice, amount0Desired, amount1Desired
|
|
1360
|
+
|
|
1361
|
+
5. **addSwapLiquidityByTicks(args)** - Create position using precise tick boundaries (advanced)
|
|
1362
|
+
|
|
1363
|
+
6. **getSwapEstimateRemoveLiquidity(args)** - Preview removal amounts before executing
|
|
1364
|
+
- Returns: estimated token amounts and accumulated fees
|
|
1365
|
+
|
|
1366
|
+
7. **removeSwapLiquidity(args)** - Close or reduce position with slippage protection
|
|
1367
|
+
- Removes liquidity and collects accumulated fees
|
|
1368
|
+
|
|
1369
|
+
8. **collectSwapPositionFees(args)** - Harvest accumulated fees without closing position
|
|
1370
|
+
- Passive income collection
|
|
1371
|
+
|
|
1372
|
+
**Fee Tiers:** 500 bps (0.05%), 3000 bps (0.30%), 10000 bps (1.00%)
|
|
1373
|
+
|
|
1374
|
+
**MCP Tools (8 tools):**
|
|
1375
|
+
- gala_launchpad_get_user_liquidity_positions
|
|
1376
|
+
- gala_launchpad_get_liquidity_position_by_id
|
|
1377
|
+
- gala_launchpad_get_liquidity_position
|
|
1378
|
+
- gala_launchpad_add_liquidity_by_price
|
|
1379
|
+
- gala_launchpad_add_liquidity_by_ticks
|
|
1380
|
+
- gala_launchpad_estimate_remove_liquidity
|
|
1381
|
+
- gala_launchpad_remove_liquidity
|
|
1382
|
+
- gala_launchpad_collect_position_fees
|
|
1383
|
+
|
|
1384
|
+
**Slash Commands (4 commands):**
|
|
1385
|
+
- /galachain-launchpad:my-positions - View all positions
|
|
1386
|
+
- /galachain-launchpad:add-liquidity - Create position
|
|
1387
|
+
- /galachain-launchpad:remove-liquidity - Close position
|
|
1388
|
+
- /galachain-launchpad:collect-fees - Harvest fees
|
|
1389
|
+
|
|
1390
|
+
**Demo Script:** See packages/sdk/examples/demo-liquidity-positions.ts for complete workflows
|
|
1391
|
+
`,
|
|
1392
|
+
|
|
1393
|
+
};
|
|
1394
|
+
|
|
1395
|
+
/**
|
|
1396
|
+
* SDK Usage Explanation Tool
|
|
1397
|
+
*/
|
|
1398
|
+
export const explainSdkUsageTool: MCPTool = {
|
|
1399
|
+
name: 'gala_launchpad_explain_sdk_usage',
|
|
1400
|
+
description: 'Get detailed SDK code examples for: buy-tokens, sell-tokens, pool-graduation, fetch-pools, balances, dex-trading, liquidity-positions, price-history, token-details, token-distribution, token-creation, profile-management, multi-wallet, transfers, error-handling, installation, local-calculations, mcp-to-sdk-mapping',
|
|
1401
|
+
inputSchema: {
|
|
1402
|
+
type: 'object',
|
|
1403
|
+
properties: {
|
|
1404
|
+
topic: {
|
|
1405
|
+
type: 'string',
|
|
1406
|
+
enum: [
|
|
1407
|
+
'buy-tokens',
|
|
1408
|
+
'sell-tokens',
|
|
1409
|
+
'pool-graduation',
|
|
1410
|
+
'fetch-pools',
|
|
1411
|
+
'balances',
|
|
1412
|
+
'dex-trading',
|
|
1413
|
+
'liquidity-positions',
|
|
1414
|
+
'price-history',
|
|
1415
|
+
'token-details',
|
|
1416
|
+
'token-distribution',
|
|
1417
|
+
'token-creation',
|
|
1418
|
+
'profile-management',
|
|
1419
|
+
'multi-wallet',
|
|
1420
|
+
'transfers',
|
|
1421
|
+
'error-handling',
|
|
1422
|
+
'installation',
|
|
1423
|
+
'local-calculations',
|
|
1424
|
+
'mcp-to-sdk-mapping',
|
|
1425
|
+
],
|
|
1426
|
+
description: 'The SDK usage topic to explain',
|
|
1427
|
+
},
|
|
1428
|
+
},
|
|
1429
|
+
required: ['topic'],
|
|
1430
|
+
},
|
|
1431
|
+
handler: withErrorHandling(async (_sdk, args) => {
|
|
1432
|
+
const example = SDK_EXAMPLES[args.topic as keyof typeof SDK_EXAMPLES];
|
|
1433
|
+
|
|
1434
|
+
if (!example) {
|
|
1435
|
+
throw new Error('Unknown topic: ' + args.topic);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
return formatSuccess({
|
|
1439
|
+
topic: args.topic,
|
|
1440
|
+
explanation: example,
|
|
1441
|
+
sdkVersion: '3.19.0',
|
|
1442
|
+
packageName: '@gala-chain/launchpad-sdk',
|
|
1443
|
+
documentation: 'https://www.npmjs.com/package/@gala-chain/launchpad-sdk',
|
|
1444
|
+
});
|
|
1445
|
+
}),
|
|
1446
|
+
};
|