@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.
- package/dist/browser/orca_whirlpools_core_js_bindings.d.ts +309 -289
- package/dist/browser/orca_whirlpools_core_js_bindings_bg.js +595 -575
- package/dist/browser/orca_whirlpools_core_js_bindings_bg.wasm +0 -0
- package/dist/browser/orca_whirlpools_core_js_bindings_bg.wasm.d.ts +29 -28
- package/dist/browser/package.json +1 -1
- package/dist/nodejs/orca_whirlpools_core_js_bindings.d.ts +309 -289
- package/dist/nodejs/orca_whirlpools_core_js_bindings.js +595 -575
- package/dist/nodejs/orca_whirlpools_core_js_bindings_bg.wasm +0 -0
- package/dist/nodejs/orca_whirlpools_core_js_bindings_bg.wasm.d.ts +29 -28
- package/dist/nodejs/package.json +1 -1
- package/package.json +4 -2
|
@@ -192,230 +192,441 @@ function getStringFromWasm0(ptr, len) {
|
|
|
192
192
|
ptr = ptr >>> 0;
|
|
193
193
|
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
194
194
|
}
|
|
195
|
+
|
|
196
|
+
module.exports._TICK_ARRAY_SIZE = function() {
|
|
197
|
+
const ret = wasm._TICK_ARRAY_SIZE();
|
|
198
|
+
return ret >>> 0;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
module.exports._FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD = function() {
|
|
202
|
+
const ret = wasm._FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD();
|
|
203
|
+
return ret;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
module.exports._MIN_TICK_INDEX = function() {
|
|
207
|
+
const ret = wasm._MIN_TICK_INDEX();
|
|
208
|
+
return ret;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
module.exports._MAX_TICK_INDEX = function() {
|
|
212
|
+
const ret = wasm._MAX_TICK_INDEX();
|
|
213
|
+
return ret;
|
|
214
|
+
};
|
|
215
|
+
|
|
195
216
|
/**
|
|
196
|
-
*
|
|
217
|
+
* Convert a price into a sqrt priceX64
|
|
218
|
+
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
219
|
+
* Make sure to do these operations last and not to use the result for further calculations.
|
|
197
220
|
*
|
|
198
|
-
* #
|
|
199
|
-
*
|
|
221
|
+
* # Parameters
|
|
222
|
+
* * `price` - The price to convert
|
|
223
|
+
* * `decimals_a` - The number of decimals of the base token
|
|
224
|
+
* * `decimals_b` - The number of decimals of the quote token
|
|
200
225
|
*
|
|
201
226
|
* # Returns
|
|
202
|
-
*
|
|
227
|
+
* * `u128` - The sqrt priceX64
|
|
203
228
|
*/
|
|
204
|
-
module.exports.
|
|
205
|
-
const ret = wasm.
|
|
229
|
+
module.exports.priceToSqrtPrice = function(price, decimals_a, decimals_b) {
|
|
230
|
+
const ret = wasm.priceToSqrtPrice(price, decimals_a, decimals_b);
|
|
231
|
+
return takeObject(ret);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Convert a sqrt priceX64 into a tick index
|
|
236
|
+
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
237
|
+
* Make sure to do these operations last and not to use the result for further calculations.
|
|
238
|
+
*
|
|
239
|
+
* # Parameters
|
|
240
|
+
* * `sqrt_price` - The sqrt priceX64 to convert
|
|
241
|
+
* * `decimals_a` - The number of decimals of the base token
|
|
242
|
+
* * `decimals_b` - The number of decimals of the quote token
|
|
243
|
+
*
|
|
244
|
+
* # Returns
|
|
245
|
+
* * `f64` - The decimal price
|
|
246
|
+
*/
|
|
247
|
+
module.exports.sqrtPriceToPrice = function(sqrt_price, decimals_a, decimals_b) {
|
|
248
|
+
const ret = wasm.sqrtPriceToPrice(addHeapObject(sqrt_price), decimals_a, decimals_b);
|
|
249
|
+
return ret;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Invert a price
|
|
254
|
+
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
255
|
+
* Make sure to do these operations last and not to use the result for further calculations.
|
|
256
|
+
*
|
|
257
|
+
* # Parameters
|
|
258
|
+
* * `price` - The price to invert
|
|
259
|
+
* * `decimals_a` - The number of decimals of the base token
|
|
260
|
+
* * `decimals_b` - The number of decimals of the quote token
|
|
261
|
+
*
|
|
262
|
+
* # Returns
|
|
263
|
+
* * `f64` - The inverted price
|
|
264
|
+
*/
|
|
265
|
+
module.exports.invertPrice = function(price, decimals_a, decimals_b) {
|
|
266
|
+
const ret = wasm.invertPrice(price, decimals_a, decimals_b);
|
|
267
|
+
return ret;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Convert a tick index into a price
|
|
272
|
+
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
273
|
+
* Make sure to do these operations last and not to use the result for further calculations.
|
|
274
|
+
*
|
|
275
|
+
* # Parameters
|
|
276
|
+
* * `tick_index` - The tick index to convert
|
|
277
|
+
* * `decimals_a` - The number of decimals of the base token
|
|
278
|
+
* * `decimals_b` - The number of decimals of the quote token
|
|
279
|
+
*
|
|
280
|
+
* # Returns
|
|
281
|
+
* * `f64` - The decimal price
|
|
282
|
+
*/
|
|
283
|
+
module.exports.tickIndexToPrice = function(tick_index, decimals_a, decimals_b) {
|
|
284
|
+
const ret = wasm.tickIndexToPrice(tick_index, decimals_a, decimals_b);
|
|
285
|
+
return ret;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Convert a price into a tick index
|
|
290
|
+
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
291
|
+
* Make sure to do these operations last and not to use the result for further calculations.
|
|
292
|
+
*
|
|
293
|
+
* # Parameters
|
|
294
|
+
* * `price` - The price to convert
|
|
295
|
+
* * `decimals_a` - The number of decimals of the base token
|
|
296
|
+
* * `decimals_b` - The number of decimals of the quote token
|
|
297
|
+
*
|
|
298
|
+
* # Returns
|
|
299
|
+
* * `i32` - The tick index
|
|
300
|
+
*/
|
|
301
|
+
module.exports.priceToTickIndex = function(price, decimals_a, decimals_b) {
|
|
302
|
+
const ret = wasm.priceToTickIndex(price, decimals_a, decimals_b);
|
|
303
|
+
return ret;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Computes min/max sqrt-price bounds for slippage protection.
|
|
308
|
+
*
|
|
309
|
+
* Cap: `slippage_tolerance_bps` is clamped to BPS_DENOMINATOR (10_000) so the radicands
|
|
310
|
+
* `(10000 ± bps)` stay non-negative and we never take sqrt of a negative.
|
|
311
|
+
*
|
|
312
|
+
* # Parameters
|
|
313
|
+
* * `sqrt_price` - The current sqrt priceX64
|
|
314
|
+
* * `slippage_tolerance_bps` - The slippage tolerance in basis points
|
|
315
|
+
*
|
|
316
|
+
* # Returns
|
|
317
|
+
* * `SqrtPriceSlippageBounds` - The min and max sqrt price bounds
|
|
318
|
+
*/
|
|
319
|
+
module.exports.getSqrtPriceSlippageBounds = function(sqrt_price, slippage_tolerance_bps) {
|
|
320
|
+
const ret = wasm.getSqrtPriceSlippageBounds(addHeapObject(sqrt_price), slippage_tolerance_bps);
|
|
321
|
+
return takeObject(ret);
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
module.exports._POSITION_BUNDLE_SIZE = function() {
|
|
325
|
+
const ret = wasm._POSITION_BUNDLE_SIZE();
|
|
326
|
+
return ret >>> 0;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
module.exports._FEE_RATE_DENOMINATOR = function() {
|
|
330
|
+
const ret = wasm._FEE_RATE_DENOMINATOR();
|
|
331
|
+
return ret >>> 0;
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Check if a position is in range.
|
|
336
|
+
* When a position is in range it is earning fees and rewards
|
|
337
|
+
*
|
|
338
|
+
* # Parameters
|
|
339
|
+
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
340
|
+
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
341
|
+
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
342
|
+
*
|
|
343
|
+
* # Returns
|
|
344
|
+
* - A boolean value indicating if the position is in range
|
|
345
|
+
*/
|
|
346
|
+
module.exports.isPositionInRange = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
347
|
+
const ret = wasm.isPositionInRange(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
|
|
206
348
|
return ret !== 0;
|
|
207
349
|
};
|
|
208
350
|
|
|
209
351
|
/**
|
|
210
|
-
* Calculate the
|
|
352
|
+
* Calculate the status of a position
|
|
353
|
+
* The status can be one of three values:
|
|
354
|
+
* - InRange: The position is in range
|
|
355
|
+
* - BelowRange: The position is below the range
|
|
356
|
+
* - AboveRange: The position is above the range
|
|
211
357
|
*
|
|
212
358
|
* # Parameters
|
|
213
|
-
* - `
|
|
214
|
-
* - `
|
|
215
|
-
* - `
|
|
216
|
-
* - `round_up`: Whether to round up or not
|
|
359
|
+
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
360
|
+
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
361
|
+
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
217
362
|
*
|
|
218
363
|
* # Returns
|
|
219
|
-
* -
|
|
364
|
+
* - A PositionStatus enum value indicating the status of the position
|
|
220
365
|
*/
|
|
221
|
-
module.exports.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
wasm.tryGetAmountDeltaA(retptr, addHeapObject(sqrt_price_1), addHeapObject(sqrt_price_2), addHeapObject(liquidity), round_up);
|
|
225
|
-
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
226
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
227
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
228
|
-
if (r3) {
|
|
229
|
-
throw takeObject(r2);
|
|
230
|
-
}
|
|
231
|
-
return BigInt.asUintN(64, r0);
|
|
232
|
-
} finally {
|
|
233
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
234
|
-
}
|
|
366
|
+
module.exports.positionStatus = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
367
|
+
const ret = wasm.positionStatus(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
|
|
368
|
+
return takeObject(ret);
|
|
235
369
|
};
|
|
236
370
|
|
|
237
371
|
/**
|
|
238
|
-
* Calculate the
|
|
372
|
+
* Calculate the token_a / token_b ratio of a (ficticious) position
|
|
239
373
|
*
|
|
240
374
|
* # Parameters
|
|
241
|
-
* - `
|
|
242
|
-
* - `
|
|
243
|
-
* - `
|
|
244
|
-
* - `round_up`: Whether to round up or not
|
|
375
|
+
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
376
|
+
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
377
|
+
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
245
378
|
*
|
|
246
379
|
* # Returns
|
|
247
|
-
* -
|
|
380
|
+
* - A PositionRatio struct containing the ratio of token_a and token_b
|
|
248
381
|
*/
|
|
249
|
-
module.exports.
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
wasm.tryGetAmountDeltaB(retptr, addHeapObject(sqrt_price_1), addHeapObject(sqrt_price_2), addHeapObject(liquidity), round_up);
|
|
253
|
-
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
254
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
255
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
256
|
-
if (r3) {
|
|
257
|
-
throw takeObject(r2);
|
|
258
|
-
}
|
|
259
|
-
return BigInt.asUintN(64, r0);
|
|
260
|
-
} finally {
|
|
261
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
262
|
-
}
|
|
382
|
+
module.exports.positionRatio = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
383
|
+
const ret = wasm.positionRatio(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
|
|
384
|
+
return takeObject(ret);
|
|
263
385
|
};
|
|
264
386
|
|
|
265
387
|
/**
|
|
266
|
-
*
|
|
388
|
+
* Get the first tick index in the tick array that contains the specified tick index.
|
|
267
389
|
*
|
|
268
390
|
* # Parameters
|
|
269
|
-
* - `
|
|
270
|
-
* - `
|
|
271
|
-
* - `amount`: The amount
|
|
272
|
-
* - `specified_input`: Whether the input is specified
|
|
391
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
392
|
+
* - `tick_spacing` - A i32 integer representing the tick spacing
|
|
273
393
|
*
|
|
274
394
|
* # Returns
|
|
275
|
-
* -
|
|
395
|
+
* - A i32 integer representing the first tick index in the tick array
|
|
276
396
|
*/
|
|
277
|
-
module.exports.
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
wasm.tryGetNextSqrtPriceFromA(retptr, addHeapObject(current_sqrt_price), addHeapObject(current_liquidity), amount, specified_input);
|
|
281
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
282
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
283
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
284
|
-
if (r2) {
|
|
285
|
-
throw takeObject(r1);
|
|
286
|
-
}
|
|
287
|
-
return takeObject(r0);
|
|
288
|
-
} finally {
|
|
289
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
290
|
-
}
|
|
397
|
+
module.exports.getTickArrayStartTickIndex = function(tick_index, tick_spacing) {
|
|
398
|
+
const ret = wasm.getTickArrayStartTickIndex(tick_index, tick_spacing);
|
|
399
|
+
return ret;
|
|
291
400
|
};
|
|
292
401
|
|
|
293
402
|
/**
|
|
294
|
-
*
|
|
403
|
+
* Derive the sqrt-price from a tick index. The precision of this method is only guarranted
|
|
404
|
+
* if tick is within the bounds of {max, min} tick-index.
|
|
295
405
|
*
|
|
296
406
|
* # Parameters
|
|
297
|
-
* - `
|
|
298
|
-
* - `current_liquidity`: The current liquidity
|
|
299
|
-
* - `amount`: The amount
|
|
300
|
-
* - `specified_input`: Whether the input is specified
|
|
407
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
301
408
|
*
|
|
302
409
|
* # Returns
|
|
303
|
-
* - `
|
|
410
|
+
* - `Ok`: A u128 Q32.64 representing the sqrt_price
|
|
304
411
|
*/
|
|
305
|
-
module.exports.
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
412
|
+
module.exports.tickIndexToSqrtPrice = function(tick_index) {
|
|
413
|
+
const ret = wasm.tickIndexToSqrtPrice(tick_index);
|
|
414
|
+
return takeObject(ret);
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Derive the tick index from a sqrt price. The precision of this method is only guarranted
|
|
419
|
+
* if tick is within the bounds of {max, min} tick-index.
|
|
420
|
+
* This function will make panic for zero sqrt price.
|
|
421
|
+
*
|
|
422
|
+
* # Parameters
|
|
423
|
+
* - `sqrt_price` - A u128 integer representing the sqrt price
|
|
424
|
+
*
|
|
425
|
+
* # Returns
|
|
426
|
+
* - `Ok`: A i32 integer representing the tick integer
|
|
427
|
+
*/
|
|
428
|
+
module.exports.sqrtPriceToTickIndex = function(sqrt_price) {
|
|
429
|
+
const ret = wasm.sqrtPriceToTickIndex(addHeapObject(sqrt_price));
|
|
430
|
+
return ret;
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Get the initializable tick index.
|
|
435
|
+
* If the tick index is already initializable, it is returned as is.
|
|
436
|
+
*
|
|
437
|
+
* # Parameters
|
|
438
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
439
|
+
* - `tick_spacing` - A i32 integer representing the tick spacing
|
|
440
|
+
* - `round_up` - A boolean value indicating if the supplied tick index should be rounded up. None will round to the nearest.
|
|
441
|
+
*
|
|
442
|
+
* # Returns
|
|
443
|
+
* - A i32 representing the initializable tick index (rounded per round_up or nearest).
|
|
444
|
+
*/
|
|
445
|
+
module.exports.getInitializableTickIndex = function(tick_index, tick_spacing, round_up) {
|
|
446
|
+
const ret = wasm.getInitializableTickIndex(tick_index, tick_spacing, isLikeNone(round_up) ? 0xFFFFFF : round_up ? 1 : 0);
|
|
447
|
+
return ret;
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Get the previous initializable tick index.
|
|
452
|
+
*
|
|
453
|
+
* # Parameters
|
|
454
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
455
|
+
* - `tick_spacing` - A i32 integer representing the tick spacing
|
|
456
|
+
*
|
|
457
|
+
* # Returns
|
|
458
|
+
* - A i32 integer representing the previous initializable tick index
|
|
459
|
+
*/
|
|
460
|
+
module.exports.getPrevInitializableTickIndex = function(tick_index, tick_spacing) {
|
|
461
|
+
const ret = wasm.getPrevInitializableTickIndex(tick_index, tick_spacing);
|
|
462
|
+
return ret;
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Get the next initializable tick index.
|
|
467
|
+
*
|
|
468
|
+
* # Parameters
|
|
469
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
470
|
+
* - `tick_spacing` - A i32 integer representing the tick spacing
|
|
471
|
+
*
|
|
472
|
+
* # Returns
|
|
473
|
+
* - A i32 integer representing the next initializable tick index
|
|
474
|
+
*/
|
|
475
|
+
module.exports.getNextInitializableTickIndex = function(tick_index, tick_spacing) {
|
|
476
|
+
const ret = wasm.getNextInitializableTickIndex(tick_index, tick_spacing);
|
|
477
|
+
return ret;
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Check if a tick is in-bounds.
|
|
482
|
+
*
|
|
483
|
+
* # Parameters
|
|
484
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
485
|
+
*
|
|
486
|
+
* # Returns
|
|
487
|
+
* - A boolean value indicating if the tick is in-bounds
|
|
488
|
+
*/
|
|
489
|
+
module.exports.isTickIndexInBounds = function(tick_index) {
|
|
490
|
+
const ret = wasm.isTickIndexInBounds(tick_index);
|
|
491
|
+
return ret !== 0;
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Check if a tick is initializable.
|
|
496
|
+
* A tick is initializable if it is divisible by the tick spacing.
|
|
497
|
+
*
|
|
498
|
+
* # Parameters
|
|
499
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
500
|
+
* - `tick_spacing` - A i32 integer representing the tick spacing
|
|
501
|
+
*
|
|
502
|
+
* # Returns
|
|
503
|
+
* - A boolean value indicating if the tick is initializable
|
|
504
|
+
*/
|
|
505
|
+
module.exports.isTickInitializable = function(tick_index, tick_spacing) {
|
|
506
|
+
const ret = wasm.isTickInitializable(tick_index, tick_spacing);
|
|
507
|
+
return ret !== 0;
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Get the tick index for the inverse of the price that this tick represents.
|
|
512
|
+
* Eg: Consider tick i where Pb/Pa = 1.0001 ^ i
|
|
513
|
+
* inverse of this, i.e. Pa/Pb = 1 / (1.0001 ^ i) = 1.0001^-i
|
|
514
|
+
*
|
|
515
|
+
* # Parameters
|
|
516
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
517
|
+
*
|
|
518
|
+
* # Returns
|
|
519
|
+
* - A i32 integer representing the tick index for the inverse of the price
|
|
520
|
+
*/
|
|
521
|
+
module.exports.invertTickIndex = function(tick_index) {
|
|
522
|
+
const ret = wasm.invertTickIndex(tick_index);
|
|
523
|
+
return ret;
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Get the sqrt price for the inverse of the price that this tick represents.
|
|
528
|
+
* Because converting to a tick index and then back to a sqrt price is lossy,
|
|
529
|
+
* this function is clamped to the nearest tick index.
|
|
530
|
+
*
|
|
531
|
+
* # Parameters
|
|
532
|
+
* - `sqrt_price` - A u128 integer representing the sqrt price
|
|
533
|
+
*
|
|
534
|
+
* # Returns
|
|
535
|
+
* - A u128 integer representing the sqrt price for the inverse of the price
|
|
536
|
+
*/
|
|
537
|
+
module.exports.invertSqrtPrice = function(sqrt_price) {
|
|
538
|
+
const ret = wasm.invertSqrtPrice(addHeapObject(sqrt_price));
|
|
539
|
+
return takeObject(ret);
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Get the minimum and maximum tick index that can be initialized.
|
|
544
|
+
*
|
|
545
|
+
* # Parameters
|
|
546
|
+
* - `tick_spacing` - A i32 integer representing the tick spacing
|
|
547
|
+
*
|
|
548
|
+
* # Returns
|
|
549
|
+
* - A TickRange struct containing the lower and upper tick index
|
|
550
|
+
*/
|
|
551
|
+
module.exports.getFullRangeTickIndexes = function(tick_spacing) {
|
|
552
|
+
const ret = wasm.getFullRangeTickIndexes(tick_spacing);
|
|
553
|
+
return takeObject(ret);
|
|
319
554
|
};
|
|
320
555
|
|
|
321
556
|
/**
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
557
|
+
* Order tick indexes in ascending order.
|
|
558
|
+
* If the lower tick index is greater than the upper tick index, the indexes are swapped.
|
|
559
|
+
* This is useful for ensuring that the lower tick index is always less than the upper tick index.
|
|
325
560
|
*
|
|
326
561
|
* # Parameters
|
|
327
|
-
* - `
|
|
328
|
-
* - `
|
|
562
|
+
* - `tick_index_1` - A i32 integer representing the first tick index
|
|
563
|
+
* - `tick_index_2` - A i32 integer representing the second tick index
|
|
329
564
|
*
|
|
330
565
|
* # Returns
|
|
331
|
-
* -
|
|
566
|
+
* - A TickRange struct containing the lower and upper tick index
|
|
332
567
|
*/
|
|
333
|
-
module.exports.
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
wasm.tryApplyTransferFee(retptr, amount, addHeapObject(transfer_fee));
|
|
337
|
-
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
338
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
339
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
340
|
-
if (r3) {
|
|
341
|
-
throw takeObject(r2);
|
|
342
|
-
}
|
|
343
|
-
return BigInt.asUintN(64, r0);
|
|
344
|
-
} finally {
|
|
345
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
346
|
-
}
|
|
568
|
+
module.exports.orderTickIndexes = function(tick_index_1, tick_index_2) {
|
|
569
|
+
const ret = wasm.orderTickIndexes(tick_index_1, tick_index_2);
|
|
570
|
+
return takeObject(ret);
|
|
347
571
|
};
|
|
348
572
|
|
|
349
573
|
/**
|
|
350
|
-
*
|
|
351
|
-
* e.g. You received 9900 amount with 100 fee rate. The fee amount will be 100.
|
|
352
|
-
* So the amount before fee will be 10000.
|
|
574
|
+
* Check if a whirlpool is a full-range only pool.
|
|
353
575
|
*
|
|
354
576
|
* # Parameters
|
|
355
|
-
* - `
|
|
356
|
-
* - `transfer_fee`: The transfer fee to reverse
|
|
577
|
+
* - `tick_spacing` - A u16 integer representing the tick spacing
|
|
357
578
|
*
|
|
358
579
|
* # Returns
|
|
359
|
-
* -
|
|
580
|
+
* - A boolean value indicating if the whirlpool is a full-range only pool
|
|
360
581
|
*/
|
|
361
|
-
module.exports.
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
wasm.tryReverseApplyTransferFee(retptr, amount, addHeapObject(transfer_fee));
|
|
365
|
-
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
366
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
367
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
368
|
-
if (r3) {
|
|
369
|
-
throw takeObject(r2);
|
|
370
|
-
}
|
|
371
|
-
return BigInt.asUintN(64, r0);
|
|
372
|
-
} finally {
|
|
373
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
374
|
-
}
|
|
582
|
+
module.exports.isFullRangeOnly = function(tick_spacing) {
|
|
583
|
+
const ret = wasm.isFullRangeOnly(tick_spacing);
|
|
584
|
+
return ret !== 0;
|
|
375
585
|
};
|
|
376
586
|
|
|
377
587
|
/**
|
|
378
|
-
* Get the
|
|
379
|
-
* e.g. Your estimated amount you send is 10000 with 100 slippage tolerance. The max you send will be 10100.
|
|
588
|
+
* Get the index of a tick in a tick array.
|
|
380
589
|
*
|
|
381
590
|
* # Parameters
|
|
382
|
-
* - `
|
|
383
|
-
* - `
|
|
591
|
+
* - `tick_index` - A i32 integer representing the tick index
|
|
592
|
+
* - `tick_array_start_index` - A i32 integer representing the start tick index of the tick array
|
|
593
|
+
* - `tick_spacing` - A u16 integer representing the tick spacing
|
|
384
594
|
*
|
|
385
595
|
* # Returns
|
|
386
|
-
* -
|
|
596
|
+
* - A u32 integer representing the tick index in the tick array
|
|
387
597
|
*/
|
|
388
|
-
module.exports.
|
|
598
|
+
module.exports.getTickIndexInArray = function(tick_index, tick_array_start_index, tick_spacing) {
|
|
389
599
|
try {
|
|
390
600
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
391
|
-
wasm.
|
|
392
|
-
var r0 = getDataViewMemory0().
|
|
601
|
+
wasm.getTickIndexInArray(retptr, tick_index, tick_array_start_index, tick_spacing);
|
|
602
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
603
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
393
604
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
throw takeObject(r2);
|
|
605
|
+
if (r2) {
|
|
606
|
+
throw takeObject(r1);
|
|
397
607
|
}
|
|
398
|
-
return
|
|
608
|
+
return r0 >>> 0;
|
|
399
609
|
} finally {
|
|
400
610
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
401
611
|
}
|
|
402
612
|
};
|
|
403
613
|
|
|
404
614
|
/**
|
|
405
|
-
*
|
|
406
|
-
* e.g. Your estimated amount you receive is 10000 with 100 slippage tolerance. The min amount you receive will be 9900.
|
|
615
|
+
* Calculate the amount A delta between two sqrt_prices
|
|
407
616
|
*
|
|
408
617
|
* # Parameters
|
|
409
|
-
* - `
|
|
410
|
-
* - `
|
|
618
|
+
* - `sqrt_price_1`: The first square root price
|
|
619
|
+
* - `sqrt_price_2`: The second square root price
|
|
620
|
+
* - `liquidity`: The liquidity
|
|
621
|
+
* - `round_up`: Whether to round up or not
|
|
411
622
|
*
|
|
412
623
|
* # Returns
|
|
413
|
-
* - `u64`: The
|
|
624
|
+
* - `u64`: The amount delta
|
|
414
625
|
*/
|
|
415
|
-
module.exports.
|
|
626
|
+
module.exports.tryGetAmountDeltaA = function(sqrt_price_1, sqrt_price_2, liquidity, round_up) {
|
|
416
627
|
try {
|
|
417
628
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
418
|
-
wasm.
|
|
629
|
+
wasm.tryGetAmountDeltaA(retptr, addHeapObject(sqrt_price_1), addHeapObject(sqrt_price_2), addHeapObject(liquidity), round_up);
|
|
419
630
|
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
420
631
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
421
632
|
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
@@ -429,21 +640,21 @@ module.exports.tryGetMinAmountWithSlippageTolerance = function(amount, slippage_
|
|
|
429
640
|
};
|
|
430
641
|
|
|
431
642
|
/**
|
|
432
|
-
*
|
|
433
|
-
* e.g. You send 10000 amount with 10000 fee rate. The fee amount will be 100.
|
|
434
|
-
* So the amount after fee will be 9900.
|
|
643
|
+
* Calculate the amount B delta between two sqrt_prices
|
|
435
644
|
*
|
|
436
645
|
* # Parameters
|
|
437
|
-
* - `
|
|
438
|
-
* - `
|
|
646
|
+
* - `sqrt_price_1`: The first square root price
|
|
647
|
+
* - `sqrt_price_2`: The second square root price
|
|
648
|
+
* - `liquidity`: The liquidity
|
|
649
|
+
* - `round_up`: Whether to round up or not
|
|
439
650
|
*
|
|
440
651
|
* # Returns
|
|
441
|
-
* - `u64`: The amount
|
|
652
|
+
* - `u64`: The amount delta
|
|
442
653
|
*/
|
|
443
|
-
module.exports.
|
|
654
|
+
module.exports.tryGetAmountDeltaB = function(sqrt_price_1, sqrt_price_2, liquidity, round_up) {
|
|
444
655
|
try {
|
|
445
656
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
446
|
-
wasm.
|
|
657
|
+
wasm.tryGetAmountDeltaB(retptr, addHeapObject(sqrt_price_1), addHeapObject(sqrt_price_2), addHeapObject(liquidity), round_up);
|
|
447
658
|
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
448
659
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
449
660
|
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
@@ -457,53 +668,49 @@ module.exports.tryApplySwapFee = function(amount, fee_rate) {
|
|
|
457
668
|
};
|
|
458
669
|
|
|
459
670
|
/**
|
|
460
|
-
*
|
|
461
|
-
* e.g. You received 9900 amount with 10000 fee rate. The fee amount will be 100.
|
|
462
|
-
* So the amount before fee will be 10000.
|
|
671
|
+
* Calculate the next square root price
|
|
463
672
|
*
|
|
464
673
|
* # Parameters
|
|
465
|
-
* - `
|
|
466
|
-
* - `
|
|
674
|
+
* - `current_sqrt_price`: The current square root price
|
|
675
|
+
* - `current_liquidity`: The current liquidity
|
|
676
|
+
* - `amount`: The amount
|
|
677
|
+
* - `specified_input`: Whether the input is specified
|
|
467
678
|
*
|
|
468
679
|
* # Returns
|
|
469
|
-
* - `
|
|
680
|
+
* - `u128`: The next square root price
|
|
470
681
|
*/
|
|
471
|
-
module.exports.
|
|
682
|
+
module.exports.tryGetNextSqrtPriceFromA = function(current_sqrt_price, current_liquidity, amount, specified_input) {
|
|
472
683
|
try {
|
|
473
684
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
474
|
-
wasm.
|
|
475
|
-
var r0 = getDataViewMemory0().
|
|
685
|
+
wasm.tryGetNextSqrtPriceFromA(retptr, addHeapObject(current_sqrt_price), addHeapObject(current_liquidity), amount, specified_input);
|
|
686
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
687
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
476
688
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
throw takeObject(r2);
|
|
689
|
+
if (r2) {
|
|
690
|
+
throw takeObject(r1);
|
|
480
691
|
}
|
|
481
|
-
return
|
|
692
|
+
return takeObject(r0);
|
|
482
693
|
} finally {
|
|
483
694
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
484
695
|
}
|
|
485
696
|
};
|
|
486
697
|
|
|
487
698
|
/**
|
|
488
|
-
* Calculate
|
|
699
|
+
* Calculate the next square root price
|
|
489
700
|
*
|
|
490
|
-
* #
|
|
491
|
-
* - `
|
|
492
|
-
* - `
|
|
493
|
-
* - `
|
|
494
|
-
* - `
|
|
495
|
-
* - `current_timestamp`: The current timestamp
|
|
496
|
-
* - `transfer_fee_1`: The transfer fee for token 1
|
|
497
|
-
* - `transfer_fee_2`: The transfer fee for token 2
|
|
498
|
-
* - `transfer_fee_3`: The transfer fee for token 3
|
|
701
|
+
* # Parameters
|
|
702
|
+
* - `current_sqrt_price`: The current square root price
|
|
703
|
+
* - `current_liquidity`: The current liquidity
|
|
704
|
+
* - `amount`: The amount
|
|
705
|
+
* - `specified_input`: Whether the input is specified
|
|
499
706
|
*
|
|
500
707
|
* # Returns
|
|
501
|
-
* - `
|
|
708
|
+
* - `u128`: The next square root price
|
|
502
709
|
*/
|
|
503
|
-
module.exports.
|
|
710
|
+
module.exports.tryGetNextSqrtPriceFromB = function(current_sqrt_price, current_liquidity, amount, specified_input) {
|
|
504
711
|
try {
|
|
505
712
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
506
|
-
wasm.
|
|
713
|
+
wasm.tryGetNextSqrtPriceFromB(retptr, addHeapObject(current_sqrt_price), addHeapObject(current_liquidity), amount, specified_input);
|
|
507
714
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
508
715
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
509
716
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
@@ -516,285 +723,306 @@ module.exports.collectRewardsQuote = function(whirlpool, position, tick_lower, t
|
|
|
516
723
|
}
|
|
517
724
|
};
|
|
518
725
|
|
|
519
|
-
function passArray8ToWasm0(arg, malloc) {
|
|
520
|
-
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
521
|
-
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
522
|
-
WASM_VECTOR_LEN = arg.length;
|
|
523
|
-
return ptr;
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Get the first unoccupied position in a bundle
|
|
527
|
-
*
|
|
528
|
-
* # Arguments
|
|
529
|
-
* * `bundle` - The bundle to check
|
|
530
|
-
*
|
|
531
|
-
* # Returns
|
|
532
|
-
* * `u32` - The first unoccupied position (None if full)
|
|
533
|
-
*/
|
|
534
|
-
module.exports.firstUnoccupiedPositionInBundle = function(bitmap) {
|
|
535
|
-
const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export_0);
|
|
536
|
-
const len0 = WASM_VECTOR_LEN;
|
|
537
|
-
const ret = wasm.firstUnoccupiedPositionInBundle(ptr0, len0);
|
|
538
|
-
return ret === 0x100000001 ? undefined : ret;
|
|
539
|
-
};
|
|
540
|
-
|
|
541
|
-
/**
|
|
542
|
-
* Check whether a position bundle is full
|
|
543
|
-
* A position bundle can contain 256 positions
|
|
544
|
-
*
|
|
545
|
-
* # Arguments
|
|
546
|
-
* * `bundle` - The bundle to check
|
|
547
|
-
*
|
|
548
|
-
* # Returns
|
|
549
|
-
* * `bool` - Whether the bundle is full
|
|
550
|
-
*/
|
|
551
|
-
module.exports.isPositionBundleFull = function(bitmap) {
|
|
552
|
-
const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export_0);
|
|
553
|
-
const len0 = WASM_VECTOR_LEN;
|
|
554
|
-
const ret = wasm.isPositionBundleFull(ptr0, len0);
|
|
555
|
-
return ret !== 0;
|
|
556
|
-
};
|
|
557
|
-
|
|
558
|
-
/**
|
|
559
|
-
* Check whether a position bundle is empty
|
|
560
|
-
*
|
|
561
|
-
* # Arguments
|
|
562
|
-
* * `bundle` - The bundle to check
|
|
563
|
-
*
|
|
564
|
-
* # Returns
|
|
565
|
-
* * `bool` - Whether the bundle is empty
|
|
566
|
-
*/
|
|
567
|
-
module.exports.isPositionBundleEmpty = function(bitmap) {
|
|
568
|
-
const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export_0);
|
|
569
|
-
const len0 = WASM_VECTOR_LEN;
|
|
570
|
-
const ret = wasm.isPositionBundleEmpty(ptr0, len0);
|
|
571
|
-
return ret !== 0;
|
|
572
|
-
};
|
|
573
|
-
|
|
574
|
-
/**
|
|
575
|
-
* Get the first tick index in the tick array that contains the specified tick index.
|
|
576
|
-
*
|
|
577
|
-
* # Parameters
|
|
578
|
-
* - `tick_index` - A i32 integer representing the tick integer
|
|
579
|
-
* - `tick_spacing` - A i32 integer representing the tick spacing
|
|
580
|
-
*
|
|
581
|
-
* # Returns
|
|
582
|
-
* - A i32 integer representing the first tick index in the tick array
|
|
583
|
-
*/
|
|
584
|
-
module.exports.getTickArrayStartTickIndex = function(tick_index, tick_spacing) {
|
|
585
|
-
const ret = wasm.getTickArrayStartTickIndex(tick_index, tick_spacing);
|
|
586
|
-
return ret;
|
|
587
|
-
};
|
|
588
|
-
|
|
589
726
|
/**
|
|
590
|
-
*
|
|
591
|
-
*
|
|
727
|
+
* Apply a transfer fee to an amount
|
|
728
|
+
* e.g. You send 10000 amount with 100 fee rate. The fee amount will be 100.
|
|
729
|
+
* So the amount after fee will be 9900.
|
|
592
730
|
*
|
|
593
731
|
* # Parameters
|
|
594
|
-
* - `
|
|
732
|
+
* - `amount`: The amount to apply the fee to
|
|
733
|
+
* - `transfer_fee`: The transfer fee to apply
|
|
595
734
|
*
|
|
596
735
|
* # Returns
|
|
597
|
-
* - `
|
|
736
|
+
* - `u64`: The amount after the fee has been applied
|
|
598
737
|
*/
|
|
599
|
-
module.exports.
|
|
600
|
-
|
|
601
|
-
|
|
738
|
+
module.exports.tryApplyTransferFee = function(amount, transfer_fee) {
|
|
739
|
+
try {
|
|
740
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
741
|
+
wasm.tryApplyTransferFee(retptr, amount, addHeapObject(transfer_fee));
|
|
742
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
743
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
744
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
745
|
+
if (r3) {
|
|
746
|
+
throw takeObject(r2);
|
|
747
|
+
}
|
|
748
|
+
return BigInt.asUintN(64, r0);
|
|
749
|
+
} finally {
|
|
750
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
751
|
+
}
|
|
602
752
|
};
|
|
603
753
|
|
|
604
754
|
/**
|
|
605
|
-
*
|
|
606
|
-
*
|
|
755
|
+
* Reverse the application of a transfer fee to an amount
|
|
756
|
+
* e.g. You received 9900 amount with 100 fee rate. The fee amount will be 100.
|
|
757
|
+
* So the amount before fee will be 10000.
|
|
607
758
|
*
|
|
608
759
|
* # Parameters
|
|
609
|
-
* - `
|
|
760
|
+
* - `amount`: The amount to reverse the fee from
|
|
761
|
+
* - `transfer_fee`: The transfer fee to reverse
|
|
610
762
|
*
|
|
611
763
|
* # Returns
|
|
612
|
-
* - `
|
|
764
|
+
* - `u64`: The amount before the fee has been applied
|
|
613
765
|
*/
|
|
614
|
-
module.exports.
|
|
615
|
-
|
|
616
|
-
|
|
766
|
+
module.exports.tryReverseApplyTransferFee = function(amount, transfer_fee) {
|
|
767
|
+
try {
|
|
768
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
769
|
+
wasm.tryReverseApplyTransferFee(retptr, amount, addHeapObject(transfer_fee));
|
|
770
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
771
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
772
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
773
|
+
if (r3) {
|
|
774
|
+
throw takeObject(r2);
|
|
775
|
+
}
|
|
776
|
+
return BigInt.asUintN(64, r0);
|
|
777
|
+
} finally {
|
|
778
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
779
|
+
}
|
|
617
780
|
};
|
|
618
781
|
|
|
619
782
|
/**
|
|
620
|
-
* Get the
|
|
621
|
-
*
|
|
783
|
+
* Get the maximum amount with a slippage tolerance
|
|
784
|
+
* e.g. Your estimated amount you send is 10000 with 100 slippage tolerance. The max you send will be 10100.
|
|
622
785
|
*
|
|
623
786
|
* # Parameters
|
|
624
|
-
* - `
|
|
625
|
-
* - `
|
|
626
|
-
* - `round_up` - A boolean value indicating if the supplied tick index should be rounded up. None will round to the nearest.
|
|
787
|
+
* - `amount`: The amount to apply the fee to
|
|
788
|
+
* - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
|
|
627
789
|
*
|
|
628
790
|
* # Returns
|
|
629
|
-
* -
|
|
791
|
+
* - `u64`: The maximum amount
|
|
630
792
|
*/
|
|
631
|
-
module.exports.
|
|
632
|
-
|
|
633
|
-
|
|
793
|
+
module.exports.tryGetMaxAmountWithSlippageTolerance = function(amount, slippage_tolerance_bps) {
|
|
794
|
+
try {
|
|
795
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
796
|
+
wasm.tryGetMaxAmountWithSlippageTolerance(retptr, amount, slippage_tolerance_bps);
|
|
797
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
798
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
799
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
800
|
+
if (r3) {
|
|
801
|
+
throw takeObject(r2);
|
|
802
|
+
}
|
|
803
|
+
return BigInt.asUintN(64, r0);
|
|
804
|
+
} finally {
|
|
805
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
806
|
+
}
|
|
634
807
|
};
|
|
635
808
|
|
|
636
809
|
/**
|
|
637
|
-
* Get the
|
|
810
|
+
* Get the minimum amount with a slippage tolerance
|
|
811
|
+
* e.g. Your estimated amount you receive is 10000 with 100 slippage tolerance. The min amount you receive will be 9900.
|
|
638
812
|
*
|
|
639
813
|
* # Parameters
|
|
640
|
-
* - `
|
|
641
|
-
* - `
|
|
814
|
+
* - `amount`: The amount to apply the fee to
|
|
815
|
+
* - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
|
|
642
816
|
*
|
|
643
817
|
* # Returns
|
|
644
|
-
* -
|
|
818
|
+
* - `u64`: The minimum amount
|
|
645
819
|
*/
|
|
646
|
-
module.exports.
|
|
647
|
-
|
|
648
|
-
|
|
820
|
+
module.exports.tryGetMinAmountWithSlippageTolerance = function(amount, slippage_tolerance_bps) {
|
|
821
|
+
try {
|
|
822
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
823
|
+
wasm.tryGetMinAmountWithSlippageTolerance(retptr, amount, slippage_tolerance_bps);
|
|
824
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
825
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
826
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
827
|
+
if (r3) {
|
|
828
|
+
throw takeObject(r2);
|
|
829
|
+
}
|
|
830
|
+
return BigInt.asUintN(64, r0);
|
|
831
|
+
} finally {
|
|
832
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
833
|
+
}
|
|
649
834
|
};
|
|
650
835
|
|
|
651
836
|
/**
|
|
652
|
-
*
|
|
837
|
+
* Apply a swap fee to an amount
|
|
838
|
+
* e.g. You send 10000 amount with 10000 fee rate. The fee amount will be 100.
|
|
839
|
+
* So the amount after fee will be 9900.
|
|
653
840
|
*
|
|
654
841
|
* # Parameters
|
|
655
|
-
* - `
|
|
656
|
-
* - `
|
|
842
|
+
* - `amount`: The amount to apply the fee to
|
|
843
|
+
* - `fee_rate`: The fee rate to apply denominated in 1e6
|
|
657
844
|
*
|
|
658
845
|
* # Returns
|
|
659
|
-
* -
|
|
846
|
+
* - `u64`: The amount after the fee has been applied
|
|
660
847
|
*/
|
|
661
|
-
module.exports.
|
|
662
|
-
|
|
663
|
-
|
|
848
|
+
module.exports.tryApplySwapFee = function(amount, fee_rate) {
|
|
849
|
+
try {
|
|
850
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
851
|
+
wasm.tryApplySwapFee(retptr, amount, fee_rate);
|
|
852
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
853
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
854
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
855
|
+
if (r3) {
|
|
856
|
+
throw takeObject(r2);
|
|
857
|
+
}
|
|
858
|
+
return BigInt.asUintN(64, r0);
|
|
859
|
+
} finally {
|
|
860
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
861
|
+
}
|
|
664
862
|
};
|
|
665
863
|
|
|
666
864
|
/**
|
|
667
|
-
*
|
|
865
|
+
* Reverse the application of a swap fee to an amount
|
|
866
|
+
* e.g. You received 9900 amount with 10000 fee rate. The fee amount will be 100.
|
|
867
|
+
* So the amount before fee will be 10000.
|
|
668
868
|
*
|
|
669
869
|
* # Parameters
|
|
670
|
-
* - `
|
|
870
|
+
* - `amount`: The amount to reverse the fee from
|
|
871
|
+
* - `fee_rate`: The fee rate to reverse denominated in 1e6
|
|
671
872
|
*
|
|
672
873
|
* # Returns
|
|
673
|
-
* -
|
|
874
|
+
* - `u64`: The amount before the fee has been applied
|
|
674
875
|
*/
|
|
675
|
-
module.exports.
|
|
676
|
-
|
|
677
|
-
|
|
876
|
+
module.exports.tryReverseApplySwapFee = function(amount, fee_rate) {
|
|
877
|
+
try {
|
|
878
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
879
|
+
wasm.tryReverseApplySwapFee(retptr, amount, fee_rate);
|
|
880
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
881
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
882
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
883
|
+
if (r3) {
|
|
884
|
+
throw takeObject(r2);
|
|
885
|
+
}
|
|
886
|
+
return BigInt.asUintN(64, r0);
|
|
887
|
+
} finally {
|
|
888
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
889
|
+
}
|
|
678
890
|
};
|
|
679
891
|
|
|
680
892
|
/**
|
|
681
|
-
*
|
|
682
|
-
* A tick is initializable if it is divisible by the tick spacing.
|
|
893
|
+
* Calculate fees owed for a position
|
|
683
894
|
*
|
|
684
|
-
* #
|
|
685
|
-
* - `
|
|
686
|
-
* - `
|
|
895
|
+
* # Paramters
|
|
896
|
+
* - `whirlpool`: The whirlpool state
|
|
897
|
+
* - `position`: The position state
|
|
898
|
+
* - `tick_lower`: The lower tick state
|
|
899
|
+
* - `tick_upper`: The upper tick state
|
|
900
|
+
* - `transfer_fee_a`: The transfer fee for token A
|
|
901
|
+
* - `transfer_fee_b`: The transfer fee for token B
|
|
687
902
|
*
|
|
688
903
|
* # Returns
|
|
689
|
-
* -
|
|
904
|
+
* - `CollectFeesQuote`: The fees owed for token A and token B
|
|
690
905
|
*/
|
|
691
|
-
module.exports.
|
|
692
|
-
|
|
693
|
-
|
|
906
|
+
module.exports.collectFeesQuote = function(whirlpool, position, tick_lower, tick_upper, transfer_fee_a, transfer_fee_b) {
|
|
907
|
+
try {
|
|
908
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
909
|
+
wasm.collectFeesQuote(retptr, addHeapObject(whirlpool), addHeapObject(position), addHeapObject(tick_lower), addHeapObject(tick_upper), isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
|
|
910
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
911
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
912
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
913
|
+
if (r2) {
|
|
914
|
+
throw takeObject(r1);
|
|
915
|
+
}
|
|
916
|
+
return takeObject(r0);
|
|
917
|
+
} finally {
|
|
918
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
919
|
+
}
|
|
694
920
|
};
|
|
695
921
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
* inverse of this, i.e. Pa/Pb = 1 / (1.0001 ^ i) = 1.0001^-i
|
|
700
|
-
*
|
|
701
|
-
* # Parameters
|
|
702
|
-
* - `tick_index` - A i32 integer representing the tick integer
|
|
703
|
-
*
|
|
704
|
-
* # Returns
|
|
705
|
-
* - A i32 integer representing the tick index for the inverse of the price
|
|
706
|
-
*/
|
|
707
|
-
module.exports.invertTickIndex = function(tick_index) {
|
|
708
|
-
const ret = wasm.invertTickIndex(tick_index);
|
|
709
|
-
return ret;
|
|
922
|
+
module.exports._NUM_REWARDS = function() {
|
|
923
|
+
const ret = wasm._NUM_REWARDS();
|
|
924
|
+
return ret >>> 0;
|
|
710
925
|
};
|
|
711
926
|
|
|
712
927
|
/**
|
|
713
|
-
*
|
|
714
|
-
* Because converting to a tick index and then back to a sqrt price is lossy,
|
|
715
|
-
* this function is clamped to the nearest tick index.
|
|
928
|
+
* Check if the whirlpool is initialized with adaptive fee
|
|
716
929
|
*
|
|
717
|
-
* #
|
|
718
|
-
* - `
|
|
930
|
+
* # Paramters
|
|
931
|
+
* - `whirlpool`: The whirlpool state
|
|
719
932
|
*
|
|
720
933
|
* # Returns
|
|
721
|
-
* - A
|
|
934
|
+
* - A boolean value indicating if the whirlpool is initialized with adaptive fee
|
|
722
935
|
*/
|
|
723
|
-
module.exports.
|
|
724
|
-
const ret = wasm.
|
|
725
|
-
return
|
|
936
|
+
module.exports.isInitializedWithAdaptiveFee = function(whirlpool) {
|
|
937
|
+
const ret = wasm.isInitializedWithAdaptiveFee(addHeapObject(whirlpool));
|
|
938
|
+
return ret !== 0;
|
|
726
939
|
};
|
|
727
940
|
|
|
728
941
|
/**
|
|
729
|
-
*
|
|
942
|
+
* Calculate rewards owed for a position
|
|
730
943
|
*
|
|
731
|
-
* #
|
|
732
|
-
* - `
|
|
944
|
+
* # Paramters
|
|
945
|
+
* - `whirlpool`: The whirlpool state
|
|
946
|
+
* - `position`: The position state
|
|
947
|
+
* - `tick_lower`: The lower tick state
|
|
948
|
+
* - `tick_upper`: The upper tick state
|
|
949
|
+
* - `current_timestamp`: The current timestamp
|
|
950
|
+
* - `transfer_fee_1`: The transfer fee for token 1
|
|
951
|
+
* - `transfer_fee_2`: The transfer fee for token 2
|
|
952
|
+
* - `transfer_fee_3`: The transfer fee for token 3
|
|
733
953
|
*
|
|
734
954
|
* # Returns
|
|
735
|
-
* -
|
|
955
|
+
* - `CollectRewardsQuote`: The rewards owed for the 3 reward tokens.
|
|
736
956
|
*/
|
|
737
|
-
module.exports.
|
|
738
|
-
|
|
739
|
-
|
|
957
|
+
module.exports.collectRewardsQuote = function(whirlpool, position, tick_lower, tick_upper, current_timestamp, transfer_fee_1, transfer_fee_2, transfer_fee_3) {
|
|
958
|
+
try {
|
|
959
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
960
|
+
wasm.collectRewardsQuote(retptr, addHeapObject(whirlpool), addHeapObject(position), addHeapObject(tick_lower), addHeapObject(tick_upper), current_timestamp, isLikeNone(transfer_fee_1) ? 0 : addHeapObject(transfer_fee_1), isLikeNone(transfer_fee_2) ? 0 : addHeapObject(transfer_fee_2), isLikeNone(transfer_fee_3) ? 0 : addHeapObject(transfer_fee_3));
|
|
961
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
962
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
963
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
964
|
+
if (r2) {
|
|
965
|
+
throw takeObject(r1);
|
|
966
|
+
}
|
|
967
|
+
return takeObject(r0);
|
|
968
|
+
} finally {
|
|
969
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
970
|
+
}
|
|
740
971
|
};
|
|
741
972
|
|
|
973
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
974
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
975
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
976
|
+
WASM_VECTOR_LEN = arg.length;
|
|
977
|
+
return ptr;
|
|
978
|
+
}
|
|
742
979
|
/**
|
|
743
|
-
*
|
|
744
|
-
* If the lower tick index is greater than the upper tick index, the indexes are swapped.
|
|
745
|
-
* This is useful for ensuring that the lower tick index is always less than the upper tick index.
|
|
980
|
+
* Get the first unoccupied position in a bundle
|
|
746
981
|
*
|
|
747
|
-
* #
|
|
748
|
-
*
|
|
749
|
-
* - `tick_index_2` - A i32 integer representing the second tick index
|
|
982
|
+
* # Arguments
|
|
983
|
+
* * `bundle` - The bundle to check
|
|
750
984
|
*
|
|
751
985
|
* # Returns
|
|
752
|
-
*
|
|
986
|
+
* * `u32` - The first unoccupied position (None if full)
|
|
753
987
|
*/
|
|
754
|
-
module.exports.
|
|
755
|
-
const
|
|
756
|
-
|
|
988
|
+
module.exports.firstUnoccupiedPositionInBundle = function(bitmap) {
|
|
989
|
+
const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export_0);
|
|
990
|
+
const len0 = WASM_VECTOR_LEN;
|
|
991
|
+
const ret = wasm.firstUnoccupiedPositionInBundle(ptr0, len0);
|
|
992
|
+
return ret === 0x100000001 ? undefined : ret;
|
|
757
993
|
};
|
|
758
994
|
|
|
759
995
|
/**
|
|
760
|
-
* Check
|
|
996
|
+
* Check whether a position bundle is full
|
|
997
|
+
* A position bundle can contain 256 positions
|
|
761
998
|
*
|
|
762
|
-
* #
|
|
763
|
-
*
|
|
999
|
+
* # Arguments
|
|
1000
|
+
* * `bundle` - The bundle to check
|
|
764
1001
|
*
|
|
765
1002
|
* # Returns
|
|
766
|
-
*
|
|
1003
|
+
* * `bool` - Whether the bundle is full
|
|
767
1004
|
*/
|
|
768
|
-
module.exports.
|
|
769
|
-
const
|
|
1005
|
+
module.exports.isPositionBundleFull = function(bitmap) {
|
|
1006
|
+
const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export_0);
|
|
1007
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1008
|
+
const ret = wasm.isPositionBundleFull(ptr0, len0);
|
|
770
1009
|
return ret !== 0;
|
|
771
1010
|
};
|
|
772
1011
|
|
|
773
1012
|
/**
|
|
774
|
-
*
|
|
1013
|
+
* Check whether a position bundle is empty
|
|
775
1014
|
*
|
|
776
|
-
* #
|
|
777
|
-
*
|
|
778
|
-
* - `tick_array_start_index` - A i32 integer representing the start tick index of the tick array
|
|
779
|
-
* - `tick_spacing` - A u16 integer representing the tick spacing
|
|
1015
|
+
* # Arguments
|
|
1016
|
+
* * `bundle` - The bundle to check
|
|
780
1017
|
*
|
|
781
1018
|
* # Returns
|
|
782
|
-
*
|
|
1019
|
+
* * `bool` - Whether the bundle is empty
|
|
783
1020
|
*/
|
|
784
|
-
module.exports.
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
790
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
791
|
-
if (r2) {
|
|
792
|
-
throw takeObject(r1);
|
|
793
|
-
}
|
|
794
|
-
return r0 >>> 0;
|
|
795
|
-
} finally {
|
|
796
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
797
|
-
}
|
|
1021
|
+
module.exports.isPositionBundleEmpty = function(bitmap) {
|
|
1022
|
+
const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export_0);
|
|
1023
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1024
|
+
const ret = wasm.isPositionBundleEmpty(ptr0, len0);
|
|
1025
|
+
return ret !== 0;
|
|
798
1026
|
};
|
|
799
1027
|
|
|
800
1028
|
module.exports._VOLATILITY_ACCUMULATOR_SCALE_FACTOR = function() {
|
|
@@ -822,11 +1050,6 @@ module.exports._FEE_RATE_HARD_LIMIT = function() {
|
|
|
822
1050
|
return ret >>> 0;
|
|
823
1051
|
};
|
|
824
1052
|
|
|
825
|
-
module.exports._POSITION_BUNDLE_SIZE = function() {
|
|
826
|
-
const ret = wasm._POSITION_BUNDLE_SIZE();
|
|
827
|
-
return ret >>> 0;
|
|
828
|
-
};
|
|
829
|
-
|
|
830
1053
|
module.exports._TICK_ARRAY_NOT_EVENLY_SPACED = function() {
|
|
831
1054
|
try {
|
|
832
1055
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
@@ -1019,179 +1242,6 @@ module.exports._INVALID_ADAPTIVE_FEE_INFO = function() {
|
|
|
1019
1242
|
}
|
|
1020
1243
|
};
|
|
1021
1244
|
|
|
1022
|
-
module.exports._NUM_REWARDS = function() {
|
|
1023
|
-
const ret = wasm._NUM_REWARDS();
|
|
1024
|
-
return ret >>> 0;
|
|
1025
|
-
};
|
|
1026
|
-
|
|
1027
|
-
module.exports._FEE_RATE_DENOMINATOR = function() {
|
|
1028
|
-
const ret = wasm._FEE_RATE_DENOMINATOR();
|
|
1029
|
-
return ret >>> 0;
|
|
1030
|
-
};
|
|
1031
|
-
|
|
1032
|
-
module.exports._TICK_ARRAY_SIZE = function() {
|
|
1033
|
-
const ret = wasm._TICK_ARRAY_SIZE();
|
|
1034
|
-
return ret >>> 0;
|
|
1035
|
-
};
|
|
1036
|
-
|
|
1037
|
-
module.exports._FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD = function() {
|
|
1038
|
-
const ret = wasm._FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD();
|
|
1039
|
-
return ret;
|
|
1040
|
-
};
|
|
1041
|
-
|
|
1042
|
-
module.exports._MIN_TICK_INDEX = function() {
|
|
1043
|
-
const ret = wasm._MIN_TICK_INDEX();
|
|
1044
|
-
return ret;
|
|
1045
|
-
};
|
|
1046
|
-
|
|
1047
|
-
module.exports._MAX_TICK_INDEX = function() {
|
|
1048
|
-
const ret = wasm._MAX_TICK_INDEX();
|
|
1049
|
-
return ret;
|
|
1050
|
-
};
|
|
1051
|
-
|
|
1052
|
-
/**
|
|
1053
|
-
* Check if a position is in range.
|
|
1054
|
-
* When a position is in range it is earning fees and rewards
|
|
1055
|
-
*
|
|
1056
|
-
* # Parameters
|
|
1057
|
-
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
1058
|
-
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
1059
|
-
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
1060
|
-
*
|
|
1061
|
-
* # Returns
|
|
1062
|
-
* - A boolean value indicating if the position is in range
|
|
1063
|
-
*/
|
|
1064
|
-
module.exports.isPositionInRange = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
1065
|
-
const ret = wasm.isPositionInRange(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
|
|
1066
|
-
return ret !== 0;
|
|
1067
|
-
};
|
|
1068
|
-
|
|
1069
|
-
/**
|
|
1070
|
-
* Calculate the status of a position
|
|
1071
|
-
* The status can be one of three values:
|
|
1072
|
-
* - InRange: The position is in range
|
|
1073
|
-
* - BelowRange: The position is below the range
|
|
1074
|
-
* - AboveRange: The position is above the range
|
|
1075
|
-
*
|
|
1076
|
-
* # Parameters
|
|
1077
|
-
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
1078
|
-
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
1079
|
-
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
1080
|
-
*
|
|
1081
|
-
* # Returns
|
|
1082
|
-
* - A PositionStatus enum value indicating the status of the position
|
|
1083
|
-
*/
|
|
1084
|
-
module.exports.positionStatus = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
1085
|
-
const ret = wasm.positionStatus(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
|
|
1086
|
-
return takeObject(ret);
|
|
1087
|
-
};
|
|
1088
|
-
|
|
1089
|
-
/**
|
|
1090
|
-
* Calculate the token_a / token_b ratio of a (ficticious) position
|
|
1091
|
-
*
|
|
1092
|
-
* # Parameters
|
|
1093
|
-
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
1094
|
-
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
1095
|
-
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
1096
|
-
*
|
|
1097
|
-
* # Returns
|
|
1098
|
-
* - A PositionRatio struct containing the ratio of token_a and token_b
|
|
1099
|
-
*/
|
|
1100
|
-
module.exports.positionRatio = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
1101
|
-
const ret = wasm.positionRatio(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
|
|
1102
|
-
return takeObject(ret);
|
|
1103
|
-
};
|
|
1104
|
-
|
|
1105
|
-
/**
|
|
1106
|
-
* Convert a price into a sqrt priceX64
|
|
1107
|
-
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
1108
|
-
* Make sure to do these operations last and not to use the result for further calculations.
|
|
1109
|
-
*
|
|
1110
|
-
* # Parameters
|
|
1111
|
-
* * `price` - The price to convert
|
|
1112
|
-
* * `decimals_a` - The number of decimals of the base token
|
|
1113
|
-
* * `decimals_b` - The number of decimals of the quote token
|
|
1114
|
-
*
|
|
1115
|
-
* # Returns
|
|
1116
|
-
* * `u128` - The sqrt priceX64
|
|
1117
|
-
*/
|
|
1118
|
-
module.exports.priceToSqrtPrice = function(price, decimals_a, decimals_b) {
|
|
1119
|
-
const ret = wasm.priceToSqrtPrice(price, decimals_a, decimals_b);
|
|
1120
|
-
return takeObject(ret);
|
|
1121
|
-
};
|
|
1122
|
-
|
|
1123
|
-
/**
|
|
1124
|
-
* Convert a sqrt priceX64 into a tick index
|
|
1125
|
-
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
1126
|
-
* Make sure to do these operations last and not to use the result for further calculations.
|
|
1127
|
-
*
|
|
1128
|
-
* # Parameters
|
|
1129
|
-
* * `sqrt_price` - The sqrt priceX64 to convert
|
|
1130
|
-
* * `decimals_a` - The number of decimals of the base token
|
|
1131
|
-
* * `decimals_b` - The number of decimals of the quote token
|
|
1132
|
-
*
|
|
1133
|
-
* # Returns
|
|
1134
|
-
* * `f64` - The decimal price
|
|
1135
|
-
*/
|
|
1136
|
-
module.exports.sqrtPriceToPrice = function(sqrt_price, decimals_a, decimals_b) {
|
|
1137
|
-
const ret = wasm.sqrtPriceToPrice(addHeapObject(sqrt_price), decimals_a, decimals_b);
|
|
1138
|
-
return ret;
|
|
1139
|
-
};
|
|
1140
|
-
|
|
1141
|
-
/**
|
|
1142
|
-
* Invert a price
|
|
1143
|
-
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
1144
|
-
* Make sure to do these operations last and not to use the result for further calculations.
|
|
1145
|
-
*
|
|
1146
|
-
* # Parameters
|
|
1147
|
-
* * `price` - The price to invert
|
|
1148
|
-
* * `decimals_a` - The number of decimals of the base token
|
|
1149
|
-
* * `decimals_b` - The number of decimals of the quote token
|
|
1150
|
-
*
|
|
1151
|
-
* # Returns
|
|
1152
|
-
* * `f64` - The inverted price
|
|
1153
|
-
*/
|
|
1154
|
-
module.exports.invertPrice = function(price, decimals_a, decimals_b) {
|
|
1155
|
-
const ret = wasm.invertPrice(price, decimals_a, decimals_b);
|
|
1156
|
-
return ret;
|
|
1157
|
-
};
|
|
1158
|
-
|
|
1159
|
-
/**
|
|
1160
|
-
* Convert a tick index into a price
|
|
1161
|
-
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
1162
|
-
* Make sure to do these operations last and not to use the result for further calculations.
|
|
1163
|
-
*
|
|
1164
|
-
* # Parameters
|
|
1165
|
-
* * `tick_index` - The tick index to convert
|
|
1166
|
-
* * `decimals_a` - The number of decimals of the base token
|
|
1167
|
-
* * `decimals_b` - The number of decimals of the quote token
|
|
1168
|
-
*
|
|
1169
|
-
* # Returns
|
|
1170
|
-
* * `f64` - The decimal price
|
|
1171
|
-
*/
|
|
1172
|
-
module.exports.tickIndexToPrice = function(tick_index, decimals_a, decimals_b) {
|
|
1173
|
-
const ret = wasm.tickIndexToPrice(tick_index, decimals_a, decimals_b);
|
|
1174
|
-
return ret;
|
|
1175
|
-
};
|
|
1176
|
-
|
|
1177
|
-
/**
|
|
1178
|
-
* Convert a price into a tick index
|
|
1179
|
-
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
1180
|
-
* Make sure to do these operations last and not to use the result for further calculations.
|
|
1181
|
-
*
|
|
1182
|
-
* # Parameters
|
|
1183
|
-
* * `price` - The price to convert
|
|
1184
|
-
* * `decimals_a` - The number of decimals of the base token
|
|
1185
|
-
* * `decimals_b` - The number of decimals of the quote token
|
|
1186
|
-
*
|
|
1187
|
-
* # Returns
|
|
1188
|
-
* * `i32` - The tick index
|
|
1189
|
-
*/
|
|
1190
|
-
module.exports.priceToTickIndex = function(price, decimals_a, decimals_b) {
|
|
1191
|
-
const ret = wasm.priceToTickIndex(price, decimals_a, decimals_b);
|
|
1192
|
-
return ret;
|
|
1193
|
-
};
|
|
1194
|
-
|
|
1195
1245
|
/**
|
|
1196
1246
|
* Computes the exact input or output amount for a swap transaction.
|
|
1197
1247
|
*
|
|
@@ -1258,36 +1308,6 @@ module.exports.swapQuoteByOutputToken = function(token_out, specified_token_a, s
|
|
|
1258
1308
|
}
|
|
1259
1309
|
};
|
|
1260
1310
|
|
|
1261
|
-
/**
|
|
1262
|
-
* Calculate fees owed for a position
|
|
1263
|
-
*
|
|
1264
|
-
* # Paramters
|
|
1265
|
-
* - `whirlpool`: The whirlpool state
|
|
1266
|
-
* - `position`: The position state
|
|
1267
|
-
* - `tick_lower`: The lower tick state
|
|
1268
|
-
* - `tick_upper`: The upper tick state
|
|
1269
|
-
* - `transfer_fee_a`: The transfer fee for token A
|
|
1270
|
-
* - `transfer_fee_b`: The transfer fee for token B
|
|
1271
|
-
*
|
|
1272
|
-
* # Returns
|
|
1273
|
-
* - `CollectFeesQuote`: The fees owed for token A and token B
|
|
1274
|
-
*/
|
|
1275
|
-
module.exports.collectFeesQuote = function(whirlpool, position, tick_lower, tick_upper, transfer_fee_a, transfer_fee_b) {
|
|
1276
|
-
try {
|
|
1277
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1278
|
-
wasm.collectFeesQuote(retptr, addHeapObject(whirlpool), addHeapObject(position), addHeapObject(tick_lower), addHeapObject(tick_upper), isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
|
|
1279
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1280
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1281
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1282
|
-
if (r2) {
|
|
1283
|
-
throw takeObject(r1);
|
|
1284
|
-
}
|
|
1285
|
-
return takeObject(r0);
|
|
1286
|
-
} finally {
|
|
1287
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1288
|
-
}
|
|
1289
|
-
};
|
|
1290
|
-
|
|
1291
1311
|
/**
|
|
1292
1312
|
* Calculate the quote for decreasing liquidity
|
|
1293
1313
|
*
|