@crypticdot/defituna-core 3.4.2 → 3.4.3
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 +180 -176
- package/dist/browser/defituna_core_js_bindings_bg.js +794 -753
- package/dist/browser/defituna_core_js_bindings_bg.wasm +0 -0
- package/dist/browser/defituna_core_js_bindings_bg.wasm.d.ts +38 -37
- package/dist/nodejs/defituna_core_js_bindings.d.ts +180 -176
- package/dist/nodejs/defituna_core_js_bindings.js +794 -753
- package/dist/nodejs/defituna_core_js_bindings_bg.wasm +0 -0
- package/dist/nodejs/defituna_core_js_bindings_bg.wasm.d.ts +38 -37
- package/package.json +2 -2
|
@@ -252,752 +252,899 @@ function passArray8ToWasm0(arg, malloc) {
|
|
|
252
252
|
WASM_VECTOR_LEN = arg.length;
|
|
253
253
|
return ptr;
|
|
254
254
|
}
|
|
255
|
+
|
|
256
|
+
exports._POSITION_BUNDLE_SIZE = function() {
|
|
257
|
+
const ret = wasm._POSITION_BUNDLE_SIZE();
|
|
258
|
+
return ret >>> 0;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
exports._FEE_RATE_MUL_VALUE = function() {
|
|
262
|
+
const ret = wasm._FEE_RATE_MUL_VALUE();
|
|
263
|
+
return ret >>> 0;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
exports._MAX_PROTOCOL_FEE_RATE = function() {
|
|
267
|
+
const ret = wasm._MAX_PROTOCOL_FEE_RATE();
|
|
268
|
+
return ret;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
exports._PROTOCOL_FEE_RATE_MUL_VALUE = function() {
|
|
272
|
+
const ret = wasm._PROTOCOL_FEE_RATE_MUL_VALUE();
|
|
273
|
+
return ret;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
exports._TICK_ARRAY_SIZE = function() {
|
|
277
|
+
const ret = wasm._TICK_ARRAY_SIZE();
|
|
278
|
+
return ret >>> 0;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
exports._FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD = function() {
|
|
282
|
+
const ret = wasm._FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD();
|
|
283
|
+
return ret;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
exports._MIN_TICK_INDEX = function() {
|
|
287
|
+
const ret = wasm._MIN_TICK_INDEX();
|
|
288
|
+
return ret;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
exports._MAX_TICK_INDEX = function() {
|
|
292
|
+
const ret = wasm._MAX_TICK_INDEX();
|
|
293
|
+
return ret;
|
|
294
|
+
};
|
|
295
|
+
|
|
255
296
|
/**
|
|
256
|
-
*
|
|
297
|
+
* Get the first tick index in the tick array that contains the specified tick index.
|
|
257
298
|
*
|
|
258
299
|
* # Parameters
|
|
259
|
-
* - `
|
|
260
|
-
* - `
|
|
261
|
-
* - `liquidity`: The liquidity
|
|
262
|
-
* - `round_up`: Whether to round up or not
|
|
300
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
301
|
+
* - `tick_spacing` - A i32 integer representing the tick spacing
|
|
263
302
|
*
|
|
264
303
|
* # Returns
|
|
265
|
-
* -
|
|
304
|
+
* - A i32 integer representing the first tick index in the tick array
|
|
266
305
|
*/
|
|
267
|
-
exports.
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
wasm.tryGetAmountDeltaA(retptr, addHeapObject(sqrt_price_1), addHeapObject(sqrt_price_2), addHeapObject(liquidity), round_up);
|
|
271
|
-
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
272
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
273
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
274
|
-
if (r3) {
|
|
275
|
-
throw takeObject(r2);
|
|
276
|
-
}
|
|
277
|
-
return BigInt.asUintN(64, r0);
|
|
278
|
-
} finally {
|
|
279
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
280
|
-
}
|
|
306
|
+
exports.getTickArrayStartTickIndex = function(tick_index, tick_spacing) {
|
|
307
|
+
const ret = wasm.getTickArrayStartTickIndex(tick_index, tick_spacing);
|
|
308
|
+
return ret;
|
|
281
309
|
};
|
|
282
310
|
|
|
283
311
|
/**
|
|
284
|
-
*
|
|
312
|
+
* Derive the sqrt-price from a tick index. The precision of this method is only guarranted
|
|
313
|
+
* if tick is within the bounds of {max, min} tick-index.
|
|
285
314
|
*
|
|
286
315
|
* # Parameters
|
|
287
|
-
* - `
|
|
288
|
-
* - `sqrt_price_2`: The second square root price
|
|
289
|
-
* - `liquidity`: The liquidity
|
|
290
|
-
* - `round_up`: Whether to round up or not
|
|
316
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
291
317
|
*
|
|
292
318
|
* # Returns
|
|
293
|
-
* - `
|
|
319
|
+
* - `Ok`: A u128 Q32.64 representing the sqrt_price
|
|
294
320
|
*/
|
|
295
|
-
exports.
|
|
321
|
+
exports.tickIndexToSqrtPrice = function(tick_index) {
|
|
296
322
|
try {
|
|
297
323
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
298
|
-
wasm.
|
|
324
|
+
wasm.tickIndexToSqrtPrice(retptr, tick_index);
|
|
299
325
|
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
300
|
-
var r2 = getDataViewMemory0().
|
|
301
|
-
|
|
302
|
-
if (r3) {
|
|
303
|
-
throw takeObject(r2);
|
|
304
|
-
}
|
|
305
|
-
return BigInt.asUintN(64, r0);
|
|
326
|
+
var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
|
|
327
|
+
return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
|
|
306
328
|
} finally {
|
|
307
329
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
308
330
|
}
|
|
309
331
|
};
|
|
310
332
|
|
|
311
333
|
/**
|
|
312
|
-
*
|
|
334
|
+
* Derive the tick index from a sqrt price. The precision of this method is only guarranted
|
|
335
|
+
* if tick is within the bounds of {max, min} tick-index.
|
|
313
336
|
*
|
|
314
337
|
* # Parameters
|
|
315
|
-
* - `
|
|
316
|
-
* - `current_liquidity`: The current liquidity
|
|
317
|
-
* - `amount`: The amount
|
|
318
|
-
* - `specified_input`: Whether the input is specified
|
|
338
|
+
* - `sqrt_price` - A u128 integer representing the sqrt price
|
|
319
339
|
*
|
|
320
340
|
* # Returns
|
|
321
|
-
* - `
|
|
341
|
+
* - `Ok`: A i32 integer representing the tick integer
|
|
322
342
|
*/
|
|
323
|
-
exports.
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
wasm.tryGetNextSqrtPriceFromA(retptr, addHeapObject(current_sqrt_price), addHeapObject(current_liquidity), amount, specified_input);
|
|
327
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
328
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
329
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
330
|
-
if (r2) {
|
|
331
|
-
throw takeObject(r1);
|
|
332
|
-
}
|
|
333
|
-
return takeObject(r0);
|
|
334
|
-
} finally {
|
|
335
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
336
|
-
}
|
|
343
|
+
exports.sqrtPriceToTickIndex = function(sqrt_price) {
|
|
344
|
+
const ret = wasm.sqrtPriceToTickIndex(sqrt_price, sqrt_price >> BigInt(64));
|
|
345
|
+
return ret;
|
|
337
346
|
};
|
|
338
347
|
|
|
339
348
|
/**
|
|
340
|
-
*
|
|
349
|
+
* Get the initializable tick index.
|
|
350
|
+
* If the tick index is already initializable, it is returned as is.
|
|
341
351
|
*
|
|
342
352
|
* # Parameters
|
|
343
|
-
* - `
|
|
344
|
-
* - `
|
|
345
|
-
* - `
|
|
346
|
-
* - `specified_input`: Whether the input is specified
|
|
353
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
354
|
+
* - `tick_spacing` - A i32 integer representing the tick spacing
|
|
355
|
+
* - `round_up` - A boolean value indicating if the supplied tick index should be rounded up. None will round to the nearest.
|
|
347
356
|
*
|
|
348
357
|
* # Returns
|
|
349
|
-
* -
|
|
358
|
+
* - A i32 integer representing the previous initializable tick index
|
|
350
359
|
*/
|
|
351
|
-
exports.
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
wasm.tryGetNextSqrtPriceFromB(retptr, addHeapObject(current_sqrt_price), addHeapObject(current_liquidity), amount, specified_input);
|
|
355
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
356
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
357
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
358
|
-
if (r2) {
|
|
359
|
-
throw takeObject(r1);
|
|
360
|
-
}
|
|
361
|
-
return takeObject(r0);
|
|
362
|
-
} finally {
|
|
363
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
364
|
-
}
|
|
360
|
+
exports.getInitializableTickIndex = function(tick_index, tick_spacing, round_up) {
|
|
361
|
+
const ret = wasm.getInitializableTickIndex(tick_index, tick_spacing, isLikeNone(round_up) ? 0xFFFFFF : round_up ? 1 : 0);
|
|
362
|
+
return ret;
|
|
365
363
|
};
|
|
366
364
|
|
|
367
365
|
/**
|
|
368
|
-
*
|
|
369
|
-
* e.g. You send 10000 amount with 100 fee rate. The fee amount will be 100.
|
|
370
|
-
* So the amount after fee will be 9900.
|
|
366
|
+
* Get the previous initializable tick index.
|
|
371
367
|
*
|
|
372
368
|
* # Parameters
|
|
373
|
-
* - `
|
|
374
|
-
* - `
|
|
369
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
370
|
+
* - `tick_spacing` - A i32 integer representing the tick spacing
|
|
375
371
|
*
|
|
376
372
|
* # Returns
|
|
377
|
-
* -
|
|
373
|
+
* - A i32 integer representing the previous initializable tick index
|
|
378
374
|
*/
|
|
379
|
-
exports.
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
wasm.tryApplyTransferFee(retptr, amount, addHeapObject(transfer_fee));
|
|
383
|
-
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
384
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
385
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
386
|
-
if (r3) {
|
|
387
|
-
throw takeObject(r2);
|
|
388
|
-
}
|
|
389
|
-
return BigInt.asUintN(64, r0);
|
|
390
|
-
} finally {
|
|
391
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
392
|
-
}
|
|
375
|
+
exports.getPrevInitializableTickIndex = function(tick_index, tick_spacing) {
|
|
376
|
+
const ret = wasm.getPrevInitializableTickIndex(tick_index, tick_spacing);
|
|
377
|
+
return ret;
|
|
393
378
|
};
|
|
394
379
|
|
|
395
380
|
/**
|
|
396
|
-
*
|
|
397
|
-
* e.g. You received 9900 amount with 100 fee rate. The fee amount will be 100.
|
|
398
|
-
* So the amount before fee will be 10000.
|
|
381
|
+
* Get the next initializable tick index.
|
|
399
382
|
*
|
|
400
383
|
* # Parameters
|
|
401
|
-
* - `
|
|
402
|
-
* - `
|
|
384
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
385
|
+
* - `tick_spacing` - A i32 integer representing the tick spacing
|
|
403
386
|
*
|
|
404
387
|
* # Returns
|
|
405
|
-
* -
|
|
388
|
+
* - A i32 integer representing the next initializable tick index
|
|
406
389
|
*/
|
|
407
|
-
exports.
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
wasm.tryReverseApplyTransferFee(retptr, amount, addHeapObject(transfer_fee));
|
|
411
|
-
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
412
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
413
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
414
|
-
if (r3) {
|
|
415
|
-
throw takeObject(r2);
|
|
416
|
-
}
|
|
417
|
-
return BigInt.asUintN(64, r0);
|
|
418
|
-
} finally {
|
|
419
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
420
|
-
}
|
|
390
|
+
exports.getNextInitializableTickIndex = function(tick_index, tick_spacing) {
|
|
391
|
+
const ret = wasm.getNextInitializableTickIndex(tick_index, tick_spacing);
|
|
392
|
+
return ret;
|
|
421
393
|
};
|
|
422
394
|
|
|
423
395
|
/**
|
|
424
|
-
*
|
|
425
|
-
* e.g. Your estimated amount you send is 10000 with 100 slippage tolerance. The max you send will be 10100.
|
|
396
|
+
* Check if a tick is in-bounds.
|
|
426
397
|
*
|
|
427
398
|
* # Parameters
|
|
428
|
-
* - `
|
|
429
|
-
* - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
|
|
399
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
430
400
|
*
|
|
431
401
|
* # Returns
|
|
432
|
-
* -
|
|
402
|
+
* - A boolean value indicating if the tick is in-bounds
|
|
433
403
|
*/
|
|
434
|
-
exports.
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
wasm.tryGetMaxAmountWithSlippageTolerance(retptr, amount, slippage_tolerance_bps);
|
|
438
|
-
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
439
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
440
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
441
|
-
if (r3) {
|
|
442
|
-
throw takeObject(r2);
|
|
443
|
-
}
|
|
444
|
-
return BigInt.asUintN(64, r0);
|
|
445
|
-
} finally {
|
|
446
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
447
|
-
}
|
|
404
|
+
exports.isTickIndexInBounds = function(tick_index) {
|
|
405
|
+
const ret = wasm.isTickIndexInBounds(tick_index);
|
|
406
|
+
return ret !== 0;
|
|
448
407
|
};
|
|
449
408
|
|
|
450
409
|
/**
|
|
451
|
-
*
|
|
452
|
-
*
|
|
410
|
+
* Check if a tick is initializable.
|
|
411
|
+
* A tick is initializable if it is divisible by the tick spacing.
|
|
453
412
|
*
|
|
454
413
|
* # Parameters
|
|
455
|
-
* - `
|
|
456
|
-
* - `
|
|
414
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
415
|
+
* - `tick_spacing` - A i32 integer representing the tick spacing
|
|
457
416
|
*
|
|
458
417
|
* # Returns
|
|
459
|
-
* -
|
|
418
|
+
* - A boolean value indicating if the tick is initializable
|
|
460
419
|
*/
|
|
461
|
-
exports.
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
wasm.tryGetMinAmountWithSlippageTolerance(retptr, amount, slippage_tolerance_bps);
|
|
465
|
-
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
466
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
467
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
468
|
-
if (r3) {
|
|
469
|
-
throw takeObject(r2);
|
|
470
|
-
}
|
|
471
|
-
return BigInt.asUintN(64, r0);
|
|
472
|
-
} finally {
|
|
473
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
474
|
-
}
|
|
420
|
+
exports.isTickInitializable = function(tick_index, tick_spacing) {
|
|
421
|
+
const ret = wasm.isTickInitializable(tick_index, tick_spacing);
|
|
422
|
+
return ret !== 0;
|
|
475
423
|
};
|
|
476
424
|
|
|
477
425
|
/**
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
*
|
|
426
|
+
* Get the tick index for the inverse of the price that this tick represents.
|
|
427
|
+
* Eg: Consider tick i where Pb/Pa = 1.0001 ^ i
|
|
428
|
+
* inverse of this, i.e. Pa/Pb = 1 / (1.0001 ^ i) = 1.0001^-i
|
|
481
429
|
*
|
|
482
430
|
* # Parameters
|
|
483
|
-
* - `
|
|
484
|
-
* - `fee_rate`: The fee rate to apply denominated in 1e6
|
|
431
|
+
* - `tick_index` - A i32 integer representing the tick integer
|
|
485
432
|
*
|
|
486
433
|
* # Returns
|
|
487
|
-
* -
|
|
434
|
+
* - A i32 integer representing the tick index for the inverse of the price
|
|
488
435
|
*/
|
|
489
|
-
exports.
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
wasm.tryApplySwapFee(retptr, amount, fee_rate);
|
|
493
|
-
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
494
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
495
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
496
|
-
if (r3) {
|
|
497
|
-
throw takeObject(r2);
|
|
498
|
-
}
|
|
499
|
-
return BigInt.asUintN(64, r0);
|
|
500
|
-
} finally {
|
|
501
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
502
|
-
}
|
|
436
|
+
exports.invertTickIndex = function(tick_index) {
|
|
437
|
+
const ret = wasm.invertTickIndex(tick_index);
|
|
438
|
+
return ret;
|
|
503
439
|
};
|
|
504
440
|
|
|
505
441
|
/**
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
442
|
+
* Get the sqrt price for the inverse of the price that this tick represents.
|
|
443
|
+
* Because converting to a tick index and then back to a sqrt price is lossy,
|
|
444
|
+
* this function is clamped to the nearest tick index.
|
|
509
445
|
*
|
|
510
446
|
* # Parameters
|
|
511
|
-
* - `
|
|
512
|
-
* - `fee_rate`: The fee rate to reverse denominated in 1e6
|
|
447
|
+
* - `sqrt_price` - A u128 integer representing the sqrt price
|
|
513
448
|
*
|
|
514
449
|
* # Returns
|
|
515
|
-
* -
|
|
450
|
+
* - A u128 integer representing the sqrt price for the inverse of the price
|
|
516
451
|
*/
|
|
517
|
-
exports.
|
|
452
|
+
exports.invertSqrtPrice = function(sqrt_price) {
|
|
518
453
|
try {
|
|
519
454
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
520
|
-
wasm.
|
|
455
|
+
wasm.invertSqrtPrice(retptr, sqrt_price, sqrt_price >> BigInt(64));
|
|
521
456
|
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
522
|
-
var r2 = getDataViewMemory0().
|
|
523
|
-
|
|
524
|
-
if (r3) {
|
|
525
|
-
throw takeObject(r2);
|
|
526
|
-
}
|
|
527
|
-
return BigInt.asUintN(64, r0);
|
|
457
|
+
var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
|
|
458
|
+
return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
|
|
528
459
|
} finally {
|
|
529
460
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
530
461
|
}
|
|
531
462
|
};
|
|
532
463
|
|
|
533
|
-
exports._FEE_RATE_MUL_VALUE = function() {
|
|
534
|
-
const ret = wasm._FEE_RATE_MUL_VALUE();
|
|
535
|
-
return ret >>> 0;
|
|
536
|
-
};
|
|
537
|
-
|
|
538
|
-
exports._MAX_PROTOCOL_FEE_RATE = function() {
|
|
539
|
-
const ret = wasm._MAX_PROTOCOL_FEE_RATE();
|
|
540
|
-
return ret;
|
|
541
|
-
};
|
|
542
|
-
|
|
543
|
-
exports._PROTOCOL_FEE_RATE_MUL_VALUE = function() {
|
|
544
|
-
const ret = wasm._PROTOCOL_FEE_RATE_MUL_VALUE();
|
|
545
|
-
return ret;
|
|
546
|
-
};
|
|
547
|
-
|
|
548
|
-
exports._TICK_ARRAY_SIZE = function() {
|
|
549
|
-
const ret = wasm._TICK_ARRAY_SIZE();
|
|
550
|
-
return ret >>> 0;
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
exports._FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD = function() {
|
|
554
|
-
const ret = wasm._FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD();
|
|
555
|
-
return ret;
|
|
556
|
-
};
|
|
557
|
-
|
|
558
|
-
exports._MIN_TICK_INDEX = function() {
|
|
559
|
-
const ret = wasm._MIN_TICK_INDEX();
|
|
560
|
-
return ret;
|
|
561
|
-
};
|
|
562
|
-
|
|
563
|
-
exports._MAX_TICK_INDEX = function() {
|
|
564
|
-
const ret = wasm._MAX_TICK_INDEX();
|
|
565
|
-
return ret;
|
|
566
|
-
};
|
|
567
|
-
|
|
568
464
|
/**
|
|
569
|
-
* Get the
|
|
465
|
+
* Get the minimum and maximum tick index that can be initialized.
|
|
570
466
|
*
|
|
571
467
|
* # Parameters
|
|
572
|
-
* - `tick_index` - A i32 integer representing the tick integer
|
|
573
468
|
* - `tick_spacing` - A i32 integer representing the tick spacing
|
|
574
469
|
*
|
|
575
470
|
* # Returns
|
|
576
|
-
* - A
|
|
471
|
+
* - A TickRange struct containing the lower and upper tick index
|
|
577
472
|
*/
|
|
578
|
-
exports.
|
|
579
|
-
const ret = wasm.
|
|
580
|
-
return ret;
|
|
473
|
+
exports.getFullRangeTickIndexes = function(tick_spacing) {
|
|
474
|
+
const ret = wasm.getFullRangeTickIndexes(tick_spacing);
|
|
475
|
+
return takeObject(ret);
|
|
581
476
|
};
|
|
582
477
|
|
|
583
478
|
/**
|
|
584
|
-
*
|
|
585
|
-
*
|
|
479
|
+
* Order tick indexes in ascending order.
|
|
480
|
+
* If the lower tick index is greater than the upper tick index, the indexes are swapped.
|
|
481
|
+
* This is useful for ensuring that the lower tick index is always less than the upper tick index.
|
|
586
482
|
*
|
|
587
483
|
* # Parameters
|
|
588
|
-
* - `
|
|
484
|
+
* - `tick_index_1` - A i32 integer representing the first tick index
|
|
485
|
+
* - `tick_index_2` - A i32 integer representing the second tick index
|
|
589
486
|
*
|
|
590
487
|
* # Returns
|
|
591
|
-
* -
|
|
488
|
+
* - A TickRange struct containing the lower and upper tick index
|
|
592
489
|
*/
|
|
593
|
-
exports.
|
|
594
|
-
const ret = wasm.
|
|
490
|
+
exports.orderTickIndexes = function(tick_index_1, tick_index_2) {
|
|
491
|
+
const ret = wasm.orderTickIndexes(tick_index_1, tick_index_2);
|
|
595
492
|
return takeObject(ret);
|
|
596
493
|
};
|
|
597
494
|
|
|
598
495
|
/**
|
|
599
|
-
*
|
|
600
|
-
* if tick is within the bounds of {max, min} tick-index.
|
|
496
|
+
* Check if a fusion_pool is a full-range only pool.
|
|
601
497
|
*
|
|
602
498
|
* # Parameters
|
|
603
|
-
* - `
|
|
499
|
+
* - `tick_spacing` - A u16 integer representing the tick spacing
|
|
604
500
|
*
|
|
605
501
|
* # Returns
|
|
606
|
-
* -
|
|
502
|
+
* - A boolean value indicating if the fusion_pool is a full-range only pool
|
|
607
503
|
*/
|
|
608
|
-
exports.
|
|
609
|
-
const ret = wasm.
|
|
610
|
-
return ret;
|
|
504
|
+
exports.isFullRangeOnly = function(tick_spacing) {
|
|
505
|
+
const ret = wasm.isFullRangeOnly(tick_spacing);
|
|
506
|
+
return ret !== 0;
|
|
611
507
|
};
|
|
612
508
|
|
|
613
509
|
/**
|
|
614
|
-
* Get the
|
|
615
|
-
* If the tick index is already initializable, it is returned as is.
|
|
510
|
+
* Get the index of a tick in a tick array.
|
|
616
511
|
*
|
|
617
512
|
* # Parameters
|
|
618
|
-
* - `tick_index` - A i32 integer representing the tick
|
|
619
|
-
* - `
|
|
620
|
-
* - `
|
|
513
|
+
* - `tick_index` - A i32 integer representing the tick index
|
|
514
|
+
* - `tick_array_start_index` - A i32 integer representing the start tick index of the tick array
|
|
515
|
+
* - `tick_spacing` - A u16 integer representing the tick spacing
|
|
621
516
|
*
|
|
622
517
|
* # Returns
|
|
623
|
-
* - A
|
|
518
|
+
* - A u32 integer representing the tick index in the tick array
|
|
624
519
|
*/
|
|
625
|
-
exports.
|
|
626
|
-
|
|
627
|
-
|
|
520
|
+
exports.getTickIndexInArray = function(tick_index, tick_array_start_index, tick_spacing) {
|
|
521
|
+
try {
|
|
522
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
523
|
+
wasm.getTickIndexInArray(retptr, tick_index, tick_array_start_index, tick_spacing);
|
|
524
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
525
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
526
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
527
|
+
if (r2) {
|
|
528
|
+
throw takeObject(r1);
|
|
529
|
+
}
|
|
530
|
+
return r0 >>> 0;
|
|
531
|
+
} finally {
|
|
532
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
533
|
+
}
|
|
628
534
|
};
|
|
629
535
|
|
|
630
536
|
/**
|
|
631
|
-
*
|
|
537
|
+
* Calculate the quote for decreasing liquidity
|
|
632
538
|
*
|
|
633
539
|
* # Parameters
|
|
634
|
-
* - `
|
|
635
|
-
* - `
|
|
540
|
+
* - `liquidity_delta` - The amount of liquidity to decrease
|
|
541
|
+
* - `slippage_tolerance` - The slippage tolerance in bps
|
|
542
|
+
* - `current_sqrt_price` - The current sqrt price of the pool
|
|
543
|
+
* - `tick_index_1` - The first tick index of the position
|
|
544
|
+
* - `tick_index_2` - The second tick index of the position
|
|
545
|
+
* - `transfer_fee_a` - The transfer fee for token A in bps
|
|
546
|
+
* - `transfer_fee_b` - The transfer fee for token B in bps
|
|
636
547
|
*
|
|
637
548
|
* # Returns
|
|
638
|
-
* - A
|
|
549
|
+
* - A DecreaseLiquidityQuote struct containing the estimated token amounts
|
|
639
550
|
*/
|
|
640
|
-
exports.
|
|
641
|
-
|
|
642
|
-
|
|
551
|
+
exports.decreaseLiquidityQuote = function(liquidity_delta, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
|
|
552
|
+
try {
|
|
553
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
554
|
+
wasm.decreaseLiquidityQuote(retptr, liquidity_delta, liquidity_delta >> BigInt(64), slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
|
|
555
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
556
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
557
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
558
|
+
if (r2) {
|
|
559
|
+
throw takeObject(r1);
|
|
560
|
+
}
|
|
561
|
+
return takeObject(r0);
|
|
562
|
+
} finally {
|
|
563
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
564
|
+
}
|
|
643
565
|
};
|
|
644
566
|
|
|
645
567
|
/**
|
|
646
|
-
*
|
|
568
|
+
* Calculate the quote for decreasing liquidity given a token a amount
|
|
647
569
|
*
|
|
648
570
|
* # Parameters
|
|
649
|
-
* - `
|
|
650
|
-
* - `
|
|
571
|
+
* - `token_amount_a` - The amount of token a to decrease
|
|
572
|
+
* - `slippage_tolerance` - The slippage tolerance in bps
|
|
573
|
+
* - `current_sqrt_price` - The current sqrt price of the pool
|
|
574
|
+
* - `tick_index_1` - The first tick index of the position
|
|
575
|
+
* - `tick_index_2` - The second tick index of the position
|
|
576
|
+
* - `transfer_fee_a` - The transfer fee for token A in bps
|
|
577
|
+
* - `transfer_fee_b` - The transfer fee for token B in bps
|
|
651
578
|
*
|
|
652
579
|
* # Returns
|
|
653
|
-
* - A
|
|
580
|
+
* - A DecreaseLiquidityQuote struct containing the estimated token amounts
|
|
654
581
|
*/
|
|
655
|
-
exports.
|
|
656
|
-
|
|
657
|
-
|
|
582
|
+
exports.decreaseLiquidityQuoteA = function(token_amount_a, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
|
|
583
|
+
try {
|
|
584
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
585
|
+
wasm.decreaseLiquidityQuoteA(retptr, token_amount_a, slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
|
|
586
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
587
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
588
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
589
|
+
if (r2) {
|
|
590
|
+
throw takeObject(r1);
|
|
591
|
+
}
|
|
592
|
+
return takeObject(r0);
|
|
593
|
+
} finally {
|
|
594
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
595
|
+
}
|
|
658
596
|
};
|
|
659
597
|
|
|
660
598
|
/**
|
|
661
|
-
*
|
|
599
|
+
* Calculate the quote for decreasing liquidity given a token b amount
|
|
662
600
|
*
|
|
663
601
|
* # Parameters
|
|
664
|
-
* - `
|
|
602
|
+
* - `token_amount_b` - The amount of token b to decrease
|
|
603
|
+
* - `slippage_tolerance` - The slippage tolerance in bps
|
|
604
|
+
* - `current_sqrt_price` - The current sqrt price of the pool
|
|
605
|
+
* - `tick_index_1` - The first tick index of the position
|
|
606
|
+
* - `tick_index_2` - The second tick index of the position
|
|
607
|
+
* - `transfer_fee_a` - The transfer fee for token A in bps
|
|
608
|
+
* - `transfer_fee_b` - The transfer fee for token B in bps
|
|
665
609
|
*
|
|
666
610
|
* # Returns
|
|
667
|
-
* - A
|
|
611
|
+
* - A DecreaseLiquidityQuote struct containing the estimated token amounts
|
|
668
612
|
*/
|
|
669
|
-
exports.
|
|
670
|
-
|
|
671
|
-
|
|
613
|
+
exports.decreaseLiquidityQuoteB = function(token_amount_b, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
|
|
614
|
+
try {
|
|
615
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
616
|
+
wasm.decreaseLiquidityQuoteB(retptr, token_amount_b, slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
|
|
617
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
618
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
619
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
620
|
+
if (r2) {
|
|
621
|
+
throw takeObject(r1);
|
|
622
|
+
}
|
|
623
|
+
return takeObject(r0);
|
|
624
|
+
} finally {
|
|
625
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
626
|
+
}
|
|
672
627
|
};
|
|
673
628
|
|
|
674
629
|
/**
|
|
675
|
-
*
|
|
676
|
-
* A tick is initializable if it is divisible by the tick spacing.
|
|
630
|
+
* Calculate the quote for increasing liquidity
|
|
677
631
|
*
|
|
678
632
|
* # Parameters
|
|
679
|
-
* - `
|
|
680
|
-
* - `
|
|
633
|
+
* - `liquidity_delta` - The amount of liquidity to increase
|
|
634
|
+
* - `slippage_tolerance` - The slippage tolerance in bps
|
|
635
|
+
* - `current_sqrt_price` - The current sqrt price of the pool
|
|
636
|
+
* - `tick_index_1` - The first tick index of the position
|
|
637
|
+
* - `tick_index_2` - The second tick index of the position
|
|
638
|
+
* - `transfer_fee_a` - The transfer fee for token A in bps
|
|
639
|
+
* - `transfer_fee_b` - The transfer fee for token B in bps
|
|
681
640
|
*
|
|
682
641
|
* # Returns
|
|
683
|
-
* -
|
|
642
|
+
* - An IncreaseLiquidityQuote struct containing the estimated token amounts
|
|
684
643
|
*/
|
|
685
|
-
exports.
|
|
686
|
-
|
|
687
|
-
|
|
644
|
+
exports.increaseLiquidityQuote = function(liquidity_delta, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
|
|
645
|
+
try {
|
|
646
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
647
|
+
wasm.increaseLiquidityQuote(retptr, liquidity_delta, liquidity_delta >> BigInt(64), slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
|
|
648
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
649
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
650
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
651
|
+
if (r2) {
|
|
652
|
+
throw takeObject(r1);
|
|
653
|
+
}
|
|
654
|
+
return takeObject(r0);
|
|
655
|
+
} finally {
|
|
656
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
657
|
+
}
|
|
688
658
|
};
|
|
689
659
|
|
|
690
660
|
/**
|
|
691
|
-
*
|
|
692
|
-
* Eg: Consider tick i where Pb/Pa = 1.0001 ^ i
|
|
693
|
-
* inverse of this, i.e. Pa/Pb = 1 / (1.0001 ^ i) = 1.0001^-i
|
|
661
|
+
* Calculate the quote for increasing liquidity given a token a amount
|
|
694
662
|
*
|
|
695
663
|
* # Parameters
|
|
696
|
-
* - `
|
|
664
|
+
* - `token_amount_a` - The amount of token a to increase
|
|
665
|
+
* - `slippage_tolerance` - The slippage tolerance in bps
|
|
666
|
+
* - `current_sqrt_price` - The current sqrt price of the pool
|
|
667
|
+
* - `tick_index_1` - The first tick index of the position
|
|
668
|
+
* - `tick_index_2` - The second tick index of the position
|
|
669
|
+
* - `transfer_fee_a` - The transfer fee for token A in bps
|
|
670
|
+
* - `transfer_fee_b` - The transfer fee for token B in bps
|
|
697
671
|
*
|
|
698
672
|
* # Returns
|
|
699
|
-
* -
|
|
673
|
+
* - An IncreaseLiquidityQuote struct containing the estimated token amounts
|
|
700
674
|
*/
|
|
701
|
-
exports.
|
|
702
|
-
|
|
703
|
-
|
|
675
|
+
exports.increaseLiquidityQuoteA = function(token_amount_a, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
|
|
676
|
+
try {
|
|
677
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
678
|
+
wasm.increaseLiquidityQuoteA(retptr, token_amount_a, slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
|
|
679
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
680
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
681
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
682
|
+
if (r2) {
|
|
683
|
+
throw takeObject(r1);
|
|
684
|
+
}
|
|
685
|
+
return takeObject(r0);
|
|
686
|
+
} finally {
|
|
687
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
688
|
+
}
|
|
704
689
|
};
|
|
705
690
|
|
|
706
691
|
/**
|
|
707
|
-
*
|
|
708
|
-
* Because converting to a tick index and then back to a sqrt price is lossy,
|
|
709
|
-
* this function is clamped to the nearest tick index.
|
|
692
|
+
* Calculate the quote for increasing liquidity given a token b amount
|
|
710
693
|
*
|
|
711
694
|
* # Parameters
|
|
712
|
-
* - `
|
|
695
|
+
* - `token_amount_b` - The amount of token b to increase
|
|
696
|
+
* - `slippage_tolerance` - The slippage tolerance in bps
|
|
697
|
+
* - `current_sqrt_price` - The current sqrt price of the pool
|
|
698
|
+
* - `tick_index_1` - The first tick index of the position
|
|
699
|
+
* - `tick_index_2` - The second tick index of the position
|
|
700
|
+
* - `transfer_fee_a` - The transfer fee for token A in bps
|
|
701
|
+
* - `transfer_fee_b` - The transfer fee for token B in bps
|
|
713
702
|
*
|
|
714
703
|
* # Returns
|
|
715
|
-
* -
|
|
704
|
+
* - An IncreaseLiquidityQuote struct containing the estimated token amounts
|
|
716
705
|
*/
|
|
717
|
-
exports.
|
|
718
|
-
|
|
719
|
-
|
|
706
|
+
exports.increaseLiquidityQuoteB = function(token_amount_b, slippage_tolerance_bps, current_sqrt_price, tick_index_1, tick_index_2, transfer_fee_a, transfer_fee_b) {
|
|
707
|
+
try {
|
|
708
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
709
|
+
wasm.increaseLiquidityQuoteB(retptr, token_amount_b, slippage_tolerance_bps, current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
|
|
710
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
711
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
712
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
713
|
+
if (r2) {
|
|
714
|
+
throw takeObject(r1);
|
|
715
|
+
}
|
|
716
|
+
return takeObject(r0);
|
|
717
|
+
} finally {
|
|
718
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
exports.tryGetLiquidityFromA = function(token_delta_a, sqrt_price_lower, sqrt_price_upper) {
|
|
723
|
+
try {
|
|
724
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
|
|
725
|
+
wasm.tryGetLiquidityFromA(retptr, token_delta_a, sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64));
|
|
726
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
727
|
+
var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
|
|
728
|
+
var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
|
|
729
|
+
var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
|
|
730
|
+
if (r5) {
|
|
731
|
+
throw takeObject(r4);
|
|
732
|
+
}
|
|
733
|
+
return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
|
|
734
|
+
} finally {
|
|
735
|
+
wasm.__wbindgen_add_to_stack_pointer(32);
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
exports.tryGetTokenAFromLiquidity = function(liquidity_delta, sqrt_price_lower, sqrt_price_upper, round_up) {
|
|
740
|
+
try {
|
|
741
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
742
|
+
wasm.tryGetTokenAFromLiquidity(retptr, liquidity_delta, liquidity_delta >> BigInt(64), sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64), round_up);
|
|
743
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
744
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
745
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
746
|
+
if (r3) {
|
|
747
|
+
throw takeObject(r2);
|
|
748
|
+
}
|
|
749
|
+
return BigInt.asUintN(64, r0);
|
|
750
|
+
} finally {
|
|
751
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
|
|
755
|
+
exports.tryGetLiquidityFromB = function(token_delta_b, sqrt_price_lower, sqrt_price_upper) {
|
|
756
|
+
try {
|
|
757
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
|
|
758
|
+
wasm.tryGetLiquidityFromB(retptr, token_delta_b, sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64));
|
|
759
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
760
|
+
var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
|
|
761
|
+
var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
|
|
762
|
+
var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
|
|
763
|
+
if (r5) {
|
|
764
|
+
throw takeObject(r4);
|
|
765
|
+
}
|
|
766
|
+
return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
|
|
767
|
+
} finally {
|
|
768
|
+
wasm.__wbindgen_add_to_stack_pointer(32);
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
exports.tryGetTokenBFromLiquidity = function(liquidity_delta, sqrt_price_lower, sqrt_price_upper, round_up) {
|
|
773
|
+
try {
|
|
774
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
775
|
+
wasm.tryGetTokenBFromLiquidity(retptr, liquidity_delta, liquidity_delta >> BigInt(64), sqrt_price_lower, sqrt_price_lower >> BigInt(64), sqrt_price_upper, sqrt_price_upper >> BigInt(64), round_up);
|
|
776
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
777
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
778
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
779
|
+
if (r3) {
|
|
780
|
+
throw takeObject(r2);
|
|
781
|
+
}
|
|
782
|
+
return BigInt.asUintN(64, r0);
|
|
783
|
+
} finally {
|
|
784
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
|
|
788
|
+
exports.tryGetAmountsFromLiquidity = function(liquidity_delta, current_sqrt_price, tick_lower_index, tick_upper_index, round_up) {
|
|
789
|
+
try {
|
|
790
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
791
|
+
wasm.tryGetAmountsFromLiquidity(retptr, liquidity_delta, liquidity_delta >> BigInt(64), current_sqrt_price, current_sqrt_price >> BigInt(64), tick_lower_index, tick_upper_index, round_up);
|
|
792
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
793
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
794
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
795
|
+
if (r2) {
|
|
796
|
+
throw takeObject(r1);
|
|
797
|
+
}
|
|
798
|
+
return takeObject(r0);
|
|
799
|
+
} finally {
|
|
800
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
exports.tryGetLiquidityFromAmounts = function(sqrt_price, sqrt_price_a_x64, sqrt_price_b_x64, amount_a, amount_b) {
|
|
805
|
+
try {
|
|
806
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
|
|
807
|
+
wasm.tryGetLiquidityFromAmounts(retptr, sqrt_price, sqrt_price >> BigInt(64), sqrt_price_a_x64, sqrt_price_a_x64 >> BigInt(64), sqrt_price_b_x64, sqrt_price_b_x64 >> BigInt(64), amount_a, amount_b);
|
|
808
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
809
|
+
var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
|
|
810
|
+
var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
|
|
811
|
+
var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
|
|
812
|
+
if (r5) {
|
|
813
|
+
throw takeObject(r4);
|
|
814
|
+
}
|
|
815
|
+
return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
|
|
816
|
+
} finally {
|
|
817
|
+
wasm.__wbindgen_add_to_stack_pointer(32);
|
|
818
|
+
}
|
|
720
819
|
};
|
|
721
820
|
|
|
722
821
|
/**
|
|
723
|
-
*
|
|
822
|
+
* Calculate fees owed for a position
|
|
724
823
|
*
|
|
725
|
-
* #
|
|
726
|
-
* - `
|
|
824
|
+
* # Paramters
|
|
825
|
+
* - `fusion_pool`: The fusion_pool state
|
|
826
|
+
* - `position`: The position state
|
|
827
|
+
* - `tick_lower`: The lower tick state
|
|
828
|
+
* - `tick_upper`: The upper tick state
|
|
829
|
+
* - `transfer_fee_a`: The transfer fee for token A
|
|
830
|
+
* - `transfer_fee_b`: The transfer fee for token B
|
|
727
831
|
*
|
|
728
832
|
* # Returns
|
|
729
|
-
* -
|
|
833
|
+
* - `CollectFeesQuote`: The fees owed for token A and token B
|
|
730
834
|
*/
|
|
731
|
-
exports.
|
|
732
|
-
|
|
733
|
-
|
|
835
|
+
exports.collectFeesQuote = function(fusion_pool, position, tick_lower, tick_upper, transfer_fee_a, transfer_fee_b) {
|
|
836
|
+
try {
|
|
837
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
838
|
+
wasm.collectFeesQuote(retptr, addHeapObject(fusion_pool), 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));
|
|
839
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
840
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
841
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
842
|
+
if (r2) {
|
|
843
|
+
throw takeObject(r1);
|
|
844
|
+
}
|
|
845
|
+
return takeObject(r0);
|
|
846
|
+
} finally {
|
|
847
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
exports.limitOrderFee = function(fusion_pool) {
|
|
852
|
+
const ret = wasm.limitOrderFee(addHeapObject(fusion_pool));
|
|
853
|
+
return ret;
|
|
734
854
|
};
|
|
735
855
|
|
|
736
856
|
/**
|
|
737
|
-
*
|
|
738
|
-
* If the lower tick index is greater than the upper tick index, the indexes are swapped.
|
|
739
|
-
* This is useful for ensuring that the lower tick index is always less than the upper tick index.
|
|
857
|
+
* Calculate the amount A delta between two sqrt_prices
|
|
740
858
|
*
|
|
741
859
|
* # Parameters
|
|
742
|
-
* - `
|
|
743
|
-
* - `
|
|
860
|
+
* - `sqrt_price_1`: The first square root price
|
|
861
|
+
* - `sqrt_price_2`: The second square root price
|
|
862
|
+
* - `liquidity`: The liquidity
|
|
863
|
+
* - `round_up`: Whether to round up or not
|
|
744
864
|
*
|
|
745
865
|
* # Returns
|
|
746
|
-
* -
|
|
866
|
+
* - `u64`: The amount delta
|
|
747
867
|
*/
|
|
748
|
-
exports.
|
|
749
|
-
|
|
750
|
-
|
|
868
|
+
exports.tryGetAmountDeltaA = function(sqrt_price_1, sqrt_price_2, liquidity, round_up) {
|
|
869
|
+
try {
|
|
870
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
871
|
+
wasm.tryGetAmountDeltaA(retptr, sqrt_price_1, sqrt_price_1 >> BigInt(64), sqrt_price_2, sqrt_price_2 >> BigInt(64), liquidity, liquidity >> BigInt(64), round_up);
|
|
872
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
873
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
874
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
875
|
+
if (r3) {
|
|
876
|
+
throw takeObject(r2);
|
|
877
|
+
}
|
|
878
|
+
return BigInt.asUintN(64, r0);
|
|
879
|
+
} finally {
|
|
880
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
881
|
+
}
|
|
751
882
|
};
|
|
752
883
|
|
|
753
884
|
/**
|
|
754
|
-
*
|
|
885
|
+
* Calculate the amount B delta between two sqrt_prices
|
|
755
886
|
*
|
|
756
887
|
* # Parameters
|
|
757
|
-
* - `
|
|
888
|
+
* - `sqrt_price_1`: The first square root price
|
|
889
|
+
* - `sqrt_price_2`: The second square root price
|
|
890
|
+
* - `liquidity`: The liquidity
|
|
891
|
+
* - `round_up`: Whether to round up or not
|
|
758
892
|
*
|
|
759
893
|
* # Returns
|
|
760
|
-
* -
|
|
894
|
+
* - `u64`: The amount delta
|
|
761
895
|
*/
|
|
762
|
-
exports.
|
|
763
|
-
|
|
764
|
-
|
|
896
|
+
exports.tryGetAmountDeltaB = function(sqrt_price_1, sqrt_price_2, liquidity, round_up) {
|
|
897
|
+
try {
|
|
898
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
899
|
+
wasm.tryGetAmountDeltaB(retptr, sqrt_price_1, sqrt_price_1 >> BigInt(64), sqrt_price_2, sqrt_price_2 >> BigInt(64), liquidity, liquidity >> BigInt(64), round_up);
|
|
900
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
901
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
902
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
903
|
+
if (r3) {
|
|
904
|
+
throw takeObject(r2);
|
|
905
|
+
}
|
|
906
|
+
return BigInt.asUintN(64, r0);
|
|
907
|
+
} finally {
|
|
908
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
909
|
+
}
|
|
765
910
|
};
|
|
766
911
|
|
|
767
912
|
/**
|
|
768
|
-
*
|
|
913
|
+
* Calculate the next square root price
|
|
769
914
|
*
|
|
770
915
|
* # Parameters
|
|
771
|
-
* - `
|
|
772
|
-
* - `
|
|
773
|
-
* - `
|
|
916
|
+
* - `current_sqrt_price`: The current square root price
|
|
917
|
+
* - `current_liquidity`: The current liquidity
|
|
918
|
+
* - `amount`: The amount
|
|
919
|
+
* - `specified_input`: Whether the input is specified
|
|
774
920
|
*
|
|
775
921
|
* # Returns
|
|
776
|
-
* -
|
|
922
|
+
* - `u128`: The next square root price
|
|
777
923
|
*/
|
|
778
|
-
exports.
|
|
924
|
+
exports.tryGetNextSqrtPriceFromA = function(current_sqrt_price, current_liquidity, amount, specified_input) {
|
|
779
925
|
try {
|
|
780
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-
|
|
781
|
-
wasm.
|
|
782
|
-
var r0 = getDataViewMemory0().
|
|
783
|
-
var
|
|
784
|
-
var
|
|
785
|
-
|
|
786
|
-
|
|
926
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
|
|
927
|
+
wasm.tryGetNextSqrtPriceFromA(retptr, current_sqrt_price, current_sqrt_price >> BigInt(64), current_liquidity, current_liquidity >> BigInt(64), amount, specified_input);
|
|
928
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
929
|
+
var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
|
|
930
|
+
var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
|
|
931
|
+
var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
|
|
932
|
+
if (r5) {
|
|
933
|
+
throw takeObject(r4);
|
|
787
934
|
}
|
|
788
|
-
return r0
|
|
935
|
+
return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
|
|
789
936
|
} finally {
|
|
790
|
-
wasm.__wbindgen_add_to_stack_pointer(
|
|
937
|
+
wasm.__wbindgen_add_to_stack_pointer(32);
|
|
791
938
|
}
|
|
792
939
|
};
|
|
793
940
|
|
|
794
941
|
/**
|
|
795
|
-
* Calculate the
|
|
942
|
+
* Calculate the next square root price
|
|
796
943
|
*
|
|
797
944
|
* # Parameters
|
|
798
|
-
* - `
|
|
799
|
-
* - `
|
|
800
|
-
* - `
|
|
801
|
-
* - `
|
|
802
|
-
* - `tick_index_2` - The second tick index of the position
|
|
803
|
-
* - `transfer_fee_a` - The transfer fee for token A in bps
|
|
804
|
-
* - `transfer_fee_b` - The transfer fee for token B in bps
|
|
945
|
+
* - `current_sqrt_price`: The current square root price
|
|
946
|
+
* - `current_liquidity`: The current liquidity
|
|
947
|
+
* - `amount`: The amount
|
|
948
|
+
* - `specified_input`: Whether the input is specified
|
|
805
949
|
*
|
|
806
950
|
* # Returns
|
|
807
|
-
* -
|
|
951
|
+
* - `u128`: The next square root price
|
|
808
952
|
*/
|
|
809
|
-
exports.
|
|
953
|
+
exports.tryGetNextSqrtPriceFromB = function(current_sqrt_price, current_liquidity, amount, specified_input) {
|
|
810
954
|
try {
|
|
811
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-
|
|
812
|
-
wasm.
|
|
813
|
-
var r0 = getDataViewMemory0().
|
|
814
|
-
var
|
|
815
|
-
var
|
|
816
|
-
|
|
817
|
-
|
|
955
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-32);
|
|
956
|
+
wasm.tryGetNextSqrtPriceFromB(retptr, current_sqrt_price, current_sqrt_price >> BigInt(64), current_liquidity, current_liquidity >> BigInt(64), amount, specified_input);
|
|
957
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
958
|
+
var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
|
|
959
|
+
var r4 = getDataViewMemory0().getInt32(retptr + 4 * 4, true);
|
|
960
|
+
var r5 = getDataViewMemory0().getInt32(retptr + 4 * 5, true);
|
|
961
|
+
if (r5) {
|
|
962
|
+
throw takeObject(r4);
|
|
818
963
|
}
|
|
819
|
-
return
|
|
964
|
+
return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
|
|
820
965
|
} finally {
|
|
821
|
-
wasm.__wbindgen_add_to_stack_pointer(
|
|
966
|
+
wasm.__wbindgen_add_to_stack_pointer(32);
|
|
822
967
|
}
|
|
823
968
|
};
|
|
824
969
|
|
|
825
970
|
/**
|
|
826
|
-
*
|
|
971
|
+
* Apply a transfer fee to an amount
|
|
972
|
+
* e.g. You send 10000 amount with 100 fee rate. The fee amount will be 100.
|
|
973
|
+
* So the amount after fee will be 9900.
|
|
827
974
|
*
|
|
828
975
|
* # Parameters
|
|
829
|
-
* - `
|
|
830
|
-
* - `
|
|
831
|
-
* - `current_sqrt_price` - The current sqrt price of the pool
|
|
832
|
-
* - `tick_index_1` - The first tick index of the position
|
|
833
|
-
* - `tick_index_2` - The second tick index of the position
|
|
834
|
-
* - `transfer_fee_a` - The transfer fee for token A in bps
|
|
835
|
-
* - `transfer_fee_b` - The transfer fee for token B in bps
|
|
976
|
+
* - `amount`: The amount to apply the fee to
|
|
977
|
+
* - `transfer_fee`: The transfer fee to apply
|
|
836
978
|
*
|
|
837
979
|
* # Returns
|
|
838
|
-
* -
|
|
980
|
+
* - `u64`: The amount after the fee has been applied
|
|
839
981
|
*/
|
|
840
|
-
exports.
|
|
982
|
+
exports.tryApplyTransferFee = function(amount, transfer_fee) {
|
|
841
983
|
try {
|
|
842
984
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
843
|
-
wasm.
|
|
844
|
-
var r0 = getDataViewMemory0().
|
|
845
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
985
|
+
wasm.tryApplyTransferFee(retptr, amount, addHeapObject(transfer_fee));
|
|
986
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
846
987
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
847
|
-
|
|
848
|
-
|
|
988
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
989
|
+
if (r3) {
|
|
990
|
+
throw takeObject(r2);
|
|
849
991
|
}
|
|
850
|
-
return
|
|
992
|
+
return BigInt.asUintN(64, r0);
|
|
851
993
|
} finally {
|
|
852
994
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
853
995
|
}
|
|
854
996
|
};
|
|
855
997
|
|
|
856
998
|
/**
|
|
857
|
-
*
|
|
999
|
+
* Reverse the application of a transfer fee to an amount
|
|
1000
|
+
* e.g. You received 9900 amount with 100 fee rate. The fee amount will be 100.
|
|
1001
|
+
* So the amount before fee will be 10000.
|
|
858
1002
|
*
|
|
859
1003
|
* # Parameters
|
|
860
|
-
* - `
|
|
861
|
-
* - `
|
|
862
|
-
* - `current_sqrt_price` - The current sqrt price of the pool
|
|
863
|
-
* - `tick_index_1` - The first tick index of the position
|
|
864
|
-
* - `tick_index_2` - The second tick index of the position
|
|
865
|
-
* - `transfer_fee_a` - The transfer fee for token A in bps
|
|
866
|
-
* - `transfer_fee_b` - The transfer fee for token B in bps
|
|
1004
|
+
* - `amount`: The amount to reverse the fee from
|
|
1005
|
+
* - `transfer_fee`: The transfer fee to reverse
|
|
867
1006
|
*
|
|
868
1007
|
* # Returns
|
|
869
|
-
* -
|
|
1008
|
+
* - `u64`: The amount before the fee has been applied
|
|
870
1009
|
*/
|
|
871
|
-
exports.
|
|
1010
|
+
exports.tryReverseApplyTransferFee = function(amount, transfer_fee) {
|
|
872
1011
|
try {
|
|
873
1012
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
874
|
-
wasm.
|
|
875
|
-
var r0 = getDataViewMemory0().
|
|
876
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1013
|
+
wasm.tryReverseApplyTransferFee(retptr, amount, addHeapObject(transfer_fee));
|
|
1014
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
877
1015
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
878
|
-
|
|
879
|
-
|
|
1016
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1017
|
+
if (r3) {
|
|
1018
|
+
throw takeObject(r2);
|
|
880
1019
|
}
|
|
881
|
-
return
|
|
1020
|
+
return BigInt.asUintN(64, r0);
|
|
882
1021
|
} finally {
|
|
883
1022
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
884
1023
|
}
|
|
885
1024
|
};
|
|
886
1025
|
|
|
887
1026
|
/**
|
|
888
|
-
*
|
|
1027
|
+
* Get the maximum amount with a slippage tolerance
|
|
1028
|
+
* e.g. Your estimated amount you send is 10000 with 100 slippage tolerance. The max you send will be 10100.
|
|
889
1029
|
*
|
|
890
1030
|
* # Parameters
|
|
891
|
-
* - `
|
|
892
|
-
* - `
|
|
893
|
-
* - `current_sqrt_price` - The current sqrt price of the pool
|
|
894
|
-
* - `tick_index_1` - The first tick index of the position
|
|
895
|
-
* - `tick_index_2` - The second tick index of the position
|
|
896
|
-
* - `transfer_fee_a` - The transfer fee for token A in bps
|
|
897
|
-
* - `transfer_fee_b` - The transfer fee for token B in bps
|
|
1031
|
+
* - `amount`: The amount to apply the fee to
|
|
1032
|
+
* - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
|
|
898
1033
|
*
|
|
899
1034
|
* # Returns
|
|
900
|
-
* -
|
|
1035
|
+
* - `u64`: The maximum amount
|
|
901
1036
|
*/
|
|
902
|
-
exports.
|
|
1037
|
+
exports.tryGetMaxAmountWithSlippageTolerance = function(amount, slippage_tolerance_bps) {
|
|
903
1038
|
try {
|
|
904
1039
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
905
|
-
wasm.
|
|
906
|
-
var r0 = getDataViewMemory0().
|
|
907
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1040
|
+
wasm.tryGetMaxAmountWithSlippageTolerance(retptr, amount, slippage_tolerance_bps);
|
|
1041
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
908
1042
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
909
|
-
|
|
910
|
-
|
|
1043
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1044
|
+
if (r3) {
|
|
1045
|
+
throw takeObject(r2);
|
|
911
1046
|
}
|
|
912
|
-
return
|
|
1047
|
+
return BigInt.asUintN(64, r0);
|
|
913
1048
|
} finally {
|
|
914
1049
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
915
1050
|
}
|
|
916
1051
|
};
|
|
917
1052
|
|
|
918
1053
|
/**
|
|
919
|
-
*
|
|
1054
|
+
* Get the minimum amount with a slippage tolerance
|
|
1055
|
+
* e.g. Your estimated amount you receive is 10000 with 100 slippage tolerance. The min amount you receive will be 9900.
|
|
920
1056
|
*
|
|
921
1057
|
* # Parameters
|
|
922
|
-
* - `
|
|
923
|
-
* - `
|
|
924
|
-
* - `current_sqrt_price` - The current sqrt price of the pool
|
|
925
|
-
* - `tick_index_1` - The first tick index of the position
|
|
926
|
-
* - `tick_index_2` - The second tick index of the position
|
|
927
|
-
* - `transfer_fee_a` - The transfer fee for token A in bps
|
|
928
|
-
* - `transfer_fee_b` - The transfer fee for token B in bps
|
|
1058
|
+
* - `amount`: The amount to apply the fee to
|
|
1059
|
+
* - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
|
|
929
1060
|
*
|
|
930
1061
|
* # Returns
|
|
931
|
-
* -
|
|
1062
|
+
* - `u64`: The minimum amount
|
|
932
1063
|
*/
|
|
933
|
-
exports.
|
|
1064
|
+
exports.tryGetMinAmountWithSlippageTolerance = function(amount, slippage_tolerance_bps) {
|
|
934
1065
|
try {
|
|
935
1066
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
936
|
-
wasm.
|
|
937
|
-
var r0 = getDataViewMemory0().
|
|
938
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1067
|
+
wasm.tryGetMinAmountWithSlippageTolerance(retptr, amount, slippage_tolerance_bps);
|
|
1068
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
939
1069
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
940
|
-
|
|
941
|
-
|
|
1070
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1071
|
+
if (r3) {
|
|
1072
|
+
throw takeObject(r2);
|
|
942
1073
|
}
|
|
943
|
-
return
|
|
1074
|
+
return BigInt.asUintN(64, r0);
|
|
944
1075
|
} finally {
|
|
945
1076
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
946
1077
|
}
|
|
947
1078
|
};
|
|
948
1079
|
|
|
949
1080
|
/**
|
|
950
|
-
*
|
|
1081
|
+
* Apply a swap fee to an amount
|
|
1082
|
+
* e.g. You send 10000 amount with 10000 fee rate. The fee amount will be 100.
|
|
1083
|
+
* So the amount after fee will be 9900.
|
|
951
1084
|
*
|
|
952
1085
|
* # Parameters
|
|
953
|
-
* - `
|
|
954
|
-
* - `
|
|
955
|
-
* - `current_sqrt_price` - The current sqrt price of the pool
|
|
956
|
-
* - `tick_index_1` - The first tick index of the position
|
|
957
|
-
* - `tick_index_2` - The second tick index of the position
|
|
958
|
-
* - `transfer_fee_a` - The transfer fee for token A in bps
|
|
959
|
-
* - `transfer_fee_b` - The transfer fee for token B in bps
|
|
1086
|
+
* - `amount`: The amount to apply the fee to
|
|
1087
|
+
* - `fee_rate`: The fee rate to apply denominated in 1e6
|
|
960
1088
|
*
|
|
961
1089
|
* # Returns
|
|
962
|
-
* -
|
|
1090
|
+
* - `u64`: The amount after the fee has been applied
|
|
963
1091
|
*/
|
|
964
|
-
exports.
|
|
1092
|
+
exports.tryApplySwapFee = function(amount, fee_rate) {
|
|
965
1093
|
try {
|
|
966
1094
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
967
|
-
wasm.
|
|
968
|
-
var r0 = getDataViewMemory0().
|
|
969
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1095
|
+
wasm.tryApplySwapFee(retptr, amount, fee_rate);
|
|
1096
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
970
1097
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
971
|
-
|
|
972
|
-
|
|
1098
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1099
|
+
if (r3) {
|
|
1100
|
+
throw takeObject(r2);
|
|
973
1101
|
}
|
|
974
|
-
return
|
|
1102
|
+
return BigInt.asUintN(64, r0);
|
|
975
1103
|
} finally {
|
|
976
1104
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
977
1105
|
}
|
|
978
1106
|
};
|
|
979
1107
|
|
|
980
|
-
|
|
1108
|
+
/**
|
|
1109
|
+
* Reverse the application of a swap fee to an amount
|
|
1110
|
+
* e.g. You received 9900 amount with 10000 fee rate. The fee amount will be 100.
|
|
1111
|
+
* So the amount before fee will be 10000.
|
|
1112
|
+
*
|
|
1113
|
+
* # Parameters
|
|
1114
|
+
* - `amount`: The amount to reverse the fee from
|
|
1115
|
+
* - `fee_rate`: The fee rate to reverse denominated in 1e6
|
|
1116
|
+
*
|
|
1117
|
+
* # Returns
|
|
1118
|
+
* - `u64`: The amount before the fee has been applied
|
|
1119
|
+
*/
|
|
1120
|
+
exports.tryReverseApplySwapFee = function(amount, fee_rate) {
|
|
981
1121
|
try {
|
|
982
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-
|
|
983
|
-
wasm.
|
|
1122
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1123
|
+
wasm.tryReverseApplySwapFee(retptr, amount, fee_rate);
|
|
984
1124
|
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
985
|
-
var r2 = getDataViewMemory0().
|
|
986
|
-
var
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
throw takeObject(r4);
|
|
1125
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1126
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1127
|
+
if (r3) {
|
|
1128
|
+
throw takeObject(r2);
|
|
990
1129
|
}
|
|
991
|
-
return
|
|
1130
|
+
return BigInt.asUintN(64, r0);
|
|
992
1131
|
} finally {
|
|
993
|
-
wasm.__wbindgen_add_to_stack_pointer(
|
|
1132
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
994
1133
|
}
|
|
995
1134
|
};
|
|
996
1135
|
|
|
997
|
-
|
|
1136
|
+
/**
|
|
1137
|
+
* Computes the limit order output amount by input amount.
|
|
1138
|
+
* ### Parameters
|
|
1139
|
+
* - `amount_in` - The input token amount of a limit order.
|
|
1140
|
+
* - `a_to_b_order` - The limit order direction.
|
|
1141
|
+
* - `tick_index` - The tick index of an order.
|
|
1142
|
+
* - `fusion_pool` - The fusion_pool state.
|
|
1143
|
+
*/
|
|
1144
|
+
exports.limitOrderQuoteByInputToken = function(amount_in, a_to_b_order, tick_index, fusion_pool) {
|
|
998
1145
|
try {
|
|
999
1146
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1000
|
-
wasm.
|
|
1147
|
+
wasm.limitOrderQuoteByInputToken(retptr, amount_in, a_to_b_order, tick_index, addHeapObject(fusion_pool));
|
|
1001
1148
|
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
1002
1149
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1003
1150
|
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
@@ -1010,27 +1157,42 @@ exports.tryGetTokenAFromLiquidity = function(liquidity_delta, sqrt_price_lower,
|
|
|
1010
1157
|
}
|
|
1011
1158
|
};
|
|
1012
1159
|
|
|
1013
|
-
|
|
1160
|
+
/**
|
|
1161
|
+
* Computes the limit order input amount by output amount.
|
|
1162
|
+
* ### Parameters
|
|
1163
|
+
* - `amount_out` - The output token amount of a limit order.
|
|
1164
|
+
* - `a_to_b_order` - The limit order direction.
|
|
1165
|
+
* - `tick_index` - The tick index of an order.
|
|
1166
|
+
* - `fusion_pool` - The fusion_pool state.
|
|
1167
|
+
*/
|
|
1168
|
+
exports.limitOrderQuoteByOutputToken = function(amount_out, a_to_b_order, tick_index, fusion_pool) {
|
|
1014
1169
|
try {
|
|
1015
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-
|
|
1016
|
-
wasm.
|
|
1170
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1171
|
+
wasm.limitOrderQuoteByOutputToken(retptr, amount_out, a_to_b_order, tick_index, addHeapObject(fusion_pool));
|
|
1017
1172
|
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
1018
|
-
var r2 = getDataViewMemory0().
|
|
1019
|
-
var
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
throw takeObject(r4);
|
|
1173
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1174
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1175
|
+
if (r3) {
|
|
1176
|
+
throw takeObject(r2);
|
|
1023
1177
|
}
|
|
1024
|
-
return
|
|
1178
|
+
return BigInt.asUintN(64, r0);
|
|
1025
1179
|
} finally {
|
|
1026
|
-
wasm.__wbindgen_add_to_stack_pointer(
|
|
1180
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1027
1181
|
}
|
|
1028
1182
|
};
|
|
1029
1183
|
|
|
1030
|
-
|
|
1184
|
+
/**
|
|
1185
|
+
* Computes the limit order reward by input amount.
|
|
1186
|
+
* ### Parameters
|
|
1187
|
+
* - `amount_out` - The output token amount of a limit order (swap input).
|
|
1188
|
+
* - `a_to_b_order` - The limit order direction.
|
|
1189
|
+
* - `tick_index` - The tick index of an order.
|
|
1190
|
+
* - `fusion_pool` - The fusion_pool state.
|
|
1191
|
+
*/
|
|
1192
|
+
exports.limitOrderRewardByOutputToken = function(amount_out, fee_rate, protocol_fee_rate) {
|
|
1031
1193
|
try {
|
|
1032
1194
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1033
|
-
wasm.
|
|
1195
|
+
wasm.limitOrderRewardByOutputToken(retptr, amount_out, fee_rate, protocol_fee_rate);
|
|
1034
1196
|
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
1035
1197
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1036
1198
|
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
@@ -1043,10 +1205,10 @@ exports.tryGetTokenBFromLiquidity = function(liquidity_delta, sqrt_price_lower,
|
|
|
1043
1205
|
}
|
|
1044
1206
|
};
|
|
1045
1207
|
|
|
1046
|
-
exports.
|
|
1208
|
+
exports.decreaseLimitOrderQuote = function(fusion_pool, limit_order, tick, amount, transfer_fee_a, transfer_fee_b) {
|
|
1047
1209
|
try {
|
|
1048
1210
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1049
|
-
wasm.
|
|
1211
|
+
wasm.decreaseLimitOrderQuote(retptr, addHeapObject(fusion_pool), addHeapObject(limit_order), addHeapObject(tick), amount, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
|
|
1050
1212
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1051
1213
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1052
1214
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
@@ -1060,131 +1222,202 @@ exports.tryGetTokenEstimatesFromLiquidity = function(liquidity_delta, current_sq
|
|
|
1060
1222
|
};
|
|
1061
1223
|
|
|
1062
1224
|
/**
|
|
1063
|
-
*
|
|
1225
|
+
* Get the first unoccupied position in a bundle
|
|
1064
1226
|
*
|
|
1065
|
-
* #
|
|
1066
|
-
*
|
|
1067
|
-
* - `position`: The position state
|
|
1068
|
-
* - `tick_lower`: The lower tick state
|
|
1069
|
-
* - `tick_upper`: The upper tick state
|
|
1070
|
-
* - `transfer_fee_a`: The transfer fee for token A
|
|
1071
|
-
* - `transfer_fee_b`: The transfer fee for token B
|
|
1227
|
+
* # Arguments
|
|
1228
|
+
* * `bundle` - The bundle to check
|
|
1072
1229
|
*
|
|
1073
1230
|
* # Returns
|
|
1074
|
-
*
|
|
1231
|
+
* * `u32` - The first unoccupied position (None if full)
|
|
1075
1232
|
*/
|
|
1076
|
-
exports.
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1082
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1083
|
-
if (r2) {
|
|
1084
|
-
throw takeObject(r1);
|
|
1085
|
-
}
|
|
1086
|
-
return takeObject(r0);
|
|
1087
|
-
} finally {
|
|
1088
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1089
|
-
}
|
|
1233
|
+
exports.firstUnoccupiedPositionInBundle = function(bitmap) {
|
|
1234
|
+
const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
|
|
1235
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1236
|
+
const ret = wasm.firstUnoccupiedPositionInBundle(ptr0, len0);
|
|
1237
|
+
return ret === 0x100000001 ? undefined : ret;
|
|
1090
1238
|
};
|
|
1091
1239
|
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1240
|
+
/**
|
|
1241
|
+
* Check whether a position bundle is full
|
|
1242
|
+
* A position bundle can contain 256 positions
|
|
1243
|
+
*
|
|
1244
|
+
* # Arguments
|
|
1245
|
+
* * `bundle` - The bundle to check
|
|
1246
|
+
*
|
|
1247
|
+
* # Returns
|
|
1248
|
+
* * `bool` - Whether the bundle is full
|
|
1249
|
+
*/
|
|
1250
|
+
exports.isPositionBundleFull = function(bitmap) {
|
|
1251
|
+
const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
|
|
1252
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1253
|
+
const ret = wasm.isPositionBundleFull(ptr0, len0);
|
|
1254
|
+
return ret !== 0;
|
|
1095
1255
|
};
|
|
1096
1256
|
|
|
1097
1257
|
/**
|
|
1098
|
-
*
|
|
1099
|
-
*
|
|
1100
|
-
*
|
|
1101
|
-
*
|
|
1102
|
-
*
|
|
1103
|
-
*
|
|
1258
|
+
* Check whether a position bundle is empty
|
|
1259
|
+
*
|
|
1260
|
+
* # Arguments
|
|
1261
|
+
* * `bundle` - The bundle to check
|
|
1262
|
+
*
|
|
1263
|
+
* # Returns
|
|
1264
|
+
* * `bool` - Whether the bundle is empty
|
|
1104
1265
|
*/
|
|
1105
|
-
exports.
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1111
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1112
|
-
if (r3) {
|
|
1113
|
-
throw takeObject(r2);
|
|
1114
|
-
}
|
|
1115
|
-
return BigInt.asUintN(64, r0);
|
|
1116
|
-
} finally {
|
|
1117
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1118
|
-
}
|
|
1266
|
+
exports.isPositionBundleEmpty = function(bitmap) {
|
|
1267
|
+
const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
|
|
1268
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1269
|
+
const ret = wasm.isPositionBundleEmpty(ptr0, len0);
|
|
1270
|
+
return ret !== 0;
|
|
1119
1271
|
};
|
|
1120
1272
|
|
|
1121
1273
|
/**
|
|
1122
|
-
*
|
|
1123
|
-
*
|
|
1124
|
-
*
|
|
1125
|
-
*
|
|
1126
|
-
* - `
|
|
1127
|
-
* - `
|
|
1274
|
+
* Check if a position is in range.
|
|
1275
|
+
* When a position is in range it is earning fees and rewards
|
|
1276
|
+
*
|
|
1277
|
+
* # Parameters
|
|
1278
|
+
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
1279
|
+
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
1280
|
+
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
1281
|
+
*
|
|
1282
|
+
* # Returns
|
|
1283
|
+
* - A boolean value indicating if the position is in range
|
|
1128
1284
|
*/
|
|
1129
|
-
exports.
|
|
1285
|
+
exports.isPositionInRange = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
1286
|
+
const ret = wasm.isPositionInRange(current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2);
|
|
1287
|
+
return ret !== 0;
|
|
1288
|
+
};
|
|
1289
|
+
|
|
1290
|
+
/**
|
|
1291
|
+
* Calculate the status of a position
|
|
1292
|
+
* The status can be one of three values:
|
|
1293
|
+
* - InRange: The position is in range
|
|
1294
|
+
* - BelowRange: The position is below the range
|
|
1295
|
+
* - AboveRange: The position is above the range
|
|
1296
|
+
*
|
|
1297
|
+
* # Parameters
|
|
1298
|
+
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
1299
|
+
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
1300
|
+
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
1301
|
+
*
|
|
1302
|
+
* # Returns
|
|
1303
|
+
* - A PositionStatus enum value indicating the status of the position
|
|
1304
|
+
*/
|
|
1305
|
+
exports.positionStatus = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
1306
|
+
const ret = wasm.positionStatus(current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2);
|
|
1307
|
+
return takeObject(ret);
|
|
1308
|
+
};
|
|
1309
|
+
|
|
1310
|
+
/**
|
|
1311
|
+
* Calculate the token_a / token_b ratio of a (ficticious) position
|
|
1312
|
+
*
|
|
1313
|
+
* # Parameters
|
|
1314
|
+
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
1315
|
+
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
1316
|
+
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
1317
|
+
*
|
|
1318
|
+
* # Returns
|
|
1319
|
+
* - A PositionRatio struct containing the ratio of token_a and token_b
|
|
1320
|
+
*/
|
|
1321
|
+
exports.positionRatioX64 = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
1322
|
+
const ret = wasm.positionRatioX64(current_sqrt_price, current_sqrt_price >> BigInt(64), tick_index_1, tick_index_2);
|
|
1323
|
+
return takeObject(ret);
|
|
1324
|
+
};
|
|
1325
|
+
|
|
1326
|
+
/**
|
|
1327
|
+
* Convert a price into a sqrt priceX64
|
|
1328
|
+
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
1329
|
+
* Make sure to do these operations last and not to use the result for further calculations.
|
|
1330
|
+
*
|
|
1331
|
+
* # Parameters
|
|
1332
|
+
* * `price` - The price to convert
|
|
1333
|
+
* * `decimals_a` - The number of decimals of the base token
|
|
1334
|
+
* * `decimals_b` - The number of decimals of the quote token
|
|
1335
|
+
*
|
|
1336
|
+
* # Returns
|
|
1337
|
+
* * `u128` - The sqrt priceX64
|
|
1338
|
+
*/
|
|
1339
|
+
exports.priceToSqrtPrice = function(price, decimals_a, decimals_b) {
|
|
1130
1340
|
try {
|
|
1131
1341
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1132
|
-
wasm.
|
|
1342
|
+
wasm.priceToSqrtPrice(retptr, price, decimals_a, decimals_b);
|
|
1133
1343
|
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
1134
|
-
var r2 = getDataViewMemory0().
|
|
1135
|
-
|
|
1136
|
-
if (r3) {
|
|
1137
|
-
throw takeObject(r2);
|
|
1138
|
-
}
|
|
1139
|
-
return BigInt.asUintN(64, r0);
|
|
1344
|
+
var r2 = getDataViewMemory0().getBigInt64(retptr + 8 * 1, true);
|
|
1345
|
+
return (BigInt.asUintN(64, r0) | (BigInt.asUintN(64, r2) << BigInt(64)));
|
|
1140
1346
|
} finally {
|
|
1141
1347
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1142
1348
|
}
|
|
1143
1349
|
};
|
|
1144
1350
|
|
|
1145
1351
|
/**
|
|
1146
|
-
*
|
|
1147
|
-
*
|
|
1148
|
-
*
|
|
1149
|
-
*
|
|
1150
|
-
*
|
|
1151
|
-
*
|
|
1352
|
+
* Convert a sqrt priceX64 into a tick index
|
|
1353
|
+
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
1354
|
+
* Make sure to do these operations last and not to use the result for further calculations.
|
|
1355
|
+
*
|
|
1356
|
+
* # Parameters
|
|
1357
|
+
* * `sqrt_price` - The sqrt priceX64 to convert
|
|
1358
|
+
* * `decimals_a` - The number of decimals of the base token
|
|
1359
|
+
* * `decimals_b` - The number of decimals of the quote token
|
|
1360
|
+
*
|
|
1361
|
+
* # Returns
|
|
1362
|
+
* * `f64` - The decimal price
|
|
1363
|
+
*/
|
|
1364
|
+
exports.sqrtPriceToPrice = function(sqrt_price, decimals_a, decimals_b) {
|
|
1365
|
+
const ret = wasm.sqrtPriceToPrice(sqrt_price, sqrt_price >> BigInt(64), decimals_a, decimals_b);
|
|
1366
|
+
return ret;
|
|
1367
|
+
};
|
|
1368
|
+
|
|
1369
|
+
/**
|
|
1370
|
+
* Invert a price
|
|
1371
|
+
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
1372
|
+
* Make sure to do these operations last and not to use the result for further calculations.
|
|
1373
|
+
*
|
|
1374
|
+
* # Parameters
|
|
1375
|
+
* * `price` - The price to invert
|
|
1376
|
+
* * `decimals_a` - The number of decimals of the base token
|
|
1377
|
+
* * `decimals_b` - The number of decimals of the quote token
|
|
1378
|
+
*
|
|
1379
|
+
* # Returns
|
|
1380
|
+
* * `f64` - The inverted price
|
|
1381
|
+
*/
|
|
1382
|
+
exports.invertPrice = function(price, decimals_a, decimals_b) {
|
|
1383
|
+
const ret = wasm.invertPrice(price, decimals_a, decimals_b);
|
|
1384
|
+
return ret;
|
|
1385
|
+
};
|
|
1386
|
+
|
|
1387
|
+
/**
|
|
1388
|
+
* Convert a tick index into a price
|
|
1389
|
+
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
1390
|
+
* Make sure to do these operations last and not to use the result for further calculations.
|
|
1391
|
+
*
|
|
1392
|
+
* # Parameters
|
|
1393
|
+
* * `tick_index` - The tick index to convert
|
|
1394
|
+
* * `decimals_a` - The number of decimals of the base token
|
|
1395
|
+
* * `decimals_b` - The number of decimals of the quote token
|
|
1396
|
+
*
|
|
1397
|
+
* # Returns
|
|
1398
|
+
* * `f64` - The decimal price
|
|
1152
1399
|
*/
|
|
1153
|
-
exports.
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
wasm.limitOrderRewardByOutputToken(retptr, amount_out, fee_rate, protocol_fee_rate);
|
|
1157
|
-
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
1158
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1159
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1160
|
-
if (r3) {
|
|
1161
|
-
throw takeObject(r2);
|
|
1162
|
-
}
|
|
1163
|
-
return BigInt.asUintN(64, r0);
|
|
1164
|
-
} finally {
|
|
1165
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1166
|
-
}
|
|
1167
|
-
};
|
|
1168
|
-
|
|
1169
|
-
exports.decreaseLimitOrderQuote = function(fusion_pool, limit_order, tick, amount, transfer_fee_a, transfer_fee_b) {
|
|
1170
|
-
try {
|
|
1171
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1172
|
-
wasm.decreaseLimitOrderQuote(retptr, addHeapObject(fusion_pool), addHeapObject(limit_order), addHeapObject(tick), amount, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
|
|
1173
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1174
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1175
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1176
|
-
if (r2) {
|
|
1177
|
-
throw takeObject(r1);
|
|
1178
|
-
}
|
|
1179
|
-
return takeObject(r0);
|
|
1180
|
-
} finally {
|
|
1181
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1182
|
-
}
|
|
1400
|
+
exports.tickIndexToPrice = function(tick_index, decimals_a, decimals_b) {
|
|
1401
|
+
const ret = wasm.tickIndexToPrice(tick_index, decimals_a, decimals_b);
|
|
1402
|
+
return ret;
|
|
1183
1403
|
};
|
|
1184
1404
|
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1405
|
+
/**
|
|
1406
|
+
* Convert a price into a tick index
|
|
1407
|
+
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
1408
|
+
* Make sure to do these operations last and not to use the result for further calculations.
|
|
1409
|
+
*
|
|
1410
|
+
* # Parameters
|
|
1411
|
+
* * `price` - The price to convert
|
|
1412
|
+
* * `decimals_a` - The number of decimals of the base token
|
|
1413
|
+
* * `decimals_b` - The number of decimals of the quote token
|
|
1414
|
+
*
|
|
1415
|
+
* # Returns
|
|
1416
|
+
* * `i32` - The tick index
|
|
1417
|
+
*/
|
|
1418
|
+
exports.priceToTickIndex = function(price, decimals_a, decimals_b) {
|
|
1419
|
+
const ret = wasm.priceToTickIndex(price, decimals_a, decimals_b);
|
|
1420
|
+
return ret;
|
|
1188
1421
|
};
|
|
1189
1422
|
|
|
1190
1423
|
exports._TICK_ARRAY_NOT_EVENLY_SPACED = function() {
|
|
@@ -1391,198 +1624,6 @@ exports._LIMIT_ORDER_AND_POOL_ARE_OUT_OF_SYNC = function() {
|
|
|
1391
1624
|
}
|
|
1392
1625
|
};
|
|
1393
1626
|
|
|
1394
|
-
/**
|
|
1395
|
-
* Get the first unoccupied position in a bundle
|
|
1396
|
-
*
|
|
1397
|
-
* # Arguments
|
|
1398
|
-
* * `bundle` - The bundle to check
|
|
1399
|
-
*
|
|
1400
|
-
* # Returns
|
|
1401
|
-
* * `u32` - The first unoccupied position (None if full)
|
|
1402
|
-
*/
|
|
1403
|
-
exports.firstUnoccupiedPositionInBundle = function(bitmap) {
|
|
1404
|
-
const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
|
|
1405
|
-
const len0 = WASM_VECTOR_LEN;
|
|
1406
|
-
const ret = wasm.firstUnoccupiedPositionInBundle(ptr0, len0);
|
|
1407
|
-
return ret === 0x100000001 ? undefined : ret;
|
|
1408
|
-
};
|
|
1409
|
-
|
|
1410
|
-
/**
|
|
1411
|
-
* Check whether a position bundle is full
|
|
1412
|
-
* A position bundle can contain 256 positions
|
|
1413
|
-
*
|
|
1414
|
-
* # Arguments
|
|
1415
|
-
* * `bundle` - The bundle to check
|
|
1416
|
-
*
|
|
1417
|
-
* # Returns
|
|
1418
|
-
* * `bool` - Whether the bundle is full
|
|
1419
|
-
*/
|
|
1420
|
-
exports.isPositionBundleFull = function(bitmap) {
|
|
1421
|
-
const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
|
|
1422
|
-
const len0 = WASM_VECTOR_LEN;
|
|
1423
|
-
const ret = wasm.isPositionBundleFull(ptr0, len0);
|
|
1424
|
-
return ret !== 0;
|
|
1425
|
-
};
|
|
1426
|
-
|
|
1427
|
-
/**
|
|
1428
|
-
* Check whether a position bundle is empty
|
|
1429
|
-
*
|
|
1430
|
-
* # Arguments
|
|
1431
|
-
* * `bundle` - The bundle to check
|
|
1432
|
-
*
|
|
1433
|
-
* # Returns
|
|
1434
|
-
* * `bool` - Whether the bundle is empty
|
|
1435
|
-
*/
|
|
1436
|
-
exports.isPositionBundleEmpty = function(bitmap) {
|
|
1437
|
-
const ptr0 = passArray8ToWasm0(bitmap, wasm.__wbindgen_export);
|
|
1438
|
-
const len0 = WASM_VECTOR_LEN;
|
|
1439
|
-
const ret = wasm.isPositionBundleEmpty(ptr0, len0);
|
|
1440
|
-
return ret !== 0;
|
|
1441
|
-
};
|
|
1442
|
-
|
|
1443
|
-
/**
|
|
1444
|
-
* Check if a position is in range.
|
|
1445
|
-
* When a position is in range it is earning fees and rewards
|
|
1446
|
-
*
|
|
1447
|
-
* # Parameters
|
|
1448
|
-
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
1449
|
-
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
1450
|
-
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
1451
|
-
*
|
|
1452
|
-
* # Returns
|
|
1453
|
-
* - A boolean value indicating if the position is in range
|
|
1454
|
-
*/
|
|
1455
|
-
exports.isPositionInRange = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
1456
|
-
const ret = wasm.isPositionInRange(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
|
|
1457
|
-
return ret !== 0;
|
|
1458
|
-
};
|
|
1459
|
-
|
|
1460
|
-
/**
|
|
1461
|
-
* Calculate the status of a position
|
|
1462
|
-
* The status can be one of three values:
|
|
1463
|
-
* - InRange: The position is in range
|
|
1464
|
-
* - BelowRange: The position is below the range
|
|
1465
|
-
* - AboveRange: The position is above the range
|
|
1466
|
-
*
|
|
1467
|
-
* # Parameters
|
|
1468
|
-
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
1469
|
-
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
1470
|
-
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
1471
|
-
*
|
|
1472
|
-
* # Returns
|
|
1473
|
-
* - A PositionStatus enum value indicating the status of the position
|
|
1474
|
-
*/
|
|
1475
|
-
exports.positionStatus = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
1476
|
-
const ret = wasm.positionStatus(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
|
|
1477
|
-
return takeObject(ret);
|
|
1478
|
-
};
|
|
1479
|
-
|
|
1480
|
-
/**
|
|
1481
|
-
* Calculate the token_a / token_b ratio of a (ficticious) position
|
|
1482
|
-
*
|
|
1483
|
-
* # Parameters
|
|
1484
|
-
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
1485
|
-
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
1486
|
-
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
1487
|
-
*
|
|
1488
|
-
* # Returns
|
|
1489
|
-
* - A PositionRatio struct containing the ratio of token_a and token_b
|
|
1490
|
-
*/
|
|
1491
|
-
exports.positionRatioX64 = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
1492
|
-
const ret = wasm.positionRatioX64(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
|
|
1493
|
-
return takeObject(ret);
|
|
1494
|
-
};
|
|
1495
|
-
|
|
1496
|
-
/**
|
|
1497
|
-
* Convert a price into a sqrt priceX64
|
|
1498
|
-
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
1499
|
-
* Make sure to do these operations last and not to use the result for further calculations.
|
|
1500
|
-
*
|
|
1501
|
-
* # Parameters
|
|
1502
|
-
* * `price` - The price to convert
|
|
1503
|
-
* * `decimals_a` - The number of decimals of the base token
|
|
1504
|
-
* * `decimals_b` - The number of decimals of the quote token
|
|
1505
|
-
*
|
|
1506
|
-
* # Returns
|
|
1507
|
-
* * `u128` - The sqrt priceX64
|
|
1508
|
-
*/
|
|
1509
|
-
exports.priceToSqrtPrice = function(price, decimals_a, decimals_b) {
|
|
1510
|
-
const ret = wasm.priceToSqrtPrice(price, decimals_a, decimals_b);
|
|
1511
|
-
return takeObject(ret);
|
|
1512
|
-
};
|
|
1513
|
-
|
|
1514
|
-
/**
|
|
1515
|
-
* Convert a sqrt priceX64 into a tick index
|
|
1516
|
-
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
1517
|
-
* Make sure to do these operations last and not to use the result for further calculations.
|
|
1518
|
-
*
|
|
1519
|
-
* # Parameters
|
|
1520
|
-
* * `sqrt_price` - The sqrt priceX64 to convert
|
|
1521
|
-
* * `decimals_a` - The number of decimals of the base token
|
|
1522
|
-
* * `decimals_b` - The number of decimals of the quote token
|
|
1523
|
-
*
|
|
1524
|
-
* # Returns
|
|
1525
|
-
* * `f64` - The decimal price
|
|
1526
|
-
*/
|
|
1527
|
-
exports.sqrtPriceToPrice = function(sqrt_price, decimals_a, decimals_b) {
|
|
1528
|
-
const ret = wasm.sqrtPriceToPrice(addHeapObject(sqrt_price), decimals_a, decimals_b);
|
|
1529
|
-
return ret;
|
|
1530
|
-
};
|
|
1531
|
-
|
|
1532
|
-
/**
|
|
1533
|
-
* Invert a price
|
|
1534
|
-
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
1535
|
-
* Make sure to do these operations last and not to use the result for further calculations.
|
|
1536
|
-
*
|
|
1537
|
-
* # Parameters
|
|
1538
|
-
* * `price` - The price to invert
|
|
1539
|
-
* * `decimals_a` - The number of decimals of the base token
|
|
1540
|
-
* * `decimals_b` - The number of decimals of the quote token
|
|
1541
|
-
*
|
|
1542
|
-
* # Returns
|
|
1543
|
-
* * `f64` - The inverted price
|
|
1544
|
-
*/
|
|
1545
|
-
exports.invertPrice = function(price, decimals_a, decimals_b) {
|
|
1546
|
-
const ret = wasm.invertPrice(price, decimals_a, decimals_b);
|
|
1547
|
-
return ret;
|
|
1548
|
-
};
|
|
1549
|
-
|
|
1550
|
-
/**
|
|
1551
|
-
* Convert a tick index into a price
|
|
1552
|
-
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
1553
|
-
* Make sure to do these operations last and not to use the result for further calculations.
|
|
1554
|
-
*
|
|
1555
|
-
* # Parameters
|
|
1556
|
-
* * `tick_index` - The tick index to convert
|
|
1557
|
-
* * `decimals_a` - The number of decimals of the base token
|
|
1558
|
-
* * `decimals_b` - The number of decimals of the quote token
|
|
1559
|
-
*
|
|
1560
|
-
* # Returns
|
|
1561
|
-
* * `f64` - The decimal price
|
|
1562
|
-
*/
|
|
1563
|
-
exports.tickIndexToPrice = function(tick_index, decimals_a, decimals_b) {
|
|
1564
|
-
const ret = wasm.tickIndexToPrice(tick_index, decimals_a, decimals_b);
|
|
1565
|
-
return ret;
|
|
1566
|
-
};
|
|
1567
|
-
|
|
1568
|
-
/**
|
|
1569
|
-
* Convert a price into a tick index
|
|
1570
|
-
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
1571
|
-
* Make sure to do these operations last and not to use the result for further calculations.
|
|
1572
|
-
*
|
|
1573
|
-
* # Parameters
|
|
1574
|
-
* * `price` - The price to convert
|
|
1575
|
-
* * `decimals_a` - The number of decimals of the base token
|
|
1576
|
-
* * `decimals_b` - The number of decimals of the quote token
|
|
1577
|
-
*
|
|
1578
|
-
* # Returns
|
|
1579
|
-
* * `i32` - The tick index
|
|
1580
|
-
*/
|
|
1581
|
-
exports.priceToTickIndex = function(price, decimals_a, decimals_b) {
|
|
1582
|
-
const ret = wasm.priceToTickIndex(price, decimals_a, decimals_b);
|
|
1583
|
-
return ret;
|
|
1584
|
-
};
|
|
1585
|
-
|
|
1586
1627
|
/**
|
|
1587
1628
|
* Computes the exact input or output amount for a swap transaction.
|
|
1588
1629
|
*
|
|
@@ -1664,7 +1705,7 @@ exports.swapQuoteByOutputToken = function(token_out, specified_token_a, slippage
|
|
|
1664
1705
|
exports.getLpPositionLiquidationPrices = function(tick_lower_index, tick_upper_index, liquidity, leftovers_a, leftovers_b, debt_a, debt_b, liquidation_threshold) {
|
|
1665
1706
|
try {
|
|
1666
1707
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1667
|
-
wasm.getLpPositionLiquidationPrices(retptr, tick_lower_index, tick_upper_index,
|
|
1708
|
+
wasm.getLpPositionLiquidationPrices(retptr, tick_lower_index, tick_upper_index, liquidity, liquidity >> BigInt(64), leftovers_a, leftovers_b, debt_a, debt_b, liquidation_threshold);
|
|
1668
1709
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1669
1710
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1670
1711
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
@@ -1871,12 +1912,12 @@ exports.solana_program_init = function() {
|
|
|
1871
1912
|
wasm.solana_program_init();
|
|
1872
1913
|
};
|
|
1873
1914
|
|
|
1874
|
-
function
|
|
1875
|
-
wasm.
|
|
1915
|
+
function __wasm_bindgen_func_elem_2634(arg0, arg1, arg2) {
|
|
1916
|
+
wasm.__wasm_bindgen_func_elem_2634(arg0, arg1, addHeapObject(arg2));
|
|
1876
1917
|
}
|
|
1877
1918
|
|
|
1878
|
-
function
|
|
1879
|
-
wasm.
|
|
1919
|
+
function __wasm_bindgen_func_elem_3207(arg0, arg1) {
|
|
1920
|
+
wasm.__wasm_bindgen_func_elem_3207(arg0, arg1);
|
|
1880
1921
|
}
|
|
1881
1922
|
|
|
1882
1923
|
function __wasm_bindgen_func_elem_495(arg0, arg1, arg2, arg3) {
|
|
@@ -3305,7 +3346,7 @@ exports.__wbg_warn_1d74dddbe2fd1dbb = function(arg0) {
|
|
|
3305
3346
|
|
|
3306
3347
|
exports.__wbindgen_cast_0660a350899916ec = function(arg0, arg1) {
|
|
3307
3348
|
// Cast intrinsic for `Closure(Closure { dtor_idx: 360, function: Function { arguments: [], shim_idx: 361, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
3308
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
3349
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_3203, __wasm_bindgen_func_elem_3207);
|
|
3309
3350
|
return addHeapObject(ret);
|
|
3310
3351
|
};
|
|
3311
3352
|
|
|
@@ -3317,7 +3358,7 @@ exports.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
|
3317
3358
|
|
|
3318
3359
|
exports.__wbindgen_cast_2e5f7f1574aa20c6 = function(arg0, arg1) {
|
|
3319
3360
|
// Cast intrinsic for `Closure(Closure { dtor_idx: 232, function: Function { arguments: [Externref], shim_idx: 227, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
3320
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
3361
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_2653, __wasm_bindgen_func_elem_2634);
|
|
3321
3362
|
return addHeapObject(ret);
|
|
3322
3363
|
};
|
|
3323
3364
|
|