@meteora-ag/cp-amm-sdk 1.0.1-rc.31 → 1.0.1-rc.33
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 +5 -9
- package/dist/index.d.ts +5 -9
- package/dist/index.js +33 -78
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -95
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -5985,16 +5985,14 @@ declare function getSwapAmount(inAmount: BN, sqrtPrice: BN, liquidity: BN, trade
|
|
|
5985
5985
|
};
|
|
5986
5986
|
|
|
5987
5987
|
declare function getNextSqrtPrice(amount: BN, sqrtPrice: BN, liquidity: BN, aToB: boolean): BN;
|
|
5988
|
-
declare function
|
|
5989
|
-
declare function getDeltaAmountB(lowerSqrtPrice: BN, upperSqrtPrice: BN, liquidity: BN, rounding: Rounding): BN;
|
|
5990
|
-
declare function getLiquidityDeltaFromAmountA(maxAmountA: BN, lowerSqrtPrice: BN, // current sqrt price
|
|
5988
|
+
declare function getLiquidityDeltaFromAmountA(amountA: BN, lowerSqrtPrice: BN, // current sqrt price
|
|
5991
5989
|
upperSqrtPrice: BN): BN;
|
|
5992
|
-
declare function getLiquidityDeltaFromAmountB(
|
|
5990
|
+
declare function getLiquidityDeltaFromAmountB(amountB: BN, lowerSqrtPrice: BN, // min sqrt price
|
|
5993
5991
|
upperSqrtPrice: BN): BN;
|
|
5994
5992
|
declare function getAmountAFromLiquidityDelta(liquidity: BN, currentSqrtPrice: BN, // current sqrt price
|
|
5995
|
-
maxSqrtPrice: BN, rounding: Rounding):
|
|
5993
|
+
maxSqrtPrice: BN, rounding: Rounding): BN;
|
|
5996
5994
|
declare function getAmountBFromLiquidityDelta(liquidity: BN, currentSqrtPrice: BN, // current sqrt price,
|
|
5997
|
-
minSqrtPrice: BN, rounding: Rounding):
|
|
5995
|
+
minSqrtPrice: BN, rounding: Rounding): BN;
|
|
5998
5996
|
|
|
5999
5997
|
declare const getSimulationComputeUnits: (connection: Connection, instructions: Array<TransactionInstruction>, payer: PublicKey, lookupTables: Array<AddressLookupTableAccount> | [], commitment?: Commitment) => Promise<number | null>;
|
|
6000
5998
|
/**
|
|
@@ -6068,8 +6066,6 @@ declare function calculateTransferFeeExcludedAmount(transferFeeIncludedAmount: B
|
|
|
6068
6066
|
declare const ONE: BN;
|
|
6069
6067
|
declare function pow(base: BN, exp: BN): BN;
|
|
6070
6068
|
|
|
6071
|
-
declare function mulShr(x: BN, y: BN, offset: number, rounding: Rounding): BN;
|
|
6072
|
-
declare function shlDiv(x: BN, y: BN, offset: number, rounding: Rounding): BN;
|
|
6073
6069
|
declare function mulDiv(x: BN, y: BN, denominator: BN, rounding: Rounding): BN;
|
|
6074
6070
|
declare function divCeil(a: BN, b: BN): BN;
|
|
6075
6071
|
declare function q64ToDecimal(num: BN, decimalPlaces?: number): Decimal;
|
|
@@ -12414,4 +12410,4 @@ var CpAmmIDL = {
|
|
|
12414
12410
|
types: types
|
|
12415
12411
|
};
|
|
12416
12412
|
|
|
12417
|
-
export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, type BuildAddLiquidityParams, type BuildRemoveAllLiquidityInstructionParams, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeInstructionParams, type ClaimPositionFeeParams, type ClaimRewardParams, type ClosePositionInstructionParams, type ClosePositionParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionParams, type DepositQuote, type DynamicFee, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetDepositQuoteParams, type GetQuoteParams, type GetWithdrawQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, LIQUIDITY_SCALE, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type MergePositionParams, ONE, PRECISION, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparePoolCreationSingleSide, type PreparedPoolCreation, type RefreshVestingParams, type RemoveAllLiquidityAndClosePositionParams, type RemoveAllLiquidityParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, type WithdrawQuote, calculateInitSqrtPrice, calculateTransferFeeExcludedAmount, calculateTransferFeeIncludedAmount, decimalToQ64, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadge, deriveTokenBadgeAddress, deriveTokenVaultAddress, divCeil, getAllUserPositionNftAccount, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getBaseFeeNumerator,
|
|
12413
|
+
export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, type BuildAddLiquidityParams, type BuildRemoveAllLiquidityInstructionParams, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeInstructionParams, type ClaimPositionFeeParams, type ClaimRewardParams, type ClosePositionInstructionParams, type ClosePositionParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionParams, type DepositQuote, type DynamicFee, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetDepositQuoteParams, type GetQuoteParams, type GetWithdrawQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, LIQUIDITY_SCALE, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type MergePositionParams, ONE, PRECISION, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparePoolCreationSingleSide, type PreparedPoolCreation, type RefreshVestingParams, type RemoveAllLiquidityAndClosePositionParams, type RemoveAllLiquidityParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, type WithdrawQuote, calculateInitSqrtPrice, calculateTransferFeeExcludedAmount, calculateTransferFeeIncludedAmount, decimalToQ64, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadge, deriveTokenBadgeAddress, deriveTokenVaultAddress, divCeil, getAllUserPositionNftAccount, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getBaseFeeNumerator, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getNftOwner, getOrCreateATAInstruction, getPriceFromSqrtPrice, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSqrtPriceFromPrice, getSwapAmount, getTokenDecimals, getTokenProgram, getUnClaimReward, mulDiv, positionByPoolFilter, pow, q64ToDecimal, unwrapSOLInstruction, vestingByPositionFilter, wrapSOLInstruction };
|
package/dist/index.d.ts
CHANGED
|
@@ -5985,16 +5985,14 @@ declare function getSwapAmount(inAmount: BN, sqrtPrice: BN, liquidity: BN, trade
|
|
|
5985
5985
|
};
|
|
5986
5986
|
|
|
5987
5987
|
declare function getNextSqrtPrice(amount: BN, sqrtPrice: BN, liquidity: BN, aToB: boolean): BN;
|
|
5988
|
-
declare function
|
|
5989
|
-
declare function getDeltaAmountB(lowerSqrtPrice: BN, upperSqrtPrice: BN, liquidity: BN, rounding: Rounding): BN;
|
|
5990
|
-
declare function getLiquidityDeltaFromAmountA(maxAmountA: BN, lowerSqrtPrice: BN, // current sqrt price
|
|
5988
|
+
declare function getLiquidityDeltaFromAmountA(amountA: BN, lowerSqrtPrice: BN, // current sqrt price
|
|
5991
5989
|
upperSqrtPrice: BN): BN;
|
|
5992
|
-
declare function getLiquidityDeltaFromAmountB(
|
|
5990
|
+
declare function getLiquidityDeltaFromAmountB(amountB: BN, lowerSqrtPrice: BN, // min sqrt price
|
|
5993
5991
|
upperSqrtPrice: BN): BN;
|
|
5994
5992
|
declare function getAmountAFromLiquidityDelta(liquidity: BN, currentSqrtPrice: BN, // current sqrt price
|
|
5995
|
-
maxSqrtPrice: BN, rounding: Rounding):
|
|
5993
|
+
maxSqrtPrice: BN, rounding: Rounding): BN;
|
|
5996
5994
|
declare function getAmountBFromLiquidityDelta(liquidity: BN, currentSqrtPrice: BN, // current sqrt price,
|
|
5997
|
-
minSqrtPrice: BN, rounding: Rounding):
|
|
5995
|
+
minSqrtPrice: BN, rounding: Rounding): BN;
|
|
5998
5996
|
|
|
5999
5997
|
declare const getSimulationComputeUnits: (connection: Connection, instructions: Array<TransactionInstruction>, payer: PublicKey, lookupTables: Array<AddressLookupTableAccount> | [], commitment?: Commitment) => Promise<number | null>;
|
|
6000
5998
|
/**
|
|
@@ -6068,8 +6066,6 @@ declare function calculateTransferFeeExcludedAmount(transferFeeIncludedAmount: B
|
|
|
6068
6066
|
declare const ONE: BN;
|
|
6069
6067
|
declare function pow(base: BN, exp: BN): BN;
|
|
6070
6068
|
|
|
6071
|
-
declare function mulShr(x: BN, y: BN, offset: number, rounding: Rounding): BN;
|
|
6072
|
-
declare function shlDiv(x: BN, y: BN, offset: number, rounding: Rounding): BN;
|
|
6073
6069
|
declare function mulDiv(x: BN, y: BN, denominator: BN, rounding: Rounding): BN;
|
|
6074
6070
|
declare function divCeil(a: BN, b: BN): BN;
|
|
6075
6071
|
declare function q64ToDecimal(num: BN, decimalPlaces?: number): Decimal;
|
|
@@ -12414,4 +12410,4 @@ var CpAmmIDL = {
|
|
|
12414
12410
|
types: types
|
|
12415
12411
|
};
|
|
12416
12412
|
|
|
12417
|
-
export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, type BuildAddLiquidityParams, type BuildRemoveAllLiquidityInstructionParams, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeInstructionParams, type ClaimPositionFeeParams, type ClaimRewardParams, type ClosePositionInstructionParams, type ClosePositionParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionParams, type DepositQuote, type DynamicFee, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetDepositQuoteParams, type GetQuoteParams, type GetWithdrawQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, LIQUIDITY_SCALE, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type MergePositionParams, ONE, PRECISION, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparePoolCreationSingleSide, type PreparedPoolCreation, type RefreshVestingParams, type RemoveAllLiquidityAndClosePositionParams, type RemoveAllLiquidityParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, type WithdrawQuote, calculateInitSqrtPrice, calculateTransferFeeExcludedAmount, calculateTransferFeeIncludedAmount, decimalToQ64, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadge, deriveTokenBadgeAddress, deriveTokenVaultAddress, divCeil, getAllUserPositionNftAccount, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getBaseFeeNumerator,
|
|
12413
|
+
export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, type BuildAddLiquidityParams, type BuildRemoveAllLiquidityInstructionParams, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeInstructionParams, type ClaimPositionFeeParams, type ClaimRewardParams, type ClosePositionInstructionParams, type ClosePositionParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionParams, type DepositQuote, type DynamicFee, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetDepositQuoteParams, type GetQuoteParams, type GetWithdrawQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, LIQUIDITY_SCALE, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type MergePositionParams, ONE, PRECISION, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparePoolCreationSingleSide, type PreparedPoolCreation, type RefreshVestingParams, type RemoveAllLiquidityAndClosePositionParams, type RemoveAllLiquidityParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, type WithdrawQuote, calculateInitSqrtPrice, calculateTransferFeeExcludedAmount, calculateTransferFeeIncludedAmount, decimalToQ64, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadge, deriveTokenBadgeAddress, deriveTokenVaultAddress, divCeil, getAllUserPositionNftAccount, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getBaseFeeNumerator, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getNftOwner, getOrCreateATAInstruction, getPriceFromSqrtPrice, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSqrtPriceFromPrice, getSwapAmount, getTokenDecimals, getTokenProgram, getUnClaimReward, mulDiv, positionByPoolFilter, pow, q64ToDecimal, unwrapSOLInstruction, vestingByPositionFilter, wrapSOLInstruction };
|
package/dist/index.js
CHANGED
|
@@ -6371,10 +6371,10 @@ var FeeSchedulerMode = /* @__PURE__ */ ((FeeSchedulerMode2) => {
|
|
|
6371
6371
|
FeeSchedulerMode2[FeeSchedulerMode2["Exponential"] = 1] = "Exponential";
|
|
6372
6372
|
return FeeSchedulerMode2;
|
|
6373
6373
|
})(FeeSchedulerMode || {});
|
|
6374
|
-
var CollectFeeMode = /* @__PURE__ */ ((
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
return
|
|
6374
|
+
var CollectFeeMode = /* @__PURE__ */ ((CollectFeeMode2) => {
|
|
6375
|
+
CollectFeeMode2[CollectFeeMode2["BothToken"] = 0] = "BothToken";
|
|
6376
|
+
CollectFeeMode2[CollectFeeMode2["OnlyB"] = 1] = "OnlyB";
|
|
6377
|
+
return CollectFeeMode2;
|
|
6378
6378
|
})(CollectFeeMode || {});
|
|
6379
6379
|
var TradeDirection = /* @__PURE__ */ ((TradeDirection2) => {
|
|
6380
6380
|
TradeDirection2[TradeDirection2["AtoB"] = 0] = "AtoB";
|
|
@@ -6745,14 +6745,6 @@ function pow(base, exp) {
|
|
|
6745
6745
|
// src/math/mathUtils.ts
|
|
6746
6746
|
|
|
6747
6747
|
var _decimaljs = require('decimal.js'); var _decimaljs2 = _interopRequireDefault(_decimaljs);
|
|
6748
|
-
function mulShr(x, y, offset, rounding) {
|
|
6749
|
-
const denominator = new (0, _anchor.BN)(1).shln(offset);
|
|
6750
|
-
return mulDiv(x, y, denominator, rounding);
|
|
6751
|
-
}
|
|
6752
|
-
function shlDiv(x, y, offset, rounding) {
|
|
6753
|
-
const scale = new (0, _anchor.BN)(1).shln(offset);
|
|
6754
|
-
return mulDiv(x, scale, y, rounding);
|
|
6755
|
-
}
|
|
6756
6748
|
function mulDiv(x, y, denominator, rounding) {
|
|
6757
6749
|
const { div, mod } = x.mul(y).divmod(denominator);
|
|
6758
6750
|
if (rounding == 0 /* Up */ && !mod.isZero()) {
|
|
@@ -6775,7 +6767,6 @@ function decimalToQ64(num) {
|
|
|
6775
6767
|
|
|
6776
6768
|
// src/helpers/curve.ts
|
|
6777
6769
|
|
|
6778
|
-
|
|
6779
6770
|
function getNextSqrtPrice(amount, sqrtPrice, liquidity, aToB) {
|
|
6780
6771
|
let result;
|
|
6781
6772
|
if (aToB) {
|
|
@@ -6788,65 +6779,35 @@ function getNextSqrtPrice(amount, sqrtPrice, liquidity, aToB) {
|
|
|
6788
6779
|
}
|
|
6789
6780
|
return result;
|
|
6790
6781
|
}
|
|
6791
|
-
function
|
|
6792
|
-
const
|
|
6793
|
-
const
|
|
6794
|
-
|
|
6795
|
-
const result = shlDiv(prod, denominator, SCALE_OFFSET, rounding);
|
|
6796
|
-
return result.shrn(SCALE_OFFSET);
|
|
6797
|
-
}
|
|
6798
|
-
function getDeltaAmountB(lowerSqrtPrice, upperSqrtPrice, liquidity, rounding) {
|
|
6799
|
-
const deltaSqrtPrice = upperSqrtPrice.sub(lowerSqrtPrice);
|
|
6800
|
-
const prod = liquidity.mul(deltaSqrtPrice);
|
|
6801
|
-
let result;
|
|
6802
|
-
if (rounding == 0 /* Up */) {
|
|
6803
|
-
const denominator = new (0, _anchor.BN)(1).shln(SCALE_OFFSET * 2);
|
|
6804
|
-
result = divCeil(prod, denominator);
|
|
6805
|
-
} else {
|
|
6806
|
-
result = prod.shrn(SCALE_OFFSET * 2);
|
|
6807
|
-
}
|
|
6808
|
-
return result;
|
|
6809
|
-
}
|
|
6810
|
-
function getLiquidityDeltaFromAmountA(maxAmountA, lowerSqrtPrice, upperSqrtPrice) {
|
|
6811
|
-
const prod = new (0, _decimaljs2.default)(
|
|
6812
|
-
maxAmountA.mul(upperSqrtPrice.mul(lowerSqrtPrice)).toString()
|
|
6813
|
-
);
|
|
6814
|
-
const delta = new (0, _decimaljs2.default)(upperSqrtPrice.sub(lowerSqrtPrice).toString());
|
|
6815
|
-
return new (0, _anchor.BN)(prod.div(delta).floor().toFixed());
|
|
6782
|
+
function getLiquidityDeltaFromAmountA(amountA, lowerSqrtPrice, upperSqrtPrice) {
|
|
6783
|
+
const product = amountA.mul(lowerSqrtPrice).mul(upperSqrtPrice);
|
|
6784
|
+
const denominator = upperSqrtPrice.sub(lowerSqrtPrice);
|
|
6785
|
+
return product.div(denominator);
|
|
6816
6786
|
}
|
|
6817
|
-
function getLiquidityDeltaFromAmountB(
|
|
6818
|
-
const denominator =
|
|
6819
|
-
|
|
6820
|
-
);
|
|
6821
|
-
const prod = new (0, _decimaljs2.default)(maxAmountB.toString()).mul(
|
|
6822
|
-
_decimaljs2.default.pow(2, SCALE_OFFSET * 2)
|
|
6823
|
-
);
|
|
6824
|
-
return new (0, _anchor.BN)(prod.div(denominator).floor().toFixed());
|
|
6787
|
+
function getLiquidityDeltaFromAmountB(amountB, lowerSqrtPrice, upperSqrtPrice) {
|
|
6788
|
+
const denominator = upperSqrtPrice.sub(lowerSqrtPrice);
|
|
6789
|
+
const product = amountB.shln(128);
|
|
6790
|
+
return product.div(denominator);
|
|
6825
6791
|
}
|
|
6826
6792
|
function getAmountAFromLiquidityDelta(liquidity, currentSqrtPrice, maxSqrtPrice, rounding) {
|
|
6827
|
-
const
|
|
6828
|
-
new (0, _decimaljs2.default)(maxSqrtPrice.sub(currentSqrtPrice).toString())
|
|
6829
|
-
);
|
|
6793
|
+
const product = liquidity.mul(maxSqrtPrice.sub(currentSqrtPrice));
|
|
6830
6794
|
const denominator = currentSqrtPrice.mul(maxSqrtPrice);
|
|
6831
|
-
const result = prod.mul(_decimaljs2.default.pow(2, 64)).div(new (0, _decimaljs2.default)(denominator.toString()));
|
|
6832
6795
|
if (rounding == 0 /* Up */) {
|
|
6833
|
-
return
|
|
6796
|
+
return product.add(denominator.sub(new (0, _anchor.BN)(1))).div(denominator);
|
|
6834
6797
|
}
|
|
6835
|
-
return
|
|
6798
|
+
return product.div(denominator);
|
|
6836
6799
|
}
|
|
6837
6800
|
function getAmountBFromLiquidityDelta(liquidity, currentSqrtPrice, minSqrtPrice, rounding) {
|
|
6838
|
-
const
|
|
6839
|
-
const
|
|
6840
|
-
|
|
6841
|
-
);
|
|
6801
|
+
const one = new (0, _anchor.BN)(1).shln(128);
|
|
6802
|
+
const deltaPrice = currentSqrtPrice.sub(minSqrtPrice);
|
|
6803
|
+
const result = liquidity.mul(deltaPrice);
|
|
6842
6804
|
if (rounding == 0 /* Up */) {
|
|
6843
|
-
return
|
|
6805
|
+
return result.add(one.sub(new (0, _anchor.BN)(1))).div(one);
|
|
6844
6806
|
}
|
|
6845
|
-
return
|
|
6807
|
+
return result.shrn(128);
|
|
6846
6808
|
}
|
|
6847
6809
|
|
|
6848
6810
|
// src/helpers/fee.ts
|
|
6849
|
-
|
|
6850
6811
|
function getBaseFeeNumerator(feeSchedulerMode, cliffFeeNumerator, period, reductionFactor) {
|
|
6851
6812
|
let feeNumerator;
|
|
6852
6813
|
if (feeSchedulerMode == 0 /* Linear */) {
|
|
@@ -6860,14 +6821,12 @@ function getBaseFeeNumerator(feeSchedulerMode, cliffFeeNumerator, period, reduct
|
|
|
6860
6821
|
return feeNumerator;
|
|
6861
6822
|
}
|
|
6862
6823
|
function getDynamicFeeNumerator(volatilityAccumulator, binStep, variableFeeControl) {
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
|
-
|
|
6866
|
-
const squareVfaBin =
|
|
6867
|
-
const vFee =
|
|
6868
|
-
return new (0, _anchor.BN)(
|
|
6869
|
-
vFee.add(99999999999).div(1e11).floor().toFixed()
|
|
6870
|
-
);
|
|
6824
|
+
if (variableFeeControl.isZero()) {
|
|
6825
|
+
return new (0, _anchor.BN)(0);
|
|
6826
|
+
}
|
|
6827
|
+
const squareVfaBin = volatilityAccumulator.mul(new (0, _anchor.BN)(binStep)).pow(new (0, _anchor.BN)(2));
|
|
6828
|
+
const vFee = variableFeeControl.mul(squareVfaBin);
|
|
6829
|
+
return vFee.add(new (0, _anchor.BN)(99999999999)).div(new (0, _anchor.BN)(1e11));
|
|
6871
6830
|
}
|
|
6872
6831
|
function getFeeNumerator(currentPoint, activationPoint, numberOfPeriod, periodFrequency, feeSchedulerMode, cliffFeeNumerator, reductionFactor, dynamicFeeParams) {
|
|
6873
6832
|
if (Number(periodFrequency) == 0) {
|
|
@@ -6918,12 +6877,12 @@ function getSwapAmount(inAmount, sqrtPrice, liquidity, tradeFeeNumerator, aToB,
|
|
|
6918
6877
|
totalFee = getTotalFeeOnAmount(inAmount, tradeFeeNumerator);
|
|
6919
6878
|
actualInAmount = inAmount.sub(totalFee);
|
|
6920
6879
|
}
|
|
6921
|
-
const outAmount = aToB ?
|
|
6880
|
+
const outAmount = aToB ? getAmountBFromLiquidityDelta(
|
|
6922
6881
|
getNextSqrtPrice(actualInAmount, sqrtPrice, liquidity, true),
|
|
6923
6882
|
sqrtPrice,
|
|
6924
6883
|
liquidity,
|
|
6925
6884
|
1 /* Down */
|
|
6926
|
-
) :
|
|
6885
|
+
) : getAmountBFromLiquidityDelta(
|
|
6927
6886
|
sqrtPrice,
|
|
6928
6887
|
getNextSqrtPrice(actualInAmount, sqrtPrice, liquidity, false),
|
|
6929
6888
|
liquidity,
|
|
@@ -7755,15 +7714,15 @@ var CpAmm = class {
|
|
|
7755
7714
|
return {
|
|
7756
7715
|
liquidityDelta,
|
|
7757
7716
|
outAmountA: tokenATokenInfo ? calculateTransferFeeExcludedAmount(
|
|
7758
|
-
|
|
7717
|
+
amountA,
|
|
7759
7718
|
tokenATokenInfo.mint,
|
|
7760
7719
|
tokenATokenInfo.currentEpoch
|
|
7761
|
-
).amount :
|
|
7720
|
+
).amount : amountA,
|
|
7762
7721
|
outAmountB: tokenBTokenInfo ? calculateTransferFeeExcludedAmount(
|
|
7763
|
-
|
|
7722
|
+
amountB,
|
|
7764
7723
|
tokenBTokenInfo.mint,
|
|
7765
7724
|
tokenBTokenInfo.currentEpoch
|
|
7766
|
-
).amount :
|
|
7725
|
+
).amount : amountB
|
|
7767
7726
|
};
|
|
7768
7727
|
});
|
|
7769
7728
|
}
|
|
@@ -8994,9 +8953,5 @@ var index_default = cp_amm_default;
|
|
|
8994
8953
|
|
|
8995
8954
|
|
|
8996
8955
|
|
|
8997
|
-
|
|
8998
|
-
|
|
8999
|
-
|
|
9000
|
-
|
|
9001
|
-
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.LIQUIDITY_SCALE = LIQUIDITY_SCALE; 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.ONE = ONE; exports.PRECISION = PRECISION; exports.Rounding = Rounding; exports.SCALE_OFFSET = SCALE_OFFSET; exports.TradeDirection = TradeDirection; exports.calculateInitSqrtPrice = calculateInitSqrtPrice; exports.calculateTransferFeeExcludedAmount = calculateTransferFeeExcludedAmount; exports.calculateTransferFeeIncludedAmount = calculateTransferFeeIncludedAmount; exports.decimalToQ64 = decimalToQ64; exports.default = index_default; exports.deriveClaimFeeOperatorAddress = deriveClaimFeeOperatorAddress; exports.deriveConfigAddress = deriveConfigAddress; exports.deriveCustomizablePoolAddress = deriveCustomizablePoolAddress; exports.derivePoolAddress = derivePoolAddress; exports.derivePoolAuthority = derivePoolAuthority; exports.derivePositionAddress = derivePositionAddress; exports.derivePositionNftAccount = derivePositionNftAccount; exports.deriveRewardVaultAddress = deriveRewardVaultAddress; exports.deriveTokenBadge = deriveTokenBadge; exports.deriveTokenBadgeAddress = deriveTokenBadgeAddress; exports.deriveTokenVaultAddress = deriveTokenVaultAddress; exports.divCeil = divCeil; exports.getAllUserPositionNftAccount = getAllUserPositionNftAccount; exports.getAmountAFromLiquidityDelta = getAmountAFromLiquidityDelta; exports.getAmountBFromLiquidityDelta = getAmountBFromLiquidityDelta; exports.getBaseFeeNumerator = getBaseFeeNumerator; 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.getPriceFromSqrtPrice = getPriceFromSqrtPrice; exports.getPriceImpact = getPriceImpact; exports.getSecondKey = getSecondKey; exports.getSimulationComputeUnits = getSimulationComputeUnits; exports.getSqrtPriceFromPrice = getSqrtPriceFromPrice; exports.getSwapAmount = getSwapAmount; exports.getTokenDecimals = getTokenDecimals; exports.getTokenProgram = getTokenProgram; exports.getUnClaimReward = getUnClaimReward; exports.mulDiv = mulDiv; exports.mulShr = mulShr; exports.positionByPoolFilter = positionByPoolFilter; exports.pow = pow; exports.q64ToDecimal = q64ToDecimal; exports.shlDiv = shlDiv; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.vestingByPositionFilter = vestingByPositionFilter; exports.wrapSOLInstruction = wrapSOLInstruction;
|
|
8956
|
+
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.LIQUIDITY_SCALE = LIQUIDITY_SCALE; 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.ONE = ONE; exports.PRECISION = PRECISION; exports.Rounding = Rounding; exports.SCALE_OFFSET = SCALE_OFFSET; exports.TradeDirection = TradeDirection; exports.calculateInitSqrtPrice = calculateInitSqrtPrice; exports.calculateTransferFeeExcludedAmount = calculateTransferFeeExcludedAmount; exports.calculateTransferFeeIncludedAmount = calculateTransferFeeIncludedAmount; exports.decimalToQ64 = decimalToQ64; exports.default = index_default; exports.deriveClaimFeeOperatorAddress = deriveClaimFeeOperatorAddress; exports.deriveConfigAddress = deriveConfigAddress; exports.deriveCustomizablePoolAddress = deriveCustomizablePoolAddress; exports.derivePoolAddress = derivePoolAddress; exports.derivePoolAuthority = derivePoolAuthority; exports.derivePositionAddress = derivePositionAddress; exports.derivePositionNftAccount = derivePositionNftAccount; exports.deriveRewardVaultAddress = deriveRewardVaultAddress; exports.deriveTokenBadge = deriveTokenBadge; exports.deriveTokenBadgeAddress = deriveTokenBadgeAddress; exports.deriveTokenVaultAddress = deriveTokenVaultAddress; exports.divCeil = divCeil; exports.getAllUserPositionNftAccount = getAllUserPositionNftAccount; exports.getAmountAFromLiquidityDelta = getAmountAFromLiquidityDelta; exports.getAmountBFromLiquidityDelta = getAmountBFromLiquidityDelta; exports.getBaseFeeNumerator = getBaseFeeNumerator; 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.getPriceFromSqrtPrice = getPriceFromSqrtPrice; exports.getPriceImpact = getPriceImpact; exports.getSecondKey = getSecondKey; exports.getSimulationComputeUnits = getSimulationComputeUnits; exports.getSqrtPriceFromPrice = getSqrtPriceFromPrice; exports.getSwapAmount = getSwapAmount; exports.getTokenDecimals = getTokenDecimals; exports.getTokenProgram = getTokenProgram; exports.getUnClaimReward = getUnClaimReward; exports.mulDiv = mulDiv; exports.positionByPoolFilter = positionByPoolFilter; exports.pow = pow; exports.q64ToDecimal = q64ToDecimal; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.vestingByPositionFilter = vestingByPositionFilter; exports.wrapSOLInstruction = wrapSOLInstruction;
|
|
9002
8957
|
//# sourceMappingURL=index.js.map
|