@gala-chain/launchpad-sdk 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +628 -0
  3. package/dist/LaunchpadSDK.d.ts +573 -0
  4. package/dist/LaunchpadSDK.d.ts.map +1 -0
  5. package/dist/api/CommentAPI.d.ts +119 -0
  6. package/dist/api/CommentAPI.d.ts.map +1 -0
  7. package/dist/api/LaunchpadAPI.d.ts +440 -0
  8. package/dist/api/LaunchpadAPI.d.ts.map +1 -0
  9. package/dist/api/TradeAPI.d.ts +164 -0
  10. package/dist/api/TradeAPI.d.ts.map +1 -0
  11. package/dist/api/Trading.d.ts +176 -0
  12. package/dist/api/Trading.d.ts.map +1 -0
  13. package/dist/api/UserAPI.d.ts +426 -0
  14. package/dist/api/UserAPI.d.ts.map +1 -0
  15. package/dist/api/WebSocketAPI.d.ts +156 -0
  16. package/dist/api/WebSocketAPI.d.ts.map +1 -0
  17. package/dist/api/dto/BondingCurveDTOs.d.ts +142 -0
  18. package/dist/api/dto/BondingCurveDTOs.d.ts.map +1 -0
  19. package/dist/api/services/BundleService.d.ts +105 -0
  20. package/dist/api/services/BundleService.d.ts.map +1 -0
  21. package/dist/api/services/SignatureService.d.ts +71 -0
  22. package/dist/api/services/SignatureService.d.ts.map +1 -0
  23. package/dist/api/services/TokenClassKeyService.d.ts +116 -0
  24. package/dist/api/services/TokenClassKeyService.d.ts.map +1 -0
  25. package/dist/api/services/WebSocketManager.d.ts +99 -0
  26. package/dist/api/services/WebSocketManager.d.ts.map +1 -0
  27. package/dist/api/services/WebSocketService.d.ts +66 -0
  28. package/dist/api/services/WebSocketService.d.ts.map +1 -0
  29. package/dist/auth/SignatureAuth.d.ts +92 -0
  30. package/dist/auth/SignatureAuth.d.ts.map +1 -0
  31. package/dist/auth/types.d.ts +41 -0
  32. package/dist/auth/types.d.ts.map +1 -0
  33. package/dist/helpers/sdk.d.ts +75 -0
  34. package/dist/helpers/sdk.d.ts.map +1 -0
  35. package/dist/helpers/wallet.d.ts +60 -0
  36. package/dist/helpers/wallet.d.ts.map +1 -0
  37. package/dist/index.cjs.js +1 -0
  38. package/dist/index.d.ts +49 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.esm.js +1 -0
  41. package/dist/index.js +1 -0
  42. package/dist/types/comment.dto.d.ts +160 -0
  43. package/dist/types/comment.dto.d.ts.map +1 -0
  44. package/dist/types/common.d.ts +108 -0
  45. package/dist/types/common.d.ts.map +1 -0
  46. package/dist/types/dto.d.ts +145 -0
  47. package/dist/types/dto.d.ts.map +1 -0
  48. package/dist/types/launchpad.dto.d.ts +517 -0
  49. package/dist/types/launchpad.dto.d.ts.map +1 -0
  50. package/dist/types/launchpad.validation.d.ts +40 -0
  51. package/dist/types/launchpad.validation.d.ts.map +1 -0
  52. package/dist/types/trade.dto.d.ts +446 -0
  53. package/dist/types/trade.dto.d.ts.map +1 -0
  54. package/dist/types/user.dto.d.ts +330 -0
  55. package/dist/types/user.dto.d.ts.map +1 -0
  56. package/dist/utils/VaultCache.d.ts +73 -0
  57. package/dist/utils/VaultCache.d.ts.map +1 -0
  58. package/dist/utils/adapters.d.ts +111 -0
  59. package/dist/utils/adapters.d.ts.map +1 -0
  60. package/dist/utils/agent-config.d.ts +206 -0
  61. package/dist/utils/agent-config.d.ts.map +1 -0
  62. package/dist/utils/http.d.ts +85 -0
  63. package/dist/utils/http.d.ts.map +1 -0
  64. package/dist/utils/multipart.d.ts +60 -0
  65. package/dist/utils/multipart.d.ts.map +1 -0
  66. package/dist/utils/precision-math.d.ts +37 -0
  67. package/dist/utils/precision-math.d.ts.map +1 -0
  68. package/dist/utils/validation.d.ts +131 -0
  69. package/dist/utils/validation.d.ts.map +1 -0
  70. package/dist/utils/wallet.d.ts +174 -0
  71. package/dist/utils/wallet.d.ts.map +1 -0
  72. package/package.json +151 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,46 @@
1
+ # Changelog
2
+
3
+ All notable changes to the Gala Launchpad SDK will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.4.0] - 2024-01-24
8
+
9
+ ### Added
10
+ - **Wallet Creation Helpers**: New `createWallet()` function with smart auto-detection
11
+ - Automatically detects private key vs mnemonic input format
12
+ - Supports 12-word and 24-word mnemonics
13
+ - Handles 64-character hex private keys (with or without 0x prefix)
14
+ - Generates random wallets when no input provided
15
+ - **SDK Factory Functions**: Simplified SDK initialization
16
+ - `createLaunchpadSDK()` - Main factory with wallet auto-detection
17
+ - `createTestLaunchpadSDK()` - Test-optimized configuration
18
+ - **Input Validation**: New `validateWalletInput()` for format validation without wallet creation
19
+ - **Comprehensive Testing**: 27 new tests for helper functions
20
+ - Tests cover all input formats, edge cases, and error conditions
21
+ - Full validation of auto-detection logic
22
+ - Integration tests with SDK creation
23
+
24
+ ### Changed
25
+ - **Simplified API**: Streamlined helper functions for better developer experience
26
+ - **Updated Documentation**: Enhanced examples showcasing new helper functions
27
+ - **Demo Enhancement**: Updated demo script to use new factory methods
28
+
29
+ ### Removed
30
+ - **Removed Complexity**: Eliminated environment-specific SDK factory function
31
+
32
+ ### Developer Experience
33
+ - **Auto-Detection**: No need to specify input type - helpers detect format automatically
34
+ - **Error Messages**: Clear, helpful error messages for invalid inputs
35
+ - **Type Safety**: Full TypeScript support with strict typing
36
+ - **Test Coverage**: 100% line coverage for all helper functions
37
+
38
+ ### Technical Details
39
+ - 132 total tests passing (27 new helper tests)
40
+ - Bundle size maintained under 50KB limit
41
+ - Full backward compatibility preserved
42
+ - Production-ready with comprehensive error handling
43
+
44
+ ## Previous Releases
45
+
46
+ See git commit history for changes in versions prior to 0.4.0.
package/README.md ADDED
@@ -0,0 +1,628 @@
1
+ # Gala Launchpad SDK v3.0
2
+
3
+ A comprehensive TypeScript SDK for the Gala Launchpad Backend API, providing type-safe authentication, pool management, trading, and user operations for DeFi applications.
4
+
5
+ [![npm version](https://badge.fury.io/js/@gala-chain%2Flaunchpad-sdk.svg)](https://badge.fury.io/js/@gala-chain%2Flaunchpad-sdk)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
8
+
9
+ ## ๐Ÿš€ What's New in v3.0 - Revolutionary Flat API
10
+
11
+ **๐Ÿ”ฅ BREAKING CHANGE: Complete API restructure with flat design pattern**
12
+
13
+ - **Flat API Structure**: All methods now directly on SDK root (no more nested APIs)
14
+ - **Semantic Naming**: `fetch*`, `calculate*`, action verbs for clear intent
15
+ - **Options Bag Pattern**: Consistent parameter structure with required `tokenName`
16
+ - **Complete Legacy Removal**: All deprecated methods removed ("full burn")
17
+ - **22 Core Methods**: Streamlined from complex nested structure
18
+
19
+ ### Revolutionary Flat API Design
20
+
21
+ **Before v3.0 (Nested APIs):**
22
+ ```typescript
23
+ // โŒ OLD: Complex nested structure
24
+ const pools = await sdk.launchpad.getPools({ type: 'recent' });
25
+ const amount = await sdk.launchpad.getBuyTokenAmount('token', { amount: '100', type: 'native' });
26
+ const result = await sdk.trading.buyToken('token', { amount: '100', type: 'native' });
27
+ const trades = await sdk.trade.getTrades('token');
28
+ const comments = await sdk.comment.getComments('token');
29
+ ```
30
+
31
+ **After v3.0 (Flat APIs):**
32
+ ```typescript
33
+ // โœ… NEW: Everything directly on SDK root
34
+ const pools = await sdk.fetchPools({ type: 'recent' });
35
+ const amount = await sdk.calculateBuyAmount({ tokenName: 'token', amount: '100', type: 'native' });
36
+ const result = await sdk.buy({ tokenName: 'token', amount: '100', type: 'native' });
37
+ const trades = await sdk.fetchTrades('token');
38
+ const comments = await sdk.fetchComments('token');
39
+ ```
40
+
41
+ ### Complete v3.0 Flat API
42
+
43
+ **Pool & Token Operations:**
44
+ - `sdk.fetchPools()` - Get pools (recent, popular, search)
45
+ - `sdk.fetchTokenDistribution()` - Token holder distribution
46
+ - `sdk.fetchTokenBadges()` - Volume and engagement badges
47
+ - `sdk.fetchSaleDetails()` - Token sale information
48
+ - `sdk.createSale()` - Create new token sale
49
+ - `sdk.uploadTokenImage()` - Upload token images
50
+
51
+ **Price Calculations:**
52
+ - `sdk.calculateBuyAmount()` - Calculate GALA cost for tokens
53
+ - `sdk.calculateSellAmount()` - Calculate GALA received from tokens
54
+ - `sdk.calculateInitialBuyAmount()` - Pre-mint calculations
55
+
56
+ **Trading Operations:**
57
+ - `sdk.buy()` - Buy tokens with slippage protection
58
+ - `sdk.sell()` - Sell tokens with slippage protection
59
+
60
+ **Data & Analytics:**
61
+ - `sdk.fetchTrades()` - Trade history with filtering
62
+ - `sdk.fetchComments()` - Token comments
63
+ - `sdk.createComment()` - Post new comment
64
+ - `sdk.fetchGalaBalance()` - User GALA balance
65
+ - `sdk.fetchTokenBalance()` - User token holdings
66
+
67
+ **User Operations:**
68
+ - `sdk.fetchUserProfile()` - User profile data
69
+ - `sdk.updateProfile()` - Update user profile
70
+ - `sdk.requestFaucet()` - Request test tokens
71
+
72
+ ## ๐Ÿš€ Features
73
+
74
+ - **Type-Safe API Client**: Full TypeScript support with comprehensive type definitions
75
+ - **Signature Authentication**: Ethereum wallet-based authentication with automatic signature generation
76
+ - **Simplified API**: Unified methods reduce complexity while maintaining full functionality
77
+ - **Pool Management**: Create, fetch, and check token pools on the launchpad
78
+ - **Token Trading**: Buy and sell tokens with slippage protection via GalaChain
79
+ - **Pre-mint Calculations**: Calculate token amounts for initial investments using CallMemeTokenOut
80
+ - **User Operations**: Profile management, token balances, and faucet transfers
81
+ - **Comment System**: Post and retrieve comments on token pools
82
+ - **Comprehensive Validation**: Input validation and error handling for all operations
83
+ - **Multi-Environment Support**: Production, staging, and custom backend URLs
84
+
85
+ ### ๐ŸŽฏ **Complete API Restructure**
86
+ - โœ… **Flat Structure**: 22 methods directly on SDK root
87
+ - โœ… **Semantic Naming**: `fetch*`, `calculate*`, action verbs
88
+ - โœ… **Options Bag**: Consistent `{tokenName, ...}` pattern
89
+ - โœ… **Legacy Removal**: All deprecated methods removed
90
+ - โœ… **Type Safety**: Full TypeScript support maintained
91
+ - โœ… **User API**: Profile and account management (6 methods)
92
+ - โœ… **Comment API**: TokenName-based comment system (2 methods)
93
+
94
+ ### ๐Ÿ”„ **Token Architecture**
95
+ **Important:** Tokens are created as pools and traded through GalaChain integration.
96
+ - โœ… **Token Creation**: Create token sales via `/launchpad/create-sale`
97
+ - โœ… **Pool Management**: Unified pool fetching with flexible filtering
98
+ - โœ… **Trading Integration**: Simplified buy/sell operations with GalaChain Gateway
99
+ - โœ… **Real-time Data**: Graph data and sale details for market analysis
100
+
101
+ ## ๐Ÿ“ฆ Installation
102
+
103
+ ```bash
104
+ npm install @gala-chain/launchpad-sdk@^3.0.0
105
+ ```
106
+
107
+ Or with yarn:
108
+
109
+ ```bash
110
+ yarn add @gala-chain/launchpad-sdk@^3.0.0
111
+ ```
112
+
113
+ > **โš ๏ธ Breaking Changes in v3.0**: Complete API restructure with flat design. See migration guide below.
114
+
115
+ ## ๐Ÿ Quick Start
116
+
117
+ ### Basic Usage with New Flat API
118
+
119
+ ```typescript
120
+ import { Wallet } from 'ethers';
121
+ import { LaunchpadSDK } from '@gala-chain/launchpad-sdk';
122
+
123
+ // Initialize with wallet for automatic authentication
124
+ const wallet = new Wallet(process.env.PRIVATE_KEY);
125
+ const sdk = new LaunchpadSDK({
126
+ wallet: wallet,
127
+ baseUrl: 'https://lpad-backend-dev1.defi.gala.com',
128
+ timeout: 30000,
129
+ debug: false
130
+ });
131
+
132
+ // ๐Ÿš€ NEW v3.0 Flat API - Everything directly on SDK root!
133
+
134
+ // Pool Management
135
+ const pools = await sdk.fetchPools({ type: 'recent', limit: 10 });
136
+ const badges = await sdk.fetchTokenBadges('dragnrkti');
137
+ const details = await sdk.fetchSaleDetails('dragnrkti');
138
+
139
+ // Price Calculations
140
+ const buyAmount = await sdk.calculateBuyAmount({
141
+ tokenName: 'dragnrkti',
142
+ amount: '1000000000000000000', // 1 GALA
143
+ type: 'native'
144
+ });
145
+
146
+ // Trading Operations
147
+ const buyResult = await sdk.buy({
148
+ tokenName: 'dragnrkti',
149
+ amount: '1000000000000000000',
150
+ type: 'native',
151
+ slippage: 5
152
+ });
153
+
154
+ // Data & Analytics
155
+ const trades = await sdk.fetchTrades('dragnrkti');
156
+ const comments = await sdk.fetchComments('dragnrkti');
157
+ const balance = await sdk.fetchGalaBalance(sdk.getAddress());
158
+
159
+ // User Operations
160
+ const profile = await sdk.fetchUserProfile();
161
+ const tokenBalance = await sdk.fetchTokenBalance({
162
+ tokenName: 'dragnrkti',
163
+ walletAddress: sdk.getAddress()
164
+ });
165
+
166
+ // Create a new token sale
167
+ const sale = await sdk.launchpad.createSale({
168
+ tokenName: 'MyToken',
169
+ tokenSymbol: 'MTK',
170
+ tokenDescription: 'My awesome token',
171
+ preBuyQuantity: '100', // Initial GALA to invest
172
+ tokenImage: 'https://example.com/token-image.png',
173
+ websiteUrl: 'https://mytoken.com'
174
+ });
175
+
176
+ // Fetch pools with unified API
177
+ const recentPools = await sdk.launchpad.getPools({
178
+ type: 'recent',
179
+ page: 1,
180
+ limit: 10
181
+ });
182
+
183
+ // Get price calculation with unified API
184
+ const buyAmount = await sdk.launchpad.getBuyTokenAmount('tinyevil', {
185
+ amount: '10', // 10 GALA
186
+ type: 'native'
187
+ });
188
+
189
+ // Buy tokens with unified API
190
+ const buyResult = await sdk.trading.buyToken('tinyevil', {
191
+ amount: '10', // 10 GALA
192
+ type: 'native',
193
+ slippage: 5 // 5% slippage tolerance
194
+ });
195
+
196
+ // Check user's GALA balance
197
+ const balance = await sdk.user.getGalaBalance({
198
+ userAddress: sdk.getAddress()
199
+ });
200
+ ```
201
+
202
+ ### Configuration Options
203
+
204
+ ```typescript
205
+ import { Wallet } from 'ethers';
206
+ import { LaunchpadSDK } from '@gala-chain/launchpad-sdk';
207
+
208
+ const wallet = new Wallet('your-private-key');
209
+
210
+ // Basic configuration
211
+ const sdk = new LaunchpadSDK({
212
+ wallet: wallet, // Required for authentication
213
+ baseUrl: 'https://lpad-backend-dev1.defi.gala.com',
214
+ timeout: 30000,
215
+ debug: false
216
+ });
217
+
218
+ // Advanced configuration
219
+ const sdk = new LaunchpadSDK({
220
+ wallet: wallet,
221
+ baseUrl: 'https://your-custom-backend.com',
222
+ timeout: 60000,
223
+ debug: true, // Enable request/response logging
224
+ maxRetries: 3,
225
+ retryDelay: 1000
226
+ });
227
+ ```
228
+
229
+ **Common Backend URLs:**
230
+ - **Development**: `https://lpad-backend-dev1.defi.gala.com`
231
+ - **Custom**: Specify your own backend URL
232
+
233
+ ### Address Format Utilities
234
+
235
+ The SDK includes utilities for converting between Ethereum and backend address formats:
236
+
237
+ ```typescript
238
+ // Get wallet address in different formats
239
+ const ethereumAddress = sdk.getEthereumAddress(); // "0x742d35Cc..."
240
+ const backendAddress = sdk.getAddress(); // "eth|742d35Cc..."
241
+
242
+ // Manual conversion utilities
243
+ import { formatAddressForBackend, formatAddressForEthereum } from '@gala-chain/launchpad-sdk';
244
+
245
+ const backendFormat = formatAddressForBackend('0x742d35Cc...'); // "eth|742d35Cc..."
246
+ const ethFormat = formatAddressForEthereum('eth|742d35Cc...'); // "0x742d35Cc..."
247
+ ```
248
+
249
+ ## ๐Ÿ“š API Reference
250
+
251
+ ### Core SDK
252
+
253
+ - **`LaunchpadSDK`** - Main SDK class with wallet-based authentication
254
+ - **`launchpad`** - Unified pool operations and price calculations (6 methods)
255
+ - **`trading`** - Unified trading operations (2 methods)
256
+ - **`trade`** - Simplified trade history with client-side filtering (1 method)
257
+ - **`user`** - Profile and balance management (6 methods)
258
+ - **`comment`** - TokenName-based comment system (2 methods)
259
+
260
+ ### New Unified API Methods
261
+
262
+ #### Unified Pool Management
263
+ ```typescript
264
+ // Get pools with flexible filtering (replaces 4 separate methods)
265
+ const pools = await sdk.launchpad.getPools({
266
+ type: 'recent' | 'popular', // Optional filter
267
+ search: 'keyword', // Optional search
268
+ tokenName: 'specific_token', // Optional token filter
269
+ page: 1,
270
+ limit: 20
271
+ });
272
+ ```
273
+
274
+ #### Unified Price Calculations
275
+ ```typescript
276
+ // Buy calculations (replaces 2 separate methods)
277
+ const buyCalc = await sdk.launchpad.getBuyTokenAmount('tokenName', {
278
+ amount: '100',
279
+ type: 'native' | 'exact'
280
+ });
281
+
282
+ // Sell calculations (replaces 2 separate methods)
283
+ const sellCalc = await sdk.launchpad.getSellTokenAmount('tokenName', {
284
+ amount: '50',
285
+ type: 'exact' | 'native'
286
+ });
287
+ ```
288
+
289
+ #### Unified Trading Operations
290
+ ```typescript
291
+ // Buy tokens (replaces 2 separate methods)
292
+ const buyResult = await sdk.trading.buyToken('tokenName', {
293
+ amount: '100',
294
+ type: 'native' | 'exact',
295
+ slippage: 5 // Optional, defaults to 5%
296
+ });
297
+
298
+ // Sell tokens (replaces 2 separate methods)
299
+ const sellResult = await sdk.trading.sellToken('tokenName', {
300
+ amount: '50',
301
+ type: 'exact' | 'native',
302
+ slippage: 3 // Optional, defaults to 5%
303
+ });
304
+ ```
305
+
306
+ #### Unified Trade History
307
+ ```typescript
308
+ // Get all trades and filter client-side (more performant)
309
+ const allTrades = await sdk.trade.getTrades('tokenName', { page: 1, limit: 20 });
310
+
311
+ // Filter client-side for specific trade types
312
+ const buyTrades = allTrades.data.filter(trade => trade.tradeType === 'buy');
313
+ const sellTrades = allTrades.data.filter(trade => trade.tradeType === 'sell');
314
+ ```
315
+
316
+ For complete API documentation, see [API.md](./API.md).
317
+
318
+ ### Authentication
319
+
320
+ Authentication is handled automatically using wallet signatures:
321
+
322
+ ```typescript
323
+ import { Wallet } from 'ethers';
324
+
325
+ // Initialize with wallet - authentication is automatic
326
+ const wallet = new Wallet(process.env.PRIVATE_KEY);
327
+ const sdk = new LaunchpadSDK({
328
+ wallet: wallet,
329
+ baseUrl: 'https://lpad-backend-dev1.defi.gala.com'
330
+ });
331
+
332
+ // All requests are automatically signed
333
+ const pools = await sdk.launchpad.getPools({ type: 'recent' });
334
+
335
+ // Get wallet addresses
336
+ const ethAddress = sdk.getEthereumAddress(); // 0x format
337
+ const backendAddress = sdk.getAddress(); // eth| format
338
+ ```
339
+
340
+ The SDK automatically generates and signs authentication messages for each request using your wallet private key.
341
+
342
+ ### Pool Management
343
+
344
+ ```typescript
345
+ // Create a new token sale
346
+ const sale = await sdk.launchpad.createSale({
347
+ tokenName: 'MyToken',
348
+ tokenSymbol: 'MTK',
349
+ tokenDescription: 'My awesome token',
350
+ preBuyQuantity: '100', // Initial GALA investment
351
+ tokenImage: 'https://example.com/token.png',
352
+ websiteUrl: 'https://mytoken.com'
353
+ });
354
+
355
+ // Fetch pools with unified API
356
+ const recentPools = await sdk.launchpad.getPools({
357
+ type: 'recent',
358
+ page: 1,
359
+ limit: 20
360
+ });
361
+
362
+ const popularPools = await sdk.launchpad.getPools({
363
+ type: 'popular',
364
+ page: 1,
365
+ limit: 20
366
+ });
367
+
368
+ const searchResults = await sdk.launchpad.getPools({
369
+ search: 'gaming',
370
+ page: 1,
371
+ limit: 10
372
+ });
373
+
374
+ // Check if a pool exists
375
+ const exists = await sdk.launchpad.checkPool({
376
+ tokenName: 'tinyevil'
377
+ });
378
+
379
+ // Get graph data for token
380
+ const graphData = await sdk.launchpad.getGraphData({
381
+ tokenName: 'tinyevil',
382
+ from: Date.now() - 86400000, // 24 hours ago
383
+ to: Date.now(),
384
+ resolution: 3600 // 1 hour
385
+ });
386
+ ```
387
+
388
+ ### Price Calculations with Unified API
389
+
390
+ The SDK provides unified methods for all price calculation scenarios:
391
+
392
+ ```typescript
393
+ // Buy with GALA - Calculate tokens you'll receive
394
+ const buyWithGala = await sdk.launchpad.getBuyTokenAmount('tinyevil', {
395
+ amount: '10', // 10 GALA
396
+ type: 'native'
397
+ });
398
+ console.log('Tokens to receive:', buyWithGala.data.calculatedQuantity);
399
+
400
+ // Buy exact tokens - Calculate GALA needed
401
+ const buyExactTokens = await sdk.launchpad.getBuyTokenAmount('tinyevil', {
402
+ amount: '100', // 100 tokens
403
+ type: 'exact'
404
+ });
405
+ console.log('GALA needed:', buyExactTokens.data.calculatedQuantity);
406
+
407
+ // Sell exact tokens - Calculate GALA you'll receive
408
+ const sellExactTokens = await sdk.launchpad.getSellTokenAmount('tinyevil', {
409
+ amount: '50', // 50 tokens
410
+ type: 'exact'
411
+ });
412
+ console.log('GALA to receive:', sellExactTokens.data.calculatedQuantity);
413
+
414
+ // Sell for exact GALA - Calculate tokens needed
415
+ const sellForGala = await sdk.launchpad.getSellTokenAmount('tinyevil', {
416
+ amount: '5', // 5 GALA
417
+ type: 'native'
418
+ });
419
+ console.log('Tokens needed:', sellForGala.data.calculatedQuantity);
420
+
421
+ // Pre-mint calculation during token launch
422
+ const preMintResult = await sdk.launchpad.calculatePreMintTokens({
423
+ nativeTokenQuantity: '1000000000000000000' // 1 GALA for pre-buy
424
+ });
425
+ if (preMintResult.Status === 1) {
426
+ console.log('Pre-mint tokens:', preMintResult.Data.calculatedQuantity);
427
+ console.log('Fees:', preMintResult.Data.extraFees);
428
+ }
429
+ ```
430
+
431
+ ### Trading with Unified API
432
+
433
+ ```typescript
434
+ // Buy tokens with unified API
435
+ const buyResult = await sdk.trading.buyToken('tinyevil', {
436
+ amount: '10', // 10 GALA or 10 tokens depending on type
437
+ type: 'native', // 'native' = spending GALA, 'exact' = buying exact tokens
438
+ slippage: 5 // 5% slippage tolerance
439
+ });
440
+
441
+ // Sell tokens with unified API
442
+ const sellResult = await sdk.trading.sellToken('tinyevil', {
443
+ amount: '50', // 50 tokens or 50 GALA depending on type
444
+ type: 'exact', // 'exact' = selling exact tokens, 'native' = receiving exact GALA
445
+ slippage: 3 // 3% slippage tolerance
446
+ });
447
+
448
+ // Get trade history with client-side filtering (more performant)
449
+ const allTrades = await sdk.trade.getTrades('tinyevil', { page: 1, limit: 20 });
450
+
451
+ // Filter client-side for specific analysis
452
+ const buyTrades = allTrades.data.filter(trade => trade.tradeType === 'buy');
453
+ const sellTrades = allTrades.data.filter(trade => trade.tradeType === 'sell');
454
+
455
+ // Get current sale details
456
+ const saleDetails = await sdk.trade.getSaleDetailsByTokenName('tinyevil');
457
+ ```
458
+
459
+ ### User Operations
460
+
461
+ ```typescript
462
+ // Get user's created tokens
463
+ const tokenList = await sdk.user.getTokenList({
464
+ address: sdk.getAddress(),
465
+ type: 'DEFI', // or 'ASSET'
466
+ page: 1,
467
+ limit: 10
468
+ });
469
+
470
+ // Get user's token holdings
471
+ const holdings = await sdk.user.getTokensHeld({
472
+ address: sdk.getAddress(),
473
+ page: 1,
474
+ limit: 10
475
+ });
476
+
477
+ // Check GALA balance
478
+ const balance = await sdk.user.getGalaBalance({
479
+ userAddress: sdk.getAddress()
480
+ });
481
+
482
+ // Update user profile
483
+ const profile = await sdk.user.updateProfile({
484
+ profileImage: 'https://example.com/avatar.jpg',
485
+ fullName: 'John Smith', // Alphabets only
486
+ userAddress: sdk.getAddress()
487
+ });
488
+
489
+ // Get user profile
490
+ const userProfile = await sdk.user.getProfile();
491
+
492
+ // Transfer faucet tokens (if available)
493
+ const faucet = await sdk.user.transferFaucets({
494
+ userAddress: sdk.getAddress(),
495
+ amount: '1000000000000000000' // 1 token with 18 decimals
496
+ });
497
+
498
+ // Check if transfer was successful
499
+ if (faucet.status === 200 && !faucet.error) {
500
+ console.log('Faucet transfer successful:', faucet.message);
501
+ }
502
+ ```
503
+
504
+ ### Comment System
505
+
506
+ **TokenName-Based API**
507
+
508
+ ```typescript
509
+ // Get comments for a token by tokenName (CLEAN & INTUITIVE!)
510
+ const comments = await sdk.comment.getCommentsByTokenName("dragnrkti", 1, 10);
511
+ console.log('Comments:', comments.data?.comments);
512
+
513
+ // Post a comment using tokenName (SIMPLE!)
514
+ await sdk.comment.postCommentOnTokenName("rocketri", "Great project with solid fundamentals!");
515
+
516
+ // The SDK automatically resolves tokenNames to vault addresses
517
+ // No need to know vault addresses - just use simple token names!
518
+ ```
519
+
520
+ ## โš™๏ธ Configuration
521
+
522
+ ```typescript
523
+ import { Wallet } from 'ethers';
524
+ import { LaunchpadSDK } from '@gala-chain/launchpad-sdk';
525
+
526
+ const sdk = new LaunchpadSDK({
527
+ wallet: new Wallet('your-private-key'),
528
+ baseUrl: 'https://lpad-backend-dev1.defi.gala.com',
529
+ timeout: 30000,
530
+ debug: false
531
+ });
532
+ ```
533
+
534
+ ## ๐Ÿ”„ Migration Guide
535
+
536
+ ### From v1.x to v2.0
537
+
538
+ The new unified API is fully backwards compatible. Old methods are deprecated but still work:
539
+
540
+ ```typescript
541
+ // โŒ OLD API (still works but deprecated)
542
+ const recentPools = await sdk.launchpad.getRecentPools(1, 10);
543
+ const popularPools = await sdk.launchpad.getPopularPools(1, 10);
544
+ const searchResults = await sdk.launchpad.searchPools('gaming', 1, 10);
545
+
546
+ const buyAmount = await sdk.launchpad.getBuyWithNativeAmountByTokenName('token', '100');
547
+ const sellAmount = await sdk.launchpad.getSellExactTokenAmountByTokenName('token', '50');
548
+
549
+ const buyResult = await sdk.trading.buyNativeByTokenName('token', '100', expected, 5);
550
+ const sellResult = await sdk.trading.sellExactByTokenName('token', '50', expected, 5);
551
+
552
+ const buyTrades = await sdk.trade.getBuyTradesByTokenName('token', { page: 1, limit: 10 });
553
+ const sellTrades = await sdk.trade.getSellTradesByTokenName('token', { page: 1, limit: 10 });
554
+
555
+ // โœ… NEW UNIFIED API (recommended)
556
+ const recentPools = await sdk.launchpad.getPools({ type: 'recent', page: 1, limit: 10 });
557
+ const popularPools = await sdk.launchpad.getPools({ type: 'popular', page: 1, limit: 10 });
558
+ const searchResults = await sdk.launchpad.getPools({ search: 'gaming', page: 1, limit: 10 });
559
+
560
+ const buyAmount = await sdk.launchpad.getBuyTokenAmount('token', { amount: '100', type: 'native' });
561
+ const sellAmount = await sdk.launchpad.getSellTokenAmount('token', { amount: '50', type: 'exact' });
562
+
563
+ const buyResult = await sdk.trading.buyToken('token', { amount: '100', type: 'native', slippage: 5 });
564
+ const sellResult = await sdk.trading.sellToken('token', { amount: '50', type: 'exact', slippage: 5 });
565
+
566
+ const allTrades = await sdk.trade.getTrades('token', { page: 1, limit: 10 });
567
+ const buyTrades = allTrades.data.filter(t => t.tradeType === 'buy');
568
+ const sellTrades = allTrades.data.filter(t => t.tradeType === 'sell');
569
+ ```
570
+
571
+ ### Benefits of the New API
572
+
573
+ โœ… **47% fewer methods** - Easier to learn and use
574
+ โœ… **Consistent patterns** - All methods follow similar interfaces
575
+ โœ… **Better TypeScript support** - Enhanced IntelliSense and autocomplete
576
+ โœ… **Improved performance** - Client-side filtering reduces API calls
577
+ โœ… **Unified error handling** - Consistent error patterns across all methods
578
+ โœ… **Future-proof design** - Easier to extend with new functionality
579
+
580
+ ## ๐Ÿงช Testing
581
+
582
+ ```bash
583
+ # Run tests
584
+ npm test
585
+
586
+ # Run tests with coverage
587
+ npm run test:coverage
588
+
589
+ # Run tests in watch mode
590
+ npm run test:watch
591
+ ```
592
+
593
+ ## ๐Ÿ—๏ธ Development
594
+
595
+ ```bash
596
+ # Install dependencies
597
+ npm install
598
+
599
+ # Start development mode
600
+ npm run dev
601
+
602
+ # Build the package
603
+ npm run build
604
+
605
+ # Run linting
606
+ npm run lint
607
+
608
+ # Run type checking
609
+ npm run typecheck
610
+ ```
611
+
612
+ ## ๐Ÿ“„ License
613
+
614
+ MIT ยฉ [Gala Launchpad Team](https://gitlab.com/gala-games/defi/launchpad)
615
+
616
+ ## ๐Ÿค Contributing
617
+
618
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
619
+
620
+ ## ๐Ÿ“ž Support
621
+
622
+ - ๐Ÿ“ง Email: dev@gala-launchpad.com
623
+ - ๐Ÿ› Issues: [GitLab Issues](https://gitlab.com/gala-games/defi/launchpad/sdk/-/issues)
624
+ - ๐Ÿ“– Documentation: [API Documentation](https://docs.gala-launchpad.com)
625
+
626
+ ---
627
+
628
+ Built with โค๏ธ by the Gala Launchpad Team