@meteora-ag/cp-amm-sdk 1.0.0-rc.6 → 1.0.0-rc.7
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 +36 -6
- package/dist/index.d.ts +36 -6
- package/dist/index.js +56 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6886,6 +6886,57 @@ function getSwapAmount(inAmount, sqrtPrice, liquidity, tradeFeeNumerator, aToB,
|
|
|
6886
6886
|
const amountOut = feeMode.feeOnInput ? outAmount : (totalFee = getTotalFeeOnAmount(outAmount, tradeFeeNumerator), outAmount.sub(totalFee));
|
|
6887
6887
|
return { amountOut, totalFee };
|
|
6888
6888
|
}
|
|
6889
|
+
function bpsToFeeNumerator(bps) {
|
|
6890
|
+
return bps * FEE_DENOMINATOR / BASIS_POINT_MAX;
|
|
6891
|
+
}
|
|
6892
|
+
function feeNumeratorToBps(feeNumerator) {
|
|
6893
|
+
return feeNumerator * BASIS_POINT_MAX / FEE_DENOMINATOR;
|
|
6894
|
+
}
|
|
6895
|
+
function estimateLinearReductionFactor(cliffFeeBps, targetFeeBps, totalPeriods) {
|
|
6896
|
+
if (totalPeriods <= 0) {
|
|
6897
|
+
throw new Error("Total periods must be greater than zero");
|
|
6898
|
+
}
|
|
6899
|
+
if (cliffFeeBps > feeNumeratorToBps(MAX_FEE_NUMERATOR)) {
|
|
6900
|
+
throw new Error(
|
|
6901
|
+
`Cliff fee (${cliffFeeBps} bps) exceeds maximum allowed value of ${feeNumeratorToBps(
|
|
6902
|
+
MAX_FEE_NUMERATOR
|
|
6903
|
+
)} bps`
|
|
6904
|
+
);
|
|
6905
|
+
}
|
|
6906
|
+
if (targetFeeBps > cliffFeeBps) {
|
|
6907
|
+
throw new Error(
|
|
6908
|
+
"Target fee must be less than or equal to cliff fee for reduction"
|
|
6909
|
+
);
|
|
6910
|
+
}
|
|
6911
|
+
const cliffFeeNumerator = bpsToFeeNumerator(cliffFeeBps);
|
|
6912
|
+
const targetFeeNumerator = bpsToFeeNumerator(targetFeeBps);
|
|
6913
|
+
const totalReduction = cliffFeeNumerator - targetFeeNumerator;
|
|
6914
|
+
const reductionFactor = totalReduction / totalPeriods;
|
|
6915
|
+
return Math.floor(reductionFactor);
|
|
6916
|
+
}
|
|
6917
|
+
function estimateExponentialReductionFactor(cliffFeeBps, targetFeeBps, totalPeriods) {
|
|
6918
|
+
if (totalPeriods <= 0) {
|
|
6919
|
+
throw new Error("Total periods must be greater than zero");
|
|
6920
|
+
}
|
|
6921
|
+
if (cliffFeeBps > feeNumeratorToBps(MAX_FEE_NUMERATOR)) {
|
|
6922
|
+
throw new Error(
|
|
6923
|
+
`Cliff fee (${cliffFeeBps} bps) exceeds maximum allowed value of ${feeNumeratorToBps(
|
|
6924
|
+
MAX_FEE_NUMERATOR
|
|
6925
|
+
)} bps`
|
|
6926
|
+
);
|
|
6927
|
+
}
|
|
6928
|
+
if (targetFeeBps > cliffFeeBps) {
|
|
6929
|
+
throw new Error(
|
|
6930
|
+
"Target fee bps must be less than or equal to cliff fee bps for reduction"
|
|
6931
|
+
);
|
|
6932
|
+
}
|
|
6933
|
+
const cliffFeeNumerator = bpsToFeeNumerator(cliffFeeBps);
|
|
6934
|
+
const targetFeeNumerator = bpsToFeeNumerator(targetFeeBps);
|
|
6935
|
+
const ratio = targetFeeNumerator / cliffFeeNumerator;
|
|
6936
|
+
const decayBase = Math.pow(ratio, 1 / totalPeriods);
|
|
6937
|
+
const reductionFactor = BASIS_POINT_MAX * (1 - decayBase);
|
|
6938
|
+
return Math.floor(reductionFactor);
|
|
6939
|
+
}
|
|
6889
6940
|
|
|
6890
6941
|
// src/helpers/computeUnits.ts
|
|
6891
6942
|
import {
|
|
@@ -7185,13 +7236,6 @@ var CpAmm = class {
|
|
|
7185
7236
|
});
|
|
7186
7237
|
this.poolAuthority = derivePoolAuthority();
|
|
7187
7238
|
}
|
|
7188
|
-
/**
|
|
7189
|
-
* Returns the Anchor program instance.
|
|
7190
|
-
* @returns The AmmProgram instance.
|
|
7191
|
-
*/
|
|
7192
|
-
getProgram() {
|
|
7193
|
-
return this._program;
|
|
7194
|
-
}
|
|
7195
7239
|
/**
|
|
7196
7240
|
* Prepares token accounts for a transaction by retrieving or creating associated token accounts.
|
|
7197
7241
|
* @private
|
|
@@ -9204,6 +9248,7 @@ export {
|
|
|
9204
9248
|
Rounding,
|
|
9205
9249
|
SCALE_OFFSET,
|
|
9206
9250
|
TradeDirection,
|
|
9251
|
+
bpsToFeeNumerator,
|
|
9207
9252
|
calculateInitSqrtPrice,
|
|
9208
9253
|
calculateTransferFeeExcludedAmount,
|
|
9209
9254
|
calculateTransferFeeIncludedAmount,
|
|
@@ -9219,6 +9264,9 @@ export {
|
|
|
9219
9264
|
deriveRewardVaultAddress,
|
|
9220
9265
|
deriveTokenBadgeAddress,
|
|
9221
9266
|
deriveTokenVaultAddress,
|
|
9267
|
+
estimateExponentialReductionFactor,
|
|
9268
|
+
estimateLinearReductionFactor,
|
|
9269
|
+
feeNumeratorToBps,
|
|
9222
9270
|
getAllPositionNftAccountByOwner,
|
|
9223
9271
|
getAllUserPositionNftAccount,
|
|
9224
9272
|
getAmountAFromLiquidityDelta,
|