@cetusprotocol/dlmm-zap-sdk 1.0.2 → 1.0.3
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/dist/index.d.ts +576 -5
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import * as _cetusprotocol_aggregator_sdk from '@cetusprotocol/aggregator-sdk';
|
|
1
2
|
import { AggregatorClient } from '@cetusprotocol/aggregator-sdk';
|
|
2
3
|
import { StrategyType, BinAmount, BinLiquidityInfo, CetusDlmmSDK } from '@cetusprotocol/dlmm-sdk';
|
|
3
|
-
import { CoinPairType, IModule, SdkWrapper, BaseSdkOptions, BaseError } from '@cetusprotocol/common-sdk';
|
|
4
|
+
import { CoinPairType, IModule, SuiObjectIdType, SuiAddressType, SdkWrapper, BaseSdkOptions, BaseError } from '@cetusprotocol/common-sdk';
|
|
5
|
+
import * as _mysten_sui_transactions from '@mysten/sui/transactions';
|
|
4
6
|
import { TransactionObjectArgument, Transaction } from '@mysten/sui/transactions';
|
|
5
|
-
import Decimal from 'decimal.js';
|
|
7
|
+
import * as Decimal from 'decimal.js';
|
|
8
|
+
import Decimal__default from 'decimal.js';
|
|
6
9
|
|
|
7
10
|
declare const defaultSwapSlippage = 0.005;
|
|
8
11
|
/**
|
|
@@ -142,6 +145,509 @@ declare class ZapModule implements IModule<CetusDlmmZapSDK> {
|
|
|
142
145
|
buildWithdrawPayload(options: WithdrawOptions): Promise<Transaction>;
|
|
143
146
|
}
|
|
144
147
|
|
|
148
|
+
/**
|
|
149
|
+
* Common parameters shared across multiple compound operations
|
|
150
|
+
*/
|
|
151
|
+
type CommonParams = {
|
|
152
|
+
/**
|
|
153
|
+
* The object id about which pool you want to operation.
|
|
154
|
+
*/
|
|
155
|
+
pool_id: SuiObjectIdType;
|
|
156
|
+
/**
|
|
157
|
+
* The object id about position.
|
|
158
|
+
*/
|
|
159
|
+
pos_id: SuiObjectIdType;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Parameters for closing position and returning amount coins with merge swap functionality
|
|
163
|
+
*/
|
|
164
|
+
type ClosePosReturnAmountCoinAParams = CommonParams & CoinPairType & {
|
|
165
|
+
remove_percent?: number;
|
|
166
|
+
active_id: number;
|
|
167
|
+
bin_step: number;
|
|
168
|
+
slippage: number;
|
|
169
|
+
bin_infos: BinLiquidityInfo;
|
|
170
|
+
/**
|
|
171
|
+
* Coin types associated with rewarder contracts.
|
|
172
|
+
*/
|
|
173
|
+
rewarder_coin_types: SuiAddressType[];
|
|
174
|
+
close_position?: boolean;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Parameters for closing position and returning only amount coins without merge swap
|
|
178
|
+
*/
|
|
179
|
+
type ClosePosOnlyReturnAmountCoinsParams = CommonParams & CoinPairType & {
|
|
180
|
+
remove_percent?: number;
|
|
181
|
+
active_id: number;
|
|
182
|
+
bin_step: number;
|
|
183
|
+
slippage: number;
|
|
184
|
+
bin_infos: BinLiquidityInfo;
|
|
185
|
+
rewarder_coin_types: string[];
|
|
186
|
+
close_position?: boolean;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Parameters for collecting fees and rewards and returning coins
|
|
190
|
+
*/
|
|
191
|
+
type CollectFeeAndRewardsAndReturnCoinsParams = CommonParams & CoinPairType & {
|
|
192
|
+
/**
|
|
193
|
+
* Coin types associated with rewarder contracts
|
|
194
|
+
*/
|
|
195
|
+
rewarder_coin_types: SuiAddressType[];
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Parameters for calculating claim merge swap routes
|
|
199
|
+
*/
|
|
200
|
+
type CalculateClaimMergeParams = CoinPairType & {
|
|
201
|
+
/**
|
|
202
|
+
* The object id about which pool you want to operation
|
|
203
|
+
*/
|
|
204
|
+
pool_id: string;
|
|
205
|
+
/**
|
|
206
|
+
* The object id about position
|
|
207
|
+
*/
|
|
208
|
+
position_id: string;
|
|
209
|
+
/**
|
|
210
|
+
* Array of rewarder coin types
|
|
211
|
+
*/
|
|
212
|
+
rewarder_types: string[];
|
|
213
|
+
/**
|
|
214
|
+
* Target coin type for merge swap
|
|
215
|
+
*/
|
|
216
|
+
target_coin_type: string;
|
|
217
|
+
not_merge_coins: string[];
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Parameters for creating claim merge swap payload
|
|
221
|
+
*/
|
|
222
|
+
type CreateClaimMergePayloadParams = CoinPairType & {
|
|
223
|
+
/**
|
|
224
|
+
* The object id about which pool you want to operation
|
|
225
|
+
*/
|
|
226
|
+
pool_id: string;
|
|
227
|
+
/**
|
|
228
|
+
* The object id about position
|
|
229
|
+
*/
|
|
230
|
+
pos_id: string;
|
|
231
|
+
/**
|
|
232
|
+
* Array of rewarder coin types
|
|
233
|
+
*/
|
|
234
|
+
rewarder_coin_types: string[];
|
|
235
|
+
/**
|
|
236
|
+
* Coins to exclude from merge swap
|
|
237
|
+
*/
|
|
238
|
+
not_merge_coins: string[];
|
|
239
|
+
/**
|
|
240
|
+
* Router configuration for merge swap
|
|
241
|
+
*/
|
|
242
|
+
merge_routers: any;
|
|
243
|
+
/**
|
|
244
|
+
* Slippage tolerance for the swap
|
|
245
|
+
*/
|
|
246
|
+
slippage: number;
|
|
247
|
+
/**
|
|
248
|
+
* Target coin type for merge swap
|
|
249
|
+
*/
|
|
250
|
+
target_coin_type: string;
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* Parameters for calculating optimal rebalancing
|
|
254
|
+
*/
|
|
255
|
+
type CalculateRebalanceParams = {
|
|
256
|
+
/**
|
|
257
|
+
* The object id about which pool you want to operation
|
|
258
|
+
*/
|
|
259
|
+
pool_id: string;
|
|
260
|
+
/**
|
|
261
|
+
* Coin type for the first token in the pair
|
|
262
|
+
*/
|
|
263
|
+
coin_type_a: string;
|
|
264
|
+
/**
|
|
265
|
+
* Coin type for the second token in the pair
|
|
266
|
+
*/
|
|
267
|
+
coin_type_b: string;
|
|
268
|
+
/**
|
|
269
|
+
* Decimal precision for the first coin
|
|
270
|
+
*/
|
|
271
|
+
coin_decimal_a: number;
|
|
272
|
+
/**
|
|
273
|
+
* Decimal precision for the second coin
|
|
274
|
+
*/
|
|
275
|
+
coin_decimal_b: number;
|
|
276
|
+
/**
|
|
277
|
+
* Current amount of the first coin
|
|
278
|
+
*/
|
|
279
|
+
amount_a: string;
|
|
280
|
+
/**
|
|
281
|
+
* Current amount of the second coin
|
|
282
|
+
*/
|
|
283
|
+
amount_b: string;
|
|
284
|
+
lower_bin_id: number;
|
|
285
|
+
upper_bin_id: number;
|
|
286
|
+
active_id: number;
|
|
287
|
+
bin_step: number;
|
|
288
|
+
strategy_type: StrategyType;
|
|
289
|
+
active_bin_of_pool?: BinAmount;
|
|
290
|
+
/**
|
|
291
|
+
* Slippage tolerance for swaps
|
|
292
|
+
*/
|
|
293
|
+
slippage: number;
|
|
294
|
+
/**
|
|
295
|
+
* Maximum remaining rate threshold (optional, default: 0.01)
|
|
296
|
+
*/
|
|
297
|
+
max_remain_rate?: number;
|
|
298
|
+
/**
|
|
299
|
+
* Mark price for calculation (optional)
|
|
300
|
+
*/
|
|
301
|
+
mark_price?: string;
|
|
302
|
+
/**
|
|
303
|
+
* Loop counter for price verification (optional, default: 0)
|
|
304
|
+
*/
|
|
305
|
+
verify_price_loop?: number;
|
|
306
|
+
old_pos_origin_amount_a?: string;
|
|
307
|
+
old_pos_origin_amount_b?: string;
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* Result of rebalancing calculation with optimal allocation
|
|
311
|
+
*/
|
|
312
|
+
type RebalanceResult = {
|
|
313
|
+
bin_infos: BinLiquidityInfo;
|
|
314
|
+
lower_bin_id: number;
|
|
315
|
+
upper_bin_id: number;
|
|
316
|
+
/**
|
|
317
|
+
* Amount of the first coin to use
|
|
318
|
+
*/
|
|
319
|
+
use_amount_a: string;
|
|
320
|
+
/**
|
|
321
|
+
* Amount of the second coin to use
|
|
322
|
+
*/
|
|
323
|
+
use_amount_b: string;
|
|
324
|
+
/**
|
|
325
|
+
* Whether the first coin amount is fixed
|
|
326
|
+
*/
|
|
327
|
+
fix_amount_a: boolean;
|
|
328
|
+
/**
|
|
329
|
+
* Remaining amount after optimal allocation
|
|
330
|
+
*/
|
|
331
|
+
remain_amount: string;
|
|
332
|
+
/**
|
|
333
|
+
* Swap result if rebalancing requires swapping (optional)
|
|
334
|
+
*/
|
|
335
|
+
swap_result?: any;
|
|
336
|
+
/**
|
|
337
|
+
* Error message if rebalancing fails (optional)
|
|
338
|
+
*/
|
|
339
|
+
error?: string;
|
|
340
|
+
swap_amount_in?: string;
|
|
341
|
+
swap_in_coin_type?: string;
|
|
342
|
+
};
|
|
343
|
+
/**
|
|
344
|
+
* Parameters for creating move position payload to migrate from old range to new range
|
|
345
|
+
*/
|
|
346
|
+
type CreateMovePositionPayloadParams = {
|
|
347
|
+
/**
|
|
348
|
+
* Old position details
|
|
349
|
+
*/
|
|
350
|
+
oldPos: {
|
|
351
|
+
/**
|
|
352
|
+
* The object id about which pool you want to operation
|
|
353
|
+
*/
|
|
354
|
+
pool_id: string;
|
|
355
|
+
/**
|
|
356
|
+
* The object id about position
|
|
357
|
+
*/
|
|
358
|
+
pos_id: string;
|
|
359
|
+
/**
|
|
360
|
+
* Coin type for the first token in the pair
|
|
361
|
+
*/
|
|
362
|
+
coin_type_a: SuiAddressType;
|
|
363
|
+
/**
|
|
364
|
+
* Coin type for the second token in the pair
|
|
365
|
+
*/
|
|
366
|
+
coin_type_b: SuiAddressType;
|
|
367
|
+
/**
|
|
368
|
+
* Coin types associated with rewarder contracts
|
|
369
|
+
*/
|
|
370
|
+
rewarder_coin_types: SuiAddressType[];
|
|
371
|
+
active_id: number;
|
|
372
|
+
bin_step: number;
|
|
373
|
+
slippage: number;
|
|
374
|
+
bin_infos: BinLiquidityInfo;
|
|
375
|
+
remove_percent?: number;
|
|
376
|
+
close_position?: boolean;
|
|
377
|
+
};
|
|
378
|
+
/**
|
|
379
|
+
* New position details
|
|
380
|
+
*/
|
|
381
|
+
newPos: {
|
|
382
|
+
lower_bin_id: number;
|
|
383
|
+
upper_bin_id: number;
|
|
384
|
+
active_id: number;
|
|
385
|
+
bin_step: number;
|
|
386
|
+
strategy_type: StrategyType;
|
|
387
|
+
active_bin_of_pool?: BinAmount;
|
|
388
|
+
};
|
|
389
|
+
/**
|
|
390
|
+
* Pre-calculated rebalancing result
|
|
391
|
+
*/
|
|
392
|
+
rebalancePre: RebalanceResult;
|
|
393
|
+
/**
|
|
394
|
+
* Slippage tolerance for swaps
|
|
395
|
+
*/
|
|
396
|
+
slippage: number;
|
|
397
|
+
/**
|
|
398
|
+
* Optional merge swap configuration
|
|
399
|
+
*/
|
|
400
|
+
rewarderMergeOption?: {
|
|
401
|
+
/**
|
|
402
|
+
* Router configuration for merge swap
|
|
403
|
+
*/
|
|
404
|
+
merge_routers: any;
|
|
405
|
+
/**
|
|
406
|
+
* Slippage tolerance for merge swap
|
|
407
|
+
*/
|
|
408
|
+
slippage: number;
|
|
409
|
+
/**
|
|
410
|
+
* Coins to exclude from merge swap
|
|
411
|
+
*/
|
|
412
|
+
not_merge_coins: string[];
|
|
413
|
+
};
|
|
414
|
+
/**
|
|
415
|
+
* Whether fees and rewards have already been claimed (optional)
|
|
416
|
+
*/
|
|
417
|
+
have_claim?: boolean;
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
420
|
+
* Parameters for pre-calculating swap operations
|
|
421
|
+
*/
|
|
422
|
+
type PreSwapParams = {
|
|
423
|
+
/**
|
|
424
|
+
* The object id about which pool you want to operation
|
|
425
|
+
*/
|
|
426
|
+
pool_id: string;
|
|
427
|
+
/**
|
|
428
|
+
* Source coin type for the swap
|
|
429
|
+
*/
|
|
430
|
+
from_coin_type: string;
|
|
431
|
+
/**
|
|
432
|
+
* Target coin type for the swap
|
|
433
|
+
*/
|
|
434
|
+
target_coin_type: string;
|
|
435
|
+
/**
|
|
436
|
+
* Amount to swap
|
|
437
|
+
*/
|
|
438
|
+
amount: string;
|
|
439
|
+
/**
|
|
440
|
+
* Decimal precision for the source coin
|
|
441
|
+
*/
|
|
442
|
+
from_coin_decimal: number;
|
|
443
|
+
/**
|
|
444
|
+
* Decimal precision for the target coin
|
|
445
|
+
*/
|
|
446
|
+
target_coin_decimal: number;
|
|
447
|
+
/**
|
|
448
|
+
* Whether swapping from coin A to coin B
|
|
449
|
+
*/
|
|
450
|
+
is_a2b: boolean;
|
|
451
|
+
/**
|
|
452
|
+
* Slippage tolerance for the swap
|
|
453
|
+
*/
|
|
454
|
+
slippage: number;
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* Parameters for creating compound rebalance add payload
|
|
458
|
+
*/
|
|
459
|
+
type CreateCompoundRebalanceAddPayload = {
|
|
460
|
+
/**
|
|
461
|
+
* Base parameters for the compound operation
|
|
462
|
+
*/
|
|
463
|
+
baseParams: {
|
|
464
|
+
/**
|
|
465
|
+
* The object id about which pool you want to operation
|
|
466
|
+
*/
|
|
467
|
+
pool_id: string;
|
|
468
|
+
/**
|
|
469
|
+
* The object id about position
|
|
470
|
+
*/
|
|
471
|
+
pos_id: string;
|
|
472
|
+
/**
|
|
473
|
+
* Coin type for the first token in the pair
|
|
474
|
+
*/
|
|
475
|
+
coin_type_a: SuiAddressType;
|
|
476
|
+
/**
|
|
477
|
+
* Coin type for the second token in the pair
|
|
478
|
+
*/
|
|
479
|
+
coin_type_b: SuiAddressType;
|
|
480
|
+
/**
|
|
481
|
+
* Coin types associated with rewarder contracts
|
|
482
|
+
*/
|
|
483
|
+
rewarder_coin_types: SuiAddressType[];
|
|
484
|
+
active_id: number;
|
|
485
|
+
bin_step: number;
|
|
486
|
+
strategy_type: StrategyType;
|
|
487
|
+
active_bin_of_pool?: BinAmount;
|
|
488
|
+
};
|
|
489
|
+
/**
|
|
490
|
+
* Pre-calculated rebalancing result
|
|
491
|
+
*/
|
|
492
|
+
rebalancePre: RebalanceResult;
|
|
493
|
+
/**
|
|
494
|
+
* Merge swap configuration for rewarders
|
|
495
|
+
*/
|
|
496
|
+
rewarderMergeOption: {
|
|
497
|
+
/**
|
|
498
|
+
* Router configuration for merge swap
|
|
499
|
+
*/
|
|
500
|
+
merge_routers: any;
|
|
501
|
+
/**
|
|
502
|
+
* Slippage tolerance for merge swap
|
|
503
|
+
*/
|
|
504
|
+
slippage: number;
|
|
505
|
+
/**
|
|
506
|
+
* Coins to exclude from merge swap
|
|
507
|
+
*/
|
|
508
|
+
not_merge_coins: string[];
|
|
509
|
+
};
|
|
510
|
+
/**
|
|
511
|
+
* Optional transaction object (creates new one if not provided)
|
|
512
|
+
*/
|
|
513
|
+
tx?: Transaction;
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* DLMM 复投/调仓模块。
|
|
518
|
+
* 该模块负责三类核心能力:
|
|
519
|
+
* 1) 仓位手续费与奖励的归集、可选合并兑换;
|
|
520
|
+
* 2) 根据目标配比计算再平衡(是否需要先 swap);
|
|
521
|
+
* 3) 关老仓并把资产迁移到新价格区间(move position)。
|
|
522
|
+
*/
|
|
523
|
+
declare class CompoundModule implements IModule<CetusDlmmZapSDK> {
|
|
524
|
+
protected _sdk: CetusDlmmZapSDK;
|
|
525
|
+
constructor(sdk: CetusDlmmZapSDK);
|
|
526
|
+
get sdk(): CetusDlmmZapSDK;
|
|
527
|
+
/** 统一滑点处理:按向下取整保守估算可得数量,避免高估导致后续交易失败。 */
|
|
528
|
+
private calculateAmountWithSlippage;
|
|
529
|
+
/**
|
|
530
|
+
* 拉取单个仓位当前可领取的 fee/reward 快照。
|
|
531
|
+
* 注意:这里只做读取,不构建交易,也不改变链上状态。
|
|
532
|
+
*/
|
|
533
|
+
private fetchFeeAndRewardSnapshot;
|
|
534
|
+
/**
|
|
535
|
+
* 获取“归集后可用”的 A/B 两币数量:
|
|
536
|
+
* - fee + reward 中同币种会合并到 coin_amount_a / coin_amount_b;
|
|
537
|
+
* - 其它奖励币会尝试聚合路由估算后并入目标币;
|
|
538
|
+
* - not_merge_coins 中的币不会进入 merge swap。
|
|
539
|
+
*/
|
|
540
|
+
getFeeAndReward(params: {
|
|
541
|
+
pool_id: string;
|
|
542
|
+
position_id: string;
|
|
543
|
+
coin_type_a: SuiAddressType;
|
|
544
|
+
coin_type_b: SuiAddressType;
|
|
545
|
+
rewarder_types: string[];
|
|
546
|
+
merge_swap_target_coin_type: string;
|
|
547
|
+
not_merge_coins: string[];
|
|
548
|
+
}): Promise<{
|
|
549
|
+
coin_amount_a: string;
|
|
550
|
+
coin_amount_b: string;
|
|
551
|
+
merge_routers: _cetusprotocol_aggregator_sdk.MergeSwapRouterData | null | undefined;
|
|
552
|
+
}>;
|
|
553
|
+
/**
|
|
554
|
+
* 计算“claim 后一次性 merge 到目标币”的路由输入集合。
|
|
555
|
+
* 返回 null 表示无可合并资产,调用方可直接跳过 merge 流程。
|
|
556
|
+
*/
|
|
557
|
+
calculateClaimMerge(params: CalculateClaimMergeParams): Promise<_cetusprotocol_aggregator_sdk.MergeSwapRouterData | null>;
|
|
558
|
+
/**
|
|
559
|
+
* 计算再平衡方案:
|
|
560
|
+
* 1) 先用当前 A/B 数量求“理论可加仓分布”;
|
|
561
|
+
* 2) 若明显偏单边,则按目标配比求需 swap 数量;
|
|
562
|
+
* 3) 使用 swap 后的真实数量重新计算最终 bin_infos。
|
|
563
|
+
*/
|
|
564
|
+
calculateRebalance(params: CalculateRebalanceParams): Promise<RebalanceResult>;
|
|
565
|
+
/** 单次预交换查询:返回路由、路由价格、滑点后最小可得数量。 */
|
|
566
|
+
preSwap(params: PreSwapParams): Promise<{
|
|
567
|
+
swapResult: any;
|
|
568
|
+
routerPrice: string;
|
|
569
|
+
swapAmountOutWithSlippage: string;
|
|
570
|
+
}>;
|
|
571
|
+
/**
|
|
572
|
+
* 构造“领取 fee/reward 且不立即转账”的交易片段,并把同币奖励合并到 fee 结果中:
|
|
573
|
+
* - fee_a / fee_b 作为后续复投主输入;
|
|
574
|
+
* - 其它奖励币独立返回,交给上层决定是 merge 还是直接转走。
|
|
575
|
+
*/
|
|
576
|
+
collectFeeAndRewardsAndReturnCoins(params: {
|
|
577
|
+
pool_id: string;
|
|
578
|
+
pos_id: string;
|
|
579
|
+
coin_type_a: string;
|
|
580
|
+
coin_type_b: string;
|
|
581
|
+
rewarder_coin_types: string[];
|
|
582
|
+
}, tx: Transaction): Promise<{
|
|
583
|
+
fee_a: _mysten_sui_transactions.TransactionObjectArgument;
|
|
584
|
+
fee_b: _mysten_sui_transactions.TransactionObjectArgument;
|
|
585
|
+
other_rewarder: Record<string, any>;
|
|
586
|
+
}>;
|
|
587
|
+
/**
|
|
588
|
+
* 领取并处理奖励:
|
|
589
|
+
* - A/B 同币奖励直接并入 coin_a/coin_b;
|
|
590
|
+
* - 可 merge 的其它奖励币收集进 mergeInputCoinMap;
|
|
591
|
+
* - 不处理的其它奖励币直接转回用户地址。
|
|
592
|
+
*/
|
|
593
|
+
claimFeeAndRewardsAndMergeRewards(baseParams: {
|
|
594
|
+
pool_id: string;
|
|
595
|
+
pos_id: string;
|
|
596
|
+
coin_type_a: SuiAddressType;
|
|
597
|
+
coin_type_b: SuiAddressType;
|
|
598
|
+
rewarder_coin_types: SuiAddressType[];
|
|
599
|
+
}, rewarderMergeOption?: {
|
|
600
|
+
merge_routers: any;
|
|
601
|
+
slippage: number;
|
|
602
|
+
not_merge_coins: string[];
|
|
603
|
+
}, tx?: Transaction): Promise<{
|
|
604
|
+
coin_a: any;
|
|
605
|
+
coin_b: any;
|
|
606
|
+
}>;
|
|
607
|
+
/**
|
|
608
|
+
* 关闭或部分移除老仓,仅返回“仓位本金币对象”:
|
|
609
|
+
* - fee/reward 先领取并直接转给用户;
|
|
610
|
+
* - close_position=true 走 closePosition;
|
|
611
|
+
* - 否则走 removeLiquidity(按 remove_percent)。
|
|
612
|
+
*/
|
|
613
|
+
closePosOnlyReturnAmountCoins(params: ClosePosOnlyReturnAmountCoinsParams, tx: Transaction): Promise<{
|
|
614
|
+
coin_a: _mysten_sui_transactions.TransactionObjectArgument;
|
|
615
|
+
coin_b: _mysten_sui_transactions.TransactionObjectArgument;
|
|
616
|
+
}>;
|
|
617
|
+
/**
|
|
618
|
+
* 关闭/部分移除仓位并保留 A/B 两币对象:
|
|
619
|
+
* - 与 closePosOnlyReturnAmountCoins 的区别是,这里会先做奖励 merge;
|
|
620
|
+
* - 最终把仓位本金并回 coin_a/coin_b,作为后续复投输入。
|
|
621
|
+
*/
|
|
622
|
+
closePosReturnCoinWithMerge(params: ClosePosReturnAmountCoinAParams, rewarderMergeOption?: {
|
|
623
|
+
merge_routers: any;
|
|
624
|
+
slippage: number;
|
|
625
|
+
not_merge_coins: string[];
|
|
626
|
+
}, tx?: Transaction): Promise<{
|
|
627
|
+
coin_a: any;
|
|
628
|
+
coin_b: any;
|
|
629
|
+
}>;
|
|
630
|
+
/**
|
|
631
|
+
* 仅构建 claim + merge + transfer 的独立交易:
|
|
632
|
+
* 适用于“先把奖励统一换成目标币并提现”场景,不含加仓行为。
|
|
633
|
+
*/
|
|
634
|
+
createClaimMergePayload(params: CreateClaimMergePayloadParams): Promise<Transaction>;
|
|
635
|
+
/**
|
|
636
|
+
* 复投主流程(不迁仓):
|
|
637
|
+
* - 先 claim + 可选 merge;
|
|
638
|
+
* - 若 rebalance 需要 swap,则在 tx 内先完成路由兑换;
|
|
639
|
+
* - 最后按 rebalance 计算结果 addLiquidity 回原仓位。
|
|
640
|
+
*/
|
|
641
|
+
createCompoundRebalanceAddPayload(params: CreateCompoundRebalanceAddPayload): Promise<Transaction>;
|
|
642
|
+
/**
|
|
643
|
+
* 迁仓主流程(move position):
|
|
644
|
+
* 1) 老仓位取回资产(可选是否已 claim);
|
|
645
|
+
* 2) 按 rebalancePre 需要执行一次 swap;
|
|
646
|
+
* 3) 将资产按新 bin 区间 addLiquidity 到新仓位配置。
|
|
647
|
+
*/
|
|
648
|
+
createMovePositionPayload(params: CreateMovePositionPayloadParams, tx?: Transaction): Promise<Transaction>;
|
|
649
|
+
}
|
|
650
|
+
|
|
145
651
|
/**
|
|
146
652
|
* Represents options and configurations for an SDK.
|
|
147
653
|
*/
|
|
@@ -167,6 +673,7 @@ declare class CetusDlmmZapSDK extends SdkWrapper<SdkOptions> {
|
|
|
167
673
|
* Module for managing vaults.
|
|
168
674
|
*/
|
|
169
675
|
protected _zapModule: ZapModule;
|
|
676
|
+
protected _compoundModule: CompoundModule;
|
|
170
677
|
protected _dlmmSDK: CetusDlmmSDK;
|
|
171
678
|
/**
|
|
172
679
|
* Client for interacting with the Aggregator service.
|
|
@@ -198,6 +705,7 @@ declare class CetusDlmmZapSDK extends SdkWrapper<SdkOptions> {
|
|
|
198
705
|
* @returns {ZapModule} The ZapModule property value.
|
|
199
706
|
*/
|
|
200
707
|
get Zap(): ZapModule;
|
|
708
|
+
get Compound(): CompoundModule;
|
|
201
709
|
/**
|
|
202
710
|
* Static factory method to initialize the SDK
|
|
203
711
|
* @param options SDK initialization options
|
|
@@ -238,7 +746,7 @@ declare function calculateLiquidityAmountEnough(amount_a: string, amount_b: stri
|
|
|
238
746
|
liquidity: string;
|
|
239
747
|
amount_limit_a: string;
|
|
240
748
|
amount_limit_b: string;
|
|
241
|
-
remain_amount:
|
|
749
|
+
remain_amount: Decimal__default;
|
|
242
750
|
};
|
|
243
751
|
/**
|
|
244
752
|
* Calculate the optimal side for adding liquidity based on current price and tick range
|
|
@@ -266,7 +774,7 @@ declare function calculateLiquidityAmountSide(amount_a: string, amount_b: string
|
|
|
266
774
|
liquidity: string;
|
|
267
775
|
amount_limit_a: string;
|
|
268
776
|
amount_limit_b: string;
|
|
269
|
-
remain_amount:
|
|
777
|
+
remain_amount: Decimal__default;
|
|
270
778
|
fix_liquidity_amount_a: boolean;
|
|
271
779
|
};
|
|
272
780
|
/**
|
|
@@ -285,12 +793,75 @@ declare function calculateLiquidityAmountSide(amount_a: string, amount_b: string
|
|
|
285
793
|
* - final_amount_a: Final amount of token A (remaining A when fix_amount_a=true, obtained A when fix_amount_a=false)
|
|
286
794
|
* - final_amount_b: Final amount of token B (obtained B when fix_amount_a=true, remaining B when fix_amount_a=false)
|
|
287
795
|
*/
|
|
796
|
+
/**
|
|
797
|
+
* Calculate the swap amount needed to adjust two coin balances to a target ratio.
|
|
798
|
+
*
|
|
799
|
+
* The function automatically determines whether to swap A→B or B→A based on
|
|
800
|
+
* the current balances and the target ratio, then binary-searches for the
|
|
801
|
+
* minimal swap size that brings the final B/A ratio within 0.1 % of `target_ratio`.
|
|
802
|
+
*
|
|
803
|
+
* @param amount_a - Current amount of coin A
|
|
804
|
+
* @param amount_b - Current amount of coin B
|
|
805
|
+
* @param current_price - Real exchange rate expressed as B/A (how many B per 1 A)
|
|
806
|
+
* @param target_ratio - Desired final ratio expressed as B/A (final_b / final_a)
|
|
807
|
+
* @returns
|
|
808
|
+
* - swap_amount: Amount to swap (denominated in the source coin)
|
|
809
|
+
* - final_amount_a: Final amount of coin A after the swap
|
|
810
|
+
* - final_amount_b: Final amount of coin B after the swap
|
|
811
|
+
* - a_to_b: Swap direction – true = sell A for B, false = sell B for A
|
|
812
|
+
*/
|
|
813
|
+
declare function calcSwapAmountForTargetRatio(amount_a: string, amount_b: string, current_price: string, target_ratio: string): {
|
|
814
|
+
swap_amount: string;
|
|
815
|
+
final_amount_a: string;
|
|
816
|
+
final_amount_b: string;
|
|
817
|
+
a_to_b: boolean;
|
|
818
|
+
};
|
|
288
819
|
declare function calcExactSwapAmount(coin_amount: string, fix_amount_a: boolean, current_price: string, target_ratio: string): {
|
|
289
820
|
swap_amount: string;
|
|
290
821
|
final_amount_a: string;
|
|
291
822
|
final_amount_b: string;
|
|
292
823
|
};
|
|
293
824
|
|
|
825
|
+
/**
|
|
826
|
+
* Calculate liquidity amounts with fallback strategy
|
|
827
|
+
* First tries to fix amount_a, if not enough then tries to fix amount_b
|
|
828
|
+
* @param current_sqrt_price - Current sqrt price of the pool
|
|
829
|
+
* @param tick_lower - Lower tick boundary of the position
|
|
830
|
+
* @param tick_upper - Upper tick boundary of the position
|
|
831
|
+
* @param amount_a - Amount of token A available
|
|
832
|
+
* @param amount_b - Amount of token B available
|
|
833
|
+
* @param slippage - Slippage tolerance for the calculation
|
|
834
|
+
* @returns Object containing:
|
|
835
|
+
* - liquidity: Calculated liquidity amount
|
|
836
|
+
* - use_amount_a: Amount of token A to be used
|
|
837
|
+
* - use_amount_b: Amount of token B to be used
|
|
838
|
+
* - amount_limit_a: Minimum amount limit for token A
|
|
839
|
+
* - amount_limit_b: Minimum amount limit for token B
|
|
840
|
+
* - fix_amount_a: Whether amount A was fixed (true) or amount B was fixed (false)
|
|
841
|
+
* - remain_amount: Remaining amount of the non-fixed token
|
|
842
|
+
* - is_enough_amount: Whether there was enough amount for the calculation
|
|
843
|
+
*/
|
|
844
|
+
declare function calculateLiquidityWithFallback({ current_sqrt_price, tick_lower, tick_upper, amount_a, amount_b, slippage }: {
|
|
845
|
+
current_sqrt_price: string;
|
|
846
|
+
tick_lower: number;
|
|
847
|
+
tick_upper: number;
|
|
848
|
+
amount_a: string;
|
|
849
|
+
amount_b: string;
|
|
850
|
+
slippage: number;
|
|
851
|
+
}): {
|
|
852
|
+
liquidity: string;
|
|
853
|
+
use_amount_a: string;
|
|
854
|
+
use_amount_b: string;
|
|
855
|
+
amount_limit_a: string;
|
|
856
|
+
amount_limit_b: string;
|
|
857
|
+
fix_amount_a: boolean;
|
|
858
|
+
remain_amount: Decimal.Decimal;
|
|
859
|
+
is_enough_amount: boolean;
|
|
860
|
+
};
|
|
861
|
+
declare function isEmptyObj(obj: any): boolean;
|
|
862
|
+
declare function isNotMergeCoin(not_merge_coins: string[], coin_type: string): boolean;
|
|
863
|
+
declare function isSameType(coin_type1: string, coin_type2: string): boolean;
|
|
864
|
+
|
|
294
865
|
declare const zapMainnet: SdkOptions;
|
|
295
866
|
|
|
296
867
|
declare const zapTestnet: SdkOptions;
|
|
@@ -311,4 +882,4 @@ declare class ZapError extends BaseError {
|
|
|
311
882
|
declare const handleError: (code: ZapErrorCode, error: Error, details?: Record<string, any>) => never;
|
|
312
883
|
declare const handleMessageError: (code: ZapErrorCode, message: string, details?: Record<string, any>) => never;
|
|
313
884
|
|
|
314
|
-
export { type BaseDepositOptions, type CalculationDepositResult, type CalculationWithdrawAvailableAmountOptions, type CalculationWithdrawOptions, type CalculationWithdrawResult, CetusDlmmZapSDK, type DepositOptions, type OnlyCoinDepositOptions, type SdkOptions, type SwapResult, type WithdrawMode, type WithdrawOptions, ZapError, ZapErrorCode, ZapModule, calcExactSwapAmount, calculateLiquidityAmountEnough, calculateLiquidityAmountSide, CetusDlmmZapSDK as default, defaultSwapSlippage, handleError, handleMessageError, zapMainnet, zapTestnet };
|
|
885
|
+
export { type BaseDepositOptions, type CalculateClaimMergeParams, type CalculateRebalanceParams, type CalculationDepositResult, type CalculationWithdrawAvailableAmountOptions, type CalculationWithdrawOptions, type CalculationWithdrawResult, CetusDlmmZapSDK, type ClosePosOnlyReturnAmountCoinsParams, type ClosePosReturnAmountCoinAParams, type CollectFeeAndRewardsAndReturnCoinsParams, CompoundModule, type CreateClaimMergePayloadParams, type CreateCompoundRebalanceAddPayload, type CreateMovePositionPayloadParams, type DepositOptions, type OnlyCoinDepositOptions, type PreSwapParams, type RebalanceResult, type SdkOptions, type SwapResult, type WithdrawMode, type WithdrawOptions, ZapError, ZapErrorCode, ZapModule, calcExactSwapAmount, calcSwapAmountForTargetRatio, calculateLiquidityAmountEnough, calculateLiquidityAmountSide, calculateLiquidityWithFallback, CetusDlmmZapSDK as default, defaultSwapSlippage, handleError, handleMessageError, isEmptyObj, isNotMergeCoin, isSameType, zapMainnet, zapTestnet };
|