@meteora-ag/cp-amm-sdk 1.0.1-rc.11 → 1.0.1-rc.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +191 -26
- package/dist/index.d.ts +191 -26
- package/dist/index.js +313 -243
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +341 -271
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __pow = Math.pow;
|
|
2
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
3
|
return new Promise((resolve, reject) => {
|
|
3
4
|
var fulfilled = (value) => {
|
|
4
5
|
try {
|
|
@@ -21,12 +22,8 @@
|
|
|
21
22
|
|
|
22
23
|
// src/CpAmm.ts
|
|
23
24
|
var _anchor = require('@coral-xyz/anchor');
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
25
|
var _spltoken = require('@solana/spl-token');
|
|
28
26
|
var _invariant = require('invariant'); var _invariant2 = _interopRequireDefault(_invariant);
|
|
29
|
-
var _decimaljs = require('decimal.js'); var _decimaljs2 = _interopRequireDefault(_decimaljs);
|
|
30
27
|
|
|
31
28
|
// src/idl/cp_amm.json
|
|
32
29
|
var cp_amm_default = {
|
|
@@ -6287,71 +6284,7 @@ function deriveEventAuthority(programId) {
|
|
|
6287
6284
|
);
|
|
6288
6285
|
}
|
|
6289
6286
|
|
|
6290
|
-
// src/
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6294
|
-
// src/types.ts
|
|
6295
|
-
var Rounding = /* @__PURE__ */ ((Rounding2) => {
|
|
6296
|
-
Rounding2[Rounding2["Up"] = 0] = "Up";
|
|
6297
|
-
Rounding2[Rounding2["Down"] = 1] = "Down";
|
|
6298
|
-
return Rounding2;
|
|
6299
|
-
})(Rounding || {});
|
|
6300
|
-
var ActivationPoint = /* @__PURE__ */ ((ActivationPoint2) => {
|
|
6301
|
-
ActivationPoint2[ActivationPoint2["Timestamp"] = 0] = "Timestamp";
|
|
6302
|
-
ActivationPoint2[ActivationPoint2["Slot"] = 1] = "Slot";
|
|
6303
|
-
return ActivationPoint2;
|
|
6304
|
-
})(ActivationPoint || {});
|
|
6305
|
-
var FeeSchedulerMode = /* @__PURE__ */ ((FeeSchedulerMode2) => {
|
|
6306
|
-
FeeSchedulerMode2[FeeSchedulerMode2["Linear"] = 0] = "Linear";
|
|
6307
|
-
FeeSchedulerMode2[FeeSchedulerMode2["Exponential"] = 1] = "Exponential";
|
|
6308
|
-
return FeeSchedulerMode2;
|
|
6309
|
-
})(FeeSchedulerMode || {});
|
|
6310
|
-
var CollectFeeMode = /* @__PURE__ */ ((CollectFeeMode2) => {
|
|
6311
|
-
CollectFeeMode2[CollectFeeMode2["BothToken"] = 0] = "BothToken";
|
|
6312
|
-
CollectFeeMode2[CollectFeeMode2["OnlyB"] = 1] = "OnlyB";
|
|
6313
|
-
return CollectFeeMode2;
|
|
6314
|
-
})(CollectFeeMode || {});
|
|
6315
|
-
var TradeDirection = /* @__PURE__ */ ((TradeDirection2) => {
|
|
6316
|
-
TradeDirection2[TradeDirection2["AtoB"] = 0] = "AtoB";
|
|
6317
|
-
TradeDirection2[TradeDirection2["BtoA"] = 1] = "BtoA";
|
|
6318
|
-
return TradeDirection2;
|
|
6319
|
-
})(TradeDirection || {});
|
|
6320
|
-
var ActivationType = /* @__PURE__ */ ((ActivationType2) => {
|
|
6321
|
-
ActivationType2[ActivationType2["Slot"] = 0] = "Slot";
|
|
6322
|
-
ActivationType2[ActivationType2["Timestamp"] = 1] = "Timestamp";
|
|
6323
|
-
return ActivationType2;
|
|
6324
|
-
})(ActivationType || {});
|
|
6325
|
-
|
|
6326
|
-
// src/math/index.ts
|
|
6327
|
-
function shlDiv(x, y, offset, rounding) {
|
|
6328
|
-
const scale = new (0, _anchor.BN)(1).shln(offset);
|
|
6329
|
-
return mulDiv(x, scale, y, rounding);
|
|
6330
|
-
}
|
|
6331
|
-
function mulDiv(x, y, denominator, rounding) {
|
|
6332
|
-
const { div, mod } = x.mul(y).divmod(denominator);
|
|
6333
|
-
if (rounding == 0 /* Up */ && !mod.isZero()) {
|
|
6334
|
-
return div.add(new (0, _anchor.BN)(1));
|
|
6335
|
-
}
|
|
6336
|
-
return div;
|
|
6337
|
-
}
|
|
6338
|
-
function divCeil(a, b) {
|
|
6339
|
-
if (a.isZero()) {
|
|
6340
|
-
return new (0, _anchor.BN)(0);
|
|
6341
|
-
}
|
|
6342
|
-
return a.add(b.sub(new (0, _anchor.BN)(1))).div(b);
|
|
6343
|
-
}
|
|
6344
|
-
function decimalToQ64(num) {
|
|
6345
|
-
return new (0, _anchor.BN)(num.mul(_decimaljs2.default.pow(2, 64)).floor().toFixed());
|
|
6346
|
-
}
|
|
6347
|
-
function priceToSqrtPrice(initPrice, tokenADecimal, tokenBDecimal) {
|
|
6348
|
-
const sqrtPriceQ64 = decimalToQ64(
|
|
6349
|
-
initPrice.mul(_decimaljs2.default.pow(10, tokenBDecimal - tokenADecimal)).sqrt()
|
|
6350
|
-
);
|
|
6351
|
-
return sqrtPriceQ64;
|
|
6352
|
-
}
|
|
6353
|
-
|
|
6354
|
-
// src/utils/token.ts
|
|
6287
|
+
// src/helpers/token.ts
|
|
6355
6288
|
|
|
6356
6289
|
|
|
6357
6290
|
|
|
@@ -6450,9 +6383,41 @@ function getNftOwner(connection, nftMint) {
|
|
|
6450
6383
|
});
|
|
6451
6384
|
}
|
|
6452
6385
|
|
|
6453
|
-
// src/
|
|
6386
|
+
// src/helpers/fee.ts
|
|
6454
6387
|
|
|
6455
6388
|
|
|
6389
|
+
// src/types.ts
|
|
6390
|
+
var Rounding = /* @__PURE__ */ ((Rounding2) => {
|
|
6391
|
+
Rounding2[Rounding2["Up"] = 0] = "Up";
|
|
6392
|
+
Rounding2[Rounding2["Down"] = 1] = "Down";
|
|
6393
|
+
return Rounding2;
|
|
6394
|
+
})(Rounding || {});
|
|
6395
|
+
var ActivationPoint = /* @__PURE__ */ ((ActivationPoint2) => {
|
|
6396
|
+
ActivationPoint2[ActivationPoint2["Timestamp"] = 0] = "Timestamp";
|
|
6397
|
+
ActivationPoint2[ActivationPoint2["Slot"] = 1] = "Slot";
|
|
6398
|
+
return ActivationPoint2;
|
|
6399
|
+
})(ActivationPoint || {});
|
|
6400
|
+
var FeeSchedulerMode = /* @__PURE__ */ ((FeeSchedulerMode2) => {
|
|
6401
|
+
FeeSchedulerMode2[FeeSchedulerMode2["Linear"] = 0] = "Linear";
|
|
6402
|
+
FeeSchedulerMode2[FeeSchedulerMode2["Exponential"] = 1] = "Exponential";
|
|
6403
|
+
return FeeSchedulerMode2;
|
|
6404
|
+
})(FeeSchedulerMode || {});
|
|
6405
|
+
var CollectFeeMode = /* @__PURE__ */ ((CollectFeeMode3) => {
|
|
6406
|
+
CollectFeeMode3[CollectFeeMode3["BothToken"] = 0] = "BothToken";
|
|
6407
|
+
CollectFeeMode3[CollectFeeMode3["OnlyB"] = 1] = "OnlyB";
|
|
6408
|
+
return CollectFeeMode3;
|
|
6409
|
+
})(CollectFeeMode || {});
|
|
6410
|
+
var TradeDirection = /* @__PURE__ */ ((TradeDirection3) => {
|
|
6411
|
+
TradeDirection3[TradeDirection3["AtoB"] = 0] = "AtoB";
|
|
6412
|
+
TradeDirection3[TradeDirection3["BtoA"] = 1] = "BtoA";
|
|
6413
|
+
return TradeDirection3;
|
|
6414
|
+
})(TradeDirection || {});
|
|
6415
|
+
var ActivationType = /* @__PURE__ */ ((ActivationType2) => {
|
|
6416
|
+
ActivationType2[ActivationType2["Slot"] = 0] = "Slot";
|
|
6417
|
+
ActivationType2[ActivationType2["Timestamp"] = 1] = "Timestamp";
|
|
6418
|
+
return ActivationType2;
|
|
6419
|
+
})(ActivationType || {});
|
|
6420
|
+
|
|
6456
6421
|
// src/math/feeMath.ts
|
|
6457
6422
|
|
|
6458
6423
|
var MAX_EXPONENTIAL = new (0, _anchor.BN)(524288);
|
|
@@ -6557,51 +6522,32 @@ function pow(base, exp) {
|
|
|
6557
6522
|
return result;
|
|
6558
6523
|
}
|
|
6559
6524
|
|
|
6560
|
-
// src/
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
const bps = reductionFactor.shln(SCALE_OFFSET).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
|
|
6567
|
-
const base = ONE.sub(bps);
|
|
6568
|
-
const result = pow(base, period);
|
|
6569
|
-
feeNumerator = cliffFeeNumerator.mul(result).shrn(SCALE_OFFSET);
|
|
6570
|
-
}
|
|
6571
|
-
return feeNumerator;
|
|
6572
|
-
}
|
|
6573
|
-
function getDynamicFeeNumerator(volatilityAccumulator, binStep, variableFeeControl) {
|
|
6574
|
-
const squareVfaBin = volatilityAccumulator.mul(binStep).pow(new (0, _anchor.BN)(2));
|
|
6575
|
-
const vFee = squareVfaBin.mul(variableFeeControl);
|
|
6576
|
-
return vFee.addn(99999999999).divn(1e11);
|
|
6525
|
+
// src/math/index.ts
|
|
6526
|
+
|
|
6527
|
+
var _decimaljs = require('decimal.js'); var _decimaljs2 = _interopRequireDefault(_decimaljs);
|
|
6528
|
+
function shlDiv(x, y, offset, rounding) {
|
|
6529
|
+
const scale = new (0, _anchor.BN)(1).shln(offset);
|
|
6530
|
+
return mulDiv(x, scale, y, rounding);
|
|
6577
6531
|
}
|
|
6578
|
-
function
|
|
6579
|
-
|
|
6580
|
-
|
|
6532
|
+
function mulDiv(x, y, denominator, rounding) {
|
|
6533
|
+
const { div, mod } = x.mul(y).divmod(denominator);
|
|
6534
|
+
if (rounding == 0 /* Up */ && !mod.isZero()) {
|
|
6535
|
+
return div.add(new (0, _anchor.BN)(1));
|
|
6581
6536
|
}
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
)
|
|
6586
|
-
|
|
6587
|
-
feeSchedulerMode,
|
|
6588
|
-
cliffFeeNumerator,
|
|
6589
|
-
period,
|
|
6590
|
-
reductionFactor
|
|
6591
|
-
);
|
|
6592
|
-
if (dynamicFeeParams) {
|
|
6593
|
-
const { volatilityAccumulator, binStep, variableFeeControl } = dynamicFeeParams;
|
|
6594
|
-
const dynamicFeeNumberator = getDynamicFeeNumerator(
|
|
6595
|
-
volatilityAccumulator,
|
|
6596
|
-
binStep,
|
|
6597
|
-
variableFeeControl
|
|
6598
|
-
);
|
|
6599
|
-
feeNumerator.add(dynamicFeeNumberator);
|
|
6537
|
+
return div;
|
|
6538
|
+
}
|
|
6539
|
+
function divCeil(a, b) {
|
|
6540
|
+
if (a.isZero()) {
|
|
6541
|
+
return new (0, _anchor.BN)(0);
|
|
6600
6542
|
}
|
|
6601
|
-
return
|
|
6543
|
+
return a.add(b.sub(new (0, _anchor.BN)(1))).div(b);
|
|
6544
|
+
}
|
|
6545
|
+
function getInitPriceQ64(tokenAAmount, tokenBAmount) {
|
|
6546
|
+
const sqrtInitPrice = new (0, _decimaljs2.default)(tokenBAmount.toString()).div(new (0, _decimaljs2.default)(tokenAAmount.toString())).sqrt();
|
|
6547
|
+
return new (0, _anchor.BN)(sqrtInitPrice.mul(_decimaljs2.default.pow(2, 64)).floor().toFixed());
|
|
6602
6548
|
}
|
|
6603
6549
|
|
|
6604
|
-
// src/
|
|
6550
|
+
// src/helpers/curve.ts
|
|
6605
6551
|
|
|
6606
6552
|
function getNextSqrtPrice(amount, sqrtPrice, liquidity, aToB) {
|
|
6607
6553
|
let result;
|
|
@@ -6634,92 +6580,6 @@ function getDeltaAmountB(lowerSqrtPrice, upperSqrtPrice, liquidity, rounding) {
|
|
|
6634
6580
|
}
|
|
6635
6581
|
return result;
|
|
6636
6582
|
}
|
|
6637
|
-
function calculateSwap(inAmount, sqrtPrice, liquidity, tradeFeeNumerator, aToB, collectFeeMode) {
|
|
6638
|
-
let outAmount;
|
|
6639
|
-
let lpFee;
|
|
6640
|
-
if (collectFeeMode === 0 /* BothToken */) {
|
|
6641
|
-
if (aToB) {
|
|
6642
|
-
const nextSqrtPrice = getNextSqrtPrice(
|
|
6643
|
-
inAmount,
|
|
6644
|
-
sqrtPrice,
|
|
6645
|
-
liquidity,
|
|
6646
|
-
true
|
|
6647
|
-
);
|
|
6648
|
-
outAmount = getDeltaAmountB(
|
|
6649
|
-
nextSqrtPrice,
|
|
6650
|
-
sqrtPrice,
|
|
6651
|
-
liquidity,
|
|
6652
|
-
1 /* Down */
|
|
6653
|
-
);
|
|
6654
|
-
lpFee = mulDiv(
|
|
6655
|
-
outAmount,
|
|
6656
|
-
tradeFeeNumerator,
|
|
6657
|
-
new (0, _anchor.BN)(FEE_DENOMINATOR),
|
|
6658
|
-
1 /* Down */
|
|
6659
|
-
);
|
|
6660
|
-
} else {
|
|
6661
|
-
const nextSqrtPrice = getNextSqrtPrice(
|
|
6662
|
-
inAmount,
|
|
6663
|
-
sqrtPrice,
|
|
6664
|
-
liquidity,
|
|
6665
|
-
false
|
|
6666
|
-
);
|
|
6667
|
-
outAmount = getDeltaAmountA(
|
|
6668
|
-
sqrtPrice,
|
|
6669
|
-
nextSqrtPrice,
|
|
6670
|
-
liquidity,
|
|
6671
|
-
1 /* Down */
|
|
6672
|
-
);
|
|
6673
|
-
lpFee = mulDiv(
|
|
6674
|
-
outAmount,
|
|
6675
|
-
tradeFeeNumerator,
|
|
6676
|
-
new (0, _anchor.BN)(new (0, _anchor.BN)(FEE_DENOMINATOR)),
|
|
6677
|
-
1 /* Down */
|
|
6678
|
-
);
|
|
6679
|
-
}
|
|
6680
|
-
} else {
|
|
6681
|
-
const nextSqrtPrice = getNextSqrtPrice(
|
|
6682
|
-
inAmount,
|
|
6683
|
-
sqrtPrice,
|
|
6684
|
-
liquidity,
|
|
6685
|
-
true
|
|
6686
|
-
);
|
|
6687
|
-
outAmount = getDeltaAmountB(
|
|
6688
|
-
nextSqrtPrice,
|
|
6689
|
-
sqrtPrice,
|
|
6690
|
-
liquidity,
|
|
6691
|
-
1 /* Down */
|
|
6692
|
-
);
|
|
6693
|
-
lpFee = mulDiv(
|
|
6694
|
-
outAmount,
|
|
6695
|
-
tradeFeeNumerator,
|
|
6696
|
-
new (0, _anchor.BN)(FEE_DENOMINATOR),
|
|
6697
|
-
1 /* Down */
|
|
6698
|
-
);
|
|
6699
|
-
if (aToB) {
|
|
6700
|
-
} else {
|
|
6701
|
-
lpFee = mulDiv(
|
|
6702
|
-
inAmount,
|
|
6703
|
-
tradeFeeNumerator,
|
|
6704
|
-
new (0, _anchor.BN)(FEE_DENOMINATOR),
|
|
6705
|
-
1 /* Down */
|
|
6706
|
-
);
|
|
6707
|
-
const nextSqrtPrice2 = getNextSqrtPrice(
|
|
6708
|
-
inAmount.sub(lpFee),
|
|
6709
|
-
sqrtPrice,
|
|
6710
|
-
liquidity,
|
|
6711
|
-
false
|
|
6712
|
-
);
|
|
6713
|
-
outAmount = getDeltaAmountA(
|
|
6714
|
-
sqrtPrice,
|
|
6715
|
-
nextSqrtPrice2,
|
|
6716
|
-
liquidity,
|
|
6717
|
-
1 /* Down */
|
|
6718
|
-
);
|
|
6719
|
-
}
|
|
6720
|
-
}
|
|
6721
|
-
return { amountOutExcludedlpFee: outAmount.sub(lpFee), lpFee };
|
|
6722
|
-
}
|
|
6723
6583
|
function getLiquidityDeltaFromAmountA(maxAmountA, lowerSqrtPrice, upperSqrtPrice) {
|
|
6724
6584
|
const prod = maxAmountA.mul(upperSqrtPrice.mul(lowerSqrtPrice));
|
|
6725
6585
|
const delta = upperSqrtPrice.sub(lowerSqrtPrice);
|
|
@@ -6742,7 +6602,89 @@ function getAmountBFromLiquidityDelta(liquidity, currentSqrtPrice) {
|
|
|
6742
6602
|
return prod.shrn(SCALE_OFFSET * 2);
|
|
6743
6603
|
}
|
|
6744
6604
|
|
|
6745
|
-
// src/
|
|
6605
|
+
// src/helpers/fee.ts
|
|
6606
|
+
function getBaseFeeNumerator(feeSchedulerMode, cliffFeeNumerator, period, reductionFactor) {
|
|
6607
|
+
let feeNumerator;
|
|
6608
|
+
if (feeSchedulerMode == 0 /* Linear */) {
|
|
6609
|
+
feeNumerator = cliffFeeNumerator.sub(period.mul(reductionFactor));
|
|
6610
|
+
} else {
|
|
6611
|
+
const bps = reductionFactor.shln(SCALE_OFFSET).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
|
|
6612
|
+
const base = ONE.sub(bps);
|
|
6613
|
+
const result = pow(base, period);
|
|
6614
|
+
feeNumerator = cliffFeeNumerator.mul(result).shrn(SCALE_OFFSET);
|
|
6615
|
+
}
|
|
6616
|
+
return feeNumerator;
|
|
6617
|
+
}
|
|
6618
|
+
function getDynamicFeeNumerator(volatilityAccumulator, binStep, variableFeeControl) {
|
|
6619
|
+
const squareVfaBin = volatilityAccumulator.mul(binStep).pow(new (0, _anchor.BN)(2));
|
|
6620
|
+
const vFee = squareVfaBin.mul(variableFeeControl);
|
|
6621
|
+
return vFee.addn(99999999999).divn(1e11);
|
|
6622
|
+
}
|
|
6623
|
+
function getFeeNumerator(currentPoint, activationPoint, numberOfPeriod, periodFrequency, feeSchedulerMode, cliffFeeNumerator, reductionFactor, dynamicFeeParams) {
|
|
6624
|
+
if (Number(periodFrequency) == 0) {
|
|
6625
|
+
return cliffFeeNumerator;
|
|
6626
|
+
}
|
|
6627
|
+
const period = new (0, _anchor.BN)(currentPoint).lt(activationPoint) ? new (0, _anchor.BN)(numberOfPeriod) : _anchor.BN.min(
|
|
6628
|
+
new (0, _anchor.BN)(numberOfPeriod),
|
|
6629
|
+
new (0, _anchor.BN)(currentPoint).sub(activationPoint).div(periodFrequency)
|
|
6630
|
+
);
|
|
6631
|
+
let feeNumerator = getBaseFeeNumerator(
|
|
6632
|
+
feeSchedulerMode,
|
|
6633
|
+
cliffFeeNumerator,
|
|
6634
|
+
period,
|
|
6635
|
+
reductionFactor
|
|
6636
|
+
);
|
|
6637
|
+
if (dynamicFeeParams) {
|
|
6638
|
+
const { volatilityAccumulator, binStep, variableFeeControl } = dynamicFeeParams;
|
|
6639
|
+
const dynamicFeeNumberator = getDynamicFeeNumerator(
|
|
6640
|
+
volatilityAccumulator,
|
|
6641
|
+
binStep,
|
|
6642
|
+
variableFeeControl
|
|
6643
|
+
);
|
|
6644
|
+
feeNumerator.add(dynamicFeeNumberator);
|
|
6645
|
+
}
|
|
6646
|
+
return feeNumerator.gt(new (0, _anchor.BN)(MAX_FEE_NUMERATOR)) ? new (0, _anchor.BN)(MAX_FEE_NUMERATOR) : feeNumerator;
|
|
6647
|
+
}
|
|
6648
|
+
function getFeeMode(collectFeeMode, btoA) {
|
|
6649
|
+
const feeOnInput = btoA && collectFeeMode === 1 /* OnlyB */;
|
|
6650
|
+
const feesOnTokenA = btoA && collectFeeMode === 0 /* BothToken */;
|
|
6651
|
+
return {
|
|
6652
|
+
feeOnInput,
|
|
6653
|
+
feesOnTokenA
|
|
6654
|
+
};
|
|
6655
|
+
}
|
|
6656
|
+
function getTotalFeeOnAmount(amount, tradeFeeNumerator) {
|
|
6657
|
+
return mulDiv(
|
|
6658
|
+
amount,
|
|
6659
|
+
tradeFeeNumerator,
|
|
6660
|
+
new (0, _anchor.BN)(FEE_DENOMINATOR),
|
|
6661
|
+
0 /* Up */
|
|
6662
|
+
);
|
|
6663
|
+
}
|
|
6664
|
+
function getSwapAmount(inAmount, sqrtPrice, liquidity, tradeFeeNumerator, aToB, collectFeeMode) {
|
|
6665
|
+
let feeMode = getFeeMode(collectFeeMode, !aToB);
|
|
6666
|
+
let actualInAmount = inAmount;
|
|
6667
|
+
let totalFee = new (0, _anchor.BN)(0);
|
|
6668
|
+
if (feeMode.feeOnInput) {
|
|
6669
|
+
totalFee = getTotalFeeOnAmount(inAmount, tradeFeeNumerator);
|
|
6670
|
+
actualInAmount = inAmount.sub(totalFee);
|
|
6671
|
+
}
|
|
6672
|
+
const outAmount = aToB ? getDeltaAmountB(
|
|
6673
|
+
getNextSqrtPrice(actualInAmount, sqrtPrice, liquidity, true),
|
|
6674
|
+
sqrtPrice,
|
|
6675
|
+
liquidity,
|
|
6676
|
+
1 /* Down */
|
|
6677
|
+
) : getDeltaAmountA(
|
|
6678
|
+
sqrtPrice,
|
|
6679
|
+
getNextSqrtPrice(actualInAmount, sqrtPrice, liquidity, false),
|
|
6680
|
+
liquidity,
|
|
6681
|
+
1 /* Down */
|
|
6682
|
+
);
|
|
6683
|
+
const actualOutAmount = feeMode.feeOnInput ? outAmount : (totalFee = getTotalFeeOnAmount(outAmount, tradeFeeNumerator), outAmount.sub(totalFee));
|
|
6684
|
+
return { actualOutAmount, totalFee };
|
|
6685
|
+
}
|
|
6686
|
+
|
|
6687
|
+
// src/helpers/computeUnits.ts
|
|
6746
6688
|
|
|
6747
6689
|
|
|
6748
6690
|
|
|
@@ -6817,19 +6759,36 @@ var getEstimatedComputeUnitIxWithBuffer = (connection, instructions, feePayer, b
|
|
|
6817
6759
|
return _web3js.ComputeBudgetProgram.setComputeUnitLimit({ units });
|
|
6818
6760
|
});
|
|
6819
6761
|
|
|
6820
|
-
// src/
|
|
6762
|
+
// src/helpers/utils.ts
|
|
6821
6763
|
|
|
6822
6764
|
|
|
6823
|
-
var
|
|
6824
|
-
const slippage = (100
|
|
6765
|
+
var getMaxAmountWithSlippage = (amount, rate) => {
|
|
6766
|
+
const slippage = (100 + rate) / 100 * BASIS_POINT_MAX;
|
|
6767
|
+
return amount.mul(new (0, _anchor.BN)(slippage)).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
|
|
6768
|
+
};
|
|
6769
|
+
var getMinAmountWithSlippage = (amount, rate) => {
|
|
6770
|
+
const slippage = (100 - rate) / 100 * BASIS_POINT_MAX;
|
|
6825
6771
|
return amount.mul(new (0, _anchor.BN)(slippage)).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
|
|
6826
6772
|
};
|
|
6827
|
-
var getPriceImpact = (
|
|
6828
|
-
const diff =
|
|
6829
|
-
return new (0, _decimaljs2.default)(diff.toString()).div(new (0, _decimaljs2.default)(
|
|
6773
|
+
var getPriceImpact = (actualAmount, idealAmount) => {
|
|
6774
|
+
const diff = idealAmount.sub(actualAmount);
|
|
6775
|
+
return new (0, _decimaljs2.default)(diff.toString()).div(new (0, _decimaljs2.default)(idealAmount.toString())).mul(100).toNumber();
|
|
6776
|
+
};
|
|
6777
|
+
var getCurrentPrice = (sqrtPrice, tokenADecimal, tokenBDecimal) => {
|
|
6778
|
+
const rawSqrtPrice = sqrtPrice.shrn(SCALE_OFFSET);
|
|
6779
|
+
const price = rawSqrtPrice.mul(rawSqrtPrice);
|
|
6780
|
+
const expo = __pow(10, tokenADecimal - tokenBDecimal);
|
|
6781
|
+
return price.muln(expo);
|
|
6782
|
+
};
|
|
6783
|
+
var getUnClaimReward = (positionState) => {
|
|
6784
|
+
return {
|
|
6785
|
+
feeTokenA: positionState.feeAPending,
|
|
6786
|
+
feeTokenB: positionState.feeBPending,
|
|
6787
|
+
rewards: positionState.rewardInfos.length > 0 ? positionState.rewardInfos.map((item) => item.rewardPendings) : []
|
|
6788
|
+
};
|
|
6830
6789
|
};
|
|
6831
6790
|
|
|
6832
|
-
// src/
|
|
6791
|
+
// src/helpers/accountFilters.ts
|
|
6833
6792
|
var positionByPoolFilter = (pool) => {
|
|
6834
6793
|
return {
|
|
6835
6794
|
memcmp: {
|
|
@@ -6846,28 +6805,23 @@ var CpAmm = class {
|
|
|
6846
6805
|
connection
|
|
6847
6806
|
});
|
|
6848
6807
|
}
|
|
6808
|
+
/**
|
|
6809
|
+
* Returns the Anchor program instance.
|
|
6810
|
+
* @returns The AmmProgram instance.
|
|
6811
|
+
*/
|
|
6849
6812
|
getProgram() {
|
|
6850
6813
|
return this._program;
|
|
6851
6814
|
}
|
|
6852
6815
|
/**
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
@param {Decimal} initialPrice - The initial price ratio of tokenX/tokenY (will be inverted if needed).
|
|
6859
|
-
@param {Decimal} liquidity - The initial liquidity value.
|
|
6860
|
-
@returns {PreparedPoolCreation} Object containing the ordered token mints and their Q64 price/liquidity values.
|
|
6861
|
-
*/
|
|
6816
|
+
* Prepares parameters required for pool creation, including initial sqrt price and liquidity.
|
|
6817
|
+
* @private
|
|
6818
|
+
* @param {PreparePoolCreationParams} params - Initial token amounts for pool creation.
|
|
6819
|
+
* @returns init sqrt price and liquidity in Q64 format.
|
|
6820
|
+
*/
|
|
6862
6821
|
preparePoolCreationParams(params) {
|
|
6863
6822
|
return __async(this, null, function* () {
|
|
6864
|
-
const { tokenAAmount, tokenBAmount
|
|
6865
|
-
const
|
|
6866
|
-
const sqrtPriceQ64 = priceToSqrtPrice(
|
|
6867
|
-
new (0, _decimaljs2.default)(initPrice.toString()),
|
|
6868
|
-
tokenADecimal,
|
|
6869
|
-
tokenBDecimal
|
|
6870
|
-
);
|
|
6823
|
+
const { tokenAAmount, tokenBAmount } = params;
|
|
6824
|
+
const sqrtPriceQ64 = getInitPriceQ64(tokenAAmount, tokenBAmount);
|
|
6871
6825
|
if (sqrtPriceQ64.lt(MIN_SQRT_PRICE) || sqrtPriceQ64.gt(MAX_SQRT_PRICE)) {
|
|
6872
6826
|
throw new Error(`Invalid sqrt price: ${sqrtPriceQ64.toString()}`);
|
|
6873
6827
|
}
|
|
@@ -6890,7 +6844,11 @@ var CpAmm = class {
|
|
|
6890
6844
|
};
|
|
6891
6845
|
});
|
|
6892
6846
|
}
|
|
6893
|
-
|
|
6847
|
+
/**
|
|
6848
|
+
* Fetches the Config state of the program.
|
|
6849
|
+
* @param config - Public key of the config account.
|
|
6850
|
+
* @returns Parsed ConfigState.
|
|
6851
|
+
*/
|
|
6894
6852
|
fetchConfigState(config) {
|
|
6895
6853
|
return __async(this, null, function* () {
|
|
6896
6854
|
const configState = yield this._program.account.config.fetchNullable(
|
|
@@ -6900,6 +6858,11 @@ var CpAmm = class {
|
|
|
6900
6858
|
return configState;
|
|
6901
6859
|
});
|
|
6902
6860
|
}
|
|
6861
|
+
/**
|
|
6862
|
+
* Fetches the Pool state.
|
|
6863
|
+
* @param pool - Public key of the pool.
|
|
6864
|
+
* @returns Parsed PoolState.
|
|
6865
|
+
*/
|
|
6903
6866
|
fetchPoolState(pool) {
|
|
6904
6867
|
return __async(this, null, function* () {
|
|
6905
6868
|
const poolState = yield this._program.account.pool.fetchNullable(pool);
|
|
@@ -6907,6 +6870,11 @@ var CpAmm = class {
|
|
|
6907
6870
|
return poolState;
|
|
6908
6871
|
});
|
|
6909
6872
|
}
|
|
6873
|
+
/**
|
|
6874
|
+
* Fetches the Position state.
|
|
6875
|
+
* @param position - Public key of the position.
|
|
6876
|
+
* @returns Parsed PositionState.
|
|
6877
|
+
*/
|
|
6910
6878
|
fetchPositionState(position) {
|
|
6911
6879
|
return __async(this, null, function* () {
|
|
6912
6880
|
const positionState = yield this._program.account.position.fetchNullable(
|
|
@@ -6916,24 +6884,42 @@ var CpAmm = class {
|
|
|
6916
6884
|
return positionState;
|
|
6917
6885
|
});
|
|
6918
6886
|
}
|
|
6887
|
+
/**
|
|
6888
|
+
* Retrieves all config accounts.
|
|
6889
|
+
* @returns Array of config public keys and their states.
|
|
6890
|
+
*/
|
|
6919
6891
|
getAllConfigs() {
|
|
6920
6892
|
return __async(this, null, function* () {
|
|
6921
6893
|
const configAccounts = yield this._program.account.config.all();
|
|
6922
6894
|
return configAccounts;
|
|
6923
6895
|
});
|
|
6924
6896
|
}
|
|
6897
|
+
/**
|
|
6898
|
+
* Retrieves all pool accounts.
|
|
6899
|
+
* @returns Array of pool public keys and their states.
|
|
6900
|
+
*/
|
|
6925
6901
|
getAllPools() {
|
|
6926
6902
|
return __async(this, null, function* () {
|
|
6927
6903
|
const poolAccounts = yield this._program.account.pool.all();
|
|
6928
6904
|
return poolAccounts;
|
|
6929
6905
|
});
|
|
6930
6906
|
}
|
|
6907
|
+
/**
|
|
6908
|
+
* Retrieves all position accounts.
|
|
6909
|
+
* @returns Array of position public keys and their states.
|
|
6910
|
+
*/
|
|
6931
6911
|
getAllPositions() {
|
|
6932
6912
|
return __async(this, null, function* () {
|
|
6933
6913
|
const poolAccounts = yield this._program.account.position.all();
|
|
6934
6914
|
return poolAccounts;
|
|
6935
6915
|
});
|
|
6936
6916
|
}
|
|
6917
|
+
/**
|
|
6918
|
+
* Gets all positions of a user for a specific pool.
|
|
6919
|
+
* @param pool - Public key of the pool.
|
|
6920
|
+
* @param user - Public key of the user.
|
|
6921
|
+
* @returns List of user positions for the pool.
|
|
6922
|
+
*/
|
|
6937
6923
|
getUserPositionByPool(pool, user) {
|
|
6938
6924
|
return __async(this, null, function* () {
|
|
6939
6925
|
const positions = yield this._program.account.position.all([
|
|
@@ -6952,6 +6938,11 @@ var CpAmm = class {
|
|
|
6952
6938
|
return result;
|
|
6953
6939
|
});
|
|
6954
6940
|
}
|
|
6941
|
+
/**
|
|
6942
|
+
* Gets all positions of a user across all pools.
|
|
6943
|
+
* @param user - Public key of the user.
|
|
6944
|
+
* @returns Array of user positions.
|
|
6945
|
+
*/
|
|
6955
6946
|
getPositionsByUser(user) {
|
|
6956
6947
|
return __async(this, null, function* () {
|
|
6957
6948
|
const positions = yield this._program.account.position.all();
|
|
@@ -6968,6 +6959,11 @@ var CpAmm = class {
|
|
|
6968
6959
|
return result;
|
|
6969
6960
|
});
|
|
6970
6961
|
}
|
|
6962
|
+
/**
|
|
6963
|
+
* Calculates swap quote based on input amount and pool state.
|
|
6964
|
+
* @param params - Swap parameters including input amount, pool state, slippage, etc.
|
|
6965
|
+
* @returns Swap quote including expected output amount, fee, and price impact.
|
|
6966
|
+
*/
|
|
6971
6967
|
getQuote(params) {
|
|
6972
6968
|
return __async(this, null, function* () {
|
|
6973
6969
|
var _a;
|
|
@@ -7010,7 +7006,7 @@ var CpAmm = class {
|
|
|
7010
7006
|
reductionFactor,
|
|
7011
7007
|
dynamicFeeParams
|
|
7012
7008
|
);
|
|
7013
|
-
const {
|
|
7009
|
+
const { actualOutAmount, totalFee } = getSwapAmount(
|
|
7014
7010
|
inAmount,
|
|
7015
7011
|
sqrtPriceQ64,
|
|
7016
7012
|
liquidityQ64,
|
|
@@ -7019,28 +7015,22 @@ var CpAmm = class {
|
|
|
7019
7015
|
collectFeeMode
|
|
7020
7016
|
);
|
|
7021
7017
|
const minSwapOutAmount = getMinAmountWithSlippage(
|
|
7022
|
-
|
|
7018
|
+
actualOutAmount,
|
|
7023
7019
|
slippage
|
|
7024
7020
|
);
|
|
7025
7021
|
return {
|
|
7026
7022
|
swapInAmount: inAmount,
|
|
7027
|
-
swapOutAmount:
|
|
7023
|
+
swapOutAmount: actualOutAmount,
|
|
7028
7024
|
minSwapOutAmount,
|
|
7029
|
-
totalFee
|
|
7030
|
-
priceImpact: getPriceImpact(minSwapOutAmount,
|
|
7025
|
+
totalFee,
|
|
7026
|
+
priceImpact: getPriceImpact(minSwapOutAmount, actualOutAmount)
|
|
7031
7027
|
};
|
|
7032
7028
|
});
|
|
7033
7029
|
}
|
|
7034
7030
|
/**
|
|
7035
7031
|
* Computes the liquidity delta based on the provided token amounts and pool state.
|
|
7036
7032
|
*
|
|
7037
|
-
* @param {LiquidityDeltaParams} params - The parameters for liquidity calculation
|
|
7038
|
-
* - tokenX: The mint address of token X.
|
|
7039
|
-
* - tokenY: The mint address of token Y.
|
|
7040
|
-
* - maxAmountX: The maximum amount of token X available.
|
|
7041
|
-
* - maxAmountY: The maximum amount of token Y available.
|
|
7042
|
-
* - pool: The address of the liquidity pool.
|
|
7043
|
-
*
|
|
7033
|
+
* @param {LiquidityDeltaParams} params - The parameters for liquidity calculation
|
|
7044
7034
|
* @returns {Promise<BN>} - The computed liquidity delta in Q64 value.
|
|
7045
7035
|
*/
|
|
7046
7036
|
getLiquidityDelta(params) {
|
|
@@ -7065,6 +7055,11 @@ var CpAmm = class {
|
|
|
7065
7055
|
return liquidityDeltaFromAmountA.gte(liquidityDeltaFromAmountB) ? liquidityDeltaFromAmountB : liquidityDeltaFromAmountA;
|
|
7066
7056
|
});
|
|
7067
7057
|
}
|
|
7058
|
+
/**
|
|
7059
|
+
* Builds a transaction to create a permissionless pool.
|
|
7060
|
+
* @param params - Parameters for pool creation.
|
|
7061
|
+
* @returns Transaction builder.
|
|
7062
|
+
*/
|
|
7068
7063
|
createPool(params) {
|
|
7069
7064
|
return __async(this, null, function* () {
|
|
7070
7065
|
const {
|
|
@@ -7077,17 +7072,13 @@ var CpAmm = class {
|
|
|
7077
7072
|
activationPoint,
|
|
7078
7073
|
tokenAAmount,
|
|
7079
7074
|
tokenBAmount,
|
|
7080
|
-
tokenADecimal,
|
|
7081
|
-
tokenBDecimal,
|
|
7082
7075
|
tokenAProgram,
|
|
7083
7076
|
tokenBProgram
|
|
7084
7077
|
} = params;
|
|
7085
7078
|
const { sqrtPriceQ64, liquidityQ64 } = yield this.preparePoolCreationParams(
|
|
7086
7079
|
{
|
|
7087
7080
|
tokenAAmount,
|
|
7088
|
-
tokenBAmount
|
|
7089
|
-
tokenADecimal,
|
|
7090
|
-
tokenBDecimal
|
|
7081
|
+
tokenBAmount
|
|
7091
7082
|
}
|
|
7092
7083
|
);
|
|
7093
7084
|
const poolAuthority = derivePoolAuthority(this._program.programId);
|
|
@@ -7184,6 +7175,11 @@ var CpAmm = class {
|
|
|
7184
7175
|
return tx;
|
|
7185
7176
|
});
|
|
7186
7177
|
}
|
|
7178
|
+
/**
|
|
7179
|
+
* Builds a transaction to create a customizable pool.
|
|
7180
|
+
* @param params - Parameters for customizable pool creation.
|
|
7181
|
+
* @returns Transaction and related addresses.
|
|
7182
|
+
*/
|
|
7187
7183
|
createCustomPool(params) {
|
|
7188
7184
|
return __async(this, null, function* () {
|
|
7189
7185
|
const {
|
|
@@ -7207,9 +7203,7 @@ var CpAmm = class {
|
|
|
7207
7203
|
const { sqrtPriceQ64, liquidityQ64 } = yield this.preparePoolCreationParams(
|
|
7208
7204
|
{
|
|
7209
7205
|
tokenAAmount,
|
|
7210
|
-
tokenBAmount
|
|
7211
|
-
tokenADecimal,
|
|
7212
|
-
tokenBDecimal
|
|
7206
|
+
tokenBAmount
|
|
7213
7207
|
}
|
|
7214
7208
|
);
|
|
7215
7209
|
const poolAuthority = derivePoolAuthority(this._program.programId);
|
|
@@ -7310,6 +7304,11 @@ var CpAmm = class {
|
|
|
7310
7304
|
return { tx: transaction, pool, position };
|
|
7311
7305
|
});
|
|
7312
7306
|
}
|
|
7307
|
+
/**
|
|
7308
|
+
* Builds a transaction to create a position.
|
|
7309
|
+
* @param {CreatePositionParams} params - Parameters for position creation.
|
|
7310
|
+
* @returns Transaction builder.
|
|
7311
|
+
*/
|
|
7313
7312
|
createPosition(params) {
|
|
7314
7313
|
return __async(this, null, function* () {
|
|
7315
7314
|
const { owner, payer, pool, positionNft } = params;
|
|
@@ -7337,6 +7336,11 @@ var CpAmm = class {
|
|
|
7337
7336
|
}).transaction();
|
|
7338
7337
|
});
|
|
7339
7338
|
}
|
|
7339
|
+
/**
|
|
7340
|
+
* Builds a transaction to add liquidity to an existing position.
|
|
7341
|
+
* @param {AddLiquidityParams} params - Parameters for adding liquidity.
|
|
7342
|
+
* @returns Transaction builder.
|
|
7343
|
+
*/
|
|
7340
7344
|
addLiquidity(params) {
|
|
7341
7345
|
return __async(this, null, function* () {
|
|
7342
7346
|
const {
|
|
@@ -7429,6 +7433,11 @@ var CpAmm = class {
|
|
|
7429
7433
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
7430
7434
|
});
|
|
7431
7435
|
}
|
|
7436
|
+
/**
|
|
7437
|
+
* Builds a transaction to remove liquidity from a position.
|
|
7438
|
+
* @param {RemoveLiquidityParams} params - Parameters for removing liquidity.
|
|
7439
|
+
* @returns Transaction builder.
|
|
7440
|
+
*/
|
|
7432
7441
|
removeLiquidity(params) {
|
|
7433
7442
|
return __async(this, null, function* () {
|
|
7434
7443
|
const {
|
|
@@ -7505,6 +7514,11 @@ var CpAmm = class {
|
|
|
7505
7514
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
7506
7515
|
});
|
|
7507
7516
|
}
|
|
7517
|
+
/**
|
|
7518
|
+
* Builds a transaction to perform a swap in the pool.
|
|
7519
|
+
* @param {SwapParams} params - Parameters for swapping tokens.
|
|
7520
|
+
* @returns Transaction builder.
|
|
7521
|
+
*/
|
|
7508
7522
|
swap(params) {
|
|
7509
7523
|
return __async(this, null, function* () {
|
|
7510
7524
|
const {
|
|
@@ -7583,6 +7597,11 @@ var CpAmm = class {
|
|
|
7583
7597
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
7584
7598
|
});
|
|
7585
7599
|
}
|
|
7600
|
+
/**
|
|
7601
|
+
* Builds a transaction to lock a position with vesting schedule.
|
|
7602
|
+
* @param {LockPositionParams} params - Locking parameters.
|
|
7603
|
+
* @returns Transaction builder.
|
|
7604
|
+
*/
|
|
7586
7605
|
lockPosition(params) {
|
|
7587
7606
|
return __async(this, null, function* () {
|
|
7588
7607
|
const {
|
|
@@ -7624,6 +7643,11 @@ var CpAmm = class {
|
|
|
7624
7643
|
}).transaction();
|
|
7625
7644
|
});
|
|
7626
7645
|
}
|
|
7646
|
+
/**
|
|
7647
|
+
* Builds a transaction to permanently lock a position.
|
|
7648
|
+
* @param {PermanentLockParams} params - Parameters for permanent locking.
|
|
7649
|
+
* @returns Transaction builder.
|
|
7650
|
+
*/
|
|
7627
7651
|
permanentLockPosition(params) {
|
|
7628
7652
|
return __async(this, null, function* () {
|
|
7629
7653
|
const { owner, position, positionNftMint, pool, unlockedLiquidity } = params;
|
|
@@ -7641,6 +7665,11 @@ var CpAmm = class {
|
|
|
7641
7665
|
}).transaction();
|
|
7642
7666
|
});
|
|
7643
7667
|
}
|
|
7668
|
+
/**
|
|
7669
|
+
* Builds a transaction to refresh vesting status of a position.
|
|
7670
|
+
* @param {RefreshVestingParams} params - Refresh vesting parameters.
|
|
7671
|
+
* @returns Transaction builder.
|
|
7672
|
+
*/
|
|
7644
7673
|
refreshVesting(params) {
|
|
7645
7674
|
return __async(this, null, function* () {
|
|
7646
7675
|
const { owner, position, positionNftMint, pool, vestings } = params;
|
|
@@ -7664,6 +7693,11 @@ var CpAmm = class {
|
|
|
7664
7693
|
).transaction();
|
|
7665
7694
|
});
|
|
7666
7695
|
}
|
|
7696
|
+
/**
|
|
7697
|
+
* Builds a transaction to claim position fee rewards.
|
|
7698
|
+
* @param {ClaimPositionFeeParams} params - Parameters for claiming position fee.
|
|
7699
|
+
* @returns Transaction builder.
|
|
7700
|
+
*/
|
|
7667
7701
|
claimPositionFee(params) {
|
|
7668
7702
|
return __async(this, null, function* () {
|
|
7669
7703
|
const {
|
|
@@ -7733,6 +7767,11 @@ var CpAmm = class {
|
|
|
7733
7767
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
7734
7768
|
});
|
|
7735
7769
|
}
|
|
7770
|
+
/**
|
|
7771
|
+
* Builds a transaction to update reward duration.
|
|
7772
|
+
* @param {UpdateRewardDurationParams} params - Parameters including pool and new duration.
|
|
7773
|
+
* @returns Transaction builder.
|
|
7774
|
+
*/
|
|
7736
7775
|
updateRewardDuration(params) {
|
|
7737
7776
|
return __async(this, null, function* () {
|
|
7738
7777
|
const { pool, admin, rewardIndex, newDuration } = params;
|
|
@@ -7744,6 +7783,11 @@ var CpAmm = class {
|
|
|
7744
7783
|
}).transaction();
|
|
7745
7784
|
});
|
|
7746
7785
|
}
|
|
7786
|
+
/**
|
|
7787
|
+
* Builds a transaction to update reward funder address.
|
|
7788
|
+
* @param {UpdateRewardFunderParams} params - Parameters including pool and new funder address.
|
|
7789
|
+
* @returns Transaction builder.
|
|
7790
|
+
*/
|
|
7747
7791
|
updateRewardFunder(params) {
|
|
7748
7792
|
return __async(this, null, function* () {
|
|
7749
7793
|
const { pool, admin, rewardIndex, newFunder } = params;
|
|
@@ -7755,6 +7799,11 @@ var CpAmm = class {
|
|
|
7755
7799
|
}).transaction();
|
|
7756
7800
|
});
|
|
7757
7801
|
}
|
|
7802
|
+
/**
|
|
7803
|
+
* Builds a transaction to fund rewards in a pool.
|
|
7804
|
+
* @param {FundRewardParams} params - Funding parameters.
|
|
7805
|
+
* @returns Transaction builder.
|
|
7806
|
+
*/
|
|
7758
7807
|
fundReward(params) {
|
|
7759
7808
|
return __async(this, null, function* () {
|
|
7760
7809
|
const { rewardIndex, carryForward, pool, funder, amount } = params;
|
|
@@ -7792,6 +7841,11 @@ var CpAmm = class {
|
|
|
7792
7841
|
}).transaction();
|
|
7793
7842
|
});
|
|
7794
7843
|
}
|
|
7844
|
+
/**
|
|
7845
|
+
* Builds a transaction to withdraw ineligible rewards from a pool.
|
|
7846
|
+
* @param {WithdrawIneligibleRewardParams} params - Parameters for withdrawal.
|
|
7847
|
+
* @returns Transaction builder.
|
|
7848
|
+
*/
|
|
7795
7849
|
withdrawIneligibleReward(params) {
|
|
7796
7850
|
return __async(this, null, function* () {
|
|
7797
7851
|
const { rewardIndex, pool, funder } = params;
|
|
@@ -7828,6 +7882,11 @@ var CpAmm = class {
|
|
|
7828
7882
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
7829
7883
|
});
|
|
7830
7884
|
}
|
|
7885
|
+
/**
|
|
7886
|
+
* Builds a transaction to claim partner fee rewards.
|
|
7887
|
+
* @param {ClaimPartnerFeeParams} params - Claim parameters including amounts and partner address.
|
|
7888
|
+
* @returns Transaction builder.
|
|
7889
|
+
*/
|
|
7831
7890
|
claimPartnerFee(params) {
|
|
7832
7891
|
return __async(this, null, function* () {
|
|
7833
7892
|
const { partner, pool, maxAmountA, maxAmountB } = params;
|
|
@@ -7892,6 +7951,11 @@ var CpAmm = class {
|
|
|
7892
7951
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
7893
7952
|
});
|
|
7894
7953
|
}
|
|
7954
|
+
/**
|
|
7955
|
+
* Builds a transaction to claim reward from a position.
|
|
7956
|
+
* @param {ClaimRewardParams} params - Parameters for claiming reward.
|
|
7957
|
+
* @returns Transaction builder.
|
|
7958
|
+
*/
|
|
7895
7959
|
claimReward(params) {
|
|
7896
7960
|
return __async(this, null, function* () {
|
|
7897
7961
|
const { user, position, rewardIndex } = params;
|
|
@@ -7989,5 +8053,11 @@ var index_default = cp_amm_default;
|
|
|
7989
8053
|
|
|
7990
8054
|
|
|
7991
8055
|
|
|
7992
|
-
|
|
8056
|
+
|
|
8057
|
+
|
|
8058
|
+
|
|
8059
|
+
|
|
8060
|
+
|
|
8061
|
+
|
|
8062
|
+
exports.ActivationPoint = ActivationPoint; exports.ActivationType = ActivationType; exports.BASIS_POINT_MAX = BASIS_POINT_MAX; exports.CP_AMM_PROGRAM_ID = CP_AMM_PROGRAM_ID; exports.CollectFeeMode = CollectFeeMode; exports.CpAmm = CpAmm; exports.FEE_DENOMINATOR = FEE_DENOMINATOR; exports.FeeSchedulerMode = FeeSchedulerMode; exports.MAX_CU_BUFFER = MAX_CU_BUFFER; exports.MAX_FEE_NUMERATOR = MAX_FEE_NUMERATOR; exports.MAX_SQRT_PRICE = MAX_SQRT_PRICE; exports.MIN_CU_BUFFER = MIN_CU_BUFFER; exports.MIN_SQRT_PRICE = MIN_SQRT_PRICE; exports.Rounding = Rounding; exports.SCALE_OFFSET = SCALE_OFFSET; exports.TradeDirection = TradeDirection; exports.default = index_default; exports.deriveClaimFeeOperatorAddress = deriveClaimFeeOperatorAddress; exports.deriveConfigAddress = deriveConfigAddress; exports.deriveCustomizablePoolAddress = deriveCustomizablePoolAddress; exports.deriveEventAuthority = deriveEventAuthority; exports.derivePoolAddress = derivePoolAddress; exports.derivePoolAuthority = derivePoolAuthority; exports.derivePositionAddress = derivePositionAddress; exports.derivePositionNftAccount = derivePositionNftAccount; exports.deriveRewardVaultAddress = deriveRewardVaultAddress; exports.deriveTokenBadgeAddress = deriveTokenBadgeAddress; exports.deriveTokenVaultAddress = deriveTokenVaultAddress; exports.getAmountAFromLiquidityDelta = getAmountAFromLiquidityDelta; exports.getAmountBFromLiquidityDelta = getAmountBFromLiquidityDelta; exports.getBaseFeeNumerator = getBaseFeeNumerator; exports.getCurrentPrice = getCurrentPrice; exports.getDeltaAmountA = getDeltaAmountA; exports.getDeltaAmountB = getDeltaAmountB; exports.getDynamicFeeNumerator = getDynamicFeeNumerator; exports.getEstimatedComputeUnitIxWithBuffer = getEstimatedComputeUnitIxWithBuffer; exports.getEstimatedComputeUnitUsageWithBuffer = getEstimatedComputeUnitUsageWithBuffer; exports.getFeeNumerator = getFeeNumerator; exports.getFirstKey = getFirstKey; exports.getLiquidityDeltaFromAmountA = getLiquidityDeltaFromAmountA; exports.getLiquidityDeltaFromAmountB = getLiquidityDeltaFromAmountB; exports.getMaxAmountWithSlippage = getMaxAmountWithSlippage; exports.getMinAmountWithSlippage = getMinAmountWithSlippage; exports.getNextSqrtPrice = getNextSqrtPrice; exports.getNftOwner = getNftOwner; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getPriceImpact = getPriceImpact; exports.getSecondKey = getSecondKey; exports.getSimulationComputeUnits = getSimulationComputeUnits; exports.getSwapAmount = getSwapAmount; exports.getTokenDecimals = getTokenDecimals; exports.getTokenProgram = getTokenProgram; exports.getUnClaimReward = getUnClaimReward; exports.positionByPoolFilter = positionByPoolFilter; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.wrapSOLInstruction = wrapSOLInstruction;
|
|
7993
8063
|
//# sourceMappingURL=index.js.map
|