@gala-chain/launchpad-sdk 3.31.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +524 -4
- package/CHANGELOG.md +92 -0
- package/EXAMPLES.md +845 -0
- package/README.md +421 -14
- package/dist/LaunchpadSDK.d.ts +435 -18
- package/dist/LaunchpadSDK.d.ts.map +1 -1
- package/dist/api/LaunchpadAPI.d.ts.map +1 -1
- package/dist/api/dto/TransferTokenDto.d.ts.map +1 -1
- package/dist/constants/version.generated.d.ts +1 -1
- package/dist/constants/version.generated.d.ts.map +1 -1
- package/dist/helpers/sdk.d.ts +1 -0
- package/dist/helpers/sdk.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/services/BaseService.d.ts +32 -3
- package/dist/services/BaseService.d.ts.map +1 -1
- package/dist/services/BundleService.d.ts.map +1 -1
- package/dist/services/CommentService.d.ts.map +1 -1
- package/dist/services/DexBackendClient.d.ts +46 -0
- package/dist/services/DexBackendClient.d.ts.map +1 -0
- package/dist/services/DexPoolService.d.ts +54 -12
- package/dist/services/DexPoolService.d.ts.map +1 -1
- package/dist/services/DexQuoteService.d.ts +288 -0
- package/dist/services/DexQuoteService.d.ts.map +1 -0
- package/dist/services/DexService.d.ts.map +1 -1
- package/dist/services/FaucetService.d.ts.map +1 -1
- package/dist/services/GSwapService.d.ts +519 -44
- package/dist/services/GSwapService.d.ts.map +1 -1
- package/dist/services/GalaChainGatewayClient.d.ts +89 -0
- package/dist/services/GalaChainGatewayClient.d.ts.map +1 -0
- package/dist/services/GalaChainService.d.ts +26 -0
- package/dist/services/GalaChainService.d.ts.map +1 -1
- package/dist/services/ImageService.d.ts.map +1 -1
- package/dist/services/PoolService.d.ts.map +1 -1
- package/dist/services/PoolStateManager.d.ts +176 -0
- package/dist/services/PoolStateManager.d.ts.map +1 -0
- package/dist/services/PriceHistoryService.d.ts +4 -5
- package/dist/services/PriceHistoryService.d.ts.map +1 -1
- package/dist/services/SignatureService.d.ts +15 -38
- package/dist/services/SignatureService.d.ts.map +1 -1
- package/dist/services/TokenClassKeyService.d.ts +3 -4
- package/dist/services/TokenClassKeyService.d.ts.map +1 -1
- package/dist/services/TokenMetadataCache.d.ts +2 -2
- package/dist/services/TokenMetadataCache.d.ts.map +1 -1
- package/dist/services/TokenMetadataService.d.ts +3 -3
- package/dist/services/TokenMetadataService.d.ts.map +1 -1
- package/dist/services/TokenResolverService.d.ts +2 -2
- package/dist/services/TokenResolverService.d.ts.map +1 -1
- package/dist/services/TradeService.d.ts.map +1 -1
- package/dist/services/UserService.d.ts.map +1 -1
- package/dist/services/WebSocketService.d.ts +100 -2
- package/dist/services/WebSocketService.d.ts.map +1 -1
- package/dist/services/__mocks__/logger.mock.d.ts +17 -0
- package/dist/services/__mocks__/logger.mock.d.ts.map +1 -0
- package/dist/types/common.d.ts +2 -0
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/composite-pool.dto.d.ts +103 -0
- package/dist/types/composite-pool.dto.d.ts.map +1 -0
- package/dist/types/dex-pool.dto.d.ts +56 -5
- package/dist/types/dex-pool.dto.d.ts.map +1 -1
- package/dist/types/dto.d.ts +6 -6
- package/dist/types/dto.d.ts.map +1 -1
- package/dist/types/eip712-types.d.ts +140 -0
- package/dist/types/eip712-types.d.ts.map +1 -0
- package/dist/types/galachain-api.types.d.ts +206 -0
- package/dist/types/galachain-api.types.d.ts.map +1 -0
- package/dist/types/gswap-responses.types.d.ts +366 -0
- package/dist/types/gswap-responses.types.d.ts.map +1 -0
- package/dist/types/gswap.dto.d.ts +58 -3
- package/dist/types/gswap.dto.d.ts.map +1 -1
- package/dist/types/launchpad.dto.d.ts +57 -0
- package/dist/types/launchpad.dto.d.ts.map +1 -1
- package/dist/types/pool-state-delta.dto.d.ts +246 -0
- package/dist/types/pool-state-delta.dto.d.ts.map +1 -0
- package/dist/types/pool-state-manager-config.dto.d.ts +103 -0
- package/dist/types/pool-state-manager-config.dto.d.ts.map +1 -0
- package/dist/utils/SignatureHelper.d.ts.map +1 -1
- package/dist/utils/auto-pagination.d.ts +206 -0
- package/dist/utils/auto-pagination.d.ts.map +1 -0
- package/dist/utils/bignumber-helpers.d.ts +336 -0
- package/dist/utils/bignumber-helpers.d.ts.map +1 -0
- package/dist/utils/bignumber-pool-cache.d.ts +169 -0
- package/dist/utils/bignumber-pool-cache.d.ts.map +1 -0
- package/dist/utils/composite-pool-converter.d.ts +121 -0
- package/dist/utils/composite-pool-converter.d.ts.map +1 -0
- package/dist/utils/errors.d.ts +86 -0
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/http.d.ts.map +1 -1
- package/dist/utils/load-env.d.ts +31 -0
- package/dist/utils/load-env.d.ts.map +1 -0
- package/dist/utils/pool-pair-parser.d.ts +55 -0
- package/dist/utils/pool-pair-parser.d.ts.map +1 -0
- package/dist/utils/pool-state-validator.d.ts +207 -0
- package/dist/utils/pool-state-validator.d.ts.map +1 -0
- package/dist/utils/position-filters.d.ts +253 -0
- package/dist/utils/position-filters.d.ts.map +1 -0
- package/dist/utils/swap-delta-calculator.d.ts +231 -0
- package/dist/utils/swap-delta-calculator.d.ts.map +1 -0
- package/dist/utils/tick-crossing-handler.d.ts +250 -0
- package/dist/utils/tick-crossing-handler.d.ts.map +1 -0
- package/dist/utils/token-format-converter.d.ts +85 -6
- package/dist/utils/token-format-converter.d.ts.map +1 -1
- package/dist/utils/token-parser.d.ts +235 -0
- package/dist/utils/token-parser.d.ts.map +1 -0
- package/dist/utils/tokenNormalizer.d.ts +66 -0
- package/dist/utils/tokenNormalizer.d.ts.map +1 -1
- package/dist/utils/transfer-validation.d.ts.map +1 -1
- package/dist/utils/validation-helpers.d.ts +75 -0
- package/dist/utils/validation-helpers.d.ts.map +1 -1
- package/package.json +36 -15
- package/dist/utils/tokenFormatConverter.d.ts +0 -53
- package/dist/utils/tokenFormatConverter.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
A comprehensive TypeScript SDK for the Gala Launchpad Backend API, providing type-safe authentication, trading, and real-time features for DeFi applications.
|
|
4
4
|
|
|
5
|
+
> **⚠️ BREAKING CHANGE (v3.33.0+)**: Token format parsing now **ONLY accepts delimited formats** (`GALA|Unit|none|none` or `GALA$Unit$none$none`). Plain token strings (`'GALA'`, `'GUSDC'`) are **permanently rejected** for security. See [Migration Guide](#token-format-migration-v330) below.
|
|
6
|
+
|
|
5
7
|
[](https://badge.fury.io/js/@gala-chain%2Flaunchpad-sdk)
|
|
6
8
|
[](https://opensource.org/licenses/MIT)
|
|
7
9
|
[](http://www.typescriptlang.org/)
|
|
@@ -63,7 +65,7 @@ console.log(pools.hasNext); // Computed convenience properties
|
|
|
63
65
|
- **Token Trading**: Buy and sell tokens with slippage protection via GalaChain
|
|
64
66
|
- **DEX Pool Discovery**: Discover and explore GalaSwap liquidity pools with filtering, sorting, and pagination
|
|
65
67
|
- **DEX Trading**: Real-time token swaps on GalaSwap DEX with quote generation and slippage protection
|
|
66
|
-
- **Liquidity Management**: Manage liquidity positions on GalaSwap (add, remove, collect fees)
|
|
68
|
+
- **Liquidity Management**: Manage liquidity positions on GalaSwap (add, remove, collect fees) with filtering and organization utilities
|
|
67
69
|
- **Token Transfers**: Transfer GALA and launchpad tokens between wallets with EIP-712 signatures
|
|
68
70
|
- **User Operations**: Portfolio management, token balances, and account management
|
|
69
71
|
- **Comment System**: Post and retrieve comments on token pools
|
|
@@ -292,6 +294,185 @@ const result = await sdk.buy({
|
|
|
292
294
|
- ✅ Missing wallet throws `ValidationError` with code `WALLET_REQUIRED`
|
|
293
295
|
- ⚠️ Only methods that sign transactions require a wallet
|
|
294
296
|
|
|
297
|
+
## Token Format Migration (v3.33.0)
|
|
298
|
+
|
|
299
|
+
### Breaking Change: Strict Token Format Enforcement
|
|
300
|
+
|
|
301
|
+
**v3.33.0 removes support for plain token strings** and requires all tokens to use **delimited format**.
|
|
302
|
+
|
|
303
|
+
#### Old Behavior (v3.32.x and below) - DEPRECATED
|
|
304
|
+
|
|
305
|
+
Plain token strings were accepted:
|
|
306
|
+
```typescript
|
|
307
|
+
// ❌ NO LONGER WORKS (v3.33.0+)
|
|
308
|
+
await sdk.addSwapLiquidityByPrice({
|
|
309
|
+
token0: 'GALA', // Plain string
|
|
310
|
+
token1: 'GUSDC', // Plain string
|
|
311
|
+
fee: 3000,
|
|
312
|
+
minPrice: '0.95',
|
|
313
|
+
maxPrice: '1.05',
|
|
314
|
+
amount0Desired: '100',
|
|
315
|
+
amount1Desired: '100'
|
|
316
|
+
});
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
#### New Behavior (v3.33.0+) - REQUIRED
|
|
320
|
+
|
|
321
|
+
All tokens must use **pipe-delimited** (`|`) or **dollar-delimited** (`$`) format:
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
// ✅ REQUIRED FORMAT (v3.33.0+)
|
|
325
|
+
await sdk.addSwapLiquidityByPrice({
|
|
326
|
+
token0: 'GALA|Unit|none|none', // Delimited format
|
|
327
|
+
token1: 'GUSDC|Unit|none|none', // Delimited format
|
|
328
|
+
fee: 3000,
|
|
329
|
+
minPrice: '0.95',
|
|
330
|
+
maxPrice: '1.05',
|
|
331
|
+
amount0Desired: '100',
|
|
332
|
+
amount1Desired: '100'
|
|
333
|
+
});
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
#### Format Options
|
|
337
|
+
|
|
338
|
+
**Pipe-Delimited (Recommended):**
|
|
339
|
+
```typescript
|
|
340
|
+
'GALA|Unit|none|none'
|
|
341
|
+
'GUSDC|Unit|none|none'
|
|
342
|
+
'MYTOKEN|Unit|none|none'
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
**Dollar-Delimited (Alternative):**
|
|
346
|
+
```typescript
|
|
347
|
+
'GALA$Unit$none$none'
|
|
348
|
+
'GUSDC$Unit$none$none'
|
|
349
|
+
'MYTOKEN$Unit$none$none'
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
#### Migration Checklist
|
|
353
|
+
|
|
354
|
+
- [ ] Search codebase for plain token strings: `'GALA'`, `'GUSDC'`, etc.
|
|
355
|
+
- [ ] Replace with delimited format: `'GALA|Unit|none|none'`, `'GUSDC|Unit|none|none'`
|
|
356
|
+
- [ ] Update all SDK method calls that pass token parameters
|
|
357
|
+
- [ ] Test thoroughly - TypeScript strict mode will catch most issues
|
|
358
|
+
- [ ] Update internal token handling code
|
|
359
|
+
|
|
360
|
+
#### Affected Methods
|
|
361
|
+
|
|
362
|
+
The following methods now require delimited token format:
|
|
363
|
+
- `getSwapQuoteExactInput(token0, token1, amount)`
|
|
364
|
+
- `getSwapQuoteExactOutput(token0, token1, amount)`
|
|
365
|
+
- `executeSwap(token0, token1, ...)`
|
|
366
|
+
- `addSwapLiquidityByPrice({token0, token1, ...})`
|
|
367
|
+
- `addSwapLiquidityByTicks({token0, token1, ...})`
|
|
368
|
+
- `removeSwapLiquidity({token0, token1, ...})`
|
|
369
|
+
- `getSwapPoolInfo(token0, token1)`
|
|
370
|
+
|
|
371
|
+
#### Security Rationale
|
|
372
|
+
|
|
373
|
+
This breaking change enforces **strict token format validation** to:
|
|
374
|
+
- ✅ **Prevent injection attacks** via token string manipulation
|
|
375
|
+
- ✅ **Ensure deterministic parsing** with no ambiguous fallbacks
|
|
376
|
+
- ✅ **Eliminate security gaps** from loose string handling
|
|
377
|
+
- ✅ **Force explicit token specification** with full TokenClassKey structure
|
|
378
|
+
|
|
379
|
+
Plain string support created a dangerous "escape hatch" where ambiguous token identifiers could be accepted. v3.33.0 eliminates this by requiring all tokens be properly delimited.
|
|
380
|
+
|
|
381
|
+
## Upgrading to v4.0.0
|
|
382
|
+
|
|
383
|
+
### Breaking Changes: Removed Deprecated Methods
|
|
384
|
+
|
|
385
|
+
**v4.0.0 removes one deprecated method** that was superseded in v3.22.7. This is a clean removal with **minimal migration effort** - most users will not be affected.
|
|
386
|
+
|
|
387
|
+
#### Removed Method: `fetchLaunchpadTokenSpotPrice()`
|
|
388
|
+
|
|
389
|
+
This method was deprecated in v3.22.7 in favor of the more flexible `fetchTokenPrice()` method.
|
|
390
|
+
|
|
391
|
+
**Old Code (v3.35.x and below) - NO LONGER WORKS:**
|
|
392
|
+
```typescript
|
|
393
|
+
// ❌ REMOVED in v4.0.0
|
|
394
|
+
const price = await sdk.fetchLaunchpadTokenSpotPrice('anime');
|
|
395
|
+
console.log(`Price: ${price} USD`);
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
**New Code (v4.0.0+) - REQUIRED:**
|
|
399
|
+
```typescript
|
|
400
|
+
// ✅ REQUIRED - Works for both launchpad and DEX tokens
|
|
401
|
+
const price = await sdk.fetchTokenPrice('anime');
|
|
402
|
+
console.log(`Price: ${price} USD`);
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
#### Why This Change?
|
|
406
|
+
|
|
407
|
+
The new `fetchTokenPrice()` method:
|
|
408
|
+
- ✅ **Unified pricing** - Works for both launchpad tokens and DEX-graduated tokens
|
|
409
|
+
- ✅ **Automatic routing** - Detects token type and fetches from correct backend
|
|
410
|
+
- ✅ **Better performance** - Single method instead of specialized variants
|
|
411
|
+
- ✅ **Cleaner API** - Less method duplication in SDK
|
|
412
|
+
|
|
413
|
+
#### Migration Checklist
|
|
414
|
+
|
|
415
|
+
- [ ] Search codebase for `fetchLaunchpadTokenSpotPrice(`
|
|
416
|
+
- [ ] Replace all occurrences with `fetchTokenPrice(`
|
|
417
|
+
- [ ] Test with both launchpad tokens (e.g., `'anime'`) and DEX tokens
|
|
418
|
+
- [ ] Verify price results haven't changed (same calculation logic)
|
|
419
|
+
|
|
420
|
+
#### Impact Assessment
|
|
421
|
+
|
|
422
|
+
**Affected Users:**
|
|
423
|
+
- ⚠️ **Only if you explicitly called** `fetchLaunchpadTokenSpotPrice()`
|
|
424
|
+
- ✅ **Not affected if you** used `fetchTokenPrice()` or `fetchTokenSpotPrice()` methods
|
|
425
|
+
- ✅ **Not affected if you** never queried token prices
|
|
426
|
+
|
|
427
|
+
**Migration Effort:**
|
|
428
|
+
- ⏱️ **5 minutes** - Simple find/replace across codebase
|
|
429
|
+
- ⚙️ **Zero logic changes** - Functionality remains identical
|
|
430
|
+
- 🎯 **Low risk** - Price calculation algorithm unchanged
|
|
431
|
+
|
|
432
|
+
### New Features: Service Clients Documentation
|
|
433
|
+
|
|
434
|
+
v4.0.0 adds internal service client documentation for advanced users who need direct access to underlying blockchain services.
|
|
435
|
+
|
|
436
|
+
```typescript
|
|
437
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
438
|
+
|
|
439
|
+
const sdk = createLaunchpadSDK({
|
|
440
|
+
wallet: 'your-private-key'
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
// Advanced: Direct access to DEX Backend API
|
|
444
|
+
// Use case: Custom swap parameters or debugging
|
|
445
|
+
const quote = await sdk.dexBackendClient.querySwapQuote({
|
|
446
|
+
orderedTokens: [...],
|
|
447
|
+
zeroForOne: false,
|
|
448
|
+
inputAmount: '10',
|
|
449
|
+
// ... additional parameters
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
// Advanced: Direct access to GalaChain Gateway
|
|
453
|
+
// Use case: Custom transaction building
|
|
454
|
+
const result = await sdk.galaChainGatewayClient.callContract({
|
|
455
|
+
address: 'contract-address',
|
|
456
|
+
method: 'transfer',
|
|
457
|
+
// ... parameters
|
|
458
|
+
});
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
**⚠️ Important:** Service clients are internal implementation details. For standard operations, always use public SDK methods:
|
|
462
|
+
- ✅ Use `sdk.buy()` instead of `sdk.galaChainGatewayClient`
|
|
463
|
+
- ✅ Use `sdk.executeSwap()` instead of `sdk.dexBackendClient`
|
|
464
|
+
- ✅ These public methods provide better error handling and validation
|
|
465
|
+
|
|
466
|
+
For detailed service client documentation, see [docs/API-REFERENCE.md#service-clients](./docs/API-REFERENCE.md#service-clients).
|
|
467
|
+
|
|
468
|
+
### Migration Summary
|
|
469
|
+
|
|
470
|
+
**For Most Users:** Nothing to do! v4.0.0 is backward compatible except for the removal of `fetchLaunchpadTokenSpotPrice()`.
|
|
471
|
+
|
|
472
|
+
**If You Used `fetchLaunchpadTokenSpotPrice()`:** Replace with `fetchTokenPrice()` - identical functionality, better flexibility.
|
|
473
|
+
|
|
474
|
+
**If You Need Service Client Access:** They're now documented and available for advanced use cases, but use public SDK methods when possible.
|
|
475
|
+
|
|
295
476
|
## DEX Pool Discovery & Analysis
|
|
296
477
|
|
|
297
478
|
### Overview
|
|
@@ -1847,7 +2028,7 @@ getSwapPoolInfo(tokenA, tokenB): Promise<PoolInfo>
|
|
|
1847
2028
|
```
|
|
1848
2029
|
|
|
1849
2030
|
**Key Features:**
|
|
1850
|
-
- ✅ **
|
|
2031
|
+
- ✅ **Strict token format enforcement** (v3.33.0+): All tokens require delimited format (`'GALA|Unit|none|none'` or `'GALA$Unit$none$none'`)
|
|
1851
2032
|
- ✅ **Quote pattern**: Always get quote before executing swap for accurate slippage calculations
|
|
1852
2033
|
- ✅ **Unified WebSocket**: Real-time transaction monitoring via shared LaunchpadSDK WebSocket connection
|
|
1853
2034
|
- ✅ **Environment alignment**: Automatic STAGE/PROD configuration matching
|
|
@@ -2071,6 +2252,54 @@ const testSDK = createTestLaunchpadSDK({
|
|
|
2071
2252
|
});
|
|
2072
2253
|
```
|
|
2073
2254
|
|
|
2255
|
+
### **Position Filter Utilities**
|
|
2256
|
+
|
|
2257
|
+
Helpers for organizing and filtering liquidity positions by various criteria:
|
|
2258
|
+
|
|
2259
|
+
```typescript
|
|
2260
|
+
import {
|
|
2261
|
+
filterByLiquidity, // Remove positions with zero liquidity
|
|
2262
|
+
filterByMinLiquidity, // Keep positions >= threshold
|
|
2263
|
+
filterByTokenPair, // Match specific token pair
|
|
2264
|
+
filterByToken, // Find positions containing a token
|
|
2265
|
+
filterByFeeTier, // Filter by fee tier (500, 3000, 10000)
|
|
2266
|
+
filterByPoolKey, // Match specific pool (token pair + fee)
|
|
2267
|
+
sortByLiquidity, // Sort positions by liquidity amount
|
|
2268
|
+
groupByTokenPair, // Group by "TOKEN0/TOKEN1"
|
|
2269
|
+
groupByFeeTier, // Group by fee tier
|
|
2270
|
+
groupByPoolKey, // Group by "TOKEN0|TOKEN1|FEETIER"
|
|
2271
|
+
} from '@gala-chain/launchpad-sdk';
|
|
2272
|
+
|
|
2273
|
+
// Example: Find active GALA/GUSDC positions and sort by size
|
|
2274
|
+
const allPositions = await sdk.getAllSwapUserLiquidityPositions(address);
|
|
2275
|
+
const active = filterByLiquidity(allPositions); // Remove zero-liquidity
|
|
2276
|
+
const galaPositions = filterByTokenPair(active, 'GALA', 'GUSDC'); // GALA/GUSDC only
|
|
2277
|
+
const sorted = sortByLiquidity(galaPositions, 'desc'); // Largest first
|
|
2278
|
+
|
|
2279
|
+
// Group positions by token pair for portfolio analysis
|
|
2280
|
+
const grouped = groupByTokenPair(active);
|
|
2281
|
+
grouped.forEach((positions, pair) => {
|
|
2282
|
+
console.log(`${pair}: ${positions.length} positions`);
|
|
2283
|
+
});
|
|
2284
|
+
|
|
2285
|
+
// Find positions with significant liquidity
|
|
2286
|
+
const large = filterByMinLiquidity(active, '1000');
|
|
2287
|
+
|
|
2288
|
+
// Organize by pool (pair + fee tier) for advanced analysis
|
|
2289
|
+
const byPool = groupByPoolKey(active);
|
|
2290
|
+
byPool.forEach((positions, poolKey) => {
|
|
2291
|
+
console.log(`Pool ${poolKey}: ${positions.length} LPs`);
|
|
2292
|
+
});
|
|
2293
|
+
```
|
|
2294
|
+
|
|
2295
|
+
**Use Cases:**
|
|
2296
|
+
- Organize positions by token pair or pool
|
|
2297
|
+
- Filter for active positions (non-zero liquidity)
|
|
2298
|
+
- Find positions above minimum liquidity threshold
|
|
2299
|
+
- Analyze portfolio distribution by token or fee tier
|
|
2300
|
+
- Identify opportunities for fee collection
|
|
2301
|
+
- Locate positions in specific pools
|
|
2302
|
+
|
|
2074
2303
|
## Testing
|
|
2075
2304
|
|
|
2076
2305
|
```bash
|
|
@@ -2092,7 +2321,7 @@ npm run lint
|
|
|
2092
2321
|
- [SDK Method Reference](./SDK-METHOD-GRAPH.md) - Complete flat API reference
|
|
2093
2322
|
- [Clean Result Types Migration Guide](./docs/CLEAN_RESULT_TYPES_MIGRATION.md) - Migration guide for clean result types
|
|
2094
2323
|
- [Service Architecture Migration Guide](./docs/SERVICE_ARCHITECTURE_MIGRATION.md) - Guide for v3.1.0 service-based architecture
|
|
2095
|
-
- [API
|
|
2324
|
+
- [API Reference](./docs/API-REFERENCE.md) - Complete reference for all 72 SDK methods with examples
|
|
2096
2325
|
- [Examples](./examples/) - Code examples and demos
|
|
2097
2326
|
|
|
2098
2327
|
### GSwap Liquidity Operations
|
|
@@ -2103,24 +2332,202 @@ npm run lint
|
|
|
2103
2332
|
|
|
2104
2333
|
### Demo Scripts
|
|
2105
2334
|
|
|
2106
|
-
|
|
2335
|
+
The SDK includes 36 comprehensive demo scripts organized into logical categories for easy discovery and learning.
|
|
2336
|
+
|
|
2337
|
+
#### Organized Directory Structure
|
|
2338
|
+
|
|
2339
|
+
```
|
|
2340
|
+
examples/
|
|
2341
|
+
├── core/ # SDK fundamentals and authentication patterns
|
|
2342
|
+
├── liquidity/ # GalaSwap liquidity position management (9 demos)
|
|
2343
|
+
├── bonding-curve/ # Token bonding curve trading operations
|
|
2344
|
+
├── dex/ # DEX trading and pool discovery (6 demos)
|
|
2345
|
+
├── fees/ # Fee generation and collection workflows (5 demos)
|
|
2346
|
+
├── monitoring/ # Real-time event watching (2 demos)
|
|
2347
|
+
├── utilities/ # Balance checks, cache, token supply (5 demos)
|
|
2348
|
+
└── debug/ # Development and troubleshooting tools
|
|
2349
|
+
```
|
|
2350
|
+
|
|
2351
|
+
#### Quick Start Examples
|
|
2352
|
+
|
|
2353
|
+
**Core SDK Operations:**
|
|
2107
2354
|
```bash
|
|
2108
|
-
#
|
|
2109
|
-
npm run demo
|
|
2355
|
+
# Complete SDK feature demonstration
|
|
2356
|
+
npm run demo
|
|
2110
2357
|
|
|
2111
|
-
#
|
|
2112
|
-
npm run demo:
|
|
2358
|
+
# Read-only operations (no wallet required)
|
|
2359
|
+
npm run demo:read-only
|
|
2113
2360
|
|
|
2114
|
-
#
|
|
2115
|
-
npm run demo:
|
|
2361
|
+
# Authenticated operations (wallet required)
|
|
2362
|
+
npm run demo:authenticated
|
|
2363
|
+
|
|
2364
|
+
# Multi-wallet private key override pattern
|
|
2365
|
+
npm run demo:privatekey-override
|
|
2366
|
+
```
|
|
2367
|
+
|
|
2368
|
+
#### Liquidity Position Management (9 Demos)
|
|
2369
|
+
|
|
2370
|
+
Comprehensive liquidity provision workflows for GalaSwap DEX:
|
|
2371
|
+
|
|
2372
|
+
```bash
|
|
2373
|
+
# Interactive CLI for position management
|
|
2374
|
+
npm run demo:liquidity
|
|
2116
2375
|
|
|
2117
|
-
#
|
|
2118
|
-
npm run demo:liquidity
|
|
2376
|
+
# Run all 9 liquidity demos sequentially
|
|
2377
|
+
npm run demo:liquidity:all
|
|
2119
2378
|
|
|
2120
|
-
#
|
|
2121
|
-
npm run demo:liquidity:detailed
|
|
2379
|
+
# Individual demos
|
|
2380
|
+
npm run demo:liquidity:detailed # Detailed position lifecycle
|
|
2381
|
+
npm run demo:liquidity:ticks # Advanced tick-based positions
|
|
2382
|
+
npm run demo:liquidity:portfolio # Multi-position portfolio management
|
|
2383
|
+
npm run demo:liquidity:apr # APR calculation for LP positions
|
|
2384
|
+
npm run demo:liquidity:errors # Error handling patterns
|
|
2385
|
+
npm run demo:liquidity:fetch-all # Fetch all positions with pagination
|
|
2386
|
+
npm run demo:liquidity:positions-with-prices # Position pricing enrichment
|
|
2387
|
+
|
|
2388
|
+
# Complete roundtrip workflow (legacy, use orchestrator instead)
|
|
2389
|
+
npm run demo:dex:roundtrip
|
|
2390
|
+
```
|
|
2391
|
+
|
|
2392
|
+
**Orchestrator Pattern:**
|
|
2393
|
+
The liquidity orchestrator (`npm run demo:liquidity:all`) runs all demos with intelligent error handling:
|
|
2394
|
+
- Skip individual demos: `--skip=detailed,ticks`
|
|
2395
|
+
- Run specific demos only: `--only=portfolio,apr`
|
|
2396
|
+
- See all available demos: `npm run demo:liquidity:all --help`
|
|
2397
|
+
|
|
2398
|
+
#### Bonding Curve Trading (Launchpad Tokens)
|
|
2399
|
+
|
|
2400
|
+
Pre-graduation token trading on bonding curve pools:
|
|
2401
|
+
|
|
2402
|
+
```bash
|
|
2403
|
+
# Basic buy/sell operations with slippage protection
|
|
2404
|
+
npm run demo:trades
|
|
2405
|
+
```
|
|
2406
|
+
|
|
2407
|
+
**Bonding Curve Focus:**
|
|
2408
|
+
8 additional bonding curve demos are available through the orchestrator (in development):
|
|
2409
|
+
- Pool discovery and filtering
|
|
2410
|
+
- Price calculation methods
|
|
2411
|
+
- Graduation simulation
|
|
2412
|
+
- Multi-token analysis
|
|
2413
|
+
- Fee structure exploration
|
|
2414
|
+
- Slippage testing scenarios
|
|
2415
|
+
|
|
2416
|
+
#### DEX Trading Operations (6 Demos)
|
|
2417
|
+
|
|
2418
|
+
Graduated token trading on GalaSwap DEX with full liquidity pool support:
|
|
2419
|
+
|
|
2420
|
+
```bash
|
|
2421
|
+
# DEX swap workflow (quote → execute → confirm)
|
|
2422
|
+
npm run demo:dex
|
|
2423
|
+
|
|
2424
|
+
# Pool discovery and metrics
|
|
2425
|
+
npm run demo:dex:pools
|
|
2426
|
+
|
|
2427
|
+
# Pool pricing and TVL analysis
|
|
2428
|
+
npm run demo:dex:pricing
|
|
2429
|
+
|
|
2430
|
+
# Quote comparison (exact input vs exact output)
|
|
2431
|
+
npm run demo:dex:quotes
|
|
2432
|
+
|
|
2433
|
+
# Complete swap roundtrip (buy → sell → verify)
|
|
2434
|
+
npm run demo:roundtrip:swap
|
|
2122
2435
|
```
|
|
2123
2436
|
|
|
2437
|
+
#### Fee Generation and Collection (5 Demos)
|
|
2438
|
+
|
|
2439
|
+
Liquidity provider fee workflows with multi-wallet testing:
|
|
2440
|
+
|
|
2441
|
+
```bash
|
|
2442
|
+
# Basic fee generation and collection
|
|
2443
|
+
npm run demo:fees
|
|
2444
|
+
|
|
2445
|
+
# High-volume trading fee accumulation
|
|
2446
|
+
npm run demo:fees:high-volume
|
|
2447
|
+
|
|
2448
|
+
# Complete fee lifecycle test suite
|
|
2449
|
+
npm run demo:fees:test
|
|
2450
|
+
|
|
2451
|
+
# Trade and collect fees in single workflow
|
|
2452
|
+
npm run demo:fees:trade-collect
|
|
2453
|
+
```
|
|
2454
|
+
|
|
2455
|
+
**Note:** `demo-multi-wallet-fee-generation.ts` is available but not exposed in npm scripts (advanced usage).
|
|
2456
|
+
|
|
2457
|
+
#### Real-Time Monitoring (2 Demos)
|
|
2458
|
+
|
|
2459
|
+
WebSocket-based event watchers for pool and token creation:
|
|
2460
|
+
|
|
2461
|
+
```bash
|
|
2462
|
+
# Watch for new DEX pool creation
|
|
2463
|
+
npm run demo:watch
|
|
2464
|
+
|
|
2465
|
+
# Watch for new launchpad token launches
|
|
2466
|
+
npm run demo:watch:tokens
|
|
2467
|
+
```
|
|
2468
|
+
|
|
2469
|
+
#### Utility Operations (5 Demos)
|
|
2470
|
+
|
|
2471
|
+
Balance queries, caching, and token supply information:
|
|
2472
|
+
|
|
2473
|
+
```bash
|
|
2474
|
+
# Metadata cache warming and performance testing
|
|
2475
|
+
npm run demo:cache
|
|
2476
|
+
|
|
2477
|
+
# Token supply metrics from GalaChain
|
|
2478
|
+
npm run demo:token-supply
|
|
2479
|
+
```
|
|
2480
|
+
|
|
2481
|
+
**Additional utilities:**
|
|
2482
|
+
- `balances.ts` - Multi-token balance queries
|
|
2483
|
+
- `balance.ts` - Single token balance check
|
|
2484
|
+
- `price-history.ts` - Historical price data (Node.js only)
|
|
2485
|
+
|
|
2486
|
+
#### Debug and Development Tools
|
|
2487
|
+
|
|
2488
|
+
Advanced troubleshooting and environment testing:
|
|
2489
|
+
|
|
2490
|
+
```bash
|
|
2491
|
+
# Environment alignment verification
|
|
2492
|
+
tsx examples/debug/test-env-alignment.ts
|
|
2493
|
+
|
|
2494
|
+
# Slot0 data debugging
|
|
2495
|
+
tsx examples/debug/debug-getslot0-test.ts
|
|
2496
|
+
|
|
2497
|
+
# DEX simulation with monkey patching
|
|
2498
|
+
tsx examples/debug/demo-dex-monkey-patch-simulation.ts
|
|
2499
|
+
```
|
|
2500
|
+
|
|
2501
|
+
#### Demo Statistics
|
|
2502
|
+
|
|
2503
|
+
- **Total Demos:** 36 working examples
|
|
2504
|
+
- **npm Scripts:** 25 convenient shortcuts
|
|
2505
|
+
- **Categories:** 8 organized directories
|
|
2506
|
+
- **Coverage:** All major SDK features demonstrated
|
|
2507
|
+
|
|
2508
|
+
#### Recommended Learning Path
|
|
2509
|
+
|
|
2510
|
+
1. **Start Here:** `npm run demo` - Complete SDK overview
|
|
2511
|
+
2. **Liquidity Basics:** `npm run demo:liquidity` - Interactive CLI
|
|
2512
|
+
3. **DEX Trading:** `npm run demo:dex` - Swap workflow
|
|
2513
|
+
4. **Fee Management:** `npm run demo:fees` - LP fee collection
|
|
2514
|
+
5. **Advanced:** Explore individual demos by category
|
|
2515
|
+
|
|
2516
|
+
#### Migration Notes
|
|
2517
|
+
|
|
2518
|
+
**Removed Scripts (v3.32.0+):**
|
|
2519
|
+
- `demo:liquidity:simple` - Merged into `demo:liquidity`
|
|
2520
|
+
- `demo:liquidity:workflow` - Replaced by orchestrator pattern
|
|
2521
|
+
- `demo:dex:swap` - Renamed to `demo:dex` for consistency
|
|
2522
|
+
|
|
2523
|
+
**New in v3.32.0+:**
|
|
2524
|
+
- Organized directory structure with 8 categories
|
|
2525
|
+
- Bonding curve orchestrator (in development)
|
|
2526
|
+
- Fee demo npm scripts now exposed
|
|
2527
|
+
- Symmetry: Both bonding-curve and dex have pool discovery demos
|
|
2528
|
+
|
|
2529
|
+
For detailed migration guide, see [docs/DEMO_MIGRATION_GUIDE.md](./docs/DEMO_MIGRATION_GUIDE.md).
|
|
2530
|
+
|
|
2124
2531
|
## Architecture
|
|
2125
2532
|
|
|
2126
2533
|
The SDK uses a **service-based architecture** with backend-aligned services:
|