@crypticdot/defituna-core 3.4.2 → 3.4.4

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.
@@ -1,133 +1,6 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
- /**
4
- * Calculate the amount A delta between two sqrt_prices
5
- *
6
- * # Parameters
7
- * - `sqrt_price_1`: The first square root price
8
- * - `sqrt_price_2`: The second square root price
9
- * - `liquidity`: The liquidity
10
- * - `round_up`: Whether to round up or not
11
- *
12
- * # Returns
13
- * - `u64`: The amount delta
14
- */
15
- export function tryGetAmountDeltaA(sqrt_price_1: bigint, sqrt_price_2: bigint, liquidity: bigint, round_up: boolean): bigint;
16
- /**
17
- * Calculate the amount B delta between two sqrt_prices
18
- *
19
- * # Parameters
20
- * - `sqrt_price_1`: The first square root price
21
- * - `sqrt_price_2`: The second square root price
22
- * - `liquidity`: The liquidity
23
- * - `round_up`: Whether to round up or not
24
- *
25
- * # Returns
26
- * - `u64`: The amount delta
27
- */
28
- export function tryGetAmountDeltaB(sqrt_price_1: bigint, sqrt_price_2: bigint, liquidity: bigint, round_up: boolean): bigint;
29
- /**
30
- * Calculate the next square root price
31
- *
32
- * # Parameters
33
- * - `current_sqrt_price`: The current square root price
34
- * - `current_liquidity`: The current liquidity
35
- * - `amount`: The amount
36
- * - `specified_input`: Whether the input is specified
37
- *
38
- * # Returns
39
- * - `u128`: The next square root price
40
- */
41
- export function tryGetNextSqrtPriceFromA(current_sqrt_price: bigint, current_liquidity: bigint, amount: bigint, specified_input: boolean): bigint;
42
- /**
43
- * Calculate the next square root price
44
- *
45
- * # Parameters
46
- * - `current_sqrt_price`: The current square root price
47
- * - `current_liquidity`: The current liquidity
48
- * - `amount`: The amount
49
- * - `specified_input`: Whether the input is specified
50
- *
51
- * # Returns
52
- * - `u128`: The next square root price
53
- */
54
- export function tryGetNextSqrtPriceFromB(current_sqrt_price: bigint, current_liquidity: bigint, amount: bigint, specified_input: boolean): bigint;
55
- /**
56
- * Apply a transfer fee to an amount
57
- * e.g. You send 10000 amount with 100 fee rate. The fee amount will be 100.
58
- * So the amount after fee will be 9900.
59
- *
60
- * # Parameters
61
- * - `amount`: The amount to apply the fee to
62
- * - `transfer_fee`: The transfer fee to apply
63
- *
64
- * # Returns
65
- * - `u64`: The amount after the fee has been applied
66
- */
67
- export function tryApplyTransferFee(amount: bigint, transfer_fee: TransferFee): bigint;
68
- /**
69
- * Reverse the application of a transfer fee to an amount
70
- * e.g. You received 9900 amount with 100 fee rate. The fee amount will be 100.
71
- * So the amount before fee will be 10000.
72
- *
73
- * # Parameters
74
- * - `amount`: The amount to reverse the fee from
75
- * - `transfer_fee`: The transfer fee to reverse
76
- *
77
- * # Returns
78
- * - `u64`: The amount before the fee has been applied
79
- */
80
- export function tryReverseApplyTransferFee(amount: bigint, transfer_fee: TransferFee): bigint;
81
- /**
82
- * Get the maximum amount with a slippage tolerance
83
- * e.g. Your estimated amount you send is 10000 with 100 slippage tolerance. The max you send will be 10100.
84
- *
85
- * # Parameters
86
- * - `amount`: The amount to apply the fee to
87
- * - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
88
- *
89
- * # Returns
90
- * - `u64`: The maximum amount
91
- */
92
- export function tryGetMaxAmountWithSlippageTolerance(amount: bigint, slippage_tolerance_bps: number): bigint;
93
- /**
94
- * Get the minimum amount with a slippage tolerance
95
- * e.g. Your estimated amount you receive is 10000 with 100 slippage tolerance. The min amount you receive will be 9900.
96
- *
97
- * # Parameters
98
- * - `amount`: The amount to apply the fee to
99
- * - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
100
- *
101
- * # Returns
102
- * - `u64`: The minimum amount
103
- */
104
- export function tryGetMinAmountWithSlippageTolerance(amount: bigint, slippage_tolerance_bps: number): bigint;
105
- /**
106
- * Apply a swap fee to an amount
107
- * e.g. You send 10000 amount with 10000 fee rate. The fee amount will be 100.
108
- * So the amount after fee will be 9900.
109
- *
110
- * # Parameters
111
- * - `amount`: The amount to apply the fee to
112
- * - `fee_rate`: The fee rate to apply denominated in 1e6
113
- *
114
- * # Returns
115
- * - `u64`: The amount after the fee has been applied
116
- */
117
- export function tryApplySwapFee(amount: bigint, fee_rate: number): bigint;
118
- /**
119
- * Reverse the application of a swap fee to an amount
120
- * e.g. You received 9900 amount with 10000 fee rate. The fee amount will be 100.
121
- * So the amount before fee will be 10000.
122
- *
123
- * # Parameters
124
- * - `amount`: The amount to reverse the fee from
125
- * - `fee_rate`: The fee rate to reverse denominated in 1e6
126
- *
127
- * # Returns
128
- * - `u64`: The amount before the fee has been applied
129
- */
130
- export function tryReverseApplySwapFee(amount: bigint, fee_rate: number): bigint;
3
+ export function _POSITION_BUNDLE_SIZE(): number;
131
4
  export function _FEE_RATE_MUL_VALUE(): number;
132
5
  export function _MAX_PROTOCOL_FEE_RATE(): number;
133
6
  export function _PROTOCOL_FEE_RATE_MUL_VALUE(): number;
@@ -394,7 +267,8 @@ export function tryGetLiquidityFromA(token_delta_a: bigint, sqrt_price_lower: bi
394
267
  export function tryGetTokenAFromLiquidity(liquidity_delta: bigint, sqrt_price_lower: bigint, sqrt_price_upper: bigint, round_up: boolean): bigint;
395
268
  export function tryGetLiquidityFromB(token_delta_b: bigint, sqrt_price_lower: bigint, sqrt_price_upper: bigint): bigint;
396
269
  export function tryGetTokenBFromLiquidity(liquidity_delta: bigint, sqrt_price_lower: bigint, sqrt_price_upper: bigint, round_up: boolean): bigint;
397
- export function tryGetTokenEstimatesFromLiquidity(liquidity_delta: bigint, current_sqrt_price: bigint, tick_lower_index: number, tick_upper_index: number, round_up: boolean): TokenPair;
270
+ export function tryGetAmountsFromLiquidity(liquidity_delta: bigint, current_sqrt_price: bigint, tick_lower_index: number, tick_upper_index: number, round_up: boolean): TokenPair;
271
+ export function tryGetLiquidityFromAmounts(sqrt_price: bigint, sqrt_price_a_x64: bigint, sqrt_price_b_x64: bigint, amount_a: bigint, amount_b: bigint): bigint;
398
272
  /**
399
273
  * Calculate fees owed for a position
400
274
  *
@@ -411,6 +285,134 @@ export function tryGetTokenEstimatesFromLiquidity(liquidity_delta: bigint, curre
411
285
  */
412
286
  export function collectFeesQuote(fusion_pool: FusionPoolFacade, position: PositionFacade, tick_lower: TickFacade, tick_upper: TickFacade, transfer_fee_a?: TransferFee | null, transfer_fee_b?: TransferFee | null): CollectFeesQuote;
413
287
  export function limitOrderFee(fusion_pool: FusionPoolFacade): number;
288
+ /**
289
+ * Calculate the amount A delta between two sqrt_prices
290
+ *
291
+ * # Parameters
292
+ * - `sqrt_price_1`: The first square root price
293
+ * - `sqrt_price_2`: The second square root price
294
+ * - `liquidity`: The liquidity
295
+ * - `round_up`: Whether to round up or not
296
+ *
297
+ * # Returns
298
+ * - `u64`: The amount delta
299
+ */
300
+ export function tryGetAmountDeltaA(sqrt_price_1: bigint, sqrt_price_2: bigint, liquidity: bigint, round_up: boolean): bigint;
301
+ /**
302
+ * Calculate the amount B delta between two sqrt_prices
303
+ *
304
+ * # Parameters
305
+ * - `sqrt_price_1`: The first square root price
306
+ * - `sqrt_price_2`: The second square root price
307
+ * - `liquidity`: The liquidity
308
+ * - `round_up`: Whether to round up or not
309
+ *
310
+ * # Returns
311
+ * - `u64`: The amount delta
312
+ */
313
+ export function tryGetAmountDeltaB(sqrt_price_1: bigint, sqrt_price_2: bigint, liquidity: bigint, round_up: boolean): bigint;
314
+ /**
315
+ * Calculate the next square root price
316
+ *
317
+ * # Parameters
318
+ * - `current_sqrt_price`: The current square root price
319
+ * - `current_liquidity`: The current liquidity
320
+ * - `amount`: The amount
321
+ * - `specified_input`: Whether the input is specified
322
+ *
323
+ * # Returns
324
+ * - `u128`: The next square root price
325
+ */
326
+ export function tryGetNextSqrtPriceFromA(current_sqrt_price: bigint, current_liquidity: bigint, amount: bigint, specified_input: boolean): bigint;
327
+ /**
328
+ * Calculate the next square root price
329
+ *
330
+ * # Parameters
331
+ * - `current_sqrt_price`: The current square root price
332
+ * - `current_liquidity`: The current liquidity
333
+ * - `amount`: The amount
334
+ * - `specified_input`: Whether the input is specified
335
+ *
336
+ * # Returns
337
+ * - `u128`: The next square root price
338
+ */
339
+ export function tryGetNextSqrtPriceFromB(current_sqrt_price: bigint, current_liquidity: bigint, amount: bigint, specified_input: boolean): bigint;
340
+ /**
341
+ * Apply a transfer fee to an amount
342
+ * e.g. You send 10000 amount with 100 fee rate. The fee amount will be 100.
343
+ * So the amount after fee will be 9900.
344
+ *
345
+ * # Parameters
346
+ * - `amount`: The amount to apply the fee to
347
+ * - `transfer_fee`: The transfer fee to apply
348
+ *
349
+ * # Returns
350
+ * - `u64`: The amount after the fee has been applied
351
+ */
352
+ export function tryApplyTransferFee(amount: bigint, transfer_fee: TransferFee): bigint;
353
+ /**
354
+ * Reverse the application of a transfer fee to an amount
355
+ * e.g. You received 9900 amount with 100 fee rate. The fee amount will be 100.
356
+ * So the amount before fee will be 10000.
357
+ *
358
+ * # Parameters
359
+ * - `amount`: The amount to reverse the fee from
360
+ * - `transfer_fee`: The transfer fee to reverse
361
+ *
362
+ * # Returns
363
+ * - `u64`: The amount before the fee has been applied
364
+ */
365
+ export function tryReverseApplyTransferFee(amount: bigint, transfer_fee: TransferFee): bigint;
366
+ /**
367
+ * Get the maximum amount with a slippage tolerance
368
+ * e.g. Your estimated amount you send is 10000 with 100 slippage tolerance. The max you send will be 10100.
369
+ *
370
+ * # Parameters
371
+ * - `amount`: The amount to apply the fee to
372
+ * - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
373
+ *
374
+ * # Returns
375
+ * - `u64`: The maximum amount
376
+ */
377
+ export function tryGetMaxAmountWithSlippageTolerance(amount: bigint, slippage_tolerance_bps: number): bigint;
378
+ /**
379
+ * Get the minimum amount with a slippage tolerance
380
+ * e.g. Your estimated amount you receive is 10000 with 100 slippage tolerance. The min amount you receive will be 9900.
381
+ *
382
+ * # Parameters
383
+ * - `amount`: The amount to apply the fee to
384
+ * - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
385
+ *
386
+ * # Returns
387
+ * - `u64`: The minimum amount
388
+ */
389
+ export function tryGetMinAmountWithSlippageTolerance(amount: bigint, slippage_tolerance_bps: number): bigint;
390
+ /**
391
+ * Apply a swap fee to an amount
392
+ * e.g. You send 10000 amount with 10000 fee rate. The fee amount will be 100.
393
+ * So the amount after fee will be 9900.
394
+ *
395
+ * # Parameters
396
+ * - `amount`: The amount to apply the fee to
397
+ * - `fee_rate`: The fee rate to apply denominated in 1e6
398
+ *
399
+ * # Returns
400
+ * - `u64`: The amount after the fee has been applied
401
+ */
402
+ export function tryApplySwapFee(amount: bigint, fee_rate: number): bigint;
403
+ /**
404
+ * Reverse the application of a swap fee to an amount
405
+ * e.g. You received 9900 amount with 10000 fee rate. The fee amount will be 100.
406
+ * So the amount before fee will be 10000.
407
+ *
408
+ * # Parameters
409
+ * - `amount`: The amount to reverse the fee from
410
+ * - `fee_rate`: The fee rate to reverse denominated in 1e6
411
+ *
412
+ * # Returns
413
+ * - `u64`: The amount before the fee has been applied
414
+ */
415
+ export function tryReverseApplySwapFee(amount: bigint, fee_rate: number): bigint;
414
416
  /**
415
417
  * Computes the limit order output amount by input amount.
416
418
  * ### Parameters
@@ -439,24 +441,6 @@ export function limitOrderQuoteByOutputToken(amount_out: bigint, a_to_b_order: b
439
441
  */
440
442
  export function limitOrderRewardByOutputToken(amount_out: bigint, fee_rate: number, protocol_fee_rate: number): bigint;
441
443
  export function decreaseLimitOrderQuote(fusion_pool: FusionPoolFacade, limit_order: LimitOrderFacade, tick: TickFacade, amount: bigint, transfer_fee_a?: TransferFee | null, transfer_fee_b?: TransferFee | null): LimitOrderDecreaseQuote;
442
- export function _POSITION_BUNDLE_SIZE(): number;
443
- export function _TICK_ARRAY_NOT_EVENLY_SPACED(): string;
444
- export function _TICK_INDEX_OUT_OF_BOUNDS(): string;
445
- export function _INVALID_TICK_INDEX(): string;
446
- export function _ARITHMETIC_OVERFLOW(): string;
447
- export function _AMOUNT_EXCEEDS_MAX_U64(): string;
448
- export function _AMOUNT_EXCEEDS_LIMIT_ORDER_INPUT_AMOUNT(): string;
449
- export function _SQRT_PRICE_OUT_OF_BOUNDS(): string;
450
- export function _TICK_SEQUENCE_EMPTY(): string;
451
- export function _SQRT_PRICE_LIMIT_OUT_OF_BOUNDS(): string;
452
- export function _INVALID_SQRT_PRICE_LIMIT_DIRECTION(): string;
453
- export function _ZERO_TRADABLE_AMOUNT(): string;
454
- export function _INVALID_TIMESTAMP(): string;
455
- export function _INVALID_TRANSFER_FEE(): string;
456
- export function _INVALID_SLIPPAGE_TOLERANCE(): string;
457
- export function _TICK_INDEX_NOT_IN_ARRAY(): string;
458
- export function _INVALID_TICK_ARRAY_SEQUENCE(): string;
459
- export function _LIMIT_ORDER_AND_POOL_ARE_OUT_OF_SYNC(): string;
460
444
  /**
461
445
  * Get the first unoccupied position in a bundle
462
446
  *
@@ -599,6 +583,23 @@ export function tickIndexToPrice(tick_index: number, decimals_a: number, decimal
599
583
  * * `i32` - The tick index
600
584
  */
601
585
  export function priceToTickIndex(price: number, decimals_a: number, decimals_b: number): number;
586
+ export function _TICK_ARRAY_NOT_EVENLY_SPACED(): string;
587
+ export function _TICK_INDEX_OUT_OF_BOUNDS(): string;
588
+ export function _INVALID_TICK_INDEX(): string;
589
+ export function _ARITHMETIC_OVERFLOW(): string;
590
+ export function _AMOUNT_EXCEEDS_MAX_U64(): string;
591
+ export function _AMOUNT_EXCEEDS_LIMIT_ORDER_INPUT_AMOUNT(): string;
592
+ export function _SQRT_PRICE_OUT_OF_BOUNDS(): string;
593
+ export function _TICK_SEQUENCE_EMPTY(): string;
594
+ export function _SQRT_PRICE_LIMIT_OUT_OF_BOUNDS(): string;
595
+ export function _INVALID_SQRT_PRICE_LIMIT_DIRECTION(): string;
596
+ export function _ZERO_TRADABLE_AMOUNT(): string;
597
+ export function _INVALID_TIMESTAMP(): string;
598
+ export function _INVALID_TRANSFER_FEE(): string;
599
+ export function _INVALID_SLIPPAGE_TOLERANCE(): string;
600
+ export function _TICK_INDEX_NOT_IN_ARRAY(): string;
601
+ export function _INVALID_TICK_ARRAY_SEQUENCE(): string;
602
+ export function _LIMIT_ORDER_AND_POOL_ARE_OUT_OF_SYNC(): string;
602
603
  /**
603
604
  * Computes the exact input or output amount for a swap transaction.
604
605
  *
@@ -694,14 +695,14 @@ export function getDecreaseSpotPositionQuote(decrease_amount: bigint, collateral
694
695
  *
695
696
  * # Parameters
696
697
  * - `position_token`: Token of the position
697
- * - `amount`: Position total size (decimal)
698
- * - `debt`: Position total debt (decimal)
699
- * - `liquidation_threshold`: Liquidation threshold of the market (decimal)
698
+ * - `amount`: Position total size
699
+ * - `debt`: Position total debt
700
+ * - `liquidation_threshold`: Liquidation threshold of a market
700
701
  *
701
702
  * # Returns
702
703
  * - `f64`: Decimal liquidation price
703
704
  */
704
- export function getSpotPositionLiquidationPrice(position_token: number, amount: number, debt: number, liquidation_threshold: number): number;
705
+ export function getSpotPositionLiquidationPrice(position_token: number, amount: bigint, debt: bigint, liquidation_threshold: number): number;
705
706
  /**
706
707
  * Calculates the maximum tradable amount in the collateral token.
707
708
  *
@@ -762,6 +763,16 @@ export interface FusionPoolFacade {
762
763
  olpFeeOwedB: bigint;
763
764
  }
764
765
 
766
+ export interface CollectFeesQuote {
767
+ feeOwedA: bigint;
768
+ feeOwedB: bigint;
769
+ }
770
+
771
+ export interface TokenPair {
772
+ a: bigint;
773
+ b: bigint;
774
+ }
775
+
765
776
  export interface LimitOrderDecreaseQuote {
766
777
  amountOutA: bigint;
767
778
  amountOutB: bigint;
@@ -776,9 +787,9 @@ export interface LimitOrderFacade {
776
787
  age: bigint;
777
788
  }
778
789
 
779
- export interface TokenPair {
780
- a: bigint;
781
- b: bigint;
790
+ export interface TransferFee {
791
+ feeBps: number;
792
+ maxFee: bigint;
782
793
  }
783
794
 
784
795
  export interface PositionFacade {
@@ -798,6 +809,22 @@ export interface PositionRatio {
798
809
  ratioB: bigint;
799
810
  }
800
811
 
812
+ export interface IncreaseLiquidityQuote {
813
+ liquidityDelta: bigint;
814
+ tokenEstA: bigint;
815
+ tokenEstB: bigint;
816
+ tokenMaxA: bigint;
817
+ tokenMaxB: bigint;
818
+ }
819
+
820
+ export interface DecreaseLiquidityQuote {
821
+ liquidityDelta: bigint;
822
+ tokenEstA: bigint;
823
+ tokenEstB: bigint;
824
+ tokenMinA: bigint;
825
+ tokenMinB: bigint;
826
+ }
827
+
801
828
  export interface TickArrayFacade {
802
829
  startTickIndex: number;
803
830
  ticks: TickFacade[];
@@ -822,32 +849,6 @@ export interface TickRange {
822
849
  tickUpperIndex: number;
823
850
  }
824
851
 
825
- export interface IncreaseLiquidityQuote {
826
- liquidityDelta: bigint;
827
- tokenEstA: bigint;
828
- tokenEstB: bigint;
829
- tokenMaxA: bigint;
830
- tokenMaxB: bigint;
831
- }
832
-
833
- export interface DecreaseLiquidityQuote {
834
- liquidityDelta: bigint;
835
- tokenEstA: bigint;
836
- tokenEstB: bigint;
837
- tokenMinA: bigint;
838
- tokenMinB: bigint;
839
- }
840
-
841
- export interface CollectFeesQuote {
842
- feeOwedA: bigint;
843
- feeOwedB: bigint;
844
- }
845
-
846
- export interface TransferFee {
847
- feeBps: number;
848
- maxFee: bigint;
849
- }
850
-
851
852
  export interface IncreaseLpPositionQuoteResult {
852
853
  collateralA: bigint;
853
854
  collateralB: bigint;
@@ -864,6 +865,8 @@ export interface IncreaseLpPositionQuoteResult {
864
865
  swapAToB: boolean;
865
866
  protocolFeeA: bigint;
866
867
  protocolFeeB: bigint;
868
+ liquidationLowerPrice: number;
869
+ liquidationUpperPrice: number;
867
870
  }
868
871
 
869
872
  export interface IncreaseLpPositionQuoteArgs {
@@ -878,6 +881,7 @@ export interface IncreaseLpPositionQuoteArgs {
878
881
  tickLowerIndex: number;
879
882
  tickUpperIndex: number;
880
883
  maxAmountSlippage: number;
884
+ liquidationThreshold: number;
881
885
  }
882
886
 
883
887
  export interface LiquidationPrices {