@gala-chain/launchpad-sdk 4.0.3 → 4.0.4-beta.1
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/EXAMPLES.md +96 -35
- package/README.md +2 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/src/LaunchpadSDK.d.ts +750 -72
- package/dist/src/LaunchpadSDK.d.ts.map +1 -1
- package/dist/src/constants/version.generated.d.ts +1 -1
- package/dist/src/constants/version.generated.d.ts.map +1 -1
- package/dist/src/services/DexBackendClient.d.ts +139 -10
- package/dist/src/services/DexBackendClient.d.ts.map +1 -1
- package/dist/src/services/DexQuoteService.d.ts +181 -22
- package/dist/src/services/DexQuoteService.d.ts.map +1 -1
- package/dist/src/services/DexService.d.ts +274 -38
- package/dist/src/services/DexService.d.ts.map +1 -1
- package/dist/src/services/GSwapService.d.ts +555 -246
- package/dist/src/services/GSwapService.d.ts.map +1 -1
- package/dist/src/services/GalaChainGatewayClient.d.ts +139 -41
- package/dist/src/services/GalaChainGatewayClient.d.ts.map +1 -1
- package/dist/src/services/ImageService.d.ts +101 -12
- package/dist/src/services/ImageService.d.ts.map +1 -1
- package/dist/src/services/PoolCacheManager.d.ts +125 -31
- package/dist/src/services/PoolCacheManager.d.ts.map +1 -1
- package/dist/src/services/SignatureService.d.ts +35 -5
- package/dist/src/services/SignatureService.d.ts.map +1 -1
- package/dist/src/services/SwapEventQueue.d.ts +79 -10
- package/dist/src/services/SwapEventQueue.d.ts.map +1 -1
- package/dist/src/services/TokenClassKeyService.d.ts +56 -10
- package/dist/src/services/TokenClassKeyService.d.ts.map +1 -1
- package/dist/src/services/TokenMetadataService.d.ts +407 -31
- package/dist/src/services/TokenMetadataService.d.ts.map +1 -1
- package/dist/src/services/TradeService.d.ts +168 -6
- package/dist/src/services/TradeService.d.ts.map +1 -1
- package/dist/src/services/UserService.d.ts +117 -15
- package/dist/src/services/UserService.d.ts.map +1 -1
- package/package.json +12 -2
- package/API.md +0 -1475
|
@@ -24,35 +24,111 @@ export declare class GSwapService extends LoggerBase {
|
|
|
24
24
|
*/
|
|
25
25
|
setPricingConcurrency(concurrency: number): void;
|
|
26
26
|
/**
|
|
27
|
-
* Get swap quote for
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
27
|
+
* Get swap quote for spending a known input amount (exact input swap quote)
|
|
28
|
+
*
|
|
29
|
+
* Calculates how much of the destination token you will receive when spending a specific amount
|
|
30
|
+
* of the source token. Uses dynamic fee tier discovery to find the best available liquidity pool,
|
|
31
|
+
* trying fee tiers in order of typical liquidity: 3000 (0.30%), 500 (0.05%), then 10000 (1.00%).
|
|
32
|
+
* All quotes are always fresh (never cached) to prevent MEV vulnerabilities in volatile markets.
|
|
33
|
+
*
|
|
34
|
+
* @param params - Quote request parameters
|
|
35
|
+
* @param params.fromToken - Source token identifier (pipe-delimited format: 'GALA|Unit|none|none')
|
|
36
|
+
* @param params.toToken - Destination token identifier (pipe-delimited format)
|
|
37
|
+
* @param params.amount - Input amount to spend (must be positive number string)
|
|
38
|
+
* @returns Promise<SwapQuoteResult> Quote with estimated output amount, fee tier, price impact, and execution price
|
|
39
|
+
* @throws {GSwapQuoteError} If DexQuoteService not configured or all fee tiers fail to provide a quote
|
|
40
|
+
* @since 4.0.4-beta.0
|
|
41
|
+
* @category Services
|
|
42
|
+
*
|
|
43
|
+
* @example Get quote for buying tokens with 100 GALA
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const quote = await gswapService.getSwapQuoteExactInput({
|
|
46
|
+
* fromToken: 'GALA|Unit|none|none',
|
|
47
|
+
* toToken: 'Token|Unit|BENE|client:123',
|
|
48
|
+
* amount: '100'
|
|
49
|
+
* });
|
|
33
50
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
51
|
+
* console.log(`Spending ${quote.inputAmount} GALA`);
|
|
52
|
+
* console.log(`Receiving ~${quote.estimatedOutput} BENE tokens`);
|
|
53
|
+
* console.log(`Fee tier: ${quote.feeTier / 100}%`);
|
|
54
|
+
* console.log(`Price impact: ${(parseFloat(quote.priceImpact) * 100).toFixed(4)}%`);
|
|
55
|
+
* ```
|
|
37
56
|
*/
|
|
38
57
|
getSwapQuoteExactInput(params: SwapQuoteParams): Promise<SwapQuoteResult>;
|
|
39
58
|
/**
|
|
40
|
-
* Get swap quote for
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
59
|
+
* Get swap quote for receiving a known output amount (exact output swap quote)
|
|
60
|
+
*
|
|
61
|
+
* Calculates how much of the source token you need to spend to receive a specific amount
|
|
62
|
+
* of the destination token. Uses dynamic fee tier discovery to find the best available liquidity pool,
|
|
63
|
+
* trying fee tiers in order of typical liquidity: 3000 (0.30%), 500 (0.05%), then 10000 (1.00%).
|
|
64
|
+
* All quotes are always fresh (never cached) to prevent MEV vulnerabilities in volatile markets.
|
|
65
|
+
*
|
|
66
|
+
* @param params - Quote request parameters
|
|
67
|
+
* @param params.fromToken - Source token identifier (pipe-delimited format: 'GALA|Unit|none|none')
|
|
68
|
+
* @param params.toToken - Destination token identifier (pipe-delimited format)
|
|
69
|
+
* @param params.amount - Desired output amount to receive (must be positive number string)
|
|
70
|
+
* @returns Promise<SwapQuoteResult> Quote with required input amount, fee tier, price impact, and execution price
|
|
71
|
+
* @throws {GSwapQuoteError} If DexQuoteService not configured or all fee tiers fail to provide a quote
|
|
72
|
+
* @since 4.0.4-beta.0
|
|
73
|
+
* @category Services
|
|
74
|
+
*
|
|
75
|
+
* @example Get quote for receiving exactly 50 tokens
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const quote = await gswapService.getSwapQuoteExactOutput({
|
|
78
|
+
* fromToken: 'GALA|Unit|none|none',
|
|
79
|
+
* toToken: 'GUSDC|Unit|none|none',
|
|
80
|
+
* amount: '50'
|
|
81
|
+
* });
|
|
46
82
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
83
|
+
* console.log(`Need to spend ${quote.inputAmount} GALA`);
|
|
84
|
+
* console.log(`To receive exactly ${quote.estimatedOutput} GUSDC`);
|
|
85
|
+
* console.log(`Fee tier: ${quote.feeTier / 100}%`);
|
|
86
|
+
* console.log(`Price impact: ${(parseFloat(quote.priceImpact) * 100).toFixed(4)}%`);
|
|
87
|
+
* ```
|
|
50
88
|
*/
|
|
51
89
|
getSwapQuoteExactOutput(params: SwapQuoteParams): Promise<SwapQuoteResult>;
|
|
52
90
|
/**
|
|
53
|
-
* Execute a token swap with slippage protection
|
|
54
|
-
*
|
|
55
|
-
*
|
|
91
|
+
* Execute a token swap with slippage protection on GalaSwap DEX
|
|
92
|
+
*
|
|
93
|
+
* Performs a direct swap transaction between two tokens using the specified fee tier pool.
|
|
94
|
+
* Automatically calculates slippage-adjusted minimum output to protect against price movement,
|
|
95
|
+
* submits the transaction via the bundler, and monitors confirmation via WebSocket. Always get
|
|
96
|
+
* a fresh quote before executing to ensure accurate pricing and appropriate fee tier selection.
|
|
97
|
+
*
|
|
98
|
+
* @param params - Swap execution parameters
|
|
99
|
+
* @param params.fromToken - Source token to swap from (pipe-delimited format: 'GALA|Unit|none|none')
|
|
100
|
+
* @param params.toToken - Destination token to swap to (pipe-delimited format)
|
|
101
|
+
* @param params.inputAmount - Amount of source token to spend (string number)
|
|
102
|
+
* @param params.estimatedOutput - Expected output amount from quote (used for slippage calculation)
|
|
103
|
+
* @param params.feeTier - Pool fee tier in basis points (500 = 0.05%, 3000 = 0.30%, 10000 = 1.00%)
|
|
104
|
+
* @param params.slippageTolerance - Maximum acceptable slippage (default: 0.01 = 1%)
|
|
105
|
+
* @returns Promise<ExecuteSwapResult> Transaction result with status, amounts, and monitoring details
|
|
106
|
+
* @throws {Error} If private key not available, wallet address missing, or transaction fails
|
|
107
|
+
* @since 4.0.4-beta.0
|
|
108
|
+
* @category Services
|
|
109
|
+
*
|
|
110
|
+
* @example Complete swap workflow with quote and execution
|
|
111
|
+
* ```typescript
|
|
112
|
+
* // Step 1: Get fresh quote
|
|
113
|
+
* const quote = await gswapService.getSwapQuoteExactInput({
|
|
114
|
+
* fromToken: 'GALA|Unit|none|none',
|
|
115
|
+
* toToken: 'GUSDC|Unit|none|none',
|
|
116
|
+
* amount: '100'
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* // Step 2: Execute swap with 1% slippage tolerance
|
|
120
|
+
* const result = await gswapService.executeSwap({
|
|
121
|
+
* fromToken: 'GALA|Unit|none|none',
|
|
122
|
+
* toToken: 'GUSDC|Unit|none|none',
|
|
123
|
+
* inputAmount: '100',
|
|
124
|
+
* estimatedOutput: quote.estimatedOutput,
|
|
125
|
+
* feeTier: quote.feeTier, // Use fee tier from quote
|
|
126
|
+
* slippageTolerance: 0.01 // 1% max slippage
|
|
127
|
+
* });
|
|
128
|
+
*
|
|
129
|
+
* console.log(`Swap ${result.status}: ${result.transactionId}`);
|
|
130
|
+
* console.log(`Spent ${result.inputAmount} → Received ${result.outputAmount}`);
|
|
131
|
+
* ```
|
|
56
132
|
*/
|
|
57
133
|
executeSwap(params: ExecuteSwapParams): Promise<ExecuteSwapResult>;
|
|
58
134
|
/**
|
|
@@ -109,21 +185,152 @@ export declare class GSwapService extends LoggerBase {
|
|
|
109
185
|
* @returns TokenClassKey object
|
|
110
186
|
*/
|
|
111
187
|
private parseTokenFlexible;
|
|
188
|
+
/**
|
|
189
|
+
* Fetch user's liquidity positions with pagination and optional price enrichment
|
|
190
|
+
*
|
|
191
|
+
* Retrieves concentrated liquidity positions for a specific wallet address using bookmark-based
|
|
192
|
+
* cursor pagination. Supports optional real-time price enrichment to include current token prices
|
|
193
|
+
* and position value calculations. Use this method when you need manual pagination control or
|
|
194
|
+
* want to fetch positions incrementally.
|
|
195
|
+
*
|
|
196
|
+
* @param ownerAddress - Wallet address to query positions for (format: 'eth|0x...' or 'client|...')
|
|
197
|
+
* @param limit - Maximum positions per page (default: GSWAP_LIQUIDITY_POSITIONS_PAGE_SIZE)
|
|
198
|
+
* @param bookmark - Optional pagination cursor from previous result's nextBookmark field
|
|
199
|
+
* @param options - Optional configuration for price enrichment and additional data
|
|
200
|
+
* @param options.withPrices - If true, enriches positions with current token prices and USD values
|
|
201
|
+
* @returns Promise<GetLiquidityPositionsResult> Paginated positions with optional nextBookmark and prices
|
|
202
|
+
* @throws {GSwapPositionError} If API request fails or position normalization errors occur
|
|
203
|
+
* @since 4.0.4-beta.0
|
|
204
|
+
* @category Services
|
|
205
|
+
*
|
|
206
|
+
* @example Manual pagination without price enrichment
|
|
207
|
+
* ```typescript
|
|
208
|
+
* // Fetch first page
|
|
209
|
+
* const page1 = await gswapService.getUserLiquidityPositions(
|
|
210
|
+
* 'eth|0x1234...',
|
|
211
|
+
* 10
|
|
212
|
+
* );
|
|
213
|
+
*
|
|
214
|
+
* console.log(`Found ${page1.items.length} positions`);
|
|
215
|
+
*
|
|
216
|
+
* // Fetch next page if available
|
|
217
|
+
* if (page1.nextBookmark) {
|
|
218
|
+
* const page2 = await gswapService.getUserLiquidityPositions(
|
|
219
|
+
* 'eth|0x1234...',
|
|
220
|
+
* 10,
|
|
221
|
+
* page1.nextBookmark
|
|
222
|
+
* );
|
|
223
|
+
* }
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @example Fetch positions with real-time price enrichment
|
|
227
|
+
* ```typescript
|
|
228
|
+
* const positions = await gswapService.getUserLiquidityPositions(
|
|
229
|
+
* 'eth|0x1234...',
|
|
230
|
+
* 20,
|
|
231
|
+
* undefined,
|
|
232
|
+
* { withPrices: true }
|
|
233
|
+
* );
|
|
234
|
+
*
|
|
235
|
+
* // Prices map available at result.prices
|
|
236
|
+
* positions.items.forEach(pos => {
|
|
237
|
+
* const poolKey = `${pos.token0}/${pos.token1}`;
|
|
238
|
+
* const prices = positions.prices?.get(poolKey);
|
|
239
|
+
* if (prices) {
|
|
240
|
+
* console.log(`${poolKey}: Token0=$${prices.token0PriceUsd}, Token1=$${prices.token1PriceUsd}`);
|
|
241
|
+
* }
|
|
242
|
+
* });
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
112
245
|
getUserLiquidityPositions(ownerAddress: string, limit?: number, bookmark?: string, options?: GetLiquidityPositionsOptions): Promise<GetLiquidityPositionsResult>;
|
|
113
246
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
247
|
+
* Fetch ALL user liquidity positions with automatic pagination and optional price enrichment
|
|
248
|
+
*
|
|
249
|
+
* Convenience method that automatically handles bookmark-based pagination to retrieve all
|
|
250
|
+
* concentrated liquidity positions for a wallet in a single call. Uses maximum page size
|
|
251
|
+
* internally for efficiency and combines results from all pages. Optionally enriches positions
|
|
252
|
+
* with real-time token prices and USD value calculations.
|
|
253
|
+
*
|
|
254
|
+
* @param ownerAddress - Wallet address to query positions for (format: 'eth|0x...' or 'client|...')
|
|
255
|
+
* @param options - Optional configuration for price enrichment and additional data
|
|
256
|
+
* @param options.withPrices - If true, enriches all positions with current token prices and USD values
|
|
257
|
+
* @returns Promise<GSwapPosition[] | GetLiquidityPositionsResult> All positions (array if no prices, result with prices if requested)
|
|
258
|
+
* @throws {GSwapPositionError} If API request fails or position normalization errors occur
|
|
259
|
+
* @since 4.0.4-beta.0
|
|
260
|
+
* @category Services
|
|
261
|
+
*
|
|
262
|
+
* @example Fetch all positions without prices (simple array)
|
|
263
|
+
* ```typescript
|
|
264
|
+
* const allPositions = await gswapService.getAllSwapUserLiquidityPositions(
|
|
265
|
+
* 'eth|0x1234...'
|
|
266
|
+
* );
|
|
267
|
+
*
|
|
268
|
+
* console.log(`Total positions: ${allPositions.length}`);
|
|
269
|
+
* allPositions.forEach(pos => {
|
|
270
|
+
* console.log(`Position ${pos.positionId}: ${pos.token0}/${pos.token1}`);
|
|
271
|
+
* console.log(` Liquidity: ${pos.liquidity}, Range: ${pos.tickLower}-${pos.tickUpper}`);
|
|
272
|
+
* });
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* @example Fetch all positions with price enrichment (full result object)
|
|
276
|
+
* ```typescript
|
|
277
|
+
* const result = await gswapService.getAllSwapUserLiquidityPositions(
|
|
278
|
+
* 'eth|0x1234...',
|
|
279
|
+
* { withPrices: true }
|
|
280
|
+
* );
|
|
281
|
+
*
|
|
282
|
+
* // When withPrices=true, returns GetLiquidityPositionsResult with prices Map
|
|
283
|
+
* if ('prices' in result) {
|
|
284
|
+
* result.items.forEach(pos => {
|
|
285
|
+
* const poolKey = `${pos.token0}/${pos.token1}`;
|
|
286
|
+
* const prices = result.prices?.get(poolKey);
|
|
287
|
+
* if (prices) {
|
|
288
|
+
* console.log(`${poolKey}: $${prices.token0PriceUsd} / $${prices.token1PriceUsd}`);
|
|
289
|
+
* }
|
|
290
|
+
* });
|
|
291
|
+
* }
|
|
292
|
+
* ```
|
|
120
293
|
*/
|
|
121
294
|
getAllSwapUserLiquidityPositions(ownerAddress: string, options?: GetLiquidityPositionsOptions): Promise<GSwapPosition[] | GetLiquidityPositionsResult>;
|
|
122
295
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
296
|
+
* Fetch a specific liquidity position by its compound key (token pair, fee tier, and tick range)
|
|
297
|
+
*
|
|
298
|
+
* Retrieves detailed information about a single concentrated liquidity position using its
|
|
299
|
+
* compound key consisting of the token pair, fee tier, and tick boundaries. This method
|
|
300
|
+
* validates tick spacing for the given fee tier before making the API call to ensure the
|
|
301
|
+
* position parameters are valid for the specified pool.
|
|
302
|
+
*
|
|
303
|
+
* @param ownerAddress - Wallet address that owns the position (format: 'eth|0x...' or 'client|...')
|
|
304
|
+
* @param position - Compound key identifying the specific position
|
|
305
|
+
* @param position.token0 - First token identifier (pipe-delimited format: 'GALA|Unit|none|none')
|
|
306
|
+
* @param position.token1 - Second token identifier (pipe-delimited format)
|
|
307
|
+
* @param position.fee - Pool fee tier in basis points (500, 3000, or 10000)
|
|
308
|
+
* @param position.tickLower - Lower tick boundary of the position's price range
|
|
309
|
+
* @param position.tickUpper - Upper tick boundary of the position's price range
|
|
310
|
+
* @returns Promise<GSwapPosition> Complete position details with liquidity, amounts, and fees
|
|
311
|
+
* @throws {GSwapPositionError} If position not found, tick spacing invalid, or API request fails
|
|
312
|
+
* @since 4.0.4-beta.0
|
|
313
|
+
* @category Services
|
|
314
|
+
*
|
|
315
|
+
* @example Fetch position by compound key
|
|
316
|
+
* ```typescript
|
|
317
|
+
* const position = await gswapService.getLiquidityPosition(
|
|
318
|
+
* 'eth|0x1234...',
|
|
319
|
+
* {
|
|
320
|
+
* token0: 'GALA|Unit|none|none',
|
|
321
|
+
* token1: 'GUSDC|Unit|none|none',
|
|
322
|
+
* fee: 3000, // 0.30% fee tier
|
|
323
|
+
* tickLower: -276330,
|
|
324
|
+
* tickUpper: -276270
|
|
325
|
+
* }
|
|
326
|
+
* );
|
|
327
|
+
*
|
|
328
|
+
* console.log(`Position ID: ${position.positionId}`);
|
|
329
|
+
* console.log(`Liquidity: ${position.liquidity}`);
|
|
330
|
+
* console.log(`Token0 amount: ${position.amount0}`);
|
|
331
|
+
* console.log(`Token1 amount: ${position.amount1}`);
|
|
332
|
+
* console.log(`Uncollected fees: ${position.feeAmount0} / ${position.feeAmount1}`);
|
|
333
|
+
* ```
|
|
127
334
|
*/
|
|
128
335
|
getLiquidityPosition(ownerAddress: string, position: {
|
|
129
336
|
token0: string;
|
|
@@ -133,15 +340,51 @@ export declare class GSwapService extends LoggerBase {
|
|
|
133
340
|
tickUpper: number;
|
|
134
341
|
}): Promise<GSwapPosition>;
|
|
135
342
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* @param
|
|
144
|
-
* @
|
|
343
|
+
* Fetch a liquidity position by its unique position ID with automatic retry logic
|
|
344
|
+
*
|
|
345
|
+
* Retrieves detailed information about a concentrated liquidity position using its unique position ID.
|
|
346
|
+
* Includes automatic retry logic (5 attempts with 2-second delays) for newly created positions that
|
|
347
|
+
* may not be immediately indexed. Optionally accepts compound key parameters (token pair, fee tier,
|
|
348
|
+
* tick range) for faster compound key lookup instead of iterating through all positions.
|
|
349
|
+
*
|
|
350
|
+
* @param ownerAddress - Wallet address that owns the position (format: 'eth|0x...' or 'client|...')
|
|
351
|
+
* @param positionId - Unique position UUID returned when position was created
|
|
352
|
+
* @param token0 - Optional first token for compound key lookup (faster than ID scan)
|
|
353
|
+
* @param token1 - Optional second token for compound key lookup (faster than ID scan)
|
|
354
|
+
* @param feeTier - Optional fee tier in basis points for compound key lookup (500, 3000, or 10000)
|
|
355
|
+
* @param tickLower - Optional lower tick boundary for compound key lookup
|
|
356
|
+
* @param tickUpper - Optional upper tick boundary for compound key lookup
|
|
357
|
+
* @returns Promise<GSwapPosition> Complete position details with liquidity, amounts, fees, and metadata
|
|
358
|
+
* @throws {GSwapPositionError} If position not found after retries or API request fails
|
|
359
|
+
* @since 4.0.4-beta.0
|
|
360
|
+
* @category Services
|
|
361
|
+
*
|
|
362
|
+
* @example Fetch position by ID only (with automatic retry)
|
|
363
|
+
* ```typescript
|
|
364
|
+
* const position = await gswapService.getLiquidityPositionById(
|
|
365
|
+
* 'eth|0x1234...',
|
|
366
|
+
* 'abc123-position-uuid'
|
|
367
|
+
* );
|
|
368
|
+
*
|
|
369
|
+
* console.log(`Found position: ${position.token0}/${position.token1}`);
|
|
370
|
+
* console.log(`Liquidity: ${position.liquidity}`);
|
|
371
|
+
* ```
|
|
372
|
+
*
|
|
373
|
+
* @example Fetch position by ID with compound key for faster lookup
|
|
374
|
+
* ```typescript
|
|
375
|
+
* // Providing compound key parameters enables direct lookup (much faster)
|
|
376
|
+
* const position = await gswapService.getLiquidityPositionById(
|
|
377
|
+
* 'eth|0x1234...',
|
|
378
|
+
* 'abc123-position-uuid',
|
|
379
|
+
* 'GALA|Unit|none|none',
|
|
380
|
+
* 'GUSDC|Unit|none|none',
|
|
381
|
+
* 3000, // 0.30% fee tier
|
|
382
|
+
* -276330, // tickLower
|
|
383
|
+
* -276270 // tickUpper
|
|
384
|
+
* );
|
|
385
|
+
*
|
|
386
|
+
* console.log(`Position ${position.positionId} found via compound key`);
|
|
387
|
+
* ```
|
|
145
388
|
*/
|
|
146
389
|
getLiquidityPositionById(ownerAddress: string, positionId: string, token0?: string | Record<string, unknown>, token1?: string | Record<string, unknown>, feeTier?: number, tickLower?: number, tickUpper?: number): Promise<GSwapPosition>;
|
|
147
390
|
/**
|
|
@@ -164,9 +407,59 @@ export declare class GSwapService extends LoggerBase {
|
|
|
164
407
|
owner: string;
|
|
165
408
|
}): Promise<GSwapPosition>;
|
|
166
409
|
/**
|
|
167
|
-
* Estimate
|
|
168
|
-
*
|
|
169
|
-
*
|
|
410
|
+
* Estimate token amounts that will be received when removing liquidity from a position
|
|
411
|
+
*
|
|
412
|
+
* Calculates the expected token0 and token1 amounts that will be returned when removing a
|
|
413
|
+
* specific amount of liquidity from a concentrated liquidity position. This is useful for
|
|
414
|
+
* previewing the outcome before executing the actual removal transaction. Validates tick
|
|
415
|
+
* spacing for the given fee tier before making the API call to ensure valid parameters.
|
|
416
|
+
*
|
|
417
|
+
* @param args - Liquidity removal estimation parameters
|
|
418
|
+
* @param args.token0 - First token identifier (pipe-delimited format: 'GALA|Unit|none|none')
|
|
419
|
+
* @param args.token1 - Second token identifier (pipe-delimited format)
|
|
420
|
+
* @param args.fee - Pool fee tier in basis points (500, 3000, or 10000)
|
|
421
|
+
* @param args.liquidity - Amount of liquidity to remove (string number from position.liquidity)
|
|
422
|
+
* @param args.tickLower - Lower tick boundary of the position
|
|
423
|
+
* @param args.tickUpper - Upper tick boundary of the position
|
|
424
|
+
* @param args.owner - Wallet address that owns the position (format: 'eth|0x...' or 'client|...')
|
|
425
|
+
* @returns Promise<GSwapEstimateRemoveLiquidityResult> Estimated token0 and token1 amounts to be received
|
|
426
|
+
* @throws {GSwapPositionError} If tick spacing invalid, parameters incorrect, or API request fails
|
|
427
|
+
* @since 4.0.4-beta.0
|
|
428
|
+
* @category Services
|
|
429
|
+
*
|
|
430
|
+
* @example Estimate removal before executing
|
|
431
|
+
* ```typescript
|
|
432
|
+
* // First, get the position details
|
|
433
|
+
* const position = await gswapService.getLiquidityPositionById(
|
|
434
|
+
* 'eth|0x1234...',
|
|
435
|
+
* 'position-uuid'
|
|
436
|
+
* );
|
|
437
|
+
*
|
|
438
|
+
* // Estimate what you'll receive from removing all liquidity
|
|
439
|
+
* const estimate = await gswapService.estimateRemoveLiquidity({
|
|
440
|
+
* token0: position.token0,
|
|
441
|
+
* token1: position.token1,
|
|
442
|
+
* fee: position.feeTier,
|
|
443
|
+
* liquidity: position.liquidity, // Remove all liquidity
|
|
444
|
+
* tickLower: position.tickLower,
|
|
445
|
+
* tickUpper: position.tickUpper,
|
|
446
|
+
* owner: 'eth|0x1234...'
|
|
447
|
+
* });
|
|
448
|
+
*
|
|
449
|
+
* console.log(`Removing liquidity will return:`);
|
|
450
|
+
* console.log(` Token0: ${estimate.amount0}`);
|
|
451
|
+
* console.log(` Token1: ${estimate.amount1}`);
|
|
452
|
+
*
|
|
453
|
+
* // Then execute actual removal if amounts look good
|
|
454
|
+
* const result = await gswapService.removeLiquidity({
|
|
455
|
+
* token0: position.token0,
|
|
456
|
+
* token1: position.token1,
|
|
457
|
+
* fee: position.feeTier,
|
|
458
|
+
* liquidity: position.liquidity,
|
|
459
|
+
* tickLower: position.tickLower,
|
|
460
|
+
* tickUpper: position.tickUpper
|
|
461
|
+
* });
|
|
462
|
+
* ```
|
|
170
463
|
*/
|
|
171
464
|
estimateRemoveLiquidity(args: {
|
|
172
465
|
token0: string;
|
|
@@ -178,9 +471,51 @@ export declare class GSwapService extends LoggerBase {
|
|
|
178
471
|
owner: string;
|
|
179
472
|
}): Promise<GSwapEstimateRemoveLiquidityResult>;
|
|
180
473
|
/**
|
|
181
|
-
* Add liquidity
|
|
182
|
-
*
|
|
183
|
-
*
|
|
474
|
+
* Add concentrated liquidity to a DEX pool using user-friendly price ranges
|
|
475
|
+
*
|
|
476
|
+
* Creates a new liquidity position in a GalaSwap concentrated liquidity pool by specifying minimum
|
|
477
|
+
* and maximum prices instead of raw tick values. Automatically converts price ranges to tick boundaries
|
|
478
|
+
* using the pool's tick spacing, submits the transaction via bundler, and monitors confirmation via
|
|
479
|
+
* WebSocket. Returns a result object with transaction details and an optional wait() method for
|
|
480
|
+
* tracking on-chain confirmation.
|
|
481
|
+
*
|
|
482
|
+
* @param args - Liquidity addition parameters with price range
|
|
483
|
+
* @param args.token0 - First token identifier (pipe-delimited format: 'GALA|Unit|none|none')
|
|
484
|
+
* @param args.token1 - Second token identifier (pipe-delimited format)
|
|
485
|
+
* @param args.fee - Pool fee tier in basis points (500 = 0.05%, 3000 = 0.30%, 10000 = 1.00%)
|
|
486
|
+
* @param args.minPrice - Minimum price for the liquidity range (string number, token1 per token0)
|
|
487
|
+
* @param args.maxPrice - Maximum price for the liquidity range (string number, token1 per token0)
|
|
488
|
+
* @param args.amount0Desired - Desired amount of token0 to deposit (string number)
|
|
489
|
+
* @param args.amount1Desired - Desired amount of token1 to deposit (string number)
|
|
490
|
+
* @param args.amount0Min - Optional minimum amount0 to accept (default: '0')
|
|
491
|
+
* @param args.amount1Min - Optional minimum amount1 to accept (default: '0')
|
|
492
|
+
* @returns Promise<GSwapAddLiquidityResult> Transaction result with positionId, liquidity amounts, status, and wait() helper
|
|
493
|
+
* @throws {Error} If private key not available, wallet address missing, or transaction fails
|
|
494
|
+
* @since 4.0.4-beta.0
|
|
495
|
+
* @category Services
|
|
496
|
+
*
|
|
497
|
+
* @example Add liquidity with price range (user-friendly approach)
|
|
498
|
+
* ```typescript
|
|
499
|
+
* // Add liquidity to GALA/GUSDC pool with price range $0.025 to $0.035
|
|
500
|
+
* const result = await gswapService.addLiquidityByPrice({
|
|
501
|
+
* token0: 'GALA|Unit|none|none',
|
|
502
|
+
* token1: 'GUSDC|Unit|none|none',
|
|
503
|
+
* fee: 3000, // 0.30% fee tier
|
|
504
|
+
* minPrice: '0.025', // Minimum price: $0.025 per GALA
|
|
505
|
+
* maxPrice: '0.035', // Maximum price: $0.035 per GALA
|
|
506
|
+
* amount0Desired: '1000', // Deposit up to 1000 GALA
|
|
507
|
+
* amount1Desired: '30', // Deposit up to 30 GUSDC
|
|
508
|
+
* amount0Min: '900', // Accept minimum 900 GALA
|
|
509
|
+
* amount1Min: '25' // Accept minimum 25 GUSDC
|
|
510
|
+
* });
|
|
511
|
+
*
|
|
512
|
+
* console.log(`Position created: ${result.positionId}`);
|
|
513
|
+
* console.log(`Transaction: ${result.transactionId}`);
|
|
514
|
+
*
|
|
515
|
+
* // Wait for on-chain confirmation
|
|
516
|
+
* await result.wait?.();
|
|
517
|
+
* console.log(`Position confirmed with liquidity: ${result.liquidity}`);
|
|
518
|
+
* ```
|
|
184
519
|
*/
|
|
185
520
|
addLiquidityByPrice(args: {
|
|
186
521
|
token0: string;
|
|
@@ -197,71 +532,63 @@ export declare class GSwapService extends LoggerBase {
|
|
|
197
532
|
wait?: (timeoutMs?: number) => Promise<void>;
|
|
198
533
|
}>;
|
|
199
534
|
/**
|
|
200
|
-
* Add liquidity to
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
* @param args.amount0Desired Desired amount of token0
|
|
238
|
-
* @param args.amount1Desired Desired amount of token1
|
|
239
|
-
* @param args.amount0Min Optional minimum token0 (default: '0')
|
|
240
|
-
* @param args.amount1Min Optional minimum token1 (default: '0')
|
|
241
|
-
*
|
|
242
|
-
* @returns Promise<GSwapAddLiquidityResult> Transaction result with:
|
|
243
|
-
* - transactionId: Bundler transaction ID
|
|
244
|
-
* - positionId: GSwap position ID (discovered from on-chain data)
|
|
245
|
-
* - status: Transaction status from WebSocket
|
|
246
|
-
* - liquidity: Position liquidity amount
|
|
247
|
-
* - amount0/amount1: Actual amounts added
|
|
248
|
-
* - wait(): Async method to wait for confirmation
|
|
249
|
-
*
|
|
250
|
-
* @throws GSwapPositionError if private key unavailable or bundler submission fails
|
|
251
|
-
*
|
|
252
|
-
* @example
|
|
253
|
-
* // Add liquidity with explicit tick range
|
|
254
|
-
* const result = await sdk.addSwapLiquidityByTicks({
|
|
255
|
-
* token0: 'GALA',
|
|
256
|
-
* token1: 'GUSDC',
|
|
257
|
-
* fee: 3000,
|
|
258
|
-
* tickLower: -1080, // Supports negative ticks
|
|
259
|
-
* tickUpper: 900,
|
|
260
|
-
* amount0Desired: '100',
|
|
261
|
-
* amount1Desired: '100',
|
|
535
|
+
* Add concentrated liquidity to a DEX pool using precise tick boundaries (advanced)
|
|
536
|
+
*
|
|
537
|
+
* Creates a new liquidity position in a GalaSwap concentrated liquidity pool using raw tick
|
|
538
|
+
* boundaries instead of price ranges. This advanced method gives precise control over position
|
|
539
|
+
* range but requires understanding of Uniswap V3 tick mechanics and tick spacing constraints.
|
|
540
|
+
* Automatically connects WebSocket before transaction submission to prevent missed confirmations,
|
|
541
|
+
* then monitors position discovery with retry logic to handle indexing delays.
|
|
542
|
+
*
|
|
543
|
+
* @param args - Liquidity addition parameters with tick boundaries
|
|
544
|
+
* @param args.token0 - First token (pipe-delimited string or TokenClassKey object)
|
|
545
|
+
* @param args.token1 - Second token (pipe-delimited string or TokenClassKey object)
|
|
546
|
+
* @param args.fee - Pool fee tier in basis points (500 = 0.05%, 3000 = 0.30%, 10000 = 1.00%)
|
|
547
|
+
* @param args.tickLower - Lower tick boundary (must be multiple of tickSpacing, supports negative values)
|
|
548
|
+
* @param args.tickUpper - Upper tick boundary (must be multiple of tickSpacing)
|
|
549
|
+
* @param args.amount0Desired - Desired amount of token0 to deposit (string number)
|
|
550
|
+
* @param args.amount1Desired - Desired amount of token1 to deposit (string number)
|
|
551
|
+
* @param args.amount0Min - Optional minimum amount0 to accept (default: '0')
|
|
552
|
+
* @param args.amount1Min - Optional minimum amount1 to accept (default: '0')
|
|
553
|
+
* @returns Promise<GSwapAddLiquidityResult> Transaction result with positionId, liquidity amounts, status, and wait() helper
|
|
554
|
+
* @throws {Error} If private key not available, wallet address missing, tick spacing invalid, or transaction fails
|
|
555
|
+
* @since 4.0.4-beta.0
|
|
556
|
+
* @category Services
|
|
557
|
+
*
|
|
558
|
+
* @example Add liquidity with precise tick range (advanced users)
|
|
559
|
+
* ```typescript
|
|
560
|
+
* // Add liquidity to GALA/GUSDC pool with exact tick boundaries
|
|
561
|
+
* // Tick spacing for fee=3000 (0.30%) is 60, so ticks must be multiples of 60
|
|
562
|
+
* const result = await gswapService.addSwapLiquidityByTicks({
|
|
563
|
+
* token0: 'GALA|Unit|none|none',
|
|
564
|
+
* token1: 'GUSDC|Unit|none|none',
|
|
565
|
+
* fee: 3000, // 0.30% fee tier → tickSpacing=60
|
|
566
|
+
* tickLower: -276360, // Must be multiple of 60
|
|
567
|
+
* tickUpper: -276240, // Must be multiple of 60
|
|
568
|
+
* amount0Desired: '1000',
|
|
569
|
+
* amount1Desired: '30',
|
|
570
|
+
* amount0Min: '900',
|
|
571
|
+
* amount1Min: '25'
|
|
262
572
|
* });
|
|
263
|
-
*
|
|
264
|
-
*
|
|
573
|
+
*
|
|
574
|
+
* console.log(`Position ${result.positionId} created`);
|
|
575
|
+
* console.log(`Liquidity: ${result.liquidity}`);
|
|
576
|
+
*
|
|
577
|
+
* // Wait for on-chain confirmation
|
|
578
|
+
* await result.wait?.();
|
|
579
|
+
* console.log(`Position confirmed: ${result.status}`);
|
|
580
|
+
* ```
|
|
581
|
+
*
|
|
582
|
+
* @example Tick spacing constraints by fee tier
|
|
583
|
+
* ```typescript
|
|
584
|
+
* // Fee tier determines required tick spacing:
|
|
585
|
+
* // - Fee 500 (0.05%): tickSpacing = 10
|
|
586
|
+
* // - Fee 3000 (0.30%): tickSpacing = 60
|
|
587
|
+
* // - Fee 10000 (1.00%): tickSpacing = 200
|
|
588
|
+
*
|
|
589
|
+
* // Valid ticks for fee=3000: -276360, -276300, -276240, etc.
|
|
590
|
+
* // Invalid: -276350 (not multiple of 60)
|
|
591
|
+
* ```
|
|
265
592
|
*/
|
|
266
593
|
addSwapLiquidityByTicks(args: {
|
|
267
594
|
token0: string | TokenClassKey;
|
|
@@ -304,76 +631,70 @@ export declare class GSwapService extends LoggerBase {
|
|
|
304
631
|
*/
|
|
305
632
|
private monitorBundlerTransaction;
|
|
306
633
|
/**
|
|
307
|
-
* Remove liquidity from an existing concentrated liquidity position
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
* -
|
|
322
|
-
* -
|
|
323
|
-
*
|
|
324
|
-
* -
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
* @param args.amount1Min Optional minimum token1 to accept (default: '0')
|
|
345
|
-
* @param args.positionId Optional position ID for tracking/verification
|
|
346
|
-
*
|
|
347
|
-
* @returns Promise<GSwapRemoveLiquidityResult> Transaction result with:
|
|
348
|
-
* - transactionId: Bundler transaction ID
|
|
349
|
-
* - status: Transaction status from WebSocket (or 'SUBMITTED' if timeout)
|
|
350
|
-
* - timestamp: When transaction was submitted
|
|
351
|
-
* - wait(): Async method to monitor or retry confirmation
|
|
352
|
-
*
|
|
353
|
-
* @throws GSwapPositionError if private key unavailable or bundler submission fails
|
|
354
|
-
*
|
|
355
|
-
* @example
|
|
356
|
-
* // Get position first
|
|
357
|
-
* const positions = await sdk.getSwapUserLiquidityPositions(walletAddress);
|
|
358
|
-
* const position = positions[0];
|
|
359
|
-
*
|
|
360
|
-
* // Remove 50% of liquidity
|
|
361
|
-
* const liquidityToRemove = (parseFloat(position.liquidity) * 50) / 100;
|
|
362
|
-
* const result = await sdk.removeSwapLiquidity({
|
|
363
|
-
* token0: 'GALA',
|
|
364
|
-
* token1: 'GUSDC',
|
|
365
|
-
* fee: 3000,
|
|
634
|
+
* Remove liquidity from an existing concentrated liquidity position (partial or complete)
|
|
635
|
+
*
|
|
636
|
+
* Withdraws liquidity from a GalaSwap concentrated liquidity position, returning the underlying
|
|
637
|
+
* token0 and token1 amounts to your wallet. Supports both partial removal (reduce position size)
|
|
638
|
+
* and complete removal (close position). Validates liquidity amount to prevent zero-value removals
|
|
639
|
+
* that would waste gas fees. Automatically connects WebSocket before transaction submission to
|
|
640
|
+
* monitor confirmation, with graceful timeout handling if monitoring fails.
|
|
641
|
+
*
|
|
642
|
+
* @param args - Liquidity removal parameters
|
|
643
|
+
* @param args.token0 - First token (pipe-delimited string or TokenClassKey object)
|
|
644
|
+
* @param args.token1 - Second token (pipe-delimited string or TokenClassKey object)
|
|
645
|
+
* @param args.fee - Pool fee tier in basis points (500 = 0.05%, 3000 = 0.30%, 10000 = 1.00%)
|
|
646
|
+
* @param args.tickLower - Lower tick boundary of the position
|
|
647
|
+
* @param args.tickUpper - Upper tick boundary of the position
|
|
648
|
+
* @param args.liquidity - Amount of liquidity to remove (must be > 0, use position.liquidity for full removal)
|
|
649
|
+
* @param args.amount0Min - Optional minimum token0 to accept for slippage protection (default: '0')
|
|
650
|
+
* @param args.amount1Min - Optional minimum token1 to accept for slippage protection (default: '0')
|
|
651
|
+
* @param args.positionId - Optional position ID for tracking and error messaging
|
|
652
|
+
* @returns Promise<GSwapAddLiquidityResult> Transaction result with transactionId, status, timestamp, and wait() helper
|
|
653
|
+
* @throws {Error} If private key not available, liquidity is zero, or transaction fails
|
|
654
|
+
* @since 4.0.4-beta.0
|
|
655
|
+
* @category Services
|
|
656
|
+
*
|
|
657
|
+
* @example Remove 50% of liquidity from a position (partial removal)
|
|
658
|
+
* ```typescript
|
|
659
|
+
* // Step 1: Get position details
|
|
660
|
+
* const positions = await gswapService.getUserLiquidityPositions('eth|0x1234...');
|
|
661
|
+
* const position = positions.items[0];
|
|
662
|
+
*
|
|
663
|
+
* // Step 2: Calculate 50% of liquidity to remove
|
|
664
|
+
* const halfLiquidity = (parseFloat(position.liquidity) * 0.5).toString();
|
|
665
|
+
*
|
|
666
|
+
* // Step 3: Remove partial liquidity
|
|
667
|
+
* const result = await gswapService.removeLiquidity({
|
|
668
|
+
* token0: position.token0,
|
|
669
|
+
* token1: position.token1,
|
|
670
|
+
* fee: position.feeTier,
|
|
366
671
|
* tickLower: position.tickLower,
|
|
367
672
|
* tickUpper: position.tickUpper,
|
|
368
|
-
* liquidity:
|
|
369
|
-
* amount0Min: '0',
|
|
673
|
+
* liquidity: halfLiquidity,
|
|
674
|
+
* amount0Min: '0', // Accept any amount (consider slippage for production)
|
|
370
675
|
* amount1Min: '0',
|
|
371
|
-
* positionId: position.positionId
|
|
676
|
+
* positionId: position.positionId
|
|
372
677
|
* });
|
|
373
678
|
*
|
|
374
|
-
* console.log(
|
|
375
|
-
* await result.wait();
|
|
376
|
-
*
|
|
679
|
+
* console.log(`Removed half liquidity: ${result.transactionId}`);
|
|
680
|
+
* await result.wait?.();
|
|
681
|
+
* ```
|
|
682
|
+
*
|
|
683
|
+
* @example Remove all liquidity to close position (complete removal)
|
|
684
|
+
* ```typescript
|
|
685
|
+
* // Close position completely by removing all liquidity
|
|
686
|
+
* const result = await gswapService.removeLiquidity({
|
|
687
|
+
* token0: 'GALA|Unit|none|none',
|
|
688
|
+
* token1: 'GUSDC|Unit|none|none',
|
|
689
|
+
* fee: 3000,
|
|
690
|
+
* tickLower: -276360,
|
|
691
|
+
* tickUpper: -276240,
|
|
692
|
+
* liquidity: position.liquidity, // Remove ALL liquidity
|
|
693
|
+
* positionId: position.positionId
|
|
694
|
+
* });
|
|
695
|
+
*
|
|
696
|
+
* console.log(`Position closed: ${result.status}`);
|
|
697
|
+
* ```
|
|
377
698
|
*/
|
|
378
699
|
removeLiquidity(args: {
|
|
379
700
|
token0: string | TokenClassKey;
|
|
@@ -387,83 +708,71 @@ export declare class GSwapService extends LoggerBase {
|
|
|
387
708
|
positionId?: string;
|
|
388
709
|
}): Promise<GSwapAddLiquidityResult>;
|
|
389
710
|
/**
|
|
390
|
-
* Collect accumulated trading fees from a concentrated liquidity position
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
* -
|
|
405
|
-
* -
|
|
406
|
-
* -
|
|
407
|
-
* -
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
* - Both formats normalized to TokenClassKey for bundler submission
|
|
426
|
-
*
|
|
427
|
-
* @param args Fee collection parameters
|
|
428
|
-
* @param args.token0 First token (string or TokenClassKey)
|
|
429
|
-
* @param args.token1 Second token (string or TokenClassKey)
|
|
430
|
-
* @param args.fee Fee tier in basis points (500, 3000, or 10000)
|
|
431
|
-
* @param args.tickLower Lower tick boundary of the position
|
|
432
|
-
* @param args.tickUpper Upper tick boundary of the position
|
|
433
|
-
* @param args.amount0Requested Optional amount of token0 fees to collect (default: '0' = all)
|
|
434
|
-
* @param args.amount1Requested Optional amount of token1 fees to collect (default: '0' = all)
|
|
435
|
-
* @param args.positionId Optional position ID for tracking/verification
|
|
436
|
-
*
|
|
437
|
-
* @returns Promise<GSwapCollectFeesResult> Transaction result with:
|
|
438
|
-
* - transactionId: Bundler transaction ID
|
|
439
|
-
* - status: Transaction status from WebSocket (or 'SUBMITTED' if timeout)
|
|
440
|
-
* - timestamp: When transaction was submitted
|
|
441
|
-
* - wait(): Async method to monitor or retry confirmation
|
|
442
|
-
*
|
|
443
|
-
* @throws GSwapPositionError if private key unavailable or bundler submission fails
|
|
444
|
-
*
|
|
445
|
-
* @example
|
|
446
|
-
* // Get position with accumulated fees
|
|
447
|
-
* const positions = await sdk.getSwapUserLiquidityPositions(walletAddress);
|
|
448
|
-
* const position = positions[0];
|
|
449
|
-
*
|
|
711
|
+
* Collect accumulated trading fees from a concentrated liquidity position (partial or complete)
|
|
712
|
+
*
|
|
713
|
+
* Claims trading fees that have accumulated in your liquidity position without affecting the
|
|
714
|
+
* position's liquidity. Fees only accumulate when your position is in-range (current price within
|
|
715
|
+
* your tick boundaries) and trades execute in that range. Supports collecting all fees at once
|
|
716
|
+
* (default with '0' amounts) or specific amounts for capital management strategies. Automatically
|
|
717
|
+
* connects WebSocket before transaction submission to monitor confirmation.
|
|
718
|
+
*
|
|
719
|
+
* @param args - Fee collection parameters (supports two patterns: direct parameters or position lookup)
|
|
720
|
+
* @param args.token0 - First token (pipe-delimited string or TokenClassKey, required unless using ownerAddress pattern)
|
|
721
|
+
* @param args.token1 - Second token (pipe-delimited string or TokenClassKey, required unless using ownerAddress pattern)
|
|
722
|
+
* @param args.fee - Pool fee tier in basis points (500, 3000, or 10000, required unless using ownerAddress pattern)
|
|
723
|
+
* @param args.tickLower - Lower tick boundary of the position (required unless using ownerAddress pattern)
|
|
724
|
+
* @param args.tickUpper - Upper tick boundary of the position (required unless using ownerAddress pattern)
|
|
725
|
+
* @param args.amount0Requested - Optional token0 fee amount to collect (default: '0' = collect all)
|
|
726
|
+
* @param args.amount1Requested - Optional token1 fee amount to collect (default: '0' = collect all)
|
|
727
|
+
* @param args.positionId - Optional position ID for tracking and verification
|
|
728
|
+
* @param args.ownerAddress - Alternative pattern: fetch position details first using this address and positionId
|
|
729
|
+
* @param args.amount0Max - Alternative naming for amount0Requested (MCP tool compatibility)
|
|
730
|
+
* @param args.amount1Max - Alternative naming for amount1Requested (MCP tool compatibility)
|
|
731
|
+
* @returns Promise<GSwapAddLiquidityResult> Transaction result with transactionId, status, timestamp, and wait() helper
|
|
732
|
+
* @throws {Error} If private key not available, position not found, or transaction fails
|
|
733
|
+
* @since 4.0.4-beta.0
|
|
734
|
+
* @category Services
|
|
735
|
+
*
|
|
736
|
+
* @example Collect all accumulated fees from a position
|
|
737
|
+
* ```typescript
|
|
738
|
+
* // Step 1: Get position details to check accumulated fees
|
|
739
|
+
* const positions = await gswapService.getUserLiquidityPositions('eth|0x1234...');
|
|
740
|
+
* const position = positions.items[0];
|
|
741
|
+
*
|
|
742
|
+
* console.log(`Token0 fees: ${position.feeAmount0}`);
|
|
743
|
+
* console.log(`Token1 fees: ${position.feeAmount1}`);
|
|
744
|
+
*
|
|
745
|
+
* // Step 2: Collect all fees if there are any
|
|
450
746
|
* if (parseFloat(position.feeAmount0) > 0 || parseFloat(position.feeAmount1) > 0) {
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
* fee: 3000,
|
|
747
|
+
* const result = await gswapService.collectPositionFees({
|
|
748
|
+
* token0: position.token0,
|
|
749
|
+
* token1: position.token1,
|
|
750
|
+
* fee: position.feeTier,
|
|
456
751
|
* tickLower: position.tickLower,
|
|
457
752
|
* tickUpper: position.tickUpper,
|
|
458
|
-
* amount0Requested: '0', //
|
|
459
|
-
* amount1Requested: '0', //
|
|
460
|
-
* positionId: position.positionId
|
|
753
|
+
* amount0Requested: '0', // '0' means collect ALL token0 fees
|
|
754
|
+
* amount1Requested: '0', // '0' means collect ALL token1 fees
|
|
755
|
+
* positionId: position.positionId
|
|
461
756
|
* });
|
|
462
757
|
*
|
|
463
|
-
* console.log(
|
|
464
|
-
* await result.wait();
|
|
465
|
-
* console.log('
|
|
758
|
+
* console.log(`Fee collection submitted: ${result.transactionId}`);
|
|
759
|
+
* await result.wait?.();
|
|
760
|
+
* console.log('All fees collected successfully');
|
|
466
761
|
* }
|
|
762
|
+
* ```
|
|
763
|
+
*
|
|
764
|
+
* @example Collect fees using position lookup pattern (MCP tool compatible)
|
|
765
|
+
* ```typescript
|
|
766
|
+
* // Alternative pattern that fetches position details automatically
|
|
767
|
+
* const result = await gswapService.collectPositionFees({
|
|
768
|
+
* ownerAddress: 'eth|0x1234...',
|
|
769
|
+
* positionId: 'position-uuid',
|
|
770
|
+
* amount0Max: '0', // Collect all token0 fees (MCP naming)
|
|
771
|
+
* amount1Max: '0' // Collect all token1 fees (MCP naming)
|
|
772
|
+
* });
|
|
773
|
+
*
|
|
774
|
+
* console.log(`Fees collected: ${result.status}`);
|
|
775
|
+
* ```
|
|
467
776
|
*/
|
|
468
777
|
collectPositionFees(args: {
|
|
469
778
|
token0?: string | TokenClassKey;
|