@gala-chain/launchpad-sdk 4.0.4-beta.0 → 4.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/EXAMPLES.md +96 -35
  2. package/README.md +2 -0
  3. package/dist/index.cjs.js +1 -1
  4. package/dist/index.esm.js +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/src/LaunchpadSDK.d.ts +750 -72
  7. package/dist/src/LaunchpadSDK.d.ts.map +1 -1
  8. package/dist/src/constants/version.generated.d.ts +1 -1
  9. package/dist/src/constants/version.generated.d.ts.map +1 -1
  10. package/dist/src/services/DexBackendClient.d.ts +139 -10
  11. package/dist/src/services/DexBackendClient.d.ts.map +1 -1
  12. package/dist/src/services/DexQuoteService.d.ts +181 -22
  13. package/dist/src/services/DexQuoteService.d.ts.map +1 -1
  14. package/dist/src/services/DexService.d.ts +274 -38
  15. package/dist/src/services/DexService.d.ts.map +1 -1
  16. package/dist/src/services/GSwapService.d.ts +555 -246
  17. package/dist/src/services/GSwapService.d.ts.map +1 -1
  18. package/dist/src/services/GalaChainGatewayClient.d.ts +139 -41
  19. package/dist/src/services/GalaChainGatewayClient.d.ts.map +1 -1
  20. package/dist/src/services/ImageService.d.ts +101 -12
  21. package/dist/src/services/ImageService.d.ts.map +1 -1
  22. package/dist/src/services/PoolCacheManager.d.ts +125 -31
  23. package/dist/src/services/PoolCacheManager.d.ts.map +1 -1
  24. package/dist/src/services/SignatureService.d.ts +35 -5
  25. package/dist/src/services/SignatureService.d.ts.map +1 -1
  26. package/dist/src/services/SwapEventQueue.d.ts +79 -10
  27. package/dist/src/services/SwapEventQueue.d.ts.map +1 -1
  28. package/dist/src/services/TokenClassKeyService.d.ts +56 -10
  29. package/dist/src/services/TokenClassKeyService.d.ts.map +1 -1
  30. package/dist/src/services/TokenMetadataService.d.ts +407 -31
  31. package/dist/src/services/TokenMetadataService.d.ts.map +1 -1
  32. package/dist/src/services/TradeService.d.ts +168 -6
  33. package/dist/src/services/TradeService.d.ts.map +1 -1
  34. package/dist/src/services/UserService.d.ts +117 -15
  35. package/dist/src/services/UserService.d.ts.map +1 -1
  36. package/package.json +12 -2
  37. package/API.md +0 -1475
package/API.md DELETED
@@ -1,1475 +0,0 @@
1
- # Gala Launchpad SDK - API Reference
2
-
3
- Complete API documentation for the Gala Launchpad SDK (v3.23.0+).
4
-
5
- > **⚠️ BREAKING CHANGE (v3.33.0+)**: Token format parsing now **ONLY accepts delimited formats**. Plain token strings (`'GALA'`, `'GUSDC'`) are **permanently rejected** for security. Use delimited format: `'GALA|Unit|none|none'` or `'GALA$Unit$none$none'`. See README.md for [migration guide](./README.md#token-format-migration-v330).
6
-
7
- ## Table of Contents
8
-
9
- - [SDK Initialization](#sdk-initialization)
10
- - [Bonding Curve Trading (Launchpad Tokens)](#bonding-curve-trading)
11
- - [DEX Trading (Graduated Tokens)](#dex-trading-galaswap)
12
- - [GalaSwap Liquidity Position Management](#galaswap-liquidity-position-management)
13
- - [Pool Information](#pool-information)
14
- - [Token Management](#token-management)
15
- - [Portfolio & Balances](#portfolio--balances)
16
- - [Price History & Analytics](#price-history--analytics)
17
- - [Real-Time Features](#real-time-features)
18
- - [Type Definitions](#type-definitions)
19
- - [Error Handling](#error-handling)
20
-
21
- ---
22
-
23
- ## SDK Initialization
24
-
25
- ### `createLaunchpadSDK(config?)`
26
-
27
- Creates and returns a configured LaunchpadSDK instance for interacting with the Gala Launchpad Backend.
28
-
29
- **Parameters:**
30
- ```typescript
31
- interface LaunchpadSDKConfig {
32
- environment?: 'development' | 'staging' | 'production'; // Default: 'production'
33
- privateKey?: string; // Private key for signing (optional)
34
- wallet?: string; // Wallet address (optional)
35
- timeout?: number; // Request timeout in ms (default: 30000)
36
- debug?: boolean; // Enable debug logging (default: false)
37
- }
38
- ```
39
-
40
- **Example:**
41
- ```typescript
42
- import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
43
-
44
- // Read-only mode
45
- const sdk = createLaunchpadSDK({ environment: 'production' });
46
-
47
- // With wallet for signing operations
48
- const sdk = createLaunchpadSDK({
49
- environment: 'production',
50
- privateKey: process.env.PRIVATE_KEY,
51
- wallet: 'eth|0x...'
52
- });
53
- ```
54
-
55
- ---
56
-
57
- ## Bonding Curve Trading
58
-
59
- Trading tokens that are still in bonding curve pools (pre-graduation).
60
-
61
- ### `calculateBuyAmount(tokenName, amount, type?)`
62
-
63
- Calculate token amounts and fees for a purchase on a bonding curve.
64
-
65
- **Parameters:**
66
- ```typescript
67
- tokenName: string; // Token symbol (e.g., "anime")
68
- amount: string; // Input amount (GALA or exact token count)
69
- type?: 'native' | 'exact'; // 'native' = GALA amount, 'exact' = token amount (default: 'native')
70
- ```
71
-
72
- **Returns:**
73
- ```typescript
74
- {
75
- amount: string; // Token quantity you'll receive
76
- totalCost: string; // Total GALA cost (input + fees)
77
- transactionFee: string; // Transaction fee in GALA
78
- gasFee: string; // Gas fee in GALA
79
- reverseBondingCurveFee: string; // RBC fee in GALA
80
- }
81
- ```
82
-
83
- **Example:**
84
- ```typescript
85
- // How many tokens for 100 GALA?
86
- const quote = await sdk.calculateBuyAmount('anime', '100', 'native');
87
- console.log(`Receive: ${quote.amount} tokens`);
88
- console.log(`Cost: ${quote.totalCost} GALA`);
89
-
90
- // How much GALA for 10,000 tokens?
91
- const exactQuote = await sdk.calculateBuyAmount('anime', '10000', 'exact');
92
- console.log(`Need: ${exactQuote.totalCost} GALA`);
93
- ```
94
-
95
- ### `calculateSellAmount(tokenName, amount, type?)`
96
-
97
- Calculate GALA amount received when selling tokens.
98
-
99
- **Parameters:**
100
- ```typescript
101
- tokenName: string; // Token symbol
102
- amount: string; // Token amount or GALA desired
103
- type?: 'native' | 'exact'; // 'native' = GALA desired, 'exact' = token amount (default: 'native')
104
- ```
105
-
106
- **Returns:**
107
- ```typescript
108
- {
109
- amount: string; // GALA you'll receive
110
- transactionFee: string; // Transaction fee
111
- gasFee: string; // Gas fee
112
- reverseBondingCurveFee: string; // RBC fee
113
- }
114
- ```
115
-
116
- **Example:**
117
- ```typescript
118
- // How much GALA for selling 5000 tokens?
119
- const sellQuote = await sdk.calculateSellAmount('anime', '5000', 'exact');
120
- console.log(`Receive: ${sellQuote.amount} GALA`);
121
- ```
122
-
123
- ### `buyTokens(tokenName, amount, expectedAmount, slippageToleranceFactor?, maxAcceptableReverseBondingCurveFee?)`
124
-
125
- Execute a token purchase with slippage protection.
126
-
127
- **Parameters:**
128
- ```typescript
129
- tokenName: string; // Token symbol
130
- amount: string; // GALA amount to spend
131
- expectedAmount: string; // Expected token output (from calculateBuyAmount)
132
- slippageToleranceFactor?: number; // Slippage tolerance (0-1, default: 0.01 = 1%)
133
- maxAcceptableReverseBondingCurveFee?: string; // Max RBC fee
134
- ```
135
-
136
- **Returns:**
137
- ```typescript
138
- {
139
- transactionId: string;
140
- status: 'PENDING' | 'COMPLETED' | 'FAILED';
141
- inputAmount: string;
142
- outputAmount: string;
143
- actualFees: { transaction: string; gas: string; rbc: string };
144
- wait(): Promise<TransactionResult>; // Wait for completion
145
- }
146
- ```
147
-
148
- **Example:**
149
- ```typescript
150
- // Get quote first
151
- const quote = await sdk.calculateBuyAmount('anime', '100', 'native');
152
-
153
- // Execute buy with 1% slippage tolerance
154
- const result = await sdk.buyTokens('anime', '100', quote.amount, 0.01);
155
-
156
- console.log(`Transaction ID: ${result.transactionId}`);
157
-
158
- // Wait for completion (optional)
159
- const completed = await result.wait();
160
- console.log(`Received: ${completed.outputAmount} tokens`);
161
- ```
162
-
163
- ### `sellTokens(tokenName, amount, expectedAmount, slippageToleranceFactor?)`
164
-
165
- Execute a token sale with slippage protection.
166
-
167
- **Parameters:**
168
- ```typescript
169
- tokenName: string; // Token symbol
170
- amount: string; // Token amount to sell
171
- expectedAmount: string; // Expected GALA output (from calculateSellAmount)
172
- slippageToleranceFactor?: number; // Slippage tolerance (default: 0.01 = 1%)
173
- ```
174
-
175
- **Returns:** Same structure as `buyTokens()`
176
-
177
- **Example:**
178
- ```typescript
179
- // Get quote
180
- const quote = await sdk.calculateSellAmount('anime', '5000', 'exact');
181
-
182
- // Execute sell
183
- const result = await sdk.sellTokens('anime', '5000', quote.amount, 0.01);
184
- console.log(`Received: ${result.outputAmount} GALA`);
185
- ```
186
-
187
- ### `calculateBuyAmountForGraduation(tokenName)`
188
-
189
- Calculate total GALA cost to graduate a token (buy all remaining tokens).
190
-
191
- **⚠️ CRITICAL:** Returns **GALA cost**, NOT token quantity!
192
-
193
- **Parameters:**
194
- ```typescript
195
- tokenName: string; // Token symbol
196
- ```
197
-
198
- **Returns:**
199
- ```typescript
200
- {
201
- amount: string; // GALA cost to graduate (e.g., "1639972.84")
202
- totalCost: string; // Total cost including fees
203
- transactionFee: string;
204
- gasFee: string;
205
- }
206
- ```
207
-
208
- **Example:**
209
- ```typescript
210
- const graduation = await sdk.calculateBuyAmountForGraduation('QATOKEN');
211
- console.log(`Cost to graduate: ${graduation.amount} GALA`);
212
- // Example output: "1639972.84 GALA" (1.6 million GALA, not tokens!)
213
- ```
214
-
215
- ### `graduateToken(tokenName, options?)`
216
-
217
- Graduate a token by buying all remaining bonding curve tokens (convenience method).
218
-
219
- **Parameters:**
220
- ```typescript
221
- tokenName: string;
222
- options?: {
223
- slippageToleranceFactor?: number; // Default: 0.01 (1%)
224
- }
225
- ```
226
-
227
- **Returns:** Transaction result (same as buyTokens)
228
-
229
- **Example:**
230
- ```typescript
231
- const result = await sdk.graduateToken('QATOKEN', { slippageToleranceFactor: 0.01 });
232
- console.log(`Graduation initiated: ${result.transactionId}`);
233
-
234
- // Verify graduation
235
- const pool = await sdk.fetchPoolDetails('QATOKEN');
236
- console.log(`Pool status: ${pool.saleStatus}`); // Should be "Completed"
237
- ```
238
-
239
- ---
240
-
241
- ## DEX Trading (GalaSwap)
242
-
243
- Trading tokens that have graduated from bonding curves to full DEX trading.
244
-
245
- ### `getSwapQuoteExactInput(fromToken, toToken, amount)`
246
-
247
- Get a quote for swapping a known input amount on GalaSwap DEX.
248
-
249
- **Parameters:**
250
- ```typescript
251
- fromToken: string; // Source token in delimited format (e.g., "GALA|Unit|none|none" or "GALA$Unit$none$none") - v3.33.0+ REQUIRED
252
- toToken: string; // Destination token in delimited format (e.g., "GUSDC|Unit|none|none" or "GUSDC$Unit$none$none") - v3.33.0+ REQUIRED
253
- amount: string; // Input amount (how much fromToken to spend)
254
- ```
255
-
256
- **Returns:**
257
- ```typescript
258
- {
259
- estimatedOutput: string; // Expected toToken amount
260
- priceImpact: number; // Price impact percentage (0-1)
261
- feeTier: number; // Fee tier in basis points (500, 3000, 10000)
262
- exchangeRate: string; // Rate: toToken per fromToken
263
- minimumOutput: string; // Minimum output with 1% slippage
264
- }
265
- ```
266
-
267
- **Example:**
268
- ```typescript
269
- // How many GUSDC for 100 GALA? (v3.33.0+ requires delimited token format)
270
- const quote = await sdk.getSwapQuoteExactInput('GALA|Unit|none|none', 'GUSDC|Unit|none|none', '100');
271
- console.log(`Spend: 100 GALA`);
272
- console.log(`Receive: ~${quote.estimatedOutput} GUSDC`);
273
- console.log(`Price impact: ${(quote.priceImpact * 100).toFixed(2)}%`);
274
- console.log(`Fee tier: ${quote.feeTier} (${quote.feeTier / 100}%)`);
275
- ```
276
-
277
- ### `getSwapQuoteExactOutput(fromToken, toToken, amount)`
278
-
279
- Get a quote for swapping to a known output amount on GalaSwap DEX.
280
-
281
- **Parameters:**
282
- ```typescript
283
- fromToken: string; // Source token
284
- toToken: string; // Destination token
285
- amount: string; // Desired output amount (how much toToken you want)
286
- ```
287
-
288
- **Returns:**
289
- ```typescript
290
- {
291
- inputAmount: string; // fromToken amount needed to spend
292
- priceImpact: number; // Price impact percentage
293
- feeTier: number; // Fee tier
294
- exchangeRate: string; // Exchange rate
295
- maximumInput: string; // Maximum input with 1% slippage
296
- }
297
- ```
298
-
299
- **Example:**
300
- ```typescript
301
- // How much GALA to get 100 GUSDC?
302
- const quote = await sdk.getSwapQuoteExactOutput('GALA', 'GUSDC', '100');
303
- console.log(`Need: ${quote.inputAmount} GALA`);
304
- console.log(`To get: 100 GUSDC`);
305
- ```
306
-
307
- ### `executeSwap(fromToken, toToken, inputAmount, estimatedOutput, feeTier, slippageTolerance?)`
308
-
309
- Execute a token swap on GalaSwap DEX with slippage protection.
310
-
311
- **Parameters:**
312
- ```typescript
313
- fromToken: string; // Source token
314
- toToken: string; // Destination token
315
- inputAmount: string; // How much fromToken to spend
316
- estimatedOutput: string; // Expected output (from quote)
317
- feeTier: number; // Fee tier (from quote)
318
- slippageTolerance?: number; // Slippage tolerance (0-1, default: 0.01)
319
- ```
320
-
321
- **Returns:**
322
- ```typescript
323
- {
324
- transactionId: string;
325
- status: 'PENDING' | 'COMPLETED' | 'FAILED';
326
- inputAmount: string;
327
- outputAmount: string;
328
- actualFees: { transaction: string; gas: string };
329
- wait(): Promise<TransactionResult>;
330
- }
331
- ```
332
-
333
- **Example:**
334
- ```typescript
335
- // Get quote
336
- const quote = await sdk.getSwapQuoteExactInput('GALA', 'GUSDC', '100');
337
-
338
- // Execute swap with 1% slippage protection
339
- const result = await sdk.executeSwap(
340
- 'GALA',
341
- 'GUSDC',
342
- '100',
343
- quote.estimatedOutput,
344
- quote.feeTier,
345
- 0.01 // 1% slippage tolerance
346
- );
347
-
348
- console.log(`Swap ID: ${result.transactionId}`);
349
- console.log(`Received: ${result.outputAmount} GUSDC`);
350
-
351
- // Wait for confirmation (optional)
352
- await result.wait();
353
- ```
354
-
355
- ### `getSwapUserAssets(walletAddress)`
356
-
357
- Get all token balances for a wallet on GalaSwap.
358
-
359
- **Parameters:**
360
- ```typescript
361
- walletAddress: string; // Wallet address (eth|0x... format)
362
- ```
363
-
364
- **Returns:**
365
- ```typescript
366
- Array<{
367
- symbol: string; // Token symbol (e.g., "GALA")
368
- balance: string; // Token balance
369
- decimals: number; // Token decimals
370
- tokenId: string; // Pipe-delimited token ID
371
- }>
372
- ```
373
-
374
- **Example:**
375
- ```typescript
376
- const assets = await sdk.getSwapUserAssets('eth|0x...');
377
-
378
- assets.forEach(asset => {
379
- console.log(`${asset.symbol}: ${asset.balance}`);
380
- });
381
- ```
382
-
383
- ### `getSwapPoolInfo(tokenA, tokenB)`
384
-
385
- Get liquidity and fee information for a DEX pool.
386
-
387
- **Parameters:**
388
- ```typescript
389
- tokenA: string; // First token
390
- tokenB: string; // Second token
391
- ```
392
-
393
- **Returns:**
394
- ```typescript
395
- {
396
- liquidity: string; // Total pool liquidity
397
- feeTiers: number[]; // Available fee tiers
398
- volume24h: string; // 24-hour volume
399
- swapCount: number; // Total swap count
400
- lastUpdated: Date; // Snapshot timestamp
401
- }
402
- ```
403
-
404
- **Example:**
405
- ```typescript
406
- const pool = await sdk.getSwapPoolInfo('GALA', 'GUSDC');
407
- console.log(`Liquidity: ${pool.liquidity}`);
408
- console.log(`Fee tiers: ${pool.feeTiers.map(t => t / 100 + '%').join(', ')}`);
409
- ```
410
-
411
- ---
412
-
413
- ## GalaSwap Liquidity Position Management
414
-
415
- Provide liquidity to DEX pools and earn trading fees. Liquidity positions enable passive income through fee accumulation while helping maintain DEX liquidity.
416
-
417
- ### `getAllSwapUserLiquidityPositions(ownerAddress)`
418
-
419
- Get **all** open liquidity positions for a wallet with automatic pagination (recommended).
420
-
421
- **Parameters:**
422
- ```typescript
423
- ownerAddress: string; // Wallet address (e.g., "0x1234..." or "eth|1234...")
424
- ```
425
-
426
- **Returns:**
427
- ```typescript
428
- Array<{
429
- positionId: string; // Unique position identifier
430
- token0: string; // First token symbol
431
- token1: string; // Second token symbol
432
- feeTier: number; // Fee tier in basis points
433
- liquidity: string; // Liquidity amount
434
- amount0: string; // Token0 amount in position
435
- amount1: string; // Token1 amount in position
436
- feeAmount0: string; // Accumulated fees (Token0)
437
- feeAmount1: string; // Accumulated fees (Token1)
438
- tickLower: number; // Lower tick boundary
439
- tickUpper: number; // Upper tick boundary
440
- }>
441
- ```
442
-
443
- **Example:**
444
- ```typescript
445
- // Fetch all positions with automatic pagination
446
- const allPositions = await sdk.getAllSwapUserLiquidityPositions('eth|0x...');
447
-
448
- console.log(`Total positions: ${allPositions.length}`);
449
-
450
- // Analyze positions
451
- allPositions.forEach(pos => {
452
- console.log(`${pos.token0}/${pos.token1}: ${pos.liquidity} liquidity`);
453
- console.log(`Fees earned: ${pos.feeAmount0} ${pos.token0}, ${pos.feeAmount1} ${pos.token1}`);
454
- });
455
-
456
- // Find best-performing position (highest accumulated fees)
457
- const bestPosition = allPositions.reduce((best, current) => {
458
- const currentFees = parseFloat(current.feeAmount0) + parseFloat(current.feeAmount1);
459
- const bestFees = parseFloat(best.feeAmount0) + parseFloat(best.feeAmount1);
460
- return currentFees > bestFees ? current : best;
461
- });
462
- console.log(`Best position: ${bestPosition.token0}/${bestPosition.token1}`);
463
- ```
464
-
465
- ### `getSwapUserLiquidityPositions(ownerAddress, limit?, bookmark?)`
466
-
467
- Get open liquidity positions with manual pagination control (paginated version).
468
-
469
- **Parameters:**
470
- ```typescript
471
- ownerAddress: string; // Wallet address
472
- limit?: number; // Results per page (default: 10, max: 20)
473
- bookmark?: string; // Pagination bookmark from previous response
474
- ```
475
-
476
- **Returns:** Same array structure as getAllSwapUserLiquidityPositions, plus pagination metadata:
477
- ```typescript
478
- {
479
- positions: Array<...>; // Array of position objects
480
- bookmark?: string; // Bookmark for next page (if more results exist)
481
- hasMore: boolean; // True if more pages available
482
- total: number; // Total positions
483
- }
484
- ```
485
-
486
- **Example:**
487
- ```typescript
488
- // Paginated retrieval for streaming/processing
489
- let allPositions = [];
490
- let bookmark;
491
- let hasMore = true;
492
-
493
- while (hasMore) {
494
- const page = await sdk.getSwapUserLiquidityPositions('eth|0x...', 10, bookmark);
495
- allPositions = allPositions.concat(page.positions);
496
- hasMore = !!page.bookmark;
497
- bookmark = page.bookmark;
498
- console.log(`Fetched page: ${page.positions.length} positions`);
499
- }
500
-
501
- console.log(`Total fetched: ${allPositions.length}`);
502
- ```
503
-
504
- ### `getSwapLiquidityPositionById(ownerAddress, positionId)`
505
-
506
- Get a specific liquidity position by its ID.
507
-
508
- **Parameters:**
509
- ```typescript
510
- ownerAddress: string; // Wallet address
511
- positionId: string; // Position UUID
512
- ```
513
-
514
- **Returns:** Single position object (same structure as above)
515
-
516
- **Example:**
517
- ```typescript
518
- const position = await sdk.getSwapLiquidityPositionById('eth|0x...', 'position-uuid');
519
-
520
- console.log(`Position: ${position.token0}/${position.token1}`);
521
- console.log(`Liquidity: ${position.liquidity}`);
522
- console.log(`Accumulated fees: ${position.feeAmount0} + ${position.feeAmount1}`);
523
- ```
524
-
525
- ### `getSwapLiquidityPosition(ownerAddress, token0, token1, fee, tickLower, tickUpper)`
526
-
527
- Get a liquidity position by token pair and price range.
528
-
529
- **Parameters:**
530
- ```typescript
531
- ownerAddress: string; // Wallet address
532
- token0: string; // First token
533
- token1: string; // Second token
534
- fee: number; // Fee tier (500, 3000, or 10000)
535
- tickLower: number; // Lower tick boundary
536
- tickUpper: number; // Upper tick boundary
537
- ```
538
-
539
- **Returns:** Single position object
540
-
541
- **Example:**
542
- ```typescript
543
- const position = await sdk.getSwapLiquidityPosition(
544
- 'eth|0x...',
545
- 'GALA',
546
- 'GUSDC',
547
- 3000,
548
- -1000,
549
- 1000
550
- );
551
-
552
- console.log(`Active: ${position.liquidity > 0}`);
553
- ```
554
-
555
- ### `getSwapEstimateRemoveLiquidity(token0, token1, fee, liquidity, tickLower, tickUpper)`
556
-
557
- Estimate tokens and fees you'll receive when removing liquidity.
558
-
559
- **Parameters:**
560
- ```typescript
561
- token0: string; // First token
562
- token1: string; // Second token
563
- fee: number; // Fee tier
564
- liquidity: string; // Liquidity amount to remove
565
- tickLower: number; // Lower tick
566
- tickUpper: number; // Upper tick
567
- ```
568
-
569
- **Returns:**
570
- ```typescript
571
- {
572
- amount0: string; // Token0 amount to receive
573
- amount1: string; // Token1 amount to receive
574
- fee0: string; // Collected fees (Token0)
575
- fee1: string; // Collected fees (Token1)
576
- feeAmount0: string; // Same as fee0
577
- feeAmount1: string; // Same as fee1
578
- token0Symbol: string; // Token0 symbol
579
- token1Symbol: string; // Token1 symbol
580
- }
581
- ```
582
-
583
- **Example:**
584
- ```typescript
585
- // Preview removal before executing
586
- const estimate = await sdk.getSwapEstimateRemoveLiquidity(
587
- 'GALA',
588
- 'GUSDC',
589
- 3000,
590
- position.liquidity,
591
- position.tickLower,
592
- position.tickUpper
593
- );
594
-
595
- console.log(`Will receive: ${estimate.amount0} GALA, ${estimate.amount1} GUSDC`);
596
- console.log(`Collected fees: ${estimate.feeAmount0} GALA, ${estimate.feeAmount1} GUSDC`);
597
- ```
598
-
599
- ### `addSwapLiquidityByPrice(token0, token1, fee, minPrice, maxPrice, amount0Desired, amount1Desired, amount0Min?, amount1Min?)`
600
-
601
- Add liquidity by specifying a price range (user-friendly approach).
602
-
603
- **Parameters:**
604
- ```typescript
605
- token0: string; // First token
606
- token1: string; // Second token
607
- fee: number; // Fee tier (500, 3000, or 10000)
608
- minPrice: string; // Minimum price (e.g., "0.95")
609
- maxPrice: string; // Maximum price (e.g., "1.05")
610
- amount0Desired: string; // Desired Token0 amount to provide
611
- amount1Desired: string; // Desired Token1 amount to provide
612
- amount0Min?: string; // Minimum Token0 (slippage protection, default: "0")
613
- amount1Min?: string; // Minimum Token1 (slippage protection, default: "0")
614
- ```
615
-
616
- **Returns:**
617
- ```typescript
618
- {
619
- transactionId: string;
620
- status: 'PENDING' | 'COMPLETED' | 'FAILED';
621
- positionId: string; // New position ID
622
- liquidity: string; // Liquidity amount provided
623
- amount0Used: string; // Actual Token0 used
624
- amount1Used: string; // Actual Token1 used
625
- wait(): Promise<TransactionResult>;
626
- }
627
- ```
628
-
629
- **Example:**
630
- ```typescript
631
- // Create position with 0.95-1.05 price range
632
- const result = await sdk.addSwapLiquidityByPrice({
633
- token0: 'GALA',
634
- token1: 'GUSDC',
635
- fee: 3000, // 0.30% fee tier
636
- minPrice: '0.95', // Active when price between 0.95-1.05
637
- maxPrice: '1.05',
638
- amount0Desired: '100', // Provide 100 GALA
639
- amount1Desired: '100', // Provide 100 GUSDC
640
- amount0Min: '95', // Accept at least 95 GALA
641
- amount1Min: '95' // Accept at least 95 GUSDC
642
- });
643
-
644
- console.log(`Position created: ${result.positionId}`);
645
- console.log(`Liquidity provided: ${result.liquidity}`);
646
-
647
- // Wait for confirmation
648
- await result.wait();
649
- ```
650
-
651
- ### `addSwapLiquidityByTicks(token0, token1, feeTier, tickLower, tickUpper, amount0Desired, amount1Desired, amount0Min?, amount1Min?)`
652
-
653
- Add liquidity by specifying exact tick boundaries (advanced users).
654
-
655
- **Parameters:**
656
- ```typescript
657
- token0: string; // First token
658
- token1: string; // Second token
659
- feeTier: number; // Fee tier (500, 3000, or 10000)
660
- tickLower: number; // Lower tick (must align with tickSpacing)
661
- tickUpper: number; // Upper tick (must align with tickSpacing)
662
- amount0Desired: string; // Desired Token0 amount
663
- amount1Desired: string; // Desired Token1 amount
664
- amount0Min?: string; // Minimum Token0 (default: "0")
665
- amount1Min?: string; // Minimum Token1 (default: "0")
666
- ```
667
-
668
- **Returns:** Same as addSwapLiquidityByPrice
669
-
670
- **Example:**
671
- ```typescript
672
- // Create position with exact tick boundaries (advanced)
673
- // Note: ticks must be multiples of tickSpacing (varies by fee tier)
674
- const result = await sdk.addSwapLiquidityByTicks({
675
- token0: 'GALA',
676
- token1: 'GUSDC',
677
- feeTier: 3000,
678
- tickLower: -1000, // Exact tick
679
- tickUpper: 1000, // Exact tick
680
- amount0Desired: '100',
681
- amount1Desired: '100'
682
- });
683
-
684
- console.log(`Position ID: ${result.positionId}`);
685
- ```
686
-
687
- ### `removeSwapLiquidity(ownerAddress, positionId, liquidity, amount0Min, amount1Min, deadline?)`
688
-
689
- Remove liquidity from a position and withdraw underlying tokens.
690
-
691
- **Parameters:**
692
- ```typescript
693
- ownerAddress: string; // Wallet address
694
- positionId: string; // Position ID to remove from
695
- liquidity: string; // Liquidity amount to remove (use full amount to close)
696
- amount0Min: string; // Minimum Token0 to receive (slippage protection)
697
- amount1Min: string; // Minimum Token1 to receive (slippage protection)
698
- deadline?: number; // Deadline timestamp (unix seconds, optional)
699
- ```
700
-
701
- **Returns:**
702
- ```typescript
703
- {
704
- transactionId: string;
705
- status: 'PENDING' | 'COMPLETED' | 'FAILED';
706
- amount0Withdrawn: string; // Token0 received
707
- amount1Withdrawn: string; // Token1 received
708
- fee0Collected: string; // Fees collected (Token0)
709
- fee1Collected: string; // Fees collected (Token1)
710
- wait(): Promise<TransactionResult>;
711
- }
712
- ```
713
-
714
- **Example:**
715
- ```typescript
716
- // Preview removal before executing
717
- const estimate = await sdk.getSwapEstimateRemoveLiquidity(
718
- position.token0,
719
- position.token1,
720
- position.feeTier,
721
- position.liquidity,
722
- position.tickLower,
723
- position.tickUpper
724
- );
725
-
726
- // Remove full liquidity and close position
727
- const result = await sdk.removeSwapLiquidity({
728
- ownerAddress: 'eth|0x...',
729
- positionId: position.positionId,
730
- liquidity: position.liquidity,
731
- amount0Min: estimate.amount0, // Use estimate values
732
- amount1Min: estimate.amount1,
733
- deadline: Math.floor(Date.now() / 1000) + 3600 // 1 hour from now
734
- });
735
-
736
- console.log(`Withdrawn: ${result.amount0Withdrawn} + ${result.amount1Withdrawn}`);
737
- console.log(`Fees collected: ${result.fee0Collected} + ${result.fee1Collected}`);
738
- ```
739
-
740
- ### `collectSwapPositionFees(ownerAddress, positionId, amount0Max?, amount1Max?)`
741
-
742
- Collect accumulated trading fees without closing the position.
743
-
744
- **Parameters:**
745
- ```typescript
746
- ownerAddress: string; // Wallet address
747
- positionId: string; // Position ID
748
- amount0Max?: string; // Maximum Token0 fees (optional)
749
- amount1Max?: string; // Maximum Token1 fees (optional)
750
- ```
751
-
752
- **Returns:**
753
- ```typescript
754
- {
755
- transactionId: string;
756
- status: 'PENDING' | 'COMPLETED' | 'FAILED';
757
- amount0Collected: string; // Token0 fees collected
758
- amount1Collected: string; // Token1 fees collected
759
- wait(): Promise<TransactionResult>;
760
- }
761
- ```
762
-
763
- **Example:**
764
- ```typescript
765
- // Collect fees periodically without removing liquidity
766
- const result = await sdk.collectSwapPositionFees({
767
- ownerAddress: 'eth|0x...',
768
- positionId: position.positionId
769
- });
770
-
771
- console.log(`Collected: ${result.amount0Collected} + ${result.amount1Collected}`);
772
-
773
- // Position remains active and continues earning fees
774
- ```
775
-
776
- ### Complete Liquidity Management Workflow
777
-
778
- ```typescript
779
- // 1. View all positions
780
- const positions = await sdk.getAllSwapUserLiquidityPositions('eth|0x...');
781
- console.log(`You have ${positions.length} active positions`);
782
-
783
- // 2. Create new position
784
- const newPos = await sdk.addSwapLiquidityByPrice({
785
- token0: 'GALA',
786
- token1: 'GUSDC',
787
- fee: 3000,
788
- minPrice: '0.95',
789
- maxPrice: '1.05',
790
- amount0Desired: '1000',
791
- amount1Desired: '1000'
792
- });
793
-
794
- await newPos.wait();
795
- console.log(`Position created: ${newPos.positionId}`);
796
-
797
- // 3. Monitor fees (periodically)
798
- setTimeout(async () => {
799
- const position = await sdk.getSwapLiquidityPositionById('eth|0x...', newPos.positionId);
800
- console.log(`Fees earned: ${position.feeAmount0} + ${position.feeAmount1}`);
801
- }, 3600000); // Every hour
802
-
803
- // 4. Collect fees when ready
804
- const fees = await sdk.collectSwapPositionFees({
805
- ownerAddress: 'eth|0x...',
806
- positionId: newPos.positionId
807
- });
808
-
809
- console.log(`Harvested: ${fees.amount0Collected} + ${fees.amount1Collected}`);
810
-
811
- // 5. Close position when desired
812
- const removed = await sdk.removeSwapLiquidity({
813
- ownerAddress: 'eth|0x...',
814
- positionId: newPos.positionId,
815
- liquidity: newPos.liquidity,
816
- amount0Min: '0',
817
- amount1Min: '0'
818
- });
819
-
820
- console.log(`Closed position, received: ${removed.amount0Withdrawn} + ${removed.amount1Withdrawn}`);
821
- ```
822
-
823
- ---
824
-
825
- ## Pool Information
826
-
827
- ### `fetchPoolDetails(tokenName)`
828
-
829
- Get detailed information about a bonding curve pool.
830
-
831
- **Parameters:**
832
- ```typescript
833
- tokenName: string; // Token symbol
834
- ```
835
-
836
- **Returns:**
837
- ```typescript
838
- {
839
- tokenName: string;
840
- symbol: string;
841
- currentSupply: string;
842
- maxSupply: string;
843
- sellingTokenQuantity: string;
844
- reserveGala: string;
845
- saleStatus: 'Ongoing' | 'Completed';
846
- createdAt: Date;
847
- fees: {
848
- transactionFee: string;
849
- reverseBondingCurveFee: { min: string; max: string };
850
- };
851
- }
852
- ```
853
-
854
- **Example:**
855
- ```typescript
856
- const pool = await sdk.fetchPoolDetails('anime');
857
- console.log(`Supply: ${pool.currentSupply}/${pool.maxSupply}`);
858
- console.log(`Status: ${pool.saleStatus}`);
859
- ```
860
-
861
- ### `fetchAllPools(options?)`
862
-
863
- Fetch all bonding curve pools with filtering and pagination.
864
-
865
- **Parameters:**
866
- ```typescript
867
- interface FetchPoolsOptions {
868
- type?: 'recent' | 'popular'; // Default: 'recent'
869
- page?: number; // Default: 1
870
- limit?: number; // Default: 20, max: 100
871
- }
872
- ```
873
-
874
- **Example:**
875
- ```typescript
876
- const pools = await sdk.fetchAllPools({ type: 'popular', limit: 50 });
877
- pools.forEach(pool => {
878
- console.log(`${pool.tokenName}: ${pool.saleStatus}`);
879
- });
880
- ```
881
-
882
- ---
883
-
884
- ## Token Management
885
-
886
- ### `launchToken(options)`
887
-
888
- Create a new token on the launchpad.
889
-
890
- **Parameters:**
891
- ```typescript
892
- interface TokenLaunchOptions {
893
- tokenName: string; // Token name (3-20 alphanumeric)
894
- tokenSymbol: string; // Token symbol (1-8 uppercase)
895
- tokenDescription: string; // Description (1-500 chars)
896
- tokenImage: string; // Image URL
897
- websiteUrl?: string; // Website URL (optional)
898
- twitterUrl?: string; // Twitter URL (optional)
899
- telegramUrl?: string; // Telegram URL (optional)
900
- preBuyQuantity?: string; // Pre-buy token amount (default: "0")
901
- reverseBondingCurveConfiguration?: {
902
- minFeePortion?: string;
903
- maxFeePortion?: string;
904
- };
905
- }
906
- ```
907
-
908
- **Returns:**
909
- ```typescript
910
- {
911
- tokenName: string;
912
- tokenSymbol: string;
913
- creatorAddress: string;
914
- transactionId: string;
915
- status: 'PENDING' | 'COMPLETED' | 'FAILED';
916
- }
917
- ```
918
-
919
- **Example:**
920
- ```typescript
921
- const result = await sdk.launchToken({
922
- tokenName: 'mytoken',
923
- tokenSymbol: 'MTK',
924
- tokenDescription: 'A new launchpad token',
925
- tokenImage: 'https://example.com/image.png',
926
- websiteUrl: 'https://example.com',
927
- preBuyQuantity: '1000' // Pre-buy 1000 tokens
928
- });
929
-
930
- console.log(`Token created: ${result.tokenName}`);
931
- ```
932
-
933
- ### `checkTokenName(tokenName)`
934
-
935
- Check if a token name is available.
936
-
937
- **Parameters:**
938
- ```typescript
939
- tokenName: string;
940
- ```
941
-
942
- **Returns:**
943
- ```typescript
944
- {
945
- available: boolean;
946
- tokenName: string;
947
- }
948
- ```
949
-
950
- ### `checkTokenSymbol(symbol)`
951
-
952
- Check if a token symbol is available.
953
-
954
- **Parameters:**
955
- ```typescript
956
- symbol: string; // 1-8 uppercase characters
957
- ```
958
-
959
- **Returns:**
960
- ```typescript
961
- {
962
- available: boolean;
963
- symbol: string;
964
- }
965
- ```
966
-
967
- ### `fetchTokenClassesWithSupply(tokenClasses)`
968
-
969
- Fetch authoritative supply information for one or more token classes from GalaChain.
970
-
971
- Queries the GalaChain network for definitive token supply data including total supply, maximum supply, burned amounts, and mint-related metrics. This method provides blockchain-verified token information.
972
-
973
- **Parameters:**
974
- ```typescript
975
- tokenClasses: TokenClassKey[]; // Array of token class identifiers
976
- ```
977
-
978
- **Returns:**
979
- ```typescript
980
- Promise<Array<{
981
- // Token Identification
982
- collection: string; // Token collection (e.g., 'Token')
983
- category: string; // Token category (e.g., 'Unit')
984
- type: string; // Token type (e.g., 'GALA', 'GUSDC')
985
- additionalKey: string; // Additional key/network (e.g., 'eth:0x...', 'none')
986
-
987
- // Token Metadata
988
- symbol: string; // Token symbol
989
- name: string; // Token display name
990
- decimals: number; // Decimal precision
991
-
992
- // Supply Information
993
- totalSupply: string; // Current total supply in circulation
994
- maxSupply: string; // Maximum possible supply
995
- totalBurned: string; // Total amount burned
996
- knownMintSupply: string; // Known mint supply
997
- knownMintAllowanceSupply: string; // Known mint allowance
998
- }>>
999
- ```
1000
-
1001
- **Example:**
1002
- ```typescript
1003
- // Query single token
1004
- const supplies = await sdk.fetchTokenClassesWithSupply([
1005
- {
1006
- collection: 'GALA',
1007
- category: 'Unit',
1008
- type: 'none',
1009
- additionalKey: 'none'
1010
- }
1011
- ]);
1012
-
1013
- console.log(`GALA Total Supply: ${supplies[0].totalSupply}`);
1014
- console.log(`GALA Max Supply: ${supplies[0].maxSupply}`);
1015
- console.log(`GALA Burned: ${supplies[0].totalBurned}`);
1016
-
1017
- // Query multiple tokens in one call
1018
- const multiSupplies = await sdk.fetchTokenClassesWithSupply([
1019
- { collection: 'GALA', category: 'Unit', type: 'none', additionalKey: 'none' },
1020
- { collection: 'GUSDC', category: 'Unit', type: 'none', additionalKey: 'none' }
1021
- ]);
1022
-
1023
- // Analyze supply metrics
1024
- for (const token of multiSupplies) {
1025
- const circulationPercent = (parseFloat(token.totalSupply) / parseFloat(token.maxSupply)) * 100;
1026
- const burnPercent = (parseFloat(token.totalBurned) / parseFloat(token.totalSupply)) * 100;
1027
-
1028
- console.log(`${token.symbol}:`);
1029
- console.log(` Circulation: ${circulationPercent.toFixed(2)}% of max`);
1030
- console.log(` Burned: ${burnPercent.toFixed(2)}% of total`);
1031
- }
1032
- ```
1033
-
1034
- **Use Cases:**
1035
- - Token supply tracking and dashboards
1036
- - Burn rate analysis and monitoring
1037
- - Mint allowance verification
1038
- - Token health metrics and reporting
1039
- - Supply distribution analysis
1040
- - Compliance and audit reporting
1041
-
1042
- ---
1043
-
1044
- ## Portfolio & Balances
1045
-
1046
- ### `fetchGalaBalance(address?)`
1047
-
1048
- Get GALA token balance for a wallet.
1049
-
1050
- **Parameters:**
1051
- ```typescript
1052
- address?: string; // Wallet address (default: authenticated wallet)
1053
- ```
1054
-
1055
- **Returns:**
1056
- ```typescript
1057
- string; // GALA balance
1058
- ```
1059
-
1060
- **Example:**
1061
- ```typescript
1062
- const balance = await sdk.fetchGalaBalance();
1063
- console.log(`GALA balance: ${balance}`);
1064
- ```
1065
-
1066
- ### `fetchTokenBalance(tokenName, address)`
1067
-
1068
- Get balance for a specific launchpad token.
1069
-
1070
- **Parameters:**
1071
- ```typescript
1072
- tokenName: string; // Token symbol
1073
- address: string; // Wallet address
1074
- ```
1075
-
1076
- **Returns:**
1077
- ```typescript
1078
- string; // Token balance
1079
- ```
1080
-
1081
- ### `fetchTokensHeld(options?)`
1082
-
1083
- Get all tokens held by a wallet with optional filtering.
1084
-
1085
- **Parameters:**
1086
- ```typescript
1087
- interface FetchTokensOptions {
1088
- tokenName?: string; // Exact token name filter
1089
- search?: string; // Fuzzy search filter
1090
- page?: number; // Default: 1
1091
- limit?: number; // Default: 20, max: 20
1092
- }
1093
- ```
1094
-
1095
- **Returns:**
1096
- ```typescript
1097
- Array<{
1098
- tokenName: string;
1099
- balance: string;
1100
- symbol: string;
1101
- decimals: number;
1102
- }>
1103
- ```
1104
-
1105
- **Example:**
1106
- ```typescript
1107
- // Get specific token
1108
- const anime = await sdk.fetchTokensHeld({ tokenName: 'anime', limit: 1 });
1109
-
1110
- // Search for tokens
1111
- const dragonTokens = await sdk.fetchTokensHeld({ search: 'dragon', limit: 10 });
1112
- ```
1113
-
1114
- ### `fetchTokensCreated(options?)`
1115
-
1116
- Get all tokens created by a wallet with optional filtering.
1117
-
1118
- **Parameters:** Same as `fetchTokensHeld()`
1119
-
1120
- ### `fetchTokenDistribution(tokenName)`
1121
-
1122
- Get all token holders and distribution percentages (non-paginated).
1123
-
1124
- **Parameters:**
1125
- ```typescript
1126
- tokenName: string;
1127
- ```
1128
-
1129
- **Returns:**
1130
- ```typescript
1131
- {
1132
- holders: Array<{
1133
- address: string; // Holder address
1134
- balance: string; // Token balance
1135
- percentage: number; // Ownership percentage
1136
- }>;
1137
- totalSupply: string;
1138
- totalHolders: number;
1139
- lastUpdated: Date;
1140
- }
1141
- ```
1142
-
1143
- **Example:**
1144
- ```typescript
1145
- const distribution = await sdk.fetchTokenDistribution('anime');
1146
- const topHolders = distribution.holders
1147
- .sort((a, b) => b.percentage - a.percentage)
1148
- .slice(0, 5);
1149
-
1150
- topHolders.forEach((h, i) => {
1151
- console.log(`#${i + 1}: ${h.percentage.toFixed(2)}% (${h.address})`);
1152
- });
1153
- ```
1154
-
1155
- ### `fetchProfile(address?)`
1156
-
1157
- Get user profile information.
1158
-
1159
- **Parameters:**
1160
- ```typescript
1161
- address?: string; // Wallet address (default: authenticated user)
1162
- ```
1163
-
1164
- **Returns:**
1165
- ```typescript
1166
- {
1167
- address: string;
1168
- fullName: string;
1169
- profileImage: string;
1170
- createdAt: Date;
1171
- }
1172
- ```
1173
-
1174
- ### `updateProfile(options)`
1175
-
1176
- Update user profile.
1177
-
1178
- **Parameters:**
1179
- ```typescript
1180
- interface UpdateProfileOptions {
1181
- fullName: string;
1182
- profileImage: string; // URL or empty string
1183
- address: string; // Wallet address
1184
- }
1185
- ```
1186
-
1187
- ---
1188
-
1189
- ## Price History & Analytics
1190
-
1191
- ### `fetchPriceHistory(options)`
1192
-
1193
- Get historical price snapshots (paginated, Node.js only).
1194
-
1195
- **Parameters:**
1196
- ```typescript
1197
- interface FetchPriceHistoryOptions {
1198
- tokenName?: string; // Simple token name (NEW v3.20.0)
1199
- tokenId?: string | TokenClassKey; // OR full token ID
1200
- from?: Date | string; // Start date (ISO 8601)
1201
- to?: Date | string; // End date (ISO 8601)
1202
- sortOrder?: 'ASC' | 'DESC'; // Default: 'DESC' (newest first)
1203
- page?: number; // Default: 1
1204
- limit?: number; // Default: 10, max: 50
1205
- }
1206
- ```
1207
-
1208
- **Returns:**
1209
- ```typescript
1210
- {
1211
- snapshots: Array<{
1212
- price: string; // Token price in GUSDC
1213
- timestamp: Date; // Snapshot timestamp
1214
- tokenId: string; // Token identifier
1215
- }>;
1216
- page: number;
1217
- limit: number;
1218
- total: number;
1219
- totalPages: number;
1220
- hasNext: boolean;
1221
- hasPrevious: boolean;
1222
- }
1223
- ```
1224
-
1225
- **Example:**
1226
- ```typescript
1227
- // Using simple token name
1228
- const history = await sdk.fetchPriceHistory({
1229
- tokenName: 'anime',
1230
- from: new Date('2025-01-01'),
1231
- to: new Date('2025-01-31'),
1232
- limit: 50
1233
- });
1234
-
1235
- console.log(`Latest price: $${history.snapshots[0].price}`);
1236
- ```
1237
-
1238
- ### `fetchAllPriceHistory(options)`
1239
-
1240
- Get all historical price snapshots (auto-paginated, Node.js only).
1241
-
1242
- **Parameters:** Same as `fetchPriceHistory()` but without pagination parameters
1243
-
1244
- **Returns:** Same structure as `fetchPriceHistory()` with all snapshots combined
1245
-
1246
- **Example:**
1247
- ```typescript
1248
- const allHistory = await sdk.fetchAllPriceHistory({
1249
- tokenName: 'anime',
1250
- from: '2024-01-01',
1251
- to: '2025-01-31'
1252
- });
1253
-
1254
- console.log(`Total snapshots: ${allHistory.snapshots.length}`);
1255
- ```
1256
-
1257
- ### `fetchTokenDetails(tokenId)`
1258
-
1259
- Get comprehensive token metadata from DEX API.
1260
-
1261
- **Parameters:**
1262
- ```typescript
1263
- tokenId: string | {
1264
- collection: string;
1265
- category: string;
1266
- type: string;
1267
- additionalKey: string;
1268
- };
1269
- ```
1270
-
1271
- **Returns:**
1272
- ```typescript
1273
- {
1274
- symbol: string;
1275
- name: string;
1276
- decimals: number;
1277
- verified: boolean;
1278
- image: string;
1279
- description: string;
1280
- network: string;
1281
- chainId: string;
1282
- contractAddress: string;
1283
- tradingEnabled: boolean;
1284
- currentPrice?: string;
1285
- volume24h?: string;
1286
- }
1287
- ```
1288
-
1289
- **Example:**
1290
- ```typescript
1291
- const details = await sdk.fetchTokenDetails('GUSDC|Unit|none|eth:0x...');
1292
-
1293
- if (details.verified && details.tradingEnabled) {
1294
- console.log(`${details.symbol}: ${details.name}`);
1295
- }
1296
- ```
1297
-
1298
- ---
1299
-
1300
- ## Real-Time Features
1301
-
1302
- ### `fetchTrades(options?)`
1303
-
1304
- Get trade history for your wallet.
1305
-
1306
- **Parameters:**
1307
- ```typescript
1308
- interface FetchTradesOptions {
1309
- tokenName?: string; // Filter by token
1310
- tradeType?: 'BUY' | 'SELL'; // Filter by type
1311
- userAddress?: string; // Filter by user address
1312
- startDate?: Date; // Start date
1313
- endDate?: Date; // End date
1314
- sortOrder?: 'ASC' | 'DESC'; // Default: 'DESC'
1315
- page?: number; // Default: 1
1316
- limit?: number; // Default: 10, max: 20
1317
- }
1318
- ```
1319
-
1320
- **Returns:**
1321
- ```typescript
1322
- Array<{
1323
- transactionId: string;
1324
- type: 'BUY' | 'SELL';
1325
- tokenName: string;
1326
- inputAmount: string;
1327
- outputAmount: string;
1328
- fees: { transaction: string; gas: string };
1329
- timestamp: Date;
1330
- status: 'COMPLETED' | 'FAILED' | 'PENDING';
1331
- }>
1332
- ```
1333
-
1334
- ### `getBundlerTransactionResult(transactionId)`
1335
-
1336
- Get detailed transaction status and results.
1337
-
1338
- **Parameters:**
1339
- ```typescript
1340
- transactionId: string; // UUID format transaction ID
1341
- ```
1342
-
1343
- **Returns:**
1344
- ```typescript
1345
- {
1346
- id: string;
1347
- method: string;
1348
- status: 'COMPLETED' | 'FAILED' | 'PENDING' | 'PROCESSING';
1349
- result?: {
1350
- transactionId: string;
1351
- inputAmount: string;
1352
- outputAmount: string;
1353
- };
1354
- }
1355
- ```
1356
-
1357
- ---
1358
-
1359
- ## Type Definitions
1360
-
1361
- ### TokenClassKey
1362
- ```typescript
1363
- interface TokenClassKey {
1364
- collection: string; // Usually "Token"
1365
- category: string; // Usually "Unit"
1366
- type: string; // Token symbol (e.g., "GALA")
1367
- additionalKey: string; // Network/chain info or "none"
1368
- }
1369
- ```
1370
-
1371
- ### TokenClassWithSupply
1372
- ```typescript
1373
- interface TokenClassWithSupply {
1374
- // Token Identification
1375
- collection: string; // Token collection (e.g., "Token")
1376
- category: string; // Token category (e.g., "Unit")
1377
- type: string; // Token type (e.g., "GALA", "GUSDC")
1378
- additionalKey: string; // Network/chain info (e.g., "eth:0x...", "none")
1379
-
1380
- // Token Metadata
1381
- symbol: string; // Token symbol
1382
- name: string; // Token display name
1383
- decimals: number; // Decimal precision
1384
-
1385
- // Supply Information
1386
- totalSupply: string; // Current total supply in circulation
1387
- maxSupply: string; // Maximum possible supply
1388
- totalBurned: string; // Total amount burned
1389
- knownMintSupply: string; // Known mint supply
1390
- knownMintAllowanceSupply: string; // Known mint allowance supply
1391
-
1392
- // Optional Fields
1393
- authorities?: Array<{ // Optional token authorities
1394
- address?: string; // Authority address
1395
- role?: string; // Authority role/type
1396
- }>;
1397
- }
1398
- ```
1399
-
1400
- ### TransactionResult
1401
- ```typescript
1402
- interface TransactionResult {
1403
- transactionId: string;
1404
- status: 'COMPLETED' | 'FAILED' | 'PENDING';
1405
- inputAmount: string;
1406
- outputAmount: string;
1407
- actualFees: {
1408
- transaction: string;
1409
- gas: string;
1410
- rbc?: string;
1411
- };
1412
- timestamp: Date;
1413
- }
1414
- ```
1415
-
1416
- ### SwapQuote
1417
- ```typescript
1418
- interface SwapQuote {
1419
- estimatedOutput: string;
1420
- priceImpact: number;
1421
- feeTier: number;
1422
- exchangeRate: string;
1423
- minimumOutput: string;
1424
- }
1425
- ```
1426
-
1427
- ---
1428
-
1429
- ## Error Handling
1430
-
1431
- The SDK throws descriptive errors for invalid operations:
1432
-
1433
- ```typescript
1434
- try {
1435
- const quote = await sdk.getSwapQuoteExactInput('GALA', 'UNKNOWN', '100');
1436
- } catch (error) {
1437
- if (error.message.includes('Pool not found')) {
1438
- console.log('Token pair has no DEX liquidity');
1439
- } else if (error.message.includes('Invalid token')) {
1440
- console.log('Token format is not recognized');
1441
- } else if (error.message.includes('Wallet')) {
1442
- console.log('No wallet configured - set privateKey in SDK config');
1443
- } else {
1444
- console.log(`Error: ${error.message}`);
1445
- }
1446
- }
1447
- ```
1448
-
1449
- ### Common Error Scenarios
1450
-
1451
- | Error | Cause | Solution |
1452
- |-------|-------|----------|
1453
- | "Wallet not configured" | No privateKey set for signing | Add privateKey to SDK config |
1454
- | "Pool not found" | Token pair has no DEX liquidity | Check token has graduated |
1455
- | "Slippage exceeded" | Price moved too much | Increase slippageTolerance |
1456
- | "Insufficient balance" | Not enough tokens to sell | Check wallet balance first |
1457
- | "Invalid token format" | Token ID is malformed | Use correct format or simple symbol |
1458
-
1459
- ---
1460
-
1461
- ## Version Compatibility
1462
-
1463
- - **SDK Version**: v3.23.0+
1464
- - **GSwap SDK**: v0.0.7+
1465
- - **Node.js**: 16+
1466
- - **Browser**: Modern browsers with ES2020+ support
1467
-
1468
- ---
1469
-
1470
- ## Additional Resources
1471
-
1472
- - [GalaSwap Integration Guide](../docs/gswap-integration.md)
1473
- - [Project Instructions & Examples](../CLAUDE.md)
1474
- - [GitHub Repository](https://github.com/GalaChain/launchpad-sdk)
1475
- - [MCP Server Tools Reference](../packages/mcp-server/README.md)