@meteora-ag/cp-amm-sdk 1.1.0 → 1.1.1
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 +24 -7
- package/dist/index.d.ts +24 -7
- package/dist/index.js +55 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
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;
|
|
@@ -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;
|
|
@@ -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,
|
|
@@ -7770,7 +7770,7 @@ function getSwapResultFromOutAmount(pool, outAmount, feeMode, tradeDirection, cu
|
|
|
7770
7770
|
|
|
7771
7771
|
|
|
7772
7772
|
|
|
7773
|
-
var getSimulationComputeUnits = (connection, instructions, payer, lookupTables, commitment = "confirmed") => __async(
|
|
7773
|
+
var getSimulationComputeUnits = (connection, instructions, payer, lookupTables, commitment = "confirmed") => __async(void 0, null, function* () {
|
|
7774
7774
|
var _a, _b, _c;
|
|
7775
7775
|
const testInstructions = [
|
|
7776
7776
|
// Set an arbitrarily high number in simulation
|
|
@@ -7802,7 +7802,7 @@ var getSimulationComputeUnits = (connection, instructions, payer, lookupTables,
|
|
|
7802
7802
|
}
|
|
7803
7803
|
return rpcResponse.value.unitsConsumed || null;
|
|
7804
7804
|
});
|
|
7805
|
-
var getEstimatedComputeUnitUsageWithBuffer = (connection, instructions, feePayer, buffer) => __async(
|
|
7805
|
+
var getEstimatedComputeUnitUsageWithBuffer = (connection, instructions, feePayer, buffer) => __async(void 0, null, function* () {
|
|
7806
7806
|
if (!buffer) {
|
|
7807
7807
|
buffer = 0.1;
|
|
7808
7808
|
}
|
|
@@ -7825,7 +7825,7 @@ var getEstimatedComputeUnitUsageWithBuffer = (connection, instructions, feePayer
|
|
|
7825
7825
|
}
|
|
7826
7826
|
return estimatedComputeUnitUsage + extraComputeUnitBuffer;
|
|
7827
7827
|
});
|
|
7828
|
-
var getEstimatedComputeUnitIxWithBuffer = (connection, instructions, feePayer, buffer) => __async(
|
|
7828
|
+
var getEstimatedComputeUnitIxWithBuffer = (connection, instructions, feePayer, buffer) => __async(void 0, null, function* () {
|
|
7829
7829
|
const units = yield getEstimatedComputeUnitUsageWithBuffer(
|
|
7830
7830
|
connection,
|
|
7831
7831
|
instructions,
|
|
@@ -7849,13 +7849,41 @@ var getMinAmountWithSlippage = (amount, rate) => {
|
|
|
7849
7849
|
const slippage = (100 - rate) / 100 * BASIS_POINT_MAX;
|
|
7850
7850
|
return amount.mul(new (0, _anchor.BN)(slippage)).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
|
|
7851
7851
|
};
|
|
7852
|
-
var getPriceImpact = (
|
|
7852
|
+
var getPriceImpact = (amountIn, amountOut, currentSqrtPrice, aToB, tokenADecimal, tokenBDecimal) => {
|
|
7853
|
+
if (amountIn.eq(new (0, _anchor.BN)(0))) {
|
|
7854
|
+
return new (0, _decimaljs2.default)(0);
|
|
7855
|
+
}
|
|
7856
|
+
if (amountOut.eq(new (0, _anchor.BN)(0))) {
|
|
7857
|
+
throw new Error("Amount out must be greater than 0");
|
|
7858
|
+
}
|
|
7859
|
+
const spotPrice = getPriceFromSqrtPrice(
|
|
7860
|
+
currentSqrtPrice,
|
|
7861
|
+
tokenADecimal,
|
|
7862
|
+
tokenBDecimal
|
|
7863
|
+
);
|
|
7864
|
+
const executionPrice = new (0, _decimaljs2.default)(amountIn.toString()).div(new (0, _decimaljs2.default)(amountOut.toString())).mul(
|
|
7865
|
+
_decimaljs2.default.pow(
|
|
7866
|
+
10,
|
|
7867
|
+
aToB ? tokenBDecimal - tokenADecimal : tokenADecimal - tokenBDecimal
|
|
7868
|
+
)
|
|
7869
|
+
);
|
|
7870
|
+
let priceImpact;
|
|
7871
|
+
let actualExecutionPrice;
|
|
7872
|
+
if (aToB) {
|
|
7873
|
+
actualExecutionPrice = new (0, _decimaljs2.default)(1).div(executionPrice);
|
|
7874
|
+
} else {
|
|
7875
|
+
actualExecutionPrice = executionPrice;
|
|
7876
|
+
}
|
|
7877
|
+
priceImpact = actualExecutionPrice.sub(spotPrice).abs().div(spotPrice).mul(100);
|
|
7878
|
+
return priceImpact;
|
|
7879
|
+
};
|
|
7880
|
+
var getPriceChange = (nextSqrtPrice, currentSqrtPrice) => {
|
|
7853
7881
|
const diff = nextSqrtPrice.pow(new (0, _anchor.BN)(2)).sub(currentSqrtPrice.pow(new (0, _anchor.BN)(2))).abs();
|
|
7854
7882
|
return new (0, _decimaljs2.default)(diff.toString()).div(new (0, _decimaljs2.default)(currentSqrtPrice.pow(new (0, _anchor.BN)(2)).toString())).mul(100).toNumber();
|
|
7855
7883
|
};
|
|
7856
7884
|
var getPriceFromSqrtPrice = (sqrtPrice, tokenADecimal, tokenBDecimal) => {
|
|
7857
7885
|
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))
|
|
7886
|
+
const price = decimalSqrtPrice.mul(decimalSqrtPrice).mul(new (0, _decimaljs2.default)(__pow(10, tokenADecimal - tokenBDecimal))).div(_decimaljs2.default.pow(2, 128));
|
|
7859
7887
|
return price;
|
|
7860
7888
|
};
|
|
7861
7889
|
var getSqrtPriceFromPrice = (price, tokenADecimal, tokenBDecimal) => {
|
|
@@ -8837,7 +8865,14 @@ var CpAmm = class {
|
|
|
8837
8865
|
swapOutAmount: actualAmountOut,
|
|
8838
8866
|
minSwapOutAmount,
|
|
8839
8867
|
totalFee,
|
|
8840
|
-
priceImpact: getPriceImpact(
|
|
8868
|
+
priceImpact: getPriceImpact(
|
|
8869
|
+
actualAmountIn,
|
|
8870
|
+
actualAmountOut,
|
|
8871
|
+
sqrtPriceQ64,
|
|
8872
|
+
aToB,
|
|
8873
|
+
params.tokenADecimal,
|
|
8874
|
+
params.tokenBDecimal
|
|
8875
|
+
)
|
|
8841
8876
|
};
|
|
8842
8877
|
}
|
|
8843
8878
|
/**
|
|
@@ -8898,7 +8933,15 @@ var CpAmm = class {
|
|
|
8898
8933
|
const maxInputAmount = new (0, _anchor.BN)(
|
|
8899
8934
|
Math.ceil(actualInputAmount.toNumber() * (1 + slippage / 100))
|
|
8900
8935
|
);
|
|
8901
|
-
const priceImpact = getPriceImpact(
|
|
8936
|
+
const priceImpact = getPriceImpact(
|
|
8937
|
+
actualInputAmount,
|
|
8938
|
+
actualAmountOut,
|
|
8939
|
+
sqrtPriceQ64,
|
|
8940
|
+
!bToA,
|
|
8941
|
+
// aToB is the opposite of bToA
|
|
8942
|
+
params.tokenADecimal,
|
|
8943
|
+
params.tokenBDecimal
|
|
8944
|
+
).toNumber();
|
|
8902
8945
|
return {
|
|
8903
8946
|
swapResult,
|
|
8904
8947
|
inputAmount: actualInputAmount,
|
|
@@ -10557,5 +10600,6 @@ var index_default = cp_amm_default;
|
|
|
10557
10600
|
|
|
10558
10601
|
|
|
10559
10602
|
|
|
10560
|
-
|
|
10603
|
+
|
|
10604
|
+
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
10605
|
//# sourceMappingURL=index.js.map
|