@crypticdot/defituna-core 3.4.4 → 3.4.6

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.
@@ -252,6 +252,204 @@ function passArray8ToWasm0(arg, malloc) {
252
252
  WASM_VECTOR_LEN = arg.length;
253
253
  return ptr;
254
254
  }
255
+ /**
256
+ * Get the first unoccupied position in a bundle
257
+ *
258
+ * # Arguments
259
+ * * `bundle` - The bundle to check
260
+ *
261
+ * # Returns
262
+ * * `u32` - The first unoccupied position (None if full)
263
+ */
264
+ exports.firstUnoccupiedPositionInBundle = function(bitmap) {
265
+ const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
266
+ const len0 = WASM_VECTOR_LEN;
267
+ const ret = wasm.firstUnoccupiedPositionInBundle(ptr0, len0);
268
+ return ret === 0x100000001 ? undefined : ret;
269
+ };
270
+
271
+ /**
272
+ * Check whether a position bundle is full
273
+ * A position bundle can contain 256 positions
274
+ *
275
+ * # Arguments
276
+ * * `bundle` - The bundle to check
277
+ *
278
+ * # Returns
279
+ * * `bool` - Whether the bundle is full
280
+ */
281
+ exports.isPositionBundleFull = function(bitmap) {
282
+ const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
283
+ const len0 = WASM_VECTOR_LEN;
284
+ const ret = wasm.isPositionBundleFull(ptr0, len0);
285
+ return ret !== 0;
286
+ };
287
+
288
+ /**
289
+ * Check whether a position bundle is empty
290
+ *
291
+ * # Arguments
292
+ * * `bundle` - The bundle to check
293
+ *
294
+ * # Returns
295
+ * * `bool` - Whether the bundle is empty
296
+ */
297
+ exports.isPositionBundleEmpty = function(bitmap) {
298
+ const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
299
+ const len0 = WASM_VECTOR_LEN;
300
+ const ret = wasm.isPositionBundleEmpty(ptr0, len0);
301
+ return ret !== 0;
302
+ };
303
+
304
+ /**
305
+ * Check if a position is in range.
306
+ * When a position is in range it is earning fees and rewards
307
+ *
308
+ * # Parameters
309
+ * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
310
+ * - `tick_index_1` - A i32 integer representing the first tick index of the position
311
+ * - `tick_index_2` - A i32 integer representing the second tick index of the position
312
+ *
313
+ * # Returns
314
+ * - A boolean value indicating if the position is in range
315
+ */
316
+ exports.isPositionInRange = function(current_sqrt_price, tick_index_1, tick_index_2) {
317
+ const ret = wasm.isPositionInRange(current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2);
318
+ return ret !== 0;
319
+ };
320
+
321
+ /**
322
+ * Calculate the status of a position
323
+ * The status can be one of three values:
324
+ * - InRange: The position is in range
325
+ * - BelowRange: The position is below the range
326
+ * - AboveRange: The position is above the range
327
+ *
328
+ * # Parameters
329
+ * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
330
+ * - `tick_index_1` - A i32 integer representing the first tick index of the position
331
+ * - `tick_index_2` - A i32 integer representing the second tick index of the position
332
+ *
333
+ * # Returns
334
+ * - A PositionStatus enum value indicating the status of the position
335
+ */
336
+ exports.positionStatus = function(current_sqrt_price, tick_index_1, tick_index_2) {
337
+ const ret = wasm.positionStatus(current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2);
338
+ return takeObject(ret);
339
+ };
340
+
341
+ /**
342
+ * Calculate the token_a / token_b ratio of a (ficticious) position
343
+ *
344
+ * # Parameters
345
+ * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
346
+ * - `tick_index_1` - A i32 integer representing the first tick index of the position
347
+ * - `tick_index_2` - A i32 integer representing the second tick index of the position
348
+ *
349
+ * # Returns
350
+ * - A PositionRatio struct containing the ratio of token_a and token_b
351
+ */
352
+ exports.positionRatioX64 = function(current_sqrt_price, tick_index_1, tick_index_2) {
353
+ const ret = wasm.positionRatioX64(current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2);
354
+ return takeObject(ret);
355
+ };
356
+
357
+ /**
358
+ * Convert a price into a sqrt priceX64
359
+ * IMPORTANT: floating point operations can reduce the precision of the result.
360
+ * Make sure to do these operations last and not to use the result for further calculations.
361
+ *
362
+ * # Parameters
363
+ * * `price` - The price to convert
364
+ * * `decimals_a` - The number of decimals of the base token
365
+ * * `decimals_b` - The number of decimals of the quote token
366
+ *
367
+ * # Returns
368
+ * * `u128` - The sqrt priceX64
369
+ */
370
+ exports.priceToSqrtPrice = function(price, decimals_a, decimals_b) {
371
+ try {
372
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
373
+ wasm.priceToSqrtPrice(retptr, price, decimals_a, decimals_b);
374
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
375
+ var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
376
+ return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
377
+ } finally {
378
+ wasm.__wbindgen_add_to_stack_pointer(16);
379
+ }
380
+ };
381
+
382
+ /**
383
+ * Convert a sqrt priceX64 into a tick index
384
+ * IMPORTANT: floating point operations can reduce the precision of the result.
385
+ * Make sure to do these operations last and not to use the result for further calculations.
386
+ *
387
+ * # Parameters
388
+ * * `sqrt_price` - The sqrt priceX64 to convert
389
+ * * `decimals_a` - The number of decimals of the base token
390
+ * * `decimals_b` - The number of decimals of the quote token
391
+ *
392
+ * # Returns
393
+ * * `f64` - The decimal price
394
+ */
395
+ exports.sqrtPriceToPrice = function(sqrt_price, decimals_a, decimals_b) {
396
+ const ret = wasm.sqrtPriceToPrice(sqrt_price, sqrt_price >> BigInt(64), decimals_a, decimals_b);
397
+ return ret;
398
+ };
399
+
400
+ /**
401
+ * Invert a price
402
+ * IMPORTANT: floating point operations can reduce the precision of the result.
403
+ * Make sure to do these operations last and not to use the result for further calculations.
404
+ *
405
+ * # Parameters
406
+ * * `price` - The price to invert
407
+ * * `decimals_a` - The number of decimals of the base token
408
+ * * `decimals_b` - The number of decimals of the quote token
409
+ *
410
+ * # Returns
411
+ * * `f64` - The inverted price
412
+ */
413
+ exports.invertPrice = function(price, decimals_a, decimals_b) {
414
+ const ret = wasm.invertPrice(price, decimals_a, decimals_b);
415
+ return ret;
416
+ };
417
+
418
+ /**
419
+ * Convert a tick index into a price
420
+ * IMPORTANT: floating point operations can reduce the precision of the result.
421
+ * Make sure to do these operations last and not to use the result for further calculations.
422
+ *
423
+ * # Parameters
424
+ * * `tick_index` - The tick index to convert
425
+ * * `decimals_a` - The number of decimals of the base token
426
+ * * `decimals_b` - The number of decimals of the quote token
427
+ *
428
+ * # Returns
429
+ * * `f64` - The decimal price
430
+ */
431
+ exports.tickIndexToPrice = function(tick_index, decimals_a, decimals_b) {
432
+ const ret = wasm.tickIndexToPrice(tick_index, decimals_a, decimals_b);
433
+ return ret;
434
+ };
435
+
436
+ /**
437
+ * Convert a price into a tick index
438
+ * IMPORTANT: floating point operations can reduce the precision of the result.
439
+ * Make sure to do these operations last and not to use the result for further calculations.
440
+ *
441
+ * # Parameters
442
+ * * `price` - The price to convert
443
+ * * `decimals_a` - The number of decimals of the base token
444
+ * * `decimals_b` - The number of decimals of the quote token
445
+ *
446
+ * # Returns
447
+ * * `i32` - The tick index
448
+ */
449
+ exports.priceToTickIndex = function(price, decimals_a, decimals_b) {
450
+ const ret = wasm.priceToTickIndex(price, decimals_a, decimals_b);
451
+ return ret;
452
+ };
255
453
 
256
454
  exports._POSITION_BUNDLE_SIZE = function() {
257
455
  const ret = wasm._POSITION_BUNDLE_SIZE();
@@ -533,87 +731,76 @@ exports.getTickIndexInArray = function(tick_index, tick_array_start_index, tick_
533
731
  }
534
732
  };
535
733
 
536
- /**
537
- * Calculate the quote for decreasing liquidity
538
- *
539
- * # Parameters
540
- * - `liquidity_delta` - The amount of liquidity to decrease
541
- * - `slippage_tolerance` - The slippage tolerance in bps
542
- * - `current_sqrt_price` - The current sqrt price of the pool
543
- * - `tick_index_1` - The first tick index of the position
544
- * - `tick_index_2` - The second tick index of the position
545
- * - `transfer_fee_a` - The transfer fee for token A in bps
546
- * - `transfer_fee_b` - The transfer fee for token B in bps
547
- *
548
- * # Returns
549
- * - A DecreaseLiquidityQuote struct containing the estimated token amounts
550
- */
551
- exports.decreaseLiquidityQuote = function(liquidity_delta, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
734
+ exports.tryGetLiquidityFromAmountA = function(amount_a, sqrt_price_lower, sqrt_price_upper) {
735
+ try {
736
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
737
+ wasm.tryGetLiquidityFromAmountA(retptr, amount_a, sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64));
738
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
739
+ var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
740
+ var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
741
+ var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
742
+ if (r5) {
743
+ throw takeObject(r4);
744
+ }
745
+ return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
746
+ } finally {
747
+ wasm.__wbindgen_add_to_stack_pointer(32);
748
+ }
749
+ };
750
+
751
+ exports.tryGetAmountAFromLiquidity = function(liquidity, sqrt_price_lower, sqrt_price_upper, round_up) {
552
752
  try {
553
753
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
554
- wasm.decreaseLiquidityQuote(retptr, liquidity_delta, liquidity_delta >> BigInt(64), slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
555
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
556
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
754
+ wasm.tryGetAmountAFromLiquidity(retptr, liquidity, liquidity >> BigInt(64), sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64), round_up);
755
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
557
756
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
558
- if (r2) {
559
- throw takeObject(r1);
757
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
758
+ if (r3) {
759
+ throw takeObject(r2);
560
760
  }
561
- return takeObject(r0);
761
+ return BigInt.asUintN(64, r0);
562
762
  } finally {
563
763
  wasm.__wbindgen_add_to_stack_pointer(16);
564
764
  }
565
765
  };
566
766
 
567
- /**
568
- * Calculate the quote for decreasing liquidity given a token a amount
569
- *
570
- * # Parameters
571
- * - `token_amount_a` - The amount of token a to decrease
572
- * - `slippage_tolerance` - The slippage tolerance in bps
573
- * - `current_sqrt_price` - The current sqrt price of the pool
574
- * - `tick_index_1` - The first tick index of the position
575
- * - `tick_index_2` - The second tick index of the position
576
- * - `transfer_fee_a` - The transfer fee for token A in bps
577
- * - `transfer_fee_b` - The transfer fee for token B in bps
578
- *
579
- * # Returns
580
- * - A DecreaseLiquidityQuote struct containing the estimated token amounts
581
- */
582
- exports.decreaseLiquidityQuoteA = function(token_amount_a, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
767
+ exports.tryGetLiquidityFromAmountB = function(amount_b, sqrt_price_lower, sqrt_price_upper) {
768
+ try {
769
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
770
+ wasm.tryGetLiquidityFromAmountB(retptr, amount_b, sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64));
771
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
772
+ var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
773
+ var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
774
+ var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
775
+ if (r5) {
776
+ throw takeObject(r4);
777
+ }
778
+ return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
779
+ } finally {
780
+ wasm.__wbindgen_add_to_stack_pointer(32);
781
+ }
782
+ };
783
+
784
+ exports.tryGetAmountBFromLiquidity = function(liquidity, sqrt_price_lower, sqrt_price_upper, round_up) {
583
785
  try {
584
786
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
585
- wasm.decreaseLiquidityQuoteA(retptr, token_amount_a, slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
586
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
587
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
787
+ wasm.tryGetAmountBFromLiquidity(retptr, liquidity, liquidity >> BigInt(64), sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64), round_up);
788
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
588
789
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
589
- if (r2) {
590
- throw takeObject(r1);
790
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
791
+ if (r3) {
792
+ throw takeObject(r2);
591
793
  }
592
- return takeObject(r0);
794
+ return BigInt.asUintN(64, r0);
593
795
  } finally {
594
796
  wasm.__wbindgen_add_to_stack_pointer(16);
595
797
  }
596
798
  };
597
799
 
598
- /**
599
- * Calculate the quote for decreasing liquidity given a token b amount
600
- *
601
- * # Parameters
602
- * - `token_amount_b` - The amount of token b to decrease
603
- * - `slippage_tolerance` - The slippage tolerance in bps
604
- * - `current_sqrt_price` - The current sqrt price of the pool
605
- * - `tick_index_1` - The first tick index of the position
606
- * - `tick_index_2` - The second tick index of the position
607
- * - `transfer_fee_a` - The transfer fee for token A in bps
608
- * - `transfer_fee_b` - The transfer fee for token B in bps
609
- *
610
- * # Returns
611
- * - A DecreaseLiquidityQuote struct containing the estimated token amounts
612
- */
613
- exports.decreaseLiquidityQuoteB = function(token_amount_b, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
800
+ exports.tryGetAmountsFromLiquidity = function(liquidity, sqrt_price, tick_lower_index, tick_upper_index, round_up) {
614
801
  try {
615
802
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
616
- wasm.decreaseLiquidityQuoteB(retptr, token_amount_b, slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
803
+ wasm.tryGetAmountsFromLiquidity(retptr, liquidity, liquidity >> BigInt(64), sqrt_price, sqrt_price >> BigInt(64), tick_lower_index, tick_upper_index, round_up);
617
804
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
618
805
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
619
806
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -626,11 +813,28 @@ exports.decreaseLiquidityQuoteB = function(token_amount_b, slippage_tolerance_bp
626
813
  }
627
814
  };
628
815
 
816
+ exports.tryGetLiquidityFromAmounts = function(sqrt_price, sqrt_price_lower, sqrt_price_upper, amount_a, amount_b) {
817
+ try {
818
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
819
+ wasm.tryGetLiquidityFromAmounts(retptr, sqrt_price, sqrt_price >> BigInt(64), sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64), amount_a, amount_b);
820
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
821
+ var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
822
+ var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
823
+ var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
824
+ if (r5) {
825
+ throw takeObject(r4);
826
+ }
827
+ return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
828
+ } finally {
829
+ wasm.__wbindgen_add_to_stack_pointer(32);
830
+ }
831
+ };
832
+
629
833
  /**
630
- * Calculate the quote for increasing liquidity
834
+ * Calculate the quote for decreasing liquidity
631
835
  *
632
836
  * # Parameters
633
- * - `liquidity_delta` - The amount of liquidity to increase
837
+ * - `liquidity_delta` - The amount of liquidity to decrease
634
838
  * - `slippage_tolerance` - The slippage tolerance in bps
635
839
  * - `current_sqrt_price` - The current sqrt price of the pool
636
840
  * - `tick_index_1` - The first tick index of the position
@@ -639,12 +843,12 @@ exports.decreaseLiquidityQuoteB = function(token_amount_b, slippage_tolerance_bp
639
843
  * - `transfer_fee_b` - The transfer fee for token B in bps
640
844
  *
641
845
  * # Returns
642
- * - An IncreaseLiquidityQuote struct containing the estimated token amounts
846
+ * - A DecreaseLiquidityQuote struct containing the estimated token amounts
643
847
  */
644
- exports.increaseLiquidityQuote = function(liquidity_delta, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
848
+ exports.decreaseLiquidityQuote = function(liquidity_delta, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
645
849
  try {
646
850
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
647
- wasm.increaseLiquidityQuote(retptr, liquidity_delta, liquidity_delta >> BigInt(64), slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
851
+ wasm.decreaseLiquidityQuote(retptr, liquidity_delta, liquidity_delta >> BigInt(64), slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
648
852
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
649
853
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
650
854
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -658,10 +862,10 @@ exports.increaseLiquidityQuote = function(liquidity_delta, slippage_tolerance_bp
658
862
  };
659
863
 
660
864
  /**
661
- * Calculate the quote for increasing liquidity given a token a amount
865
+ * Calculate the quote for decreasing liquidity given a token a amount
662
866
  *
663
867
  * # Parameters
664
- * - `token_amount_a` - The amount of token a to increase
868
+ * - `token_amount_a` - The amount of token a to decrease
665
869
  * - `slippage_tolerance` - The slippage tolerance in bps
666
870
  * - `current_sqrt_price` - The current sqrt price of the pool
667
871
  * - `tick_index_1` - The first tick index of the position
@@ -670,12 +874,12 @@ exports.increaseLiquidityQuote = function(liquidity_delta, slippage_tolerance_bp
670
874
  * - `transfer_fee_b` - The transfer fee for token B in bps
671
875
  *
672
876
  * # Returns
673
- * - An IncreaseLiquidityQuote struct containing the estimated token amounts
877
+ * - A DecreaseLiquidityQuote struct containing the estimated token amounts
674
878
  */
675
- exports.increaseLiquidityQuoteA = function(token_amount_a, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
879
+ exports.decreaseLiquidityQuoteA = function(token_amount_a, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
676
880
  try {
677
881
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
678
- wasm.increaseLiquidityQuoteA(retptr, token_amount_a, slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
882
+ wasm.decreaseLiquidityQuoteA(retptr, token_amount_a, slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
679
883
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
680
884
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
681
885
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -689,10 +893,10 @@ exports.increaseLiquidityQuoteA = function(token_amount_a, slippage_tolerance_bp
689
893
  };
690
894
 
691
895
  /**
692
- * Calculate the quote for increasing liquidity given a token b amount
896
+ * Calculate the quote for decreasing liquidity given a token b amount
693
897
  *
694
898
  * # Parameters
695
- * - `token_amount_b` - The amount of token b to increase
899
+ * - `token_amount_b` - The amount of token b to decrease
696
900
  * - `slippage_tolerance` - The slippage tolerance in bps
697
901
  * - `current_sqrt_price` - The current sqrt price of the pool
698
902
  * - `tick_index_1` - The first tick index of the position
@@ -700,95 +904,44 @@ exports.increaseLiquidityQuoteA = function(token_amount_a, slippage_tolerance_bp
700
904
  * - `transfer_fee_a` - The transfer fee for token A in bps
701
905
  * - `transfer_fee_b` - The transfer fee for token B in bps
702
906
  *
703
- * # Returns
704
- * - An IncreaseLiquidityQuote struct containing the estimated token amounts
705
- */
706
- exports.increaseLiquidityQuoteB = function(token_amount_b, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
707
- try {
708
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
709
- wasm.increaseLiquidityQuoteB(retptr, token_amount_b, slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
710
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
711
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
712
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
713
- if (r2) {
714
- throw takeObject(r1);
715
- }
716
- return takeObject(r0);
717
- } finally {
718
- wasm.__wbindgen_add_to_stack_pointer(16);
719
- }
720
- };
721
-
722
- exports.tryGetLiquidityFromA = function(token_delta_a, sqrt_price_lower, sqrt_price_upper) {
723
- try {
724
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
725
- wasm.tryGetLiquidityFromA(retptr, token_delta_a, sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64));
726
- var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
727
- var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
728
- var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
729
- var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
730
- if (r5) {
731
- throw takeObject(r4);
732
- }
733
- return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
734
- } finally {
735
- wasm.__wbindgen_add_to_stack_pointer(32);
736
- }
737
- };
738
-
739
- exports.tryGetTokenAFromLiquidity = function(liquidity_delta, sqrt_price_lower, sqrt_price_upper, round_up) {
740
- try {
741
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
742
- wasm.tryGetTokenAFromLiquidity(retptr, liquidity_delta, liquidity_delta >> BigInt(64), sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64), round_up);
743
- var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
744
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
745
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
746
- if (r3) {
747
- throw takeObject(r2);
748
- }
749
- return BigInt.asUintN(64, r0);
750
- } finally {
751
- wasm.__wbindgen_add_to_stack_pointer(16);
752
- }
753
- };
754
-
755
- exports.tryGetLiquidityFromB = function(token_delta_b, sqrt_price_lower, sqrt_price_upper) {
756
- try {
757
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
758
- wasm.tryGetLiquidityFromB(retptr, token_delta_b, sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64));
759
- var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
760
- var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
761
- var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
762
- var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
763
- if (r5) {
764
- throw takeObject(r4);
765
- }
766
- return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
767
- } finally {
768
- wasm.__wbindgen_add_to_stack_pointer(32);
769
- }
770
- };
771
-
772
- exports.tryGetTokenBFromLiquidity = function(liquidity_delta, sqrt_price_lower, sqrt_price_upper, round_up) {
907
+ * # Returns
908
+ * - A DecreaseLiquidityQuote struct containing the estimated token amounts
909
+ */
910
+ exports.decreaseLiquidityQuoteB = function(token_amount_b, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
773
911
  try {
774
912
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
775
- wasm.tryGetTokenBFromLiquidity(retptr, liquidity_delta, liquidity_delta >> BigInt(64), sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64), round_up);
776
- var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
913
+ wasm.decreaseLiquidityQuoteB(retptr, token_amount_b, slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
914
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
915
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
777
916
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
778
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
779
- if (r3) {
780
- throw takeObject(r2);
917
+ if (r2) {
918
+ throw takeObject(r1);
781
919
  }
782
- return BigInt.asUintN(64, r0);
920
+ return takeObject(r0);
783
921
  } finally {
784
922
  wasm.__wbindgen_add_to_stack_pointer(16);
785
923
  }
786
924
  };
787
925
 
788
- exports.tryGetAmountsFromLiquidity = function(liquidity_delta, current_sqrt_price, tick_lower_index, tick_upper_index, round_up) {
926
+ /**
927
+ * Calculate the quote for increasing liquidity
928
+ *
929
+ * # Parameters
930
+ * - `liquidity_delta` - The amount of liquidity to increase
931
+ * - `slippage_tolerance` - The slippage tolerance in bps
932
+ * - `current_sqrt_price` - The current sqrt price of the pool
933
+ * - `tick_index_1` - The first tick index of the position
934
+ * - `tick_index_2` - The second tick index of the position
935
+ * - `transfer_fee_a` - The transfer fee for token A in bps
936
+ * - `transfer_fee_b` - The transfer fee for token B in bps
937
+ *
938
+ * # Returns
939
+ * - An IncreaseLiquidityQuote struct containing the estimated token amounts
940
+ */
941
+ exports.increaseLiquidityQuote = function(liquidity_delta, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
789
942
  try {
790
943
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
791
- wasm.tryGetAmountsFromLiquidity(retptr, liquidity_delta, liquidity_delta >> BigInt(64), current_sqrt_price, current_sqrt_price >> BigInt(64), tick_lower_index, tick_upper_index, round_up);
944
+ wasm.increaseLiquidityQuote(retptr, liquidity_delta, liquidity_delta >> BigInt(64), slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
792
945
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
793
946
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
794
947
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -801,41 +954,56 @@ exports.tryGetAmountsFromLiquidity = function(liquidity_delta, current_sqrt_pric
801
954
  }
802
955
  };
803
956
 
804
- exports.tryGetLiquidityFromAmounts = function(sqrt_price, sqrt_price_a_x64, sqrt_price_b_x64, amount_a, amount_b) {
957
+ /**
958
+ * Calculate the quote for increasing liquidity given a token a amount
959
+ *
960
+ * # Parameters
961
+ * - `token_amount_a` - The amount of token a to increase
962
+ * - `slippage_tolerance` - The slippage tolerance in bps
963
+ * - `current_sqrt_price` - The current sqrt price of the pool
964
+ * - `tick_index_1` - The first tick index of the position
965
+ * - `tick_index_2` - The second tick index of the position
966
+ * - `transfer_fee_a` - The transfer fee for token A in bps
967
+ * - `transfer_fee_b` - The transfer fee for token B in bps
968
+ *
969
+ * # Returns
970
+ * - An IncreaseLiquidityQuote struct containing the estimated token amounts
971
+ */
972
+ exports.increaseLiquidityQuoteA = function(token_amount_a, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
805
973
  try {
806
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
807
- wasm.tryGetLiquidityFromAmounts(retptr, sqrt_price, sqrt_price >> BigInt(64), sqrt_price_a_x64, sqrt_price_a_x64 >> BigInt(64), sqrt_price_b_x64, sqrt_price_b_x64 >> BigInt(64), amount_a, amount_b);
808
- var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
809
- var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
810
- var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
811
- var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
812
- if (r5) {
813
- throw takeObject(r4);
974
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
975
+ wasm.increaseLiquidityQuoteA(retptr, token_amount_a, slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
976
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
977
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
978
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
979
+ if (r2) {
980
+ throw takeObject(r1);
814
981
  }
815
- return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
982
+ return takeObject(r0);
816
983
  } finally {
817
- wasm.__wbindgen_add_to_stack_pointer(32);
984
+ wasm.__wbindgen_add_to_stack_pointer(16);
818
985
  }
819
986
  };
820
987
 
821
988
  /**
822
- * Calculate fees owed for a position
989
+ * Calculate the quote for increasing liquidity given a token b amount
823
990
  *
824
- * # Paramters
825
- * - `fusion_pool`: The fusion_pool state
826
- * - `position`: The position state
827
- * - `tick_lower`: The lower tick state
828
- * - `tick_upper`: The upper tick state
829
- * - `transfer_fee_a`: The transfer fee for token A
830
- * - `transfer_fee_b`: The transfer fee for token B
991
+ * # Parameters
992
+ * - `token_amount_b` - The amount of token b to increase
993
+ * - `slippage_tolerance` - The slippage tolerance in bps
994
+ * - `current_sqrt_price` - The current sqrt price of the pool
995
+ * - `tick_index_1` - The first tick index of the position
996
+ * - `tick_index_2` - The second tick index of the position
997
+ * - `transfer_fee_a` - The transfer fee for token A in bps
998
+ * - `transfer_fee_b` - The transfer fee for token B in bps
831
999
  *
832
1000
  * # Returns
833
- * - `CollectFeesQuote`: The fees owed for token A and token B
1001
+ * - An IncreaseLiquidityQuote struct containing the estimated token amounts
834
1002
  */
835
- exports.collectFeesQuote = function(fusion_pool, position, tick_lower, tick_upper, transfer_fee_a, transfer_fee_b) {
1003
+ exports.increaseLiquidityQuoteB = function(token_amount_b, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
836
1004
  try {
837
1005
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
838
- wasm.collectFeesQuote(retptr, addHeapObject(fusion_pool), addHeapObject(position), addHeapObject(tick_lower), addHeapObject(tick_upper), isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
1006
+ wasm.increaseLiquidityQuoteB(retptr, token_amount_b, slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
839
1007
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
840
1008
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
841
1009
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -848,11 +1016,6 @@ exports.collectFeesQuote = function(fusion_pool, position, tick_lower, tick_uppe
848
1016
  }
849
1017
  };
850
1018
 
851
- exports.limitOrderFee = function(fusion_pool) {
852
- const ret = wasm.limitOrderFee(addHeapObject(fusion_pool));
853
- return ret;
854
- };
855
-
856
1019
  /**
857
1020
  * Calculate the amount A delta between two sqrt_prices
858
1021
  *
@@ -1202,221 +1365,57 @@ exports.limitOrderRewardByOutputToken = function(amount_out, fee_rate, protocol_
1202
1365
  return BigInt.asUintN(64, r0);
1203
1366
  } finally {
1204
1367
  wasm.__wbindgen_add_to_stack_pointer(16);
1205
- }
1206
- };
1207
-
1208
- exports.decreaseLimitOrderQuote = function(fusion_pool, limit_order, tick, amount, transfer_fee_a, transfer_fee_b) {
1209
- try {
1210
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1211
- wasm.decreaseLimitOrderQuote(retptr, addHeapObject(fusion_pool), addHeapObject(limit_order), addHeapObject(tick), amount, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
1212
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1213
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1214
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1215
- if (r2) {
1216
- throw takeObject(r1);
1217
- }
1218
- return takeObject(r0);
1219
- } finally {
1220
- wasm.__wbindgen_add_to_stack_pointer(16);
1221
- }
1222
- };
1223
-
1224
- /**
1225
- * Get the first unoccupied position in a bundle
1226
- *
1227
- * # Arguments
1228
- * * `bundle` - The bundle to check
1229
- *
1230
- * # Returns
1231
- * * `u32` - The first unoccupied position (None if full)
1232
- */
1233
- exports.firstUnoccupiedPositionInBundle = function(bitmap) {
1234
- const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
1235
- const len0 = WASM_VECTOR_LEN;
1236
- const ret = wasm.firstUnoccupiedPositionInBundle(ptr0, len0);
1237
- return ret === 0x100000001 ? undefined : ret;
1238
- };
1239
-
1240
- /**
1241
- * Check whether a position bundle is full
1242
- * A position bundle can contain 256 positions
1243
- *
1244
- * # Arguments
1245
- * * `bundle` - The bundle to check
1246
- *
1247
- * # Returns
1248
- * * `bool` - Whether the bundle is full
1249
- */
1250
- exports.isPositionBundleFull = function(bitmap) {
1251
- const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
1252
- const len0 = WASM_VECTOR_LEN;
1253
- const ret = wasm.isPositionBundleFull(ptr0, len0);
1254
- return ret !== 0;
1255
- };
1256
-
1257
- /**
1258
- * Check whether a position bundle is empty
1259
- *
1260
- * # Arguments
1261
- * * `bundle` - The bundle to check
1262
- *
1263
- * # Returns
1264
- * * `bool` - Whether the bundle is empty
1265
- */
1266
- exports.isPositionBundleEmpty = function(bitmap) {
1267
- const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
1268
- const len0 = WASM_VECTOR_LEN;
1269
- const ret = wasm.isPositionBundleEmpty(ptr0, len0);
1270
- return ret !== 0;
1271
- };
1272
-
1273
- /**
1274
- * Check if a position is in range.
1275
- * When a position is in range it is earning fees and rewards
1276
- *
1277
- * # Parameters
1278
- * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
1279
- * - `tick_index_1` - A i32 integer representing the first tick index of the position
1280
- * - `tick_index_2` - A i32 integer representing the second tick index of the position
1281
- *
1282
- * # Returns
1283
- * - A boolean value indicating if the position is in range
1284
- */
1285
- exports.isPositionInRange = function(current_sqrt_price, tick_index_1, tick_index_2) {
1286
- const ret = wasm.isPositionInRange(current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2);
1287
- return ret !== 0;
1288
- };
1289
-
1290
- /**
1291
- * Calculate the status of a position
1292
- * The status can be one of three values:
1293
- * - InRange: The position is in range
1294
- * - BelowRange: The position is below the range
1295
- * - AboveRange: The position is above the range
1296
- *
1297
- * # Parameters
1298
- * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
1299
- * - `tick_index_1` - A i32 integer representing the first tick index of the position
1300
- * - `tick_index_2` - A i32 integer representing the second tick index of the position
1301
- *
1302
- * # Returns
1303
- * - A PositionStatus enum value indicating the status of the position
1304
- */
1305
- exports.positionStatus = function(current_sqrt_price, tick_index_1, tick_index_2) {
1306
- const ret = wasm.positionStatus(current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2);
1307
- return takeObject(ret);
1308
- };
1309
-
1310
- /**
1311
- * Calculate the token_a / token_b ratio of a (ficticious) position
1312
- *
1313
- * # Parameters
1314
- * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
1315
- * - `tick_index_1` - A i32 integer representing the first tick index of the position
1316
- * - `tick_index_2` - A i32 integer representing the second tick index of the position
1317
- *
1318
- * # Returns
1319
- * - A PositionRatio struct containing the ratio of token_a and token_b
1320
- */
1321
- exports.positionRatioX64 = function(current_sqrt_price, tick_index_1, tick_index_2) {
1322
- const ret = wasm.positionRatioX64(current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2);
1323
- return takeObject(ret);
1324
- };
1325
-
1326
- /**
1327
- * Convert a price into a sqrt priceX64
1328
- * IMPORTANT: floating point operations can reduce the precision of the result.
1329
- * Make sure to do these operations last and not to use the result for further calculations.
1330
- *
1331
- * # Parameters
1332
- * * `price` - The price to convert
1333
- * * `decimals_a` - The number of decimals of the base token
1334
- * * `decimals_b` - The number of decimals of the quote token
1335
- *
1336
- * # Returns
1337
- * * `u128` - The sqrt priceX64
1338
- */
1339
- exports.priceToSqrtPrice = function(price, decimals_a, decimals_b) {
1340
- try {
1341
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1342
- wasm.priceToSqrtPrice(retptr, price, decimals_a, decimals_b);
1343
- var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
1344
- var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
1345
- return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
1346
- } finally {
1347
- wasm.__wbindgen_add_to_stack_pointer(16);
1348
- }
1349
- };
1350
-
1351
- /**
1352
- * Convert a sqrt priceX64 into a tick index
1353
- * IMPORTANT: floating point operations can reduce the precision of the result.
1354
- * Make sure to do these operations last and not to use the result for further calculations.
1355
- *
1356
- * # Parameters
1357
- * * `sqrt_price` - The sqrt priceX64 to convert
1358
- * * `decimals_a` - The number of decimals of the base token
1359
- * * `decimals_b` - The number of decimals of the quote token
1360
- *
1361
- * # Returns
1362
- * * `f64` - The decimal price
1363
- */
1364
- exports.sqrtPriceToPrice = function(sqrt_price, decimals_a, decimals_b) {
1365
- const ret = wasm.sqrtPriceToPrice(sqrt_price, sqrt_price >> BigInt(64), decimals_a, decimals_b);
1366
- return ret;
1368
+ }
1367
1369
  };
1368
1370
 
1369
- /**
1370
- * Invert a price
1371
- * IMPORTANT: floating point operations can reduce the precision of the result.
1372
- * Make sure to do these operations last and not to use the result for further calculations.
1373
- *
1374
- * # Parameters
1375
- * * `price` - The price to invert
1376
- * * `decimals_a` - The number of decimals of the base token
1377
- * * `decimals_b` - The number of decimals of the quote token
1378
- *
1379
- * # Returns
1380
- * * `f64` - The inverted price
1381
- */
1382
- exports.invertPrice = function(price, decimals_a, decimals_b) {
1383
- const ret = wasm.invertPrice(price, decimals_a, decimals_b);
1384
- return ret;
1371
+ exports.decreaseLimitOrderQuote = function(fusion_pool, limit_order, tick, amount, transfer_fee_a, transfer_fee_b) {
1372
+ try {
1373
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1374
+ wasm.decreaseLimitOrderQuote(retptr, addHeapObject(fusion_pool), addHeapObject(limit_order), addHeapObject(tick), amount, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
1375
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1376
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1377
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1378
+ if (r2) {
1379
+ throw takeObject(r1);
1380
+ }
1381
+ return takeObject(r0);
1382
+ } finally {
1383
+ wasm.__wbindgen_add_to_stack_pointer(16);
1384
+ }
1385
1385
  };
1386
1386
 
1387
1387
  /**
1388
- * Convert a tick index into a price
1389
- * IMPORTANT: floating point operations can reduce the precision of the result.
1390
- * Make sure to do these operations last and not to use the result for further calculations.
1388
+ * Calculate fees owed for a position
1391
1389
  *
1392
- * # Parameters
1393
- * * `tick_index` - The tick index to convert
1394
- * * `decimals_a` - The number of decimals of the base token
1395
- * * `decimals_b` - The number of decimals of the quote token
1390
+ * # Paramters
1391
+ * - `fusion_pool`: The fusion_pool state
1392
+ * - `position`: The position state
1393
+ * - `tick_lower`: The lower tick state
1394
+ * - `tick_upper`: The upper tick state
1395
+ * - `transfer_fee_a`: The transfer fee for token A
1396
+ * - `transfer_fee_b`: The transfer fee for token B
1396
1397
  *
1397
1398
  * # Returns
1398
- * * `f64` - The decimal price
1399
+ * - `CollectFeesQuote`: The fees owed for token A and token B
1399
1400
  */
1400
- exports.tickIndexToPrice = function(tick_index, decimals_a, decimals_b) {
1401
- const ret = wasm.tickIndexToPrice(tick_index, decimals_a, decimals_b);
1402
- return ret;
1401
+ exports.collectFeesQuote = function(fusion_pool, position, tick_lower, tick_upper, transfer_fee_a, transfer_fee_b) {
1402
+ try {
1403
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1404
+ wasm.collectFeesQuote(retptr, addHeapObject(fusion_pool), addHeapObject(position), addHeapObject(tick_lower), addHeapObject(tick_upper), isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
1405
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1406
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1407
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1408
+ if (r2) {
1409
+ throw takeObject(r1);
1410
+ }
1411
+ return takeObject(r0);
1412
+ } finally {
1413
+ wasm.__wbindgen_add_to_stack_pointer(16);
1414
+ }
1403
1415
  };
1404
1416
 
1405
- /**
1406
- * Convert a price into a tick index
1407
- * IMPORTANT: floating point operations can reduce the precision of the result.
1408
- * Make sure to do these operations last and not to use the result for further calculations.
1409
- *
1410
- * # Parameters
1411
- * * `price` - The price to convert
1412
- * * `decimals_a` - The number of decimals of the base token
1413
- * * `decimals_b` - The number of decimals of the quote token
1414
- *
1415
- * # Returns
1416
- * * `i32` - The tick index
1417
- */
1418
- exports.priceToTickIndex = function(price, decimals_a, decimals_b) {
1419
- const ret = wasm.priceToTickIndex(price, decimals_a, decimals_b);
1417
+ exports.limitOrderFee = function(fusion_pool) {
1418
+ const ret = wasm.limitOrderFee(addHeapObject(fusion_pool));
1420
1419
  return ret;
1421
1420
  };
1422
1421
 
@@ -1540,6 +1539,18 @@ exports._INVALID_SQRT_PRICE_LIMIT_DIRECTION = function() {
1540
1539
  }
1541
1540
  };
1542
1541
 
1542
+ exports._INVALID_RANGE_BOUNDS = function() {
1543
+ try {
1544
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1545
+ wasm._INVALID_RANGE_BOUNDS(retptr);
1546
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1547
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1548
+ return getStringFromWasm0(r0, r1);
1549
+ } finally {
1550
+ wasm.__wbindgen_add_to_stack_pointer(16);
1551
+ }
1552
+ };
1553
+
1543
1554
  exports._ZERO_TRADABLE_AMOUNT = function() {
1544
1555
  try {
1545
1556
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
@@ -1686,54 +1697,6 @@ exports.swapQuoteByOutputToken = function(token_out, specified_token_a, slippage
1686
1697
  }
1687
1698
  };
1688
1699
 
1689
- /**
1690
- * Computes the liquidation prices for an existing position.
1691
- *
1692
- * # Parameters
1693
- * - `tick_lower_index`: The lower tick index of the position.
1694
- * - `tick_upper_index`: The upper tick index of the position.
1695
- * - `leftovers_a`: The amount of leftovers A in the position.
1696
- * - `leftovers_a`: The amount of leftovers B in the position.
1697
- * - `liquidity`: Liquidity of the position.
1698
- * - `debt_a`: The amount of tokens A borrowed.
1699
- * - `debt_b`: The amount of tokens B borrowed.
1700
- * - `liquidation_threshold`: The liquidation threshold of the market.
1701
- *
1702
- * # Returns
1703
- * - `LiquidationPrices`: An object containing lower/upper liquidation prices.
1704
- */
1705
- exports.getLpPositionLiquidationPrices = function(tick_lower_index, tick_upper_index, liquidity, leftovers_a, leftovers_b, debt_a, debt_b, liquidation_threshold) {
1706
- try {
1707
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1708
- wasm.getLpPositionLiquidationPrices(retptr, tick_lower_index, tick_upper_index, liquidity, liquidity >> BigInt(64), leftovers_a, leftovers_b, debt_a, debt_b, liquidation_threshold);
1709
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1710
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1711
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1712
- if (r2) {
1713
- throw takeObject(r1);
1714
- }
1715
- return takeObject(r0);
1716
- } finally {
1717
- wasm.__wbindgen_add_to_stack_pointer(16);
1718
- }
1719
- };
1720
-
1721
- exports.getIncreaseLpPositionQuote = function(args) {
1722
- try {
1723
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1724
- wasm.getIncreaseLpPositionQuote(retptr, addHeapObject(args));
1725
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1726
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1727
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1728
- if (r2) {
1729
- throw takeObject(r1);
1730
- }
1731
- return takeObject(r0);
1732
- } finally {
1733
- wasm.__wbindgen_add_to_stack_pointer(16);
1734
- }
1735
- };
1736
-
1737
1700
  exports._HUNDRED_PERCENT = function() {
1738
1701
  const ret = wasm._HUNDRED_PERCENT();
1739
1702
  return ret >>> 0;
@@ -1864,11 +1827,123 @@ exports.calculateTunaSpotPositionProtocolFee = function(collateral_token, borrow
1864
1827
  return takeObject(ret);
1865
1828
  };
1866
1829
 
1830
+ exports.applyTunaProtocolFee = function(amount, protocol_fee_rate, round_up) {
1831
+ try {
1832
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1833
+ wasm.applyTunaProtocolFee(retptr, amount, protocol_fee_rate, round_up);
1834
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
1835
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1836
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1837
+ if (r3) {
1838
+ throw takeObject(r2);
1839
+ }
1840
+ return BigInt.asUintN(64, r0);
1841
+ } finally {
1842
+ wasm.__wbindgen_add_to_stack_pointer(16);
1843
+ }
1844
+ };
1845
+
1846
+ exports.reverseApplyTunaProtocolFee = function(amount, protocol_fee_rate, round_up) {
1847
+ try {
1848
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1849
+ wasm.reverseApplyTunaProtocolFee(retptr, amount, protocol_fee_rate, round_up);
1850
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
1851
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1852
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1853
+ if (r3) {
1854
+ throw takeObject(r2);
1855
+ }
1856
+ return BigInt.asUintN(64, r0);
1857
+ } finally {
1858
+ wasm.__wbindgen_add_to_stack_pointer(16);
1859
+ }
1860
+ };
1861
+
1867
1862
  exports.calculateTunaProtocolFee = function(collateral, borrow, protocol_fee_rate_on_collateral, protocol_fee_rate) {
1868
1863
  const ret = wasm.calculateTunaProtocolFee(collateral, borrow, protocol_fee_rate_on_collateral, protocol_fee_rate);
1869
1864
  return BigInt.asUintN(64, ret);
1870
1865
  };
1871
1866
 
1867
+ /**
1868
+ * Computes the liquidation prices for an existing position.
1869
+ *
1870
+ * # Parameters
1871
+ * - `tick_lower_index`: The lower tick index of the position.
1872
+ * - `tick_upper_index`: The upper tick index of the position.
1873
+ * - `leftovers_a`: The amount of leftovers A in the position.
1874
+ * - `leftovers_a`: The amount of leftovers B in the position.
1875
+ * - `liquidity`: Liquidity of the position.
1876
+ * - `debt_a`: The amount of tokens A borrowed.
1877
+ * - `debt_b`: The amount of tokens B borrowed.
1878
+ * - `liquidation_threshold`: The liquidation threshold of the market.
1879
+ *
1880
+ * # Returns
1881
+ * - `LiquidationPrices`: An object containing lower/upper liquidation prices.
1882
+ */
1883
+ exports.getLpPositionLiquidationPrices = function(tick_lower_index, tick_upper_index, liquidity, leftovers_a, leftovers_b, debt_a, debt_b, liquidation_threshold) {
1884
+ try {
1885
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1886
+ wasm.getLpPositionLiquidationPrices(retptr, tick_lower_index, tick_upper_index, liquidity, liquidity >> BigInt(64), leftovers_a, leftovers_b, debt_a, debt_b, liquidation_threshold);
1887
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1888
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1889
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1890
+ if (r2) {
1891
+ throw takeObject(r1);
1892
+ }
1893
+ return takeObject(r0);
1894
+ } finally {
1895
+ wasm.__wbindgen_add_to_stack_pointer(16);
1896
+ }
1897
+ };
1898
+
1899
+ exports.getIncreaseLpPositionQuote = function(args) {
1900
+ try {
1901
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1902
+ wasm.getIncreaseLpPositionQuote(retptr, addHeapObject(args));
1903
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1904
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1905
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1906
+ if (r2) {
1907
+ throw takeObject(r1);
1908
+ }
1909
+ return takeObject(r0);
1910
+ } finally {
1911
+ wasm.__wbindgen_add_to_stack_pointer(16);
1912
+ }
1913
+ };
1914
+
1915
+ exports.getRepayLpPositionDebtQuote = function(args) {
1916
+ try {
1917
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1918
+ wasm.getRepayLpPositionDebtQuote(retptr, addHeapObject(args));
1919
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1920
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1921
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1922
+ if (r2) {
1923
+ throw takeObject(r1);
1924
+ }
1925
+ return takeObject(r0);
1926
+ } finally {
1927
+ wasm.__wbindgen_add_to_stack_pointer(16);
1928
+ }
1929
+ };
1930
+
1931
+ exports.computeLeverage = function(total_a, total_b, debt_a, debt_b, sqrt_price) {
1932
+ try {
1933
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1934
+ wasm.computeLeverage(retptr, total_a, total_b, debt_a, debt_b, sqrt_price, sqrt_price >> BigInt(64));
1935
+ var r0 = getDataViewMemory0().getFloat64(retptr + 8 * 0, true);
1936
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1937
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1938
+ if (r3) {
1939
+ throw takeObject(r2);
1940
+ }
1941
+ return r0;
1942
+ } finally {
1943
+ wasm.__wbindgen_add_to_stack_pointer(16);
1944
+ }
1945
+ };
1946
+
1872
1947
  exports._INVALID_ARGUMENTS = function() {
1873
1948
  try {
1874
1949
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
@@ -1912,16 +1987,16 @@ exports.solana_program_init = function() {
1912
1987
  wasm.solana_program_init();
1913
1988
  };
1914
1989
 
1915
- function __wasm_bindgen_func_elem_2634(arg0, arg1, arg2) {
1916
- wasm.__wasm_bindgen_func_elem_2634(arg0, arg1, addHeapObject(arg2));
1990
+ function __wasm_bindgen_func_elem_3154(arg0, arg1) {
1991
+ wasm.__wasm_bindgen_func_elem_3154(arg0, arg1);
1917
1992
  }
1918
1993
 
1919
- function __wasm_bindgen_func_elem_3207(arg0, arg1) {
1920
- wasm.__wasm_bindgen_func_elem_3207(arg0, arg1);
1994
+ function __wasm_bindgen_func_elem_3288(arg0, arg1, arg2) {
1995
+ wasm.__wasm_bindgen_func_elem_3288(arg0, arg1, addHeapObject(arg2));
1921
1996
  }
1922
1997
 
1923
- function __wasm_bindgen_func_elem_495(arg0, arg1, arg2, arg3) {
1924
- wasm.__wasm_bindgen_func_elem_495(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1998
+ function __wasm_bindgen_func_elem_494(arg0, arg1, arg2, arg3) {
1999
+ wasm.__wasm_bindgen_func_elem_494(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1925
2000
  }
1926
2001
 
1927
2002
  const __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
@@ -3100,7 +3175,7 @@ exports.__wbg_new_3c3d849046688a66 = function(arg0, arg1) {
3100
3175
  const a = state0.a;
3101
3176
  state0.a = 0;
3102
3177
  try {
3103
- return __wasm_bindgen_func_elem_495(a, state0.b, arg0, arg1);
3178
+ return __wasm_bindgen_func_elem_494(a, state0.b, arg0, arg1);
3104
3179
  } finally {
3105
3180
  state0.a = a;
3106
3181
  }
@@ -3344,30 +3419,30 @@ exports.__wbg_warn_1d74dddbe2fd1dbb = function(arg0) {
3344
3419
  console.warn(getObject(arg0));
3345
3420
  };
3346
3421
 
3347
- exports.__wbindgen_cast_0660a350899916ec = function(arg0, arg1) {
3348
- // Cast intrinsic for `Closure(Closure { dtor_idx: 360, function: Function { arguments: [], shim_idx: 361, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
3349
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_3203, __wasm_bindgen_func_elem_3207);
3350
- return addHeapObject(ret);
3351
- };
3352
-
3353
3422
  exports.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
3354
3423
  // Cast intrinsic for `Ref(String) -> Externref`.
3355
3424
  const ret = getStringFromWasm0(arg0, arg1);
3356
3425
  return addHeapObject(ret);
3357
3426
  };
3358
3427
 
3359
- exports.__wbindgen_cast_2e5f7f1574aa20c6 = function(arg0, arg1) {
3360
- // Cast intrinsic for `Closure(Closure { dtor_idx: 232, function: Function { arguments: [Externref], shim_idx: 227, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
3361
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_2653, __wasm_bindgen_func_elem_2634);
3362
- return addHeapObject(ret);
3363
- };
3364
-
3365
3428
  exports.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
3366
3429
  // Cast intrinsic for `U64 -> Externref`.
3367
3430
  const ret = BigInt.asUintN(64, arg0);
3368
3431
  return addHeapObject(ret);
3369
3432
  };
3370
3433
 
3434
+ exports.__wbindgen_cast_49dae81bf02b4884 = function(arg0, arg1) {
3435
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 369, function: Function { arguments: [Externref], shim_idx: 380, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
3436
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_3261, __wasm_bindgen_func_elem_3288);
3437
+ return addHeapObject(ret);
3438
+ };
3439
+
3440
+ exports.__wbindgen_cast_7879599246031d81 = function(arg0, arg1) {
3441
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 343, function: Function { arguments: [], shim_idx: 344, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
3442
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_3150, __wasm_bindgen_func_elem_3154);
3443
+ return addHeapObject(ret);
3444
+ };
3445
+
3371
3446
  exports.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
3372
3447
  // Cast intrinsic for `I64 -> Externref`.
3373
3448
  const ret = arg0;