@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.
@@ -262,752 +262,899 @@ function passArray8ToWasm0(arg, malloc) {
262
262
  WASM_VECTOR_LEN = arg.length;
263
263
  return ptr;
264
264
  }
265
+
266
+ export function _POSITION_BUNDLE_SIZE() {
267
+ const ret = wasm._POSITION_BUNDLE_SIZE();
268
+ return ret >>> 0;
269
+ }
270
+
271
+ export function _FEE_RATE_MUL_VALUE() {
272
+ const ret = wasm._FEE_RATE_MUL_VALUE();
273
+ return ret >>> 0;
274
+ }
275
+
276
+ export function _MAX_PROTOCOL_FEE_RATE() {
277
+ const ret = wasm._MAX_PROTOCOL_FEE_RATE();
278
+ return ret;
279
+ }
280
+
281
+ export function _PROTOCOL_FEE_RATE_MUL_VALUE() {
282
+ const ret = wasm._PROTOCOL_FEE_RATE_MUL_VALUE();
283
+ return ret;
284
+ }
285
+
286
+ export function _TICK_ARRAY_SIZE() {
287
+ const ret = wasm._TICK_ARRAY_SIZE();
288
+ return ret >>> 0;
289
+ }
290
+
291
+ export function _FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD() {
292
+ const ret = wasm._FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD();
293
+ return ret;
294
+ }
295
+
296
+ export function _MIN_TICK_INDEX() {
297
+ const ret = wasm._MIN_TICK_INDEX();
298
+ return ret;
299
+ }
300
+
301
+ export function _MAX_TICK_INDEX() {
302
+ const ret = wasm._MAX_TICK_INDEX();
303
+ return ret;
304
+ }
305
+
265
306
  /**
266
- * Calculate the amount A delta between two sqrt_prices
307
+ * Get the first tick index in the tick array that contains the specified tick index.
267
308
  *
268
309
  * # Parameters
269
- * - `sqrt_price_1`: The first square root price
270
- * - `sqrt_price_2`: The second square root price
271
- * - `liquidity`: The liquidity
272
- * - `round_up`: Whether to round up or not
310
+ * - `tick_index` - A i32 integer representing the tick integer
311
+ * - `tick_spacing` - A i32 integer representing the tick spacing
273
312
  *
274
313
  * # Returns
275
- * - `u64`: The amount delta
314
+ * - A i32 integer representing the first tick index in the tick array
276
315
  */
277
- export function tryGetAmountDeltaA(sqrt_price_1, sqrt_price_2, liquidity, round_up) {
278
- try {
279
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
280
- wasm.tryGetAmountDeltaA(retptr, addHeapObject(sqrt_price_1), addHeapObject(sqrt_price_2), addHeapObject(liquidity), round_up);
281
- var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
282
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
283
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
284
- if (r3) {
285
- throw takeObject(r2);
286
- }
287
- return BigInt.asUintN(64, r0);
288
- } finally {
289
- wasm.__wbindgen_add_to_stack_pointer(16);
290
- }
316
+ export function getTickArrayStartTickIndex(tick_index, tick_spacing) {
317
+ const ret = wasm.getTickArrayStartTickIndex(tick_index, tick_spacing);
318
+ return ret;
291
319
  }
292
320
 
293
321
  /**
294
- * Calculate the amount B delta between two sqrt_prices
322
+ * Derive the sqrt-price from a tick index. The precision of this method is only guarranted
323
+ * if tick is within the bounds of {max, min} tick-index.
295
324
  *
296
325
  * # Parameters
297
- * - `sqrt_price_1`: The first square root price
298
- * - `sqrt_price_2`: The second square root price
299
- * - `liquidity`: The liquidity
300
- * - `round_up`: Whether to round up or not
326
+ * - `tick_index` - A i32 integer representing the tick integer
301
327
  *
302
328
  * # Returns
303
- * - `u64`: The amount delta
329
+ * - `Ok`: A u128 Q32.64 representing the sqrt_price
304
330
  */
305
- export function tryGetAmountDeltaB(sqrt_price_1, sqrt_price_2, liquidity, round_up) {
331
+ export function tickIndexToSqrtPrice(tick_index) {
306
332
  try {
307
333
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
308
- wasm.tryGetAmountDeltaB(retptr, addHeapObject(sqrt_price_1), addHeapObject(sqrt_price_2), addHeapObject(liquidity), round_up);
334
+ wasm.tickIndexToSqrtPrice(retptr, tick_index);
309
335
  var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
310
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
311
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
312
- if (r3) {
313
- throw takeObject(r2);
314
- }
315
- return BigInt.asUintN(64, r0);
336
+ var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
337
+ return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
316
338
  } finally {
317
339
  wasm.__wbindgen_add_to_stack_pointer(16);
318
340
  }
319
341
  }
320
342
 
321
343
  /**
322
- * Calculate the next square root price
344
+ * Derive the tick index from a sqrt price. The precision of this method is only guarranted
345
+ * if tick is within the bounds of {max, min} tick-index.
323
346
  *
324
347
  * # Parameters
325
- * - `current_sqrt_price`: The current square root price
326
- * - `current_liquidity`: The current liquidity
327
- * - `amount`: The amount
328
- * - `specified_input`: Whether the input is specified
348
+ * - `sqrt_price` - A u128 integer representing the sqrt price
329
349
  *
330
350
  * # Returns
331
- * - `u128`: The next square root price
351
+ * - `Ok`: A i32 integer representing the tick integer
332
352
  */
333
- export function tryGetNextSqrtPriceFromA(current_sqrt_price, current_liquidity, amount, specified_input) {
334
- try {
335
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
336
- wasm.tryGetNextSqrtPriceFromA(retptr, addHeapObject(current_sqrt_price), addHeapObject(current_liquidity), amount, specified_input);
337
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
338
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
339
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
340
- if (r2) {
341
- throw takeObject(r1);
342
- }
343
- return takeObject(r0);
344
- } finally {
345
- wasm.__wbindgen_add_to_stack_pointer(16);
346
- }
353
+ export function sqrtPriceToTickIndex(sqrt_price) {
354
+ const ret = wasm.sqrtPriceToTickIndex(sqrt_price, sqrt_price >> BigInt(64));
355
+ return ret;
347
356
  }
348
357
 
349
358
  /**
350
- * Calculate the next square root price
359
+ * Get the initializable tick index.
360
+ * If the tick index is already initializable, it is returned as is.
351
361
  *
352
362
  * # Parameters
353
- * - `current_sqrt_price`: The current square root price
354
- * - `current_liquidity`: The current liquidity
355
- * - `amount`: The amount
356
- * - `specified_input`: Whether the input is specified
363
+ * - `tick_index` - A i32 integer representing the tick integer
364
+ * - `tick_spacing` - A i32 integer representing the tick spacing
365
+ * - `round_up` - A boolean value indicating if the supplied tick index should be rounded up. None will round to the nearest.
357
366
  *
358
367
  * # Returns
359
- * - `u128`: The next square root price
368
+ * - A i32 integer representing the previous initializable tick index
360
369
  */
361
- export function tryGetNextSqrtPriceFromB(current_sqrt_price, current_liquidity, amount, specified_input) {
362
- try {
363
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
364
- wasm.tryGetNextSqrtPriceFromB(retptr, addHeapObject(current_sqrt_price), addHeapObject(current_liquidity), amount, specified_input);
365
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
366
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
367
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
368
- if (r2) {
369
- throw takeObject(r1);
370
- }
371
- return takeObject(r0);
372
- } finally {
373
- wasm.__wbindgen_add_to_stack_pointer(16);
374
- }
370
+ export function getInitializableTickIndex(tick_index, tick_spacing, round_up) {
371
+ const ret = wasm.getInitializableTickIndex(tick_index, tick_spacing, isLikeNone(round_up) ? 0xFFFFFF : round_up ? 1 : 0);
372
+ return ret;
375
373
  }
376
374
 
377
375
  /**
378
- * Apply a transfer fee to an amount
379
- * e.g. You send 10000 amount with 100 fee rate. The fee amount will be 100.
380
- * So the amount after fee will be 9900.
376
+ * Get the previous initializable tick index.
381
377
  *
382
378
  * # Parameters
383
- * - `amount`: The amount to apply the fee to
384
- * - `transfer_fee`: The transfer fee to apply
379
+ * - `tick_index` - A i32 integer representing the tick integer
380
+ * - `tick_spacing` - A i32 integer representing the tick spacing
385
381
  *
386
382
  * # Returns
387
- * - `u64`: The amount after the fee has been applied
383
+ * - A i32 integer representing the previous initializable tick index
388
384
  */
389
- export function tryApplyTransferFee(amount, transfer_fee) {
390
- try {
391
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
392
- wasm.tryApplyTransferFee(retptr, amount, addHeapObject(transfer_fee));
393
- var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
394
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
395
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
396
- if (r3) {
397
- throw takeObject(r2);
398
- }
399
- return BigInt.asUintN(64, r0);
400
- } finally {
401
- wasm.__wbindgen_add_to_stack_pointer(16);
402
- }
385
+ export function getPrevInitializableTickIndex(tick_index, tick_spacing) {
386
+ const ret = wasm.getPrevInitializableTickIndex(tick_index, tick_spacing);
387
+ return ret;
403
388
  }
404
389
 
405
390
  /**
406
- * Reverse the application of a transfer fee to an amount
407
- * e.g. You received 9900 amount with 100 fee rate. The fee amount will be 100.
408
- * So the amount before fee will be 10000.
391
+ * Get the next initializable tick index.
409
392
  *
410
393
  * # Parameters
411
- * - `amount`: The amount to reverse the fee from
412
- * - `transfer_fee`: The transfer fee to reverse
394
+ * - `tick_index` - A i32 integer representing the tick integer
395
+ * - `tick_spacing` - A i32 integer representing the tick spacing
413
396
  *
414
397
  * # Returns
415
- * - `u64`: The amount before the fee has been applied
398
+ * - A i32 integer representing the next initializable tick index
416
399
  */
417
- export function tryReverseApplyTransferFee(amount, transfer_fee) {
418
- try {
419
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
420
- wasm.tryReverseApplyTransferFee(retptr, amount, addHeapObject(transfer_fee));
421
- var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
422
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
423
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
424
- if (r3) {
425
- throw takeObject(r2);
426
- }
427
- return BigInt.asUintN(64, r0);
428
- } finally {
429
- wasm.__wbindgen_add_to_stack_pointer(16);
430
- }
400
+ export function getNextInitializableTickIndex(tick_index, tick_spacing) {
401
+ const ret = wasm.getNextInitializableTickIndex(tick_index, tick_spacing);
402
+ return ret;
431
403
  }
432
404
 
433
405
  /**
434
- * Get the maximum amount with a slippage tolerance
435
- * e.g. Your estimated amount you send is 10000 with 100 slippage tolerance. The max you send will be 10100.
406
+ * Check if a tick is in-bounds.
436
407
  *
437
408
  * # Parameters
438
- * - `amount`: The amount to apply the fee to
439
- * - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
409
+ * - `tick_index` - A i32 integer representing the tick integer
440
410
  *
441
411
  * # Returns
442
- * - `u64`: The maximum amount
412
+ * - A boolean value indicating if the tick is in-bounds
443
413
  */
444
- export function tryGetMaxAmountWithSlippageTolerance(amount, slippage_tolerance_bps) {
445
- try {
446
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
447
- wasm.tryGetMaxAmountWithSlippageTolerance(retptr, amount, slippage_tolerance_bps);
448
- var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
449
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
450
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
451
- if (r3) {
452
- throw takeObject(r2);
453
- }
454
- return BigInt.asUintN(64, r0);
455
- } finally {
456
- wasm.__wbindgen_add_to_stack_pointer(16);
457
- }
414
+ export function isTickIndexInBounds(tick_index) {
415
+ const ret = wasm.isTickIndexInBounds(tick_index);
416
+ return ret !== 0;
458
417
  }
459
418
 
460
419
  /**
461
- * Get the minimum amount with a slippage tolerance
462
- * e.g. Your estimated amount you receive is 10000 with 100 slippage tolerance. The min amount you receive will be 9900.
420
+ * Check if a tick is initializable.
421
+ * A tick is initializable if it is divisible by the tick spacing.
463
422
  *
464
423
  * # Parameters
465
- * - `amount`: The amount to apply the fee to
466
- * - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
424
+ * - `tick_index` - A i32 integer representing the tick integer
425
+ * - `tick_spacing` - A i32 integer representing the tick spacing
467
426
  *
468
427
  * # Returns
469
- * - `u64`: The minimum amount
428
+ * - A boolean value indicating if the tick is initializable
470
429
  */
471
- export function tryGetMinAmountWithSlippageTolerance(amount, slippage_tolerance_bps) {
472
- try {
473
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
474
- wasm.tryGetMinAmountWithSlippageTolerance(retptr, amount, slippage_tolerance_bps);
475
- var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
476
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
477
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
478
- if (r3) {
479
- throw takeObject(r2);
480
- }
481
- return BigInt.asUintN(64, r0);
482
- } finally {
483
- wasm.__wbindgen_add_to_stack_pointer(16);
484
- }
430
+ export function isTickInitializable(tick_index, tick_spacing) {
431
+ const ret = wasm.isTickInitializable(tick_index, tick_spacing);
432
+ return ret !== 0;
485
433
  }
486
434
 
487
435
  /**
488
- * Apply a swap fee to an amount
489
- * e.g. You send 10000 amount with 10000 fee rate. The fee amount will be 100.
490
- * So the amount after fee will be 9900.
436
+ * Get the tick index for the inverse of the price that this tick represents.
437
+ * Eg: Consider tick i where Pb/Pa = 1.0001 ^ i
438
+ * inverse of this, i.e. Pa/Pb = 1 / (1.0001 ^ i) = 1.0001^-i
491
439
  *
492
440
  * # Parameters
493
- * - `amount`: The amount to apply the fee to
494
- * - `fee_rate`: The fee rate to apply denominated in 1e6
441
+ * - `tick_index` - A i32 integer representing the tick integer
495
442
  *
496
443
  * # Returns
497
- * - `u64`: The amount after the fee has been applied
444
+ * - A i32 integer representing the tick index for the inverse of the price
498
445
  */
499
- export function tryApplySwapFee(amount, fee_rate) {
500
- try {
501
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
502
- wasm.tryApplySwapFee(retptr, amount, fee_rate);
503
- var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
504
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
505
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
506
- if (r3) {
507
- throw takeObject(r2);
508
- }
509
- return BigInt.asUintN(64, r0);
510
- } finally {
511
- wasm.__wbindgen_add_to_stack_pointer(16);
512
- }
446
+ export function invertTickIndex(tick_index) {
447
+ const ret = wasm.invertTickIndex(tick_index);
448
+ return ret;
513
449
  }
514
450
 
515
451
  /**
516
- * Reverse the application of a swap fee to an amount
517
- * e.g. You received 9900 amount with 10000 fee rate. The fee amount will be 100.
518
- * So the amount before fee will be 10000.
452
+ * Get the sqrt price for the inverse of the price that this tick represents.
453
+ * Because converting to a tick index and then back to a sqrt price is lossy,
454
+ * this function is clamped to the nearest tick index.
519
455
  *
520
456
  * # Parameters
521
- * - `amount`: The amount to reverse the fee from
522
- * - `fee_rate`: The fee rate to reverse denominated in 1e6
457
+ * - `sqrt_price` - A u128 integer representing the sqrt price
523
458
  *
524
459
  * # Returns
525
- * - `u64`: The amount before the fee has been applied
460
+ * - A u128 integer representing the sqrt price for the inverse of the price
526
461
  */
527
- export function tryReverseApplySwapFee(amount, fee_rate) {
462
+ export function invertSqrtPrice(sqrt_price) {
528
463
  try {
529
464
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
530
- wasm.tryReverseApplySwapFee(retptr, amount, fee_rate);
465
+ wasm.invertSqrtPrice(retptr, sqrt_price, sqrt_price >> BigInt(64));
531
466
  var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
532
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
533
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
534
- if (r3) {
535
- throw takeObject(r2);
536
- }
537
- return BigInt.asUintN(64, r0);
467
+ var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
468
+ return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
538
469
  } finally {
539
470
  wasm.__wbindgen_add_to_stack_pointer(16);
540
471
  }
541
472
  }
542
473
 
543
- export function _FEE_RATE_MUL_VALUE() {
544
- const ret = wasm._FEE_RATE_MUL_VALUE();
545
- return ret >>> 0;
546
- }
547
-
548
- export function _MAX_PROTOCOL_FEE_RATE() {
549
- const ret = wasm._MAX_PROTOCOL_FEE_RATE();
550
- return ret;
551
- }
552
-
553
- export function _PROTOCOL_FEE_RATE_MUL_VALUE() {
554
- const ret = wasm._PROTOCOL_FEE_RATE_MUL_VALUE();
555
- return ret;
556
- }
557
-
558
- export function _TICK_ARRAY_SIZE() {
559
- const ret = wasm._TICK_ARRAY_SIZE();
560
- return ret >>> 0;
561
- }
562
-
563
- export function _FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD() {
564
- const ret = wasm._FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD();
565
- return ret;
566
- }
567
-
568
- export function _MIN_TICK_INDEX() {
569
- const ret = wasm._MIN_TICK_INDEX();
570
- return ret;
571
- }
572
-
573
- export function _MAX_TICK_INDEX() {
574
- const ret = wasm._MAX_TICK_INDEX();
575
- return ret;
576
- }
577
-
578
474
  /**
579
- * Get the first tick index in the tick array that contains the specified tick index.
475
+ * Get the minimum and maximum tick index that can be initialized.
580
476
  *
581
477
  * # Parameters
582
- * - `tick_index` - A i32 integer representing the tick integer
583
478
  * - `tick_spacing` - A i32 integer representing the tick spacing
584
479
  *
585
480
  * # Returns
586
- * - A i32 integer representing the first tick index in the tick array
481
+ * - A TickRange struct containing the lower and upper tick index
587
482
  */
588
- export function getTickArrayStartTickIndex(tick_index, tick_spacing) {
589
- const ret = wasm.getTickArrayStartTickIndex(tick_index, tick_spacing);
590
- return ret;
483
+ export function getFullRangeTickIndexes(tick_spacing) {
484
+ const ret = wasm.getFullRangeTickIndexes(tick_spacing);
485
+ return takeObject(ret);
591
486
  }
592
487
 
593
488
  /**
594
- * Derive the sqrt-price from a tick index. The precision of this method is only guarranted
595
- * if tick is within the bounds of {max, min} tick-index.
489
+ * Order tick indexes in ascending order.
490
+ * If the lower tick index is greater than the upper tick index, the indexes are swapped.
491
+ * This is useful for ensuring that the lower tick index is always less than the upper tick index.
596
492
  *
597
493
  * # Parameters
598
- * - `tick_index` - A i32 integer representing the tick integer
494
+ * - `tick_index_1` - A i32 integer representing the first tick index
495
+ * - `tick_index_2` - A i32 integer representing the second tick index
599
496
  *
600
497
  * # Returns
601
- * - `Ok`: A u128 Q32.64 representing the sqrt_price
498
+ * - A TickRange struct containing the lower and upper tick index
602
499
  */
603
- export function tickIndexToSqrtPrice(tick_index) {
604
- const ret = wasm.tickIndexToSqrtPrice(tick_index);
500
+ export function orderTickIndexes(tick_index_1, tick_index_2) {
501
+ const ret = wasm.orderTickIndexes(tick_index_1, tick_index_2);
605
502
  return takeObject(ret);
606
503
  }
607
504
 
608
505
  /**
609
- * Derive the tick index from a sqrt price. The precision of this method is only guarranted
610
- * if tick is within the bounds of {max, min} tick-index.
506
+ * Check if a fusion_pool is a full-range only pool.
611
507
  *
612
508
  * # Parameters
613
- * - `sqrt_price` - A u128 integer representing the sqrt price
509
+ * - `tick_spacing` - A u16 integer representing the tick spacing
614
510
  *
615
511
  * # Returns
616
- * - `Ok`: A i32 integer representing the tick integer
512
+ * - A boolean value indicating if the fusion_pool is a full-range only pool
617
513
  */
618
- export function sqrtPriceToTickIndex(sqrt_price) {
619
- const ret = wasm.sqrtPriceToTickIndex(addHeapObject(sqrt_price));
620
- return ret;
514
+ export function isFullRangeOnly(tick_spacing) {
515
+ const ret = wasm.isFullRangeOnly(tick_spacing);
516
+ return ret !== 0;
621
517
  }
622
518
 
623
519
  /**
624
- * Get the initializable tick index.
625
- * If the tick index is already initializable, it is returned as is.
520
+ * Get the index of a tick in a tick array.
626
521
  *
627
522
  * # Parameters
628
- * - `tick_index` - A i32 integer representing the tick integer
629
- * - `tick_spacing` - A i32 integer representing the tick spacing
630
- * - `round_up` - A boolean value indicating if the supplied tick index should be rounded up. None will round to the nearest.
523
+ * - `tick_index` - A i32 integer representing the tick index
524
+ * - `tick_array_start_index` - A i32 integer representing the start tick index of the tick array
525
+ * - `tick_spacing` - A u16 integer representing the tick spacing
631
526
  *
632
527
  * # Returns
633
- * - A i32 integer representing the previous initializable tick index
528
+ * - A u32 integer representing the tick index in the tick array
634
529
  */
635
- export function getInitializableTickIndex(tick_index, tick_spacing, round_up) {
636
- const ret = wasm.getInitializableTickIndex(tick_index, tick_spacing, isLikeNone(round_up) ? 0xFFFFFF : round_up ? 1 : 0);
637
- return ret;
530
+ export function getTickIndexInArray(tick_index, tick_array_start_index, tick_spacing) {
531
+ try {
532
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
533
+ wasm.getTickIndexInArray(retptr, tick_index, tick_array_start_index, tick_spacing);
534
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
535
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
536
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
537
+ if (r2) {
538
+ throw takeObject(r1);
539
+ }
540
+ return r0 >>> 0;
541
+ } finally {
542
+ wasm.__wbindgen_add_to_stack_pointer(16);
543
+ }
638
544
  }
639
545
 
640
546
  /**
641
- * Get the previous initializable tick index.
547
+ * Calculate the quote for decreasing liquidity
642
548
  *
643
549
  * # Parameters
644
- * - `tick_index` - A i32 integer representing the tick integer
645
- * - `tick_spacing` - A i32 integer representing the tick spacing
550
+ * - `liquidity_delta` - The amount of liquidity to decrease
551
+ * - `slippage_tolerance` - The slippage tolerance in bps
552
+ * - `current_sqrt_price` - The current sqrt price of the pool
553
+ * - `tick_index_1` - The first tick index of the position
554
+ * - `tick_index_2` - The second tick index of the position
555
+ * - `transfer_fee_a` - The transfer fee for token A in bps
556
+ * - `transfer_fee_b` - The transfer fee for token B in bps
646
557
  *
647
558
  * # Returns
648
- * - A i32 integer representing the previous initializable tick index
559
+ * - A DecreaseLiquidityQuote struct containing the estimated token amounts
649
560
  */
650
- export function getPrevInitializableTickIndex(tick_index, tick_spacing) {
651
- const ret = wasm.getPrevInitializableTickIndex(tick_index, tick_spacing);
652
- return ret;
561
+ export function decreaseLiquidityQuote(liquidity_delta, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
562
+ try {
563
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
564
+ 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));
565
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
566
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
567
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
568
+ if (r2) {
569
+ throw takeObject(r1);
570
+ }
571
+ return takeObject(r0);
572
+ } finally {
573
+ wasm.__wbindgen_add_to_stack_pointer(16);
574
+ }
653
575
  }
654
576
 
655
577
  /**
656
- * Get the next initializable tick index.
578
+ * Calculate the quote for decreasing liquidity given a token a amount
657
579
  *
658
580
  * # Parameters
659
- * - `tick_index` - A i32 integer representing the tick integer
660
- * - `tick_spacing` - A i32 integer representing the tick spacing
581
+ * - `token_amount_a` - The amount of token a to decrease
582
+ * - `slippage_tolerance` - The slippage tolerance in bps
583
+ * - `current_sqrt_price` - The current sqrt price of the pool
584
+ * - `tick_index_1` - The first tick index of the position
585
+ * - `tick_index_2` - The second tick index of the position
586
+ * - `transfer_fee_a` - The transfer fee for token A in bps
587
+ * - `transfer_fee_b` - The transfer fee for token B in bps
661
588
  *
662
589
  * # Returns
663
- * - A i32 integer representing the next initializable tick index
590
+ * - A DecreaseLiquidityQuote struct containing the estimated token amounts
664
591
  */
665
- export function getNextInitializableTickIndex(tick_index, tick_spacing) {
666
- const ret = wasm.getNextInitializableTickIndex(tick_index, tick_spacing);
667
- return ret;
592
+ export function decreaseLiquidityQuoteA(token_amount_a, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
593
+ try {
594
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
595
+ 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));
596
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
597
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
598
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
599
+ if (r2) {
600
+ throw takeObject(r1);
601
+ }
602
+ return takeObject(r0);
603
+ } finally {
604
+ wasm.__wbindgen_add_to_stack_pointer(16);
605
+ }
668
606
  }
669
607
 
670
608
  /**
671
- * Check if a tick is in-bounds.
609
+ * Calculate the quote for decreasing liquidity given a token b amount
672
610
  *
673
611
  * # Parameters
674
- * - `tick_index` - A i32 integer representing the tick integer
612
+ * - `token_amount_b` - The amount of token b to decrease
613
+ * - `slippage_tolerance` - The slippage tolerance in bps
614
+ * - `current_sqrt_price` - The current sqrt price of the pool
615
+ * - `tick_index_1` - The first tick index of the position
616
+ * - `tick_index_2` - The second tick index of the position
617
+ * - `transfer_fee_a` - The transfer fee for token A in bps
618
+ * - `transfer_fee_b` - The transfer fee for token B in bps
675
619
  *
676
620
  * # Returns
677
- * - A boolean value indicating if the tick is in-bounds
621
+ * - A DecreaseLiquidityQuote struct containing the estimated token amounts
678
622
  */
679
- export function isTickIndexInBounds(tick_index) {
680
- const ret = wasm.isTickIndexInBounds(tick_index);
681
- return ret !== 0;
623
+ export function decreaseLiquidityQuoteB(token_amount_b, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
624
+ try {
625
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
626
+ 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));
627
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
628
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
629
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
630
+ if (r2) {
631
+ throw takeObject(r1);
632
+ }
633
+ return takeObject(r0);
634
+ } finally {
635
+ wasm.__wbindgen_add_to_stack_pointer(16);
636
+ }
682
637
  }
683
638
 
684
639
  /**
685
- * Check if a tick is initializable.
686
- * A tick is initializable if it is divisible by the tick spacing.
640
+ * Calculate the quote for increasing liquidity
687
641
  *
688
642
  * # Parameters
689
- * - `tick_index` - A i32 integer representing the tick integer
690
- * - `tick_spacing` - A i32 integer representing the tick spacing
643
+ * - `liquidity_delta` - The amount of liquidity to increase
644
+ * - `slippage_tolerance` - The slippage tolerance in bps
645
+ * - `current_sqrt_price` - The current sqrt price of the pool
646
+ * - `tick_index_1` - The first tick index of the position
647
+ * - `tick_index_2` - The second tick index of the position
648
+ * - `transfer_fee_a` - The transfer fee for token A in bps
649
+ * - `transfer_fee_b` - The transfer fee for token B in bps
691
650
  *
692
651
  * # Returns
693
- * - A boolean value indicating if the tick is initializable
652
+ * - An IncreaseLiquidityQuote struct containing the estimated token amounts
694
653
  */
695
- export function isTickInitializable(tick_index, tick_spacing) {
696
- const ret = wasm.isTickInitializable(tick_index, tick_spacing);
697
- return ret !== 0;
654
+ export function increaseLiquidityQuote(liquidity_delta, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
655
+ try {
656
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
657
+ 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));
658
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
659
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
660
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
661
+ if (r2) {
662
+ throw takeObject(r1);
663
+ }
664
+ return takeObject(r0);
665
+ } finally {
666
+ wasm.__wbindgen_add_to_stack_pointer(16);
667
+ }
698
668
  }
699
669
 
700
670
  /**
701
- * Get the tick index for the inverse of the price that this tick represents.
702
- * Eg: Consider tick i where Pb/Pa = 1.0001 ^ i
703
- * inverse of this, i.e. Pa/Pb = 1 / (1.0001 ^ i) = 1.0001^-i
671
+ * Calculate the quote for increasing liquidity given a token a amount
704
672
  *
705
673
  * # Parameters
706
- * - `tick_index` - A i32 integer representing the tick integer
674
+ * - `token_amount_a` - The amount of token a to increase
675
+ * - `slippage_tolerance` - The slippage tolerance in bps
676
+ * - `current_sqrt_price` - The current sqrt price of the pool
677
+ * - `tick_index_1` - The first tick index of the position
678
+ * - `tick_index_2` - The second tick index of the position
679
+ * - `transfer_fee_a` - The transfer fee for token A in bps
680
+ * - `transfer_fee_b` - The transfer fee for token B in bps
707
681
  *
708
682
  * # Returns
709
- * - A i32 integer representing the tick index for the inverse of the price
683
+ * - An IncreaseLiquidityQuote struct containing the estimated token amounts
710
684
  */
711
- export function invertTickIndex(tick_index) {
712
- const ret = wasm.invertTickIndex(tick_index);
713
- return ret;
685
+ export function increaseLiquidityQuoteA(token_amount_a, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
686
+ try {
687
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
688
+ 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));
689
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
690
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
691
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
692
+ if (r2) {
693
+ throw takeObject(r1);
694
+ }
695
+ return takeObject(r0);
696
+ } finally {
697
+ wasm.__wbindgen_add_to_stack_pointer(16);
698
+ }
714
699
  }
715
700
 
716
701
  /**
717
- * Get the sqrt price for the inverse of the price that this tick represents.
718
- * Because converting to a tick index and then back to a sqrt price is lossy,
719
- * this function is clamped to the nearest tick index.
702
+ * Calculate the quote for increasing liquidity given a token b amount
720
703
  *
721
704
  * # Parameters
722
- * - `sqrt_price` - A u128 integer representing the sqrt price
705
+ * - `token_amount_b` - The amount of token b to increase
706
+ * - `slippage_tolerance` - The slippage tolerance in bps
707
+ * - `current_sqrt_price` - The current sqrt price of the pool
708
+ * - `tick_index_1` - The first tick index of the position
709
+ * - `tick_index_2` - The second tick index of the position
710
+ * - `transfer_fee_a` - The transfer fee for token A in bps
711
+ * - `transfer_fee_b` - The transfer fee for token B in bps
723
712
  *
724
713
  * # Returns
725
- * - A u128 integer representing the sqrt price for the inverse of the price
714
+ * - An IncreaseLiquidityQuote struct containing the estimated token amounts
726
715
  */
727
- export function invertSqrtPrice(sqrt_price) {
728
- const ret = wasm.invertSqrtPrice(addHeapObject(sqrt_price));
729
- return takeObject(ret);
716
+ export function increaseLiquidityQuoteB(token_amount_b, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
717
+ try {
718
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
719
+ 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));
720
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
721
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
722
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
723
+ if (r2) {
724
+ throw takeObject(r1);
725
+ }
726
+ return takeObject(r0);
727
+ } finally {
728
+ wasm.__wbindgen_add_to_stack_pointer(16);
729
+ }
730
+ }
731
+
732
+ export function tryGetLiquidityFromA(token_delta_a, sqrt_price_lower, sqrt_price_upper) {
733
+ try {
734
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
735
+ wasm.tryGetLiquidityFromA(retptr, token_delta_a, sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64));
736
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
737
+ var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
738
+ var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
739
+ var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
740
+ if (r5) {
741
+ throw takeObject(r4);
742
+ }
743
+ return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
744
+ } finally {
745
+ wasm.__wbindgen_add_to_stack_pointer(32);
746
+ }
747
+ }
748
+
749
+ export function tryGetTokenAFromLiquidity(liquidity_delta, sqrt_price_lower, sqrt_price_upper, round_up) {
750
+ try {
751
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
752
+ 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);
753
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
754
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
755
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
756
+ if (r3) {
757
+ throw takeObject(r2);
758
+ }
759
+ return BigInt.asUintN(64, r0);
760
+ } finally {
761
+ wasm.__wbindgen_add_to_stack_pointer(16);
762
+ }
763
+ }
764
+
765
+ export function tryGetLiquidityFromB(token_delta_b, sqrt_price_lower, sqrt_price_upper) {
766
+ try {
767
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
768
+ wasm.tryGetLiquidityFromB(retptr, token_delta_b, sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64));
769
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
770
+ var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
771
+ var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
772
+ var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
773
+ if (r5) {
774
+ throw takeObject(r4);
775
+ }
776
+ return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
777
+ } finally {
778
+ wasm.__wbindgen_add_to_stack_pointer(32);
779
+ }
780
+ }
781
+
782
+ export function tryGetTokenBFromLiquidity(liquidity_delta, sqrt_price_lower, sqrt_price_upper, round_up) {
783
+ try {
784
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
785
+ 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);
786
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
787
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
788
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
789
+ if (r3) {
790
+ throw takeObject(r2);
791
+ }
792
+ return BigInt.asUintN(64, r0);
793
+ } finally {
794
+ wasm.__wbindgen_add_to_stack_pointer(16);
795
+ }
796
+ }
797
+
798
+ export function tryGetAmountsFromLiquidity(liquidity_delta, current_sqrt_price, tick_lower_index, tick_upper_index, round_up) {
799
+ try {
800
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
801
+ 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);
802
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
803
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
804
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
805
+ if (r2) {
806
+ throw takeObject(r1);
807
+ }
808
+ return takeObject(r0);
809
+ } finally {
810
+ wasm.__wbindgen_add_to_stack_pointer(16);
811
+ }
812
+ }
813
+
814
+ export function tryGetLiquidityFromAmounts(sqrt_price, sqrt_price_a_x64, sqrt_price_b_x64, amount_a, amount_b) {
815
+ try {
816
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
817
+ 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);
818
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
819
+ var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
820
+ var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
821
+ var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
822
+ if (r5) {
823
+ throw takeObject(r4);
824
+ }
825
+ return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
826
+ } finally {
827
+ wasm.__wbindgen_add_to_stack_pointer(32);
828
+ }
730
829
  }
731
830
 
732
831
  /**
733
- * Get the minimum and maximum tick index that can be initialized.
832
+ * Calculate fees owed for a position
734
833
  *
735
- * # Parameters
736
- * - `tick_spacing` - A i32 integer representing the tick spacing
834
+ * # Paramters
835
+ * - `fusion_pool`: The fusion_pool state
836
+ * - `position`: The position state
837
+ * - `tick_lower`: The lower tick state
838
+ * - `tick_upper`: The upper tick state
839
+ * - `transfer_fee_a`: The transfer fee for token A
840
+ * - `transfer_fee_b`: The transfer fee for token B
737
841
  *
738
842
  * # Returns
739
- * - A TickRange struct containing the lower and upper tick index
843
+ * - `CollectFeesQuote`: The fees owed for token A and token B
740
844
  */
741
- export function getFullRangeTickIndexes(tick_spacing) {
742
- const ret = wasm.getFullRangeTickIndexes(tick_spacing);
743
- return takeObject(ret);
845
+ export function collectFeesQuote(fusion_pool, position, tick_lower, tick_upper, transfer_fee_a, transfer_fee_b) {
846
+ try {
847
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
848
+ 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));
849
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
850
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
851
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
852
+ if (r2) {
853
+ throw takeObject(r1);
854
+ }
855
+ return takeObject(r0);
856
+ } finally {
857
+ wasm.__wbindgen_add_to_stack_pointer(16);
858
+ }
859
+ }
860
+
861
+ export function limitOrderFee(fusion_pool) {
862
+ const ret = wasm.limitOrderFee(addHeapObject(fusion_pool));
863
+ return ret;
744
864
  }
745
865
 
746
866
  /**
747
- * Order tick indexes in ascending order.
748
- * If the lower tick index is greater than the upper tick index, the indexes are swapped.
749
- * This is useful for ensuring that the lower tick index is always less than the upper tick index.
867
+ * Calculate the amount A delta between two sqrt_prices
750
868
  *
751
869
  * # Parameters
752
- * - `tick_index_1` - A i32 integer representing the first tick index
753
- * - `tick_index_2` - A i32 integer representing the second tick index
870
+ * - `sqrt_price_1`: The first square root price
871
+ * - `sqrt_price_2`: The second square root price
872
+ * - `liquidity`: The liquidity
873
+ * - `round_up`: Whether to round up or not
754
874
  *
755
875
  * # Returns
756
- * - A TickRange struct containing the lower and upper tick index
876
+ * - `u64`: The amount delta
757
877
  */
758
- export function orderTickIndexes(tick_index_1, tick_index_2) {
759
- const ret = wasm.orderTickIndexes(tick_index_1, tick_index_2);
760
- return takeObject(ret);
878
+ export function tryGetAmountDeltaA(sqrt_price_1, sqrt_price_2, liquidity, round_up) {
879
+ try {
880
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
881
+ wasm.tryGetAmountDeltaA(retptr, sqrt_price_1, sqrt_price_1 >> BigInt(64), sqrt_price_2, sqrt_price_2 >> BigInt(64), liquidity, liquidity >> BigInt(64), round_up);
882
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
883
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
884
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
885
+ if (r3) {
886
+ throw takeObject(r2);
887
+ }
888
+ return BigInt.asUintN(64, r0);
889
+ } finally {
890
+ wasm.__wbindgen_add_to_stack_pointer(16);
891
+ }
761
892
  }
762
893
 
763
894
  /**
764
- * Check if a fusion_pool is a full-range only pool.
895
+ * Calculate the amount B delta between two sqrt_prices
765
896
  *
766
897
  * # Parameters
767
- * - `tick_spacing` - A u16 integer representing the tick spacing
898
+ * - `sqrt_price_1`: The first square root price
899
+ * - `sqrt_price_2`: The second square root price
900
+ * - `liquidity`: The liquidity
901
+ * - `round_up`: Whether to round up or not
768
902
  *
769
903
  * # Returns
770
- * - A boolean value indicating if the fusion_pool is a full-range only pool
904
+ * - `u64`: The amount delta
771
905
  */
772
- export function isFullRangeOnly(tick_spacing) {
773
- const ret = wasm.isFullRangeOnly(tick_spacing);
774
- return ret !== 0;
906
+ export function tryGetAmountDeltaB(sqrt_price_1, sqrt_price_2, liquidity, round_up) {
907
+ try {
908
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
909
+ wasm.tryGetAmountDeltaB(retptr, sqrt_price_1, sqrt_price_1 >> BigInt(64), sqrt_price_2, sqrt_price_2 >> BigInt(64), liquidity, liquidity >> BigInt(64), round_up);
910
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
911
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
912
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
913
+ if (r3) {
914
+ throw takeObject(r2);
915
+ }
916
+ return BigInt.asUintN(64, r0);
917
+ } finally {
918
+ wasm.__wbindgen_add_to_stack_pointer(16);
919
+ }
775
920
  }
776
921
 
777
922
  /**
778
- * Get the index of a tick in a tick array.
923
+ * Calculate the next square root price
779
924
  *
780
925
  * # Parameters
781
- * - `tick_index` - A i32 integer representing the tick index
782
- * - `tick_array_start_index` - A i32 integer representing the start tick index of the tick array
783
- * - `tick_spacing` - A u16 integer representing the tick spacing
926
+ * - `current_sqrt_price`: The current square root price
927
+ * - `current_liquidity`: The current liquidity
928
+ * - `amount`: The amount
929
+ * - `specified_input`: Whether the input is specified
784
930
  *
785
931
  * # Returns
786
- * - A u32 integer representing the tick index in the tick array
932
+ * - `u128`: The next square root price
787
933
  */
788
- export function getTickIndexInArray(tick_index, tick_array_start_index, tick_spacing) {
934
+ export function tryGetNextSqrtPriceFromA(current_sqrt_price, current_liquidity, amount, specified_input) {
789
935
  try {
790
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
791
- wasm.getTickIndexInArray(retptr, tick_index, tick_array_start_index, tick_spacing);
792
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
793
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
794
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
795
- if (r2) {
796
- throw takeObject(r1);
936
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
937
+ wasm.tryGetNextSqrtPriceFromA(retptr, current_sqrt_price, current_sqrt_price >> BigInt(64), current_liquidity, current_liquidity >> BigInt(64), amount, specified_input);
938
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
939
+ var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
940
+ var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
941
+ var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
942
+ if (r5) {
943
+ throw takeObject(r4);
797
944
  }
798
- return r0 >>> 0;
945
+ return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
799
946
  } finally {
800
- wasm.__wbindgen_add_to_stack_pointer(16);
947
+ wasm.__wbindgen_add_to_stack_pointer(32);
801
948
  }
802
949
  }
803
950
 
804
951
  /**
805
- * Calculate the quote for decreasing liquidity
952
+ * Calculate the next square root price
806
953
  *
807
954
  * # Parameters
808
- * - `liquidity_delta` - The amount of liquidity to decrease
809
- * - `slippage_tolerance` - The slippage tolerance in bps
810
- * - `current_sqrt_price` - The current sqrt price of the pool
811
- * - `tick_index_1` - The first tick index of the position
812
- * - `tick_index_2` - The second tick index of the position
813
- * - `transfer_fee_a` - The transfer fee for token A in bps
814
- * - `transfer_fee_b` - The transfer fee for token B in bps
955
+ * - `current_sqrt_price`: The current square root price
956
+ * - `current_liquidity`: The current liquidity
957
+ * - `amount`: The amount
958
+ * - `specified_input`: Whether the input is specified
815
959
  *
816
960
  * # Returns
817
- * - A DecreaseLiquidityQuote struct containing the estimated token amounts
961
+ * - `u128`: The next square root price
818
962
  */
819
- export function decreaseLiquidityQuote(liquidity_delta, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
963
+ export function tryGetNextSqrtPriceFromB(current_sqrt_price, current_liquidity, amount, specified_input) {
820
964
  try {
821
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
822
- wasm.decreaseLiquidityQuote(retptr, addHeapObject(liquidity_delta), slippage_tolerance_bps, addHeapObject(current_sqrt_price), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
823
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
824
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
825
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
826
- if (r2) {
827
- throw takeObject(r1);
965
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
966
+ wasm.tryGetNextSqrtPriceFromB(retptr, current_sqrt_price, current_sqrt_price >> BigInt(64), current_liquidity, current_liquidity >> BigInt(64), amount, specified_input);
967
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
968
+ var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
969
+ var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
970
+ var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
971
+ if (r5) {
972
+ throw takeObject(r4);
828
973
  }
829
- return takeObject(r0);
974
+ return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
830
975
  } finally {
831
- wasm.__wbindgen_add_to_stack_pointer(16);
976
+ wasm.__wbindgen_add_to_stack_pointer(32);
832
977
  }
833
978
  }
834
979
 
835
980
  /**
836
- * Calculate the quote for decreasing liquidity given a token a amount
981
+ * Apply a transfer fee to an amount
982
+ * e.g. You send 10000 amount with 100 fee rate. The fee amount will be 100.
983
+ * So the amount after fee will be 9900.
837
984
  *
838
985
  * # Parameters
839
- * - `token_amount_a` - The amount of token a to decrease
840
- * - `slippage_tolerance` - The slippage tolerance in bps
841
- * - `current_sqrt_price` - The current sqrt price of the pool
842
- * - `tick_index_1` - The first tick index of the position
843
- * - `tick_index_2` - The second tick index of the position
844
- * - `transfer_fee_a` - The transfer fee for token A in bps
845
- * - `transfer_fee_b` - The transfer fee for token B in bps
986
+ * - `amount`: The amount to apply the fee to
987
+ * - `transfer_fee`: The transfer fee to apply
846
988
  *
847
989
  * # Returns
848
- * - A DecreaseLiquidityQuote struct containing the estimated token amounts
990
+ * - `u64`: The amount after the fee has been applied
849
991
  */
850
- export function decreaseLiquidityQuoteA(token_amount_a, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
992
+ export function tryApplyTransferFee(amount, transfer_fee) {
851
993
  try {
852
994
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
853
- wasm.decreaseLiquidityQuoteA(retptr, token_amount_a, slippage_tolerance_bps, addHeapObject(current_sqrt_price), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
854
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
855
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
995
+ wasm.tryApplyTransferFee(retptr, amount, addHeapObject(transfer_fee));
996
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
856
997
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
857
- if (r2) {
858
- throw takeObject(r1);
998
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
999
+ if (r3) {
1000
+ throw takeObject(r2);
859
1001
  }
860
- return takeObject(r0);
1002
+ return BigInt.asUintN(64, r0);
861
1003
  } finally {
862
1004
  wasm.__wbindgen_add_to_stack_pointer(16);
863
1005
  }
864
1006
  }
865
1007
 
866
1008
  /**
867
- * Calculate the quote for decreasing liquidity given a token b amount
1009
+ * Reverse the application of a transfer fee to an amount
1010
+ * e.g. You received 9900 amount with 100 fee rate. The fee amount will be 100.
1011
+ * So the amount before fee will be 10000.
868
1012
  *
869
1013
  * # Parameters
870
- * - `token_amount_b` - The amount of token b to decrease
871
- * - `slippage_tolerance` - The slippage tolerance in bps
872
- * - `current_sqrt_price` - The current sqrt price of the pool
873
- * - `tick_index_1` - The first tick index of the position
874
- * - `tick_index_2` - The second tick index of the position
875
- * - `transfer_fee_a` - The transfer fee for token A in bps
876
- * - `transfer_fee_b` - The transfer fee for token B in bps
1014
+ * - `amount`: The amount to reverse the fee from
1015
+ * - `transfer_fee`: The transfer fee to reverse
877
1016
  *
878
1017
  * # Returns
879
- * - A DecreaseLiquidityQuote struct containing the estimated token amounts
1018
+ * - `u64`: The amount before the fee has been applied
880
1019
  */
881
- export function decreaseLiquidityQuoteB(token_amount_b, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
1020
+ export function tryReverseApplyTransferFee(amount, transfer_fee) {
882
1021
  try {
883
1022
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
884
- wasm.decreaseLiquidityQuoteB(retptr, token_amount_b, slippage_tolerance_bps, addHeapObject(current_sqrt_price), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
885
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
886
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1023
+ wasm.tryReverseApplyTransferFee(retptr, amount, addHeapObject(transfer_fee));
1024
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
887
1025
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
888
- if (r2) {
889
- throw takeObject(r1);
1026
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1027
+ if (r3) {
1028
+ throw takeObject(r2);
890
1029
  }
891
- return takeObject(r0);
1030
+ return BigInt.asUintN(64, r0);
892
1031
  } finally {
893
1032
  wasm.__wbindgen_add_to_stack_pointer(16);
894
1033
  }
895
1034
  }
896
1035
 
897
1036
  /**
898
- * Calculate the quote for increasing liquidity
1037
+ * Get the maximum amount with a slippage tolerance
1038
+ * e.g. Your estimated amount you send is 10000 with 100 slippage tolerance. The max you send will be 10100.
899
1039
  *
900
1040
  * # Parameters
901
- * - `liquidity_delta` - The amount of liquidity to increase
902
- * - `slippage_tolerance` - The slippage tolerance in bps
903
- * - `current_sqrt_price` - The current sqrt price of the pool
904
- * - `tick_index_1` - The first tick index of the position
905
- * - `tick_index_2` - The second tick index of the position
906
- * - `transfer_fee_a` - The transfer fee for token A in bps
907
- * - `transfer_fee_b` - The transfer fee for token B in bps
1041
+ * - `amount`: The amount to apply the fee to
1042
+ * - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
908
1043
  *
909
1044
  * # Returns
910
- * - An IncreaseLiquidityQuote struct containing the estimated token amounts
1045
+ * - `u64`: The maximum amount
911
1046
  */
912
- export function increaseLiquidityQuote(liquidity_delta, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
1047
+ export function tryGetMaxAmountWithSlippageTolerance(amount, slippage_tolerance_bps) {
913
1048
  try {
914
1049
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
915
- wasm.increaseLiquidityQuote(retptr, addHeapObject(liquidity_delta), slippage_tolerance_bps, addHeapObject(current_sqrt_price), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
916
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
917
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1050
+ wasm.tryGetMaxAmountWithSlippageTolerance(retptr, amount, slippage_tolerance_bps);
1051
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
918
1052
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
919
- if (r2) {
920
- throw takeObject(r1);
1053
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1054
+ if (r3) {
1055
+ throw takeObject(r2);
921
1056
  }
922
- return takeObject(r0);
1057
+ return BigInt.asUintN(64, r0);
923
1058
  } finally {
924
1059
  wasm.__wbindgen_add_to_stack_pointer(16);
925
1060
  }
926
1061
  }
927
1062
 
928
1063
  /**
929
- * Calculate the quote for increasing liquidity given a token a amount
1064
+ * Get the minimum amount with a slippage tolerance
1065
+ * e.g. Your estimated amount you receive is 10000 with 100 slippage tolerance. The min amount you receive will be 9900.
930
1066
  *
931
1067
  * # Parameters
932
- * - `token_amount_a` - The amount of token a to increase
933
- * - `slippage_tolerance` - The slippage tolerance in bps
934
- * - `current_sqrt_price` - The current sqrt price of the pool
935
- * - `tick_index_1` - The first tick index of the position
936
- * - `tick_index_2` - The second tick index of the position
937
- * - `transfer_fee_a` - The transfer fee for token A in bps
938
- * - `transfer_fee_b` - The transfer fee for token B in bps
1068
+ * - `amount`: The amount to apply the fee to
1069
+ * - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
939
1070
  *
940
1071
  * # Returns
941
- * - An IncreaseLiquidityQuote struct containing the estimated token amounts
1072
+ * - `u64`: The minimum amount
942
1073
  */
943
- export function increaseLiquidityQuoteA(token_amount_a, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
1074
+ export function tryGetMinAmountWithSlippageTolerance(amount, slippage_tolerance_bps) {
944
1075
  try {
945
1076
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
946
- wasm.increaseLiquidityQuoteA(retptr, token_amount_a, slippage_tolerance_bps, addHeapObject(current_sqrt_price), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
947
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
948
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1077
+ wasm.tryGetMinAmountWithSlippageTolerance(retptr, amount, slippage_tolerance_bps);
1078
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
949
1079
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
950
- if (r2) {
951
- throw takeObject(r1);
1080
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1081
+ if (r3) {
1082
+ throw takeObject(r2);
952
1083
  }
953
- return takeObject(r0);
1084
+ return BigInt.asUintN(64, r0);
954
1085
  } finally {
955
1086
  wasm.__wbindgen_add_to_stack_pointer(16);
956
1087
  }
957
1088
  }
958
1089
 
959
1090
  /**
960
- * Calculate the quote for increasing liquidity given a token b amount
1091
+ * Apply a swap fee to an amount
1092
+ * e.g. You send 10000 amount with 10000 fee rate. The fee amount will be 100.
1093
+ * So the amount after fee will be 9900.
961
1094
  *
962
1095
  * # Parameters
963
- * - `token_amount_b` - The amount of token b to increase
964
- * - `slippage_tolerance` - The slippage tolerance in bps
965
- * - `current_sqrt_price` - The current sqrt price of the pool
966
- * - `tick_index_1` - The first tick index of the position
967
- * - `tick_index_2` - The second tick index of the position
968
- * - `transfer_fee_a` - The transfer fee for token A in bps
969
- * - `transfer_fee_b` - The transfer fee for token B in bps
1096
+ * - `amount`: The amount to apply the fee to
1097
+ * - `fee_rate`: The fee rate to apply denominated in 1e6
970
1098
  *
971
1099
  * # Returns
972
- * - An IncreaseLiquidityQuote struct containing the estimated token amounts
1100
+ * - `u64`: The amount after the fee has been applied
973
1101
  */
974
- export function increaseLiquidityQuoteB(token_amount_b, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
1102
+ export function tryApplySwapFee(amount, fee_rate) {
975
1103
  try {
976
1104
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
977
- wasm.increaseLiquidityQuoteB(retptr, token_amount_b, slippage_tolerance_bps, addHeapObject(current_sqrt_price), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
978
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
979
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1105
+ wasm.tryApplySwapFee(retptr, amount, fee_rate);
1106
+ var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
980
1107
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
981
- if (r2) {
982
- throw takeObject(r1);
1108
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1109
+ if (r3) {
1110
+ throw takeObject(r2);
983
1111
  }
984
- return takeObject(r0);
1112
+ return BigInt.asUintN(64, r0);
985
1113
  } finally {
986
1114
  wasm.__wbindgen_add_to_stack_pointer(16);
987
1115
  }
988
1116
  }
989
1117
 
990
- export function tryGetLiquidityFromA(token_delta_a, sqrt_price_lower, sqrt_price_upper) {
1118
+ /**
1119
+ * Reverse the application of a swap fee to an amount
1120
+ * e.g. You received 9900 amount with 10000 fee rate. The fee amount will be 100.
1121
+ * So the amount before fee will be 10000.
1122
+ *
1123
+ * # Parameters
1124
+ * - `amount`: The amount to reverse the fee from
1125
+ * - `fee_rate`: The fee rate to reverse denominated in 1e6
1126
+ *
1127
+ * # Returns
1128
+ * - `u64`: The amount before the fee has been applied
1129
+ */
1130
+ export function tryReverseApplySwapFee(amount, fee_rate) {
991
1131
  try {
992
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
993
- wasm.tryGetLiquidityFromA(retptr, token_delta_a, sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64));
1132
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1133
+ wasm.tryReverseApplySwapFee(retptr, amount, fee_rate);
994
1134
  var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
995
- var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
996
- var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
997
- var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
998
- if (r5) {
999
- throw takeObject(r4);
1135
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1136
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1137
+ if (r3) {
1138
+ throw takeObject(r2);
1000
1139
  }
1001
- return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
1140
+ return BigInt.asUintN(64, r0);
1002
1141
  } finally {
1003
- wasm.__wbindgen_add_to_stack_pointer(32);
1142
+ wasm.__wbindgen_add_to_stack_pointer(16);
1004
1143
  }
1005
1144
  }
1006
1145
 
1007
- export function tryGetTokenAFromLiquidity(liquidity_delta, sqrt_price_lower, sqrt_price_upper, round_up) {
1146
+ /**
1147
+ * Computes the limit order output amount by input amount.
1148
+ * ### Parameters
1149
+ * - `amount_in` - The input token amount of a limit order.
1150
+ * - `a_to_b_order` - The limit order direction.
1151
+ * - `tick_index` - The tick index of an order.
1152
+ * - `fusion_pool` - The fusion_pool state.
1153
+ */
1154
+ export function limitOrderQuoteByInputToken(amount_in, a_to_b_order, tick_index, fusion_pool) {
1008
1155
  try {
1009
1156
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1010
- 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);
1157
+ wasm.limitOrderQuoteByInputToken(retptr, amount_in, a_to_b_order, tick_index, addHeapObject(fusion_pool));
1011
1158
  var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
1012
1159
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1013
1160
  var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
@@ -1020,27 +1167,42 @@ export function tryGetTokenAFromLiquidity(liquidity_delta, sqrt_price_lower, sqr
1020
1167
  }
1021
1168
  }
1022
1169
 
1023
- export function tryGetLiquidityFromB(token_delta_b, sqrt_price_lower, sqrt_price_upper) {
1170
+ /**
1171
+ * Computes the limit order input amount by output amount.
1172
+ * ### Parameters
1173
+ * - `amount_out` - The output token amount of a limit order.
1174
+ * - `a_to_b_order` - The limit order direction.
1175
+ * - `tick_index` - The tick index of an order.
1176
+ * - `fusion_pool` - The fusion_pool state.
1177
+ */
1178
+ export function limitOrderQuoteByOutputToken(amount_out, a_to_b_order, tick_index, fusion_pool) {
1024
1179
  try {
1025
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
1026
- wasm.tryGetLiquidityFromB(retptr, token_delta_b, sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64));
1180
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1181
+ wasm.limitOrderQuoteByOutputToken(retptr, amount_out, a_to_b_order, tick_index, addHeapObject(fusion_pool));
1027
1182
  var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
1028
- var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
1029
- var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
1030
- var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
1031
- if (r5) {
1032
- throw takeObject(r4);
1183
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1184
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1185
+ if (r3) {
1186
+ throw takeObject(r2);
1033
1187
  }
1034
- return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
1188
+ return BigInt.asUintN(64, r0);
1035
1189
  } finally {
1036
- wasm.__wbindgen_add_to_stack_pointer(32);
1190
+ wasm.__wbindgen_add_to_stack_pointer(16);
1037
1191
  }
1038
1192
  }
1039
1193
 
1040
- export function tryGetTokenBFromLiquidity(liquidity_delta, sqrt_price_lower, sqrt_price_upper, round_up) {
1194
+ /**
1195
+ * Computes the limit order reward by input amount.
1196
+ * ### Parameters
1197
+ * - `amount_out` - The output token amount of a limit order (swap input).
1198
+ * - `a_to_b_order` - The limit order direction.
1199
+ * - `tick_index` - The tick index of an order.
1200
+ * - `fusion_pool` - The fusion_pool state.
1201
+ */
1202
+ export function limitOrderRewardByOutputToken(amount_out, fee_rate, protocol_fee_rate) {
1041
1203
  try {
1042
1204
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1043
- 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);
1205
+ wasm.limitOrderRewardByOutputToken(retptr, amount_out, fee_rate, protocol_fee_rate);
1044
1206
  var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
1045
1207
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1046
1208
  var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
@@ -1053,10 +1215,10 @@ export function tryGetTokenBFromLiquidity(liquidity_delta, sqrt_price_lower, sqr
1053
1215
  }
1054
1216
  }
1055
1217
 
1056
- export function tryGetTokenEstimatesFromLiquidity(liquidity_delta, current_sqrt_price, tick_lower_index, tick_upper_index, round_up) {
1218
+ export function decreaseLimitOrderQuote(fusion_pool, limit_order, tick, amount, transfer_fee_a, transfer_fee_b) {
1057
1219
  try {
1058
1220
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1059
- wasm.tryGetTokenEstimatesFromLiquidity(retptr, liquidity_delta, liquidity_delta >> BigInt(64), current_sqrt_price, current_sqrt_price >> BigInt(64), tick_lower_index, tick_upper_index, round_up);
1221
+ 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));
1060
1222
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1061
1223
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1062
1224
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -1070,131 +1232,202 @@ export function tryGetTokenEstimatesFromLiquidity(liquidity_delta, current_sqrt_
1070
1232
  }
1071
1233
 
1072
1234
  /**
1073
- * Calculate fees owed for a position
1235
+ * Get the first unoccupied position in a bundle
1074
1236
  *
1075
- * # Paramters
1076
- * - `fusion_pool`: The fusion_pool state
1077
- * - `position`: The position state
1078
- * - `tick_lower`: The lower tick state
1079
- * - `tick_upper`: The upper tick state
1080
- * - `transfer_fee_a`: The transfer fee for token A
1081
- * - `transfer_fee_b`: The transfer fee for token B
1237
+ * # Arguments
1238
+ * * `bundle` - The bundle to check
1082
1239
  *
1083
1240
  * # Returns
1084
- * - `CollectFeesQuote`: The fees owed for token A and token B
1241
+ * * `u32` - The first unoccupied position (None if full)
1085
1242
  */
1086
- export function collectFeesQuote(fusion_pool, position, tick_lower, tick_upper, transfer_fee_a, transfer_fee_b) {
1087
- try {
1088
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1089
- 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));
1090
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1091
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1092
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1093
- if (r2) {
1094
- throw takeObject(r1);
1095
- }
1096
- return takeObject(r0);
1097
- } finally {
1098
- wasm.__wbindgen_add_to_stack_pointer(16);
1099
- }
1243
+ export function firstUnoccupiedPositionInBundle(bitmap) {
1244
+ const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
1245
+ const len0 = WASM_VECTOR_LEN;
1246
+ const ret = wasm.firstUnoccupiedPositionInBundle(ptr0, len0);
1247
+ return ret === 0x100000001 ? undefined : ret;
1100
1248
  }
1101
1249
 
1102
- export function limitOrderFee(fusion_pool) {
1103
- const ret = wasm.limitOrderFee(addHeapObject(fusion_pool));
1104
- return ret;
1250
+ /**
1251
+ * Check whether a position bundle is full
1252
+ * A position bundle can contain 256 positions
1253
+ *
1254
+ * # Arguments
1255
+ * * `bundle` - The bundle to check
1256
+ *
1257
+ * # Returns
1258
+ * * `bool` - Whether the bundle is full
1259
+ */
1260
+ export function isPositionBundleFull(bitmap) {
1261
+ const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
1262
+ const len0 = WASM_VECTOR_LEN;
1263
+ const ret = wasm.isPositionBundleFull(ptr0, len0);
1264
+ return ret !== 0;
1105
1265
  }
1106
1266
 
1107
1267
  /**
1108
- * Computes the limit order output amount by input amount.
1109
- * ### Parameters
1110
- * - `amount_in` - The input token amount of a limit order.
1111
- * - `a_to_b_order` - The limit order direction.
1112
- * - `tick_index` - The tick index of an order.
1113
- * - `fusion_pool` - The fusion_pool state.
1268
+ * Check whether a position bundle is empty
1269
+ *
1270
+ * # Arguments
1271
+ * * `bundle` - The bundle to check
1272
+ *
1273
+ * # Returns
1274
+ * * `bool` - Whether the bundle is empty
1114
1275
  */
1115
- export function limitOrderQuoteByInputToken(amount_in, a_to_b_order, tick_index, fusion_pool) {
1116
- try {
1117
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1118
- wasm.limitOrderQuoteByInputToken(retptr, amount_in, a_to_b_order, tick_index, addHeapObject(fusion_pool));
1119
- var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
1120
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1121
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1122
- if (r3) {
1123
- throw takeObject(r2);
1124
- }
1125
- return BigInt.asUintN(64, r0);
1126
- } finally {
1127
- wasm.__wbindgen_add_to_stack_pointer(16);
1128
- }
1276
+ export function isPositionBundleEmpty(bitmap) {
1277
+ const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
1278
+ const len0 = WASM_VECTOR_LEN;
1279
+ const ret = wasm.isPositionBundleEmpty(ptr0, len0);
1280
+ return ret !== 0;
1129
1281
  }
1130
1282
 
1131
1283
  /**
1132
- * Computes the limit order input amount by output amount.
1133
- * ### Parameters
1134
- * - `amount_out` - The output token amount of a limit order.
1135
- * - `a_to_b_order` - The limit order direction.
1136
- * - `tick_index` - The tick index of an order.
1137
- * - `fusion_pool` - The fusion_pool state.
1284
+ * Check if a position is in range.
1285
+ * When a position is in range it is earning fees and rewards
1286
+ *
1287
+ * # Parameters
1288
+ * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
1289
+ * - `tick_index_1` - A i32 integer representing the first tick index of the position
1290
+ * - `tick_index_2` - A i32 integer representing the second tick index of the position
1291
+ *
1292
+ * # Returns
1293
+ * - A boolean value indicating if the position is in range
1138
1294
  */
1139
- export function limitOrderQuoteByOutputToken(amount_out, a_to_b_order, tick_index, fusion_pool) {
1295
+ export function isPositionInRange(current_sqrt_price, tick_index_1, tick_index_2) {
1296
+ const ret = wasm.isPositionInRange(current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2);
1297
+ return ret !== 0;
1298
+ }
1299
+
1300
+ /**
1301
+ * Calculate the status of a position
1302
+ * The status can be one of three values:
1303
+ * - InRange: The position is in range
1304
+ * - BelowRange: The position is below the range
1305
+ * - AboveRange: The position is above the range
1306
+ *
1307
+ * # Parameters
1308
+ * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
1309
+ * - `tick_index_1` - A i32 integer representing the first tick index of the position
1310
+ * - `tick_index_2` - A i32 integer representing the second tick index of the position
1311
+ *
1312
+ * # Returns
1313
+ * - A PositionStatus enum value indicating the status of the position
1314
+ */
1315
+ export function positionStatus(current_sqrt_price, tick_index_1, tick_index_2) {
1316
+ const ret = wasm.positionStatus(current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2);
1317
+ return takeObject(ret);
1318
+ }
1319
+
1320
+ /**
1321
+ * Calculate the token_a / token_b ratio of a (ficticious) position
1322
+ *
1323
+ * # Parameters
1324
+ * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
1325
+ * - `tick_index_1` - A i32 integer representing the first tick index of the position
1326
+ * - `tick_index_2` - A i32 integer representing the second tick index of the position
1327
+ *
1328
+ * # Returns
1329
+ * - A PositionRatio struct containing the ratio of token_a and token_b
1330
+ */
1331
+ export function positionRatioX64(current_sqrt_price, tick_index_1, tick_index_2) {
1332
+ const ret = wasm.positionRatioX64(current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2);
1333
+ return takeObject(ret);
1334
+ }
1335
+
1336
+ /**
1337
+ * Convert a price into a sqrt priceX64
1338
+ * IMPORTANT: floating point operations can reduce the precision of the result.
1339
+ * Make sure to do these operations last and not to use the result for further calculations.
1340
+ *
1341
+ * # Parameters
1342
+ * * `price` - The price to convert
1343
+ * * `decimals_a` - The number of decimals of the base token
1344
+ * * `decimals_b` - The number of decimals of the quote token
1345
+ *
1346
+ * # Returns
1347
+ * * `u128` - The sqrt priceX64
1348
+ */
1349
+ export function priceToSqrtPrice(price, decimals_a, decimals_b) {
1140
1350
  try {
1141
1351
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1142
- wasm.limitOrderQuoteByOutputToken(retptr, amount_out, a_to_b_order, tick_index, addHeapObject(fusion_pool));
1352
+ wasm.priceToSqrtPrice(retptr, price, decimals_a, decimals_b);
1143
1353
  var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
1144
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1145
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1146
- if (r3) {
1147
- throw takeObject(r2);
1148
- }
1149
- return BigInt.asUintN(64, r0);
1354
+ var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
1355
+ return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
1150
1356
  } finally {
1151
1357
  wasm.__wbindgen_add_to_stack_pointer(16);
1152
1358
  }
1153
1359
  }
1154
1360
 
1155
1361
  /**
1156
- * Computes the limit order reward by input amount.
1157
- * ### Parameters
1158
- * - `amount_out` - The output token amount of a limit order (swap input).
1159
- * - `a_to_b_order` - The limit order direction.
1160
- * - `tick_index` - The tick index of an order.
1161
- * - `fusion_pool` - The fusion_pool state.
1362
+ * Convert a sqrt priceX64 into a tick index
1363
+ * IMPORTANT: floating point operations can reduce the precision of the result.
1364
+ * Make sure to do these operations last and not to use the result for further calculations.
1365
+ *
1366
+ * # Parameters
1367
+ * * `sqrt_price` - The sqrt priceX64 to convert
1368
+ * * `decimals_a` - The number of decimals of the base token
1369
+ * * `decimals_b` - The number of decimals of the quote token
1370
+ *
1371
+ * # Returns
1372
+ * * `f64` - The decimal price
1373
+ */
1374
+ export function sqrtPriceToPrice(sqrt_price, decimals_a, decimals_b) {
1375
+ const ret = wasm.sqrtPriceToPrice(sqrt_price, sqrt_price >> BigInt(64), decimals_a, decimals_b);
1376
+ return ret;
1377
+ }
1378
+
1379
+ /**
1380
+ * Invert a price
1381
+ * IMPORTANT: floating point operations can reduce the precision of the result.
1382
+ * Make sure to do these operations last and not to use the result for further calculations.
1383
+ *
1384
+ * # Parameters
1385
+ * * `price` - The price to invert
1386
+ * * `decimals_a` - The number of decimals of the base token
1387
+ * * `decimals_b` - The number of decimals of the quote token
1388
+ *
1389
+ * # Returns
1390
+ * * `f64` - The inverted price
1391
+ */
1392
+ export function invertPrice(price, decimals_a, decimals_b) {
1393
+ const ret = wasm.invertPrice(price, decimals_a, decimals_b);
1394
+ return ret;
1395
+ }
1396
+
1397
+ /**
1398
+ * Convert a tick index into a price
1399
+ * IMPORTANT: floating point operations can reduce the precision of the result.
1400
+ * Make sure to do these operations last and not to use the result for further calculations.
1401
+ *
1402
+ * # Parameters
1403
+ * * `tick_index` - The tick index to convert
1404
+ * * `decimals_a` - The number of decimals of the base token
1405
+ * * `decimals_b` - The number of decimals of the quote token
1406
+ *
1407
+ * # Returns
1408
+ * * `f64` - The decimal price
1162
1409
  */
1163
- export function limitOrderRewardByOutputToken(amount_out, fee_rate, protocol_fee_rate) {
1164
- try {
1165
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1166
- wasm.limitOrderRewardByOutputToken(retptr, amount_out, fee_rate, protocol_fee_rate);
1167
- var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
1168
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1169
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1170
- if (r3) {
1171
- throw takeObject(r2);
1172
- }
1173
- return BigInt.asUintN(64, r0);
1174
- } finally {
1175
- wasm.__wbindgen_add_to_stack_pointer(16);
1176
- }
1177
- }
1178
-
1179
- export function decreaseLimitOrderQuote(fusion_pool, limit_order, tick, amount, transfer_fee_a, transfer_fee_b) {
1180
- try {
1181
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1182
- 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));
1183
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1184
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1185
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1186
- if (r2) {
1187
- throw takeObject(r1);
1188
- }
1189
- return takeObject(r0);
1190
- } finally {
1191
- wasm.__wbindgen_add_to_stack_pointer(16);
1192
- }
1410
+ export function tickIndexToPrice(tick_index, decimals_a, decimals_b) {
1411
+ const ret = wasm.tickIndexToPrice(tick_index, decimals_a, decimals_b);
1412
+ return ret;
1193
1413
  }
1194
1414
 
1195
- export function _POSITION_BUNDLE_SIZE() {
1196
- const ret = wasm._POSITION_BUNDLE_SIZE();
1197
- return ret >>> 0;
1415
+ /**
1416
+ * Convert a price into a tick index
1417
+ * IMPORTANT: floating point operations can reduce the precision of the result.
1418
+ * Make sure to do these operations last and not to use the result for further calculations.
1419
+ *
1420
+ * # Parameters
1421
+ * * `price` - The price to convert
1422
+ * * `decimals_a` - The number of decimals of the base token
1423
+ * * `decimals_b` - The number of decimals of the quote token
1424
+ *
1425
+ * # Returns
1426
+ * * `i32` - The tick index
1427
+ */
1428
+ export function priceToTickIndex(price, decimals_a, decimals_b) {
1429
+ const ret = wasm.priceToTickIndex(price, decimals_a, decimals_b);
1430
+ return ret;
1198
1431
  }
1199
1432
 
1200
1433
  export function _TICK_ARRAY_NOT_EVENLY_SPACED() {
@@ -1401,198 +1634,6 @@ export function _LIMIT_ORDER_AND_POOL_ARE_OUT_OF_SYNC() {
1401
1634
  }
1402
1635
  }
1403
1636
 
1404
- /**
1405
- * Get the first unoccupied position in a bundle
1406
- *
1407
- * # Arguments
1408
- * * `bundle` - The bundle to check
1409
- *
1410
- * # Returns
1411
- * * `u32` - The first unoccupied position (None if full)
1412
- */
1413
- export function firstUnoccupiedPositionInBundle(bitmap) {
1414
- const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
1415
- const len0 = WASM_VECTOR_LEN;
1416
- const ret = wasm.firstUnoccupiedPositionInBundle(ptr0, len0);
1417
- return ret === 0x100000001 ? undefined : ret;
1418
- }
1419
-
1420
- /**
1421
- * Check whether a position bundle is full
1422
- * A position bundle can contain 256 positions
1423
- *
1424
- * # Arguments
1425
- * * `bundle` - The bundle to check
1426
- *
1427
- * # Returns
1428
- * * `bool` - Whether the bundle is full
1429
- */
1430
- export function isPositionBundleFull(bitmap) {
1431
- const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
1432
- const len0 = WASM_VECTOR_LEN;
1433
- const ret = wasm.isPositionBundleFull(ptr0, len0);
1434
- return ret !== 0;
1435
- }
1436
-
1437
- /**
1438
- * Check whether a position bundle is empty
1439
- *
1440
- * # Arguments
1441
- * * `bundle` - The bundle to check
1442
- *
1443
- * # Returns
1444
- * * `bool` - Whether the bundle is empty
1445
- */
1446
- export function isPositionBundleEmpty(bitmap) {
1447
- const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
1448
- const len0 = WASM_VECTOR_LEN;
1449
- const ret = wasm.isPositionBundleEmpty(ptr0, len0);
1450
- return ret !== 0;
1451
- }
1452
-
1453
- /**
1454
- * Check if a position is in range.
1455
- * When a position is in range it is earning fees and rewards
1456
- *
1457
- * # Parameters
1458
- * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
1459
- * - `tick_index_1` - A i32 integer representing the first tick index of the position
1460
- * - `tick_index_2` - A i32 integer representing the second tick index of the position
1461
- *
1462
- * # Returns
1463
- * - A boolean value indicating if the position is in range
1464
- */
1465
- export function isPositionInRange(current_sqrt_price, tick_index_1, tick_index_2) {
1466
- const ret = wasm.isPositionInRange(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
1467
- return ret !== 0;
1468
- }
1469
-
1470
- /**
1471
- * Calculate the status of a position
1472
- * The status can be one of three values:
1473
- * - InRange: The position is in range
1474
- * - BelowRange: The position is below the range
1475
- * - AboveRange: The position is above the range
1476
- *
1477
- * # Parameters
1478
- * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
1479
- * - `tick_index_1` - A i32 integer representing the first tick index of the position
1480
- * - `tick_index_2` - A i32 integer representing the second tick index of the position
1481
- *
1482
- * # Returns
1483
- * - A PositionStatus enum value indicating the status of the position
1484
- */
1485
- export function positionStatus(current_sqrt_price, tick_index_1, tick_index_2) {
1486
- const ret = wasm.positionStatus(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
1487
- return takeObject(ret);
1488
- }
1489
-
1490
- /**
1491
- * Calculate the token_a / token_b ratio of a (ficticious) position
1492
- *
1493
- * # Parameters
1494
- * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
1495
- * - `tick_index_1` - A i32 integer representing the first tick index of the position
1496
- * - `tick_index_2` - A i32 integer representing the second tick index of the position
1497
- *
1498
- * # Returns
1499
- * - A PositionRatio struct containing the ratio of token_a and token_b
1500
- */
1501
- export function positionRatioX64(current_sqrt_price, tick_index_1, tick_index_2) {
1502
- const ret = wasm.positionRatioX64(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
1503
- return takeObject(ret);
1504
- }
1505
-
1506
- /**
1507
- * Convert a price into a sqrt priceX64
1508
- * IMPORTANT: floating point operations can reduce the precision of the result.
1509
- * Make sure to do these operations last and not to use the result for further calculations.
1510
- *
1511
- * # Parameters
1512
- * * `price` - The price to convert
1513
- * * `decimals_a` - The number of decimals of the base token
1514
- * * `decimals_b` - The number of decimals of the quote token
1515
- *
1516
- * # Returns
1517
- * * `u128` - The sqrt priceX64
1518
- */
1519
- export function priceToSqrtPrice(price, decimals_a, decimals_b) {
1520
- const ret = wasm.priceToSqrtPrice(price, decimals_a, decimals_b);
1521
- return takeObject(ret);
1522
- }
1523
-
1524
- /**
1525
- * Convert a sqrt priceX64 into a tick index
1526
- * IMPORTANT: floating point operations can reduce the precision of the result.
1527
- * Make sure to do these operations last and not to use the result for further calculations.
1528
- *
1529
- * # Parameters
1530
- * * `sqrt_price` - The sqrt priceX64 to convert
1531
- * * `decimals_a` - The number of decimals of the base token
1532
- * * `decimals_b` - The number of decimals of the quote token
1533
- *
1534
- * # Returns
1535
- * * `f64` - The decimal price
1536
- */
1537
- export function sqrtPriceToPrice(sqrt_price, decimals_a, decimals_b) {
1538
- const ret = wasm.sqrtPriceToPrice(addHeapObject(sqrt_price), decimals_a, decimals_b);
1539
- return ret;
1540
- }
1541
-
1542
- /**
1543
- * Invert a price
1544
- * IMPORTANT: floating point operations can reduce the precision of the result.
1545
- * Make sure to do these operations last and not to use the result for further calculations.
1546
- *
1547
- * # Parameters
1548
- * * `price` - The price to invert
1549
- * * `decimals_a` - The number of decimals of the base token
1550
- * * `decimals_b` - The number of decimals of the quote token
1551
- *
1552
- * # Returns
1553
- * * `f64` - The inverted price
1554
- */
1555
- export function invertPrice(price, decimals_a, decimals_b) {
1556
- const ret = wasm.invertPrice(price, decimals_a, decimals_b);
1557
- return ret;
1558
- }
1559
-
1560
- /**
1561
- * Convert a tick index into a price
1562
- * IMPORTANT: floating point operations can reduce the precision of the result.
1563
- * Make sure to do these operations last and not to use the result for further calculations.
1564
- *
1565
- * # Parameters
1566
- * * `tick_index` - The tick index to convert
1567
- * * `decimals_a` - The number of decimals of the base token
1568
- * * `decimals_b` - The number of decimals of the quote token
1569
- *
1570
- * # Returns
1571
- * * `f64` - The decimal price
1572
- */
1573
- export function tickIndexToPrice(tick_index, decimals_a, decimals_b) {
1574
- const ret = wasm.tickIndexToPrice(tick_index, decimals_a, decimals_b);
1575
- return ret;
1576
- }
1577
-
1578
- /**
1579
- * Convert a price into a tick index
1580
- * IMPORTANT: floating point operations can reduce the precision of the result.
1581
- * Make sure to do these operations last and not to use the result for further calculations.
1582
- *
1583
- * # Parameters
1584
- * * `price` - The price to convert
1585
- * * `decimals_a` - The number of decimals of the base token
1586
- * * `decimals_b` - The number of decimals of the quote token
1587
- *
1588
- * # Returns
1589
- * * `i32` - The tick index
1590
- */
1591
- export function priceToTickIndex(price, decimals_a, decimals_b) {
1592
- const ret = wasm.priceToTickIndex(price, decimals_a, decimals_b);
1593
- return ret;
1594
- }
1595
-
1596
1637
  /**
1597
1638
  * Computes the exact input or output amount for a swap transaction.
1598
1639
  *
@@ -1674,7 +1715,7 @@ export function swapQuoteByOutputToken(token_out, specified_token_a, slippage_to
1674
1715
  export function getLpPositionLiquidationPrices(tick_lower_index, tick_upper_index, liquidity, leftovers_a, leftovers_b, debt_a, debt_b, liquidation_threshold) {
1675
1716
  try {
1676
1717
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1677
- wasm.getLpPositionLiquidationPrices(retptr, tick_lower_index, tick_upper_index, addHeapObject(liquidity), leftovers_a, leftovers_b, debt_a, debt_b, liquidation_threshold);
1718
+ wasm.getLpPositionLiquidationPrices(retptr, tick_lower_index, tick_upper_index, liquidity, liquidity >> BigInt(64), leftovers_a, leftovers_b, debt_a, debt_b, liquidation_threshold);
1678
1719
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1679
1720
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1680
1721
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -1772,9 +1813,9 @@ export function getDecreaseSpotPositionQuote(decrease_amount, collateral_token,
1772
1813
  *
1773
1814
  * # Parameters
1774
1815
  * - `position_token`: Token of the position
1775
- * - `amount`: Position total size (decimal)
1776
- * - `debt`: Position total debt (decimal)
1777
- * - `liquidation_threshold`: Liquidation threshold of the market (decimal)
1816
+ * - `amount`: Position total size
1817
+ * - `debt`: Position total debt
1818
+ * - `liquidation_threshold`: Liquidation threshold of a market
1778
1819
  *
1779
1820
  * # Returns
1780
1821
  * - `f64`: Decimal liquidation price
@@ -1881,12 +1922,12 @@ export function solana_program_init() {
1881
1922
  wasm.solana_program_init();
1882
1923
  }
1883
1924
 
1884
- function __wasm_bindgen_func_elem_2635(arg0, arg1, arg2) {
1885
- wasm.__wasm_bindgen_func_elem_2635(arg0, arg1, addHeapObject(arg2));
1925
+ function __wasm_bindgen_func_elem_2634(arg0, arg1, arg2) {
1926
+ wasm.__wasm_bindgen_func_elem_2634(arg0, arg1, addHeapObject(arg2));
1886
1927
  }
1887
1928
 
1888
- function __wasm_bindgen_func_elem_3208(arg0, arg1) {
1889
- wasm.__wasm_bindgen_func_elem_3208(arg0, arg1);
1929
+ function __wasm_bindgen_func_elem_3207(arg0, arg1) {
1930
+ wasm.__wasm_bindgen_func_elem_3207(arg0, arg1);
1890
1931
  }
1891
1932
 
1892
1933
  function __wasm_bindgen_func_elem_495(arg0, arg1, arg2, arg3) {
@@ -3299,7 +3340,7 @@ export function __wbg_warn_1d74dddbe2fd1dbb(arg0) {
3299
3340
 
3300
3341
  export function __wbindgen_cast_0660a350899916ec(arg0, arg1) {
3301
3342
  // Cast intrinsic for `Closure(Closure { dtor_idx: 360, function: Function { arguments: [], shim_idx: 361, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
3302
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_3204, __wasm_bindgen_func_elem_3208);
3343
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_3203, __wasm_bindgen_func_elem_3207);
3303
3344
  return addHeapObject(ret);
3304
3345
  };
3305
3346
 
@@ -3311,7 +3352,7 @@ export function __wbindgen_cast_2241b6af4c4b2941(arg0, arg1) {
3311
3352
 
3312
3353
  export function __wbindgen_cast_2e5f7f1574aa20c6(arg0, arg1) {
3313
3354
  // Cast intrinsic for `Closure(Closure { dtor_idx: 232, function: Function { arguments: [Externref], shim_idx: 227, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
3314
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_2654, __wasm_bindgen_func_elem_2635);
3355
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_2653, __wasm_bindgen_func_elem_2634);
3315
3356
  return addHeapObject(ret);
3316
3357
  };
3317
3358