@meteora-ag/cp-amm-sdk 1.0.1-rc.13 → 1.0.1-rc.15
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 +14 -4
- package/dist/index.d.ts +14 -4
- package/dist/index.js +45 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Program, IdlAccounts, BN, IdlTypes } from '@coral-xyz/anchor';
|
|
2
2
|
import { PublicKey, Transaction, Connection, TransactionInstruction, AddressLookupTableAccount, Commitment, GetProgramAccountsFilter } from '@solana/web3.js';
|
|
3
|
+
import Decimal from 'decimal.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Program IDL in camelCase format in order to be used in JS/TS.
|
|
@@ -6610,6 +6611,7 @@ declare const SCALE_OFFSET = 64;
|
|
|
6610
6611
|
declare const BASIS_POINT_MAX = 10000;
|
|
6611
6612
|
declare const MAX_FEE_NUMERATOR = 500000000;
|
|
6612
6613
|
declare const FEE_DENOMINATOR = 1000000000;
|
|
6614
|
+
declare const PRECISION = 1000000;
|
|
6613
6615
|
declare const MIN_SQRT_PRICE: BN;
|
|
6614
6616
|
declare const MAX_SQRT_PRICE: BN;
|
|
6615
6617
|
declare const MIN_CU_BUFFER = 50000;
|
|
@@ -6656,8 +6658,8 @@ declare function getLiquidityDeltaFromAmountA(maxAmountA: BN, lowerSqrtPrice: BN
|
|
|
6656
6658
|
upperSqrtPrice: BN): BN;
|
|
6657
6659
|
declare function getLiquidityDeltaFromAmountB(maxAmountB: BN, lowerSqrtPrice: BN, // min sqrt price
|
|
6658
6660
|
upperSqrtPrice: BN): BN;
|
|
6659
|
-
declare function getAmountAFromLiquidityDelta(liquidity: BN, currentSqrtPrice: BN):
|
|
6660
|
-
declare function getAmountBFromLiquidityDelta(liquidity: BN, currentSqrtPrice: BN):
|
|
6661
|
+
declare function getAmountAFromLiquidityDelta(liquidity: BN, currentSqrtPrice: BN): string;
|
|
6662
|
+
declare function getAmountBFromLiquidityDelta(liquidity: BN, currentSqrtPrice: BN): string;
|
|
6661
6663
|
|
|
6662
6664
|
declare const getSimulationComputeUnits: (connection: Connection, instructions: Array<TransactionInstruction>, payer: PublicKey, lookupTables: Array<AddressLookupTableAccount> | [], commitment?: Commitment) => Promise<number | null>;
|
|
6663
6665
|
/**
|
|
@@ -6704,7 +6706,7 @@ declare const getMinAmountWithSlippage: (amount: BN, rate: number) => BN;
|
|
|
6704
6706
|
* @returns Price impact as a percentage (e.g., 1.5 means 1.5%)
|
|
6705
6707
|
*/
|
|
6706
6708
|
declare const getPriceImpact: (actualAmount: BN, idealAmount: BN) => number;
|
|
6707
|
-
declare const getCurrentPrice: (sqrtPrice: BN, tokenADecimal: number, tokenBDecimal: number) =>
|
|
6709
|
+
declare const getCurrentPrice: (sqrtPrice: BN, tokenADecimal: number, tokenBDecimal: number) => string;
|
|
6708
6710
|
declare const getUnClaimReward: (positionState: PositionState) => {
|
|
6709
6711
|
feeTokenA: BN;
|
|
6710
6712
|
feeTokenB: BN;
|
|
@@ -6713,6 +6715,14 @@ declare const getUnClaimReward: (positionState: PositionState) => {
|
|
|
6713
6715
|
|
|
6714
6716
|
declare const positionByPoolFilter: (pool: PublicKey) => GetProgramAccountsFilter;
|
|
6715
6717
|
|
|
6718
|
+
declare function mulShr(x: BN, y: BN, offset: number, rounding: Rounding): BN;
|
|
6719
|
+
declare function shlDiv(x: BN, y: BN, offset: number, rounding: Rounding): BN;
|
|
6720
|
+
declare function mulDiv(x: BN, y: BN, denominator: BN, rounding: Rounding): BN;
|
|
6721
|
+
declare function divCeil(a: BN, b: BN): BN;
|
|
6722
|
+
declare function q64ToDecimal(num: BN, decimalPlaces?: number): Decimal;
|
|
6723
|
+
declare function decimalToQ64(num: Decimal): BN;
|
|
6724
|
+
declare function getInitPriceQ64(tokenAAmount: BN, tokenBAmount: BN): BN;
|
|
6725
|
+
|
|
6716
6726
|
var address = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG";
|
|
6717
6727
|
var metadata = {
|
|
6718
6728
|
name: "cp_amm",
|
|
@@ -12872,4 +12882,4 @@ var CpAmmIDL = {
|
|
|
12872
12882
|
types: types
|
|
12873
12883
|
};
|
|
12874
12884
|
|
|
12875
|
-
export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeParams, type ClaimRewardParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionParams, type DynamicFee, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparedPoolCreation, type RefreshVestingParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, deriveEventAuthority, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getBaseFeeNumerator, getCurrentPrice, getDeltaAmountA, getDeltaAmountB, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getNftOwner, getOrCreateATAInstruction, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSwapAmount, getTokenDecimals, getTokenProgram, getUnClaimReward, positionByPoolFilter, unwrapSOLInstruction, wrapSOLInstruction };
|
|
12885
|
+
export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeParams, type ClaimRewardParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionParams, type DynamicFee, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, PRECISION, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparedPoolCreation, type RefreshVestingParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, decimalToQ64, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, deriveEventAuthority, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, divCeil, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getBaseFeeNumerator, getCurrentPrice, getDeltaAmountA, getDeltaAmountB, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getInitPriceQ64, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getNftOwner, getOrCreateATAInstruction, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSwapAmount, getTokenDecimals, getTokenProgram, getUnClaimReward, mulDiv, mulShr, positionByPoolFilter, q64ToDecimal, shlDiv, unwrapSOLInstruction, wrapSOLInstruction };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Program, IdlAccounts, BN, IdlTypes } from '@coral-xyz/anchor';
|
|
2
2
|
import { PublicKey, Transaction, Connection, TransactionInstruction, AddressLookupTableAccount, Commitment, GetProgramAccountsFilter } from '@solana/web3.js';
|
|
3
|
+
import Decimal from 'decimal.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Program IDL in camelCase format in order to be used in JS/TS.
|
|
@@ -6610,6 +6611,7 @@ declare const SCALE_OFFSET = 64;
|
|
|
6610
6611
|
declare const BASIS_POINT_MAX = 10000;
|
|
6611
6612
|
declare const MAX_FEE_NUMERATOR = 500000000;
|
|
6612
6613
|
declare const FEE_DENOMINATOR = 1000000000;
|
|
6614
|
+
declare const PRECISION = 1000000;
|
|
6613
6615
|
declare const MIN_SQRT_PRICE: BN;
|
|
6614
6616
|
declare const MAX_SQRT_PRICE: BN;
|
|
6615
6617
|
declare const MIN_CU_BUFFER = 50000;
|
|
@@ -6656,8 +6658,8 @@ declare function getLiquidityDeltaFromAmountA(maxAmountA: BN, lowerSqrtPrice: BN
|
|
|
6656
6658
|
upperSqrtPrice: BN): BN;
|
|
6657
6659
|
declare function getLiquidityDeltaFromAmountB(maxAmountB: BN, lowerSqrtPrice: BN, // min sqrt price
|
|
6658
6660
|
upperSqrtPrice: BN): BN;
|
|
6659
|
-
declare function getAmountAFromLiquidityDelta(liquidity: BN, currentSqrtPrice: BN):
|
|
6660
|
-
declare function getAmountBFromLiquidityDelta(liquidity: BN, currentSqrtPrice: BN):
|
|
6661
|
+
declare function getAmountAFromLiquidityDelta(liquidity: BN, currentSqrtPrice: BN): string;
|
|
6662
|
+
declare function getAmountBFromLiquidityDelta(liquidity: BN, currentSqrtPrice: BN): string;
|
|
6661
6663
|
|
|
6662
6664
|
declare const getSimulationComputeUnits: (connection: Connection, instructions: Array<TransactionInstruction>, payer: PublicKey, lookupTables: Array<AddressLookupTableAccount> | [], commitment?: Commitment) => Promise<number | null>;
|
|
6663
6665
|
/**
|
|
@@ -6704,7 +6706,7 @@ declare const getMinAmountWithSlippage: (amount: BN, rate: number) => BN;
|
|
|
6704
6706
|
* @returns Price impact as a percentage (e.g., 1.5 means 1.5%)
|
|
6705
6707
|
*/
|
|
6706
6708
|
declare const getPriceImpact: (actualAmount: BN, idealAmount: BN) => number;
|
|
6707
|
-
declare const getCurrentPrice: (sqrtPrice: BN, tokenADecimal: number, tokenBDecimal: number) =>
|
|
6709
|
+
declare const getCurrentPrice: (sqrtPrice: BN, tokenADecimal: number, tokenBDecimal: number) => string;
|
|
6708
6710
|
declare const getUnClaimReward: (positionState: PositionState) => {
|
|
6709
6711
|
feeTokenA: BN;
|
|
6710
6712
|
feeTokenB: BN;
|
|
@@ -6713,6 +6715,14 @@ declare const getUnClaimReward: (positionState: PositionState) => {
|
|
|
6713
6715
|
|
|
6714
6716
|
declare const positionByPoolFilter: (pool: PublicKey) => GetProgramAccountsFilter;
|
|
6715
6717
|
|
|
6718
|
+
declare function mulShr(x: BN, y: BN, offset: number, rounding: Rounding): BN;
|
|
6719
|
+
declare function shlDiv(x: BN, y: BN, offset: number, rounding: Rounding): BN;
|
|
6720
|
+
declare function mulDiv(x: BN, y: BN, denominator: BN, rounding: Rounding): BN;
|
|
6721
|
+
declare function divCeil(a: BN, b: BN): BN;
|
|
6722
|
+
declare function q64ToDecimal(num: BN, decimalPlaces?: number): Decimal;
|
|
6723
|
+
declare function decimalToQ64(num: Decimal): BN;
|
|
6724
|
+
declare function getInitPriceQ64(tokenAAmount: BN, tokenBAmount: BN): BN;
|
|
6725
|
+
|
|
6716
6726
|
var address = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG";
|
|
6717
6727
|
var metadata = {
|
|
6718
6728
|
name: "cp_amm",
|
|
@@ -12872,4 +12882,4 @@ var CpAmmIDL = {
|
|
|
12872
12882
|
types: types
|
|
12873
12883
|
};
|
|
12874
12884
|
|
|
12875
|
-
export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeParams, type ClaimRewardParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionParams, type DynamicFee, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparedPoolCreation, type RefreshVestingParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, deriveEventAuthority, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getBaseFeeNumerator, getCurrentPrice, getDeltaAmountA, getDeltaAmountB, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getNftOwner, getOrCreateATAInstruction, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSwapAmount, getTokenDecimals, getTokenProgram, getUnClaimReward, positionByPoolFilter, unwrapSOLInstruction, wrapSOLInstruction };
|
|
12885
|
+
export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeParams, type ClaimRewardParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionParams, type DynamicFee, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, PRECISION, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparedPoolCreation, type RefreshVestingParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, decimalToQ64, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, deriveEventAuthority, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, divCeil, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getBaseFeeNumerator, getCurrentPrice, getDeltaAmountA, getDeltaAmountB, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getInitPriceQ64, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getNftOwner, getOrCreateATAInstruction, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSwapAmount, getTokenDecimals, getTokenProgram, getUnClaimReward, mulDiv, mulShr, positionByPoolFilter, q64ToDecimal, shlDiv, unwrapSOLInstruction, wrapSOLInstruction };
|
package/dist/index.js
CHANGED
|
@@ -6185,6 +6185,7 @@ var SCALE_OFFSET = 64;
|
|
|
6185
6185
|
var BASIS_POINT_MAX = 1e4;
|
|
6186
6186
|
var MAX_FEE_NUMERATOR = 5e8;
|
|
6187
6187
|
var FEE_DENOMINATOR = 1e9;
|
|
6188
|
+
var PRECISION = 1e6;
|
|
6188
6189
|
var MIN_SQRT_PRICE = new (0, _anchor.BN)("4295048016");
|
|
6189
6190
|
var MAX_SQRT_PRICE = new (0, _anchor.BN)("79226673521066979257578248091");
|
|
6190
6191
|
var MIN_CU_BUFFER = 5e4;
|
|
@@ -6525,6 +6526,10 @@ function pow(base, exp) {
|
|
|
6525
6526
|
// src/math/index.ts
|
|
6526
6527
|
|
|
6527
6528
|
var _decimaljs = require('decimal.js'); var _decimaljs2 = _interopRequireDefault(_decimaljs);
|
|
6529
|
+
function mulShr(x, y, offset, rounding) {
|
|
6530
|
+
const denominator = new (0, _anchor.BN)(1).shln(offset);
|
|
6531
|
+
return mulDiv(x, y, denominator, rounding);
|
|
6532
|
+
}
|
|
6528
6533
|
function shlDiv(x, y, offset, rounding) {
|
|
6529
6534
|
const scale = new (0, _anchor.BN)(1).shln(offset);
|
|
6530
6535
|
return mulDiv(x, scale, y, rounding);
|
|
@@ -6542,6 +6547,12 @@ function divCeil(a, b) {
|
|
|
6542
6547
|
}
|
|
6543
6548
|
return a.add(b.sub(new (0, _anchor.BN)(1))).div(b);
|
|
6544
6549
|
}
|
|
6550
|
+
function q64ToDecimal(num, decimalPlaces) {
|
|
6551
|
+
return new (0, _decimaljs2.default)(num.toString()).div(_decimaljs2.default.pow(2, 64)).toDecimalPlaces(decimalPlaces);
|
|
6552
|
+
}
|
|
6553
|
+
function decimalToQ64(num) {
|
|
6554
|
+
return new (0, _anchor.BN)(num.mul(_decimaljs2.default.pow(2, 64)).floor().toFixed());
|
|
6555
|
+
}
|
|
6545
6556
|
function getInitPriceQ64(tokenAAmount, tokenBAmount) {
|
|
6546
6557
|
const sqrtInitPrice = new (0, _decimaljs2.default)(tokenBAmount.toString()).div(new (0, _decimaljs2.default)(tokenAAmount.toString())).sqrt();
|
|
6547
6558
|
return new (0, _anchor.BN)(sqrtInitPrice.mul(_decimaljs2.default.pow(2, 64)).floor().toFixed());
|
|
@@ -6549,6 +6560,7 @@ function getInitPriceQ64(tokenAAmount, tokenBAmount) {
|
|
|
6549
6560
|
|
|
6550
6561
|
// src/helpers/curve.ts
|
|
6551
6562
|
|
|
6563
|
+
|
|
6552
6564
|
function getNextSqrtPrice(amount, sqrtPrice, liquidity, aToB) {
|
|
6553
6565
|
let result;
|
|
6554
6566
|
if (aToB) {
|
|
@@ -6581,25 +6593,35 @@ function getDeltaAmountB(lowerSqrtPrice, upperSqrtPrice, liquidity, rounding) {
|
|
|
6581
6593
|
return result;
|
|
6582
6594
|
}
|
|
6583
6595
|
function getLiquidityDeltaFromAmountA(maxAmountA, lowerSqrtPrice, upperSqrtPrice) {
|
|
6584
|
-
const prod =
|
|
6585
|
-
|
|
6586
|
-
|
|
6596
|
+
const prod = new (0, _decimaljs2.default)(
|
|
6597
|
+
maxAmountA.mul(upperSqrtPrice.mul(lowerSqrtPrice)).toString()
|
|
6598
|
+
);
|
|
6599
|
+
const delta = new (0, _decimaljs2.default)(upperSqrtPrice.sub(lowerSqrtPrice).toString());
|
|
6600
|
+
return new (0, _anchor.BN)(prod.div(delta).floor().toFixed());
|
|
6587
6601
|
}
|
|
6588
6602
|
function getLiquidityDeltaFromAmountB(maxAmountB, lowerSqrtPrice, upperSqrtPrice) {
|
|
6589
|
-
const denominator =
|
|
6590
|
-
|
|
6591
|
-
|
|
6603
|
+
const denominator = new (0, _decimaljs2.default)(
|
|
6604
|
+
upperSqrtPrice.sub(lowerSqrtPrice).toString()
|
|
6605
|
+
);
|
|
6606
|
+
const prod = new (0, _decimaljs2.default)(maxAmountB.toString()).mul(
|
|
6607
|
+
_decimaljs2.default.pow(2, SCALE_OFFSET * 2)
|
|
6608
|
+
);
|
|
6609
|
+
return new (0, _anchor.BN)(prod.div(denominator).floor().toFixed());
|
|
6592
6610
|
}
|
|
6593
6611
|
function getAmountAFromLiquidityDelta(liquidity, currentSqrtPrice) {
|
|
6594
|
-
const prod =
|
|
6612
|
+
const prod = new (0, _decimaljs2.default)(liquidity.toString()).mul(
|
|
6613
|
+
new (0, _decimaljs2.default)(MAX_SQRT_PRICE.sub(currentSqrtPrice).toString())
|
|
6614
|
+
);
|
|
6595
6615
|
const denominator = currentSqrtPrice.mul(MAX_SQRT_PRICE);
|
|
6596
|
-
const result =
|
|
6597
|
-
return result.
|
|
6616
|
+
const result = prod.mul(_decimaljs2.default.pow(2, 64)).div(new (0, _decimaljs2.default)(denominator.toString()));
|
|
6617
|
+
return result.div(_decimaljs2.default.pow(2, 64)).floor().toFixed();
|
|
6598
6618
|
}
|
|
6599
6619
|
function getAmountBFromLiquidityDelta(liquidity, currentSqrtPrice) {
|
|
6600
6620
|
const delta = currentSqrtPrice.sub(MIN_SQRT_PRICE);
|
|
6601
|
-
const prod = liquidity.mul(
|
|
6602
|
-
|
|
6621
|
+
const prod = new (0, _decimaljs2.default)(liquidity.toString()).mul(
|
|
6622
|
+
new (0, _decimaljs2.default)(delta.toString())
|
|
6623
|
+
);
|
|
6624
|
+
return prod.div(_decimaljs2.default.pow(2, 128)).floor().toFixed();
|
|
6603
6625
|
}
|
|
6604
6626
|
|
|
6605
6627
|
// src/helpers/fee.ts
|
|
@@ -6775,10 +6797,9 @@ var getPriceImpact = (actualAmount, idealAmount) => {
|
|
|
6775
6797
|
return new (0, _decimaljs2.default)(diff.toString()).div(new (0, _decimaljs2.default)(idealAmount.toString())).mul(100).toNumber();
|
|
6776
6798
|
};
|
|
6777
6799
|
var getCurrentPrice = (sqrtPrice, tokenADecimal, tokenBDecimal) => {
|
|
6778
|
-
const
|
|
6779
|
-
const price =
|
|
6780
|
-
|
|
6781
|
-
return price.muln(expo);
|
|
6800
|
+
const decimalSqrtPrice = new (0, _decimaljs2.default)(sqrtPrice.toString());
|
|
6801
|
+
const price = decimalSqrtPrice.mul(decimalSqrtPrice).mul(new (0, _decimaljs2.default)(__pow(10, tokenADecimal - tokenBDecimal))).div(_decimaljs2.default.pow(2, 128)).toString();
|
|
6802
|
+
return price;
|
|
6782
6803
|
};
|
|
6783
6804
|
var getUnClaimReward = (positionState) => {
|
|
6784
6805
|
return {
|
|
@@ -8059,5 +8080,13 @@ var index_default = cp_amm_default;
|
|
|
8059
8080
|
|
|
8060
8081
|
|
|
8061
8082
|
|
|
8062
|
-
|
|
8083
|
+
|
|
8084
|
+
|
|
8085
|
+
|
|
8086
|
+
|
|
8087
|
+
|
|
8088
|
+
|
|
8089
|
+
|
|
8090
|
+
|
|
8091
|
+
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.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.PRECISION = PRECISION; exports.Rounding = Rounding; exports.SCALE_OFFSET = SCALE_OFFSET; exports.TradeDirection = TradeDirection; exports.decimalToQ64 = decimalToQ64; exports.default = index_default; exports.deriveClaimFeeOperatorAddress = deriveClaimFeeOperatorAddress; exports.deriveConfigAddress = deriveConfigAddress; exports.deriveCustomizablePoolAddress = deriveCustomizablePoolAddress; exports.deriveEventAuthority = deriveEventAuthority; exports.derivePoolAddress = derivePoolAddress; exports.derivePoolAuthority = derivePoolAuthority; exports.derivePositionAddress = derivePositionAddress; exports.derivePositionNftAccount = derivePositionNftAccount; exports.deriveRewardVaultAddress = deriveRewardVaultAddress; exports.deriveTokenBadgeAddress = deriveTokenBadgeAddress; exports.deriveTokenVaultAddress = deriveTokenVaultAddress; exports.divCeil = divCeil; exports.getAmountAFromLiquidityDelta = getAmountAFromLiquidityDelta; exports.getAmountBFromLiquidityDelta = getAmountBFromLiquidityDelta; exports.getBaseFeeNumerator = getBaseFeeNumerator; exports.getCurrentPrice = getCurrentPrice; exports.getDeltaAmountA = getDeltaAmountA; exports.getDeltaAmountB = getDeltaAmountB; exports.getDynamicFeeNumerator = getDynamicFeeNumerator; exports.getEstimatedComputeUnitIxWithBuffer = getEstimatedComputeUnitIxWithBuffer; exports.getEstimatedComputeUnitUsageWithBuffer = getEstimatedComputeUnitUsageWithBuffer; exports.getFeeNumerator = getFeeNumerator; exports.getFirstKey = getFirstKey; exports.getInitPriceQ64 = getInitPriceQ64; exports.getLiquidityDeltaFromAmountA = getLiquidityDeltaFromAmountA; exports.getLiquidityDeltaFromAmountB = getLiquidityDeltaFromAmountB; exports.getMaxAmountWithSlippage = getMaxAmountWithSlippage; exports.getMinAmountWithSlippage = getMinAmountWithSlippage; exports.getNextSqrtPrice = getNextSqrtPrice; exports.getNftOwner = getNftOwner; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getPriceImpact = getPriceImpact; exports.getSecondKey = getSecondKey; exports.getSimulationComputeUnits = getSimulationComputeUnits; exports.getSwapAmount = getSwapAmount; exports.getTokenDecimals = getTokenDecimals; exports.getTokenProgram = getTokenProgram; exports.getUnClaimReward = getUnClaimReward; exports.mulDiv = mulDiv; exports.mulShr = mulShr; exports.positionByPoolFilter = positionByPoolFilter; exports.q64ToDecimal = q64ToDecimal; exports.shlDiv = shlDiv; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.wrapSOLInstruction = wrapSOLInstruction;
|
|
8063
8092
|
//# sourceMappingURL=index.js.map
|