@meteora-ag/cp-amm-sdk 1.1.0 → 1.1.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.d.mts +25 -8
- package/dist/index.d.ts +25 -8
- package/dist/index.js +61 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +41 -40
package/dist/index.d.mts
CHANGED
|
@@ -5893,6 +5893,8 @@ type GetQuoteParams = {
|
|
|
5893
5893
|
mint: Mint;
|
|
5894
5894
|
currentEpoch: number;
|
|
5895
5895
|
};
|
|
5896
|
+
tokenADecimal: number;
|
|
5897
|
+
tokenBDecimal: number;
|
|
5896
5898
|
};
|
|
5897
5899
|
type SwapAmount = {
|
|
5898
5900
|
outputAmount: BN;
|
|
@@ -5913,6 +5915,8 @@ type GetQuoteExactOutParams = {
|
|
|
5913
5915
|
mint: Mint;
|
|
5914
5916
|
currentEpoch: number;
|
|
5915
5917
|
};
|
|
5918
|
+
tokenADecimal: number;
|
|
5919
|
+
tokenBDecimal: number;
|
|
5916
5920
|
};
|
|
5917
5921
|
type SwapResult = {
|
|
5918
5922
|
outputAmount: BN;
|
|
@@ -6354,7 +6358,7 @@ declare class CpAmm {
|
|
|
6354
6358
|
swapOutAmount: BN;
|
|
6355
6359
|
minSwapOutAmount: BN;
|
|
6356
6360
|
totalFee: BN;
|
|
6357
|
-
priceImpact:
|
|
6361
|
+
priceImpact: Decimal;
|
|
6358
6362
|
};
|
|
6359
6363
|
/**
|
|
6360
6364
|
* Calculates swap quote based on desired output amount and pool state.
|
|
@@ -6557,8 +6561,8 @@ declare class CpAmm {
|
|
|
6557
6561
|
splitPosition(params: SplitPositionParams): TxBuilder;
|
|
6558
6562
|
}
|
|
6559
6563
|
|
|
6560
|
-
declare function getFirstKey(key1: PublicKey, key2: PublicKey): Buffer
|
|
6561
|
-
declare function getSecondKey(key1: PublicKey, key2: PublicKey): Buffer
|
|
6564
|
+
declare function getFirstKey(key1: PublicKey, key2: PublicKey): Buffer<ArrayBufferLike>;
|
|
6565
|
+
declare function getSecondKey(key1: PublicKey, key2: PublicKey): Buffer<ArrayBufferLike>;
|
|
6562
6566
|
declare function derivePoolAuthority(): PublicKey;
|
|
6563
6567
|
declare function deriveConfigAddress(index: BN): PublicKey;
|
|
6564
6568
|
declare function derivePoolAddress(config: PublicKey, tokenAMint: PublicKey, tokenBMint: PublicKey): PublicKey;
|
|
@@ -6604,7 +6608,7 @@ declare function getAllPositionNftAccountByOwner(connection: Connection, user: P
|
|
|
6604
6608
|
positionNftAccount: PublicKey;
|
|
6605
6609
|
}>>;
|
|
6606
6610
|
|
|
6607
|
-
declare function getBaseFeeNumerator(feeSchedulerMode: FeeSchedulerMode, cliffFeeNumerator: BN, period: BN, reductionFactor: BN): BN;
|
|
6611
|
+
declare function getBaseFeeNumerator(feeSchedulerMode: FeeSchedulerMode, cliffFeeNumerator: BN, period: BN, reductionFactor: BN, periodFrequency: BN): BN;
|
|
6608
6612
|
/**
|
|
6609
6613
|
* Calculates the dynamic fee numerator based on market volatility metrics
|
|
6610
6614
|
*
|
|
@@ -6780,12 +6784,25 @@ declare const getMaxAmountWithSlippage: (amount: BN, rate: number) => BN;
|
|
|
6780
6784
|
declare const getMinAmountWithSlippage: (amount: BN, rate: number) => BN;
|
|
6781
6785
|
/**
|
|
6782
6786
|
* Calculate price impact as a percentage
|
|
6787
|
+
* Price impact measures how much worse the user's execution was compared to the current market price
|
|
6788
|
+
* @param amountIn - Input amount (in base units)
|
|
6789
|
+
* @param amountOut - Output amount (in base units)
|
|
6790
|
+
* @param currentSqrtPrice - Current pool sqrt price (spot price)
|
|
6791
|
+
* @param aToB - Direction of swap: true for token A to token B, false for token B to token A
|
|
6792
|
+
* @param tokenADecimal - Decimal places for token A
|
|
6793
|
+
* @param tokenBDecimal - Decimal places for token B
|
|
6794
|
+
* @returns Price impact as a percentage (e.g., 1.5 means 1.5% worse than spot price)
|
|
6795
|
+
*/
|
|
6796
|
+
declare const getPriceImpact: (amountIn: BN, amountOut: BN, currentSqrtPrice: BN, aToB: boolean, tokenADecimal: number, tokenBDecimal: number) => Decimal;
|
|
6797
|
+
/**
|
|
6798
|
+
* Calculate price change as a percentage (old implementation)
|
|
6799
|
+
* This measures the percentage change in pool price after a swap
|
|
6783
6800
|
* @param nextSqrtPrice sqrt price after swap
|
|
6784
6801
|
* @param currentSqrtPrice current pool sqrt price
|
|
6785
|
-
* @returns Price
|
|
6802
|
+
* @returns Price change as a percentage (e.g., 1.5 means 1.5% change)
|
|
6786
6803
|
*/
|
|
6787
|
-
declare const
|
|
6788
|
-
declare const getPriceFromSqrtPrice: (sqrtPrice: BN, tokenADecimal: number, tokenBDecimal: number) =>
|
|
6804
|
+
declare const getPriceChange: (nextSqrtPrice: BN, currentSqrtPrice: BN) => number;
|
|
6805
|
+
declare const getPriceFromSqrtPrice: (sqrtPrice: BN, tokenADecimal: number, tokenBDecimal: number) => Decimal;
|
|
6789
6806
|
declare const getSqrtPriceFromPrice: (price: string, tokenADecimal: number, tokenBDecimal: number) => BN;
|
|
6790
6807
|
declare const getUnClaimReward: (poolState: PoolState, positionState: PositionState) => {
|
|
6791
6808
|
feeTokenA: BN;
|
|
@@ -13747,4 +13764,4 @@ var CpAmmIDL = {
|
|
|
13747
13764
|
types: types
|
|
13748
13765
|
};
|
|
13749
13766
|
|
|
13750
|
-
export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, BIN_STEP_BPS_DEFAULT, BIN_STEP_BPS_U128_DEFAULT, type BaseFee, type BuildAddLiquidityParams, type BuildLiquidatePositionInstructionParams, type BuildRemoveAllLiquidityInstructionParams, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeInstructionParams, type ClaimPositionFeeParams, type ClaimPositionFeeParams2, type ClaimRewardParams, type ClosePositionInstructionParams, type ClosePositionParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionAndAddLiquidity, type CreatePositionParams, DYNAMIC_FEE_DECAY_PERIOD_DEFAULT, DYNAMIC_FEE_FILTER_PERIOD_DEFAULT, DYNAMIC_FEE_REDUCTION_FACTOR_DEFAULT, type DepositQuote, type DynamicFee, type DynamicFeeParams, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetDepositQuoteParams, type GetQuoteExactOutParams, type GetQuoteParams, type GetWithdrawQuoteParams, type InitializeCustomizeablePoolParams, type InitializeCustomizeablePoolWithDynamicConfigParams, type InitializeRewardParams, LIQUIDITY_SCALE, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_PRICE_CHANGE_BPS_DEFAULT, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type MergePositionParams, ONE, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PrepareCustomizablePoolParams, type PreparePoolCreationParams, type PreparePoolCreationSingleSide, type PrepareTokenAccountParams, type PreparedPoolCreation, type QuoteExactOutResult, type RefreshVestingParams, type RemoveAllLiquidityAndClosePositionParams, type RemoveAllLiquidityParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SetupFeeClaimAccountsParams, type SplitPositionParams, type SwapAmount, type SwapParams, type SwapQuotes, type SwapResult, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, type WithdrawQuote, bpsToFeeNumerator, calculateInitSqrtPrice, calculateTransferFeeExcludedAmount, calculateTransferFeeIncludedAmount, decimalToQ64, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, feeNumeratorToBps, getAllPositionNftAccountByOwner, getAllUserPositionNftAccount, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getAvailableVestingLiquidity, getBaseFeeNumerator, getBaseFeeParams, getDynamicFeeNumerator, getDynamicFeeParams, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getExcludedFeeAmount, getFeeMode, getFeeNumerator, getFirstKey, getIncludedFeeAmount, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getNextSqrtPriceFromAmountARoundingDown, getNextSqrtPriceFromAmountBRoundingUp, getNextSqrtPriceFromOutput, getOrCreateATAInstruction, getPriceFromSqrtPrice, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSqrtPriceFromPrice, getSwapAmount, getSwapResultFromOutAmount, getTokenDecimals, getTokenProgram, getTotalLockedLiquidity, getUnClaimReward, isVestingComplete, mulDiv, positionByPoolFilter, pow, q64ToDecimal, unwrapSOLInstruction, vestingByPositionFilter, wrapSOLInstruction };
|
|
13767
|
+
export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, BIN_STEP_BPS_DEFAULT, BIN_STEP_BPS_U128_DEFAULT, type BaseFee, type BuildAddLiquidityParams, type BuildLiquidatePositionInstructionParams, type BuildRemoveAllLiquidityInstructionParams, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeInstructionParams, type ClaimPositionFeeParams, type ClaimPositionFeeParams2, type ClaimRewardParams, type ClosePositionInstructionParams, type ClosePositionParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionAndAddLiquidity, type CreatePositionParams, DYNAMIC_FEE_DECAY_PERIOD_DEFAULT, DYNAMIC_FEE_FILTER_PERIOD_DEFAULT, DYNAMIC_FEE_REDUCTION_FACTOR_DEFAULT, type DepositQuote, type DynamicFee, type DynamicFeeParams, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetDepositQuoteParams, type GetQuoteExactOutParams, type GetQuoteParams, type GetWithdrawQuoteParams, type InitializeCustomizeablePoolParams, type InitializeCustomizeablePoolWithDynamicConfigParams, type InitializeRewardParams, LIQUIDITY_SCALE, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_PRICE_CHANGE_BPS_DEFAULT, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type MergePositionParams, ONE, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PrepareCustomizablePoolParams, type PreparePoolCreationParams, type PreparePoolCreationSingleSide, type PrepareTokenAccountParams, type PreparedPoolCreation, type QuoteExactOutResult, type RefreshVestingParams, type RemoveAllLiquidityAndClosePositionParams, type RemoveAllLiquidityParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SetupFeeClaimAccountsParams, type SplitPositionParams, type SwapAmount, type SwapParams, type SwapQuotes, type SwapResult, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, type WithdrawQuote, bpsToFeeNumerator, calculateInitSqrtPrice, calculateTransferFeeExcludedAmount, calculateTransferFeeIncludedAmount, decimalToQ64, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, feeNumeratorToBps, getAllPositionNftAccountByOwner, getAllUserPositionNftAccount, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getAvailableVestingLiquidity, getBaseFeeNumerator, getBaseFeeParams, getDynamicFeeNumerator, getDynamicFeeParams, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getExcludedFeeAmount, getFeeMode, getFeeNumerator, getFirstKey, getIncludedFeeAmount, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getNextSqrtPriceFromAmountARoundingDown, getNextSqrtPriceFromAmountBRoundingUp, getNextSqrtPriceFromOutput, getOrCreateATAInstruction, getPriceChange, getPriceFromSqrtPrice, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSqrtPriceFromPrice, getSwapAmount, getSwapResultFromOutAmount, getTokenDecimals, getTokenProgram, getTotalLockedLiquidity, getUnClaimReward, isVestingComplete, mulDiv, positionByPoolFilter, pow, q64ToDecimal, unwrapSOLInstruction, vestingByPositionFilter, wrapSOLInstruction };
|
package/dist/index.d.ts
CHANGED
|
@@ -5893,6 +5893,8 @@ type GetQuoteParams = {
|
|
|
5893
5893
|
mint: Mint;
|
|
5894
5894
|
currentEpoch: number;
|
|
5895
5895
|
};
|
|
5896
|
+
tokenADecimal: number;
|
|
5897
|
+
tokenBDecimal: number;
|
|
5896
5898
|
};
|
|
5897
5899
|
type SwapAmount = {
|
|
5898
5900
|
outputAmount: BN;
|
|
@@ -5913,6 +5915,8 @@ type GetQuoteExactOutParams = {
|
|
|
5913
5915
|
mint: Mint;
|
|
5914
5916
|
currentEpoch: number;
|
|
5915
5917
|
};
|
|
5918
|
+
tokenADecimal: number;
|
|
5919
|
+
tokenBDecimal: number;
|
|
5916
5920
|
};
|
|
5917
5921
|
type SwapResult = {
|
|
5918
5922
|
outputAmount: BN;
|
|
@@ -6354,7 +6358,7 @@ declare class CpAmm {
|
|
|
6354
6358
|
swapOutAmount: BN;
|
|
6355
6359
|
minSwapOutAmount: BN;
|
|
6356
6360
|
totalFee: BN;
|
|
6357
|
-
priceImpact:
|
|
6361
|
+
priceImpact: Decimal;
|
|
6358
6362
|
};
|
|
6359
6363
|
/**
|
|
6360
6364
|
* Calculates swap quote based on desired output amount and pool state.
|
|
@@ -6557,8 +6561,8 @@ declare class CpAmm {
|
|
|
6557
6561
|
splitPosition(params: SplitPositionParams): TxBuilder;
|
|
6558
6562
|
}
|
|
6559
6563
|
|
|
6560
|
-
declare function getFirstKey(key1: PublicKey, key2: PublicKey): Buffer
|
|
6561
|
-
declare function getSecondKey(key1: PublicKey, key2: PublicKey): Buffer
|
|
6564
|
+
declare function getFirstKey(key1: PublicKey, key2: PublicKey): Buffer<ArrayBufferLike>;
|
|
6565
|
+
declare function getSecondKey(key1: PublicKey, key2: PublicKey): Buffer<ArrayBufferLike>;
|
|
6562
6566
|
declare function derivePoolAuthority(): PublicKey;
|
|
6563
6567
|
declare function deriveConfigAddress(index: BN): PublicKey;
|
|
6564
6568
|
declare function derivePoolAddress(config: PublicKey, tokenAMint: PublicKey, tokenBMint: PublicKey): PublicKey;
|
|
@@ -6604,7 +6608,7 @@ declare function getAllPositionNftAccountByOwner(connection: Connection, user: P
|
|
|
6604
6608
|
positionNftAccount: PublicKey;
|
|
6605
6609
|
}>>;
|
|
6606
6610
|
|
|
6607
|
-
declare function getBaseFeeNumerator(feeSchedulerMode: FeeSchedulerMode, cliffFeeNumerator: BN, period: BN, reductionFactor: BN): BN;
|
|
6611
|
+
declare function getBaseFeeNumerator(feeSchedulerMode: FeeSchedulerMode, cliffFeeNumerator: BN, period: BN, reductionFactor: BN, periodFrequency: BN): BN;
|
|
6608
6612
|
/**
|
|
6609
6613
|
* Calculates the dynamic fee numerator based on market volatility metrics
|
|
6610
6614
|
*
|
|
@@ -6780,12 +6784,25 @@ declare const getMaxAmountWithSlippage: (amount: BN, rate: number) => BN;
|
|
|
6780
6784
|
declare const getMinAmountWithSlippage: (amount: BN, rate: number) => BN;
|
|
6781
6785
|
/**
|
|
6782
6786
|
* Calculate price impact as a percentage
|
|
6787
|
+
* Price impact measures how much worse the user's execution was compared to the current market price
|
|
6788
|
+
* @param amountIn - Input amount (in base units)
|
|
6789
|
+
* @param amountOut - Output amount (in base units)
|
|
6790
|
+
* @param currentSqrtPrice - Current pool sqrt price (spot price)
|
|
6791
|
+
* @param aToB - Direction of swap: true for token A to token B, false for token B to token A
|
|
6792
|
+
* @param tokenADecimal - Decimal places for token A
|
|
6793
|
+
* @param tokenBDecimal - Decimal places for token B
|
|
6794
|
+
* @returns Price impact as a percentage (e.g., 1.5 means 1.5% worse than spot price)
|
|
6795
|
+
*/
|
|
6796
|
+
declare const getPriceImpact: (amountIn: BN, amountOut: BN, currentSqrtPrice: BN, aToB: boolean, tokenADecimal: number, tokenBDecimal: number) => Decimal;
|
|
6797
|
+
/**
|
|
6798
|
+
* Calculate price change as a percentage (old implementation)
|
|
6799
|
+
* This measures the percentage change in pool price after a swap
|
|
6783
6800
|
* @param nextSqrtPrice sqrt price after swap
|
|
6784
6801
|
* @param currentSqrtPrice current pool sqrt price
|
|
6785
|
-
* @returns Price
|
|
6802
|
+
* @returns Price change as a percentage (e.g., 1.5 means 1.5% change)
|
|
6786
6803
|
*/
|
|
6787
|
-
declare const
|
|
6788
|
-
declare const getPriceFromSqrtPrice: (sqrtPrice: BN, tokenADecimal: number, tokenBDecimal: number) =>
|
|
6804
|
+
declare const getPriceChange: (nextSqrtPrice: BN, currentSqrtPrice: BN) => number;
|
|
6805
|
+
declare const getPriceFromSqrtPrice: (sqrtPrice: BN, tokenADecimal: number, tokenBDecimal: number) => Decimal;
|
|
6789
6806
|
declare const getSqrtPriceFromPrice: (price: string, tokenADecimal: number, tokenBDecimal: number) => BN;
|
|
6790
6807
|
declare const getUnClaimReward: (poolState: PoolState, positionState: PositionState) => {
|
|
6791
6808
|
feeTokenA: BN;
|
|
@@ -13747,4 +13764,4 @@ var CpAmmIDL = {
|
|
|
13747
13764
|
types: types
|
|
13748
13765
|
};
|
|
13749
13766
|
|
|
13750
|
-
export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, BIN_STEP_BPS_DEFAULT, BIN_STEP_BPS_U128_DEFAULT, type BaseFee, type BuildAddLiquidityParams, type BuildLiquidatePositionInstructionParams, type BuildRemoveAllLiquidityInstructionParams, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeInstructionParams, type ClaimPositionFeeParams, type ClaimPositionFeeParams2, type ClaimRewardParams, type ClosePositionInstructionParams, type ClosePositionParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionAndAddLiquidity, type CreatePositionParams, DYNAMIC_FEE_DECAY_PERIOD_DEFAULT, DYNAMIC_FEE_FILTER_PERIOD_DEFAULT, DYNAMIC_FEE_REDUCTION_FACTOR_DEFAULT, type DepositQuote, type DynamicFee, type DynamicFeeParams, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetDepositQuoteParams, type GetQuoteExactOutParams, type GetQuoteParams, type GetWithdrawQuoteParams, type InitializeCustomizeablePoolParams, type InitializeCustomizeablePoolWithDynamicConfigParams, type InitializeRewardParams, LIQUIDITY_SCALE, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_PRICE_CHANGE_BPS_DEFAULT, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type MergePositionParams, ONE, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PrepareCustomizablePoolParams, type PreparePoolCreationParams, type PreparePoolCreationSingleSide, type PrepareTokenAccountParams, type PreparedPoolCreation, type QuoteExactOutResult, type RefreshVestingParams, type RemoveAllLiquidityAndClosePositionParams, type RemoveAllLiquidityParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SetupFeeClaimAccountsParams, type SplitPositionParams, type SwapAmount, type SwapParams, type SwapQuotes, type SwapResult, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, type WithdrawQuote, bpsToFeeNumerator, calculateInitSqrtPrice, calculateTransferFeeExcludedAmount, calculateTransferFeeIncludedAmount, decimalToQ64, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, feeNumeratorToBps, getAllPositionNftAccountByOwner, getAllUserPositionNftAccount, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getAvailableVestingLiquidity, getBaseFeeNumerator, getBaseFeeParams, getDynamicFeeNumerator, getDynamicFeeParams, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getExcludedFeeAmount, getFeeMode, getFeeNumerator, getFirstKey, getIncludedFeeAmount, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getNextSqrtPriceFromAmountARoundingDown, getNextSqrtPriceFromAmountBRoundingUp, getNextSqrtPriceFromOutput, getOrCreateATAInstruction, getPriceFromSqrtPrice, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSqrtPriceFromPrice, getSwapAmount, getSwapResultFromOutAmount, getTokenDecimals, getTokenProgram, getTotalLockedLiquidity, getUnClaimReward, isVestingComplete, mulDiv, positionByPoolFilter, pow, q64ToDecimal, unwrapSOLInstruction, vestingByPositionFilter, wrapSOLInstruction };
|
|
13767
|
+
export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, BIN_STEP_BPS_DEFAULT, BIN_STEP_BPS_U128_DEFAULT, type BaseFee, type BuildAddLiquidityParams, type BuildLiquidatePositionInstructionParams, type BuildRemoveAllLiquidityInstructionParams, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeInstructionParams, type ClaimPositionFeeParams, type ClaimPositionFeeParams2, type ClaimRewardParams, type ClosePositionInstructionParams, type ClosePositionParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionAndAddLiquidity, type CreatePositionParams, DYNAMIC_FEE_DECAY_PERIOD_DEFAULT, DYNAMIC_FEE_FILTER_PERIOD_DEFAULT, DYNAMIC_FEE_REDUCTION_FACTOR_DEFAULT, type DepositQuote, type DynamicFee, type DynamicFeeParams, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetDepositQuoteParams, type GetQuoteExactOutParams, type GetQuoteParams, type GetWithdrawQuoteParams, type InitializeCustomizeablePoolParams, type InitializeCustomizeablePoolWithDynamicConfigParams, type InitializeRewardParams, LIQUIDITY_SCALE, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_PRICE_CHANGE_BPS_DEFAULT, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type MergePositionParams, ONE, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PrepareCustomizablePoolParams, type PreparePoolCreationParams, type PreparePoolCreationSingleSide, type PrepareTokenAccountParams, type PreparedPoolCreation, type QuoteExactOutResult, type RefreshVestingParams, type RemoveAllLiquidityAndClosePositionParams, type RemoveAllLiquidityParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SetupFeeClaimAccountsParams, type SplitPositionParams, type SwapAmount, type SwapParams, type SwapQuotes, type SwapResult, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, type WithdrawQuote, bpsToFeeNumerator, calculateInitSqrtPrice, calculateTransferFeeExcludedAmount, calculateTransferFeeIncludedAmount, decimalToQ64, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, feeNumeratorToBps, getAllPositionNftAccountByOwner, getAllUserPositionNftAccount, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getAvailableVestingLiquidity, getBaseFeeNumerator, getBaseFeeParams, getDynamicFeeNumerator, getDynamicFeeParams, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getExcludedFeeAmount, getFeeMode, getFeeNumerator, getFirstKey, getIncludedFeeAmount, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getNextSqrtPriceFromAmountARoundingDown, getNextSqrtPriceFromAmountBRoundingUp, getNextSqrtPriceFromOutput, getOrCreateATAInstruction, getPriceChange, getPriceFromSqrtPrice, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSqrtPriceFromPrice, getSwapAmount, getSwapResultFromOutAmount, getTokenDecimals, getTokenProgram, getTotalLockedLiquidity, getUnClaimReward, isVestingComplete, mulDiv, positionByPoolFilter, pow, q64ToDecimal, unwrapSOLInstruction, vestingByPositionFilter, wrapSOLInstruction };
|
package/dist/index.js
CHANGED
|
@@ -7091,10 +7091,10 @@ var _bytes = require('@coral-xyz/anchor/dist/cjs/utils/bytes');
|
|
|
7091
7091
|
function getTokenProgram(flag) {
|
|
7092
7092
|
return flag == 0 ? _spltoken.TOKEN_PROGRAM_ID : _spltoken.TOKEN_2022_PROGRAM_ID;
|
|
7093
7093
|
}
|
|
7094
|
-
var getTokenDecimals = (connection, mint) => __async(
|
|
7094
|
+
var getTokenDecimals = (connection, mint) => __async(void 0, null, function* () {
|
|
7095
7095
|
return (yield _spltoken.getMint.call(void 0, connection, mint)).decimals;
|
|
7096
7096
|
});
|
|
7097
|
-
var getOrCreateATAInstruction = (_0, _1, _2, ..._3) => __async(
|
|
7097
|
+
var getOrCreateATAInstruction = (_0, _1, _2, ..._3) => __async(void 0, [_0, _1, _2, ..._3], function* (connection, tokenMint, owner, payer = owner, allowOwnerOffCurve = true, tokenProgram) {
|
|
7098
7098
|
const toAccount = _spltoken.getAssociatedTokenAddressSync.call(void 0,
|
|
7099
7099
|
tokenMint,
|
|
7100
7100
|
owner,
|
|
@@ -7140,7 +7140,7 @@ var wrapSOLInstruction = (from, to, amount) => {
|
|
|
7140
7140
|
})
|
|
7141
7141
|
];
|
|
7142
7142
|
};
|
|
7143
|
-
var unwrapSOLInstruction = (_0, ..._1) => __async(
|
|
7143
|
+
var unwrapSOLInstruction = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (owner, receiver = owner, allowOwnerOffCurve = true) {
|
|
7144
7144
|
const wSolATAAccount = _spltoken.getAssociatedTokenAddressSync.call(void 0,
|
|
7145
7145
|
_spltoken.NATIVE_MINT,
|
|
7146
7146
|
owner,
|
|
@@ -7419,7 +7419,10 @@ function getNextSqrtPriceFromOutput(sqrtPrice, liquidity, outAmount, isB) {
|
|
|
7419
7419
|
|
|
7420
7420
|
// src/helpers/fee.ts
|
|
7421
7421
|
|
|
7422
|
-
function getBaseFeeNumerator(feeSchedulerMode, cliffFeeNumerator, period, reductionFactor) {
|
|
7422
|
+
function getBaseFeeNumerator(feeSchedulerMode, cliffFeeNumerator, period, reductionFactor, periodFrequency) {
|
|
7423
|
+
if (periodFrequency.eq(new (0, _anchor.BN)(0)) || period.eq(new (0, _anchor.BN)(0))) {
|
|
7424
|
+
return cliffFeeNumerator;
|
|
7425
|
+
}
|
|
7423
7426
|
let feeNumerator;
|
|
7424
7427
|
if (feeSchedulerMode == 0 /* Linear */) {
|
|
7425
7428
|
feeNumerator = cliffFeeNumerator.sub(period.mul(reductionFactor));
|
|
@@ -7451,7 +7454,8 @@ function getFeeNumerator(currentPoint, activationPoint, numberOfPeriod, periodFr
|
|
|
7451
7454
|
feeSchedulerMode,
|
|
7452
7455
|
cliffFeeNumerator,
|
|
7453
7456
|
period,
|
|
7454
|
-
reductionFactor
|
|
7457
|
+
reductionFactor,
|
|
7458
|
+
periodFrequency
|
|
7455
7459
|
);
|
|
7456
7460
|
if (dynamicFeeParams) {
|
|
7457
7461
|
const { volatilityAccumulator, binStep, variableFeeControl } = dynamicFeeParams;
|
|
@@ -7770,7 +7774,7 @@ function getSwapResultFromOutAmount(pool, outAmount, feeMode, tradeDirection, cu
|
|
|
7770
7774
|
|
|
7771
7775
|
|
|
7772
7776
|
|
|
7773
|
-
var getSimulationComputeUnits = (connection, instructions, payer, lookupTables, commitment = "confirmed") => __async(
|
|
7777
|
+
var getSimulationComputeUnits = (connection, instructions, payer, lookupTables, commitment = "confirmed") => __async(void 0, null, function* () {
|
|
7774
7778
|
var _a, _b, _c;
|
|
7775
7779
|
const testInstructions = [
|
|
7776
7780
|
// Set an arbitrarily high number in simulation
|
|
@@ -7802,7 +7806,7 @@ var getSimulationComputeUnits = (connection, instructions, payer, lookupTables,
|
|
|
7802
7806
|
}
|
|
7803
7807
|
return rpcResponse.value.unitsConsumed || null;
|
|
7804
7808
|
});
|
|
7805
|
-
var getEstimatedComputeUnitUsageWithBuffer = (connection, instructions, feePayer, buffer) => __async(
|
|
7809
|
+
var getEstimatedComputeUnitUsageWithBuffer = (connection, instructions, feePayer, buffer) => __async(void 0, null, function* () {
|
|
7806
7810
|
if (!buffer) {
|
|
7807
7811
|
buffer = 0.1;
|
|
7808
7812
|
}
|
|
@@ -7825,7 +7829,7 @@ var getEstimatedComputeUnitUsageWithBuffer = (connection, instructions, feePayer
|
|
|
7825
7829
|
}
|
|
7826
7830
|
return estimatedComputeUnitUsage + extraComputeUnitBuffer;
|
|
7827
7831
|
});
|
|
7828
|
-
var getEstimatedComputeUnitIxWithBuffer = (connection, instructions, feePayer, buffer) => __async(
|
|
7832
|
+
var getEstimatedComputeUnitIxWithBuffer = (connection, instructions, feePayer, buffer) => __async(void 0, null, function* () {
|
|
7829
7833
|
const units = yield getEstimatedComputeUnitUsageWithBuffer(
|
|
7830
7834
|
connection,
|
|
7831
7835
|
instructions,
|
|
@@ -7849,13 +7853,41 @@ var getMinAmountWithSlippage = (amount, rate) => {
|
|
|
7849
7853
|
const slippage = (100 - rate) / 100 * BASIS_POINT_MAX;
|
|
7850
7854
|
return amount.mul(new (0, _anchor.BN)(slippage)).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
|
|
7851
7855
|
};
|
|
7852
|
-
var getPriceImpact = (
|
|
7856
|
+
var getPriceImpact = (amountIn, amountOut, currentSqrtPrice, aToB, tokenADecimal, tokenBDecimal) => {
|
|
7857
|
+
if (amountIn.eq(new (0, _anchor.BN)(0))) {
|
|
7858
|
+
return new (0, _decimaljs2.default)(0);
|
|
7859
|
+
}
|
|
7860
|
+
if (amountOut.eq(new (0, _anchor.BN)(0))) {
|
|
7861
|
+
throw new Error("Amount out must be greater than 0");
|
|
7862
|
+
}
|
|
7863
|
+
const spotPrice = getPriceFromSqrtPrice(
|
|
7864
|
+
currentSqrtPrice,
|
|
7865
|
+
tokenADecimal,
|
|
7866
|
+
tokenBDecimal
|
|
7867
|
+
);
|
|
7868
|
+
const executionPrice = new (0, _decimaljs2.default)(amountIn.toString()).div(new (0, _decimaljs2.default)(amountOut.toString())).mul(
|
|
7869
|
+
_decimaljs2.default.pow(
|
|
7870
|
+
10,
|
|
7871
|
+
aToB ? tokenBDecimal - tokenADecimal : tokenADecimal - tokenBDecimal
|
|
7872
|
+
)
|
|
7873
|
+
);
|
|
7874
|
+
let priceImpact;
|
|
7875
|
+
let actualExecutionPrice;
|
|
7876
|
+
if (aToB) {
|
|
7877
|
+
actualExecutionPrice = new (0, _decimaljs2.default)(1).div(executionPrice);
|
|
7878
|
+
} else {
|
|
7879
|
+
actualExecutionPrice = executionPrice;
|
|
7880
|
+
}
|
|
7881
|
+
priceImpact = actualExecutionPrice.sub(spotPrice).abs().div(spotPrice).mul(100);
|
|
7882
|
+
return priceImpact;
|
|
7883
|
+
};
|
|
7884
|
+
var getPriceChange = (nextSqrtPrice, currentSqrtPrice) => {
|
|
7853
7885
|
const diff = nextSqrtPrice.pow(new (0, _anchor.BN)(2)).sub(currentSqrtPrice.pow(new (0, _anchor.BN)(2))).abs();
|
|
7854
7886
|
return new (0, _decimaljs2.default)(diff.toString()).div(new (0, _decimaljs2.default)(currentSqrtPrice.pow(new (0, _anchor.BN)(2)).toString())).mul(100).toNumber();
|
|
7855
7887
|
};
|
|
7856
7888
|
var getPriceFromSqrtPrice = (sqrtPrice, tokenADecimal, tokenBDecimal) => {
|
|
7857
7889
|
const decimalSqrtPrice = new (0, _decimaljs2.default)(sqrtPrice.toString());
|
|
7858
|
-
const price = decimalSqrtPrice.mul(decimalSqrtPrice).mul(new (0, _decimaljs2.default)(__pow(10, tokenADecimal - tokenBDecimal))).div(_decimaljs2.default.pow(2, 128))
|
|
7890
|
+
const price = decimalSqrtPrice.mul(decimalSqrtPrice).mul(new (0, _decimaljs2.default)(__pow(10, tokenADecimal - tokenBDecimal))).div(_decimaljs2.default.pow(2, 128));
|
|
7859
7891
|
return price;
|
|
7860
7892
|
};
|
|
7861
7893
|
var getSqrtPriceFromPrice = (price, tokenADecimal, tokenBDecimal) => {
|
|
@@ -8837,7 +8869,14 @@ var CpAmm = class {
|
|
|
8837
8869
|
swapOutAmount: actualAmountOut,
|
|
8838
8870
|
minSwapOutAmount,
|
|
8839
8871
|
totalFee,
|
|
8840
|
-
priceImpact: getPriceImpact(
|
|
8872
|
+
priceImpact: getPriceImpact(
|
|
8873
|
+
actualAmountIn,
|
|
8874
|
+
actualAmountOut,
|
|
8875
|
+
sqrtPriceQ64,
|
|
8876
|
+
aToB,
|
|
8877
|
+
params.tokenADecimal,
|
|
8878
|
+
params.tokenBDecimal
|
|
8879
|
+
)
|
|
8841
8880
|
};
|
|
8842
8881
|
}
|
|
8843
8882
|
/**
|
|
@@ -8898,7 +8937,15 @@ var CpAmm = class {
|
|
|
8898
8937
|
const maxInputAmount = new (0, _anchor.BN)(
|
|
8899
8938
|
Math.ceil(actualInputAmount.toNumber() * (1 + slippage / 100))
|
|
8900
8939
|
);
|
|
8901
|
-
const priceImpact = getPriceImpact(
|
|
8940
|
+
const priceImpact = getPriceImpact(
|
|
8941
|
+
actualInputAmount,
|
|
8942
|
+
actualAmountOut,
|
|
8943
|
+
sqrtPriceQ64,
|
|
8944
|
+
!bToA,
|
|
8945
|
+
// aToB is the opposite of bToA
|
|
8946
|
+
params.tokenADecimal,
|
|
8947
|
+
params.tokenBDecimal
|
|
8948
|
+
).toNumber();
|
|
8902
8949
|
return {
|
|
8903
8950
|
swapResult,
|
|
8904
8951
|
inputAmount: actualInputAmount,
|
|
@@ -10557,5 +10604,6 @@ var index_default = cp_amm_default;
|
|
|
10557
10604
|
|
|
10558
10605
|
|
|
10559
10606
|
|
|
10560
|
-
|
|
10607
|
+
|
|
10608
|
+
exports.ActivationPoint = ActivationPoint; exports.ActivationType = ActivationType; 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.CP_AMM_PROGRAM_ID = CP_AMM_PROGRAM_ID; exports.CollectFeeMode = CollectFeeMode; exports.CpAmm = CpAmm; 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.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_PRICE_CHANGE_BPS_DEFAULT = MAX_PRICE_CHANGE_BPS_DEFAULT; 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.Rounding = Rounding; exports.SCALE_OFFSET = SCALE_OFFSET; exports.TradeDirection = TradeDirection; exports.bpsToFeeNumerator = bpsToFeeNumerator; 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.deriveTokenBadgeAddress = deriveTokenBadgeAddress; exports.deriveTokenVaultAddress = deriveTokenVaultAddress; exports.feeNumeratorToBps = feeNumeratorToBps; exports.getAllPositionNftAccountByOwner = getAllPositionNftAccountByOwner; exports.getAllUserPositionNftAccount = getAllUserPositionNftAccount; exports.getAmountAFromLiquidityDelta = getAmountAFromLiquidityDelta; exports.getAmountBFromLiquidityDelta = getAmountBFromLiquidityDelta; exports.getAvailableVestingLiquidity = getAvailableVestingLiquidity; exports.getBaseFeeNumerator = getBaseFeeNumerator; exports.getBaseFeeParams = getBaseFeeParams; exports.getDynamicFeeNumerator = getDynamicFeeNumerator; exports.getDynamicFeeParams = getDynamicFeeParams; exports.getEstimatedComputeUnitIxWithBuffer = getEstimatedComputeUnitIxWithBuffer; exports.getEstimatedComputeUnitUsageWithBuffer = getEstimatedComputeUnitUsageWithBuffer; exports.getExcludedFeeAmount = getExcludedFeeAmount; exports.getFeeMode = getFeeMode; exports.getFeeNumerator = getFeeNumerator; exports.getFirstKey = getFirstKey; exports.getIncludedFeeAmount = getIncludedFeeAmount; exports.getLiquidityDeltaFromAmountA = getLiquidityDeltaFromAmountA; exports.getLiquidityDeltaFromAmountB = getLiquidityDeltaFromAmountB; exports.getMaxAmountWithSlippage = getMaxAmountWithSlippage; exports.getMinAmountWithSlippage = getMinAmountWithSlippage; exports.getNextSqrtPrice = getNextSqrtPrice; exports.getNextSqrtPriceFromAmountARoundingDown = getNextSqrtPriceFromAmountARoundingDown; exports.getNextSqrtPriceFromAmountBRoundingUp = getNextSqrtPriceFromAmountBRoundingUp; exports.getNextSqrtPriceFromOutput = getNextSqrtPriceFromOutput; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getPriceChange = getPriceChange; exports.getPriceFromSqrtPrice = getPriceFromSqrtPrice; exports.getPriceImpact = getPriceImpact; exports.getSecondKey = getSecondKey; exports.getSimulationComputeUnits = getSimulationComputeUnits; exports.getSqrtPriceFromPrice = getSqrtPriceFromPrice; exports.getSwapAmount = getSwapAmount; exports.getSwapResultFromOutAmount = getSwapResultFromOutAmount; exports.getTokenDecimals = getTokenDecimals; exports.getTokenProgram = getTokenProgram; exports.getTotalLockedLiquidity = getTotalLockedLiquidity; exports.getUnClaimReward = getUnClaimReward; exports.isVestingComplete = isVestingComplete; exports.mulDiv = mulDiv; exports.positionByPoolFilter = positionByPoolFilter; exports.pow = pow; exports.q64ToDecimal = q64ToDecimal; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.vestingByPositionFilter = vestingByPositionFilter; exports.wrapSOLInstruction = wrapSOLInstruction;
|
|
10561
10609
|
//# sourceMappingURL=index.js.map
|