@meteora-ag/dynamic-bonding-curve-sdk 1.3.0 → 1.3.2
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.cjs +406 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +113 -17
- package/dist/index.d.ts +113 -17
- package/dist/index.js +405 -53
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -365,6 +365,42 @@ function getInitializeAmounts(sqrtMinPrice, sqrtMaxPrice, sqrtPrice, liquidity)
|
|
|
365
365
|
);
|
|
366
366
|
return [amountBase, amountQuote];
|
|
367
367
|
}
|
|
368
|
+
function getNextSqrtPriceFromAmountQuoteRoundingUp(sqrtPrice, liquidity, amount) {
|
|
369
|
+
if (amount.isZero()) {
|
|
370
|
+
return sqrtPrice;
|
|
371
|
+
}
|
|
372
|
+
const amountShifted = SafeMath.shl(amount, 128);
|
|
373
|
+
const step1 = SafeMath.add(amountShifted, liquidity);
|
|
374
|
+
const step2 = SafeMath.sub(step1, new (0, _bnjs2.default)(1));
|
|
375
|
+
const quotient = SafeMath.div(step2, liquidity);
|
|
376
|
+
return SafeMath.sub(sqrtPrice, quotient);
|
|
377
|
+
}
|
|
378
|
+
function getNextSqrtPriceFromAmountBaseRoundingDown(sqrtPrice, liquidity, amount) {
|
|
379
|
+
if (amount.isZero()) {
|
|
380
|
+
return sqrtPrice;
|
|
381
|
+
}
|
|
382
|
+
const product = SafeMath.mul(amount, sqrtPrice);
|
|
383
|
+
const denominator = SafeMath.sub(liquidity, product);
|
|
384
|
+
return mulDiv(liquidity, sqrtPrice, denominator, 1 /* Down */);
|
|
385
|
+
}
|
|
386
|
+
function getNextSqrtPriceFromOutput(sqrtPrice, liquidity, outAmount, isQuote) {
|
|
387
|
+
if (sqrtPrice.isZero()) {
|
|
388
|
+
throw new Error("Sqrt price cannot be zero");
|
|
389
|
+
}
|
|
390
|
+
if (isQuote) {
|
|
391
|
+
return getNextSqrtPriceFromAmountQuoteRoundingUp(
|
|
392
|
+
sqrtPrice,
|
|
393
|
+
liquidity,
|
|
394
|
+
outAmount
|
|
395
|
+
);
|
|
396
|
+
} else {
|
|
397
|
+
return getNextSqrtPriceFromAmountBaseRoundingDown(
|
|
398
|
+
sqrtPrice,
|
|
399
|
+
liquidity,
|
|
400
|
+
outAmount
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
368
404
|
|
|
369
405
|
// src/helpers/common.ts
|
|
370
406
|
|
|
@@ -21611,9 +21647,272 @@ function calculateQuoteExactInAmount(config, virtualPool, currentPoint) {
|
|
|
21611
21647
|
return amountInAfterFee;
|
|
21612
21648
|
}
|
|
21613
21649
|
}
|
|
21650
|
+
function getExcludedFeeAmount(tradeFeeNumerator, includedFeeAmount) {
|
|
21651
|
+
const tradingFee = mulDiv(
|
|
21652
|
+
includedFeeAmount,
|
|
21653
|
+
tradeFeeNumerator,
|
|
21654
|
+
new (0, _bnjs2.default)(FEE_DENOMINATOR),
|
|
21655
|
+
0 /* Up */
|
|
21656
|
+
);
|
|
21657
|
+
const excludedFeeAmount = SafeMath.sub(includedFeeAmount, tradingFee);
|
|
21658
|
+
return [excludedFeeAmount, tradingFee];
|
|
21659
|
+
}
|
|
21660
|
+
function getIncludedFeeAmount(tradeFeeNumerator, excludedFeeAmount) {
|
|
21661
|
+
const includedFeeAmount = mulDiv(
|
|
21662
|
+
excludedFeeAmount,
|
|
21663
|
+
new (0, _bnjs2.default)(FEE_DENOMINATOR),
|
|
21664
|
+
new (0, _bnjs2.default)(FEE_DENOMINATOR).sub(tradeFeeNumerator),
|
|
21665
|
+
0 /* Up */
|
|
21666
|
+
);
|
|
21667
|
+
const [inverseAmount] = getExcludedFeeAmount(
|
|
21668
|
+
tradeFeeNumerator,
|
|
21669
|
+
includedFeeAmount
|
|
21670
|
+
);
|
|
21671
|
+
if (inverseAmount.lt(excludedFeeAmount)) {
|
|
21672
|
+
throw new Error("Inverse amount is less than excluded_fee_amount");
|
|
21673
|
+
}
|
|
21674
|
+
return includedFeeAmount;
|
|
21675
|
+
}
|
|
21676
|
+
function getSwapResultFromOutAmount(poolState, configState, outAmount, feeMode, tradeDirection, currentPoint) {
|
|
21677
|
+
let actualProtocolFee = new (0, _bnjs2.default)(0);
|
|
21678
|
+
let actualTradingFee = new (0, _bnjs2.default)(0);
|
|
21679
|
+
let actualReferralFee = new (0, _bnjs2.default)(0);
|
|
21680
|
+
const baseFeeNumerator = getBaseFeeNumerator(
|
|
21681
|
+
configState.poolFees.baseFee,
|
|
21682
|
+
tradeDirection,
|
|
21683
|
+
currentPoint,
|
|
21684
|
+
poolState.activationPoint
|
|
21685
|
+
);
|
|
21686
|
+
let tradeFeeNumerator = baseFeeNumerator;
|
|
21687
|
+
if (configState.poolFees.dynamicFee.initialized !== 0) {
|
|
21688
|
+
const variableFee = getVariableFee(
|
|
21689
|
+
configState.poolFees.dynamicFee,
|
|
21690
|
+
poolState.volatilityTracker
|
|
21691
|
+
);
|
|
21692
|
+
tradeFeeNumerator = SafeMath.add(tradeFeeNumerator, variableFee);
|
|
21693
|
+
}
|
|
21694
|
+
tradeFeeNumerator = _bnjs2.default.min(tradeFeeNumerator, new (0, _bnjs2.default)(MAX_FEE_NUMERATOR));
|
|
21695
|
+
const includedFeeOutAmount = feeMode.feesOnInput ? outAmount : getIncludedFeeAmount(tradeFeeNumerator, outAmount);
|
|
21696
|
+
if (!feeMode.feesOnInput) {
|
|
21697
|
+
const feeResult = getFeeOnAmount(
|
|
21698
|
+
includedFeeOutAmount,
|
|
21699
|
+
configState.poolFees,
|
|
21700
|
+
feeMode.hasReferral,
|
|
21701
|
+
currentPoint,
|
|
21702
|
+
poolState.activationPoint,
|
|
21703
|
+
poolState.volatilityTracker,
|
|
21704
|
+
tradeDirection
|
|
21705
|
+
);
|
|
21706
|
+
actualProtocolFee = feeResult.protocolFee;
|
|
21707
|
+
actualTradingFee = feeResult.tradingFee;
|
|
21708
|
+
actualReferralFee = feeResult.referralFee;
|
|
21709
|
+
}
|
|
21710
|
+
const swapAmount = tradeDirection === 0 /* BaseToQuote */ ? getInAmountFromBaseToQuote(
|
|
21711
|
+
configState,
|
|
21712
|
+
poolState.sqrtPrice,
|
|
21713
|
+
includedFeeOutAmount
|
|
21714
|
+
) : getInAmountFromQuoteToBase(
|
|
21715
|
+
configState,
|
|
21716
|
+
poolState.sqrtPrice,
|
|
21717
|
+
includedFeeOutAmount
|
|
21718
|
+
);
|
|
21719
|
+
const includedFeeInAmount = feeMode.feesOnInput ? getIncludedFeeAmount(tradeFeeNumerator, swapAmount.outputAmount) : swapAmount.outputAmount;
|
|
21720
|
+
if (feeMode.feesOnInput) {
|
|
21721
|
+
const feeResult = getFeeOnAmount(
|
|
21722
|
+
includedFeeInAmount,
|
|
21723
|
+
configState.poolFees,
|
|
21724
|
+
feeMode.hasReferral,
|
|
21725
|
+
currentPoint,
|
|
21726
|
+
poolState.activationPoint,
|
|
21727
|
+
poolState.volatilityTracker,
|
|
21728
|
+
tradeDirection
|
|
21729
|
+
);
|
|
21730
|
+
actualProtocolFee = feeResult.protocolFee;
|
|
21731
|
+
actualTradingFee = feeResult.tradingFee;
|
|
21732
|
+
actualReferralFee = feeResult.referralFee;
|
|
21733
|
+
}
|
|
21734
|
+
return {
|
|
21735
|
+
amountOut: includedFeeInAmount,
|
|
21736
|
+
minimumAmountOut: outAmount,
|
|
21737
|
+
nextSqrtPrice: swapAmount.nextSqrtPrice,
|
|
21738
|
+
fee: {
|
|
21739
|
+
trading: actualTradingFee,
|
|
21740
|
+
protocol: actualProtocolFee,
|
|
21741
|
+
referral: actualReferralFee
|
|
21742
|
+
},
|
|
21743
|
+
price: {
|
|
21744
|
+
beforeSwap: poolState.sqrtPrice,
|
|
21745
|
+
afterSwap: swapAmount.nextSqrtPrice
|
|
21746
|
+
}
|
|
21747
|
+
};
|
|
21748
|
+
}
|
|
21749
|
+
function getInAmountFromBaseToQuote(configState, currentSqrtPrice, outAmount) {
|
|
21750
|
+
let currentSqrtPriceLocal = currentSqrtPrice;
|
|
21751
|
+
let amountLeft = outAmount;
|
|
21752
|
+
let totalAmountIn = new (0, _bnjs2.default)(0);
|
|
21753
|
+
for (let i = configState.curve.length - 1; i >= 0; i--) {
|
|
21754
|
+
if (configState.curve[i].sqrtPrice.isZero() || configState.curve[i].liquidity.isZero()) {
|
|
21755
|
+
continue;
|
|
21756
|
+
}
|
|
21757
|
+
if (configState.curve[i].sqrtPrice.lt(currentSqrtPriceLocal)) {
|
|
21758
|
+
const currentLiquidity = i + 1 < configState.curve.length ? configState.curve[i + 1].liquidity : configState.curve[i].liquidity;
|
|
21759
|
+
if (currentLiquidity.isZero()) continue;
|
|
21760
|
+
const maxAmountOut = getDeltaAmountQuoteUnsigned(
|
|
21761
|
+
configState.curve[i].sqrtPrice,
|
|
21762
|
+
currentSqrtPriceLocal,
|
|
21763
|
+
currentLiquidity,
|
|
21764
|
+
1 /* Down */
|
|
21765
|
+
);
|
|
21766
|
+
if (amountLeft.lt(maxAmountOut)) {
|
|
21767
|
+
const nextSqrtPrice = getNextSqrtPriceFromOutput(
|
|
21768
|
+
currentSqrtPriceLocal,
|
|
21769
|
+
currentLiquidity,
|
|
21770
|
+
amountLeft,
|
|
21771
|
+
true
|
|
21772
|
+
);
|
|
21773
|
+
const inAmount = getDeltaAmountBaseUnsigned(
|
|
21774
|
+
nextSqrtPrice,
|
|
21775
|
+
currentSqrtPriceLocal,
|
|
21776
|
+
currentLiquidity,
|
|
21777
|
+
0 /* Up */
|
|
21778
|
+
);
|
|
21779
|
+
totalAmountIn = SafeMath.add(totalAmountIn, inAmount);
|
|
21780
|
+
currentSqrtPriceLocal = nextSqrtPrice;
|
|
21781
|
+
amountLeft = new (0, _bnjs2.default)(0);
|
|
21782
|
+
break;
|
|
21783
|
+
} else {
|
|
21784
|
+
const nextSqrtPrice = configState.curve[i].sqrtPrice;
|
|
21785
|
+
const inAmount = getDeltaAmountBaseUnsigned(
|
|
21786
|
+
nextSqrtPrice,
|
|
21787
|
+
currentSqrtPriceLocal,
|
|
21788
|
+
currentLiquidity,
|
|
21789
|
+
0 /* Up */
|
|
21790
|
+
);
|
|
21791
|
+
totalAmountIn = SafeMath.add(totalAmountIn, inAmount);
|
|
21792
|
+
currentSqrtPriceLocal = nextSqrtPrice;
|
|
21793
|
+
amountLeft = SafeMath.sub(amountLeft, maxAmountOut);
|
|
21794
|
+
}
|
|
21795
|
+
}
|
|
21796
|
+
}
|
|
21797
|
+
if (!amountLeft.isZero()) {
|
|
21798
|
+
const nextSqrtPrice = getNextSqrtPriceFromOutput(
|
|
21799
|
+
currentSqrtPriceLocal,
|
|
21800
|
+
configState.curve[0].liquidity,
|
|
21801
|
+
amountLeft,
|
|
21802
|
+
true
|
|
21803
|
+
);
|
|
21804
|
+
if (nextSqrtPrice.lt(configState.sqrtStartPrice)) {
|
|
21805
|
+
throw new Error("Not enough liquidity");
|
|
21806
|
+
}
|
|
21807
|
+
const inAmount = getDeltaAmountBaseUnsigned(
|
|
21808
|
+
nextSqrtPrice,
|
|
21809
|
+
currentSqrtPriceLocal,
|
|
21810
|
+
configState.curve[0].liquidity,
|
|
21811
|
+
0 /* Up */
|
|
21812
|
+
);
|
|
21813
|
+
totalAmountIn = SafeMath.add(totalAmountIn, inAmount);
|
|
21814
|
+
currentSqrtPriceLocal = nextSqrtPrice;
|
|
21815
|
+
}
|
|
21816
|
+
return {
|
|
21817
|
+
outputAmount: totalAmountIn,
|
|
21818
|
+
nextSqrtPrice: currentSqrtPriceLocal
|
|
21819
|
+
};
|
|
21820
|
+
}
|
|
21821
|
+
function getInAmountFromQuoteToBase(configState, currentSqrtPrice, outAmount) {
|
|
21822
|
+
let totalInAmount = new (0, _bnjs2.default)(0);
|
|
21823
|
+
let currentSqrtPriceLocal = currentSqrtPrice;
|
|
21824
|
+
let amountLeft = outAmount;
|
|
21825
|
+
for (let i = 0; i < configState.curve.length; i++) {
|
|
21826
|
+
if (configState.curve[i].sqrtPrice.isZero() || configState.curve[i].liquidity.isZero()) {
|
|
21827
|
+
break;
|
|
21828
|
+
}
|
|
21829
|
+
if (configState.curve[i].liquidity.isZero()) continue;
|
|
21830
|
+
if (configState.curve[i].sqrtPrice.gt(currentSqrtPriceLocal)) {
|
|
21831
|
+
const maxAmountOut = getDeltaAmountBaseUnsigned(
|
|
21832
|
+
currentSqrtPriceLocal,
|
|
21833
|
+
configState.curve[i].sqrtPrice,
|
|
21834
|
+
configState.curve[i].liquidity,
|
|
21835
|
+
1 /* Down */
|
|
21836
|
+
);
|
|
21837
|
+
if (amountLeft.lt(maxAmountOut)) {
|
|
21838
|
+
const nextSqrtPrice = getNextSqrtPriceFromOutput(
|
|
21839
|
+
currentSqrtPriceLocal,
|
|
21840
|
+
configState.curve[i].liquidity,
|
|
21841
|
+
amountLeft,
|
|
21842
|
+
false
|
|
21843
|
+
);
|
|
21844
|
+
const inAmount = getDeltaAmountQuoteUnsigned(
|
|
21845
|
+
currentSqrtPriceLocal,
|
|
21846
|
+
nextSqrtPrice,
|
|
21847
|
+
configState.curve[i].liquidity,
|
|
21848
|
+
0 /* Up */
|
|
21849
|
+
);
|
|
21850
|
+
totalInAmount = SafeMath.add(totalInAmount, inAmount);
|
|
21851
|
+
currentSqrtPriceLocal = nextSqrtPrice;
|
|
21852
|
+
amountLeft = new (0, _bnjs2.default)(0);
|
|
21853
|
+
break;
|
|
21854
|
+
} else {
|
|
21855
|
+
const nextSqrtPrice = configState.curve[i].sqrtPrice;
|
|
21856
|
+
const inAmount = getDeltaAmountQuoteUnsigned(
|
|
21857
|
+
currentSqrtPriceLocal,
|
|
21858
|
+
nextSqrtPrice,
|
|
21859
|
+
configState.curve[i].liquidity,
|
|
21860
|
+
0 /* Up */
|
|
21861
|
+
);
|
|
21862
|
+
totalInAmount = SafeMath.add(totalInAmount, inAmount);
|
|
21863
|
+
currentSqrtPriceLocal = nextSqrtPrice;
|
|
21864
|
+
amountLeft = SafeMath.sub(amountLeft, maxAmountOut);
|
|
21865
|
+
}
|
|
21866
|
+
}
|
|
21867
|
+
}
|
|
21868
|
+
if (!amountLeft.isZero()) {
|
|
21869
|
+
throw new Error("Not enough liquidity");
|
|
21870
|
+
}
|
|
21871
|
+
return {
|
|
21872
|
+
outputAmount: totalInAmount,
|
|
21873
|
+
nextSqrtPrice: currentSqrtPriceLocal
|
|
21874
|
+
};
|
|
21875
|
+
}
|
|
21876
|
+
function swapQuoteExactOut(virtualPool, config, swapBaseForQuote, outAmount, slippageBps = 0, hasReferral, currentPoint) {
|
|
21877
|
+
if (virtualPool.quoteReserve.gte(config.migrationQuoteThreshold)) {
|
|
21878
|
+
throw new Error("Virtual pool is completed");
|
|
21879
|
+
}
|
|
21880
|
+
if (outAmount.isZero()) {
|
|
21881
|
+
throw new Error("Amount is zero");
|
|
21882
|
+
}
|
|
21883
|
+
const tradeDirection = swapBaseForQuote ? 0 /* BaseToQuote */ : 1 /* QuoteToBase */;
|
|
21884
|
+
const feeMode = getFeeMode(
|
|
21885
|
+
config.collectFeeMode,
|
|
21886
|
+
tradeDirection,
|
|
21887
|
+
hasReferral
|
|
21888
|
+
);
|
|
21889
|
+
const result = getSwapResultFromOutAmount(
|
|
21890
|
+
virtualPool,
|
|
21891
|
+
config,
|
|
21892
|
+
outAmount,
|
|
21893
|
+
feeMode,
|
|
21894
|
+
tradeDirection,
|
|
21895
|
+
currentPoint
|
|
21896
|
+
);
|
|
21897
|
+
if (slippageBps > 0) {
|
|
21898
|
+
const slippageFactor = new (0, _bnjs2.default)(1e4 + slippageBps);
|
|
21899
|
+
const denominator = new (0, _bnjs2.default)(1e4);
|
|
21900
|
+
const maximumAmountIn = result.amountOut.mul(slippageFactor).div(denominator);
|
|
21901
|
+
return {
|
|
21902
|
+
...result,
|
|
21903
|
+
amountOut: maximumAmountIn,
|
|
21904
|
+
minimumAmountOut: outAmount
|
|
21905
|
+
};
|
|
21906
|
+
}
|
|
21907
|
+
return {
|
|
21908
|
+
...result,
|
|
21909
|
+
minimumAmountOut: outAmount
|
|
21910
|
+
};
|
|
21911
|
+
}
|
|
21614
21912
|
|
|
21615
21913
|
// src/services/state.ts
|
|
21616
21914
|
|
|
21915
|
+
|
|
21617
21916
|
var StateService = class extends DynamicBondingCurveProgram {
|
|
21618
21917
|
constructor(connection, commitment) {
|
|
21619
21918
|
super(connection, commitment);
|
|
@@ -21720,9 +22019,9 @@ var StateService = class extends DynamicBondingCurveProgram {
|
|
|
21720
22019
|
const config = await this.getPoolConfig(pool.config);
|
|
21721
22020
|
const quoteReserve = pool.quoteReserve;
|
|
21722
22021
|
const migrationThreshold = config.migrationQuoteThreshold;
|
|
21723
|
-
const
|
|
21724
|
-
const
|
|
21725
|
-
const progress =
|
|
22022
|
+
const quoteReserveDecimal = new (0, _decimaljs2.default)(quoteReserve.toString());
|
|
22023
|
+
const thresholdDecimal = new (0, _decimaljs2.default)(migrationThreshold.toString());
|
|
22024
|
+
const progress = quoteReserveDecimal.div(thresholdDecimal).toNumber();
|
|
21726
22025
|
return Math.min(Math.max(progress, 0), 1);
|
|
21727
22026
|
}
|
|
21728
22027
|
/**
|
|
@@ -21949,10 +22248,9 @@ var PoolService = class extends DynamicBondingCurveProgram {
|
|
|
21949
22248
|
}
|
|
21950
22249
|
/**
|
|
21951
22250
|
* Private method to create pool transaction
|
|
21952
|
-
* @param
|
|
21953
|
-
* @param
|
|
21954
|
-
* @param
|
|
21955
|
-
* @param payerAddress - The payer address
|
|
22251
|
+
* @param createPoolParam - The parameters for the pool
|
|
22252
|
+
* @param tokenType - The token type
|
|
22253
|
+
* @param quoteMint - The quote mint token
|
|
21956
22254
|
* @returns A transaction that creates the pool
|
|
21957
22255
|
*/
|
|
21958
22256
|
async createPoolTx(createPoolParam, tokenType, quoteMint) {
|
|
@@ -21982,10 +22280,12 @@ var PoolService = class extends DynamicBondingCurveProgram {
|
|
|
21982
22280
|
}
|
|
21983
22281
|
/**
|
|
21984
22282
|
* Private method to create first buy transaction
|
|
21985
|
-
* @param
|
|
21986
|
-
* @param
|
|
21987
|
-
* @param
|
|
21988
|
-
* @param
|
|
22283
|
+
* @param firstBuyParam - The parameters for the first buy
|
|
22284
|
+
* @param baseMint - The base mint token
|
|
22285
|
+
* @param config - The config key
|
|
22286
|
+
* @param baseFeeMode - The base fee mode
|
|
22287
|
+
* @param tokenType - The token type
|
|
22288
|
+
* @param quoteMint - The quote mint token
|
|
21989
22289
|
* @returns Instructions for the first buy
|
|
21990
22290
|
*/
|
|
21991
22291
|
async swapBuyTx(firstBuyParam, baseMint, config, baseFeeMode, tokenType, quoteMint) {
|
|
@@ -22176,14 +22476,19 @@ var PoolService = class extends DynamicBondingCurveProgram {
|
|
|
22176
22476
|
createConfigAndPoolWithFirstBuyParam.tokenType,
|
|
22177
22477
|
quoteMintToken
|
|
22178
22478
|
);
|
|
22179
|
-
|
|
22180
|
-
|
|
22181
|
-
|
|
22182
|
-
|
|
22183
|
-
|
|
22184
|
-
|
|
22185
|
-
|
|
22186
|
-
|
|
22479
|
+
let swapBuyTx;
|
|
22480
|
+
if (createConfigAndPoolWithFirstBuyParam.firstBuyParam && createConfigAndPoolWithFirstBuyParam.firstBuyParam.buyAmount.gt(
|
|
22481
|
+
new (0, _bnjs2.default)(0)
|
|
22482
|
+
)) {
|
|
22483
|
+
swapBuyTx = await this.swapBuyTx(
|
|
22484
|
+
createConfigAndPoolWithFirstBuyParam.firstBuyParam,
|
|
22485
|
+
createConfigAndPoolWithFirstBuyParam.preCreatePoolParam.baseMint,
|
|
22486
|
+
configKey,
|
|
22487
|
+
createConfigAndPoolWithFirstBuyParam.poolFees.baseFee.baseFeeMode,
|
|
22488
|
+
createConfigAndPoolWithFirstBuyParam.tokenType,
|
|
22489
|
+
quoteMintToken
|
|
22490
|
+
);
|
|
22491
|
+
}
|
|
22187
22492
|
return {
|
|
22188
22493
|
createConfigTx,
|
|
22189
22494
|
createPoolTx,
|
|
@@ -22204,14 +22509,17 @@ var PoolService = class extends DynamicBondingCurveProgram {
|
|
|
22204
22509
|
tokenType,
|
|
22205
22510
|
quoteMint
|
|
22206
22511
|
);
|
|
22207
|
-
|
|
22208
|
-
|
|
22209
|
-
|
|
22210
|
-
|
|
22211
|
-
|
|
22212
|
-
|
|
22213
|
-
|
|
22214
|
-
|
|
22512
|
+
let swapBuyTx;
|
|
22513
|
+
if (createPoolWithFirstBuyParam.firstBuyParam && createPoolWithFirstBuyParam.firstBuyParam.buyAmount.gt(new (0, _bnjs2.default)(0))) {
|
|
22514
|
+
swapBuyTx = await this.swapBuyTx(
|
|
22515
|
+
createPoolWithFirstBuyParam.firstBuyParam,
|
|
22516
|
+
createPoolWithFirstBuyParam.createPoolParam.baseMint,
|
|
22517
|
+
config,
|
|
22518
|
+
poolConfigState.poolFees.baseFee.baseFeeMode,
|
|
22519
|
+
tokenType,
|
|
22520
|
+
quoteMint
|
|
22521
|
+
);
|
|
22522
|
+
}
|
|
22215
22523
|
return {
|
|
22216
22524
|
createPoolTx,
|
|
22217
22525
|
swapBuyTx
|
|
@@ -22231,32 +22539,42 @@ var PoolService = class extends DynamicBondingCurveProgram {
|
|
|
22231
22539
|
tokenType,
|
|
22232
22540
|
quoteMint
|
|
22233
22541
|
);
|
|
22234
|
-
|
|
22235
|
-
|
|
22236
|
-
|
|
22237
|
-
|
|
22238
|
-
|
|
22239
|
-
|
|
22240
|
-
|
|
22241
|
-
|
|
22242
|
-
|
|
22243
|
-
|
|
22244
|
-
|
|
22245
|
-
|
|
22246
|
-
|
|
22247
|
-
|
|
22248
|
-
|
|
22249
|
-
|
|
22250
|
-
|
|
22251
|
-
|
|
22252
|
-
|
|
22253
|
-
|
|
22254
|
-
|
|
22255
|
-
|
|
22256
|
-
|
|
22257
|
-
|
|
22258
|
-
|
|
22259
|
-
|
|
22542
|
+
let partnerSwapBuyTx;
|
|
22543
|
+
if (createPoolWithPartnerAndCreatorFirstBuyParam.partnerFirstBuyParam && createPoolWithPartnerAndCreatorFirstBuyParam.partnerFirstBuyParam.buyAmount.gt(
|
|
22544
|
+
new (0, _bnjs2.default)(0)
|
|
22545
|
+
)) {
|
|
22546
|
+
partnerSwapBuyTx = await this.swapBuyTx(
|
|
22547
|
+
{
|
|
22548
|
+
buyer: createPoolWithPartnerAndCreatorFirstBuyParam.partnerFirstBuyParam.partner,
|
|
22549
|
+
buyAmount: createPoolWithPartnerAndCreatorFirstBuyParam.partnerFirstBuyParam.buyAmount,
|
|
22550
|
+
minimumAmountOut: createPoolWithPartnerAndCreatorFirstBuyParam.partnerFirstBuyParam.minimumAmountOut,
|
|
22551
|
+
referralTokenAccount: createPoolWithPartnerAndCreatorFirstBuyParam.partnerFirstBuyParam.referralTokenAccount
|
|
22552
|
+
},
|
|
22553
|
+
createPoolWithPartnerAndCreatorFirstBuyParam.createPoolParam.baseMint,
|
|
22554
|
+
config,
|
|
22555
|
+
poolConfigState.poolFees.baseFee.baseFeeMode,
|
|
22556
|
+
tokenType,
|
|
22557
|
+
quoteMint
|
|
22558
|
+
);
|
|
22559
|
+
}
|
|
22560
|
+
let creatorSwapBuyTx;
|
|
22561
|
+
if (createPoolWithPartnerAndCreatorFirstBuyParam.creatorFirstBuyParam && createPoolWithPartnerAndCreatorFirstBuyParam.creatorFirstBuyParam.buyAmount.gt(
|
|
22562
|
+
new (0, _bnjs2.default)(0)
|
|
22563
|
+
)) {
|
|
22564
|
+
creatorSwapBuyTx = await this.swapBuyTx(
|
|
22565
|
+
{
|
|
22566
|
+
buyer: createPoolWithPartnerAndCreatorFirstBuyParam.creatorFirstBuyParam.creator,
|
|
22567
|
+
buyAmount: createPoolWithPartnerAndCreatorFirstBuyParam.creatorFirstBuyParam.buyAmount,
|
|
22568
|
+
minimumAmountOut: createPoolWithPartnerAndCreatorFirstBuyParam.creatorFirstBuyParam.minimumAmountOut,
|
|
22569
|
+
referralTokenAccount: createPoolWithPartnerAndCreatorFirstBuyParam.creatorFirstBuyParam.referralTokenAccount
|
|
22570
|
+
},
|
|
22571
|
+
createPoolWithPartnerAndCreatorFirstBuyParam.createPoolParam.baseMint,
|
|
22572
|
+
config,
|
|
22573
|
+
poolConfigState.poolFees.baseFee.baseFeeMode,
|
|
22574
|
+
tokenType,
|
|
22575
|
+
quoteMint
|
|
22576
|
+
);
|
|
22577
|
+
}
|
|
22260
22578
|
return {
|
|
22261
22579
|
createPoolTx,
|
|
22262
22580
|
partnerSwapBuyTx,
|
|
@@ -22395,6 +22713,31 @@ var PoolService = class extends DynamicBondingCurveProgram {
|
|
|
22395
22713
|
exactAmountIn: requiredQuoteAmount
|
|
22396
22714
|
};
|
|
22397
22715
|
}
|
|
22716
|
+
/**
|
|
22717
|
+
* Calculate the amount in for a swap with exact output amount (quote)
|
|
22718
|
+
* @param swapQuoteExactOutParam - The parameters for the swap
|
|
22719
|
+
* @returns The swap quote result with input amount calculated
|
|
22720
|
+
*/
|
|
22721
|
+
swapQuoteExactOut(swapQuoteExactOutParam) {
|
|
22722
|
+
const {
|
|
22723
|
+
virtualPool,
|
|
22724
|
+
config,
|
|
22725
|
+
swapBaseForQuote,
|
|
22726
|
+
outAmount,
|
|
22727
|
+
slippageBps = 0,
|
|
22728
|
+
hasReferral,
|
|
22729
|
+
currentPoint
|
|
22730
|
+
} = swapQuoteExactOutParam;
|
|
22731
|
+
return swapQuoteExactOut(
|
|
22732
|
+
virtualPool,
|
|
22733
|
+
config,
|
|
22734
|
+
swapBaseForQuote,
|
|
22735
|
+
outAmount,
|
|
22736
|
+
slippageBps,
|
|
22737
|
+
hasReferral,
|
|
22738
|
+
currentPoint
|
|
22739
|
+
);
|
|
22740
|
+
}
|
|
22398
22741
|
};
|
|
22399
22742
|
|
|
22400
22743
|
// src/services/migration.ts
|
|
@@ -23977,5 +24320,14 @@ var DynamicBondingCurveClient = class _DynamicBondingCurveClient {
|
|
|
23977
24320
|
|
|
23978
24321
|
|
|
23979
24322
|
|
|
23980
|
-
|
|
24323
|
+
|
|
24324
|
+
|
|
24325
|
+
|
|
24326
|
+
|
|
24327
|
+
|
|
24328
|
+
|
|
24329
|
+
|
|
24330
|
+
|
|
24331
|
+
|
|
24332
|
+
exports.ActivationType = ActivationType; exports.BASE_ADDRESS = BASE_ADDRESS; exports.BASIS_POINT_MAX = BASIS_POINT_MAX; exports.BIN_STEP_BPS_DEFAULT = BIN_STEP_BPS_DEFAULT; exports.BIN_STEP_BPS_U128_DEFAULT = BIN_STEP_BPS_U128_DEFAULT; exports.BaseFeeMode = BaseFeeMode; exports.CollectFeeMode = CollectFeeMode; exports.CreatorService = CreatorService; exports.DAMM_V1_MIGRATION_FEE_ADDRESS = DAMM_V1_MIGRATION_FEE_ADDRESS; exports.DAMM_V1_PROGRAM_ID = DAMM_V1_PROGRAM_ID; exports.DAMM_V2_MIGRATION_FEE_ADDRESS = DAMM_V2_MIGRATION_FEE_ADDRESS; exports.DAMM_V2_PROGRAM_ID = DAMM_V2_PROGRAM_ID; exports.DYNAMIC_BONDING_CURVE_PROGRAM_ID = DYNAMIC_BONDING_CURVE_PROGRAM_ID; exports.DYNAMIC_FEE_DECAY_PERIOD_DEFAULT = DYNAMIC_FEE_DECAY_PERIOD_DEFAULT; exports.DYNAMIC_FEE_FILTER_PERIOD_DEFAULT = DYNAMIC_FEE_FILTER_PERIOD_DEFAULT; exports.DYNAMIC_FEE_REDUCTION_FACTOR_DEFAULT = DYNAMIC_FEE_REDUCTION_FACTOR_DEFAULT; exports.DynamicBondingCurveClient = DynamicBondingCurveClient; exports.DynamicBondingCurveProgram = DynamicBondingCurveProgram; exports.FEE_DENOMINATOR = FEE_DENOMINATOR; exports.LOCKER_PROGRAM_ID = LOCKER_PROGRAM_ID; exports.MAX_CREATOR_MIGRATION_FEE_PERCENTAGE = MAX_CREATOR_MIGRATION_FEE_PERCENTAGE; exports.MAX_CURVE_POINT = MAX_CURVE_POINT; exports.MAX_FEE_BPS = MAX_FEE_BPS; exports.MAX_FEE_NUMERATOR = MAX_FEE_NUMERATOR; exports.MAX_MIGRATION_FEE_PERCENTAGE = MAX_MIGRATION_FEE_PERCENTAGE; exports.MAX_PRICE_CHANGE_BPS_DEFAULT = MAX_PRICE_CHANGE_BPS_DEFAULT; exports.MAX_RATE_LIMITER_DURATION_IN_SECONDS = MAX_RATE_LIMITER_DURATION_IN_SECONDS; exports.MAX_RATE_LIMITER_DURATION_IN_SLOTS = MAX_RATE_LIMITER_DURATION_IN_SLOTS; exports.MAX_SQRT_PRICE = MAX_SQRT_PRICE; exports.MAX_SWALLOW_PERCENTAGE = MAX_SWALLOW_PERCENTAGE; exports.METAPLEX_PROGRAM_ID = METAPLEX_PROGRAM_ID; exports.MIN_FEE_BPS = MIN_FEE_BPS; exports.MIN_FEE_NUMERATOR = MIN_FEE_NUMERATOR; exports.MIN_SQRT_PRICE = MIN_SQRT_PRICE; exports.MigrationFeeOption = MigrationFeeOption; exports.MigrationOption = MigrationOption; exports.MigrationService = MigrationService; exports.OFFSET = OFFSET; exports.ONE_Q64 = ONE_Q64; exports.PARTNER_SURPLUS_SHARE = PARTNER_SURPLUS_SHARE; exports.PartnerService = PartnerService; exports.PoolService = PoolService; exports.RESOLUTION = RESOLUTION; exports.Rounding = Rounding; exports.SLOT_DURATION = SLOT_DURATION; exports.SWAP_BUFFER_PERCENTAGE = SWAP_BUFFER_PERCENTAGE; exports.TIMESTAMP_DURATION = TIMESTAMP_DURATION; exports.TokenDecimal = TokenDecimal; exports.TokenType = TokenType; exports.TokenUpdateAuthorityOption = TokenUpdateAuthorityOption; exports.TradeDirection = TradeDirection; exports.U64_MAX = U64_MAX; exports.VAULT_PROGRAM_ID = VAULT_PROGRAM_ID; exports.bpsToFeeNumerator = bpsToFeeNumerator; exports.buildCurve = buildCurve; exports.buildCurveWithLiquidityWeights = buildCurveWithLiquidityWeights; exports.buildCurveWithMarketCap = buildCurveWithMarketCap; exports.buildCurveWithTwoSegments = buildCurveWithTwoSegments; exports.calculateFeeSchedulerEndingBaseFeeBps = calculateFeeSchedulerEndingBaseFeeBps; exports.calculateQuoteExactInAmount = calculateQuoteExactInAmount; exports.checkRateLimiterApplied = checkRateLimiterApplied; exports.cleanUpTokenAccountTx = cleanUpTokenAccountTx; exports.convertDecimalToBN = convertDecimalToBN; exports.convertToLamports = convertToLamports; exports.createDammV1Program = createDammV1Program; exports.createDammV2Program = createDammV2Program; exports.createDbcProgram = createDbcProgram; exports.createInitializePermissionlessDynamicVaultIx = createInitializePermissionlessDynamicVaultIx; exports.createLockEscrowIx = createLockEscrowIx; exports.createProgramAccountFilter = createProgramAccountFilter; exports.createVaultProgram = createVaultProgram; exports.deriveBaseKeyForLocker = deriveBaseKeyForLocker; exports.deriveDammV1EventAuthority = deriveDammV1EventAuthority; exports.deriveDammV1LockEscrowAddress = deriveDammV1LockEscrowAddress; exports.deriveDammV1LpMintAddress = deriveDammV1LpMintAddress; exports.deriveDammV1MigrationMetadataAddress = deriveDammV1MigrationMetadataAddress; exports.deriveDammV1PoolAddress = deriveDammV1PoolAddress; exports.deriveDammV1PoolAuthority = deriveDammV1PoolAuthority; exports.deriveDammV1ProtocolFeeAddress = deriveDammV1ProtocolFeeAddress; exports.deriveDammV1VaultLPAddress = deriveDammV1VaultLPAddress; exports.deriveDammV2EventAuthority = deriveDammV2EventAuthority; exports.deriveDammV2LockEscrowAddress = deriveDammV2LockEscrowAddress; exports.deriveDammV2MigrationMetadataAddress = deriveDammV2MigrationMetadataAddress; exports.deriveDammV2PoolAddress = deriveDammV2PoolAddress; exports.deriveDammV2PoolAuthority = deriveDammV2PoolAuthority; exports.deriveDammV2TokenVaultAddress = deriveDammV2TokenVaultAddress; exports.deriveDbcEventAuthority = deriveDbcEventAuthority; exports.deriveDbcPoolAddress = deriveDbcPoolAddress; exports.deriveDbcPoolAuthority = deriveDbcPoolAuthority; exports.deriveDbcPoolMetadata = deriveDbcPoolMetadata; exports.deriveDbcTokenVaultAddress = deriveDbcTokenVaultAddress; exports.deriveEscrow = deriveEscrow; exports.deriveLockerEventAuthority = deriveLockerEventAuthority; exports.deriveMintMetadata = deriveMintMetadata; exports.derivePartnerMetadata = derivePartnerMetadata; exports.derivePositionAddress = derivePositionAddress; exports.derivePositionNftAccount = derivePositionNftAccount; exports.deriveTokenVaultKey = deriveTokenVaultKey; exports.deriveVaultAddress = deriveVaultAddress; exports.deriveVaultLpMintAddress = deriveVaultLpMintAddress; exports.deriveVaultPdas = deriveVaultPdas; exports.feeNumeratorToBps = feeNumeratorToBps; exports.findAssociatedTokenAddress = findAssociatedTokenAddress; exports.fromDecimalToBN = fromDecimalToBN; exports.getAccountCreationTimestamp = getAccountCreationTimestamp; exports.getAccountCreationTimestamps = getAccountCreationTimestamps; exports.getAccountData = getAccountData; exports.getBaseFeeNumerator = getBaseFeeNumerator; exports.getBaseFeeParams = getBaseFeeParams; exports.getBaseTokenForSwap = getBaseTokenForSwap; exports.getDeltaAmountBase = getDeltaAmountBase; exports.getDeltaAmountBaseUnsigned = getDeltaAmountBaseUnsigned; exports.getDeltaAmountQuoteUnsigned = getDeltaAmountQuoteUnsigned; exports.getDynamicFeeParams = getDynamicFeeParams; exports.getExcludedFeeAmount = getExcludedFeeAmount; exports.getFeeMode = getFeeMode; exports.getFeeNumeratorOnExponentialFeeScheduler = getFeeNumeratorOnExponentialFeeScheduler; exports.getFeeNumeratorOnLinearFeeScheduler = getFeeNumeratorOnLinearFeeScheduler; exports.getFeeNumeratorOnRateLimiter = getFeeNumeratorOnRateLimiter; exports.getFeeOnAmount = getFeeOnAmount; exports.getFeeSchedulerParams = getFeeSchedulerParams; exports.getFirstCurve = getFirstCurve; exports.getFirstKey = getFirstKey; exports.getInAmountFromBaseToQuote = getInAmountFromBaseToQuote; exports.getInAmountFromQuoteToBase = getInAmountFromQuoteToBase; exports.getIncludedFeeAmount = getIncludedFeeAmount; exports.getInitialLiquidityFromDeltaBase = getInitialLiquidityFromDeltaBase; exports.getInitialLiquidityFromDeltaQuote = getInitialLiquidityFromDeltaQuote; exports.getInitializeAmounts = getInitializeAmounts; exports.getLiquidity = getLiquidity; exports.getLockedVestingParams = getLockedVestingParams; exports.getMigrationBaseToken = getMigrationBaseToken; exports.getMigrationQuoteAmount = getMigrationQuoteAmount; exports.getMigrationQuoteAmountFromMigrationQuoteThreshold = getMigrationQuoteAmountFromMigrationQuoteThreshold; exports.getMigrationQuoteThresholdFromMigrationQuoteAmount = getMigrationQuoteThresholdFromMigrationQuoteAmount; exports.getMigrationThresholdPrice = getMigrationThresholdPrice; exports.getNextSqrtPriceFromAmountBaseRoundingDown = getNextSqrtPriceFromAmountBaseRoundingDown; exports.getNextSqrtPriceFromAmountBaseRoundingUp = getNextSqrtPriceFromAmountBaseRoundingUp; exports.getNextSqrtPriceFromAmountQuoteRoundingDown = getNextSqrtPriceFromAmountQuoteRoundingDown; exports.getNextSqrtPriceFromAmountQuoteRoundingUp = getNextSqrtPriceFromAmountQuoteRoundingUp; exports.getNextSqrtPriceFromInput = getNextSqrtPriceFromInput; exports.getNextSqrtPriceFromOutput = getNextSqrtPriceFromOutput; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getPercentageSupplyOnMigration = getPercentageSupplyOnMigration; exports.getPriceFromSqrtPrice = getPriceFromSqrtPrice; exports.getQuoteReserveFromNextSqrtPrice = getQuoteReserveFromNextSqrtPrice; exports.getRateLimiterParams = getRateLimiterParams; exports.getSecondKey = getSecondKey; exports.getSqrtPriceFromMarketCap = getSqrtPriceFromMarketCap; exports.getSqrtPriceFromPrice = getSqrtPriceFromPrice; exports.getSwapAmountFromBaseToQuote = getSwapAmountFromBaseToQuote; exports.getSwapAmountFromQuoteToBase = getSwapAmountFromQuoteToBase; exports.getSwapAmountWithBuffer = getSwapAmountWithBuffer; exports.getSwapResult = getSwapResult; exports.getSwapResultFromOutAmount = getSwapResultFromOutAmount; exports.getTokenDecimals = getTokenDecimals; exports.getTokenProgram = getTokenProgram; exports.getTokenType = getTokenType; exports.getTotalSupplyFromCurve = getTotalSupplyFromCurve; exports.getTotalTokenSupply = getTotalTokenSupply; exports.getTotalVestingAmount = getTotalVestingAmount; exports.getTwoCurve = getTwoCurve; exports.getVariableFee = getVariableFee; exports.isDefaultLockedVesting = isDefaultLockedVesting; exports.isNativeSol = isNativeSol; exports.prepareTokenAccountTx = prepareTokenAccountTx; exports.swapQuote = swapQuote; exports.swapQuoteExactOut = swapQuoteExactOut; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.validateActivationType = validateActivationType; exports.validateBalance = validateBalance; exports.validateBaseTokenType = validateBaseTokenType; exports.validateCollectFeeMode = validateCollectFeeMode; exports.validateConfigParameters = validateConfigParameters; exports.validateCurve = validateCurve; exports.validateFeeRateLimiter = validateFeeRateLimiter; exports.validateFeeScheduler = validateFeeScheduler; exports.validateLPPercentages = validateLPPercentages; exports.validateMigrationAndTokenType = validateMigrationAndTokenType; exports.validateMigrationFeeOption = validateMigrationFeeOption; exports.validatePoolFees = validatePoolFees; exports.validateSwapAmount = validateSwapAmount; exports.validateTokenDecimals = validateTokenDecimals; exports.validateTokenSupply = validateTokenSupply; exports.validateTokenUpdateAuthorityOptions = validateTokenUpdateAuthorityOptions; exports.wrapSOLInstruction = wrapSOLInstruction;
|
|
23981
24333
|
//# sourceMappingURL=index.cjs.map
|