@meteora-ag/cp-amm-sdk 1.0.1-rc.12 → 1.0.1-rc.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -22,12 +22,8 @@ var __async = (__this, __arguments, generator) => {
22
22
 
23
23
  // src/CpAmm.ts
24
24
  import { Program } from "@coral-xyz/anchor";
25
- import {
26
- NATIVE_MINT as NATIVE_MINT2,
27
- TOKEN_2022_PROGRAM_ID as TOKEN_2022_PROGRAM_ID2
28
- } from "@solana/spl-token";
25
+ import { NATIVE_MINT as NATIVE_MINT2, TOKEN_2022_PROGRAM_ID as TOKEN_2022_PROGRAM_ID2 } from "@solana/spl-token";
29
26
  import invariant from "invariant";
30
- import Decimal3 from "decimal.js";
31
27
 
32
28
  // src/idl/cp_amm.json
33
29
  var cp_amm_default = {
@@ -6189,6 +6185,7 @@ var SCALE_OFFSET = 64;
6189
6185
  var BASIS_POINT_MAX = 1e4;
6190
6186
  var MAX_FEE_NUMERATOR = 5e8;
6191
6187
  var FEE_DENOMINATOR = 1e9;
6188
+ var PRECISION = 1e6;
6192
6189
  var MIN_SQRT_PRICE = new BN("4295048016");
6193
6190
  var MAX_SQRT_PRICE = new BN("79226673521066979257578248091");
6194
6191
  var MIN_CU_BUFFER = 5e4;
@@ -6288,71 +6285,7 @@ function deriveEventAuthority(programId) {
6288
6285
  );
6289
6286
  }
6290
6287
 
6291
- // src/math/index.ts
6292
- import { BN as BN2 } from "@coral-xyz/anchor";
6293
- import Decimal from "decimal.js";
6294
-
6295
- // src/types.ts
6296
- var Rounding = /* @__PURE__ */ ((Rounding2) => {
6297
- Rounding2[Rounding2["Up"] = 0] = "Up";
6298
- Rounding2[Rounding2["Down"] = 1] = "Down";
6299
- return Rounding2;
6300
- })(Rounding || {});
6301
- var ActivationPoint = /* @__PURE__ */ ((ActivationPoint2) => {
6302
- ActivationPoint2[ActivationPoint2["Timestamp"] = 0] = "Timestamp";
6303
- ActivationPoint2[ActivationPoint2["Slot"] = 1] = "Slot";
6304
- return ActivationPoint2;
6305
- })(ActivationPoint || {});
6306
- var FeeSchedulerMode = /* @__PURE__ */ ((FeeSchedulerMode2) => {
6307
- FeeSchedulerMode2[FeeSchedulerMode2["Linear"] = 0] = "Linear";
6308
- FeeSchedulerMode2[FeeSchedulerMode2["Exponential"] = 1] = "Exponential";
6309
- return FeeSchedulerMode2;
6310
- })(FeeSchedulerMode || {});
6311
- var CollectFeeMode = /* @__PURE__ */ ((CollectFeeMode2) => {
6312
- CollectFeeMode2[CollectFeeMode2["BothToken"] = 0] = "BothToken";
6313
- CollectFeeMode2[CollectFeeMode2["OnlyB"] = 1] = "OnlyB";
6314
- return CollectFeeMode2;
6315
- })(CollectFeeMode || {});
6316
- var TradeDirection = /* @__PURE__ */ ((TradeDirection2) => {
6317
- TradeDirection2[TradeDirection2["AtoB"] = 0] = "AtoB";
6318
- TradeDirection2[TradeDirection2["BtoA"] = 1] = "BtoA";
6319
- return TradeDirection2;
6320
- })(TradeDirection || {});
6321
- var ActivationType = /* @__PURE__ */ ((ActivationType2) => {
6322
- ActivationType2[ActivationType2["Slot"] = 0] = "Slot";
6323
- ActivationType2[ActivationType2["Timestamp"] = 1] = "Timestamp";
6324
- return ActivationType2;
6325
- })(ActivationType || {});
6326
-
6327
- // src/math/index.ts
6328
- function shlDiv(x, y, offset, rounding) {
6329
- const scale = new BN2(1).shln(offset);
6330
- return mulDiv(x, scale, y, rounding);
6331
- }
6332
- function mulDiv(x, y, denominator, rounding) {
6333
- const { div, mod } = x.mul(y).divmod(denominator);
6334
- if (rounding == 0 /* Up */ && !mod.isZero()) {
6335
- return div.add(new BN2(1));
6336
- }
6337
- return div;
6338
- }
6339
- function divCeil(a, b) {
6340
- if (a.isZero()) {
6341
- return new BN2(0);
6342
- }
6343
- return a.add(b.sub(new BN2(1))).div(b);
6344
- }
6345
- function decimalToQ64(num) {
6346
- return new BN2(num.mul(Decimal.pow(2, 64)).floor().toFixed());
6347
- }
6348
- function priceToSqrtPrice(initPrice, tokenADecimal, tokenBDecimal) {
6349
- const sqrtPriceQ64 = decimalToQ64(
6350
- initPrice.mul(Decimal.pow(10, tokenBDecimal - tokenADecimal)).sqrt()
6351
- );
6352
- return sqrtPriceQ64;
6353
- }
6354
-
6355
- // src/utils/token.ts
6288
+ // src/helpers/token.ts
6356
6289
  import {
6357
6290
  createAssociatedTokenAccountIdempotentInstruction,
6358
6291
  createCloseAccountInstruction,
@@ -6451,14 +6384,46 @@ function getNftOwner(connection, nftMint) {
6451
6384
  });
6452
6385
  }
6453
6386
 
6454
- // src/utils/fee.ts
6455
- import { BN as BN4 } from "@coral-xyz/anchor";
6387
+ // src/helpers/fee.ts
6388
+ import { BN as BN5 } from "@coral-xyz/anchor";
6389
+
6390
+ // src/types.ts
6391
+ var Rounding = /* @__PURE__ */ ((Rounding2) => {
6392
+ Rounding2[Rounding2["Up"] = 0] = "Up";
6393
+ Rounding2[Rounding2["Down"] = 1] = "Down";
6394
+ return Rounding2;
6395
+ })(Rounding || {});
6396
+ var ActivationPoint = /* @__PURE__ */ ((ActivationPoint2) => {
6397
+ ActivationPoint2[ActivationPoint2["Timestamp"] = 0] = "Timestamp";
6398
+ ActivationPoint2[ActivationPoint2["Slot"] = 1] = "Slot";
6399
+ return ActivationPoint2;
6400
+ })(ActivationPoint || {});
6401
+ var FeeSchedulerMode = /* @__PURE__ */ ((FeeSchedulerMode2) => {
6402
+ FeeSchedulerMode2[FeeSchedulerMode2["Linear"] = 0] = "Linear";
6403
+ FeeSchedulerMode2[FeeSchedulerMode2["Exponential"] = 1] = "Exponential";
6404
+ return FeeSchedulerMode2;
6405
+ })(FeeSchedulerMode || {});
6406
+ var CollectFeeMode = /* @__PURE__ */ ((CollectFeeMode3) => {
6407
+ CollectFeeMode3[CollectFeeMode3["BothToken"] = 0] = "BothToken";
6408
+ CollectFeeMode3[CollectFeeMode3["OnlyB"] = 1] = "OnlyB";
6409
+ return CollectFeeMode3;
6410
+ })(CollectFeeMode || {});
6411
+ var TradeDirection = /* @__PURE__ */ ((TradeDirection3) => {
6412
+ TradeDirection3[TradeDirection3["AtoB"] = 0] = "AtoB";
6413
+ TradeDirection3[TradeDirection3["BtoA"] = 1] = "BtoA";
6414
+ return TradeDirection3;
6415
+ })(TradeDirection || {});
6416
+ var ActivationType = /* @__PURE__ */ ((ActivationType2) => {
6417
+ ActivationType2[ActivationType2["Slot"] = 0] = "Slot";
6418
+ ActivationType2[ActivationType2["Timestamp"] = 1] = "Timestamp";
6419
+ return ActivationType2;
6420
+ })(ActivationType || {});
6456
6421
 
6457
6422
  // src/math/feeMath.ts
6458
- import { BN as BN3 } from "@coral-xyz/anchor";
6459
- var MAX_EXPONENTIAL = new BN3(524288);
6460
- var ONE = new BN3(1).shln(SCALE_OFFSET);
6461
- var MAX = new BN3(2).pow(new BN3(128)).sub(new BN3(1));
6423
+ import { BN as BN2 } from "@coral-xyz/anchor";
6424
+ var MAX_EXPONENTIAL = new BN2(524288);
6425
+ var ONE = new BN2(1).shln(SCALE_OFFSET);
6426
+ var MAX = new BN2(2).pow(new BN2(128)).sub(new BN2(1));
6462
6427
  function pow(base, exp) {
6463
6428
  let invert = exp.isNeg();
6464
6429
  if (exp.isZero()) {
@@ -6466,7 +6431,7 @@ function pow(base, exp) {
6466
6431
  }
6467
6432
  exp = invert ? exp.abs() : exp;
6468
6433
  if (exp.gt(MAX_EXPONENTIAL)) {
6469
- return new BN3(0);
6434
+ return new BN2(0);
6470
6435
  }
6471
6436
  let squaredBase = base;
6472
6437
  let result = ONE;
@@ -6474,83 +6439,83 @@ function pow(base, exp) {
6474
6439
  squaredBase = MAX.div(squaredBase);
6475
6440
  invert = !invert;
6476
6441
  }
6477
- if (!exp.and(new BN3(1)).isZero()) {
6442
+ if (!exp.and(new BN2(1)).isZero()) {
6478
6443
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6479
6444
  }
6480
6445
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6481
- if (!exp.and(new BN3(2)).isZero()) {
6446
+ if (!exp.and(new BN2(2)).isZero()) {
6482
6447
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6483
6448
  }
6484
6449
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6485
- if (!exp.and(new BN3(4)).isZero()) {
6450
+ if (!exp.and(new BN2(4)).isZero()) {
6486
6451
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6487
6452
  }
6488
6453
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6489
- if (!exp.and(new BN3(8)).isZero()) {
6454
+ if (!exp.and(new BN2(8)).isZero()) {
6490
6455
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6491
6456
  }
6492
6457
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6493
- if (!exp.and(new BN3(16)).isZero()) {
6458
+ if (!exp.and(new BN2(16)).isZero()) {
6494
6459
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6495
6460
  }
6496
6461
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6497
- if (!exp.and(new BN3(32)).isZero()) {
6462
+ if (!exp.and(new BN2(32)).isZero()) {
6498
6463
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6499
6464
  }
6500
6465
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6501
- if (!exp.and(new BN3(64)).isZero()) {
6466
+ if (!exp.and(new BN2(64)).isZero()) {
6502
6467
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6503
6468
  }
6504
6469
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6505
- if (!exp.and(new BN3(128)).isZero()) {
6470
+ if (!exp.and(new BN2(128)).isZero()) {
6506
6471
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6507
6472
  }
6508
6473
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6509
- if (!exp.and(new BN3(256)).isZero()) {
6474
+ if (!exp.and(new BN2(256)).isZero()) {
6510
6475
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6511
6476
  }
6512
6477
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6513
- if (!exp.and(new BN3(512)).isZero()) {
6478
+ if (!exp.and(new BN2(512)).isZero()) {
6514
6479
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6515
6480
  }
6516
6481
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6517
- if (!exp.and(new BN3(1024)).isZero()) {
6482
+ if (!exp.and(new BN2(1024)).isZero()) {
6518
6483
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6519
6484
  }
6520
6485
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6521
- if (!exp.and(new BN3(2048)).isZero()) {
6486
+ if (!exp.and(new BN2(2048)).isZero()) {
6522
6487
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6523
6488
  }
6524
6489
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6525
- if (!exp.and(new BN3(4096)).isZero()) {
6490
+ if (!exp.and(new BN2(4096)).isZero()) {
6526
6491
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6527
6492
  }
6528
6493
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6529
- if (!exp.and(new BN3(8192)).isZero()) {
6494
+ if (!exp.and(new BN2(8192)).isZero()) {
6530
6495
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6531
6496
  }
6532
6497
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6533
- if (!exp.and(new BN3(16384)).isZero()) {
6498
+ if (!exp.and(new BN2(16384)).isZero()) {
6534
6499
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6535
6500
  }
6536
6501
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6537
- if (!exp.and(new BN3(32768)).isZero()) {
6502
+ if (!exp.and(new BN2(32768)).isZero()) {
6538
6503
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6539
6504
  }
6540
6505
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6541
- if (!exp.and(new BN3(65536)).isZero()) {
6506
+ if (!exp.and(new BN2(65536)).isZero()) {
6542
6507
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6543
6508
  }
6544
6509
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6545
- if (!exp.and(new BN3(131072)).isZero()) {
6510
+ if (!exp.and(new BN2(131072)).isZero()) {
6546
6511
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6547
6512
  }
6548
6513
  squaredBase = squaredBase.mul(squaredBase).shrn(SCALE_OFFSET);
6549
- if (!exp.and(new BN3(262144)).isZero()) {
6514
+ if (!exp.and(new BN2(262144)).isZero()) {
6550
6515
  result = result.mul(squaredBase).shrn(SCALE_OFFSET);
6551
6516
  }
6552
6517
  if (result.isZero()) {
6553
- return new BN3(0);
6518
+ return new BN2(0);
6554
6519
  }
6555
6520
  if (invert) {
6556
6521
  result = MAX.div(result);
@@ -6558,52 +6523,34 @@ function pow(base, exp) {
6558
6523
  return result;
6559
6524
  }
6560
6525
 
6561
- // src/utils/fee.ts
6562
- function getBaseFeeNumerator(feeSchedulerMode, cliffFeeNumerator, period, reductionFactor) {
6563
- let feeNumerator;
6564
- if (feeSchedulerMode == 0 /* Linear */) {
6565
- feeNumerator = cliffFeeNumerator.sub(period.mul(reductionFactor));
6566
- } else {
6567
- const bps = reductionFactor.shln(SCALE_OFFSET).div(new BN4(BASIS_POINT_MAX));
6568
- const base = ONE.sub(bps);
6569
- const result = pow(base, period);
6570
- feeNumerator = cliffFeeNumerator.mul(result).shrn(SCALE_OFFSET);
6571
- }
6572
- return feeNumerator;
6573
- }
6574
- function getDynamicFeeNumerator(volatilityAccumulator, binStep, variableFeeControl) {
6575
- const squareVfaBin = volatilityAccumulator.mul(binStep).pow(new BN4(2));
6576
- const vFee = squareVfaBin.mul(variableFeeControl);
6577
- return vFee.addn(99999999999).divn(1e11);
6526
+ // src/math/index.ts
6527
+ import { BN as BN3 } from "@coral-xyz/anchor";
6528
+ import Decimal from "decimal.js";
6529
+ function shlDiv(x, y, offset, rounding) {
6530
+ const scale = new BN3(1).shln(offset);
6531
+ return mulDiv(x, scale, y, rounding);
6578
6532
  }
6579
- function getFeeNumerator(currentPoint, activationPoint, numberOfPeriod, periodFrequency, feeSchedulerMode, cliffFeeNumerator, reductionFactor, dynamicFeeParams) {
6580
- if (Number(periodFrequency) == 0) {
6581
- return cliffFeeNumerator;
6533
+ function mulDiv(x, y, denominator, rounding) {
6534
+ const { div, mod } = x.mul(y).divmod(denominator);
6535
+ if (rounding == 0 /* Up */ && !mod.isZero()) {
6536
+ return div.add(new BN3(1));
6582
6537
  }
6583
- const period = new BN4(currentPoint).lt(activationPoint) ? new BN4(numberOfPeriod) : BN4.min(
6584
- new BN4(numberOfPeriod),
6585
- new BN4(currentPoint).sub(activationPoint).div(periodFrequency)
6586
- );
6587
- let feeNumerator = getBaseFeeNumerator(
6588
- feeSchedulerMode,
6589
- cliffFeeNumerator,
6590
- period,
6591
- reductionFactor
6592
- );
6593
- if (dynamicFeeParams) {
6594
- const { volatilityAccumulator, binStep, variableFeeControl } = dynamicFeeParams;
6595
- const dynamicFeeNumberator = getDynamicFeeNumerator(
6596
- volatilityAccumulator,
6597
- binStep,
6598
- variableFeeControl
6599
- );
6600
- feeNumerator.add(dynamicFeeNumberator);
6538
+ return div;
6539
+ }
6540
+ function divCeil(a, b) {
6541
+ if (a.isZero()) {
6542
+ return new BN3(0);
6601
6543
  }
6602
- return feeNumerator.gt(new BN4(MAX_FEE_NUMERATOR)) ? new BN4(MAX_FEE_NUMERATOR) : feeNumerator;
6544
+ return a.add(b.sub(new BN3(1))).div(b);
6545
+ }
6546
+ function getInitPriceQ64(tokenAAmount, tokenBAmount) {
6547
+ const sqrtInitPrice = new Decimal(tokenBAmount.toString()).div(new Decimal(tokenAAmount.toString())).sqrt();
6548
+ return new BN3(sqrtInitPrice.mul(Decimal.pow(2, 64)).floor().toFixed());
6603
6549
  }
6604
6550
 
6605
- // src/utils/curve.ts
6606
- import { BN as BN5 } from "@coral-xyz/anchor";
6551
+ // src/helpers/curve.ts
6552
+ import { BN as BN4 } from "@coral-xyz/anchor";
6553
+ import Decimal2 from "decimal.js";
6607
6554
  function getNextSqrtPrice(amount, sqrtPrice, liquidity, aToB) {
6608
6555
  let result;
6609
6556
  if (aToB) {
@@ -6628,122 +6575,128 @@ function getDeltaAmountB(lowerSqrtPrice, upperSqrtPrice, liquidity, rounding) {
6628
6575
  const prod = liquidity.mul(deltaSqrtPrice);
6629
6576
  let result;
6630
6577
  if (rounding == 0 /* Up */) {
6631
- const denominator = new BN5(1).shln(SCALE_OFFSET * 2);
6578
+ const denominator = new BN4(1).shln(SCALE_OFFSET * 2);
6632
6579
  result = divCeil(prod, denominator);
6633
6580
  } else {
6634
6581
  result = prod.shrn(SCALE_OFFSET * 2);
6635
6582
  }
6636
6583
  return result;
6637
6584
  }
6638
- function calculateSwap(inAmount, sqrtPrice, liquidity, tradeFeeNumerator, aToB, collectFeeMode) {
6639
- let outAmount;
6640
- let lpFee;
6641
- if (collectFeeMode === 0 /* BothToken */) {
6642
- if (aToB) {
6643
- const nextSqrtPrice = getNextSqrtPrice(
6644
- inAmount,
6645
- sqrtPrice,
6646
- liquidity,
6647
- true
6648
- );
6649
- outAmount = getDeltaAmountB(
6650
- nextSqrtPrice,
6651
- sqrtPrice,
6652
- liquidity,
6653
- 1 /* Down */
6654
- );
6655
- lpFee = mulDiv(
6656
- outAmount,
6657
- tradeFeeNumerator,
6658
- new BN5(FEE_DENOMINATOR),
6659
- 1 /* Down */
6660
- );
6661
- } else {
6662
- const nextSqrtPrice = getNextSqrtPrice(
6663
- inAmount,
6664
- sqrtPrice,
6665
- liquidity,
6666
- false
6667
- );
6668
- outAmount = getDeltaAmountA(
6669
- sqrtPrice,
6670
- nextSqrtPrice,
6671
- liquidity,
6672
- 1 /* Down */
6673
- );
6674
- lpFee = mulDiv(
6675
- outAmount,
6676
- tradeFeeNumerator,
6677
- new BN5(new BN5(FEE_DENOMINATOR)),
6678
- 1 /* Down */
6679
- );
6680
- }
6681
- } else {
6682
- const nextSqrtPrice = getNextSqrtPrice(
6683
- inAmount,
6684
- sqrtPrice,
6685
- liquidity,
6686
- true
6687
- );
6688
- outAmount = getDeltaAmountB(
6689
- nextSqrtPrice,
6690
- sqrtPrice,
6691
- liquidity,
6692
- 1 /* Down */
6693
- );
6694
- lpFee = mulDiv(
6695
- outAmount,
6696
- tradeFeeNumerator,
6697
- new BN5(FEE_DENOMINATOR),
6698
- 1 /* Down */
6699
- );
6700
- if (aToB) {
6701
- } else {
6702
- lpFee = mulDiv(
6703
- inAmount,
6704
- tradeFeeNumerator,
6705
- new BN5(FEE_DENOMINATOR),
6706
- 1 /* Down */
6707
- );
6708
- const nextSqrtPrice2 = getNextSqrtPrice(
6709
- inAmount.sub(lpFee),
6710
- sqrtPrice,
6711
- liquidity,
6712
- false
6713
- );
6714
- outAmount = getDeltaAmountA(
6715
- sqrtPrice,
6716
- nextSqrtPrice2,
6717
- liquidity,
6718
- 1 /* Down */
6719
- );
6720
- }
6721
- }
6722
- return { amountOutExcludedlpFee: outAmount.sub(lpFee), lpFee };
6723
- }
6724
6585
  function getLiquidityDeltaFromAmountA(maxAmountA, lowerSqrtPrice, upperSqrtPrice) {
6725
- const prod = maxAmountA.mul(upperSqrtPrice.mul(lowerSqrtPrice));
6726
- const delta = upperSqrtPrice.sub(lowerSqrtPrice);
6727
- return prod.div(delta);
6586
+ const prod = new Decimal2(
6587
+ maxAmountA.mul(upperSqrtPrice.mul(lowerSqrtPrice)).toString()
6588
+ );
6589
+ const delta = new Decimal2(upperSqrtPrice.sub(lowerSqrtPrice).toString());
6590
+ return new BN4(prod.div(delta).floor().toFixed());
6728
6591
  }
6729
6592
  function getLiquidityDeltaFromAmountB(maxAmountB, lowerSqrtPrice, upperSqrtPrice) {
6730
- const denominator = upperSqrtPrice.sub(lowerSqrtPrice);
6731
- const result = maxAmountB.shln(SCALE_OFFSET * 2).div(denominator);
6732
- return result;
6593
+ const denominator = new Decimal2(
6594
+ upperSqrtPrice.sub(lowerSqrtPrice).toString()
6595
+ );
6596
+ const prod = new Decimal2(maxAmountB.toString()).mul(
6597
+ Decimal2.pow(2, SCALE_OFFSET * 2)
6598
+ );
6599
+ return new BN4(prod.div(denominator).floor().toFixed());
6733
6600
  }
6734
6601
  function getAmountAFromLiquidityDelta(liquidity, currentSqrtPrice) {
6735
- const prod = liquidity.mul(MAX_SQRT_PRICE.sub(currentSqrtPrice));
6602
+ const prod = new Decimal2(liquidity.toString()).mul(
6603
+ new Decimal2(MAX_SQRT_PRICE.sub(currentSqrtPrice).toString())
6604
+ );
6736
6605
  const denominator = currentSqrtPrice.mul(MAX_SQRT_PRICE);
6737
- const result = shlDiv(prod, denominator, SCALE_OFFSET, 1 /* Down */);
6738
- return result.shrn(SCALE_OFFSET);
6606
+ const result = prod.mul(Decimal2.pow(2, 64)).div(new Decimal2(denominator.toString()));
6607
+ return result.div(Decimal2.pow(2, 64)).floor().toFixed();
6739
6608
  }
6740
6609
  function getAmountBFromLiquidityDelta(liquidity, currentSqrtPrice) {
6741
6610
  const delta = currentSqrtPrice.sub(MIN_SQRT_PRICE);
6742
- const prod = liquidity.mul(delta);
6743
- return prod.shrn(SCALE_OFFSET * 2);
6611
+ const prod = new Decimal2(liquidity.toString()).mul(
6612
+ new Decimal2(delta.toString())
6613
+ );
6614
+ return prod.div(Decimal2.pow(2, 128)).floor().toFixed();
6744
6615
  }
6745
6616
 
6746
- // src/utils/computeUnits.ts
6617
+ // src/helpers/fee.ts
6618
+ function getBaseFeeNumerator(feeSchedulerMode, cliffFeeNumerator, period, reductionFactor) {
6619
+ let feeNumerator;
6620
+ if (feeSchedulerMode == 0 /* Linear */) {
6621
+ feeNumerator = cliffFeeNumerator.sub(period.mul(reductionFactor));
6622
+ } else {
6623
+ const bps = reductionFactor.shln(SCALE_OFFSET).div(new BN5(BASIS_POINT_MAX));
6624
+ const base = ONE.sub(bps);
6625
+ const result = pow(base, period);
6626
+ feeNumerator = cliffFeeNumerator.mul(result).shrn(SCALE_OFFSET);
6627
+ }
6628
+ return feeNumerator;
6629
+ }
6630
+ function getDynamicFeeNumerator(volatilityAccumulator, binStep, variableFeeControl) {
6631
+ const squareVfaBin = volatilityAccumulator.mul(binStep).pow(new BN5(2));
6632
+ const vFee = squareVfaBin.mul(variableFeeControl);
6633
+ return vFee.addn(99999999999).divn(1e11);
6634
+ }
6635
+ function getFeeNumerator(currentPoint, activationPoint, numberOfPeriod, periodFrequency, feeSchedulerMode, cliffFeeNumerator, reductionFactor, dynamicFeeParams) {
6636
+ if (Number(periodFrequency) == 0) {
6637
+ return cliffFeeNumerator;
6638
+ }
6639
+ const period = new BN5(currentPoint).lt(activationPoint) ? new BN5(numberOfPeriod) : BN5.min(
6640
+ new BN5(numberOfPeriod),
6641
+ new BN5(currentPoint).sub(activationPoint).div(periodFrequency)
6642
+ );
6643
+ let feeNumerator = getBaseFeeNumerator(
6644
+ feeSchedulerMode,
6645
+ cliffFeeNumerator,
6646
+ period,
6647
+ reductionFactor
6648
+ );
6649
+ if (dynamicFeeParams) {
6650
+ const { volatilityAccumulator, binStep, variableFeeControl } = dynamicFeeParams;
6651
+ const dynamicFeeNumberator = getDynamicFeeNumerator(
6652
+ volatilityAccumulator,
6653
+ binStep,
6654
+ variableFeeControl
6655
+ );
6656
+ feeNumerator.add(dynamicFeeNumberator);
6657
+ }
6658
+ return feeNumerator.gt(new BN5(MAX_FEE_NUMERATOR)) ? new BN5(MAX_FEE_NUMERATOR) : feeNumerator;
6659
+ }
6660
+ function getFeeMode(collectFeeMode, btoA) {
6661
+ const feeOnInput = btoA && collectFeeMode === 1 /* OnlyB */;
6662
+ const feesOnTokenA = btoA && collectFeeMode === 0 /* BothToken */;
6663
+ return {
6664
+ feeOnInput,
6665
+ feesOnTokenA
6666
+ };
6667
+ }
6668
+ function getTotalFeeOnAmount(amount, tradeFeeNumerator) {
6669
+ return mulDiv(
6670
+ amount,
6671
+ tradeFeeNumerator,
6672
+ new BN5(FEE_DENOMINATOR),
6673
+ 0 /* Up */
6674
+ );
6675
+ }
6676
+ function getSwapAmount(inAmount, sqrtPrice, liquidity, tradeFeeNumerator, aToB, collectFeeMode) {
6677
+ let feeMode = getFeeMode(collectFeeMode, !aToB);
6678
+ let actualInAmount = inAmount;
6679
+ let totalFee = new BN5(0);
6680
+ if (feeMode.feeOnInput) {
6681
+ totalFee = getTotalFeeOnAmount(inAmount, tradeFeeNumerator);
6682
+ actualInAmount = inAmount.sub(totalFee);
6683
+ }
6684
+ const outAmount = aToB ? getDeltaAmountB(
6685
+ getNextSqrtPrice(actualInAmount, sqrtPrice, liquidity, true),
6686
+ sqrtPrice,
6687
+ liquidity,
6688
+ 1 /* Down */
6689
+ ) : getDeltaAmountA(
6690
+ sqrtPrice,
6691
+ getNextSqrtPrice(actualInAmount, sqrtPrice, liquidity, false),
6692
+ liquidity,
6693
+ 1 /* Down */
6694
+ );
6695
+ const actualOutAmount = feeMode.feeOnInput ? outAmount : (totalFee = getTotalFeeOnAmount(outAmount, tradeFeeNumerator), outAmount.sub(totalFee));
6696
+ return { actualOutAmount, totalFee };
6697
+ }
6698
+
6699
+ // src/helpers/computeUnits.ts
6747
6700
  import {
6748
6701
  ComputeBudgetProgram,
6749
6702
  PublicKey as PublicKey4,
@@ -6818,26 +6771,25 @@ var getEstimatedComputeUnitIxWithBuffer = (connection, instructions, feePayer, b
6818
6771
  return ComputeBudgetProgram.setComputeUnitLimit({ units });
6819
6772
  });
6820
6773
 
6821
- // src/utils/utils.ts
6774
+ // src/helpers/utils.ts
6822
6775
  import { BN as BN6 } from "@coral-xyz/anchor";
6823
- import Decimal2 from "decimal.js";
6824
- var getMaxAmountWithSlippage = (amount, slippageRate) => {
6825
- const slippage = (100 + slippageRate) / 100 * BASIS_POINT_MAX;
6776
+ import Decimal3 from "decimal.js";
6777
+ var getMaxAmountWithSlippage = (amount, rate) => {
6778
+ const slippage = (100 + rate) / 100 * BASIS_POINT_MAX;
6826
6779
  return amount.mul(new BN6(slippage)).div(new BN6(BASIS_POINT_MAX));
6827
6780
  };
6828
- var getMinAmountWithSlippage = (amount, slippageRate) => {
6829
- const slippage = (100 - slippageRate) / 100 * BASIS_POINT_MAX;
6781
+ var getMinAmountWithSlippage = (amount, rate) => {
6782
+ const slippage = (100 - rate) / 100 * BASIS_POINT_MAX;
6830
6783
  return amount.mul(new BN6(slippage)).div(new BN6(BASIS_POINT_MAX));
6831
6784
  };
6832
- var getPriceImpact = (amount, amountWithoutSlippage) => {
6833
- const diff = amountWithoutSlippage.sub(amount);
6834
- return new Decimal2(diff.toString()).div(new Decimal2(amountWithoutSlippage.toString())).mul(100).toNumber();
6785
+ var getPriceImpact = (actualAmount, idealAmount) => {
6786
+ const diff = idealAmount.sub(actualAmount);
6787
+ return new Decimal3(diff.toString()).div(new Decimal3(idealAmount.toString())).mul(100).toNumber();
6835
6788
  };
6836
6789
  var getCurrentPrice = (sqrtPrice, tokenADecimal, tokenBDecimal) => {
6837
- const rawSqrtPrice = sqrtPrice.shrn(SCALE_OFFSET);
6838
- const price = rawSqrtPrice.mul(rawSqrtPrice);
6839
- const expo = __pow(10, tokenADecimal - tokenBDecimal);
6840
- return price.muln(expo);
6790
+ const decimalSqrtPrice = new Decimal3(sqrtPrice.toString());
6791
+ const price = decimalSqrtPrice.mul(decimalSqrtPrice).mul(new Decimal3(__pow(10, tokenADecimal - tokenBDecimal))).div(Decimal3.pow(2, 128)).toString();
6792
+ return price;
6841
6793
  };
6842
6794
  var getUnClaimReward = (positionState) => {
6843
6795
  return {
@@ -6847,7 +6799,7 @@ var getUnClaimReward = (positionState) => {
6847
6799
  };
6848
6800
  };
6849
6801
 
6850
- // src/utils/accountFilters.ts
6802
+ // src/helpers/accountFilters.ts
6851
6803
  var positionByPoolFilter = (pool) => {
6852
6804
  return {
6853
6805
  memcmp: {
@@ -6864,28 +6816,23 @@ var CpAmm = class {
6864
6816
  connection
6865
6817
  });
6866
6818
  }
6819
+ /**
6820
+ * Returns the Anchor program instance.
6821
+ * @returns The AmmProgram instance.
6822
+ */
6867
6823
  getProgram() {
6868
6824
  return this._program;
6869
6825
  }
6870
6826
  /**
6871
- Prepares token ordering, calculates the initial sqrtPrice in Q64 format,
6872
- @private
6873
- @async
6874
- @param {PublicKey} tokenX - One token mint address in the pair.
6875
- @param {PublicKey} tokenY - The other token mint address in the pair.
6876
- @param {Decimal} initialPrice - The initial price ratio of tokenX/tokenY (will be inverted if needed).
6877
- @param {Decimal} liquidity - The initial liquidity value.
6878
- @returns {PreparedPoolCreation} Object containing the ordered token mints and their Q64 price/liquidity values.
6879
- */
6827
+ * Prepares parameters required for pool creation, including initial sqrt price and liquidity.
6828
+ * @private
6829
+ * @param {PreparePoolCreationParams} params - Initial token amounts for pool creation.
6830
+ * @returns init sqrt price and liquidity in Q64 format.
6831
+ */
6880
6832
  preparePoolCreationParams(params) {
6881
6833
  return __async(this, null, function* () {
6882
- const { tokenAAmount, tokenBAmount, tokenADecimal, tokenBDecimal } = params;
6883
- const initPrice = tokenBAmount.div(tokenAAmount);
6884
- const sqrtPriceQ64 = priceToSqrtPrice(
6885
- new Decimal3(initPrice.toString()),
6886
- tokenADecimal,
6887
- tokenBDecimal
6888
- );
6834
+ const { tokenAAmount, tokenBAmount } = params;
6835
+ const sqrtPriceQ64 = getInitPriceQ64(tokenAAmount, tokenBAmount);
6889
6836
  if (sqrtPriceQ64.lt(MIN_SQRT_PRICE) || sqrtPriceQ64.gt(MAX_SQRT_PRICE)) {
6890
6837
  throw new Error(`Invalid sqrt price: ${sqrtPriceQ64.toString()}`);
6891
6838
  }
@@ -6908,7 +6855,11 @@ var CpAmm = class {
6908
6855
  };
6909
6856
  });
6910
6857
  }
6911
- // fetcher
6858
+ /**
6859
+ * Fetches the Config state of the program.
6860
+ * @param config - Public key of the config account.
6861
+ * @returns Parsed ConfigState.
6862
+ */
6912
6863
  fetchConfigState(config) {
6913
6864
  return __async(this, null, function* () {
6914
6865
  const configState = yield this._program.account.config.fetchNullable(
@@ -6918,6 +6869,11 @@ var CpAmm = class {
6918
6869
  return configState;
6919
6870
  });
6920
6871
  }
6872
+ /**
6873
+ * Fetches the Pool state.
6874
+ * @param pool - Public key of the pool.
6875
+ * @returns Parsed PoolState.
6876
+ */
6921
6877
  fetchPoolState(pool) {
6922
6878
  return __async(this, null, function* () {
6923
6879
  const poolState = yield this._program.account.pool.fetchNullable(pool);
@@ -6925,6 +6881,11 @@ var CpAmm = class {
6925
6881
  return poolState;
6926
6882
  });
6927
6883
  }
6884
+ /**
6885
+ * Fetches the Position state.
6886
+ * @param position - Public key of the position.
6887
+ * @returns Parsed PositionState.
6888
+ */
6928
6889
  fetchPositionState(position) {
6929
6890
  return __async(this, null, function* () {
6930
6891
  const positionState = yield this._program.account.position.fetchNullable(
@@ -6934,24 +6895,42 @@ var CpAmm = class {
6934
6895
  return positionState;
6935
6896
  });
6936
6897
  }
6898
+ /**
6899
+ * Retrieves all config accounts.
6900
+ * @returns Array of config public keys and their states.
6901
+ */
6937
6902
  getAllConfigs() {
6938
6903
  return __async(this, null, function* () {
6939
6904
  const configAccounts = yield this._program.account.config.all();
6940
6905
  return configAccounts;
6941
6906
  });
6942
6907
  }
6908
+ /**
6909
+ * Retrieves all pool accounts.
6910
+ * @returns Array of pool public keys and their states.
6911
+ */
6943
6912
  getAllPools() {
6944
6913
  return __async(this, null, function* () {
6945
6914
  const poolAccounts = yield this._program.account.pool.all();
6946
6915
  return poolAccounts;
6947
6916
  });
6948
6917
  }
6918
+ /**
6919
+ * Retrieves all position accounts.
6920
+ * @returns Array of position public keys and their states.
6921
+ */
6949
6922
  getAllPositions() {
6950
6923
  return __async(this, null, function* () {
6951
6924
  const poolAccounts = yield this._program.account.position.all();
6952
6925
  return poolAccounts;
6953
6926
  });
6954
6927
  }
6928
+ /**
6929
+ * Gets all positions of a user for a specific pool.
6930
+ * @param pool - Public key of the pool.
6931
+ * @param user - Public key of the user.
6932
+ * @returns List of user positions for the pool.
6933
+ */
6955
6934
  getUserPositionByPool(pool, user) {
6956
6935
  return __async(this, null, function* () {
6957
6936
  const positions = yield this._program.account.position.all([
@@ -6970,6 +6949,11 @@ var CpAmm = class {
6970
6949
  return result;
6971
6950
  });
6972
6951
  }
6952
+ /**
6953
+ * Gets all positions of a user across all pools.
6954
+ * @param user - Public key of the user.
6955
+ * @returns Array of user positions.
6956
+ */
6973
6957
  getPositionsByUser(user) {
6974
6958
  return __async(this, null, function* () {
6975
6959
  const positions = yield this._program.account.position.all();
@@ -6986,6 +6970,11 @@ var CpAmm = class {
6986
6970
  return result;
6987
6971
  });
6988
6972
  }
6973
+ /**
6974
+ * Calculates swap quote based on input amount and pool state.
6975
+ * @param params - Swap parameters including input amount, pool state, slippage, etc.
6976
+ * @returns Swap quote including expected output amount, fee, and price impact.
6977
+ */
6989
6978
  getQuote(params) {
6990
6979
  return __async(this, null, function* () {
6991
6980
  var _a;
@@ -7028,7 +7017,7 @@ var CpAmm = class {
7028
7017
  reductionFactor,
7029
7018
  dynamicFeeParams
7030
7019
  );
7031
- const { amountOutExcludedlpFee, lpFee } = calculateSwap(
7020
+ const { actualOutAmount, totalFee } = getSwapAmount(
7032
7021
  inAmount,
7033
7022
  sqrtPriceQ64,
7034
7023
  liquidityQ64,
@@ -7037,28 +7026,22 @@ var CpAmm = class {
7037
7026
  collectFeeMode
7038
7027
  );
7039
7028
  const minSwapOutAmount = getMinAmountWithSlippage(
7040
- amountOutExcludedlpFee,
7029
+ actualOutAmount,
7041
7030
  slippage
7042
7031
  );
7043
7032
  return {
7044
7033
  swapInAmount: inAmount,
7045
- swapOutAmount: amountOutExcludedlpFee,
7034
+ swapOutAmount: actualOutAmount,
7046
7035
  minSwapOutAmount,
7047
- totalFee: lpFee,
7048
- priceImpact: getPriceImpact(minSwapOutAmount, amountOutExcludedlpFee)
7036
+ totalFee,
7037
+ priceImpact: getPriceImpact(minSwapOutAmount, actualOutAmount)
7049
7038
  };
7050
7039
  });
7051
7040
  }
7052
7041
  /**
7053
7042
  * Computes the liquidity delta based on the provided token amounts and pool state.
7054
7043
  *
7055
- * @param {LiquidityDeltaParams} params - The parameters for liquidity calculation, including:
7056
- * - tokenX: The mint address of token X.
7057
- * - tokenY: The mint address of token Y.
7058
- * - maxAmountX: The maximum amount of token X available.
7059
- * - maxAmountY: The maximum amount of token Y available.
7060
- * - pool: The address of the liquidity pool.
7061
- *
7044
+ * @param {LiquidityDeltaParams} params - The parameters for liquidity calculation
7062
7045
  * @returns {Promise<BN>} - The computed liquidity delta in Q64 value.
7063
7046
  */
7064
7047
  getLiquidityDelta(params) {
@@ -7083,6 +7066,11 @@ var CpAmm = class {
7083
7066
  return liquidityDeltaFromAmountA.gte(liquidityDeltaFromAmountB) ? liquidityDeltaFromAmountB : liquidityDeltaFromAmountA;
7084
7067
  });
7085
7068
  }
7069
+ /**
7070
+ * Builds a transaction to create a permissionless pool.
7071
+ * @param params - Parameters for pool creation.
7072
+ * @returns Transaction builder.
7073
+ */
7086
7074
  createPool(params) {
7087
7075
  return __async(this, null, function* () {
7088
7076
  const {
@@ -7095,17 +7083,13 @@ var CpAmm = class {
7095
7083
  activationPoint,
7096
7084
  tokenAAmount,
7097
7085
  tokenBAmount,
7098
- tokenADecimal,
7099
- tokenBDecimal,
7100
7086
  tokenAProgram,
7101
7087
  tokenBProgram
7102
7088
  } = params;
7103
7089
  const { sqrtPriceQ64, liquidityQ64 } = yield this.preparePoolCreationParams(
7104
7090
  {
7105
7091
  tokenAAmount,
7106
- tokenBAmount,
7107
- tokenADecimal,
7108
- tokenBDecimal
7092
+ tokenBAmount
7109
7093
  }
7110
7094
  );
7111
7095
  const poolAuthority = derivePoolAuthority(this._program.programId);
@@ -7202,6 +7186,11 @@ var CpAmm = class {
7202
7186
  return tx;
7203
7187
  });
7204
7188
  }
7189
+ /**
7190
+ * Builds a transaction to create a customizable pool.
7191
+ * @param params - Parameters for customizable pool creation.
7192
+ * @returns Transaction and related addresses.
7193
+ */
7205
7194
  createCustomPool(params) {
7206
7195
  return __async(this, null, function* () {
7207
7196
  const {
@@ -7225,9 +7214,7 @@ var CpAmm = class {
7225
7214
  const { sqrtPriceQ64, liquidityQ64 } = yield this.preparePoolCreationParams(
7226
7215
  {
7227
7216
  tokenAAmount,
7228
- tokenBAmount,
7229
- tokenADecimal,
7230
- tokenBDecimal
7217
+ tokenBAmount
7231
7218
  }
7232
7219
  );
7233
7220
  const poolAuthority = derivePoolAuthority(this._program.programId);
@@ -7328,6 +7315,11 @@ var CpAmm = class {
7328
7315
  return { tx: transaction, pool, position };
7329
7316
  });
7330
7317
  }
7318
+ /**
7319
+ * Builds a transaction to create a position.
7320
+ * @param {CreatePositionParams} params - Parameters for position creation.
7321
+ * @returns Transaction builder.
7322
+ */
7331
7323
  createPosition(params) {
7332
7324
  return __async(this, null, function* () {
7333
7325
  const { owner, payer, pool, positionNft } = params;
@@ -7355,6 +7347,11 @@ var CpAmm = class {
7355
7347
  }).transaction();
7356
7348
  });
7357
7349
  }
7350
+ /**
7351
+ * Builds a transaction to add liquidity to an existing position.
7352
+ * @param {AddLiquidityParams} params - Parameters for adding liquidity.
7353
+ * @returns Transaction builder.
7354
+ */
7358
7355
  addLiquidity(params) {
7359
7356
  return __async(this, null, function* () {
7360
7357
  const {
@@ -7447,6 +7444,11 @@ var CpAmm = class {
7447
7444
  }).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
7448
7445
  });
7449
7446
  }
7447
+ /**
7448
+ * Builds a transaction to remove liquidity from a position.
7449
+ * @param {RemoveLiquidityParams} params - Parameters for removing liquidity.
7450
+ * @returns Transaction builder.
7451
+ */
7450
7452
  removeLiquidity(params) {
7451
7453
  return __async(this, null, function* () {
7452
7454
  const {
@@ -7523,6 +7525,11 @@ var CpAmm = class {
7523
7525
  }).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
7524
7526
  });
7525
7527
  }
7528
+ /**
7529
+ * Builds a transaction to perform a swap in the pool.
7530
+ * @param {SwapParams} params - Parameters for swapping tokens.
7531
+ * @returns Transaction builder.
7532
+ */
7526
7533
  swap(params) {
7527
7534
  return __async(this, null, function* () {
7528
7535
  const {
@@ -7601,6 +7608,11 @@ var CpAmm = class {
7601
7608
  }).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
7602
7609
  });
7603
7610
  }
7611
+ /**
7612
+ * Builds a transaction to lock a position with vesting schedule.
7613
+ * @param {LockPositionParams} params - Locking parameters.
7614
+ * @returns Transaction builder.
7615
+ */
7604
7616
  lockPosition(params) {
7605
7617
  return __async(this, null, function* () {
7606
7618
  const {
@@ -7642,6 +7654,11 @@ var CpAmm = class {
7642
7654
  }).transaction();
7643
7655
  });
7644
7656
  }
7657
+ /**
7658
+ * Builds a transaction to permanently lock a position.
7659
+ * @param {PermanentLockParams} params - Parameters for permanent locking.
7660
+ * @returns Transaction builder.
7661
+ */
7645
7662
  permanentLockPosition(params) {
7646
7663
  return __async(this, null, function* () {
7647
7664
  const { owner, position, positionNftMint, pool, unlockedLiquidity } = params;
@@ -7659,6 +7676,11 @@ var CpAmm = class {
7659
7676
  }).transaction();
7660
7677
  });
7661
7678
  }
7679
+ /**
7680
+ * Builds a transaction to refresh vesting status of a position.
7681
+ * @param {RefreshVestingParams} params - Refresh vesting parameters.
7682
+ * @returns Transaction builder.
7683
+ */
7662
7684
  refreshVesting(params) {
7663
7685
  return __async(this, null, function* () {
7664
7686
  const { owner, position, positionNftMint, pool, vestings } = params;
@@ -7682,6 +7704,11 @@ var CpAmm = class {
7682
7704
  ).transaction();
7683
7705
  });
7684
7706
  }
7707
+ /**
7708
+ * Builds a transaction to claim position fee rewards.
7709
+ * @param {ClaimPositionFeeParams} params - Parameters for claiming position fee.
7710
+ * @returns Transaction builder.
7711
+ */
7685
7712
  claimPositionFee(params) {
7686
7713
  return __async(this, null, function* () {
7687
7714
  const {
@@ -7751,6 +7778,11 @@ var CpAmm = class {
7751
7778
  }).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
7752
7779
  });
7753
7780
  }
7781
+ /**
7782
+ * Builds a transaction to update reward duration.
7783
+ * @param {UpdateRewardDurationParams} params - Parameters including pool and new duration.
7784
+ * @returns Transaction builder.
7785
+ */
7754
7786
  updateRewardDuration(params) {
7755
7787
  return __async(this, null, function* () {
7756
7788
  const { pool, admin, rewardIndex, newDuration } = params;
@@ -7762,6 +7794,11 @@ var CpAmm = class {
7762
7794
  }).transaction();
7763
7795
  });
7764
7796
  }
7797
+ /**
7798
+ * Builds a transaction to update reward funder address.
7799
+ * @param {UpdateRewardFunderParams} params - Parameters including pool and new funder address.
7800
+ * @returns Transaction builder.
7801
+ */
7765
7802
  updateRewardFunder(params) {
7766
7803
  return __async(this, null, function* () {
7767
7804
  const { pool, admin, rewardIndex, newFunder } = params;
@@ -7773,6 +7810,11 @@ var CpAmm = class {
7773
7810
  }).transaction();
7774
7811
  });
7775
7812
  }
7813
+ /**
7814
+ * Builds a transaction to fund rewards in a pool.
7815
+ * @param {FundRewardParams} params - Funding parameters.
7816
+ * @returns Transaction builder.
7817
+ */
7776
7818
  fundReward(params) {
7777
7819
  return __async(this, null, function* () {
7778
7820
  const { rewardIndex, carryForward, pool, funder, amount } = params;
@@ -7810,6 +7852,11 @@ var CpAmm = class {
7810
7852
  }).transaction();
7811
7853
  });
7812
7854
  }
7855
+ /**
7856
+ * Builds a transaction to withdraw ineligible rewards from a pool.
7857
+ * @param {WithdrawIneligibleRewardParams} params - Parameters for withdrawal.
7858
+ * @returns Transaction builder.
7859
+ */
7813
7860
  withdrawIneligibleReward(params) {
7814
7861
  return __async(this, null, function* () {
7815
7862
  const { rewardIndex, pool, funder } = params;
@@ -7846,6 +7893,11 @@ var CpAmm = class {
7846
7893
  }).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
7847
7894
  });
7848
7895
  }
7896
+ /**
7897
+ * Builds a transaction to claim partner fee rewards.
7898
+ * @param {ClaimPartnerFeeParams} params - Claim parameters including amounts and partner address.
7899
+ * @returns Transaction builder.
7900
+ */
7849
7901
  claimPartnerFee(params) {
7850
7902
  return __async(this, null, function* () {
7851
7903
  const { partner, pool, maxAmountA, maxAmountB } = params;
@@ -7910,6 +7962,11 @@ var CpAmm = class {
7910
7962
  }).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
7911
7963
  });
7912
7964
  }
7965
+ /**
7966
+ * Builds a transaction to claim reward from a position.
7967
+ * @param {ClaimRewardParams} params - Parameters for claiming reward.
7968
+ * @returns Transaction builder.
7969
+ */
7913
7970
  claimReward(params) {
7914
7971
  return __async(this, null, function* () {
7915
7972
  const { user, position, rewardIndex } = params;
@@ -7970,10 +8027,10 @@ export {
7970
8027
  MAX_SQRT_PRICE,
7971
8028
  MIN_CU_BUFFER,
7972
8029
  MIN_SQRT_PRICE,
8030
+ PRECISION,
7973
8031
  Rounding,
7974
8032
  SCALE_OFFSET,
7975
8033
  TradeDirection,
7976
- calculateSwap,
7977
8034
  index_default as default,
7978
8035
  deriveClaimFeeOperatorAddress,
7979
8036
  deriveConfigAddress,
@@ -8007,9 +8064,11 @@ export {
8007
8064
  getPriceImpact,
8008
8065
  getSecondKey,
8009
8066
  getSimulationComputeUnits,
8067
+ getSwapAmount,
8010
8068
  getTokenDecimals,
8011
8069
  getTokenProgram,
8012
8070
  getUnClaimReward,
8071
+ positionByPoolFilter,
8013
8072
  unwrapSOLInstruction,
8014
8073
  wrapSOLInstruction
8015
8074
  };