@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
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GalaChain Gateway Client
|
|
3
|
+
*
|
|
4
|
+
* Direct HTTP client for GalaChain Gateway DEX contract endpoints.
|
|
5
|
+
* Fully typed API interactions with zero `any` types.
|
|
6
|
+
*/
|
|
7
|
+
import { GalaChainGatewayResponse, GalaChainPoolData, GalaChainGetPoolDataRequest, GalaChainGetPositionsRequest, GalaChainGetPositionsResponse, GalaChainGetRemoveLiquidityEstimationRequest, GalaChainRemoveLiquidityEstimation } from '../types/galachain-api.types';
|
|
8
|
+
/**
|
|
9
|
+
* GalaChain Gateway Client configuration
|
|
10
|
+
*/
|
|
11
|
+
export interface GalaChainGatewayClientConfig {
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
timeout?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Direct HTTP client for GalaChain Gateway DEX contract endpoints
|
|
17
|
+
*/
|
|
18
|
+
export declare class GalaChainGatewayClient {
|
|
19
|
+
private client;
|
|
20
|
+
constructor(config: GalaChainGatewayClientConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Get pool data from GalaChain Gateway
|
|
23
|
+
* Endpoint: POST /api/asset/dexv3-contract/GetPoolData
|
|
24
|
+
*
|
|
25
|
+
* @param request - Pool data request with token pair and fee tier
|
|
26
|
+
* @returns Fully typed pool data
|
|
27
|
+
* @throws ApiError if request fails
|
|
28
|
+
*/
|
|
29
|
+
getPoolData(request: GalaChainGetPoolDataRequest): Promise<GalaChainPoolData>;
|
|
30
|
+
/**
|
|
31
|
+
* Get position(s) from GalaChain Gateway
|
|
32
|
+
* Endpoint: POST /api/asset/dexv3-contract/GetPositions
|
|
33
|
+
*
|
|
34
|
+
* Supports multiple query filters:
|
|
35
|
+
* - Get all positions for owner
|
|
36
|
+
* - Get positions for specific token pair
|
|
37
|
+
* - Get specific position by ID
|
|
38
|
+
* - Pagination via bookmark
|
|
39
|
+
*
|
|
40
|
+
* @param request - Position query request with optional filters
|
|
41
|
+
* @returns List of positions matching criteria
|
|
42
|
+
* @throws ApiError if request fails
|
|
43
|
+
*/
|
|
44
|
+
getPositions(request: GalaChainGetPositionsRequest): Promise<GalaChainGetPositionsResponse>;
|
|
45
|
+
/**
|
|
46
|
+
* Get position by ID from GalaChain Gateway
|
|
47
|
+
* Convenience method that queries positions and returns first match
|
|
48
|
+
*
|
|
49
|
+
* @param positionId - Unique position identifier
|
|
50
|
+
* @returns Position data if found
|
|
51
|
+
* @throws ApiError if position not found or request fails
|
|
52
|
+
*/
|
|
53
|
+
getPositionById(positionId: string): Promise<GalaChainResponse<any>>;
|
|
54
|
+
/**
|
|
55
|
+
* Get liquidity removal estimation from GalaChain Gateway
|
|
56
|
+
* Endpoint: POST /api/asset/dexv3-contract/GetRemoveLiquidityEstimation
|
|
57
|
+
*
|
|
58
|
+
* Calculates amounts user will receive when removing liquidity
|
|
59
|
+
* Includes both principal amounts and accumulated fees
|
|
60
|
+
*
|
|
61
|
+
* @param request - Removal estimation request with position details
|
|
62
|
+
* @returns Estimated amounts to be received
|
|
63
|
+
* @throws ApiError if request fails
|
|
64
|
+
*/
|
|
65
|
+
getRemoveLiquidityEstimation(request: GalaChainGetRemoveLiquidityEstimationRequest): Promise<GalaChainRemoveLiquidityEstimation>;
|
|
66
|
+
/**
|
|
67
|
+
* Validate GalaChain Gateway response wrapper
|
|
68
|
+
* Checks for errors and required fields
|
|
69
|
+
*
|
|
70
|
+
* @param response - Response object to validate
|
|
71
|
+
* @throws ApiError if response indicates error or is malformed
|
|
72
|
+
*/
|
|
73
|
+
private validateResponse;
|
|
74
|
+
/**
|
|
75
|
+
* Handle errors from axios or gateway
|
|
76
|
+
* Converts various error types to ApiError
|
|
77
|
+
*
|
|
78
|
+
* @param error - Error from axios or validation
|
|
79
|
+
* @param context - Method name for better error messages
|
|
80
|
+
* @returns ApiError with context
|
|
81
|
+
*/
|
|
82
|
+
private handleError;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Type re-export for convenience
|
|
86
|
+
* Used when function returns wrapped response
|
|
87
|
+
*/
|
|
88
|
+
export type GalaChainResponse<T> = GalaChainGatewayResponse<T>;
|
|
89
|
+
//# sourceMappingURL=GalaChainGatewayClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GalaChainGatewayClient.d.ts","sourceRoot":"","sources":["../../src/services/GalaChainGatewayClient.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,2BAA2B,EAC3B,4BAA4B,EAC5B,6BAA6B,EAC7B,4CAA4C,EAC5C,kCAAkC,EAInC,MAAM,8BAA8B,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,EAAE,4BAA4B;IAOhD;;;;;;;OAOG;IACG,WAAW,CAAC,OAAO,EAAE,2BAA2B,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAwBnF;;;;;;;;;;;;;OAaG;IACG,YAAY,CAAC,OAAO,EAAE,4BAA4B,GAAG,OAAO,CAAC,6BAA6B,CAAC;IAoCjG;;;;;;;OAOG;IACG,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;IA4B1E;;;;;;;;;;OAUG;IACG,4BAA4B,CAChC,OAAO,EAAE,4CAA4C,GACpD,OAAO,CAAC,kCAAkC,CAAC;IA8B9C;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAexB;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW;CAkBpB;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,wBAAwB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -52,6 +52,7 @@ import { BaseService } from './BaseService';
|
|
|
52
52
|
import { FetchPoolDetailsData, InternalFetchPoolDetailsResponse } from '../types/trade.dto';
|
|
53
53
|
import { TokenBalanceResult } from '../types/user.dto';
|
|
54
54
|
import { TransferGalaData, TransferTokenData } from '../types/transfer.dto';
|
|
55
|
+
import { TokenClassWithSupply } from '../types/launchpad.dto';
|
|
55
56
|
/**
|
|
56
57
|
* GalaChain Service for blockchain operations
|
|
57
58
|
*/
|
|
@@ -202,6 +203,31 @@ export declare class GalaChainService extends BaseService {
|
|
|
202
203
|
* ```
|
|
203
204
|
*/
|
|
204
205
|
fetchTokenClassFromChain(tokenId: string | TokenClassKey): Promise<TokenClass>;
|
|
206
|
+
/**
|
|
207
|
+
* Fetch supply information for one or more token classes from GalaChain
|
|
208
|
+
*
|
|
209
|
+
* Queries GalaChain for authoritative token supply data including:
|
|
210
|
+
* - Total supply and maximum supply
|
|
211
|
+
* - Total burned amount
|
|
212
|
+
* - Mint-related supply metrics
|
|
213
|
+
* - Token metadata (symbol, decimals, name)
|
|
214
|
+
*
|
|
215
|
+
* @param tokenClasses - Array of token class keys to query
|
|
216
|
+
* @returns Promise<TokenClassWithSupply[]> Array of token classes with supply information
|
|
217
|
+
* @throws {ValidationError} if tokenClasses array is empty
|
|
218
|
+
* @throws {Error} if network request fails or GalaChain returns error status
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const supplies = await galaChainService.fetchTokenClassesWithSupply([
|
|
223
|
+
* { collection: 'GALA', category: 'Unit', type: 'none', additionalKey: 'none' },
|
|
224
|
+
* { collection: 'GUSDC', category: 'Unit', type: 'none', additionalKey: 'eth:0x...' }
|
|
225
|
+
* ]);
|
|
226
|
+
*
|
|
227
|
+
* console.log(`${supplies[0].symbol}: ${supplies[0].totalSupply}`);
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
fetchTokenClassesWithSupply(tokenClasses: TokenClassKey[]): Promise<TokenClassWithSupply[]>;
|
|
205
231
|
/**
|
|
206
232
|
* Transfer GALA tokens between wallets
|
|
207
233
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GalaChainService.d.ts","sourceRoot":"","sources":["../../src/services/GalaChainService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAM3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,EACL,oBAAoB,EACpB,gCAAgC,EAGjC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEL,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EAQlB,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"GalaChainService.d.ts","sourceRoot":"","sources":["../../src/services/GalaChainService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;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O,CAAC,wBAAwB;IAuBhC;;OAEG;IACH,OAAO,CAAC,yBAAyB;IA4CjC;;;OAGG;YACW,oBAAoB;IA0ClC;;;;OAIG;IACH,OAAO,CAAC,oCAAoC;IAwB5C;;;;;;;;;OASG;IACH,OAAO,CAAC,gCAAgC;IAmCxC;;OAEG;IACH,OAAO,CAAC,mBAAmB;CAiE5B"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pool State Manager
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates efficient pool state tracking through incremental swap deltas
|
|
5
|
+
* instead of full refetches. Provides the main API for arbitrage bots and other
|
|
6
|
+
* applications needing real-time pool state with minimal network latency.
|
|
7
|
+
*
|
|
8
|
+
* Core features:
|
|
9
|
+
* - Cached pool state with incremental updates (10-15x faster than full refetches)
|
|
10
|
+
* - Automatic validation and drift detection
|
|
11
|
+
* - Graceful fallback to full refetch on errors
|
|
12
|
+
* - Performance monitoring and metrics
|
|
13
|
+
* - Support for both exact input and exact output swaps
|
|
14
|
+
*
|
|
15
|
+
* Performance: ~30-50ms per swap (vs 200-400ms for full refetch)
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
import BigNumber from 'bignumber.js';
|
|
20
|
+
import { Pool, TickData } from '@gala-chain/dex';
|
|
21
|
+
import { SwapEventData, SwapDeltaResult, PoolStateMetadata } from '../types/pool-state-delta.dto';
|
|
22
|
+
import { CompositePoolDataResult } from '../types/composite-pool.dto';
|
|
23
|
+
/**
|
|
24
|
+
* Configuration for PoolStateManager behavior
|
|
25
|
+
*
|
|
26
|
+
* @category Pool State Manager
|
|
27
|
+
*/
|
|
28
|
+
export interface PoolStateManagerConfig {
|
|
29
|
+
/** Safety limit for maximum iterations in swap calculation (default: 100) */
|
|
30
|
+
maxIterations?: number;
|
|
31
|
+
/** Enable BigNumber cache for performance (default: true) */
|
|
32
|
+
enableBigNumberCache?: boolean;
|
|
33
|
+
/** BigNumber rounding mode (default: ROUND_DOWN) */
|
|
34
|
+
roundingMode?: BigNumber.RoundingMode;
|
|
35
|
+
/** Enable debug logging (default: false) */
|
|
36
|
+
debug?: boolean;
|
|
37
|
+
/** Maximum swaps to apply before forcing full refetch (default: 50) */
|
|
38
|
+
maxSwapsSinceRefetch?: number;
|
|
39
|
+
/** Maximum cumulative drift percentage before forcing refetch (default: 5%) */
|
|
40
|
+
maxCumulativeDrift?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Callback for when full refetch is needed
|
|
43
|
+
* Allows client to provide fresh pool data when drift accumulates
|
|
44
|
+
*/
|
|
45
|
+
onRefetchNeeded?: (pool: Pool, tickDataMap: Record<string, TickData>) => Promise<CompositePoolDataResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Enable strict validation mode (default: false)
|
|
48
|
+
* Throws errors instead of warnings for validation failures
|
|
49
|
+
*/
|
|
50
|
+
strictValidation?: boolean;
|
|
51
|
+
/** Enable performance warnings when swap calculation exceeds threshold (default: true) */
|
|
52
|
+
enablePerformanceWarnings?: boolean;
|
|
53
|
+
/** Performance warning threshold in milliseconds (default: 100ms) */
|
|
54
|
+
performanceWarningThreshold?: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Efficient pool state manager using incremental swap deltas
|
|
58
|
+
*
|
|
59
|
+
* Main orchestrator for the monkey-patching strategy that avoids full pool refetches.
|
|
60
|
+
* Coordinates SwapDeltaCalculator, PoolStateValidator, and other utilities to provide
|
|
61
|
+
* a fast, accurate view of pool state with minimal network calls.
|
|
62
|
+
*
|
|
63
|
+
* Usage:
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const manager = new PoolStateManager(compositePoolData, config);
|
|
66
|
+
*
|
|
67
|
+
* // Apply swaps incrementally (fast - ~30-50ms)
|
|
68
|
+
* const result = await manager.applySwapDelta(swapEvent);
|
|
69
|
+
*
|
|
70
|
+
* // Get current pool state
|
|
71
|
+
* const currentPool = manager.getPoolState();
|
|
72
|
+
* const metadata = manager.getMetadata();
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @category Pool State Manager
|
|
76
|
+
* @since 3.33.0
|
|
77
|
+
*/
|
|
78
|
+
export declare class PoolStateManager {
|
|
79
|
+
private readonly logger;
|
|
80
|
+
private readonly config;
|
|
81
|
+
private readonly validationConfig;
|
|
82
|
+
/** Current cached pool state */
|
|
83
|
+
private pool;
|
|
84
|
+
/** Current tick data map */
|
|
85
|
+
private tickDataMap;
|
|
86
|
+
/** Metadata about cache state and drift tracking */
|
|
87
|
+
private metadata;
|
|
88
|
+
/** Performance metrics for last swap */
|
|
89
|
+
private lastSwapMetrics?;
|
|
90
|
+
/**
|
|
91
|
+
* Calculate hash of critical pool state for validation
|
|
92
|
+
*
|
|
93
|
+
* @param pool Pool to hash
|
|
94
|
+
* @returns Hash string of pool state
|
|
95
|
+
*/
|
|
96
|
+
private static calculatePoolStateHash;
|
|
97
|
+
/**
|
|
98
|
+
* Initialize PoolStateManager with initial pool state
|
|
99
|
+
*
|
|
100
|
+
* @param poolData Initial composite pool data (from fetchCompositePoolData)
|
|
101
|
+
* @param config Optional configuration overrides
|
|
102
|
+
* @throws Error if poolData is invalid
|
|
103
|
+
*/
|
|
104
|
+
constructor(poolData: CompositePoolDataResult, config?: PoolStateManagerConfig);
|
|
105
|
+
/**
|
|
106
|
+
* Apply a swap delta to the cached pool state
|
|
107
|
+
*
|
|
108
|
+
* Calculates how the swap affects pool state, validates the result,
|
|
109
|
+
* and updates the cache incrementally. Much faster than full refetch.
|
|
110
|
+
*
|
|
111
|
+
* @param swapEvent The swap event to apply
|
|
112
|
+
* @returns Result with updated pool state and metadata
|
|
113
|
+
* @throws Error if swap calculation or validation fails (in strict mode)
|
|
114
|
+
*/
|
|
115
|
+
applySwapDelta(swapEvent: SwapEventData): Promise<SwapDeltaResult>;
|
|
116
|
+
/**
|
|
117
|
+
* Force a full refetch of pool state
|
|
118
|
+
*
|
|
119
|
+
* Resets all drift tracking and reloads pool state from the provided data.
|
|
120
|
+
* Use this after receiving a full fetchCompositePoolData response.
|
|
121
|
+
*
|
|
122
|
+
* @param poolData Fresh pool data from fetchCompositePoolData
|
|
123
|
+
*/
|
|
124
|
+
forceFullRefetch(poolData: CompositePoolDataResult): void;
|
|
125
|
+
/**
|
|
126
|
+
* Get current pool state
|
|
127
|
+
*
|
|
128
|
+
* @returns Current cached Pool object
|
|
129
|
+
*/
|
|
130
|
+
getPoolState(): Pool;
|
|
131
|
+
/**
|
|
132
|
+
* Get current tick data
|
|
133
|
+
*
|
|
134
|
+
* @returns Copy of current tick data map
|
|
135
|
+
*/
|
|
136
|
+
getTickDataMap(): Record<string, TickData>;
|
|
137
|
+
/**
|
|
138
|
+
* Get metadata about cache state
|
|
139
|
+
*
|
|
140
|
+
* @returns Current PoolStateMetadata
|
|
141
|
+
*/
|
|
142
|
+
getMetadata(): PoolStateMetadata;
|
|
143
|
+
/**
|
|
144
|
+
* Get performance metrics from last swap
|
|
145
|
+
*
|
|
146
|
+
* @returns Performance metrics or undefined if no swap applied yet
|
|
147
|
+
*/
|
|
148
|
+
getLastSwapMetrics(): {
|
|
149
|
+
calculationTimeMs: number;
|
|
150
|
+
swapSteps: number;
|
|
151
|
+
timestamp: number;
|
|
152
|
+
} | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* Check if a full refetch is recommended
|
|
155
|
+
*
|
|
156
|
+
* @returns true if drift or swap count thresholds exceeded
|
|
157
|
+
*/
|
|
158
|
+
isRefetchRecommended(): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Reset the manager to initial state (clears all cached data)
|
|
161
|
+
*
|
|
162
|
+
* @param poolData Initial pool data to reload
|
|
163
|
+
*/
|
|
164
|
+
reset(poolData: CompositePoolDataResult): void;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Factory function for creating a PoolStateManager instance
|
|
168
|
+
*
|
|
169
|
+
* Simplifies initialization by bundling common configuration.
|
|
170
|
+
*
|
|
171
|
+
* @param poolData Initial pool data
|
|
172
|
+
* @param options Configuration options
|
|
173
|
+
* @returns New PoolStateManager instance
|
|
174
|
+
*/
|
|
175
|
+
export declare function createPoolStateManager(poolData: CompositePoolDataResult, options?: PoolStateManagerConfig): PoolStateManager;
|
|
176
|
+
//# sourceMappingURL=PoolStateManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PoolStateManager.d.ts","sourceRoot":"","sources":["../../src/services/PoolStateManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EACL,aAAa,EACb,eAAe,EACf,iBAAiB,EAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAKtE;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC,6EAA6E;IAC7E,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,6DAA6D;IAC7D,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B,oDAAoD;IACpD,YAAY,CAAC,EAAE,SAAS,CAAC,YAAY,CAAC;IAEtC,4CAA4C;IAC5C,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,uEAAuE;IACvE,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,+EAA+E;IAC/E,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAE1G;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B,0FAA0F;IAC1F,yBAAyB,CAAC,EAAE,OAAO,CAAC;IAEpC,qEAAqE;IACrE,2BAA2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AC/B,gBAAgB,CAElB"}
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* EIP-712 Signature Service for Bonding Curve Transactions
|
|
3
3
|
*
|
|
4
|
-
* This service handles EIP-712 signature generation for
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* This service handles EIP-712 signature generation for bonding curve operations
|
|
5
|
+
* using ethers.js Wallet. It replicates the exact signature generation process
|
|
6
|
+
* used in the frontend to ensure compatibility with the GalaChain backend.
|
|
7
7
|
*
|
|
8
|
-
* ## Supported
|
|
9
|
-
* -
|
|
10
|
-
* - TrustWallet (signMessage with serialization)
|
|
11
|
-
* - GalaWallet (custom implementation)
|
|
8
|
+
* ## Supported Signing Method:
|
|
9
|
+
* - ethers.js Wallet (signTypedData)
|
|
12
10
|
*
|
|
13
11
|
* ## Key Features:
|
|
14
12
|
* - Dynamic EIP-712 type generation
|
|
15
13
|
* - Personal sign prefix calculation
|
|
16
|
-
* -
|
|
17
|
-
* - Full compatibility with frontend implementation
|
|
14
|
+
* - Full compatibility with GalaChain backend
|
|
18
15
|
*
|
|
19
16
|
* @category Services
|
|
20
17
|
* @since 2.0.0
|
|
@@ -49,14 +46,6 @@ interface EIP712Domain {
|
|
|
49
46
|
name: string;
|
|
50
47
|
chainId: number;
|
|
51
48
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Wallet preference enumeration
|
|
54
|
-
*/
|
|
55
|
-
export declare enum WalletPreference {
|
|
56
|
-
METAMASK = 0,
|
|
57
|
-
TRUST_WALLET = 1,
|
|
58
|
-
GALA_WALLET = 2
|
|
59
|
-
}
|
|
60
49
|
/**
|
|
61
50
|
* Service for handling EIP-712 signatures for bonding curve operations
|
|
62
51
|
*/
|
|
@@ -64,42 +53,31 @@ export declare class SignatureService extends LoggerBase {
|
|
|
64
53
|
private walletProvider;
|
|
65
54
|
constructor(walletProvider: WalletProvider, debug?: boolean);
|
|
66
55
|
/**
|
|
67
|
-
* Sign a DTO using EIP-712 with
|
|
56
|
+
* Sign a DTO using EIP-712 with ethers.js Wallet
|
|
68
57
|
*
|
|
69
58
|
* @param dto - The DTO to sign (extends ChainCallDTO)
|
|
70
59
|
* @param methodName - The method name for type generation
|
|
71
60
|
* @param walletAddress - The user's wallet address
|
|
72
|
-
* @param walletPreference - Wallet type preference
|
|
73
61
|
* @returns Signed payload ready for bundle submission
|
|
74
62
|
*/
|
|
75
|
-
signDTO(dto: SignableDTO, methodName: string,
|
|
63
|
+
signDTO(dto: SignableDTO, methodName: string, _walletAddress: string): Promise<SignableDTO & {
|
|
76
64
|
signature: string;
|
|
77
65
|
types?: EIP712Types;
|
|
78
66
|
domain?: EIP712Domain;
|
|
79
67
|
}>;
|
|
80
68
|
/**
|
|
81
|
-
* Sign with
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
* Sign with TrustWallet using signMessage
|
|
86
|
-
*/
|
|
87
|
-
private signWithTrustWallet;
|
|
88
|
-
/**
|
|
89
|
-
* Sign with GalaWallet using custom implementation
|
|
90
|
-
* Falls back to MetaMask signing in non-browser environments
|
|
69
|
+
* Sign with ethers.js Wallet using signTypedData
|
|
70
|
+
*
|
|
71
|
+
* Supports both direct ethers.js Wallet instances and Web3 providers
|
|
72
|
+
* with dynamic network detection capabilities.
|
|
91
73
|
*/
|
|
92
|
-
private
|
|
74
|
+
private signWithEthersWallet;
|
|
93
75
|
/**
|
|
94
76
|
* Generate EIP-712 types from DTO structure
|
|
95
77
|
* Dynamically creates type definitions based on DTO fields
|
|
96
78
|
* EXACTLY matches frontend implementation from readWriteUtils.ts
|
|
97
79
|
*/
|
|
98
80
|
private generateEIP712Types;
|
|
99
|
-
/**
|
|
100
|
-
* Detect wallet preference from provider
|
|
101
|
-
*/
|
|
102
|
-
detectWalletPreference(): WalletPreference;
|
|
103
81
|
}
|
|
104
82
|
export {};
|
|
105
83
|
//# sourceMappingURL=SignatureService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignatureService.d.ts","sourceRoot":"","sources":["../../src/services/SignatureService.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"SignatureService.d.ts","sourceRoot":"","sources":["../../src/services/SignatureService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAQ3C;;GAEG;AACH,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAChH,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACnD,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC,CAAC;CACxE;AAED;;GAEG;AACH,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE3C;;GAEG;AACH,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,UAAU;IAE5C,OAAO,CAAC,cAAc;gBAAd,cAAc,EAAE,cAAc,EACtC,KAAK,GAAE,OAAe;IAKxB;;;;;;;OAOG;IACG,OAAO,CACX,GAAG,EAAE,WAAW,EAChB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,WAAW,GAAG;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,WAAW,CAAC;QAAC,MAAM,CAAC,EAAE,YAAY,CAAA;KAAE,CAAC;IAoC3F;;;;;OAKG;YACW,oBAAoB;IA8ClC;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;CA0F5B"}
|
|
@@ -17,11 +17,76 @@ export interface TransactionStatus {
|
|
|
17
17
|
timestamp: number;
|
|
18
18
|
blockHash?: string;
|
|
19
19
|
gasUsed?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Raw transaction data from bundler response
|
|
22
|
+
* Contains actual swap/buy/sell amounts and other transaction details
|
|
23
|
+
* @since v3.32.0 - Added to capture actual transaction output
|
|
24
|
+
*/
|
|
25
|
+
data?: Record<string, unknown>;
|
|
20
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* WebSocket service configuration with timeout customization
|
|
29
|
+
*
|
|
30
|
+
* **Timeout Configuration**
|
|
31
|
+
* Control how long the SDK waits for WebSocket transaction confirmation:
|
|
32
|
+
* - Default: 300000ms (5 minutes) - suitable for typical blockchain finalization
|
|
33
|
+
* - Minimum: 10000ms (10 seconds) - for fast-finality blockchains
|
|
34
|
+
* - Custom: Set to any millisecond value matching your blockchain requirements
|
|
35
|
+
*
|
|
36
|
+
* **When Timeout Occurs**
|
|
37
|
+
* If no transaction confirmation is received within the timeout period:
|
|
38
|
+
* - WebSocket monitoring is terminated
|
|
39
|
+
* - Operation returns with `status: 'SUBMITTED'` indicating transaction was accepted
|
|
40
|
+
* - Transaction may still succeed on-chain even if monitoring times out
|
|
41
|
+
* - Users can call `.wait()` again to retry monitoring
|
|
42
|
+
* - Recommended: retry monitoring after waiting or check on-chain later
|
|
43
|
+
*
|
|
44
|
+
* **Use Cases for Custom Timeouts**
|
|
45
|
+
* - **Slow Blockchains** (5+ min finality): Increase to 600000+ ms
|
|
46
|
+
* - **Fast Blockchains** (Solana, Polygon): Reduce to 30000-60000 ms
|
|
47
|
+
* - **High Network Congestion**: Increase timeout tolerance
|
|
48
|
+
* - **Mobile Networks**: Increase to handle intermittent connectivity
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // Initialize SDK with custom WebSocket timeout
|
|
53
|
+
* const sdk = await createLaunchpadSDK({
|
|
54
|
+
* wallet: privateKey,
|
|
55
|
+
* config: {
|
|
56
|
+
* // Custom 2-minute timeout for faster networks
|
|
57
|
+
* websocket: {
|
|
58
|
+
* timeout: 120000 // 120 seconds instead of default 5 minutes
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* // Or for slow networks
|
|
64
|
+
* const sdk = await createLaunchpadSDK({
|
|
65
|
+
* wallet: privateKey,
|
|
66
|
+
* config: {
|
|
67
|
+
* websocket: {
|
|
68
|
+
* timeout: 600000 // 10 minutes for very slow finality
|
|
69
|
+
* }
|
|
70
|
+
* }
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
21
74
|
export interface WebSocketConfig {
|
|
75
|
+
/** WebSocket server URL for transaction monitoring */
|
|
22
76
|
url: string;
|
|
77
|
+
/** Maximum reconnection attempts on connection loss (default: 5) */
|
|
23
78
|
reconnectAttempts?: number;
|
|
79
|
+
/** Delay between reconnection attempts in milliseconds (default: 2000) */
|
|
24
80
|
reconnectDelay?: number;
|
|
81
|
+
/**
|
|
82
|
+
* Maximum time to wait for transaction confirmation in milliseconds (default: 300000 / 5 minutes)
|
|
83
|
+
*
|
|
84
|
+
* Configure based on blockchain finality time:
|
|
85
|
+
* - Ethereum/GalaChain: 300000ms (5 minutes) ✅ Default
|
|
86
|
+
* - Polygon: 120000ms (2 minutes)
|
|
87
|
+
* - Solana: 30000ms (30 seconds)
|
|
88
|
+
* - Custom: Adjust to match your blockchain's block time + finality buffer
|
|
89
|
+
*/
|
|
25
90
|
timeout?: number;
|
|
26
91
|
}
|
|
27
92
|
export declare class WebSocketService extends LoggerBase {
|
|
@@ -33,6 +98,24 @@ export declare class WebSocketService extends LoggerBase {
|
|
|
33
98
|
private debug;
|
|
34
99
|
private isSocketIOAvailable;
|
|
35
100
|
private hasOnAnyListener;
|
|
101
|
+
/**
|
|
102
|
+
* CRITICAL FIX FOR RACE CONDITION:
|
|
103
|
+
* Buffers bundler events that arrive before their listeners are registered.
|
|
104
|
+
*
|
|
105
|
+
* **The Problem:**
|
|
106
|
+
* 1. SDK sends HTTP request to bundler
|
|
107
|
+
* 2. Bundler processes synchronously and sends "PROCESSED" event immediately
|
|
108
|
+
* 3. Event arrives over WebSocket before SDK registers listener
|
|
109
|
+
* 4. Event is lost forever, SDK hangs waiting for confirmation
|
|
110
|
+
*
|
|
111
|
+
* **The Solution:**
|
|
112
|
+
* Use a catch-all listener to buffer ALL bundler events, regardless of
|
|
113
|
+
* when the specific transactionId listener is registered. This ensures
|
|
114
|
+
* no events are ever lost, even if they arrive milliseconds early.
|
|
115
|
+
*/
|
|
116
|
+
private eventBuffer;
|
|
117
|
+
private eventBufferTimeouts;
|
|
118
|
+
private readonly MAX_BUFFER_SIZE;
|
|
36
119
|
constructor(config: WebSocketConfig, debug?: boolean);
|
|
37
120
|
/**
|
|
38
121
|
* Check if Socket.IO is available in the current environment
|
|
@@ -45,8 +128,23 @@ export declare class WebSocketService extends LoggerBase {
|
|
|
45
128
|
connect(): Promise<void>;
|
|
46
129
|
/**
|
|
47
130
|
* Monitor a specific transaction
|
|
131
|
+
*
|
|
132
|
+
* CRITICAL: This method checks for buffered events first.
|
|
133
|
+
* If an event arrived before this listener was registered,
|
|
134
|
+
* it will be delivered immediately from the buffer.
|
|
135
|
+
* This prevents transactions from hanging due to race conditions.
|
|
48
136
|
*/
|
|
49
137
|
monitorTransaction(transactionId: string, callback: (status: TransactionStatus) => void): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* CRITICAL: Shared event processing logic for both real-time and buffered events
|
|
140
|
+
* Extracts common parsing and status mapping from socket listener
|
|
141
|
+
* Allows both paths (live events + buffered events) to use identical logic
|
|
142
|
+
*
|
|
143
|
+
* @param transactionId - The transaction to process
|
|
144
|
+
* @param data - The raw event data
|
|
145
|
+
* @param callback - The listener callback to invoke
|
|
146
|
+
*/
|
|
147
|
+
private processTransactionEvent;
|
|
50
148
|
/**
|
|
51
149
|
* Wait for transaction completion
|
|
52
150
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketService.d.ts","sourceRoot":"","sources":["../../src/services/WebSocketService.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAM,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAEL,oBAAoB,EAErB,MAAM,0BAA0B,CAAC;AAElC,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"WebSocketService.d.ts","sourceRoot":"","sources":["../../src/services/WebSocketService.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAM,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAEL,oBAAoB,EAErB,MAAM,0BAA0B,CAAC;AAElC,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;I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,CAAC;IAY3E;;OAEG;IACH,OAAO,CAAC,eAAe;IAKvB;;OAEG;YACW,eAAe;IAmB7B;;OAEG;IACH,UAAU,IAAI,IAAI;IAoClB;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;;;;;;;;;;;OAYG;IACH,SAAS,IAAI,MAAM,GAAG,IAAI;CAG3B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock Logger for testing
|
|
3
|
+
* Captures all logging calls for assertion in tests
|
|
4
|
+
* (Does not implement Logger class due to private properties;
|
|
5
|
+
* uses duck typing for test assertions)
|
|
6
|
+
*/
|
|
7
|
+
export declare class MockLogger {
|
|
8
|
+
debugCalls: string[];
|
|
9
|
+
infoCalls: string[];
|
|
10
|
+
warnCalls: string[];
|
|
11
|
+
errorCalls: string[];
|
|
12
|
+
debug(message: string, _context?: any): void;
|
|
13
|
+
info(message: string, _context?: any): void;
|
|
14
|
+
warn(message: string, _context?: any): void;
|
|
15
|
+
error(message: string, _context?: any): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=logger.mock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.mock.d.ts","sourceRoot":"","sources":["../../../src/services/__mocks__/logger.mock.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qBAAa,UAAU;IACrB,UAAU,EAAE,MAAM,EAAE,CAAM;IAC1B,SAAS,EAAE,MAAM,EAAE,CAAM;IACzB,SAAS,EAAE,MAAM,EAAE,CAAM;IACzB,UAAU,EAAE,MAAM,EAAE,CAAM;IAE1B,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,IAAI;IAI5C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,IAAI;IAI3C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,IAAI;IAI3C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,IAAI;CAG7C"}
|
package/dist/types/common.d.ts
CHANGED
|
@@ -63,6 +63,8 @@ export interface SDKConfig {
|
|
|
63
63
|
headers?: Record<string, string>;
|
|
64
64
|
/** Whether to enable debug logging */
|
|
65
65
|
debug?: boolean;
|
|
66
|
+
/** Concurrency level for pricing operations on liquidity positions (default: 5) */
|
|
67
|
+
pricingConcurrency?: number;
|
|
66
68
|
}
|
|
67
69
|
/**
|
|
68
70
|
* Standard error response from the backend
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,OAAO;IACtC,mDAAmD;IACnD,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qBAAqB;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,uBAAuB;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,OAAO;IAC5C,qBAAqB;IACrB,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,KAAK,E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