@meteora-ag/dynamic-bonding-curve-sdk 1.5.13 → 2.0.0

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/math.cjs ADDED
@@ -0,0 +1,125 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+ var _chunkIRVDOLO7cjs = require('./chunk-IRVDOLO7.cjs');
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+ exports.FeeRateLimiter = _chunkIRVDOLO7cjs.FeeRateLimiter; exports.FeeScheduler = _chunkIRVDOLO7cjs.FeeScheduler; exports.ProgramError = _chunkIRVDOLO7cjs.ProgramError; exports.SafeMath = _chunkIRVDOLO7cjs.SafeMath; exports.calculateBaseToQuoteFromAmountIn = _chunkIRVDOLO7cjs.calculateBaseToQuoteFromAmountIn; exports.calculateBaseToQuoteFromAmountOut = _chunkIRVDOLO7cjs.calculateBaseToQuoteFromAmountOut; exports.calculateQuoteToBaseFromAmountIn = _chunkIRVDOLO7cjs.calculateQuoteToBaseFromAmountIn; exports.calculateQuoteToBaseFromAmountOut = _chunkIRVDOLO7cjs.calculateQuoteToBaseFromAmountOut; exports.calculateTransferFeeExcludedAmount = _chunkIRVDOLO7cjs.calculateTransferFeeExcludedAmount; exports.calculateTransferFeeIncludedAmount = _chunkIRVDOLO7cjs.calculateTransferFeeIncludedAmount; exports.getBaseFeeHandler = _chunkIRVDOLO7cjs.getBaseFeeHandler; exports.getBaseFeeNumerator = _chunkIRVDOLO7cjs.getBaseFeeNumerator; exports.getBaseFeeNumeratorByPeriod = _chunkIRVDOLO7cjs.getBaseFeeNumeratorByPeriod; exports.getBaseTransferFee = _chunkIRVDOLO7cjs.getBaseTransferFee; exports.getCheckedAmounts = _chunkIRVDOLO7cjs.getCheckedAmounts; exports.getDeltaAmountBaseUnsigned = _chunkIRVDOLO7cjs.getDeltaAmountBaseUnsigned; exports.getDeltaAmountBaseUnsigned256 = _chunkIRVDOLO7cjs.getDeltaAmountBaseUnsigned256; exports.getDeltaAmountQuoteUnsigned = _chunkIRVDOLO7cjs.getDeltaAmountQuoteUnsigned; exports.getDeltaAmountQuoteUnsigned256 = _chunkIRVDOLO7cjs.getDeltaAmountQuoteUnsigned256; exports.getEpochTransferFee = _chunkIRVDOLO7cjs.getEpochTransferFee; exports.getExcludedFeeAmount = _chunkIRVDOLO7cjs.getExcludedFeeAmount; exports.getFeeMode = _chunkIRVDOLO7cjs.getFeeMode; exports.getFeeNumeratorFromExcludedAmount = _chunkIRVDOLO7cjs.getFeeNumeratorFromExcludedAmount; exports.getFeeNumeratorFromIncludedAmount = _chunkIRVDOLO7cjs.getFeeNumeratorFromIncludedAmount; exports.getFeeNumeratorOnExponentialFeeScheduler = _chunkIRVDOLO7cjs.getFeeNumeratorOnExponentialFeeScheduler; exports.getFeeNumeratorOnLinearFeeScheduler = _chunkIRVDOLO7cjs.getFeeNumeratorOnLinearFeeScheduler; exports.getFeeOnAmount = _chunkIRVDOLO7cjs.getFeeOnAmount; exports.getFeeSchedulerMinBaseFeeNumerator = _chunkIRVDOLO7cjs.getFeeSchedulerMinBaseFeeNumerator; exports.getIncludedFeeAmount = _chunkIRVDOLO7cjs.getIncludedFeeAmount; exports.getInitialLiquidityFromDeltaBase = _chunkIRVDOLO7cjs.getInitialLiquidityFromDeltaBase; exports.getInitialLiquidityFromDeltaQuote = _chunkIRVDOLO7cjs.getInitialLiquidityFromDeltaQuote; exports.getMaxIndex = _chunkIRVDOLO7cjs.getMaxIndex; exports.getMaxOutAmountWithMinBaseFee = _chunkIRVDOLO7cjs.getMaxOutAmountWithMinBaseFee; exports.getNextSqrtPriceFromBaseAmountInRoundingUp = _chunkIRVDOLO7cjs.getNextSqrtPriceFromBaseAmountInRoundingUp; exports.getNextSqrtPriceFromBaseAmountOutRoundingUp = _chunkIRVDOLO7cjs.getNextSqrtPriceFromBaseAmountOutRoundingUp; exports.getNextSqrtPriceFromInput = _chunkIRVDOLO7cjs.getNextSqrtPriceFromInput; exports.getNextSqrtPriceFromOutput = _chunkIRVDOLO7cjs.getNextSqrtPriceFromOutput; exports.getNextSqrtPriceFromQuoteAmountInRoundingDown = _chunkIRVDOLO7cjs.getNextSqrtPriceFromQuoteAmountInRoundingDown; exports.getNextSqrtPriceFromQuoteAmountOutRoundingDown = _chunkIRVDOLO7cjs.getNextSqrtPriceFromQuoteAmountOutRoundingDown; exports.getRateLimiterExcludedFeeAmount = _chunkIRVDOLO7cjs.getRateLimiterExcludedFeeAmount; exports.getSwapResult = _chunkIRVDOLO7cjs.getSwapResult; exports.getSwapResultFromExactInput = _chunkIRVDOLO7cjs.getSwapResultFromExactInput; exports.getSwapResultFromExactOutput = _chunkIRVDOLO7cjs.getSwapResultFromExactOutput; exports.getSwapResultFromPartialInput = _chunkIRVDOLO7cjs.getSwapResultFromPartialInput; exports.getTotalFeeNumerator = _chunkIRVDOLO7cjs.getTotalFeeNumerator; exports.getTotalFeeNumeratorFromExcludedFeeAmount = _chunkIRVDOLO7cjs.getTotalFeeNumeratorFromExcludedFeeAmount; exports.getTotalFeeNumeratorFromIncludedFeeAmount = _chunkIRVDOLO7cjs.getTotalFeeNumeratorFromIncludedFeeAmount; exports.getVariableFeeNumerator = _chunkIRVDOLO7cjs.getVariableFeeNumerator; exports.isDynamicFeeEnabled = _chunkIRVDOLO7cjs.isDynamicFeeEnabled; exports.isNonZeroRateLimiter = _chunkIRVDOLO7cjs.isNonZeroRateLimiter; exports.isRateLimiterApplied = _chunkIRVDOLO7cjs.isRateLimiterApplied; exports.isZeroRateLimiter = _chunkIRVDOLO7cjs.isZeroRateLimiter; exports.isZeroTransferFee = _chunkIRVDOLO7cjs.isZeroTransferFee; exports.liveCurve = _chunkIRVDOLO7cjs.liveCurve; exports.mulDiv = _chunkIRVDOLO7cjs.mulDiv; exports.pow = _chunkIRVDOLO7cjs.pow; exports.resolveSwapTransferFees = _chunkIRVDOLO7cjs.resolveSwapTransferFees; exports.splitFees = _chunkIRVDOLO7cjs.splitFees; exports.sqrt = _chunkIRVDOLO7cjs.sqrt; exports.toNumerator = _chunkIRVDOLO7cjs.toNumerator;
125
+ //# sourceMappingURL=math.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/dann/Documents/github/dynamic-bonding-curve-sdk/packages/dynamic-bonding-curve/dist/math.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,iqJAAC","file":"/Users/dann/Documents/github/dynamic-bonding-curve-sdk/packages/dynamic-bonding-curve/dist/math.cjs"}
@@ -0,0 +1,216 @@
1
+ import BN from 'bn.js';
2
+ import { aY as Rounding, j as CollectFeeMode, b4 as TradeDirection, aF as FeeMode, aG as FeeOnAmountResult, aS as QuoteDynamicFee, aW as QuoteVolatilityTracker, aU as QuotePoolFees, au as BaseFeeHandler, ac as BaseFeeMode } from './swapQuote-CURAm57K.cjs';
3
+ export { aq as EpochTransferFee, bf as SwapAmountFromOutput, b5 as TransferFeeAmount, bg as calculateBaseToQuoteFromAmountIn, bh as calculateBaseToQuoteFromAmountOut, bi as calculateQuoteToBaseFromAmountIn, bj as calculateQuoteToBaseFromAmountOut, ba as calculateTransferFeeExcludedAmount, bb as calculateTransferFeeIncludedAmount, bk as getBaseTransferFee, bl as getEpochTransferFee, bm as getSwapResult, bn as getSwapResultFromExactInput, bo as getSwapResultFromExactOutput, bp as getSwapResultFromPartialInput, bc as isZeroTransferFee, bd as resolveSwapTransferFees } from './swapQuote-CURAm57K.cjs';
4
+ import '@solana/spl-token';
5
+ import '@coral-xyz/anchor';
6
+ import '@solana/web3.js';
7
+
8
+ /** L = Δb / (√P_upper - √P_lower), rounded down, bounded by u128. */
9
+ declare function getInitialLiquidityFromDeltaQuote(quoteAmount: BN, sqrtMinPrice: BN, sqrtPrice: BN): BN;
10
+ /** L = Δa * √P_lower * √P_upper / (√P_upper - √P_lower), rounded down. */
11
+ declare function getInitialLiquidityFromDeltaBase(baseAmount: BN, sqrtMaxPrice: BN, sqrtPrice: BN): BN;
12
+ /** Δa = L * (√P_upper - √P_lower) / (√P_upper * √P_lower), bounded by u64. */
13
+ declare function getDeltaAmountBaseUnsigned(lowerSqrtPrice: BN, upperSqrtPrice: BN, liquidity: BN, round: Rounding): BN;
14
+ /** Δa = L * (√P_upper - √P_lower) / (√P_upper * √P_lower), unbounded. */
15
+ declare function getDeltaAmountBaseUnsigned256(lowerSqrtPrice: BN, upperSqrtPrice: BN, liquidity: BN, round: Rounding): BN;
16
+ /** Δb = L * (√P_upper - √P_lower), bounded by u64. */
17
+ declare function getDeltaAmountQuoteUnsigned(lowerSqrtPrice: BN, upperSqrtPrice: BN, liquidity: BN, round: Rounding): BN;
18
+ /** Δb = L * (√P_upper - √P_lower), unbounded. */
19
+ declare function getDeltaAmountQuoteUnsigned256(lowerSqrtPrice: BN, upperSqrtPrice: BN, liquidity: BN, round: Rounding): BN;
20
+ /** Next sqrt price after amountIn of base (baseForQuote) or quote enters the segment. */
21
+ declare function getNextSqrtPriceFromInput(sqrtPrice: BN, liquidity: BN, amountIn: BN, baseForQuote: boolean): BN;
22
+ /** Next sqrt price after amountOut of quote (baseForQuote) or base leaves the segment. */
23
+ declare function getNextSqrtPriceFromOutput(sqrtPrice: BN, liquidity: BN, amountOut: BN, baseForQuote: boolean): BN;
24
+ /** √P' = √P - ceil(Δy / L) */
25
+ declare function getNextSqrtPriceFromQuoteAmountOutRoundingDown(sqrtPrice: BN, liquidity: BN, amount: BN): BN;
26
+ /** √P' = √P * L / (L - Δx * √P), rounded up */
27
+ declare function getNextSqrtPriceFromBaseAmountOutRoundingUp(sqrtPrice: BN, liquidity: BN, amount: BN): BN;
28
+ /**
29
+ * √P' = √P * L / (L + Δx * √P), rounded up so an exact output is met and an
30
+ * exact input does not move the price further than necessary.
31
+ */
32
+ declare function getNextSqrtPriceFromBaseAmountInRoundingUp(sqrtPrice: BN, liquidity: BN, amount: BN): BN;
33
+ /**
34
+ * √P' = √P + Δy / L, rounded down so an exact output is met and an exact
35
+ * input does not move the price further than necessary.
36
+ */
37
+ declare function getNextSqrtPriceFromQuoteAmountInRoundingDown(sqrtPrice: BN, liquidity: BN, amount: BN): BN;
38
+ /**
39
+ * The points of a stored curve up to the first zero point. PoolConfig.curve
40
+ * holds MAX_CURVE_POINT entries and the unused ones are zero; the program
41
+ * stops at the first of them.
42
+ */
43
+ declare function liveCurve<T extends {
44
+ sqrtPrice: BN;
45
+ liquidity: BN;
46
+ }>(curve: T[]): T[];
47
+
48
+ declare const ProgramError: {
49
+ readonly MathOverflow: "Math operation overflow";
50
+ readonly ExceededSlippage: "Exceeded slippage tolerance";
51
+ readonly ExceedMaxFeeBps: "Exceeded max fee bps";
52
+ readonly AmountIsZero: "Amount is zero";
53
+ readonly TypeCastFailed: "Type cast error";
54
+ readonly InvalidActivationType: "Invalid activation type";
55
+ readonly InvalidQuoteMint: "Invalid quote mint";
56
+ readonly InvalidCollectFeeMode: "Invalid collect fee mode";
57
+ readonly InvalidMigrationFeeOption: "Invalid migration fee option";
58
+ readonly InvalidInput: "Invalid input";
59
+ readonly NotEnoughLiquidity: "Not enough liquidity";
60
+ readonly PoolIsCompleted: "Pool is completed";
61
+ readonly InvalidMigrationOption: "Invalid migration option";
62
+ readonly InvalidTokenDecimals: "Invalid token decimals";
63
+ readonly InvalidTokenType: "Invalid token type";
64
+ readonly InvalidQuoteThreshold: "Invalid quote threshold";
65
+ readonly InvalidTokenSupply: "Invalid token supply";
66
+ readonly InvalidCurve: "Invalid curve";
67
+ readonly InvalidVestingParameters: "Invalid vesting parameters";
68
+ readonly InsufficientLiquidity: "Liquidity in bonding curve is insufficient";
69
+ readonly InvalidFeeScheduler: "Invalid fee scheduler";
70
+ readonly InvalidCreatorTradingFeePercentage: "Invalid creator trading fee percentage";
71
+ readonly InvalidBaseFeeMode: "Invalid base fee mode";
72
+ readonly InvalidFeeRateLimiter: "Invalid fee rate limiter";
73
+ readonly InvalidMigratedPoolFee: "Invalid migrated pool fee params";
74
+ readonly UndeterminedError: "Undetermined error";
75
+ readonly AmountLeftIsNotZero: "Amount left is not zero";
76
+ readonly InvalidPoolCreationFee: "Invalid pool creation fee";
77
+ readonly InvalidFeeMarketCapScheduler: "Invalid fee market cap scheduler";
78
+ readonly DeprecatedBaseFeeMode: "Deprecated base fee mode";
79
+ readonly QuoteMintHasNonZeroTransferFee: "Quote mint has a non zero transfer fee or a live transfer fee config authority";
80
+ readonly DeprecatedMigrationOption: "Deprecated migration option";
81
+ readonly FeeInverseIsIncorrect: "Transfer fee inverse calculation is incorrect";
82
+ readonly InvalidTransferFeeParameters: "Invalid transfer fee parameters";
83
+ readonly ExceededInputAmount: "Required input amount exceeds the provided amount in";
84
+ readonly InvalidFeeClaimer: "Invalid fee claimer";
85
+ };
86
+
87
+ /**
88
+ * [amount after the fee, fee], with the fee rounded up;
89
+ * the program's PoolFeesConfig::get_excluded_fee_amount.
90
+ */
91
+ declare function getExcludedFeeAmount(tradeFeeNumerator: BN, includedFeeAmount: BN): [BN, BN];
92
+ /**
93
+ * [amount before the fee, fee], rounded up and bounded by u64;
94
+ * the program's PoolFeesConfig::get_included_fee_amount.
95
+ */
96
+ declare function getIncludedFeeAmount(tradeFeeNumerator: BN, excludedFeeAmount: BN): [BN, BN];
97
+
98
+ /** Which side of a swap the fee is taken from; the program's FeeMode::get_fee_mode. */
99
+ declare function getFeeMode(collectFeeMode: CollectFeeMode, tradeDirection: TradeDirection, hasReferral: boolean): FeeMode;
100
+ /** Base plus dynamic fee numerator for an amount that includes the fee. */
101
+ declare function getTotalFeeNumeratorFromIncludedFeeAmount(poolFees: QuotePoolFees, volatilityTracker: QuoteVolatilityTracker, currentPoint: BN, activationPoint: BN, includedFeeAmount: BN, tradeDirection: TradeDirection): BN;
102
+ /** Base plus dynamic fee numerator for an amount that excludes the fee. */
103
+ declare function getTotalFeeNumeratorFromExcludedFeeAmount(poolFees: QuotePoolFees, volatilityTracker: QuoteVolatilityTracker, currentPoint: BN, activationPoint: BN, excludedFeeAmount: BN, tradeDirection: TradeDirection): BN;
104
+ /** Base plus dynamic fee numerator, capped at MAX_FEE_NUMERATOR. */
105
+ declare function getTotalFeeNumerator(baseFeeNumerator: BN, dynamicFee: QuoteDynamicFee, volatilityTracker: QuoteVolatilityTracker): BN;
106
+ /** Take the fee out of an amount and split it; the program's get_fee_on_amount. */
107
+ declare function getFeeOnAmount(tradeFeeNumerator: BN, amount: BN, hasReferral: boolean): FeeOnAmountResult;
108
+ /**
109
+ * [trading fee, protocol fee, referral fee]: the protocol takes
110
+ * PROTOCOL_FEE_PERCENT of the fee and the referrer HOST_FEE_PERCENT of that,
111
+ * both rounded down.
112
+ */
113
+ declare function splitFees(feeAmount: BN, hasReferral: boolean): [BN, BN, BN];
114
+
115
+ /**
116
+ * The program's safe_math on BN. BN is arbitrary precision, so only
117
+ * subtraction and division can fail here; the u64 and u128 bounds are
118
+ * checked by the callers.
119
+ */
120
+ declare class SafeMath {
121
+ static add(a: BN, b: BN): BN;
122
+ static sub(a: BN, b: BN): BN;
123
+ static mul(a: BN, b: BN): BN;
124
+ static div(a: BN, b: BN): BN;
125
+ static shl(a: BN, b: number): BN;
126
+ static shr(a: BN, b: number): BN;
127
+ }
128
+ /**
129
+ * Q64 power, matching the program. A base at or above 1 is inverted through
130
+ * u128::MAX so each multiplication stays inside u128.
131
+ */
132
+ declare function pow(base: BN, exponent: BN, scaling?: boolean): BN;
133
+
134
+ /** (x * y) / denominator with the given rounding; the program's mul_div. */
135
+ declare function mulDiv(x: BN, y: BN, denominator: BN, rounding: Rounding): BN;
136
+ /** bps * feeDenominator / 10_000, rounded down; the program's to_numerator. */
137
+ declare function toNumerator(bps: BN, feeDenominator: BN): BN;
138
+ /** Integer square root by Newton's method, rounded down; the program's sqrt_u256. */
139
+ declare function sqrt(value: BN): BN;
140
+
141
+ declare class FeeRateLimiter implements BaseFeeHandler {
142
+ cliffFeeNumerator: BN;
143
+ feeIncrementBps: number;
144
+ maxLimiterDuration: BN;
145
+ referenceAmount: BN;
146
+ constructor(cliffFeeNumerator: BN, feeIncrementBps: number, maxLimiterDuration: BN, referenceAmount: BN);
147
+ getMinBaseFeeNumerator(): BN;
148
+ private isApplied;
149
+ getBaseFeeNumeratorFromIncludedFeeAmount(currentPoint: BN, activationPoint: BN, tradeDirection: TradeDirection, includedFeeAmount: BN): BN;
150
+ getBaseFeeNumeratorFromExcludedFeeAmount(currentPoint: BN, activationPoint: BN, tradeDirection: TradeDirection, excludedFeeAmount: BN): BN;
151
+ }
152
+ declare class FeeScheduler implements BaseFeeHandler {
153
+ cliffFeeNumerator: BN;
154
+ numberOfPeriod: number;
155
+ periodFrequency: BN;
156
+ reductionFactor: BN;
157
+ feeSchedulerMode: BaseFeeMode;
158
+ constructor(cliffFeeNumerator: BN, numberOfPeriod: number, periodFrequency: BN, reductionFactor: BN, feeSchedulerMode: BaseFeeMode);
159
+ getMinBaseFeeNumerator(): BN;
160
+ getBaseFeeNumeratorFromIncludedFeeAmount(currentPoint: BN, activationPoint: BN): BN;
161
+ getBaseFeeNumeratorFromExcludedFeeAmount(currentPoint: BN, activationPoint: BN): BN;
162
+ }
163
+ /**
164
+ * The handler for a base fee config. The factors are the scheduler's
165
+ * numberOfPeriod, periodFrequency and reductionFactor, or the rate limiter's
166
+ * feeIncrementBps, maxLimiterDuration and referenceAmount.
167
+ */
168
+ declare function getBaseFeeHandler(cliffFeeNumerator: BN, firstFactor: number, secondFactor: BN, thirdFactor: BN, baseFeeMode: BaseFeeMode): BaseFeeHandler;
169
+
170
+ declare function isDynamicFeeEnabled(dynamicFee: QuoteDynamicFee): boolean;
171
+ /**
172
+ * ((volatility_accumulator * bin_step)^2 * variable_fee_control + 99_999_999_999) / 100_000_000_000,
173
+ * or 0 when the dynamic fee is not initialized.
174
+ */
175
+ declare function getVariableFeeNumerator(dynamicFee: QuoteDynamicFee, volatilityTracker: QuoteVolatilityTracker): BN;
176
+
177
+ /** The fee after every period has elapsed. */
178
+ declare function getFeeSchedulerMinBaseFeeNumerator(cliffFeeNumerator: BN, numberOfPeriod: number, reductionFactor: BN, feeSchedulerMode: BaseFeeMode): BN;
179
+ /** The fee in a period, which stops decaying after numberOfPeriod. */
180
+ declare function getBaseFeeNumeratorByPeriod(cliffFeeNumerator: BN, numberOfPeriod: number, period: BN, reductionFactor: BN, feeSchedulerMode: BaseFeeMode): BN;
181
+ /** fee = cliff_fee_numerator - period * reduction_factor */
182
+ declare function getFeeNumeratorOnLinearFeeScheduler(cliffFeeNumerator: BN, reductionFactor: BN, period: number): BN;
183
+ /** fee = cliff_fee_numerator * (1 - reduction_factor / 10_000)^period in Q64 */
184
+ declare function getFeeNumeratorOnExponentialFeeScheduler(cliffFeeNumerator: BN, reductionFactor: BN, period: number): BN;
185
+ /** The fee at currentPoint, with period = (currentPoint - activationPoint) / periodFrequency. */
186
+ declare function getBaseFeeNumerator(cliffFeeNumerator: BN, numberOfPeriod: number, periodFrequency: BN, reductionFactor: BN, feeSchedulerMode: BaseFeeMode, currentPoint: BN, activationPoint: BN): BN;
187
+
188
+ /** The rate limiter only applies to quote-to-base swaps inside maxLimiterDuration after activation. */
189
+ declare function isRateLimiterApplied(currentPoint: BN, activationPoint: BN, tradeDirection: TradeDirection, maxLimiterDuration: BN, referenceAmount: BN, feeIncrementBps: BN): boolean;
190
+ declare function isZeroRateLimiter(referenceAmount: BN, maxLimiterDuration: BN, feeIncrementBps: BN): boolean;
191
+ declare function isNonZeroRateLimiter(referenceAmount: BN, maxLimiterDuration: BN, feeIncrementBps: BN): boolean;
192
+ /** Number of fee increments between the cliff fee and MAX_FEE_NUMERATOR. */
193
+ declare function getMaxIndex(cliffFeeNumerator: BN, feeIncrementBps: BN): BN;
194
+ /**
195
+ * The amounts at which the fee reaches its maximum:
196
+ * [excluded fee amount, included fee amount, whether the included amount overflowed u64].
197
+ */
198
+ declare function getCheckedAmounts(cliffFeeNumerator: BN, referenceAmount: BN, feeIncrementBps: BN): [BN, BN, boolean];
199
+ /**
200
+ * Fee numerator for an amount that excludes the fee. The included amount is
201
+ * recovered from the excluded one, so this is not exact; the program only
202
+ * requires the result to be at or above the cliff fee, and it leaves out the
203
+ * dynamic fee.
204
+ */
205
+ declare function getFeeNumeratorFromExcludedAmount(cliffFeeNumerator: BN, referenceAmount: BN, feeIncrementBps: BN, excludedFeeAmount: BN): BN;
206
+ /** Amount after the rate limiter fee for an amount that includes it. */
207
+ declare function getRateLimiterExcludedFeeAmount(cliffFeeNumerator: BN, referenceAmount: BN, feeIncrementBps: BN, includedFeeAmount: BN): BN;
208
+ /** The output of a swap of exactly the reference amount, which pays the cliff fee. */
209
+ declare function getMaxOutAmountWithMinBaseFee(cliffFeeNumerator: BN, referenceAmount: BN, feeIncrementBps: BN): BN;
210
+ /**
211
+ * Fee numerator for an amount that includes the fee. Each whole reference
212
+ * amount above the first pays one more fee increment, up to the maximum fee.
213
+ */
214
+ declare function getFeeNumeratorFromIncludedAmount(cliffFeeNumerator: BN, referenceAmount: BN, feeIncrementBps: BN, includedFeeAmount: BN): BN;
215
+
216
+ export { FeeRateLimiter, FeeScheduler, ProgramError, SafeMath, getBaseFeeHandler, getBaseFeeNumerator, getBaseFeeNumeratorByPeriod, getCheckedAmounts, getDeltaAmountBaseUnsigned, getDeltaAmountBaseUnsigned256, getDeltaAmountQuoteUnsigned, getDeltaAmountQuoteUnsigned256, getExcludedFeeAmount, getFeeMode, getFeeNumeratorFromExcludedAmount, getFeeNumeratorFromIncludedAmount, getFeeNumeratorOnExponentialFeeScheduler, getFeeNumeratorOnLinearFeeScheduler, getFeeOnAmount, getFeeSchedulerMinBaseFeeNumerator, getIncludedFeeAmount, getInitialLiquidityFromDeltaBase, getInitialLiquidityFromDeltaQuote, getMaxIndex, getMaxOutAmountWithMinBaseFee, getNextSqrtPriceFromBaseAmountInRoundingUp, getNextSqrtPriceFromBaseAmountOutRoundingUp, getNextSqrtPriceFromInput, getNextSqrtPriceFromOutput, getNextSqrtPriceFromQuoteAmountInRoundingDown, getNextSqrtPriceFromQuoteAmountOutRoundingDown, getRateLimiterExcludedFeeAmount, getTotalFeeNumerator, getTotalFeeNumeratorFromExcludedFeeAmount, getTotalFeeNumeratorFromIncludedFeeAmount, getVariableFeeNumerator, isDynamicFeeEnabled, isNonZeroRateLimiter, isRateLimiterApplied, isZeroRateLimiter, liveCurve, mulDiv, pow, splitFees, sqrt, toNumerator };
package/dist/math.d.ts ADDED
@@ -0,0 +1,216 @@
1
+ import BN from 'bn.js';
2
+ import { aY as Rounding, j as CollectFeeMode, b4 as TradeDirection, aF as FeeMode, aG as FeeOnAmountResult, aS as QuoteDynamicFee, aW as QuoteVolatilityTracker, aU as QuotePoolFees, au as BaseFeeHandler, ac as BaseFeeMode } from './swapQuote-CURAm57K.js';
3
+ export { aq as EpochTransferFee, bf as SwapAmountFromOutput, b5 as TransferFeeAmount, bg as calculateBaseToQuoteFromAmountIn, bh as calculateBaseToQuoteFromAmountOut, bi as calculateQuoteToBaseFromAmountIn, bj as calculateQuoteToBaseFromAmountOut, ba as calculateTransferFeeExcludedAmount, bb as calculateTransferFeeIncludedAmount, bk as getBaseTransferFee, bl as getEpochTransferFee, bm as getSwapResult, bn as getSwapResultFromExactInput, bo as getSwapResultFromExactOutput, bp as getSwapResultFromPartialInput, bc as isZeroTransferFee, bd as resolveSwapTransferFees } from './swapQuote-CURAm57K.js';
4
+ import '@solana/spl-token';
5
+ import '@coral-xyz/anchor';
6
+ import '@solana/web3.js';
7
+
8
+ /** L = Δb / (√P_upper - √P_lower), rounded down, bounded by u128. */
9
+ declare function getInitialLiquidityFromDeltaQuote(quoteAmount: BN, sqrtMinPrice: BN, sqrtPrice: BN): BN;
10
+ /** L = Δa * √P_lower * √P_upper / (√P_upper - √P_lower), rounded down. */
11
+ declare function getInitialLiquidityFromDeltaBase(baseAmount: BN, sqrtMaxPrice: BN, sqrtPrice: BN): BN;
12
+ /** Δa = L * (√P_upper - √P_lower) / (√P_upper * √P_lower), bounded by u64. */
13
+ declare function getDeltaAmountBaseUnsigned(lowerSqrtPrice: BN, upperSqrtPrice: BN, liquidity: BN, round: Rounding): BN;
14
+ /** Δa = L * (√P_upper - √P_lower) / (√P_upper * √P_lower), unbounded. */
15
+ declare function getDeltaAmountBaseUnsigned256(lowerSqrtPrice: BN, upperSqrtPrice: BN, liquidity: BN, round: Rounding): BN;
16
+ /** Δb = L * (√P_upper - √P_lower), bounded by u64. */
17
+ declare function getDeltaAmountQuoteUnsigned(lowerSqrtPrice: BN, upperSqrtPrice: BN, liquidity: BN, round: Rounding): BN;
18
+ /** Δb = L * (√P_upper - √P_lower), unbounded. */
19
+ declare function getDeltaAmountQuoteUnsigned256(lowerSqrtPrice: BN, upperSqrtPrice: BN, liquidity: BN, round: Rounding): BN;
20
+ /** Next sqrt price after amountIn of base (baseForQuote) or quote enters the segment. */
21
+ declare function getNextSqrtPriceFromInput(sqrtPrice: BN, liquidity: BN, amountIn: BN, baseForQuote: boolean): BN;
22
+ /** Next sqrt price after amountOut of quote (baseForQuote) or base leaves the segment. */
23
+ declare function getNextSqrtPriceFromOutput(sqrtPrice: BN, liquidity: BN, amountOut: BN, baseForQuote: boolean): BN;
24
+ /** √P' = √P - ceil(Δy / L) */
25
+ declare function getNextSqrtPriceFromQuoteAmountOutRoundingDown(sqrtPrice: BN, liquidity: BN, amount: BN): BN;
26
+ /** √P' = √P * L / (L - Δx * √P), rounded up */
27
+ declare function getNextSqrtPriceFromBaseAmountOutRoundingUp(sqrtPrice: BN, liquidity: BN, amount: BN): BN;
28
+ /**
29
+ * √P' = √P * L / (L + Δx * √P), rounded up so an exact output is met and an
30
+ * exact input does not move the price further than necessary.
31
+ */
32
+ declare function getNextSqrtPriceFromBaseAmountInRoundingUp(sqrtPrice: BN, liquidity: BN, amount: BN): BN;
33
+ /**
34
+ * √P' = √P + Δy / L, rounded down so an exact output is met and an exact
35
+ * input does not move the price further than necessary.
36
+ */
37
+ declare function getNextSqrtPriceFromQuoteAmountInRoundingDown(sqrtPrice: BN, liquidity: BN, amount: BN): BN;
38
+ /**
39
+ * The points of a stored curve up to the first zero point. PoolConfig.curve
40
+ * holds MAX_CURVE_POINT entries and the unused ones are zero; the program
41
+ * stops at the first of them.
42
+ */
43
+ declare function liveCurve<T extends {
44
+ sqrtPrice: BN;
45
+ liquidity: BN;
46
+ }>(curve: T[]): T[];
47
+
48
+ declare const ProgramError: {
49
+ readonly MathOverflow: "Math operation overflow";
50
+ readonly ExceededSlippage: "Exceeded slippage tolerance";
51
+ readonly ExceedMaxFeeBps: "Exceeded max fee bps";
52
+ readonly AmountIsZero: "Amount is zero";
53
+ readonly TypeCastFailed: "Type cast error";
54
+ readonly InvalidActivationType: "Invalid activation type";
55
+ readonly InvalidQuoteMint: "Invalid quote mint";
56
+ readonly InvalidCollectFeeMode: "Invalid collect fee mode";
57
+ readonly InvalidMigrationFeeOption: "Invalid migration fee option";
58
+ readonly InvalidInput: "Invalid input";
59
+ readonly NotEnoughLiquidity: "Not enough liquidity";
60
+ readonly PoolIsCompleted: "Pool is completed";
61
+ readonly InvalidMigrationOption: "Invalid migration option";
62
+ readonly InvalidTokenDecimals: "Invalid token decimals";
63
+ readonly InvalidTokenType: "Invalid token type";
64
+ readonly InvalidQuoteThreshold: "Invalid quote threshold";
65
+ readonly InvalidTokenSupply: "Invalid token supply";
66
+ readonly InvalidCurve: "Invalid curve";
67
+ readonly InvalidVestingParameters: "Invalid vesting parameters";
68
+ readonly InsufficientLiquidity: "Liquidity in bonding curve is insufficient";
69
+ readonly InvalidFeeScheduler: "Invalid fee scheduler";
70
+ readonly InvalidCreatorTradingFeePercentage: "Invalid creator trading fee percentage";
71
+ readonly InvalidBaseFeeMode: "Invalid base fee mode";
72
+ readonly InvalidFeeRateLimiter: "Invalid fee rate limiter";
73
+ readonly InvalidMigratedPoolFee: "Invalid migrated pool fee params";
74
+ readonly UndeterminedError: "Undetermined error";
75
+ readonly AmountLeftIsNotZero: "Amount left is not zero";
76
+ readonly InvalidPoolCreationFee: "Invalid pool creation fee";
77
+ readonly InvalidFeeMarketCapScheduler: "Invalid fee market cap scheduler";
78
+ readonly DeprecatedBaseFeeMode: "Deprecated base fee mode";
79
+ readonly QuoteMintHasNonZeroTransferFee: "Quote mint has a non zero transfer fee or a live transfer fee config authority";
80
+ readonly DeprecatedMigrationOption: "Deprecated migration option";
81
+ readonly FeeInverseIsIncorrect: "Transfer fee inverse calculation is incorrect";
82
+ readonly InvalidTransferFeeParameters: "Invalid transfer fee parameters";
83
+ readonly ExceededInputAmount: "Required input amount exceeds the provided amount in";
84
+ readonly InvalidFeeClaimer: "Invalid fee claimer";
85
+ };
86
+
87
+ /**
88
+ * [amount after the fee, fee], with the fee rounded up;
89
+ * the program's PoolFeesConfig::get_excluded_fee_amount.
90
+ */
91
+ declare function getExcludedFeeAmount(tradeFeeNumerator: BN, includedFeeAmount: BN): [BN, BN];
92
+ /**
93
+ * [amount before the fee, fee], rounded up and bounded by u64;
94
+ * the program's PoolFeesConfig::get_included_fee_amount.
95
+ */
96
+ declare function getIncludedFeeAmount(tradeFeeNumerator: BN, excludedFeeAmount: BN): [BN, BN];
97
+
98
+ /** Which side of a swap the fee is taken from; the program's FeeMode::get_fee_mode. */
99
+ declare function getFeeMode(collectFeeMode: CollectFeeMode, tradeDirection: TradeDirection, hasReferral: boolean): FeeMode;
100
+ /** Base plus dynamic fee numerator for an amount that includes the fee. */
101
+ declare function getTotalFeeNumeratorFromIncludedFeeAmount(poolFees: QuotePoolFees, volatilityTracker: QuoteVolatilityTracker, currentPoint: BN, activationPoint: BN, includedFeeAmount: BN, tradeDirection: TradeDirection): BN;
102
+ /** Base plus dynamic fee numerator for an amount that excludes the fee. */
103
+ declare function getTotalFeeNumeratorFromExcludedFeeAmount(poolFees: QuotePoolFees, volatilityTracker: QuoteVolatilityTracker, currentPoint: BN, activationPoint: BN, excludedFeeAmount: BN, tradeDirection: TradeDirection): BN;
104
+ /** Base plus dynamic fee numerator, capped at MAX_FEE_NUMERATOR. */
105
+ declare function getTotalFeeNumerator(baseFeeNumerator: BN, dynamicFee: QuoteDynamicFee, volatilityTracker: QuoteVolatilityTracker): BN;
106
+ /** Take the fee out of an amount and split it; the program's get_fee_on_amount. */
107
+ declare function getFeeOnAmount(tradeFeeNumerator: BN, amount: BN, hasReferral: boolean): FeeOnAmountResult;
108
+ /**
109
+ * [trading fee, protocol fee, referral fee]: the protocol takes
110
+ * PROTOCOL_FEE_PERCENT of the fee and the referrer HOST_FEE_PERCENT of that,
111
+ * both rounded down.
112
+ */
113
+ declare function splitFees(feeAmount: BN, hasReferral: boolean): [BN, BN, BN];
114
+
115
+ /**
116
+ * The program's safe_math on BN. BN is arbitrary precision, so only
117
+ * subtraction and division can fail here; the u64 and u128 bounds are
118
+ * checked by the callers.
119
+ */
120
+ declare class SafeMath {
121
+ static add(a: BN, b: BN): BN;
122
+ static sub(a: BN, b: BN): BN;
123
+ static mul(a: BN, b: BN): BN;
124
+ static div(a: BN, b: BN): BN;
125
+ static shl(a: BN, b: number): BN;
126
+ static shr(a: BN, b: number): BN;
127
+ }
128
+ /**
129
+ * Q64 power, matching the program. A base at or above 1 is inverted through
130
+ * u128::MAX so each multiplication stays inside u128.
131
+ */
132
+ declare function pow(base: BN, exponent: BN, scaling?: boolean): BN;
133
+
134
+ /** (x * y) / denominator with the given rounding; the program's mul_div. */
135
+ declare function mulDiv(x: BN, y: BN, denominator: BN, rounding: Rounding): BN;
136
+ /** bps * feeDenominator / 10_000, rounded down; the program's to_numerator. */
137
+ declare function toNumerator(bps: BN, feeDenominator: BN): BN;
138
+ /** Integer square root by Newton's method, rounded down; the program's sqrt_u256. */
139
+ declare function sqrt(value: BN): BN;
140
+
141
+ declare class FeeRateLimiter implements BaseFeeHandler {
142
+ cliffFeeNumerator: BN;
143
+ feeIncrementBps: number;
144
+ maxLimiterDuration: BN;
145
+ referenceAmount: BN;
146
+ constructor(cliffFeeNumerator: BN, feeIncrementBps: number, maxLimiterDuration: BN, referenceAmount: BN);
147
+ getMinBaseFeeNumerator(): BN;
148
+ private isApplied;
149
+ getBaseFeeNumeratorFromIncludedFeeAmount(currentPoint: BN, activationPoint: BN, tradeDirection: TradeDirection, includedFeeAmount: BN): BN;
150
+ getBaseFeeNumeratorFromExcludedFeeAmount(currentPoint: BN, activationPoint: BN, tradeDirection: TradeDirection, excludedFeeAmount: BN): BN;
151
+ }
152
+ declare class FeeScheduler implements BaseFeeHandler {
153
+ cliffFeeNumerator: BN;
154
+ numberOfPeriod: number;
155
+ periodFrequency: BN;
156
+ reductionFactor: BN;
157
+ feeSchedulerMode: BaseFeeMode;
158
+ constructor(cliffFeeNumerator: BN, numberOfPeriod: number, periodFrequency: BN, reductionFactor: BN, feeSchedulerMode: BaseFeeMode);
159
+ getMinBaseFeeNumerator(): BN;
160
+ getBaseFeeNumeratorFromIncludedFeeAmount(currentPoint: BN, activationPoint: BN): BN;
161
+ getBaseFeeNumeratorFromExcludedFeeAmount(currentPoint: BN, activationPoint: BN): BN;
162
+ }
163
+ /**
164
+ * The handler for a base fee config. The factors are the scheduler's
165
+ * numberOfPeriod, periodFrequency and reductionFactor, or the rate limiter's
166
+ * feeIncrementBps, maxLimiterDuration and referenceAmount.
167
+ */
168
+ declare function getBaseFeeHandler(cliffFeeNumerator: BN, firstFactor: number, secondFactor: BN, thirdFactor: BN, baseFeeMode: BaseFeeMode): BaseFeeHandler;
169
+
170
+ declare function isDynamicFeeEnabled(dynamicFee: QuoteDynamicFee): boolean;
171
+ /**
172
+ * ((volatility_accumulator * bin_step)^2 * variable_fee_control + 99_999_999_999) / 100_000_000_000,
173
+ * or 0 when the dynamic fee is not initialized.
174
+ */
175
+ declare function getVariableFeeNumerator(dynamicFee: QuoteDynamicFee, volatilityTracker: QuoteVolatilityTracker): BN;
176
+
177
+ /** The fee after every period has elapsed. */
178
+ declare function getFeeSchedulerMinBaseFeeNumerator(cliffFeeNumerator: BN, numberOfPeriod: number, reductionFactor: BN, feeSchedulerMode: BaseFeeMode): BN;
179
+ /** The fee in a period, which stops decaying after numberOfPeriod. */
180
+ declare function getBaseFeeNumeratorByPeriod(cliffFeeNumerator: BN, numberOfPeriod: number, period: BN, reductionFactor: BN, feeSchedulerMode: BaseFeeMode): BN;
181
+ /** fee = cliff_fee_numerator - period * reduction_factor */
182
+ declare function getFeeNumeratorOnLinearFeeScheduler(cliffFeeNumerator: BN, reductionFactor: BN, period: number): BN;
183
+ /** fee = cliff_fee_numerator * (1 - reduction_factor / 10_000)^period in Q64 */
184
+ declare function getFeeNumeratorOnExponentialFeeScheduler(cliffFeeNumerator: BN, reductionFactor: BN, period: number): BN;
185
+ /** The fee at currentPoint, with period = (currentPoint - activationPoint) / periodFrequency. */
186
+ declare function getBaseFeeNumerator(cliffFeeNumerator: BN, numberOfPeriod: number, periodFrequency: BN, reductionFactor: BN, feeSchedulerMode: BaseFeeMode, currentPoint: BN, activationPoint: BN): BN;
187
+
188
+ /** The rate limiter only applies to quote-to-base swaps inside maxLimiterDuration after activation. */
189
+ declare function isRateLimiterApplied(currentPoint: BN, activationPoint: BN, tradeDirection: TradeDirection, maxLimiterDuration: BN, referenceAmount: BN, feeIncrementBps: BN): boolean;
190
+ declare function isZeroRateLimiter(referenceAmount: BN, maxLimiterDuration: BN, feeIncrementBps: BN): boolean;
191
+ declare function isNonZeroRateLimiter(referenceAmount: BN, maxLimiterDuration: BN, feeIncrementBps: BN): boolean;
192
+ /** Number of fee increments between the cliff fee and MAX_FEE_NUMERATOR. */
193
+ declare function getMaxIndex(cliffFeeNumerator: BN, feeIncrementBps: BN): BN;
194
+ /**
195
+ * The amounts at which the fee reaches its maximum:
196
+ * [excluded fee amount, included fee amount, whether the included amount overflowed u64].
197
+ */
198
+ declare function getCheckedAmounts(cliffFeeNumerator: BN, referenceAmount: BN, feeIncrementBps: BN): [BN, BN, boolean];
199
+ /**
200
+ * Fee numerator for an amount that excludes the fee. The included amount is
201
+ * recovered from the excluded one, so this is not exact; the program only
202
+ * requires the result to be at or above the cliff fee, and it leaves out the
203
+ * dynamic fee.
204
+ */
205
+ declare function getFeeNumeratorFromExcludedAmount(cliffFeeNumerator: BN, referenceAmount: BN, feeIncrementBps: BN, excludedFeeAmount: BN): BN;
206
+ /** Amount after the rate limiter fee for an amount that includes it. */
207
+ declare function getRateLimiterExcludedFeeAmount(cliffFeeNumerator: BN, referenceAmount: BN, feeIncrementBps: BN, includedFeeAmount: BN): BN;
208
+ /** The output of a swap of exactly the reference amount, which pays the cliff fee. */
209
+ declare function getMaxOutAmountWithMinBaseFee(cliffFeeNumerator: BN, referenceAmount: BN, feeIncrementBps: BN): BN;
210
+ /**
211
+ * Fee numerator for an amount that includes the fee. Each whole reference
212
+ * amount above the first pays one more fee increment, up to the maximum fee.
213
+ */
214
+ declare function getFeeNumeratorFromIncludedAmount(cliffFeeNumerator: BN, referenceAmount: BN, feeIncrementBps: BN, includedFeeAmount: BN): BN;
215
+
216
+ export { FeeRateLimiter, FeeScheduler, ProgramError, SafeMath, getBaseFeeHandler, getBaseFeeNumerator, getBaseFeeNumeratorByPeriod, getCheckedAmounts, getDeltaAmountBaseUnsigned, getDeltaAmountBaseUnsigned256, getDeltaAmountQuoteUnsigned, getDeltaAmountQuoteUnsigned256, getExcludedFeeAmount, getFeeMode, getFeeNumeratorFromExcludedAmount, getFeeNumeratorFromIncludedAmount, getFeeNumeratorOnExponentialFeeScheduler, getFeeNumeratorOnLinearFeeScheduler, getFeeOnAmount, getFeeSchedulerMinBaseFeeNumerator, getIncludedFeeAmount, getInitialLiquidityFromDeltaBase, getInitialLiquidityFromDeltaQuote, getMaxIndex, getMaxOutAmountWithMinBaseFee, getNextSqrtPriceFromBaseAmountInRoundingUp, getNextSqrtPriceFromBaseAmountOutRoundingUp, getNextSqrtPriceFromInput, getNextSqrtPriceFromOutput, getNextSqrtPriceFromQuoteAmountInRoundingDown, getNextSqrtPriceFromQuoteAmountOutRoundingDown, getRateLimiterExcludedFeeAmount, getTotalFeeNumerator, getTotalFeeNumeratorFromExcludedFeeAmount, getTotalFeeNumeratorFromIncludedFeeAmount, getVariableFeeNumerator, isDynamicFeeEnabled, isNonZeroRateLimiter, isRateLimiterApplied, isZeroRateLimiter, liveCurve, mulDiv, pow, splitFees, sqrt, toNumerator };