@crypticdot/defituna-core 3.1.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,674 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+ /**
4
+ * Get the first tick index in the tick array that contains the specified tick index.
5
+ *
6
+ * # Parameters
7
+ * - `tick_index` - A i32 integer representing the tick integer
8
+ * - `tick_spacing` - A i32 integer representing the tick spacing
9
+ *
10
+ * # Returns
11
+ * - A i32 integer representing the first tick index in the tick array
12
+ */
13
+ export function getTickArrayStartTickIndex(tick_index: number, tick_spacing: number): number;
14
+ /**
15
+ * Derive the sqrt-price from a tick index. The precision of this method is only guarranted
16
+ * if tick is within the bounds of {max, min} tick-index.
17
+ *
18
+ * # Parameters
19
+ * - `tick_index` - A i32 integer representing the tick integer
20
+ *
21
+ * # Returns
22
+ * - `Ok`: A u128 Q32.64 representing the sqrt_price
23
+ */
24
+ export function tickIndexToSqrtPrice(tick_index: number): bigint;
25
+ /**
26
+ * Derive the tick index from a sqrt price. The precision of this method is only guarranted
27
+ * if tick is within the bounds of {max, min} tick-index.
28
+ *
29
+ * # Parameters
30
+ * - `sqrt_price` - A u128 integer representing the sqrt price
31
+ *
32
+ * # Returns
33
+ * - `Ok`: A i32 integer representing the tick integer
34
+ */
35
+ export function sqrtPriceToTickIndex(sqrt_price: bigint): number;
36
+ /**
37
+ * Get the initializable tick index.
38
+ * If the tick index is already initializable, it is returned as is.
39
+ *
40
+ * # Parameters
41
+ * - `tick_index` - A i32 integer representing the tick integer
42
+ * - `tick_spacing` - A i32 integer representing the tick spacing
43
+ * - `round_up` - A boolean value indicating if the supplied tick index should be rounded up. None will round to the nearest.
44
+ *
45
+ * # Returns
46
+ * - A i32 integer representing the previous initializable tick index
47
+ */
48
+ export function getInitializableTickIndex(tick_index: number, tick_spacing: number, round_up?: boolean | null): number;
49
+ /**
50
+ * Get the previous initializable tick index.
51
+ *
52
+ * # Parameters
53
+ * - `tick_index` - A i32 integer representing the tick integer
54
+ * - `tick_spacing` - A i32 integer representing the tick spacing
55
+ *
56
+ * # Returns
57
+ * - A i32 integer representing the previous initializable tick index
58
+ */
59
+ export function getPrevInitializableTickIndex(tick_index: number, tick_spacing: number): number;
60
+ /**
61
+ * Get the next initializable tick index.
62
+ *
63
+ * # Parameters
64
+ * - `tick_index` - A i32 integer representing the tick integer
65
+ * - `tick_spacing` - A i32 integer representing the tick spacing
66
+ *
67
+ * # Returns
68
+ * - A i32 integer representing the next initializable tick index
69
+ */
70
+ export function getNextInitializableTickIndex(tick_index: number, tick_spacing: number): number;
71
+ /**
72
+ * Check if a tick is in-bounds.
73
+ *
74
+ * # Parameters
75
+ * - `tick_index` - A i32 integer representing the tick integer
76
+ *
77
+ * # Returns
78
+ * - A boolean value indicating if the tick is in-bounds
79
+ */
80
+ export function isTickIndexInBounds(tick_index: number): boolean;
81
+ /**
82
+ * Check if a tick is initializable.
83
+ * A tick is initializable if it is divisible by the tick spacing.
84
+ *
85
+ * # Parameters
86
+ * - `tick_index` - A i32 integer representing the tick integer
87
+ * - `tick_spacing` - A i32 integer representing the tick spacing
88
+ *
89
+ * # Returns
90
+ * - A boolean value indicating if the tick is initializable
91
+ */
92
+ export function isTickInitializable(tick_index: number, tick_spacing: number): boolean;
93
+ /**
94
+ * Get the tick index for the inverse of the price that this tick represents.
95
+ * Eg: Consider tick i where Pb/Pa = 1.0001 ^ i
96
+ * inverse of this, i.e. Pa/Pb = 1 / (1.0001 ^ i) = 1.0001^-i
97
+ *
98
+ * # Parameters
99
+ * - `tick_index` - A i32 integer representing the tick integer
100
+ *
101
+ * # Returns
102
+ * - A i32 integer representing the tick index for the inverse of the price
103
+ */
104
+ export function invertTickIndex(tick_index: number): number;
105
+ /**
106
+ * Get the sqrt price for the inverse of the price that this tick represents.
107
+ * Because converting to a tick index and then back to a sqrt price is lossy,
108
+ * this function is clamped to the nearest tick index.
109
+ *
110
+ * # Parameters
111
+ * - `sqrt_price` - A u128 integer representing the sqrt price
112
+ *
113
+ * # Returns
114
+ * - A u128 integer representing the sqrt price for the inverse of the price
115
+ */
116
+ export function invertSqrtPrice(sqrt_price: bigint): bigint;
117
+ /**
118
+ * Get the minimum and maximum tick index that can be initialized.
119
+ *
120
+ * # Parameters
121
+ * - `tick_spacing` - A i32 integer representing the tick spacing
122
+ *
123
+ * # Returns
124
+ * - A TickRange struct containing the lower and upper tick index
125
+ */
126
+ export function getFullRangeTickIndexes(tick_spacing: number): TickRange;
127
+ /**
128
+ * Order tick indexes in ascending order.
129
+ * If the lower tick index is greater than the upper tick index, the indexes are swapped.
130
+ * This is useful for ensuring that the lower tick index is always less than the upper tick index.
131
+ *
132
+ * # Parameters
133
+ * - `tick_index_1` - A i32 integer representing the first tick index
134
+ * - `tick_index_2` - A i32 integer representing the second tick index
135
+ *
136
+ * # Returns
137
+ * - A TickRange struct containing the lower and upper tick index
138
+ */
139
+ export function orderTickIndexes(tick_index_1: number, tick_index_2: number): TickRange;
140
+ /**
141
+ * Check if a fusion_pool is a full-range only pool.
142
+ *
143
+ * # Parameters
144
+ * - `tick_spacing` - A u16 integer representing the tick spacing
145
+ *
146
+ * # Returns
147
+ * - A boolean value indicating if the fusion_pool is a full-range only pool
148
+ */
149
+ export function isFullRangeOnly(tick_spacing: number): boolean;
150
+ /**
151
+ * Get the index of a tick in a tick array.
152
+ *
153
+ * # Parameters
154
+ * - `tick_index` - A i32 integer representing the tick index
155
+ * - `tick_array_start_index` - A i32 integer representing the start tick index of the tick array
156
+ * - `tick_spacing` - A u16 integer representing the tick spacing
157
+ *
158
+ * # Returns
159
+ * - A u32 integer representing the tick index in the tick array
160
+ */
161
+ export function getTickIndexInArray(tick_index: number, tick_array_start_index: number, tick_spacing: number): number;
162
+ /**
163
+ * Calculate the amount A delta between two sqrt_prices
164
+ *
165
+ * # Parameters
166
+ * - `sqrt_price_1`: The first square root price
167
+ * - `sqrt_price_2`: The second square root price
168
+ * - `liquidity`: The liquidity
169
+ * - `round_up`: Whether to round up or not
170
+ *
171
+ * # Returns
172
+ * - `u64`: The amount delta
173
+ */
174
+ export function tryGetAmountDeltaA(sqrt_price_1: bigint, sqrt_price_2: bigint, liquidity: bigint, round_up: boolean): bigint;
175
+ /**
176
+ * Calculate the amount B delta between two sqrt_prices
177
+ *
178
+ * # Parameters
179
+ * - `sqrt_price_1`: The first square root price
180
+ * - `sqrt_price_2`: The second square root price
181
+ * - `liquidity`: The liquidity
182
+ * - `round_up`: Whether to round up or not
183
+ *
184
+ * # Returns
185
+ * - `u64`: The amount delta
186
+ */
187
+ export function tryGetAmountDeltaB(sqrt_price_1: bigint, sqrt_price_2: bigint, liquidity: bigint, round_up: boolean): bigint;
188
+ /**
189
+ * Calculate the next square root price
190
+ *
191
+ * # Parameters
192
+ * - `current_sqrt_price`: The current square root price
193
+ * - `current_liquidity`: The current liquidity
194
+ * - `amount`: The amount
195
+ * - `specified_input`: Whether the input is specified
196
+ *
197
+ * # Returns
198
+ * - `u128`: The next square root price
199
+ */
200
+ export function tryGetNextSqrtPriceFromA(current_sqrt_price: bigint, current_liquidity: bigint, amount: bigint, specified_input: boolean): bigint;
201
+ /**
202
+ * Calculate the next square root price
203
+ *
204
+ * # Parameters
205
+ * - `current_sqrt_price`: The current square root price
206
+ * - `current_liquidity`: The current liquidity
207
+ * - `amount`: The amount
208
+ * - `specified_input`: Whether the input is specified
209
+ *
210
+ * # Returns
211
+ * - `u128`: The next square root price
212
+ */
213
+ export function tryGetNextSqrtPriceFromB(current_sqrt_price: bigint, current_liquidity: bigint, amount: bigint, specified_input: boolean): bigint;
214
+ /**
215
+ * Apply a transfer fee to an amount
216
+ * e.g. You send 10000 amount with 100 fee rate. The fee amount will be 100.
217
+ * So the amount after fee will be 9900.
218
+ *
219
+ * # Parameters
220
+ * - `amount`: The amount to apply the fee to
221
+ * - `transfer_fee`: The transfer fee to apply
222
+ *
223
+ * # Returns
224
+ * - `u64`: The amount after the fee has been applied
225
+ */
226
+ export function tryApplyTransferFee(amount: bigint, transfer_fee: TransferFee): bigint;
227
+ /**
228
+ * Reverse the application of a transfer fee to an amount
229
+ * e.g. You received 9900 amount with 100 fee rate. The fee amount will be 100.
230
+ * So the amount before fee will be 10000.
231
+ *
232
+ * # Parameters
233
+ * - `amount`: The amount to reverse the fee from
234
+ * - `transfer_fee`: The transfer fee to reverse
235
+ *
236
+ * # Returns
237
+ * - `u64`: The amount before the fee has been applied
238
+ */
239
+ export function tryReverseApplyTransferFee(amount: bigint, transfer_fee: TransferFee): bigint;
240
+ /**
241
+ * Get the maximum amount with a slippage tolerance
242
+ * e.g. Your estimated amount you send is 10000 with 100 slippage tolerance. The max you send will be 10100.
243
+ *
244
+ * # Parameters
245
+ * - `amount`: The amount to apply the fee to
246
+ * - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
247
+ *
248
+ * # Returns
249
+ * - `u64`: The maximum amount
250
+ */
251
+ export function tryGetMaxAmountWithSlippageTolerance(amount: bigint, slippage_tolerance_bps: number): bigint;
252
+ /**
253
+ * Get the minimum amount with a slippage tolerance
254
+ * e.g. Your estimated amount you receive is 10000 with 100 slippage tolerance. The min amount you receive will be 9900.
255
+ *
256
+ * # Parameters
257
+ * - `amount`: The amount to apply the fee to
258
+ * - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
259
+ *
260
+ * # Returns
261
+ * - `u64`: The minimum amount
262
+ */
263
+ export function tryGetMinAmountWithSlippageTolerance(amount: bigint, slippage_tolerance_bps: number): bigint;
264
+ /**
265
+ * Apply a swap fee to an amount
266
+ * e.g. You send 10000 amount with 10000 fee rate. The fee amount will be 100.
267
+ * So the amount after fee will be 9900.
268
+ *
269
+ * # Parameters
270
+ * - `amount`: The amount to apply the fee to
271
+ * - `fee_rate`: The fee rate to apply denominated in 1e6
272
+ *
273
+ * # Returns
274
+ * - `u64`: The amount after the fee has been applied
275
+ */
276
+ export function tryApplySwapFee(amount: bigint, fee_rate: number): bigint;
277
+ /**
278
+ * Reverse the application of a swap fee to an amount
279
+ * e.g. You received 9900 amount with 10000 fee rate. The fee amount will be 100.
280
+ * So the amount before fee will be 10000.
281
+ *
282
+ * # Parameters
283
+ * - `amount`: The amount to reverse the fee from
284
+ * - `fee_rate`: The fee rate to reverse denominated in 1e6
285
+ *
286
+ * # Returns
287
+ * - `u64`: The amount before the fee has been applied
288
+ */
289
+ export function tryReverseApplySwapFee(amount: bigint, fee_rate: number): bigint;
290
+ /**
291
+ * Computes the limit order output amount by input amount.
292
+ * ### Parameters
293
+ * - `amount_in` - The input token amount of a limit order.
294
+ * - `a_to_b_order` - The limit order direction.
295
+ * - `tick_index` - The tick index of an order.
296
+ * - `fusion_pool` - The fusion_pool state.
297
+ */
298
+ export function limitOrderQuoteByInputToken(amount_in: bigint, a_to_b_order: boolean, tick_index: number, fusion_pool: FusionPoolFacade): bigint;
299
+ /**
300
+ * Computes the limit order input amount by output amount.
301
+ * ### Parameters
302
+ * - `amount_out` - The output token amount of a limit order.
303
+ * - `a_to_b_order` - The limit order direction.
304
+ * - `tick_index` - The tick index of an order.
305
+ * - `fusion_pool` - The fusion_pool state.
306
+ */
307
+ export function limitOrderQuoteByOutputToken(amount_out: bigint, a_to_b_order: boolean, tick_index: number, fusion_pool: FusionPoolFacade): bigint;
308
+ /**
309
+ * Computes the limit order reward by input amount.
310
+ * ### Parameters
311
+ * - `amount_out` - The output token amount of a limit order (swap input).
312
+ * - `a_to_b_order` - The limit order direction.
313
+ * - `tick_index` - The tick index of an order.
314
+ * - `fusion_pool` - The fusion_pool state.
315
+ */
316
+ export function limitOrderRewardByOutputToken(amount_out: bigint, fee_rate: number, protocol_fee_rate: number): bigint;
317
+ export function decreaseLimitOrderQuote(fusion_pool: FusionPoolFacade, limit_order: LimitOrderFacade, tick: TickFacade, amount: bigint, transfer_fee_a?: TransferFee | null, transfer_fee_b?: TransferFee | null): LimitOrderDecreaseQuote;
318
+ /**
319
+ * Calculate the quote for decreasing liquidity
320
+ *
321
+ * # Parameters
322
+ * - `liquidity_delta` - The amount of liquidity to decrease
323
+ * - `slippage_tolerance` - The slippage tolerance in bps
324
+ * - `current_sqrt_price` - The current sqrt price of the pool
325
+ * - `tick_index_1` - The first tick index of the position
326
+ * - `tick_index_2` - The second tick index of the position
327
+ * - `transfer_fee_a` - The transfer fee for token A in bps
328
+ * - `transfer_fee_b` - The transfer fee for token B in bps
329
+ *
330
+ * # Returns
331
+ * - A DecreaseLiquidityQuote struct containing the estimated token amounts
332
+ */
333
+ export function decreaseLiquidityQuote(liquidity_delta: 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): DecreaseLiquidityQuote;
334
+ /**
335
+ * Calculate the quote for decreasing liquidity given a token a amount
336
+ *
337
+ * # Parameters
338
+ * - `token_amount_a` - The amount of token a to decrease
339
+ * - `slippage_tolerance` - The slippage tolerance in bps
340
+ * - `current_sqrt_price` - The current sqrt price of the pool
341
+ * - `tick_index_1` - The first tick index of the position
342
+ * - `tick_index_2` - The second tick index of the position
343
+ * - `transfer_fee_a` - The transfer fee for token A in bps
344
+ * - `transfer_fee_b` - The transfer fee for token B in bps
345
+ *
346
+ * # Returns
347
+ * - A DecreaseLiquidityQuote struct containing the estimated token amounts
348
+ */
349
+ export function decreaseLiquidityQuoteA(token_amount_a: 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): DecreaseLiquidityQuote;
350
+ /**
351
+ * Calculate the quote for decreasing liquidity given a token b amount
352
+ *
353
+ * # Parameters
354
+ * - `token_amount_b` - The amount of token b to decrease
355
+ * - `slippage_tolerance` - The slippage tolerance in bps
356
+ * - `current_sqrt_price` - The current sqrt price of the pool
357
+ * - `tick_index_1` - The first tick index of the position
358
+ * - `tick_index_2` - The second tick index of the position
359
+ * - `transfer_fee_a` - The transfer fee for token A in bps
360
+ * - `transfer_fee_b` - The transfer fee for token B in bps
361
+ *
362
+ * # Returns
363
+ * - A DecreaseLiquidityQuote struct containing the estimated token amounts
364
+ */
365
+ export function decreaseLiquidityQuoteB(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): DecreaseLiquidityQuote;
366
+ /**
367
+ * Calculate the quote for increasing liquidity
368
+ *
369
+ * # Parameters
370
+ * - `liquidity_delta` - The amount of liquidity to increase
371
+ * - `slippage_tolerance` - The slippage tolerance in bps
372
+ * - `current_sqrt_price` - The current sqrt price of the pool
373
+ * - `tick_index_1` - The first tick index of the position
374
+ * - `tick_index_2` - The second tick index of the position
375
+ * - `transfer_fee_a` - The transfer fee for token A in bps
376
+ * - `transfer_fee_b` - The transfer fee for token B in bps
377
+ *
378
+ * # Returns
379
+ * - An IncreaseLiquidityQuote struct containing the estimated token amounts
380
+ */
381
+ export function increaseLiquidityQuote(liquidity_delta: 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;
382
+ /**
383
+ * Calculate the quote for increasing liquidity given a token a amount
384
+ *
385
+ * # Parameters
386
+ * - `token_amount_a` - The amount of token a to increase
387
+ * - `slippage_tolerance` - The slippage tolerance in bps
388
+ * - `current_sqrt_price` - The current sqrt price of the pool
389
+ * - `tick_index_1` - The first tick index of the position
390
+ * - `tick_index_2` - The second tick index of the position
391
+ * - `transfer_fee_a` - The transfer fee for token A in bps
392
+ * - `transfer_fee_b` - The transfer fee for token B in bps
393
+ *
394
+ * # Returns
395
+ * - An IncreaseLiquidityQuote struct containing the estimated token amounts
396
+ */
397
+ export function increaseLiquidityQuoteA(token_amount_a: 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;
398
+ /**
399
+ * Calculate the quote for increasing liquidity given a token b amount
400
+ *
401
+ * # Parameters
402
+ * - `token_amount_b` - The amount of token b to increase
403
+ * - `slippage_tolerance` - The slippage tolerance in bps
404
+ * - `current_sqrt_price` - The current sqrt price of the pool
405
+ * - `tick_index_1` - The first tick index of the position
406
+ * - `tick_index_2` - The second tick index of the position
407
+ * - `transfer_fee_a` - The transfer fee for token A in bps
408
+ * - `transfer_fee_b` - The transfer fee for token B in bps
409
+ *
410
+ * # Returns
411
+ * - An IncreaseLiquidityQuote struct containing the estimated token amounts
412
+ */
413
+ 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;
414
+ export function tryGetLiquidityFromA(token_delta_a: bigint, sqrt_price_lower: bigint, sqrt_price_upper: bigint): bigint;
415
+ export function tryGetTokenAFromLiquidity(liquidity_delta: bigint, sqrt_price_lower: bigint, sqrt_price_upper: bigint, round_up: boolean): bigint;
416
+ export function tryGetLiquidityFromB(token_delta_b: bigint, sqrt_price_lower: bigint, sqrt_price_upper: bigint): bigint;
417
+ export function tryGetTokenBFromLiquidity(liquidity_delta: bigint, sqrt_price_lower: bigint, sqrt_price_upper: bigint, round_up: boolean): bigint;
418
+ export function tryGetTokenEstimatesFromLiquidity(liquidity_delta: bigint, current_sqrt_price: bigint, tick_lower_index: number, tick_upper_index: number, round_up: boolean): TokenPair;
419
+ /**
420
+ * Calculate fees owed for a position
421
+ *
422
+ * # Paramters
423
+ * - `fusion_pool`: The fusion_pool state
424
+ * - `position`: The position state
425
+ * - `tick_lower`: The lower tick state
426
+ * - `tick_upper`: The upper tick state
427
+ * - `transfer_fee_a`: The transfer fee for token A
428
+ * - `transfer_fee_b`: The transfer fee for token B
429
+ *
430
+ * # Returns
431
+ * - `CollectFeesQuote`: The fees owed for token A and token B
432
+ */
433
+ export function collectFeesQuote(fusion_pool: FusionPoolFacade, position: PositionFacade, tick_lower: TickFacade, tick_upper: TickFacade, transfer_fee_a?: TransferFee | null, transfer_fee_b?: TransferFee | null): CollectFeesQuote;
434
+ export function limitOrderFee(fusion_pool: FusionPoolFacade): number;
435
+ export function _TICK_ARRAY_SIZE(): number;
436
+ export function _FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD(): number;
437
+ export function _MIN_TICK_INDEX(): number;
438
+ export function _MAX_TICK_INDEX(): number;
439
+ /**
440
+ * Convert a price into a sqrt priceX64
441
+ * IMPORTANT: floating point operations can reduce the precision of the result.
442
+ * Make sure to do these operations last and not to use the result for further calculations.
443
+ *
444
+ * # Parameters
445
+ * * `price` - The price to convert
446
+ * * `decimals_a` - The number of decimals of the base token
447
+ * * `decimals_b` - The number of decimals of the quote token
448
+ *
449
+ * # Returns
450
+ * * `u128` - The sqrt priceX64
451
+ */
452
+ export function priceToSqrtPrice(price: number, decimals_a: number, decimals_b: number): bigint;
453
+ /**
454
+ * Convert a sqrt priceX64 into a tick index
455
+ * IMPORTANT: floating point operations can reduce the precision of the result.
456
+ * Make sure to do these operations last and not to use the result for further calculations.
457
+ *
458
+ * # Parameters
459
+ * * `sqrt_price` - The sqrt priceX64 to convert
460
+ * * `decimals_a` - The number of decimals of the base token
461
+ * * `decimals_b` - The number of decimals of the quote token
462
+ *
463
+ * # Returns
464
+ * * `f64` - The decimal price
465
+ */
466
+ export function sqrtPriceToPrice(sqrt_price: bigint, decimals_a: number, decimals_b: number): number;
467
+ /**
468
+ * Invert a price
469
+ * IMPORTANT: floating point operations can reduce the precision of the result.
470
+ * Make sure to do these operations last and not to use the result for further calculations.
471
+ *
472
+ * # Parameters
473
+ * * `price` - The price to invert
474
+ * * `decimals_a` - The number of decimals of the base token
475
+ * * `decimals_b` - The number of decimals of the quote token
476
+ *
477
+ * # Returns
478
+ * * `f64` - The inverted price
479
+ */
480
+ export function invertPrice(price: number, decimals_a: number, decimals_b: number): number;
481
+ /**
482
+ * Convert a tick index into a price
483
+ * IMPORTANT: floating point operations can reduce the precision of the result.
484
+ * Make sure to do these operations last and not to use the result for further calculations.
485
+ *
486
+ * # Parameters
487
+ * * `tick_index` - The tick index to convert
488
+ * * `decimals_a` - The number of decimals of the base token
489
+ * * `decimals_b` - The number of decimals of the quote token
490
+ *
491
+ * # Returns
492
+ * * `f64` - The decimal price
493
+ */
494
+ export function tickIndexToPrice(tick_index: number, decimals_a: number, decimals_b: number): number;
495
+ /**
496
+ * Convert a price into a tick index
497
+ * IMPORTANT: floating point operations can reduce the precision of the result.
498
+ * Make sure to do these operations last and not to use the result for further calculations.
499
+ *
500
+ * # Parameters
501
+ * * `price` - The price to convert
502
+ * * `decimals_a` - The number of decimals of the base token
503
+ * * `decimals_b` - The number of decimals of the quote token
504
+ *
505
+ * # Returns
506
+ * * `i32` - The tick index
507
+ */
508
+ export function priceToTickIndex(price: number, decimals_a: number, decimals_b: number): number;
509
+ export function _POSITION_BUNDLE_SIZE(): number;
510
+ export function _TICK_ARRAY_NOT_EVENLY_SPACED(): string;
511
+ export function _TICK_INDEX_OUT_OF_BOUNDS(): string;
512
+ export function _INVALID_TICK_INDEX(): string;
513
+ export function _ARITHMETIC_OVERFLOW(): string;
514
+ export function _AMOUNT_EXCEEDS_MAX_U64(): string;
515
+ export function _AMOUNT_EXCEEDS_LIMIT_ORDER_INPUT_AMOUNT(): string;
516
+ export function _SQRT_PRICE_OUT_OF_BOUNDS(): string;
517
+ export function _TICK_SEQUENCE_EMPTY(): string;
518
+ export function _SQRT_PRICE_LIMIT_OUT_OF_BOUNDS(): string;
519
+ export function _INVALID_SQRT_PRICE_LIMIT_DIRECTION(): string;
520
+ export function _ZERO_TRADABLE_AMOUNT(): string;
521
+ export function _INVALID_TIMESTAMP(): string;
522
+ export function _INVALID_TRANSFER_FEE(): string;
523
+ export function _INVALID_SLIPPAGE_TOLERANCE(): string;
524
+ export function _TICK_INDEX_NOT_IN_ARRAY(): string;
525
+ export function _INVALID_TICK_ARRAY_SEQUENCE(): string;
526
+ export function _LIMIT_ORDER_AND_POOL_ARE_OUT_OF_SYNC(): string;
527
+ export function _FEE_RATE_MUL_VALUE(): number;
528
+ export function _MAX_PROTOCOL_FEE_RATE(): number;
529
+ export function _PROTOCOL_FEE_RATE_MUL_VALUE(): number;
530
+ /**
531
+ * Get the first unoccupied position in a bundle
532
+ *
533
+ * # Arguments
534
+ * * `bundle` - The bundle to check
535
+ *
536
+ * # Returns
537
+ * * `u32` - The first unoccupied position (None if full)
538
+ */
539
+ export function firstUnoccupiedPositionInBundle(bitmap: Uint8Array): number | undefined;
540
+ /**
541
+ * Check whether a position bundle is full
542
+ * A position bundle can contain 256 positions
543
+ *
544
+ * # Arguments
545
+ * * `bundle` - The bundle to check
546
+ *
547
+ * # Returns
548
+ * * `bool` - Whether the bundle is full
549
+ */
550
+ export function isPositionBundleFull(bitmap: Uint8Array): boolean;
551
+ /**
552
+ * Check whether a position bundle is empty
553
+ *
554
+ * # Arguments
555
+ * * `bundle` - The bundle to check
556
+ *
557
+ * # Returns
558
+ * * `bool` - Whether the bundle is empty
559
+ */
560
+ export function isPositionBundleEmpty(bitmap: Uint8Array): boolean;
561
+ /**
562
+ * Check if a position is in range.
563
+ * When a position is in range it is earning fees and rewards
564
+ *
565
+ * # Parameters
566
+ * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
567
+ * - `tick_index_1` - A i32 integer representing the first tick index of the position
568
+ * - `tick_index_2` - A i32 integer representing the second tick index of the position
569
+ *
570
+ * # Returns
571
+ * - A boolean value indicating if the position is in range
572
+ */
573
+ export function isPositionInRange(current_sqrt_price: bigint, tick_index_1: number, tick_index_2: number): boolean;
574
+ /**
575
+ * Calculate the status of a position
576
+ * The status can be one of three values:
577
+ * - InRange: The position is in range
578
+ * - BelowRange: The position is below the range
579
+ * - AboveRange: The position is above the range
580
+ *
581
+ * # Parameters
582
+ * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
583
+ * - `tick_index_1` - A i32 integer representing the first tick index of the position
584
+ * - `tick_index_2` - A i32 integer representing the second tick index of the position
585
+ *
586
+ * # Returns
587
+ * - A PositionStatus enum value indicating the status of the position
588
+ */
589
+ export function positionStatus(current_sqrt_price: bigint, tick_index_1: number, tick_index_2: number): PositionStatus;
590
+ /**
591
+ * Calculate the token_a / token_b ratio of a (ficticious) position
592
+ *
593
+ * # Parameters
594
+ * - `sqrt_price` - A u128 integer representing the sqrt price of the pool
595
+ * - `tick_index_1` - A i32 integer representing the first tick index of the position
596
+ * - `tick_index_2` - A i32 integer representing the second tick index of the position
597
+ *
598
+ * # Returns
599
+ * - A PositionRatio struct containing the ratio of token_a and token_b
600
+ */
601
+ export function positionRatioX64(current_sqrt_price: bigint, tick_index_1: number, tick_index_2: number): PositionRatio;
602
+ /**
603
+ * Computes the exact input or output amount for a swap transaction.
604
+ *
605
+ * # Arguments
606
+ * - `token_in`: The input token amount.
607
+ * - `specified_token_a`: If `true`, the input token is token A. Otherwise, it is token B.
608
+ * - `slippage_tolerance`: The slippage tolerance in basis points.
609
+ * - `fusion_pool`: The fusion_pool state.
610
+ * - `tick_arrays`: The tick arrays needed for the swap.
611
+ * - `transfer_fee_a`: The transfer fee for token A.
612
+ * - `transfer_fee_b`: The transfer fee for token B.
613
+ *
614
+ * # Returns
615
+ * The exact input or output amount for the swap transaction.
616
+ */
617
+ export function swapQuoteByInputToken(token_in: bigint, specified_token_a: boolean, slippage_tolerance_bps: number, fusion_pool: FusionPoolFacade, tick_arrays: TickArrayFacade[], transfer_fee_a?: TransferFee | null, transfer_fee_b?: TransferFee | null): ExactInSwapQuote;
618
+ /**
619
+ * Computes the exact input or output amount for a swap transaction.
620
+ *
621
+ * # Arguments
622
+ * - `token_out`: The output token amount.
623
+ * - `specified_token_a`: If `true`, the output token is token A. Otherwise, it is token B.
624
+ * - `slippage_tolerance`: The slippage tolerance in basis points.
625
+ * - `fusion_pool`: The fusion_pool state.
626
+ * - `tick_arrays`: The tick arrays needed for the swap.
627
+ * - `transfer_fee_a`: The transfer fee for token A.
628
+ * - `transfer_fee_b`: The transfer fee for token B.
629
+ *
630
+ * # Returns
631
+ * The exact input or output amount for the swap transaction.
632
+ */
633
+ export function swapQuoteByOutputToken(token_out: bigint, specified_token_a: boolean, slippage_tolerance_bps: number, fusion_pool: FusionPoolFacade, tick_arrays: TickArrayFacade[], transfer_fee_a?: TransferFee | null, transfer_fee_b?: TransferFee | null): ExactOutSwapQuote;
3
634
  export function _INVALID_ARGUMENTS(): string;
635
+ /**
636
+ * Spot position increase quote
637
+ *
638
+ * # Parameters
639
+ * - `increase_amount`: Position total size in the collateral_token.
640
+ * - `collateral_token`: Collateral token.
641
+ * - `position_token`: Token of the position.
642
+ * - `leverage`: Leverage (1.0 or higher).
643
+ * - `protocol_fee_rate`: Protocol fee rate from a market account represented as hundredths of a basis point (0.01% = 100).
644
+ * - `protocol_fee_rate_on_collateral`: Protocol fee rate from a market account represented as hundredths of a basis point (0.01% = 100).
645
+ * - `fusion_pool`: Fusion pool.
646
+ * - `tick_arrays`: Five tick arrays around the current pool price.
647
+ *
648
+ * # Returns
649
+ * - `IncreaseSpotPositionQuoteResult`: quote result
650
+ */
651
+ export function getIncreaseSpotPositionQuote(increase_amount: bigint, collateral_token: PoolTokenFacade, position_token: PoolTokenFacade, leverage: number, protocol_fee_rate: number, protocol_fee_rate_on_collateral: number, fusion_pool: FusionPoolFacade, tick_arrays: TickArrayFacade[]): IncreaseSpotPositionQuoteResult;
652
+ /**
653
+ * Spot position decrease quote
654
+ *
655
+ * # Parameters
656
+ * - `increase_amount`: Position total size in the collateral_token.
657
+ * - `collateral_token`: Collateral token.
658
+ * - `position_token`: Token of the existing position.
659
+ * - `leverage`: Leverage (1.0 or higher).
660
+ * - `position_amount`: Existing position amount in the position_token.
661
+ * - `position_debt`: Existing position debt in the token opposite to the position_token.
662
+ * - `reduce_only`: Only allow reducing the existing position.
663
+ * - `protocol_fee_rate`: Protocol fee rate from a market account represented as hundredths of a basis point (0.01% = 100).
664
+ * - `protocol_fee_rate_on_collateral`: Protocol fee rate from a market account represented as hundredths of a basis point (0.01% = 100).
665
+ * - `fusion_pool`: Fusion pool.
666
+ * - `tick_arrays`: Five tick arrays around the current pool price.
667
+ *
668
+ * # Returns
669
+ * - `DecreaseSpotPositionQuoteResult`: quote result
670
+ */
671
+ export function getDecreaseSpotPositionQuote(decrease_amount: bigint, collateral_token: PoolTokenFacade, leverage: number, reduce_only: boolean, position_token: PoolTokenFacade, position_amount: bigint, position_debt: bigint, protocol_fee_rate: number, protocol_fee_rate_on_collateral: number, fusion_pool: FusionPoolFacade, tick_arrays: TickArrayFacade[]): DecreaseSpotPositionQuoteResult;
4
672
  /**
5
673
  * Returns the liquidation price
6
674
  *
@@ -14,6 +682,146 @@ export function _INVALID_ARGUMENTS(): string;
14
682
  * - `f64`: Decimal liquidation price
15
683
  */
16
684
  export function getLiquidationPrice(position_token: PoolTokenFacade, amount: number, debt: number, liquidation_threshold: number): number;
685
+ /**
686
+ * Calculates the maximum tradable amount in the collateral token.
687
+ *
688
+ * # Parameters
689
+ * - `collateral_token`: Collateral token.
690
+ * - `available_balance`: Available wallet balance in the collateral_token.
691
+ * - `leverage`: Leverage (1.0 or higher).
692
+ * - `new_position_token`: Token of the new position.
693
+ * - `position_token`: Token of the existing position. Should be set to new_position_token if position_amount is zero.
694
+ * - `position_amount`: Existing position amount in the position_token.
695
+ * - `position_debt`: Existing position debt in the token opposite to the position_token.
696
+ * - `reduce_only`: Only allow reducing the existing position.///
697
+ * - `protocol_fee_rate`: Protocol fee rate from a market account represented as hundredths of a basis point (0.01% = 100).
698
+ * - `protocol_fee_rate_on_collateral`: Protocol fee rate from a market account represented as hundredths of a basis point (0.01% = 100).
699
+ * - `fusion_pool`: Fusion pool.
700
+ * - `tick_arrays`: Five tick arrays around the current pool price.
701
+ *
702
+ * # Returns
703
+ * - `u64`: the maximum tradable amount
704
+ */
705
+ export function getTradableAmount(collateral_token: PoolTokenFacade, available_balance: bigint, leverage: number, new_position_token: PoolTokenFacade, reduce_only: boolean, position_token: PoolTokenFacade, position_amount: bigint, position_debt: bigint, protocol_fee_rate: number, protocol_fee_rate_on_collateral: number, fusion_pool: FusionPoolFacade, tick_arrays: TickArrayFacade[]): bigint;
706
+ export interface TickArrayFacade {
707
+ startTickIndex: number;
708
+ ticks: TickFacade[];
709
+ }
710
+
711
+ export interface TickFacade {
712
+ initialized: boolean;
713
+ liquidityNet: bigint;
714
+ liquidityGross: bigint;
715
+ feeGrowthOutsideA: bigint;
716
+ feeGrowthOutsideB: bigint;
717
+ age: bigint;
718
+ openOrdersInput: bigint;
719
+ partFilledOrdersInput: bigint;
720
+ partFilledOrdersRemainingInput: bigint;
721
+ fulfilledAToBOrdersInput: bigint;
722
+ fulfilledBToAOrdersInput: bigint;
723
+ }
724
+
725
+ export interface TickRange {
726
+ tickLowerIndex: number;
727
+ tickUpperIndex: number;
728
+ }
729
+
730
+ export interface ExactOutSwapQuote {
731
+ tokenOut: bigint;
732
+ tokenEstIn: bigint;
733
+ tokenMaxIn: bigint;
734
+ tradeFee: bigint;
735
+ nextSqrtPrice: bigint;
736
+ }
737
+
738
+ export interface ExactInSwapQuote {
739
+ tokenIn: bigint;
740
+ tokenEstOut: bigint;
741
+ tokenMinOut: bigint;
742
+ tradeFee: bigint;
743
+ nextSqrtPrice: bigint;
744
+ }
745
+
746
+ export interface FusionPoolFacade {
747
+ tickSpacing: number;
748
+ feeRate: number;
749
+ protocolFeeRate: number;
750
+ liquidity: bigint;
751
+ sqrtPrice: bigint;
752
+ tickCurrentIndex: number;
753
+ feeGrowthGlobalA: bigint;
754
+ feeGrowthGlobalB: bigint;
755
+ ordersTotalAmountA: bigint;
756
+ ordersTotalAmountB: bigint;
757
+ ordersFilledAmountA: bigint;
758
+ ordersFilledAmountB: bigint;
759
+ olpFeeOwedA: bigint;
760
+ olpFeeOwedB: bigint;
761
+ }
762
+
763
+ export interface IncreaseLiquidityQuote {
764
+ liquidityDelta: bigint;
765
+ tokenEstA: bigint;
766
+ tokenEstB: bigint;
767
+ tokenMaxA: bigint;
768
+ tokenMaxB: bigint;
769
+ }
770
+
771
+ export interface DecreaseLiquidityQuote {
772
+ liquidityDelta: bigint;
773
+ tokenEstA: bigint;
774
+ tokenEstB: bigint;
775
+ tokenMinA: bigint;
776
+ tokenMinB: bigint;
777
+ }
778
+
779
+ export interface CollectFeesQuote {
780
+ feeOwedA: bigint;
781
+ feeOwedB: bigint;
782
+ }
783
+
784
+ export interface TokenPair {
785
+ a: bigint;
786
+ b: bigint;
787
+ }
788
+
789
+ export interface TransferFee {
790
+ feeBps: number;
791
+ maxFee: bigint;
792
+ }
793
+
794
+ export interface LimitOrderDecreaseQuote {
795
+ amountOutA: bigint;
796
+ amountOutB: bigint;
797
+ rewardA: bigint;
798
+ rewardB: bigint;
799
+ }
800
+
801
+ export interface LimitOrderFacade {
802
+ tickIndex: number;
803
+ amount: bigint;
804
+ aToB: boolean;
805
+ age: bigint;
806
+ }
807
+
808
+ export interface PositionFacade {
809
+ liquidity: bigint;
810
+ tickLowerIndex: number;
811
+ tickUpperIndex: number;
812
+ feeGrowthCheckpointA: bigint;
813
+ feeOwedA: bigint;
814
+ feeGrowthCheckpointB: bigint;
815
+ feeOwedB: bigint;
816
+ }
817
+
818
+ export type PositionStatus = "priceInRange" | "priceBelowRange" | "priceAboveRange" | "invalid";
819
+
820
+ export interface PositionRatio {
821
+ ratioA: bigint;
822
+ ratioB: bigint;
823
+ }
824
+
17
825
  export interface TunaSpotPositionFacade {
18
826
  version: number;
19
827
  marketMaker: MarketMakerFacade;
@@ -32,3 +840,26 @@ export type MarketMakerFacade = "orca" | "fusion";
32
840
 
33
841
  export type PoolTokenFacade = "a" | "b";
34
842
 
843
+ export interface DecreaseSpotPositionQuoteResult {
844
+ decreasePercent: number;
845
+ collateralToken: PoolTokenFacade;
846
+ positionToken: PoolTokenFacade;
847
+ collateral: bigint;
848
+ borrow: bigint;
849
+ swapInputAmount: bigint;
850
+ estimatedAmount: bigint;
851
+ protocolFeeA: bigint;
852
+ protocolFeeB: bigint;
853
+ priceImpact: number;
854
+ }
855
+
856
+ export interface IncreaseSpotPositionQuoteResult {
857
+ collateral: bigint;
858
+ borrow: bigint;
859
+ estimatedAmount: bigint;
860
+ swapInputAmount: bigint;
861
+ protocolFeeA: bigint;
862
+ protocolFeeB: bigint;
863
+ priceImpact: number;
864
+ }
865
+