@gala-chain/launchpad-sdk 3.31.2 → 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/constants/version.generated.d.ts +1 -1
- package/dist/constants/version.generated.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/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/GSwapService.d.ts +468 -38
- 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/PoolStateManager.d.ts +176 -0
- package/dist/services/PoolStateManager.d.ts.map +1 -0
- package/dist/services/SignatureService.d.ts +13 -35
- package/dist/services/SignatureService.d.ts.map +1 -1
- package/dist/services/WebSocketService.d.ts +98 -0
- 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/auto-pagination.d.ts +74 -0
- package/dist/utils/auto-pagination.d.ts.map +1 -1
- package/dist/utils/bignumber-helpers.d.ts +75 -3
- package/dist/utils/bignumber-helpers.d.ts.map +1 -1
- 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 +10 -3
- 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/transfer-validation.d.ts.map +1 -1
- package/package.json +36 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommentService.d.ts","sourceRoot":"","sources":["../../src/services/CommentService.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAS3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAEL,cAAc,EAKf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAGnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,cAAe,SAAQ,WAAW;IAG3C,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAD5B,IAAI,EAAE,UAAU,EACC,WAAW,EAAE,WAAW,EACzC,SAAS,GAAE,OAAe;IAK5B;;;;;;;;;;OAUG;IACG,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"CommentService.d.ts","sourceRoot":"","sources":["../../src/services/CommentService.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAS3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAEL,cAAc,EAKf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAGnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,cAAe,SAAQ,WAAW;IAG3C,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAD5B,IAAI,EAAE,UAAU,EACC,WAAW,EAAE,WAAW,EACzC,SAAS,GAAE,OAAe;IAK5B;;;;;;;;;;OAUG;IACG,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,CAAC;IAqF3E;;;;;;;;;;OAUG;IACG,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CAgE9D"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DEX Backend API Client
|
|
3
|
+
*
|
|
4
|
+
* HTTP client for DEX Backend API endpoints using injected HttpClient.
|
|
5
|
+
* Ensures proper authentication and error handling via interceptors.
|
|
6
|
+
* Fully typed API interactions with zero `any` types.
|
|
7
|
+
*/
|
|
8
|
+
import { HttpClient } from '../utils/http';
|
|
9
|
+
import { DexBackendUserAssetsResponse } from '../types/galachain-api.types';
|
|
10
|
+
/**
|
|
11
|
+
* DEX Backend Client configuration
|
|
12
|
+
*/
|
|
13
|
+
export interface DexBackendClientConfig {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* HTTP client for DEX Backend API using injected HttpClient for proper authentication
|
|
19
|
+
*/
|
|
20
|
+
export declare class DexBackendClient {
|
|
21
|
+
private http;
|
|
22
|
+
constructor(http: HttpClient);
|
|
23
|
+
/**
|
|
24
|
+
* Get user assets from DEX Backend
|
|
25
|
+
* Endpoint: GET /user/assets
|
|
26
|
+
*
|
|
27
|
+
* Returns all tokens in user's wallet on the DEX
|
|
28
|
+
*
|
|
29
|
+
* @param walletAddress - User's wallet address
|
|
30
|
+
* @param limit - Optional limit on results (default: 20)
|
|
31
|
+
* @param offset - Optional offset for pagination (internally converted to page)
|
|
32
|
+
* @returns List of user's assets with balances
|
|
33
|
+
* @throws ApiError if request fails
|
|
34
|
+
*/
|
|
35
|
+
getUserAssets(walletAddress: string, limit?: number, offset?: number): Promise<DexBackendUserAssetsResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* Handle errors from HttpClient or validation
|
|
38
|
+
* Converts various error types to ApiError
|
|
39
|
+
*
|
|
40
|
+
* @param error - Error from HttpClient or validation
|
|
41
|
+
* @param context - Method name for better error messages
|
|
42
|
+
* @returns ApiError with context
|
|
43
|
+
*/
|
|
44
|
+
private handleError;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=DexBackendClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DexBackendClient.d.ts","sourceRoot":"","sources":["../../src/services/DexBackendClient.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAEL,4BAA4B,EAE7B,MAAM,8BAA8B,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,IAAI,CAAa;gBAEb,IAAI,EAAE,UAAU;IAI5B;;;;;;;;;;;OAWG;IACG,aAAa,CACjB,aAAa,EAAE,MAAM,EACrB,KAAK,GAAE,MAAW,EAClB,MAAM,GAAE,MAAU,GACjB,OAAO,CAAC,4BAA4B,CAAC;IAoGxC;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW;CA6BpB"}
|
|
@@ -2,18 +2,19 @@
|
|
|
2
2
|
* DEX Pool Discovery Service
|
|
3
3
|
*
|
|
4
4
|
* Service for querying and exploring GalaSwap DEX liquidity pools
|
|
5
|
-
* with pagination, filtering, and
|
|
5
|
+
* with pagination, filtering, sorting, and quote-based pricing enrichment.
|
|
6
6
|
*
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*/
|
|
9
9
|
import { BaseService } from './BaseService';
|
|
10
10
|
import type { HttpClient } from '../utils/http';
|
|
11
11
|
import type { DexPoolsResult, FetchDexPoolsOptions } from '../types/dex-pool.dto';
|
|
12
|
+
import type { GSwapService } from './GSwapService';
|
|
12
13
|
/**
|
|
13
14
|
* Service for fetching and exploring DEX pools on GalaSwap
|
|
14
15
|
*
|
|
15
|
-
* Handles pagination, filtering, and
|
|
16
|
-
* across all graduated tokens and base tokens.
|
|
16
|
+
* Handles pagination, filtering, sorting, and optional quote-based pricing enrichment
|
|
17
|
+
* of liquidity pools across all graduated tokens and base tokens.
|
|
17
18
|
*
|
|
18
19
|
* @category GSwap
|
|
19
20
|
* @since 3.28.0
|
|
@@ -21,14 +22,47 @@ import type { DexPoolsResult, FetchDexPoolsOptions } from '../types/dex-pool.dto
|
|
|
21
22
|
export declare class DexPoolService extends BaseService {
|
|
22
23
|
/** Base URL for DEX backend API */
|
|
23
24
|
private readonly dexBackendBaseUrl;
|
|
25
|
+
/** GSwap service for quote-based pricing enrichment */
|
|
26
|
+
private gswapService;
|
|
27
|
+
/** Concurrency level for parallel pricing requests */
|
|
28
|
+
private pricingConcurrency;
|
|
24
29
|
/**
|
|
25
30
|
* Create a new DexPoolService instance
|
|
26
31
|
*
|
|
27
32
|
* @param http HttpClient for making API requests
|
|
28
33
|
* @param dexBackendBaseUrl Base URL for DEX backend API
|
|
34
|
+
* @param gswapService Optional GSwap service for pricing enrichment
|
|
35
|
+
* @param pricingConcurrency Concurrency level for parallel pricing requests (default: 5)
|
|
29
36
|
* @param debugMode Enable debug logging
|
|
30
37
|
*/
|
|
31
|
-
constructor(http: HttpClient, dexBackendBaseUrl: string, debugMode?: boolean);
|
|
38
|
+
constructor(http: HttpClient, dexBackendBaseUrl: string, gswapService?: GSwapService | undefined, pricingConcurrency?: number, debugMode?: boolean);
|
|
39
|
+
/**
|
|
40
|
+
* Set GSwap service for pricing enrichment
|
|
41
|
+
*
|
|
42
|
+
* @param service GSwap service instance
|
|
43
|
+
*/
|
|
44
|
+
setGSwapService(service: GSwapService): void;
|
|
45
|
+
/**
|
|
46
|
+
* Set concurrency level for pricing requests
|
|
47
|
+
*
|
|
48
|
+
* @param concurrency Number of concurrent pricing requests
|
|
49
|
+
*/
|
|
50
|
+
setPricingConcurrency(concurrency: number): void;
|
|
51
|
+
/**
|
|
52
|
+
* Enrich pools with quote-based pricing
|
|
53
|
+
*
|
|
54
|
+
* Uses parallel requests with concurrency control to price each pool's tokens
|
|
55
|
+
* against GUSDC (as stable reference) via `getSwapQuoteExactInput()`.
|
|
56
|
+
*
|
|
57
|
+
* Failed pricing requests are caught and logged - pools without prices are still
|
|
58
|
+
* included with all other metrics intact (graceful degradation).
|
|
59
|
+
*
|
|
60
|
+
* @param pools Pools to enrich with pricing
|
|
61
|
+
* @returns Promise resolving to pools with token0Price and token1Price populated
|
|
62
|
+
*
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
private enrichPoolsWithPricing;
|
|
32
66
|
/**
|
|
33
67
|
* Fetch DEX pools with pagination and filtering
|
|
34
68
|
*
|
|
@@ -36,6 +70,7 @@ export declare class DexPoolService extends BaseService {
|
|
|
36
70
|
* - Pagination (max 20 per page)
|
|
37
71
|
* - Sorting by TVL, 30-day volume, or 1-day volume
|
|
38
72
|
* - Search filtering by token symbols
|
|
73
|
+
* - Optional quote-based pricing enrichment via `withPrices` option
|
|
39
74
|
*
|
|
40
75
|
* @param options Fetch options (all optional)
|
|
41
76
|
* @returns Promise resolving to paginated pool results
|
|
@@ -45,16 +80,19 @@ export declare class DexPoolService extends BaseService {
|
|
|
45
80
|
*
|
|
46
81
|
* @example
|
|
47
82
|
* ```typescript
|
|
48
|
-
* // Fetch top 10 pools by volume
|
|
83
|
+
* // Fetch top 10 pools by volume with pricing
|
|
49
84
|
* const result = await dexPoolService.fetchDexPools({
|
|
50
85
|
* sortBy: 'volume1d',
|
|
51
86
|
* sortOrder: 'desc',
|
|
52
87
|
* limit: 10,
|
|
53
|
-
* page: 1
|
|
88
|
+
* page: 1,
|
|
89
|
+
* withPrices: true
|
|
54
90
|
* });
|
|
55
91
|
*
|
|
56
92
|
* console.log(`Found ${result.total} total pools`);
|
|
57
|
-
*
|
|
93
|
+
* result.pools.forEach(pool => {
|
|
94
|
+
* console.log(`${pool.poolName}: ${pool.token0Price} / ${pool.token1Price}`);
|
|
95
|
+
* });
|
|
58
96
|
* ```
|
|
59
97
|
*
|
|
60
98
|
* @since 3.28.0
|
|
@@ -67,24 +105,28 @@ export declare class DexPoolService extends BaseService {
|
|
|
67
105
|
* all available DEX pools. Uses maximum page size (20) for efficiency.
|
|
68
106
|
*
|
|
69
107
|
* This is useful when you need complete pool data regardless of result size.
|
|
70
|
-
* For large result sets,
|
|
108
|
+
* For large result sets with pricing, note that the operation may take significant time
|
|
109
|
+
* since all pools must be priced. Consider using fetchDexPools() with explicit pagination
|
|
110
|
+
* and batching if you need to process pricing incrementally.
|
|
71
111
|
*
|
|
72
112
|
* @param options Fetch options (no pagination fields)
|
|
73
113
|
* @returns Promise resolving to all pools with flattened pagination
|
|
74
114
|
*
|
|
75
115
|
* @example
|
|
76
116
|
* ```typescript
|
|
77
|
-
* // Fetch all pools sorted by TVL
|
|
117
|
+
* // Fetch all pools sorted by TVL with pricing
|
|
78
118
|
* const allPools = await dexPoolService.fetchAllDexPools({
|
|
79
119
|
* sortBy: 'tvl',
|
|
80
|
-
* sortOrder: 'desc'
|
|
120
|
+
* sortOrder: 'desc',
|
|
121
|
+
* withPrices: true // Enable pricing for all pools
|
|
81
122
|
* });
|
|
82
123
|
*
|
|
83
124
|
* console.log(`Total pools: ${allPools.total}`);
|
|
125
|
+
* console.log(`Priced pools: ${allPools.pools.filter(p => p.token0Price).length}`);
|
|
84
126
|
*
|
|
85
|
-
* // Find top GALA pools
|
|
127
|
+
* // Find top GALA pools with prices
|
|
86
128
|
* const galaPools = allPools.pools
|
|
87
|
-
* .filter(p => p.poolName.includes('GALA'))
|
|
129
|
+
* .filter(p => p.poolName.includes('GALA') && p.token0Price)
|
|
88
130
|
* .slice(0, 10);
|
|
89
131
|
* ```
|
|
90
132
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DexPoolService.d.ts","sourceRoot":"","sources":["../../src/services/DexPoolService.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,
|
|
1
|
+
{"version":3,"file":"DexPoolService.d.ts","sourceRoot":"","sources":["../../src/services/DexPoolService.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EAErB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;;;;;;;GAQG;AACH,qBAAa,cAAe,SAAQ,WAAW;IAC7C,mCAAmC;IACnC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAE3C,uDAAuD;IACvD,OAAO,CAAC,YAAY,CAA2B;IAE/C,sDAAsD;IACtD,OAAO,CAAC,kBAAkB,CAAa;IAEvC;;;;;;;;OAQG;gBAED,IAAI,EAAE,UAAU,EAChB,iBAAiB,EAAE,MAAM,EACzB,YAAY,GAAE,YAAY,GAAG,SAAqB,EAClD,kBAAkB,GAAE,MAAU,EAC9B,SAAS,GAAE,OAAe;IAQ5B;;;;OAIG;IACH,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAI5C;;;;OAIG;IACH,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAKhD;;;;;;;;;;;;;OAaG;YACW,sBAAsB;IAoHpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACG,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,cAAc,CAAC;IAgFhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACG,gBAAgB,CACpB,OAAO,GAAE,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,OAAO,CAAM,GACzD,OAAO,CAAC,cAAc,CAAC;CAmC3B"}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DEX Quote Service
|
|
3
|
+
*
|
|
4
|
+
* Handles offline and online DEX quote calculations using composite pool data.
|
|
5
|
+
* Provides three calculation modes:
|
|
6
|
+
* - LOCAL: Client-side calculation (instant, no network)
|
|
7
|
+
* - EXTERNAL: GalaChain network calculation (real-time, slower)
|
|
8
|
+
* - HYBRID: Local with external validation (best of both)
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
import { BaseService } from './BaseService';
|
|
13
|
+
import type { HttpClient } from '../utils/http';
|
|
14
|
+
import type { FetchCompositePoolDataOptions, CompositePoolDataResult, CalculateDexPoolQuoteOptions, DexPoolQuoteResult } from '../types/composite-pool.dto';
|
|
15
|
+
/**
|
|
16
|
+
* Concurrency constant for parallel composite pool fetching
|
|
17
|
+
*/
|
|
18
|
+
export declare const COMPOSITE_POOL_FETCH_CONCURRENCY = 5;
|
|
19
|
+
/**
|
|
20
|
+
* Service for DEX quote calculations with composite pool data
|
|
21
|
+
*
|
|
22
|
+
* Provides offline and online quote calculations using composite pool state from GalaChain.
|
|
23
|
+
* Handles dependency version conflicts between @gala-chain/api and @gala-chain/dex through
|
|
24
|
+
* strategic type assertions validated by BigNumber.js runtime conversions.
|
|
25
|
+
*
|
|
26
|
+
* ## Dependency Version Management
|
|
27
|
+
*
|
|
28
|
+
* **Version Conflicts:**
|
|
29
|
+
* - `@gala-chain/api`: Used for TokenBalance class (imported from this package)
|
|
30
|
+
* - `@gala-chain/dex`: Used for Pool, TickData, CompositePoolDto classes
|
|
31
|
+
* - **Issue**: SDK may depend on different versions of @gala-chain/api than @gala-chain/dex
|
|
32
|
+
* - **Solution**: Type assertions with runtime validation via BigNumber.js
|
|
33
|
+
*
|
|
34
|
+
* **Current Dependency Stack:**
|
|
35
|
+
* ```
|
|
36
|
+
* SDK
|
|
37
|
+
* ├── @gala-chain/api@X.Y.Z (TokenBalance)
|
|
38
|
+
* ├── @gala-chain/dex@A.B.C (Pool, TickData, CompositePoolDto)
|
|
39
|
+
* ├── @gala-chain/connect (GalaChain client)
|
|
40
|
+
* └── axios (HTTP requests)
|
|
41
|
+
*
|
|
42
|
+
* Potential Conflict: @gala-chain/dex depends on different @gala-chain/api version
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* **Type Assertion Patterns:**
|
|
46
|
+
* 1. **TokenBalance Construction** - `new TokenBalance(data as any)`
|
|
47
|
+
* - Reason: TokenBalance class definition may differ between versions
|
|
48
|
+
* - Validation: Constructor throws on invalid data
|
|
49
|
+
*
|
|
50
|
+
* 2. **Property Assignment** - `(instance as any).propertyName = value`
|
|
51
|
+
* - Reason: TickData constructor only accepts 2 params; properties set after
|
|
52
|
+
* - Validation: All assignments use BigNumber.js conversion or primitives
|
|
53
|
+
*
|
|
54
|
+
* 3. **CompositePoolDto Construction** - Passing TokenBalance instances
|
|
55
|
+
* - Reason: TokenBalance types may not match exactly between versions
|
|
56
|
+
* - Validation: BigNumber.js validates all numeric conversions
|
|
57
|
+
*
|
|
58
|
+
* **Risk Mitigation:**
|
|
59
|
+
* - ✓ BigNumber.js throws immediately on invalid numbers (NaN, non-numeric strings)
|
|
60
|
+
* - ✓ Pool, TickData, TokenBalance constructors throw on structural errors
|
|
61
|
+
* - ✓ All numeric fields converted to BigNumber before use
|
|
62
|
+
* - ✓ String-to-number conversions validated at instantiation time
|
|
63
|
+
*
|
|
64
|
+
* @category GSwap
|
|
65
|
+
* @since 3.32.0
|
|
66
|
+
* @architecture Uses composition and dependency injection for testability
|
|
67
|
+
* @note Type assertions are isolated to conversion functions; business logic uses proper types
|
|
68
|
+
*/
|
|
69
|
+
export declare class DexQuoteService extends BaseService {
|
|
70
|
+
private readonly galaChainBaseUrl;
|
|
71
|
+
private readonly networkTimeout;
|
|
72
|
+
private compositePoolFetchConcurrency;
|
|
73
|
+
/**
|
|
74
|
+
* Initialize DEX Quote Service
|
|
75
|
+
*
|
|
76
|
+
* @param http HttpClient for GalaChain requests
|
|
77
|
+
* @param galaChainBaseUrl Base URL for GalaChain gateway
|
|
78
|
+
* @param debugMode Enable debug logging
|
|
79
|
+
* @param networkTimeout Network timeout in milliseconds (default: 30000ms)
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* // Use default 30-second timeout
|
|
83
|
+
* const service = new DexQuoteService(http, galaChainBaseUrl, false);
|
|
84
|
+
*
|
|
85
|
+
* // Use custom 60-second timeout for rate-limited APIs
|
|
86
|
+
* const service = new DexQuoteService(http, galaChainBaseUrl, false, 60000);
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
constructor(http: HttpClient, galaChainBaseUrl: string, debugMode?: boolean, networkTimeout?: number);
|
|
90
|
+
/**
|
|
91
|
+
* Validate input parameters for fetchCompositePoolData
|
|
92
|
+
*
|
|
93
|
+
* @private
|
|
94
|
+
* @param token0 First token in pipe-delimited format
|
|
95
|
+
* @param token1 Second token in pipe-delimited format
|
|
96
|
+
* @param fee Fee tier (500, 3000, or 10000)
|
|
97
|
+
* @throws DexQuoteError if validation fails
|
|
98
|
+
*/
|
|
99
|
+
private validateFetchCompositePoolDataInput;
|
|
100
|
+
/**
|
|
101
|
+
* Validate input parameters for quote calculation methods
|
|
102
|
+
*
|
|
103
|
+
* @private
|
|
104
|
+
* @param amount Amount to validate (should be positive numeric string)
|
|
105
|
+
* @throws DexQuoteError if validation fails
|
|
106
|
+
*/
|
|
107
|
+
private validateQuoteAmount;
|
|
108
|
+
/**
|
|
109
|
+
* Convert SDK TokenClassKey to DexTokenClassKey for @gala-chain/dex
|
|
110
|
+
*
|
|
111
|
+
* @private
|
|
112
|
+
* @param tokenKey SDK TokenClassKey
|
|
113
|
+
* @returns DexTokenClassKey for use with @gala-chain/dex
|
|
114
|
+
*/
|
|
115
|
+
private convertTokenClassKey;
|
|
116
|
+
/**
|
|
117
|
+
* Set concurrency level for parallel composite pool fetching
|
|
118
|
+
*
|
|
119
|
+
* Controls how many composite pool data requests can be in-flight simultaneously.
|
|
120
|
+
* Higher values fetch pools faster but use more network connections. Lower values
|
|
121
|
+
* use fewer connections but take longer to fetch multiple pools.
|
|
122
|
+
*
|
|
123
|
+
* **Default**: 5 concurrent requests
|
|
124
|
+
* **Valid Range**: 1-20 (values outside this range are clamped)
|
|
125
|
+
*
|
|
126
|
+
* @param concurrency Number of concurrent requests (automatically clamped to 1-20)
|
|
127
|
+
*
|
|
128
|
+
* @example Default usage
|
|
129
|
+
* ```typescript
|
|
130
|
+
* // Fetch 3 pools with default concurrency (5)
|
|
131
|
+
* const pools = await Promise.all([
|
|
132
|
+
* sdk.fetchCompositePoolData({ token0: 'GALA|Unit|none|none', token1: 'Token|Unit|BENE|client:123', fee: 3000 }),
|
|
133
|
+
* sdk.fetchCompositePoolData({ token0: 'GALA|Unit|none|none', token1: 'Token|Unit|USDC|eth:0x...', fee: 500 }),
|
|
134
|
+
* sdk.fetchCompositePoolData({ token0: 'Token|Unit|BENE|client:123', token1: 'Token|Unit|USDC|eth:0x...', fee: 3000 }),
|
|
135
|
+
* ]);
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* @example Increase concurrency for faster bulk fetching
|
|
139
|
+
* ```typescript
|
|
140
|
+
* // Optimize for fetching many pools (trading bot scenario)
|
|
141
|
+
* service.setCompositePoolFetchConcurrency(15);
|
|
142
|
+
*
|
|
143
|
+
* const pools = await Promise.all(
|
|
144
|
+
* tokenPairs.map(pair => sdk.fetchCompositePoolData(pair))
|
|
145
|
+
* );
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @example Decrease concurrency for rate-limited APIs
|
|
149
|
+
* ```typescript
|
|
150
|
+
* // Optimize for rate-limited GalaChain gateways
|
|
151
|
+
* service.setCompositePoolFetchConcurrency(2);
|
|
152
|
+
*
|
|
153
|
+
* // Fetch pools one-by-one (slow but respects rate limits)
|
|
154
|
+
* for (const pair of tokenPairs) {
|
|
155
|
+
* const composite = await sdk.fetchCompositePoolData(pair);
|
|
156
|
+
* processPool(composite);
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @example Reset to default
|
|
161
|
+
* ```typescript
|
|
162
|
+
* // Reset concurrency back to default (5)
|
|
163
|
+
* service.setCompositePoolFetchConcurrency(5);
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
setCompositePoolFetchConcurrency(concurrency: number): void;
|
|
167
|
+
/**
|
|
168
|
+
* Fetch composite pool data from GalaChain
|
|
169
|
+
*
|
|
170
|
+
* Retrieves complete pool state including:
|
|
171
|
+
* - Pool liquidity and price data
|
|
172
|
+
* - Tick data for liquidity calculations
|
|
173
|
+
* - Token balances and decimals
|
|
174
|
+
*
|
|
175
|
+
* @param options Composite pool fetch options (token0/token1 in pipe-delimited format)
|
|
176
|
+
* @returns Complete composite pool data for offline quote calculations
|
|
177
|
+
* @throws DexPoolNotFoundError if pool does not exist
|
|
178
|
+
* @throws DexQuoteError on API or conversion errors
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const compositePool = await sdk.fetchCompositePoolData({
|
|
183
|
+
* token0: 'GALA|Unit|none|none',
|
|
184
|
+
* token1: 'Token|Unit|BENE|client:123',
|
|
185
|
+
* fee: 3000 // 0.30%
|
|
186
|
+
* });
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
fetchCompositePoolData(options: FetchCompositePoolDataOptions): Promise<CompositePoolDataResult>;
|
|
190
|
+
/**
|
|
191
|
+
* Calculate DEX pool quote using LOCAL client-side calculation
|
|
192
|
+
*
|
|
193
|
+
* Instant quotes without network calls. Uses quoteExactAmount from @gala-chain/dex
|
|
194
|
+
* with pre-fetched composite pool data.
|
|
195
|
+
*
|
|
196
|
+
* @param options Quote calculation options (must include compositePoolData)
|
|
197
|
+
* @returns Quote result with amounts and price data
|
|
198
|
+
* @throws DexQuoteError on calculation errors
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* // Step 1: Fetch composite data (one network call)
|
|
203
|
+
* const composite = await sdk.fetchCompositePoolData({
|
|
204
|
+
* token0: 'GALA|Unit|none|none',
|
|
205
|
+
* token1: 'Token|Unit|BENE|client:123',
|
|
206
|
+
* fee: 3000
|
|
207
|
+
* });
|
|
208
|
+
*
|
|
209
|
+
* // Step 2: Calculate quote (instant, local)
|
|
210
|
+
* const quote = await sdk.calculateDexPoolQuoteExactAmountLocal({
|
|
211
|
+
* compositePoolData: composite,
|
|
212
|
+
* fromToken: 'GALA|Unit|none|none',
|
|
213
|
+
* toToken: 'Token|Unit|BENE|client:123',
|
|
214
|
+
* amount: '1000'
|
|
215
|
+
* });
|
|
216
|
+
* console.log(`Receive: ${quote.amount1} BENE`);
|
|
217
|
+
*
|
|
218
|
+
* // Step 3: More quotes reusing same composite data (instant!)
|
|
219
|
+
* const quote2 = await sdk.calculateDexPoolQuoteExactAmountLocal({
|
|
220
|
+
* compositePoolData: composite,
|
|
221
|
+
* fromToken: 'GALA|Unit|none|none',
|
|
222
|
+
* toToken: 'Token|Unit|BENE|client:123',
|
|
223
|
+
* amount: '5000'
|
|
224
|
+
* });
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
calculateDexPoolQuoteExactAmountLocal(options: CalculateDexPoolQuoteOptions): Promise<DexPoolQuoteResult>;
|
|
228
|
+
/**
|
|
229
|
+
* Calculate DEX pool quote using EXTERNAL GalaChain network call
|
|
230
|
+
*
|
|
231
|
+
* Real-time quotes from chain. Slower than local but always fresh.
|
|
232
|
+
* Uses QuoteExactAmount chain method directly.
|
|
233
|
+
*
|
|
234
|
+
* @param options Quote calculation options (must include compositePoolData for token info)
|
|
235
|
+
* @returns Quote result from chain
|
|
236
|
+
* @throws DexQuoteError on network or calculation errors
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* // Fetch composite data to get token ClassKeys
|
|
241
|
+
* const composite = await sdk.fetchCompositePoolData({
|
|
242
|
+
* token0: 'GALA|Unit|none|none',
|
|
243
|
+
* token1: 'Token|Unit|BENE|client:123',
|
|
244
|
+
* fee: 3000
|
|
245
|
+
* });
|
|
246
|
+
*
|
|
247
|
+
* // Get real-time quote from chain
|
|
248
|
+
* const quote = await sdk.calculateDexPoolQuoteExactAmountExternal({
|
|
249
|
+
* compositePoolData: composite,
|
|
250
|
+
* fromToken: 'GALA|Unit|none|none',
|
|
251
|
+
* toToken: 'Token|Unit|BENE|client:123',
|
|
252
|
+
* amount: '1000'
|
|
253
|
+
* });
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
calculateDexPoolQuoteExactAmountExternal(options: CalculateDexPoolQuoteOptions): Promise<DexPoolQuoteResult>;
|
|
257
|
+
/**
|
|
258
|
+
* Calculate DEX pool quote with automatic mode selection
|
|
259
|
+
*
|
|
260
|
+
* Main method that delegates to local or external based on mode parameter.
|
|
261
|
+
* Defaults to local (instant) calculation.
|
|
262
|
+
*
|
|
263
|
+
* @param options Quote calculation options
|
|
264
|
+
* @param mode 'local' (instant) or 'external' (real-time) - defaults to 'local'
|
|
265
|
+
* @returns Quote result
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* const quote = await sdk.calculateDexPoolQuoteExactAmount({
|
|
270
|
+
* compositePoolData: composite,
|
|
271
|
+
* fromToken: 'GALA|Unit|none|none',
|
|
272
|
+
* toToken: 'Token|Unit|BENE|client:123',
|
|
273
|
+
* amount: '1000'
|
|
274
|
+
* });
|
|
275
|
+
* // Uses local calculation by default
|
|
276
|
+
*
|
|
277
|
+
* // Or explicitly specify external mode for real-time:
|
|
278
|
+
* const quote = await sdk.calculateDexPoolQuoteExactAmount({
|
|
279
|
+
* compositePoolData: composite,
|
|
280
|
+
* fromToken: 'GALA|Unit|none|none',
|
|
281
|
+
* toToken: 'Token|Unit|BENE|client:123',
|
|
282
|
+
* amount: '1000'
|
|
283
|
+
* }, 'external');
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
calculateDexPoolQuoteExactAmount(options: CalculateDexPoolQuoteOptions, mode?: 'local' | 'external'): Promise<DexPoolQuoteResult>;
|
|
287
|
+
}
|
|
288
|
+
//# sourceMappingURL=DexQuoteService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DexQuoteService.d.ts","sourceRoot":"","sources":["../../src/services/DexQuoteService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAUhD,OAAO,KAAK,EACV,6BAA6B,EAC7B,uBAAuB,EACvB,4BAA4B,EAC5B,kBAAkB,EAEnB,MAAM,6BAA6B,CAAC;AAGrC;;GAEG;AACH,eAAO,MAAM,gCAAgC,IAAI,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,qBAAa,eAAgB,SAAQ,WAAW;IAC9C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,6BAA6B,CAA4C;IAEjF;;;;;;;;;;;;;;;OAeG;gBAED,IAAI,EAAE,UAAU,EAChB,gBAAgB,EAAE,MAAM,EACxB,SAAS,GAAE,OAAe,EAC1B,cAAc,GAAE,MAAc;IAOhC;;;;;;;;OAQG;IACH,OAAO,CAAC,mCAAmC;IAuC3C;;;;;;OAMG;IACH,OAAO,CAAC,mBAAmB;IAc3B;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;IAS5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiDG;IACH,gCAAgC,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAO3D;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,sBAAsB,CAC1B,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,uBAAuB,CAAC;IA+DnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACG,qCAAqC,CACzC,OAAO,EAAE,4BAA4B,GACpC,OAAO,CAAC,kBAAkB,CAAC;IAyD9B;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,wCAAwC,CAC5C,OAAO,EAAE,4BAA4B,GACpC,OAAO,CAAC,kBAAkB,CAAC;IAmE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,gCAAgC,CACpC,OAAO,EAAE,4BAA4B,EACrC,IAAI,GAAE,OAAO,GAAG,UAAoB,GACnC,OAAO,CAAC,kBAAkB,CAAC;CAM/B"}
|