@crypticdot/defituna-core 3.3.5 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/defituna_core_js_bindings.d.ts +333 -311
- package/dist/browser/defituna_core_js_bindings_bg.js +520 -488
- package/dist/browser/defituna_core_js_bindings_bg.wasm +0 -0
- package/dist/browser/defituna_core_js_bindings_bg.wasm.d.ts +40 -39
- package/dist/nodejs/defituna_core_js_bindings.d.ts +333 -311
- package/dist/nodejs/defituna_core_js_bindings.js +520 -488
- package/dist/nodejs/defituna_core_js_bindings_bg.wasm +0 -0
- package/dist/nodejs/defituna_core_js_bindings_bg.wasm.d.ts +40 -39
- package/package.json +2 -2
|
@@ -1,5 +1,140 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Calculate the amount A delta between two sqrt_prices
|
|
5
|
+
*
|
|
6
|
+
* # Parameters
|
|
7
|
+
* - `sqrt_price_1`: The first square root price
|
|
8
|
+
* - `sqrt_price_2`: The second square root price
|
|
9
|
+
* - `liquidity`: The liquidity
|
|
10
|
+
* - `round_up`: Whether to round up or not
|
|
11
|
+
*
|
|
12
|
+
* # Returns
|
|
13
|
+
* - `u64`: The amount delta
|
|
14
|
+
*/
|
|
15
|
+
export function tryGetAmountDeltaA(sqrt_price_1: bigint, sqrt_price_2: bigint, liquidity: bigint, round_up: boolean): bigint;
|
|
16
|
+
/**
|
|
17
|
+
* Calculate the amount B delta between two sqrt_prices
|
|
18
|
+
*
|
|
19
|
+
* # Parameters
|
|
20
|
+
* - `sqrt_price_1`: The first square root price
|
|
21
|
+
* - `sqrt_price_2`: The second square root price
|
|
22
|
+
* - `liquidity`: The liquidity
|
|
23
|
+
* - `round_up`: Whether to round up or not
|
|
24
|
+
*
|
|
25
|
+
* # Returns
|
|
26
|
+
* - `u64`: The amount delta
|
|
27
|
+
*/
|
|
28
|
+
export function tryGetAmountDeltaB(sqrt_price_1: bigint, sqrt_price_2: bigint, liquidity: bigint, round_up: boolean): bigint;
|
|
29
|
+
/**
|
|
30
|
+
* Calculate the next square root price
|
|
31
|
+
*
|
|
32
|
+
* # Parameters
|
|
33
|
+
* - `current_sqrt_price`: The current square root price
|
|
34
|
+
* - `current_liquidity`: The current liquidity
|
|
35
|
+
* - `amount`: The amount
|
|
36
|
+
* - `specified_input`: Whether the input is specified
|
|
37
|
+
*
|
|
38
|
+
* # Returns
|
|
39
|
+
* - `u128`: The next square root price
|
|
40
|
+
*/
|
|
41
|
+
export function tryGetNextSqrtPriceFromA(current_sqrt_price: bigint, current_liquidity: bigint, amount: bigint, specified_input: boolean): bigint;
|
|
42
|
+
/**
|
|
43
|
+
* Calculate the next square root price
|
|
44
|
+
*
|
|
45
|
+
* # Parameters
|
|
46
|
+
* - `current_sqrt_price`: The current square root price
|
|
47
|
+
* - `current_liquidity`: The current liquidity
|
|
48
|
+
* - `amount`: The amount
|
|
49
|
+
* - `specified_input`: Whether the input is specified
|
|
50
|
+
*
|
|
51
|
+
* # Returns
|
|
52
|
+
* - `u128`: The next square root price
|
|
53
|
+
*/
|
|
54
|
+
export function tryGetNextSqrtPriceFromB(current_sqrt_price: bigint, current_liquidity: bigint, amount: bigint, specified_input: boolean): bigint;
|
|
55
|
+
/**
|
|
56
|
+
* Apply a transfer fee to an amount
|
|
57
|
+
* e.g. You send 10000 amount with 100 fee rate. The fee amount will be 100.
|
|
58
|
+
* So the amount after fee will be 9900.
|
|
59
|
+
*
|
|
60
|
+
* # Parameters
|
|
61
|
+
* - `amount`: The amount to apply the fee to
|
|
62
|
+
* - `transfer_fee`: The transfer fee to apply
|
|
63
|
+
*
|
|
64
|
+
* # Returns
|
|
65
|
+
* - `u64`: The amount after the fee has been applied
|
|
66
|
+
*/
|
|
67
|
+
export function tryApplyTransferFee(amount: bigint, transfer_fee: TransferFee): bigint;
|
|
68
|
+
/**
|
|
69
|
+
* Reverse the application of a transfer fee to an amount
|
|
70
|
+
* e.g. You received 9900 amount with 100 fee rate. The fee amount will be 100.
|
|
71
|
+
* So the amount before fee will be 10000.
|
|
72
|
+
*
|
|
73
|
+
* # Parameters
|
|
74
|
+
* - `amount`: The amount to reverse the fee from
|
|
75
|
+
* - `transfer_fee`: The transfer fee to reverse
|
|
76
|
+
*
|
|
77
|
+
* # Returns
|
|
78
|
+
* - `u64`: The amount before the fee has been applied
|
|
79
|
+
*/
|
|
80
|
+
export function tryReverseApplyTransferFee(amount: bigint, transfer_fee: TransferFee): bigint;
|
|
81
|
+
/**
|
|
82
|
+
* Get the maximum amount with a slippage tolerance
|
|
83
|
+
* e.g. Your estimated amount you send is 10000 with 100 slippage tolerance. The max you send will be 10100.
|
|
84
|
+
*
|
|
85
|
+
* # Parameters
|
|
86
|
+
* - `amount`: The amount to apply the fee to
|
|
87
|
+
* - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
|
|
88
|
+
*
|
|
89
|
+
* # Returns
|
|
90
|
+
* - `u64`: The maximum amount
|
|
91
|
+
*/
|
|
92
|
+
export function tryGetMaxAmountWithSlippageTolerance(amount: bigint, slippage_tolerance_bps: number): bigint;
|
|
93
|
+
/**
|
|
94
|
+
* Get the minimum amount with a slippage tolerance
|
|
95
|
+
* e.g. Your estimated amount you receive is 10000 with 100 slippage tolerance. The min amount you receive will be 9900.
|
|
96
|
+
*
|
|
97
|
+
* # Parameters
|
|
98
|
+
* - `amount`: The amount to apply the fee to
|
|
99
|
+
* - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
|
|
100
|
+
*
|
|
101
|
+
* # Returns
|
|
102
|
+
* - `u64`: The minimum amount
|
|
103
|
+
*/
|
|
104
|
+
export function tryGetMinAmountWithSlippageTolerance(amount: bigint, slippage_tolerance_bps: number): bigint;
|
|
105
|
+
/**
|
|
106
|
+
* Apply a swap fee to an amount
|
|
107
|
+
* e.g. You send 10000 amount with 10000 fee rate. The fee amount will be 100.
|
|
108
|
+
* So the amount after fee will be 9900.
|
|
109
|
+
*
|
|
110
|
+
* # Parameters
|
|
111
|
+
* - `amount`: The amount to apply the fee to
|
|
112
|
+
* - `fee_rate`: The fee rate to apply denominated in 1e6
|
|
113
|
+
*
|
|
114
|
+
* # Returns
|
|
115
|
+
* - `u64`: The amount after the fee has been applied
|
|
116
|
+
*/
|
|
117
|
+
export function tryApplySwapFee(amount: bigint, fee_rate: number): bigint;
|
|
118
|
+
/**
|
|
119
|
+
* Reverse the application of a swap fee to an amount
|
|
120
|
+
* e.g. You received 9900 amount with 10000 fee rate. The fee amount will be 100.
|
|
121
|
+
* So the amount before fee will be 10000.
|
|
122
|
+
*
|
|
123
|
+
* # Parameters
|
|
124
|
+
* - `amount`: The amount to reverse the fee from
|
|
125
|
+
* - `fee_rate`: The fee rate to reverse denominated in 1e6
|
|
126
|
+
*
|
|
127
|
+
* # Returns
|
|
128
|
+
* - `u64`: The amount before the fee has been applied
|
|
129
|
+
*/
|
|
130
|
+
export function tryReverseApplySwapFee(amount: bigint, fee_rate: number): bigint;
|
|
131
|
+
export function _FEE_RATE_MUL_VALUE(): number;
|
|
132
|
+
export function _MAX_PROTOCOL_FEE_RATE(): number;
|
|
133
|
+
export function _PROTOCOL_FEE_RATE_MUL_VALUE(): number;
|
|
134
|
+
export function _TICK_ARRAY_SIZE(): number;
|
|
135
|
+
export function _FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD(): number;
|
|
136
|
+
export function _MIN_TICK_INDEX(): number;
|
|
137
|
+
export function _MAX_TICK_INDEX(): number;
|
|
3
138
|
/**
|
|
4
139
|
* Get the first tick index in the tick array that contains the specified tick index.
|
|
5
140
|
*
|
|
@@ -159,162 +294,6 @@ export function isFullRangeOnly(tick_spacing: number): boolean;
|
|
|
159
294
|
* - A u32 integer representing the tick index in the tick array
|
|
160
295
|
*/
|
|
161
296
|
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
297
|
/**
|
|
319
298
|
* Calculate the quote for decreasing liquidity
|
|
320
299
|
*
|
|
@@ -422,90 +401,44 @@ export function tryGetTokenEstimatesFromLiquidity(liquidity_delta: bigint, curre
|
|
|
422
401
|
* # Paramters
|
|
423
402
|
* - `fusion_pool`: The fusion_pool state
|
|
424
403
|
* - `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
|
|
404
|
+
* - `tick_lower`: The lower tick state
|
|
405
|
+
* - `tick_upper`: The upper tick state
|
|
406
|
+
* - `transfer_fee_a`: The transfer fee for token A
|
|
407
|
+
* - `transfer_fee_b`: The transfer fee for token B
|
|
504
408
|
*
|
|
505
409
|
* # Returns
|
|
506
|
-
*
|
|
410
|
+
* - `CollectFeesQuote`: The fees owed for token A and token B
|
|
507
411
|
*/
|
|
508
|
-
export function
|
|
412
|
+
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;
|
|
413
|
+
export function limitOrderFee(fusion_pool: FusionPoolFacade): number;
|
|
414
|
+
/**
|
|
415
|
+
* Computes the limit order output amount by input amount.
|
|
416
|
+
* ### Parameters
|
|
417
|
+
* - `amount_in` - The input token amount of a limit order.
|
|
418
|
+
* - `a_to_b_order` - The limit order direction.
|
|
419
|
+
* - `tick_index` - The tick index of an order.
|
|
420
|
+
* - `fusion_pool` - The fusion_pool state.
|
|
421
|
+
*/
|
|
422
|
+
export function limitOrderQuoteByInputToken(amount_in: bigint, a_to_b_order: boolean, tick_index: number, fusion_pool: FusionPoolFacade): bigint;
|
|
423
|
+
/**
|
|
424
|
+
* Computes the limit order input amount by output amount.
|
|
425
|
+
* ### Parameters
|
|
426
|
+
* - `amount_out` - The output token amount of a limit order.
|
|
427
|
+
* - `a_to_b_order` - The limit order direction.
|
|
428
|
+
* - `tick_index` - The tick index of an order.
|
|
429
|
+
* - `fusion_pool` - The fusion_pool state.
|
|
430
|
+
*/
|
|
431
|
+
export function limitOrderQuoteByOutputToken(amount_out: bigint, a_to_b_order: boolean, tick_index: number, fusion_pool: FusionPoolFacade): bigint;
|
|
432
|
+
/**
|
|
433
|
+
* Computes the limit order reward by input amount.
|
|
434
|
+
* ### Parameters
|
|
435
|
+
* - `amount_out` - The output token amount of a limit order (swap input).
|
|
436
|
+
* - `a_to_b_order` - The limit order direction.
|
|
437
|
+
* - `tick_index` - The tick index of an order.
|
|
438
|
+
* - `fusion_pool` - The fusion_pool state.
|
|
439
|
+
*/
|
|
440
|
+
export function limitOrderRewardByOutputToken(amount_out: bigint, fee_rate: number, protocol_fee_rate: number): bigint;
|
|
441
|
+
export function decreaseLimitOrderQuote(fusion_pool: FusionPoolFacade, limit_order: LimitOrderFacade, tick: TickFacade, amount: bigint, transfer_fee_a?: TransferFee | null, transfer_fee_b?: TransferFee | null): LimitOrderDecreaseQuote;
|
|
509
442
|
export function _POSITION_BUNDLE_SIZE(): number;
|
|
510
443
|
export function _TICK_ARRAY_NOT_EVENLY_SPACED(): string;
|
|
511
444
|
export function _TICK_INDEX_OUT_OF_BOUNDS(): string;
|
|
@@ -524,9 +457,6 @@ export function _INVALID_SLIPPAGE_TOLERANCE(): string;
|
|
|
524
457
|
export function _TICK_INDEX_NOT_IN_ARRAY(): string;
|
|
525
458
|
export function _INVALID_TICK_ARRAY_SEQUENCE(): string;
|
|
526
459
|
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
460
|
/**
|
|
531
461
|
* Get the first unoccupied position in a bundle
|
|
532
462
|
*
|
|
@@ -599,6 +529,93 @@ export function positionStatus(current_sqrt_price: bigint, tick_index_1: number,
|
|
|
599
529
|
* - A PositionRatio struct containing the ratio of token_a and token_b
|
|
600
530
|
*/
|
|
601
531
|
export function positionRatioX64(current_sqrt_price: bigint, tick_index_1: number, tick_index_2: number): PositionRatio;
|
|
532
|
+
/**
|
|
533
|
+
* Convert a price into a sqrt priceX64
|
|
534
|
+
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
535
|
+
* Make sure to do these operations last and not to use the result for further calculations.
|
|
536
|
+
*
|
|
537
|
+
* # Parameters
|
|
538
|
+
* * `price` - The price to convert
|
|
539
|
+
* * `decimals_a` - The number of decimals of the base token
|
|
540
|
+
* * `decimals_b` - The number of decimals of the quote token
|
|
541
|
+
*
|
|
542
|
+
* # Returns
|
|
543
|
+
* * `u128` - The sqrt priceX64
|
|
544
|
+
*/
|
|
545
|
+
export function priceToSqrtPrice(price: number, decimals_a: number, decimals_b: number): bigint;
|
|
546
|
+
/**
|
|
547
|
+
* Convert a sqrt priceX64 into a tick index
|
|
548
|
+
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
549
|
+
* Make sure to do these operations last and not to use the result for further calculations.
|
|
550
|
+
*
|
|
551
|
+
* # Parameters
|
|
552
|
+
* * `sqrt_price` - The sqrt priceX64 to convert
|
|
553
|
+
* * `decimals_a` - The number of decimals of the base token
|
|
554
|
+
* * `decimals_b` - The number of decimals of the quote token
|
|
555
|
+
*
|
|
556
|
+
* # Returns
|
|
557
|
+
* * `f64` - The decimal price
|
|
558
|
+
*/
|
|
559
|
+
export function sqrtPriceToPrice(sqrt_price: bigint, decimals_a: number, decimals_b: number): number;
|
|
560
|
+
/**
|
|
561
|
+
* Invert a price
|
|
562
|
+
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
563
|
+
* Make sure to do these operations last and not to use the result for further calculations.
|
|
564
|
+
*
|
|
565
|
+
* # Parameters
|
|
566
|
+
* * `price` - The price to invert
|
|
567
|
+
* * `decimals_a` - The number of decimals of the base token
|
|
568
|
+
* * `decimals_b` - The number of decimals of the quote token
|
|
569
|
+
*
|
|
570
|
+
* # Returns
|
|
571
|
+
* * `f64` - The inverted price
|
|
572
|
+
*/
|
|
573
|
+
export function invertPrice(price: number, decimals_a: number, decimals_b: number): number;
|
|
574
|
+
/**
|
|
575
|
+
* Convert a tick index into a price
|
|
576
|
+
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
577
|
+
* Make sure to do these operations last and not to use the result for further calculations.
|
|
578
|
+
*
|
|
579
|
+
* # Parameters
|
|
580
|
+
* * `tick_index` - The tick index to convert
|
|
581
|
+
* * `decimals_a` - The number of decimals of the base token
|
|
582
|
+
* * `decimals_b` - The number of decimals of the quote token
|
|
583
|
+
*
|
|
584
|
+
* # Returns
|
|
585
|
+
* * `f64` - The decimal price
|
|
586
|
+
*/
|
|
587
|
+
export function tickIndexToPrice(tick_index: number, decimals_a: number, decimals_b: number): number;
|
|
588
|
+
/**
|
|
589
|
+
* Convert a price into a tick index
|
|
590
|
+
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
591
|
+
* Make sure to do these operations last and not to use the result for further calculations.
|
|
592
|
+
*
|
|
593
|
+
* # Parameters
|
|
594
|
+
* * `price` - The price to convert
|
|
595
|
+
* * `decimals_a` - The number of decimals of the base token
|
|
596
|
+
* * `decimals_b` - The number of decimals of the quote token
|
|
597
|
+
*
|
|
598
|
+
* # Returns
|
|
599
|
+
* * `i32` - The tick index
|
|
600
|
+
*/
|
|
601
|
+
export function priceToTickIndex(price: number, decimals_a: number, decimals_b: number): number;
|
|
602
|
+
/**
|
|
603
|
+
* Computes the liquidation prices for an existing position.
|
|
604
|
+
*
|
|
605
|
+
* # Parameters
|
|
606
|
+
* - `lower_tick_index`: The lower tick index of the position.
|
|
607
|
+
* - `upper_tick_index`: The upper tick index of the position.
|
|
608
|
+
* - `leftovers_a`: The amount of leftovers A in the position.
|
|
609
|
+
* - `leftovers_a`: The amount of leftovers B in the position.
|
|
610
|
+
* - `liquidity`: Liquidity of the position.
|
|
611
|
+
* - `debt_a`: The amount of tokens A borrowed.
|
|
612
|
+
* - `debt_b`: The amount of tokens B borrowed.
|
|
613
|
+
* - `liquidation_threshold`: The liquidation threshold of the market.
|
|
614
|
+
*
|
|
615
|
+
* # Returns
|
|
616
|
+
* - `LiquidationPrices`: An object containing lower/upper liquidation prices.
|
|
617
|
+
*/
|
|
618
|
+
export function getLpPositionLiquidationPrices(lower_tick_index: number, upper_tick_index: number, liquidity: bigint, leftovers_a: bigint, leftovers_b: bigint, debt_a: bigint, debt_b: bigint, liquidation_threshold: number): LiquidationPrices;
|
|
602
619
|
/**
|
|
603
620
|
* Computes the exact input or output amount for a swap transaction.
|
|
604
621
|
*
|
|
@@ -681,7 +698,7 @@ export function getDecreaseSpotPositionQuote(decrease_amount: bigint, collateral
|
|
|
681
698
|
* # Returns
|
|
682
699
|
* - `f64`: Decimal liquidation price
|
|
683
700
|
*/
|
|
684
|
-
export function
|
|
701
|
+
export function getSpotPositionLiquidationPrice(position_token: number, amount: number, debt: number, liquidation_threshold: number): number;
|
|
685
702
|
/**
|
|
686
703
|
* Calculates the maximum tradable amount in the collateral token.
|
|
687
704
|
*
|
|
@@ -700,7 +717,7 @@ export function getLiquidationPrice(position_token: number, amount: number, debt
|
|
|
700
717
|
* - `u64`: the maximum tradable amount
|
|
701
718
|
*/
|
|
702
719
|
export function getTradableAmount(collateral_token: number, available_balance: bigint, leverage: number, position_token: number, position_amount: bigint, protocol_fee_rate: number, protocol_fee_rate_on_collateral: number, fusion_pool: FusionPoolFacade, increase: boolean): bigint;
|
|
703
|
-
export function
|
|
720
|
+
export function calculateTunaSpotPositionProtocolFee(collateral_token: number, borrowed_token: number, collateral: bigint, borrow: bigint, protocol_fee_rate_on_collateral: number, protocol_fee_rate: number): TokenPair;
|
|
704
721
|
export function _INVALID_ARGUMENTS(): string;
|
|
705
722
|
export function _JUPITER_QUOTE_REQUEST_ERROR(): string;
|
|
706
723
|
export function _JUPITER_SWAP_INSTRUCTIONS_REQUEST_ERROR(): string;
|
|
@@ -708,35 +725,6 @@ export function _JUPITER_SWAP_INSTRUCTIONS_REQUEST_ERROR(): string;
|
|
|
708
725
|
* Initialize Javascript logging and panic handler
|
|
709
726
|
*/
|
|
710
727
|
export function solana_program_init(): void;
|
|
711
|
-
export interface CollectFeesQuote {
|
|
712
|
-
feeOwedA: bigint;
|
|
713
|
-
feeOwedB: bigint;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
export interface TickArrayFacade {
|
|
717
|
-
startTickIndex: number;
|
|
718
|
-
ticks: TickFacade[];
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
export interface TickFacade {
|
|
722
|
-
initialized: boolean;
|
|
723
|
-
liquidityNet: bigint;
|
|
724
|
-
liquidityGross: bigint;
|
|
725
|
-
feeGrowthOutsideA: bigint;
|
|
726
|
-
feeGrowthOutsideB: bigint;
|
|
727
|
-
age: bigint;
|
|
728
|
-
openOrdersInput: bigint;
|
|
729
|
-
partFilledOrdersInput: bigint;
|
|
730
|
-
partFilledOrdersRemainingInput: bigint;
|
|
731
|
-
fulfilledAToBOrdersInput: bigint;
|
|
732
|
-
fulfilledBToAOrdersInput: bigint;
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
export interface TickRange {
|
|
736
|
-
tickLowerIndex: number;
|
|
737
|
-
tickUpperIndex: number;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
728
|
export interface ExactOutSwapQuote {
|
|
741
729
|
tokenOut: bigint;
|
|
742
730
|
tokenEstIn: bigint;
|
|
@@ -770,32 +758,6 @@ export interface FusionPoolFacade {
|
|
|
770
758
|
olpFeeOwedB: bigint;
|
|
771
759
|
}
|
|
772
760
|
|
|
773
|
-
export interface IncreaseLiquidityQuote {
|
|
774
|
-
liquidityDelta: bigint;
|
|
775
|
-
tokenEstA: bigint;
|
|
776
|
-
tokenEstB: bigint;
|
|
777
|
-
tokenMaxA: bigint;
|
|
778
|
-
tokenMaxB: bigint;
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
export interface DecreaseLiquidityQuote {
|
|
782
|
-
liquidityDelta: bigint;
|
|
783
|
-
tokenEstA: bigint;
|
|
784
|
-
tokenEstB: bigint;
|
|
785
|
-
tokenMinA: bigint;
|
|
786
|
-
tokenMinB: bigint;
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
export interface TokenPair {
|
|
790
|
-
a: bigint;
|
|
791
|
-
b: bigint;
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
export interface TransferFee {
|
|
795
|
-
feeBps: number;
|
|
796
|
-
maxFee: bigint;
|
|
797
|
-
}
|
|
798
|
-
|
|
799
761
|
export interface LimitOrderDecreaseQuote {
|
|
800
762
|
amountOutA: bigint;
|
|
801
763
|
amountOutB: bigint;
|
|
@@ -810,6 +772,11 @@ export interface LimitOrderFacade {
|
|
|
810
772
|
age: bigint;
|
|
811
773
|
}
|
|
812
774
|
|
|
775
|
+
export interface TokenPair {
|
|
776
|
+
a: bigint;
|
|
777
|
+
b: bigint;
|
|
778
|
+
}
|
|
779
|
+
|
|
813
780
|
export interface PositionFacade {
|
|
814
781
|
liquidity: bigint;
|
|
815
782
|
tickLowerIndex: number;
|
|
@@ -827,6 +794,75 @@ export interface PositionRatio {
|
|
|
827
794
|
ratioB: bigint;
|
|
828
795
|
}
|
|
829
796
|
|
|
797
|
+
export interface TickArrayFacade {
|
|
798
|
+
startTickIndex: number;
|
|
799
|
+
ticks: TickFacade[];
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
export interface TickFacade {
|
|
803
|
+
initialized: boolean;
|
|
804
|
+
liquidityNet: bigint;
|
|
805
|
+
liquidityGross: bigint;
|
|
806
|
+
feeGrowthOutsideA: bigint;
|
|
807
|
+
feeGrowthOutsideB: bigint;
|
|
808
|
+
age: bigint;
|
|
809
|
+
openOrdersInput: bigint;
|
|
810
|
+
partFilledOrdersInput: bigint;
|
|
811
|
+
partFilledOrdersRemainingInput: bigint;
|
|
812
|
+
fulfilledAToBOrdersInput: bigint;
|
|
813
|
+
fulfilledBToAOrdersInput: bigint;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
export interface TickRange {
|
|
817
|
+
tickLowerIndex: number;
|
|
818
|
+
tickUpperIndex: number;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
export interface IncreaseLiquidityQuote {
|
|
822
|
+
liquidityDelta: bigint;
|
|
823
|
+
tokenEstA: bigint;
|
|
824
|
+
tokenEstB: bigint;
|
|
825
|
+
tokenMaxA: bigint;
|
|
826
|
+
tokenMaxB: bigint;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
export interface DecreaseLiquidityQuote {
|
|
830
|
+
liquidityDelta: bigint;
|
|
831
|
+
tokenEstA: bigint;
|
|
832
|
+
tokenEstB: bigint;
|
|
833
|
+
tokenMinA: bigint;
|
|
834
|
+
tokenMinB: bigint;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
export interface CollectFeesQuote {
|
|
838
|
+
feeOwedA: bigint;
|
|
839
|
+
feeOwedB: bigint;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
export interface TransferFee {
|
|
843
|
+
feeBps: number;
|
|
844
|
+
maxFee: bigint;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
export interface TunaSpotPositionFacade {
|
|
848
|
+
version: number;
|
|
849
|
+
marketMaker: number;
|
|
850
|
+
positionToken: number;
|
|
851
|
+
collateralToken: number;
|
|
852
|
+
flags: number;
|
|
853
|
+
amount: bigint;
|
|
854
|
+
loanShares: bigint;
|
|
855
|
+
loanFunds: bigint;
|
|
856
|
+
entrySqrtPrice: bigint;
|
|
857
|
+
lowerLimitOrderSqrtPrice: bigint;
|
|
858
|
+
upperLimitOrderSqrtPrice: bigint;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
export interface LiquidationPrices {
|
|
862
|
+
lower: number;
|
|
863
|
+
upper: number;
|
|
864
|
+
}
|
|
865
|
+
|
|
830
866
|
export interface SwapInstruction {
|
|
831
867
|
data: number[];
|
|
832
868
|
accounts: AccountMeta[];
|
|
@@ -855,20 +891,6 @@ export interface DecreaseSpotPositionQuoteResult {
|
|
|
855
891
|
jupiterSwapIx: SwapInstruction | undefined;
|
|
856
892
|
}
|
|
857
893
|
|
|
858
|
-
export interface TunaSpotPositionFacade {
|
|
859
|
-
version: number;
|
|
860
|
-
marketMaker: number;
|
|
861
|
-
positionToken: number;
|
|
862
|
-
collateralToken: number;
|
|
863
|
-
flags: number;
|
|
864
|
-
amount: bigint;
|
|
865
|
-
loanShares: bigint;
|
|
866
|
-
loanFunds: bigint;
|
|
867
|
-
entrySqrtPrice: bigint;
|
|
868
|
-
lowerLimitOrderSqrtPrice: bigint;
|
|
869
|
-
upperLimitOrderSqrtPrice: bigint;
|
|
870
|
-
}
|
|
871
|
-
|
|
872
894
|
/**
|
|
873
895
|
* A hash; the 32-byte output of a hashing algorithm.
|
|
874
896
|
*
|