@orca-so/whirlpools-core 2.0.0 → 3.1.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.
@@ -1,191 +1,136 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+ export function _TICK_ARRAY_SIZE(): number;
4
+ export function _FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD(): number;
5
+ export function _MIN_TICK_INDEX(): number;
6
+ export function _MAX_TICK_INDEX(): number;
3
7
  /**
4
- * Check if the whirlpool is initialized with adaptive fee
5
- *
6
- * # Paramters
7
- * - `whirlpool`: The whirlpool state
8
- *
9
- * # Returns
10
- * - A boolean value indicating if the whirlpool is initialized with adaptive fee
11
- */
12
- export function isInitializedWithAdaptiveFee(whirlpool: WhirlpoolFacade): boolean;
13
- /**
14
- * Calculate the amount A delta between two sqrt_prices
8
+ * Convert a price into a sqrt priceX64
9
+ * IMPORTANT: floating point operations can reduce the precision of the result.
10
+ * Make sure to do these operations last and not to use the result for further calculations.
15
11
  *
16
12
  * # Parameters
17
- * - `sqrt_price_1`: The first square root price
18
- * - `sqrt_price_2`: The second square root price
19
- * - `liquidity`: The liquidity
20
- * - `round_up`: Whether to round up or not
13
+ * * `price` - The price to convert
14
+ * * `decimals_a` - The number of decimals of the base token
15
+ * * `decimals_b` - The number of decimals of the quote token
21
16
  *
22
17
  * # Returns
23
- * - `u64`: The amount delta
18
+ * * `u128` - The sqrt priceX64
24
19
  */
25
- export function tryGetAmountDeltaA(sqrt_price_1: bigint, sqrt_price_2: bigint, liquidity: bigint, round_up: boolean): bigint;
20
+ export function priceToSqrtPrice(price: number, decimals_a: number, decimals_b: number): bigint;
26
21
  /**
27
- * Calculate the amount B delta between two sqrt_prices
22
+ * Convert a sqrt priceX64 into a tick index
23
+ * IMPORTANT: floating point operations can reduce the precision of the result.
24
+ * Make sure to do these operations last and not to use the result for further calculations.
28
25
  *
29
26
  * # Parameters
30
- * - `sqrt_price_1`: The first square root price
31
- * - `sqrt_price_2`: The second square root price
32
- * - `liquidity`: The liquidity
33
- * - `round_up`: Whether to round up or not
27
+ * * `sqrt_price` - The sqrt priceX64 to convert
28
+ * * `decimals_a` - The number of decimals of the base token
29
+ * * `decimals_b` - The number of decimals of the quote token
34
30
  *
35
31
  * # Returns
36
- * - `u64`: The amount delta
32
+ * * `f64` - The decimal price
37
33
  */
38
- export function tryGetAmountDeltaB(sqrt_price_1: bigint, sqrt_price_2: bigint, liquidity: bigint, round_up: boolean): bigint;
34
+ export function sqrtPriceToPrice(sqrt_price: bigint, decimals_a: number, decimals_b: number): number;
39
35
  /**
40
- * Calculate the next square root price
36
+ * Invert a price
37
+ * IMPORTANT: floating point operations can reduce the precision of the result.
38
+ * Make sure to do these operations last and not to use the result for further calculations.
41
39
  *
42
40
  * # Parameters
43
- * - `current_sqrt_price`: The current square root price
44
- * - `current_liquidity`: The current liquidity
45
- * - `amount`: The amount
46
- * - `specified_input`: Whether the input is specified
41
+ * * `price` - The price to invert
42
+ * * `decimals_a` - The number of decimals of the base token
43
+ * * `decimals_b` - The number of decimals of the quote token
47
44
  *
48
45
  * # Returns
49
- * - `u128`: The next square root price
46
+ * * `f64` - The inverted price
50
47
  */
51
- export function tryGetNextSqrtPriceFromA(current_sqrt_price: bigint, current_liquidity: bigint, amount: bigint, specified_input: boolean): bigint;
48
+ export function invertPrice(price: number, decimals_a: number, decimals_b: number): number;
52
49
  /**
53
- * Calculate the next square root price
50
+ * Convert a tick index into a price
51
+ * IMPORTANT: floating point operations can reduce the precision of the result.
52
+ * Make sure to do these operations last and not to use the result for further calculations.
54
53
  *
55
54
  * # Parameters
56
- * - `current_sqrt_price`: The current square root price
57
- * - `current_liquidity`: The current liquidity
58
- * - `amount`: The amount
59
- * - `specified_input`: Whether the input is specified
55
+ * * `tick_index` - The tick index to convert
56
+ * * `decimals_a` - The number of decimals of the base token
57
+ * * `decimals_b` - The number of decimals of the quote token
60
58
  *
61
59
  * # Returns
62
- * - `u128`: The next square root price
60
+ * * `f64` - The decimal price
63
61
  */
64
- export function tryGetNextSqrtPriceFromB(current_sqrt_price: bigint, current_liquidity: bigint, amount: bigint, specified_input: boolean): bigint;
62
+ export function tickIndexToPrice(tick_index: number, decimals_a: number, decimals_b: number): number;
65
63
  /**
66
- * Apply a transfer fee to an amount
67
- * e.g. You send 10000 amount with 100 fee rate. The fee amount will be 100.
68
- * So the amount after fee will be 9900.
64
+ * Convert a price into a tick index
65
+ * IMPORTANT: floating point operations can reduce the precision of the result.
66
+ * Make sure to do these operations last and not to use the result for further calculations.
69
67
  *
70
68
  * # Parameters
71
- * - `amount`: The amount to apply the fee to
72
- * - `transfer_fee`: The transfer fee to apply
69
+ * * `price` - The price to convert
70
+ * * `decimals_a` - The number of decimals of the base token
71
+ * * `decimals_b` - The number of decimals of the quote token
73
72
  *
74
73
  * # Returns
75
- * - `u64`: The amount after the fee has been applied
74
+ * * `i32` - The tick index
76
75
  */
77
- export function tryApplyTransferFee(amount: bigint, transfer_fee: TransferFee): bigint;
76
+ export function priceToTickIndex(price: number, decimals_a: number, decimals_b: number): number;
78
77
  /**
79
- * Reverse the application of a transfer fee to an amount
80
- * e.g. You received 9900 amount with 100 fee rate. The fee amount will be 100.
81
- * So the amount before fee will be 10000.
78
+ * Computes min/max sqrt-price bounds for slippage protection.
82
79
  *
83
- * # Parameters
84
- * - `amount`: The amount to reverse the fee from
85
- * - `transfer_fee`: The transfer fee to reverse
86
- *
87
- * # Returns
88
- * - `u64`: The amount before the fee has been applied
89
- */
90
- export function tryReverseApplyTransferFee(amount: bigint, transfer_fee: TransferFee): bigint;
91
- /**
92
- * Get the maximum amount with a slippage tolerance
93
- * e.g. Your estimated amount you send is 10000 with 100 slippage tolerance. The max you send will be 10100.
80
+ * Cap: `slippage_tolerance_bps` is clamped to BPS_DENOMINATOR (10_000) so the radicands
81
+ * `(10000 ± bps)` stay non-negative and we never take sqrt of a negative.
94
82
  *
95
83
  * # Parameters
96
- * - `amount`: The amount to apply the fee to
97
- * - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
84
+ * * `sqrt_price` - The current sqrt priceX64
85
+ * * `slippage_tolerance_bps` - The slippage tolerance in basis points
98
86
  *
99
87
  * # Returns
100
- * - `u64`: The maximum amount
88
+ * * `SqrtPriceSlippageBounds` - The min and max sqrt price bounds
101
89
  */
102
- export function tryGetMaxAmountWithSlippageTolerance(amount: bigint, slippage_tolerance_bps: number): bigint;
90
+ export function getSqrtPriceSlippageBounds(sqrt_price: bigint, slippage_tolerance_bps: number): SqrtPriceSlippageBounds;
91
+ export function _POSITION_BUNDLE_SIZE(): number;
92
+ export function _FEE_RATE_DENOMINATOR(): number;
103
93
  /**
104
- * Get the minimum amount with a slippage tolerance
105
- * e.g. Your estimated amount you receive is 10000 with 100 slippage tolerance. The min amount you receive will be 9900.
94
+ * Check if a position is in range.
95
+ * When a position is in range it is earning fees and rewards
106
96
  *
107
97
  * # Parameters
108
- * - `amount`: The amount to apply the fee to
109
- * - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
98
+ * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
99
+ * - `tick_index_1` - A i32 integer representing the first tick index of the position
100
+ * - `tick_index_2` - A i32 integer representing the second tick index of the position
110
101
  *
111
102
  * # Returns
112
- * - `u64`: The minimum amount
103
+ * - A boolean value indicating if the position is in range
113
104
  */
114
- export function tryGetMinAmountWithSlippageTolerance(amount: bigint, slippage_tolerance_bps: number): bigint;
105
+ export function isPositionInRange(current_sqrt_price: bigint, tick_index_1: number, tick_index_2: number): boolean;
115
106
  /**
116
- * Apply a swap fee to an amount
117
- * e.g. You send 10000 amount with 10000 fee rate. The fee amount will be 100.
118
- * So the amount after fee will be 9900.
107
+ * Calculate the status of a position
108
+ * The status can be one of three values:
109
+ * - InRange: The position is in range
110
+ * - BelowRange: The position is below the range
111
+ * - AboveRange: The position is above the range
119
112
  *
120
113
  * # Parameters
121
- * - `amount`: The amount to apply the fee to
122
- * - `fee_rate`: The fee rate to apply denominated in 1e6
114
+ * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
115
+ * - `tick_index_1` - A i32 integer representing the first tick index of the position
116
+ * - `tick_index_2` - A i32 integer representing the second tick index of the position
123
117
  *
124
118
  * # Returns
125
- * - `u64`: The amount after the fee has been applied
119
+ * - A PositionStatus enum value indicating the status of the position
126
120
  */
127
- export function tryApplySwapFee(amount: bigint, fee_rate: number): bigint;
121
+ export function positionStatus(current_sqrt_price: bigint, tick_index_1: number, tick_index_2: number): PositionStatus;
128
122
  /**
129
- * Reverse the application of a swap fee to an amount
130
- * e.g. You received 9900 amount with 10000 fee rate. The fee amount will be 100.
131
- * So the amount before fee will be 10000.
123
+ * Calculate the token_a / token_b ratio of a (ficticious) position
132
124
  *
133
125
  * # Parameters
134
- * - `amount`: The amount to reverse the fee from
135
- * - `fee_rate`: The fee rate to reverse denominated in 1e6
136
- *
137
- * # Returns
138
- * - `u64`: The amount before the fee has been applied
139
- */
140
- export function tryReverseApplySwapFee(amount: bigint, fee_rate: number): bigint;
141
- /**
142
- * Calculate rewards owed for a position
143
- *
144
- * # Paramters
145
- * - `whirlpool`: The whirlpool state
146
- * - `position`: The position state
147
- * - `tick_lower`: The lower tick state
148
- * - `tick_upper`: The upper tick state
149
- * - `current_timestamp`: The current timestamp
150
- * - `transfer_fee_1`: The transfer fee for token 1
151
- * - `transfer_fee_2`: The transfer fee for token 2
152
- * - `transfer_fee_3`: The transfer fee for token 3
153
- *
154
- * # Returns
155
- * - `CollectRewardsQuote`: The rewards owed for the 3 reward tokens.
156
- */
157
- export function collectRewardsQuote(whirlpool: WhirlpoolFacade, position: PositionFacade, tick_lower: TickFacade, tick_upper: TickFacade, current_timestamp: bigint, transfer_fee_1?: TransferFee | null, transfer_fee_2?: TransferFee | null, transfer_fee_3?: TransferFee | null): CollectRewardsQuote;
158
- /**
159
- * Get the first unoccupied position in a bundle
160
- *
161
- * # Arguments
162
- * * `bundle` - The bundle to check
163
- *
164
- * # Returns
165
- * * `u32` - The first unoccupied position (None if full)
166
- */
167
- export function firstUnoccupiedPositionInBundle(bitmap: Uint8Array): number | undefined;
168
- /**
169
- * Check whether a position bundle is full
170
- * A position bundle can contain 256 positions
171
- *
172
- * # Arguments
173
- * * `bundle` - The bundle to check
174
- *
175
- * # Returns
176
- * * `bool` - Whether the bundle is full
177
- */
178
- export function isPositionBundleFull(bitmap: Uint8Array): boolean;
179
- /**
180
- * Check whether a position bundle is empty
181
- *
182
- * # Arguments
183
- * * `bundle` - The bundle to check
126
+ * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
127
+ * - `tick_index_1` - A i32 integer representing the first tick index of the position
128
+ * - `tick_index_2` - A i32 integer representing the second tick index of the position
184
129
  *
185
130
  * # Returns
186
- * * `bool` - Whether the bundle is empty
131
+ * - A PositionRatio struct containing the ratio of token_a and token_b
187
132
  */
188
- export function isPositionBundleEmpty(bitmap: Uint8Array): boolean;
133
+ export function positionRatio(current_sqrt_price: bigint, tick_index_1: number, tick_index_2: number): PositionRatio;
189
134
  /**
190
135
  * Get the first tick index in the tick array that contains the specified tick index.
191
136
  *
@@ -211,6 +156,7 @@ export function tickIndexToSqrtPrice(tick_index: number): bigint;
211
156
  /**
212
157
  * Derive the tick index from a sqrt price. The precision of this method is only guarranted
213
158
  * if tick is within the bounds of {max, min} tick-index.
159
+ * This function will make panic for zero sqrt price.
214
160
  *
215
161
  * # Parameters
216
162
  * - `sqrt_price` - A u128 integer representing the sqrt price
@@ -229,7 +175,7 @@ export function sqrtPriceToTickIndex(sqrt_price: bigint): number;
229
175
  * - `round_up` - A boolean value indicating if the supplied tick index should be rounded up. None will round to the nearest.
230
176
  *
231
177
  * # Returns
232
- * - A i32 integer representing the previous initializable tick index
178
+ * - A i32 representing the initializable tick index (rounded per round_up or nearest).
233
179
  */
234
180
  export function getInitializableTickIndex(tick_index: number, tick_spacing: number, round_up?: boolean | null): number;
235
181
  /**
@@ -345,145 +291,229 @@ export function isFullRangeOnly(tick_spacing: number): boolean;
345
291
  * - A u32 integer representing the tick index in the tick array
346
292
  */
347
293
  export function getTickIndexInArray(tick_index: number, tick_array_start_index: number, tick_spacing: number): number;
348
- export function _VOLATILITY_ACCUMULATOR_SCALE_FACTOR(): number;
349
- export function _REDUCTION_FACTOR_DENOMINATOR(): number;
350
- export function _ADAPTIVE_FEE_CONTROL_FACTOR_DENOMINATOR(): number;
351
- export function _MAX_REFERENCE_AGE(): bigint;
352
- export function _FEE_RATE_HARD_LIMIT(): number;
353
- export function _POSITION_BUNDLE_SIZE(): number;
354
- export function _TICK_ARRAY_NOT_EVENLY_SPACED(): string;
355
- export function _TICK_INDEX_OUT_OF_BOUNDS(): string;
356
- export function _INVALID_TICK_INDEX(): string;
357
- export function _ARITHMETIC_OVERFLOW(): string;
358
- export function _AMOUNT_EXCEEDS_MAX_U64(): string;
359
- export function _SQRT_PRICE_OUT_OF_BOUNDS(): string;
360
- export function _TICK_SEQUENCE_EMPTY(): string;
361
- export function _SQRT_PRICE_LIMIT_OUT_OF_BOUNDS(): string;
362
- export function _INVALID_SQRT_PRICE_LIMIT_DIRECTION(): string;
363
- export function _ZERO_TRADABLE_AMOUNT(): string;
364
- export function _INVALID_TIMESTAMP(): string;
365
- export function _INVALID_TRANSFER_FEE(): string;
366
- export function _INVALID_SLIPPAGE_TOLERANCE(): string;
367
- export function _TICK_INDEX_NOT_IN_ARRAY(): string;
368
- export function _INVALID_TICK_ARRAY_SEQUENCE(): string;
369
- export function _INVALID_ADAPTIVE_FEE_INFO(): string;
370
- export function _NUM_REWARDS(): number;
371
- export function _FEE_RATE_DENOMINATOR(): number;
372
- export function _TICK_ARRAY_SIZE(): number;
373
- export function _FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD(): number;
374
- export function _MIN_TICK_INDEX(): number;
375
- export function _MAX_TICK_INDEX(): number;
376
294
  /**
377
- * Check if a position is in range.
378
- * When a position is in range it is earning fees and rewards
295
+ * Calculate the amount A delta between two sqrt_prices
296
+ *
297
+ * # Parameters
298
+ * - `sqrt_price_1`: The first square root price
299
+ * - `sqrt_price_2`: The second square root price
300
+ * - `liquidity`: The liquidity
301
+ * - `round_up`: Whether to round up or not
302
+ *
303
+ * # Returns
304
+ * - `u64`: The amount delta
305
+ */
306
+ export function tryGetAmountDeltaA(sqrt_price_1: bigint, sqrt_price_2: bigint, liquidity: bigint, round_up: boolean): bigint;
307
+ /**
308
+ * Calculate the amount B delta between two sqrt_prices
309
+ *
310
+ * # Parameters
311
+ * - `sqrt_price_1`: The first square root price
312
+ * - `sqrt_price_2`: The second square root price
313
+ * - `liquidity`: The liquidity
314
+ * - `round_up`: Whether to round up or not
315
+ *
316
+ * # Returns
317
+ * - `u64`: The amount delta
318
+ */
319
+ export function tryGetAmountDeltaB(sqrt_price_1: bigint, sqrt_price_2: bigint, liquidity: bigint, round_up: boolean): bigint;
320
+ /**
321
+ * Calculate the next square root price
322
+ *
323
+ * # Parameters
324
+ * - `current_sqrt_price`: The current square root price
325
+ * - `current_liquidity`: The current liquidity
326
+ * - `amount`: The amount
327
+ * - `specified_input`: Whether the input is specified
328
+ *
329
+ * # Returns
330
+ * - `u128`: The next square root price
331
+ */
332
+ export function tryGetNextSqrtPriceFromA(current_sqrt_price: bigint, current_liquidity: bigint, amount: bigint, specified_input: boolean): bigint;
333
+ /**
334
+ * Calculate the next square root price
335
+ *
336
+ * # Parameters
337
+ * - `current_sqrt_price`: The current square root price
338
+ * - `current_liquidity`: The current liquidity
339
+ * - `amount`: The amount
340
+ * - `specified_input`: Whether the input is specified
341
+ *
342
+ * # Returns
343
+ * - `u128`: The next square root price
344
+ */
345
+ export function tryGetNextSqrtPriceFromB(current_sqrt_price: bigint, current_liquidity: bigint, amount: bigint, specified_input: boolean): bigint;
346
+ /**
347
+ * Apply a transfer fee to an amount
348
+ * e.g. You send 10000 amount with 100 fee rate. The fee amount will be 100.
349
+ * So the amount after fee will be 9900.
350
+ *
351
+ * # Parameters
352
+ * - `amount`: The amount to apply the fee to
353
+ * - `transfer_fee`: The transfer fee to apply
354
+ *
355
+ * # Returns
356
+ * - `u64`: The amount after the fee has been applied
357
+ */
358
+ export function tryApplyTransferFee(amount: bigint, transfer_fee: TransferFee): bigint;
359
+ /**
360
+ * Reverse the application of a transfer fee to an amount
361
+ * e.g. You received 9900 amount with 100 fee rate. The fee amount will be 100.
362
+ * So the amount before fee will be 10000.
363
+ *
364
+ * # Parameters
365
+ * - `amount`: The amount to reverse the fee from
366
+ * - `transfer_fee`: The transfer fee to reverse
367
+ *
368
+ * # Returns
369
+ * - `u64`: The amount before the fee has been applied
370
+ */
371
+ export function tryReverseApplyTransferFee(amount: bigint, transfer_fee: TransferFee): bigint;
372
+ /**
373
+ * Get the maximum amount with a slippage tolerance
374
+ * e.g. Your estimated amount you send is 10000 with 100 slippage tolerance. The max you send will be 10100.
375
+ *
376
+ * # Parameters
377
+ * - `amount`: The amount to apply the fee to
378
+ * - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
379
+ *
380
+ * # Returns
381
+ * - `u64`: The maximum amount
382
+ */
383
+ export function tryGetMaxAmountWithSlippageTolerance(amount: bigint, slippage_tolerance_bps: number): bigint;
384
+ /**
385
+ * Get the minimum amount with a slippage tolerance
386
+ * e.g. Your estimated amount you receive is 10000 with 100 slippage tolerance. The min amount you receive will be 9900.
387
+ *
388
+ * # Parameters
389
+ * - `amount`: The amount to apply the fee to
390
+ * - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
391
+ *
392
+ * # Returns
393
+ * - `u64`: The minimum amount
394
+ */
395
+ export function tryGetMinAmountWithSlippageTolerance(amount: bigint, slippage_tolerance_bps: number): bigint;
396
+ /**
397
+ * Apply a swap fee to an amount
398
+ * e.g. You send 10000 amount with 10000 fee rate. The fee amount will be 100.
399
+ * So the amount after fee will be 9900.
379
400
  *
380
401
  * # Parameters
381
- * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
382
- * - `tick_index_1` - A i32 integer representing the first tick index of the position
383
- * - `tick_index_2` - A i32 integer representing the second tick index of the position
402
+ * - `amount`: The amount to apply the fee to
403
+ * - `fee_rate`: The fee rate to apply denominated in 1e6
384
404
  *
385
405
  * # Returns
386
- * - A boolean value indicating if the position is in range
406
+ * - `u64`: The amount after the fee has been applied
387
407
  */
388
- export function isPositionInRange(current_sqrt_price: bigint, tick_index_1: number, tick_index_2: number): boolean;
408
+ export function tryApplySwapFee(amount: bigint, fee_rate: number): bigint;
389
409
  /**
390
- * Calculate the status of a position
391
- * The status can be one of three values:
392
- * - InRange: The position is in range
393
- * - BelowRange: The position is below the range
394
- * - AboveRange: The position is above the range
410
+ * Reverse the application of a swap fee to an amount
411
+ * e.g. You received 9900 amount with 10000 fee rate. The fee amount will be 100.
412
+ * So the amount before fee will be 10000.
395
413
  *
396
414
  * # Parameters
397
- * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
398
- * - `tick_index_1` - A i32 integer representing the first tick index of the position
399
- * - `tick_index_2` - A i32 integer representing the second tick index of the position
415
+ * - `amount`: The amount to reverse the fee from
416
+ * - `fee_rate`: The fee rate to reverse denominated in 1e6
400
417
  *
401
418
  * # Returns
402
- * - A PositionStatus enum value indicating the status of the position
419
+ * - `u64`: The amount before the fee has been applied
403
420
  */
404
- export function positionStatus(current_sqrt_price: bigint, tick_index_1: number, tick_index_2: number): PositionStatus;
421
+ export function tryReverseApplySwapFee(amount: bigint, fee_rate: number): bigint;
405
422
  /**
406
- * Calculate the token_a / token_b ratio of a (ficticious) position
423
+ * Calculate fees owed for a position
407
424
  *
408
- * # Parameters
409
- * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
410
- * - `tick_index_1` - A i32 integer representing the first tick index of the position
411
- * - `tick_index_2` - A i32 integer representing the second tick index of the position
425
+ * # Paramters
426
+ * - `whirlpool`: The whirlpool state
427
+ * - `position`: The position state
428
+ * - `tick_lower`: The lower tick state
429
+ * - `tick_upper`: The upper tick state
430
+ * - `transfer_fee_a`: The transfer fee for token A
431
+ * - `transfer_fee_b`: The transfer fee for token B
412
432
  *
413
433
  * # Returns
414
- * - A PositionRatio struct containing the ratio of token_a and token_b
434
+ * - `CollectFeesQuote`: The fees owed for token A and token B
415
435
  */
416
- export function positionRatio(current_sqrt_price: bigint, tick_index_1: number, tick_index_2: number): PositionRatio;
436
+ export function collectFeesQuote(whirlpool: WhirlpoolFacade, position: PositionFacade, tick_lower: TickFacade, tick_upper: TickFacade, transfer_fee_a?: TransferFee | null, transfer_fee_b?: TransferFee | null): CollectFeesQuote;
437
+ export function _NUM_REWARDS(): number;
417
438
  /**
418
- * Convert a price into a sqrt priceX64
419
- * IMPORTANT: floating point operations can reduce the precision of the result.
420
- * Make sure to do these operations last and not to use the result for further calculations.
439
+ * Check if the whirlpool is initialized with adaptive fee
421
440
  *
422
- * # Parameters
423
- * * `price` - The price to convert
424
- * * `decimals_a` - The number of decimals of the base token
425
- * * `decimals_b` - The number of decimals of the quote token
441
+ * # Paramters
442
+ * - `whirlpool`: The whirlpool state
426
443
  *
427
444
  * # Returns
428
- * * `u128` - The sqrt priceX64
445
+ * - A boolean value indicating if the whirlpool is initialized with adaptive fee
429
446
  */
430
- export function priceToSqrtPrice(price: number, decimals_a: number, decimals_b: number): bigint;
447
+ export function isInitializedWithAdaptiveFee(whirlpool: WhirlpoolFacade): boolean;
431
448
  /**
432
- * Convert a sqrt priceX64 into a tick index
433
- * IMPORTANT: floating point operations can reduce the precision of the result.
434
- * Make sure to do these operations last and not to use the result for further calculations.
449
+ * Calculate rewards owed for a position
435
450
  *
436
- * # Parameters
437
- * * `sqrt_price` - The sqrt priceX64 to convert
438
- * * `decimals_a` - The number of decimals of the base token
439
- * * `decimals_b` - The number of decimals of the quote token
451
+ * # Paramters
452
+ * - `whirlpool`: The whirlpool state
453
+ * - `position`: The position state
454
+ * - `tick_lower`: The lower tick state
455
+ * - `tick_upper`: The upper tick state
456
+ * - `current_timestamp`: The current timestamp
457
+ * - `transfer_fee_1`: The transfer fee for token 1
458
+ * - `transfer_fee_2`: The transfer fee for token 2
459
+ * - `transfer_fee_3`: The transfer fee for token 3
440
460
  *
441
461
  * # Returns
442
- * * `f64` - The decimal price
462
+ * - `CollectRewardsQuote`: The rewards owed for the 3 reward tokens.
443
463
  */
444
- export function sqrtPriceToPrice(sqrt_price: bigint, decimals_a: number, decimals_b: number): number;
464
+ export function collectRewardsQuote(whirlpool: WhirlpoolFacade, position: PositionFacade, tick_lower: TickFacade, tick_upper: TickFacade, current_timestamp: bigint, transfer_fee_1?: TransferFee | null, transfer_fee_2?: TransferFee | null, transfer_fee_3?: TransferFee | null): CollectRewardsQuote;
445
465
  /**
446
- * Invert a price
447
- * IMPORTANT: floating point operations can reduce the precision of the result.
448
- * Make sure to do these operations last and not to use the result for further calculations.
466
+ * Get the first unoccupied position in a bundle
449
467
  *
450
- * # Parameters
451
- * * `price` - The price to invert
452
- * * `decimals_a` - The number of decimals of the base token
453
- * * `decimals_b` - The number of decimals of the quote token
468
+ * # Arguments
469
+ * * `bundle` - The bundle to check
454
470
  *
455
471
  * # Returns
456
- * * `f64` - The inverted price
472
+ * * `u32` - The first unoccupied position (None if full)
457
473
  */
458
- export function invertPrice(price: number, decimals_a: number, decimals_b: number): number;
474
+ export function firstUnoccupiedPositionInBundle(bitmap: Uint8Array): number | undefined;
459
475
  /**
460
- * Convert a tick index into a price
461
- * IMPORTANT: floating point operations can reduce the precision of the result.
462
- * Make sure to do these operations last and not to use the result for further calculations.
476
+ * Check whether a position bundle is full
477
+ * A position bundle can contain 256 positions
463
478
  *
464
- * # Parameters
465
- * * `tick_index` - The tick index to convert
466
- * * `decimals_a` - The number of decimals of the base token
467
- * * `decimals_b` - The number of decimals of the quote token
479
+ * # Arguments
480
+ * * `bundle` - The bundle to check
468
481
  *
469
482
  * # Returns
470
- * * `f64` - The decimal price
483
+ * * `bool` - Whether the bundle is full
471
484
  */
472
- export function tickIndexToPrice(tick_index: number, decimals_a: number, decimals_b: number): number;
485
+ export function isPositionBundleFull(bitmap: Uint8Array): boolean;
473
486
  /**
474
- * Convert a price into a tick index
475
- * IMPORTANT: floating point operations can reduce the precision of the result.
476
- * Make sure to do these operations last and not to use the result for further calculations.
487
+ * Check whether a position bundle is empty
477
488
  *
478
- * # Parameters
479
- * * `price` - The price to convert
480
- * * `decimals_a` - The number of decimals of the base token
481
- * * `decimals_b` - The number of decimals of the quote token
489
+ * # Arguments
490
+ * * `bundle` - The bundle to check
482
491
  *
483
492
  * # Returns
484
- * * `i32` - The tick index
493
+ * * `bool` - Whether the bundle is empty
485
494
  */
486
- export function priceToTickIndex(price: number, decimals_a: number, decimals_b: number): number;
495
+ export function isPositionBundleEmpty(bitmap: Uint8Array): boolean;
496
+ export function _VOLATILITY_ACCUMULATOR_SCALE_FACTOR(): number;
497
+ export function _REDUCTION_FACTOR_DENOMINATOR(): number;
498
+ export function _ADAPTIVE_FEE_CONTROL_FACTOR_DENOMINATOR(): number;
499
+ export function _MAX_REFERENCE_AGE(): bigint;
500
+ export function _FEE_RATE_HARD_LIMIT(): number;
501
+ export function _TICK_ARRAY_NOT_EVENLY_SPACED(): string;
502
+ export function _TICK_INDEX_OUT_OF_BOUNDS(): string;
503
+ export function _INVALID_TICK_INDEX(): string;
504
+ export function _ARITHMETIC_OVERFLOW(): string;
505
+ export function _AMOUNT_EXCEEDS_MAX_U64(): string;
506
+ export function _SQRT_PRICE_OUT_OF_BOUNDS(): string;
507
+ export function _TICK_SEQUENCE_EMPTY(): string;
508
+ export function _SQRT_PRICE_LIMIT_OUT_OF_BOUNDS(): string;
509
+ export function _INVALID_SQRT_PRICE_LIMIT_DIRECTION(): string;
510
+ export function _ZERO_TRADABLE_AMOUNT(): string;
511
+ export function _INVALID_TIMESTAMP(): string;
512
+ export function _INVALID_TRANSFER_FEE(): string;
513
+ export function _INVALID_SLIPPAGE_TOLERANCE(): string;
514
+ export function _TICK_INDEX_NOT_IN_ARRAY(): string;
515
+ export function _INVALID_TICK_ARRAY_SEQUENCE(): string;
516
+ export function _INVALID_ADAPTIVE_FEE_INFO(): string;
487
517
  /**
488
518
  * Computes the exact input or output amount for a swap transaction.
489
519
  *
@@ -520,21 +550,6 @@ export function swapQuoteByInputToken(token_in: bigint, specified_token_a: boole
520
550
  * The exact input or output amount for the swap transaction.
521
551
  */
522
552
  export function swapQuoteByOutputToken(token_out: bigint, specified_token_a: boolean, slippage_tolerance_bps: number, whirlpool: WhirlpoolFacade, oracle: OracleFacade | null | undefined, tick_arrays: TickArrayFacade[], timestamp: bigint, transfer_fee_a?: TransferFee | null, transfer_fee_b?: TransferFee | null): ExactOutSwapQuote;
523
- /**
524
- * Calculate fees owed for a position
525
- *
526
- * # Paramters
527
- * - `whirlpool`: The whirlpool state
528
- * - `position`: The position state
529
- * - `tick_lower`: The lower tick state
530
- * - `tick_upper`: The upper tick state
531
- * - `transfer_fee_a`: The transfer fee for token A
532
- * - `transfer_fee_b`: The transfer fee for token B
533
- *
534
- * # Returns
535
- * - `CollectFeesQuote`: The fees owed for token A and token B
536
- */
537
- export function collectFeesQuote(whirlpool: WhirlpoolFacade, position: PositionFacade, tick_lower: TickFacade, tick_upper: TickFacade, transfer_fee_a?: TransferFee | null, transfer_fee_b?: TransferFee | null): CollectFeesQuote;
538
553
  /**
539
554
  * Calculate the quote for decreasing liquidity
540
555
  *
@@ -631,32 +646,6 @@ export function increaseLiquidityQuoteA(token_amount_a: bigint, slippage_toleran
631
646
  * - An IncreaseLiquidityQuote struct containing the estimated token amounts
632
647
  */
633
648
  export function increaseLiquidityQuoteB(token_amount_b: bigint, slippage_tolerance_bps: number, current_sqrt_price: bigint, tick_index_1: number, tick_index_2: number, transfer_fee_a?: TransferFee | null, transfer_fee_b?: TransferFee | null): IncreaseLiquidityQuote;
634
- export interface TransferFee {
635
- feeBps: number;
636
- maxFee: bigint;
637
- }
638
-
639
- export interface CollectFeesQuote {
640
- feeOwedA: bigint;
641
- feeOwedB: bigint;
642
- }
643
-
644
- export interface IncreaseLiquidityQuote {
645
- liquidityDelta: bigint;
646
- tokenEstA: bigint;
647
- tokenEstB: bigint;
648
- tokenMaxA: bigint;
649
- tokenMaxB: bigint;
650
- }
651
-
652
- export interface DecreaseLiquidityQuote {
653
- liquidityDelta: bigint;
654
- tokenEstA: bigint;
655
- tokenEstB: bigint;
656
- tokenMinA: bigint;
657
- tokenMinB: bigint;
658
- }
659
-
660
649
  export interface ExactOutSwapQuote {
661
650
  tokenOut: bigint;
662
651
  tokenEstIn: bigint;
@@ -675,23 +664,38 @@ export interface ExactInSwapQuote {
675
664
  tradeFeeRateMax: number;
676
665
  }
677
666
 
678
- export interface TickArrayFacade {
679
- startTickIndex: number;
680
- ticks: TickFacade[];
667
+ export interface CollectRewardQuote {
668
+ rewardsOwed: bigint;
681
669
  }
682
670
 
683
- export interface TickFacade {
684
- initialized: boolean;
685
- liquidityNet: bigint;
686
- liquidityGross: bigint;
687
- feeGrowthOutsideA: bigint;
688
- feeGrowthOutsideB: bigint;
689
- rewardGrowthsOutside: bigint[];
671
+ export interface CollectRewardsQuote {
672
+ rewards: CollectRewardQuote[];
690
673
  }
691
674
 
692
- export interface TickRange {
693
- tickLowerIndex: number;
694
- tickUpperIndex: number;
675
+ export interface IncreaseLiquidityQuote {
676
+ liquidityDelta: bigint;
677
+ tokenEstA: bigint;
678
+ tokenEstB: bigint;
679
+ tokenMaxA: bigint;
680
+ tokenMaxB: bigint;
681
+ }
682
+
683
+ export interface DecreaseLiquidityQuote {
684
+ liquidityDelta: bigint;
685
+ tokenEstA: bigint;
686
+ tokenEstB: bigint;
687
+ tokenMinA: bigint;
688
+ tokenMinB: bigint;
689
+ }
690
+
691
+ export interface SqrtPriceSlippageBounds {
692
+ minSqrtPrice: bigint;
693
+ maxSqrtPrice: bigint;
694
+ }
695
+
696
+ export interface TransferFee {
697
+ feeBps: number;
698
+ maxFee: bigint;
695
699
  }
696
700
 
697
701
  export interface PositionRewardInfoFacade {
@@ -717,6 +721,25 @@ export interface PositionRatio {
717
721
  ratioB: number;
718
722
  }
719
723
 
724
+ export interface TickArrayFacade {
725
+ startTickIndex: number;
726
+ ticks: TickFacade[];
727
+ }
728
+
729
+ export interface TickFacade {
730
+ initialized: boolean;
731
+ liquidityNet: bigint;
732
+ liquidityGross: bigint;
733
+ feeGrowthOutsideA: bigint;
734
+ feeGrowthOutsideB: bigint;
735
+ rewardGrowthsOutside: bigint[];
736
+ }
737
+
738
+ export interface TickRange {
739
+ tickLowerIndex: number;
740
+ tickUpperIndex: number;
741
+ }
742
+
720
743
  export interface WhirlpoolRewardInfoFacade {
721
744
  emissionsPerSecondX64: bigint;
722
745
  growthGlobalX64: bigint;
@@ -765,11 +788,8 @@ export interface OracleFacade {
765
788
  adaptiveFeeVariables: AdaptiveFeeVariablesFacade;
766
789
  }
767
790
 
768
- export interface CollectRewardQuote {
769
- rewardsOwed: bigint;
770
- }
771
-
772
- export interface CollectRewardsQuote {
773
- rewards: CollectRewardQuote[];
791
+ export interface CollectFeesQuote {
792
+ feeOwedA: bigint;
793
+ feeOwedB: bigint;
774
794
  }
775
795