@orca-so/whirlpools-core 1.0.4 → 3.0.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 +275 -219
- package/dist/browser/orca_whirlpools_core_js_bindings_bg.js +456 -388
- package/dist/browser/orca_whirlpools_core_js_bindings_bg.wasm +0 -0
- package/dist/browser/orca_whirlpools_core_js_bindings_bg.wasm.d.ts +32 -24
- package/dist/browser/package.json +1 -1
- package/dist/nodejs/orca_whirlpools_core_js_bindings.d.ts +275 -219
- package/dist/nodejs/orca_whirlpools_core_js_bindings.js +456 -388
- package/dist/nodejs/orca_whirlpools_core_js_bindings_bg.wasm +0 -0
- package/dist/nodejs/orca_whirlpools_core_js_bindings_bg.wasm.d.ts +32 -24
- package/dist/nodejs/package.json +1 -1
- package/package.json +4 -2
|
@@ -192,6 +192,316 @@ function getStringFromWasm0(ptr, len) {
|
|
|
192
192
|
ptr = ptr >>> 0;
|
|
193
193
|
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
194
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Calculate the amount A delta between two sqrt_prices
|
|
197
|
+
*
|
|
198
|
+
* # Parameters
|
|
199
|
+
* - `sqrt_price_1`: The first square root price
|
|
200
|
+
* - `sqrt_price_2`: The second square root price
|
|
201
|
+
* - `liquidity`: The liquidity
|
|
202
|
+
* - `round_up`: Whether to round up or not
|
|
203
|
+
*
|
|
204
|
+
* # Returns
|
|
205
|
+
* - `u64`: The amount delta
|
|
206
|
+
*/
|
|
207
|
+
module.exports.tryGetAmountDeltaA = function(sqrt_price_1, sqrt_price_2, liquidity, round_up) {
|
|
208
|
+
try {
|
|
209
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
210
|
+
wasm.tryGetAmountDeltaA(retptr, addHeapObject(sqrt_price_1), addHeapObject(sqrt_price_2), addHeapObject(liquidity), round_up);
|
|
211
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
212
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
213
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
214
|
+
if (r3) {
|
|
215
|
+
throw takeObject(r2);
|
|
216
|
+
}
|
|
217
|
+
return BigInt.asUintN(64, r0);
|
|
218
|
+
} finally {
|
|
219
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Calculate the amount B delta between two sqrt_prices
|
|
225
|
+
*
|
|
226
|
+
* # Parameters
|
|
227
|
+
* - `sqrt_price_1`: The first square root price
|
|
228
|
+
* - `sqrt_price_2`: The second square root price
|
|
229
|
+
* - `liquidity`: The liquidity
|
|
230
|
+
* - `round_up`: Whether to round up or not
|
|
231
|
+
*
|
|
232
|
+
* # Returns
|
|
233
|
+
* - `u64`: The amount delta
|
|
234
|
+
*/
|
|
235
|
+
module.exports.tryGetAmountDeltaB = function(sqrt_price_1, sqrt_price_2, liquidity, round_up) {
|
|
236
|
+
try {
|
|
237
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
238
|
+
wasm.tryGetAmountDeltaB(retptr, addHeapObject(sqrt_price_1), addHeapObject(sqrt_price_2), addHeapObject(liquidity), round_up);
|
|
239
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
240
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
241
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
242
|
+
if (r3) {
|
|
243
|
+
throw takeObject(r2);
|
|
244
|
+
}
|
|
245
|
+
return BigInt.asUintN(64, r0);
|
|
246
|
+
} finally {
|
|
247
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Calculate the next square root price
|
|
253
|
+
*
|
|
254
|
+
* # Parameters
|
|
255
|
+
* - `current_sqrt_price`: The current square root price
|
|
256
|
+
* - `current_liquidity`: The current liquidity
|
|
257
|
+
* - `amount`: The amount
|
|
258
|
+
* - `specified_input`: Whether the input is specified
|
|
259
|
+
*
|
|
260
|
+
* # Returns
|
|
261
|
+
* - `u128`: The next square root price
|
|
262
|
+
*/
|
|
263
|
+
module.exports.tryGetNextSqrtPriceFromA = function(current_sqrt_price, current_liquidity, amount, specified_input) {
|
|
264
|
+
try {
|
|
265
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
266
|
+
wasm.tryGetNextSqrtPriceFromA(retptr, addHeapObject(current_sqrt_price), addHeapObject(current_liquidity), amount, specified_input);
|
|
267
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
268
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
269
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
270
|
+
if (r2) {
|
|
271
|
+
throw takeObject(r1);
|
|
272
|
+
}
|
|
273
|
+
return takeObject(r0);
|
|
274
|
+
} finally {
|
|
275
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Calculate the next square root price
|
|
281
|
+
*
|
|
282
|
+
* # Parameters
|
|
283
|
+
* - `current_sqrt_price`: The current square root price
|
|
284
|
+
* - `current_liquidity`: The current liquidity
|
|
285
|
+
* - `amount`: The amount
|
|
286
|
+
* - `specified_input`: Whether the input is specified
|
|
287
|
+
*
|
|
288
|
+
* # Returns
|
|
289
|
+
* - `u128`: The next square root price
|
|
290
|
+
*/
|
|
291
|
+
module.exports.tryGetNextSqrtPriceFromB = function(current_sqrt_price, current_liquidity, amount, specified_input) {
|
|
292
|
+
try {
|
|
293
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
294
|
+
wasm.tryGetNextSqrtPriceFromB(retptr, addHeapObject(current_sqrt_price), addHeapObject(current_liquidity), amount, specified_input);
|
|
295
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
296
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
297
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
298
|
+
if (r2) {
|
|
299
|
+
throw takeObject(r1);
|
|
300
|
+
}
|
|
301
|
+
return takeObject(r0);
|
|
302
|
+
} finally {
|
|
303
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Apply a transfer fee to an amount
|
|
309
|
+
* e.g. You send 10000 amount with 100 fee rate. The fee amount will be 100.
|
|
310
|
+
* So the amount after fee will be 9900.
|
|
311
|
+
*
|
|
312
|
+
* # Parameters
|
|
313
|
+
* - `amount`: The amount to apply the fee to
|
|
314
|
+
* - `transfer_fee`: The transfer fee to apply
|
|
315
|
+
*
|
|
316
|
+
* # Returns
|
|
317
|
+
* - `u64`: The amount after the fee has been applied
|
|
318
|
+
*/
|
|
319
|
+
module.exports.tryApplyTransferFee = function(amount, transfer_fee) {
|
|
320
|
+
try {
|
|
321
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
322
|
+
wasm.tryApplyTransferFee(retptr, amount, addHeapObject(transfer_fee));
|
|
323
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
324
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
325
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
326
|
+
if (r3) {
|
|
327
|
+
throw takeObject(r2);
|
|
328
|
+
}
|
|
329
|
+
return BigInt.asUintN(64, r0);
|
|
330
|
+
} finally {
|
|
331
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Reverse the application of a transfer fee to an amount
|
|
337
|
+
* e.g. You received 9900 amount with 100 fee rate. The fee amount will be 100.
|
|
338
|
+
* So the amount before fee will be 10000.
|
|
339
|
+
*
|
|
340
|
+
* # Parameters
|
|
341
|
+
* - `amount`: The amount to reverse the fee from
|
|
342
|
+
* - `transfer_fee`: The transfer fee to reverse
|
|
343
|
+
*
|
|
344
|
+
* # Returns
|
|
345
|
+
* - `u64`: The amount before the fee has been applied
|
|
346
|
+
*/
|
|
347
|
+
module.exports.tryReverseApplyTransferFee = function(amount, transfer_fee) {
|
|
348
|
+
try {
|
|
349
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
350
|
+
wasm.tryReverseApplyTransferFee(retptr, amount, addHeapObject(transfer_fee));
|
|
351
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
352
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
353
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
354
|
+
if (r3) {
|
|
355
|
+
throw takeObject(r2);
|
|
356
|
+
}
|
|
357
|
+
return BigInt.asUintN(64, r0);
|
|
358
|
+
} finally {
|
|
359
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Get the maximum amount with a slippage tolerance
|
|
365
|
+
* e.g. Your estimated amount you send is 10000 with 100 slippage tolerance. The max you send will be 10100.
|
|
366
|
+
*
|
|
367
|
+
* # Parameters
|
|
368
|
+
* - `amount`: The amount to apply the fee to
|
|
369
|
+
* - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
|
|
370
|
+
*
|
|
371
|
+
* # Returns
|
|
372
|
+
* - `u64`: The maximum amount
|
|
373
|
+
*/
|
|
374
|
+
module.exports.tryGetMaxAmountWithSlippageTolerance = function(amount, slippage_tolerance_bps) {
|
|
375
|
+
try {
|
|
376
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
377
|
+
wasm.tryGetMaxAmountWithSlippageTolerance(retptr, amount, slippage_tolerance_bps);
|
|
378
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
379
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
380
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
381
|
+
if (r3) {
|
|
382
|
+
throw takeObject(r2);
|
|
383
|
+
}
|
|
384
|
+
return BigInt.asUintN(64, r0);
|
|
385
|
+
} finally {
|
|
386
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Get the minimum amount with a slippage tolerance
|
|
392
|
+
* e.g. Your estimated amount you receive is 10000 with 100 slippage tolerance. The min amount you receive will be 9900.
|
|
393
|
+
*
|
|
394
|
+
* # Parameters
|
|
395
|
+
* - `amount`: The amount to apply the fee to
|
|
396
|
+
* - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
|
|
397
|
+
*
|
|
398
|
+
* # Returns
|
|
399
|
+
* - `u64`: The minimum amount
|
|
400
|
+
*/
|
|
401
|
+
module.exports.tryGetMinAmountWithSlippageTolerance = function(amount, slippage_tolerance_bps) {
|
|
402
|
+
try {
|
|
403
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
404
|
+
wasm.tryGetMinAmountWithSlippageTolerance(retptr, amount, slippage_tolerance_bps);
|
|
405
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
406
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
407
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
408
|
+
if (r3) {
|
|
409
|
+
throw takeObject(r2);
|
|
410
|
+
}
|
|
411
|
+
return BigInt.asUintN(64, r0);
|
|
412
|
+
} finally {
|
|
413
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Apply a swap fee to an amount
|
|
419
|
+
* e.g. You send 10000 amount with 10000 fee rate. The fee amount will be 100.
|
|
420
|
+
* So the amount after fee will be 9900.
|
|
421
|
+
*
|
|
422
|
+
* # Parameters
|
|
423
|
+
* - `amount`: The amount to apply the fee to
|
|
424
|
+
* - `fee_rate`: The fee rate to apply denominated in 1e6
|
|
425
|
+
*
|
|
426
|
+
* # Returns
|
|
427
|
+
* - `u64`: The amount after the fee has been applied
|
|
428
|
+
*/
|
|
429
|
+
module.exports.tryApplySwapFee = function(amount, fee_rate) {
|
|
430
|
+
try {
|
|
431
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
432
|
+
wasm.tryApplySwapFee(retptr, amount, fee_rate);
|
|
433
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
434
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
435
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
436
|
+
if (r3) {
|
|
437
|
+
throw takeObject(r2);
|
|
438
|
+
}
|
|
439
|
+
return BigInt.asUintN(64, r0);
|
|
440
|
+
} finally {
|
|
441
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Reverse the application of a swap fee to an amount
|
|
447
|
+
* e.g. You received 9900 amount with 10000 fee rate. The fee amount will be 100.
|
|
448
|
+
* So the amount before fee will be 10000.
|
|
449
|
+
*
|
|
450
|
+
* # Parameters
|
|
451
|
+
* - `amount`: The amount to reverse the fee from
|
|
452
|
+
* - `fee_rate`: The fee rate to reverse denominated in 1e6
|
|
453
|
+
*
|
|
454
|
+
* # Returns
|
|
455
|
+
* - `u64`: The amount before the fee has been applied
|
|
456
|
+
*/
|
|
457
|
+
module.exports.tryReverseApplySwapFee = function(amount, fee_rate) {
|
|
458
|
+
try {
|
|
459
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
460
|
+
wasm.tryReverseApplySwapFee(retptr, amount, fee_rate);
|
|
461
|
+
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
462
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
463
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
464
|
+
if (r3) {
|
|
465
|
+
throw takeObject(r2);
|
|
466
|
+
}
|
|
467
|
+
return BigInt.asUintN(64, r0);
|
|
468
|
+
} finally {
|
|
469
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Calculate rewards owed for a position
|
|
475
|
+
*
|
|
476
|
+
* # Paramters
|
|
477
|
+
* - `whirlpool`: The whirlpool state
|
|
478
|
+
* - `position`: The position state
|
|
479
|
+
* - `tick_lower`: The lower tick state
|
|
480
|
+
* - `tick_upper`: The upper tick state
|
|
481
|
+
* - `current_timestamp`: The current timestamp
|
|
482
|
+
* - `transfer_fee_1`: The transfer fee for token 1
|
|
483
|
+
* - `transfer_fee_2`: The transfer fee for token 2
|
|
484
|
+
* - `transfer_fee_3`: The transfer fee for token 3
|
|
485
|
+
*
|
|
486
|
+
* # Returns
|
|
487
|
+
* - `CollectRewardsQuote`: The rewards owed for the 3 reward tokens.
|
|
488
|
+
*/
|
|
489
|
+
module.exports.collectRewardsQuote = function(whirlpool, position, tick_lower, tick_upper, current_timestamp, transfer_fee_1, transfer_fee_2, transfer_fee_3) {
|
|
490
|
+
try {
|
|
491
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
492
|
+
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));
|
|
493
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
494
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
495
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
496
|
+
if (r2) {
|
|
497
|
+
throw takeObject(r1);
|
|
498
|
+
}
|
|
499
|
+
return takeObject(r0);
|
|
500
|
+
} finally {
|
|
501
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
|
|
195
505
|
/**
|
|
196
506
|
* Get the first tick index in the tick array that contains the specified tick index.
|
|
197
507
|
*
|
|
@@ -225,6 +535,7 @@ module.exports.tickIndexToSqrtPrice = function(tick_index) {
|
|
|
225
535
|
/**
|
|
226
536
|
* Derive the tick index from a sqrt price. The precision of this method is only guarranted
|
|
227
537
|
* if tick is within the bounds of {max, min} tick-index.
|
|
538
|
+
* This function will make panic for zero sqrt price.
|
|
228
539
|
*
|
|
229
540
|
* # Parameters
|
|
230
541
|
* - `sqrt_price` - A u128 integer representing the sqrt price
|
|
@@ -418,6 +729,41 @@ module.exports.getTickIndexInArray = function(tick_index, tick_array_start_index
|
|
|
418
729
|
}
|
|
419
730
|
};
|
|
420
731
|
|
|
732
|
+
module.exports._VOLATILITY_ACCUMULATOR_SCALE_FACTOR = function() {
|
|
733
|
+
const ret = wasm._REDUCTION_FACTOR_DENOMINATOR();
|
|
734
|
+
return ret;
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
module.exports._REDUCTION_FACTOR_DENOMINATOR = function() {
|
|
738
|
+
const ret = wasm._REDUCTION_FACTOR_DENOMINATOR();
|
|
739
|
+
return ret;
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
module.exports._ADAPTIVE_FEE_CONTROL_FACTOR_DENOMINATOR = function() {
|
|
743
|
+
const ret = wasm._ADAPTIVE_FEE_CONTROL_FACTOR_DENOMINATOR();
|
|
744
|
+
return ret >>> 0;
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
module.exports._MAX_REFERENCE_AGE = function() {
|
|
748
|
+
const ret = wasm._MAX_REFERENCE_AGE();
|
|
749
|
+
return BigInt.asUintN(64, ret);
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
module.exports._FEE_RATE_HARD_LIMIT = function() {
|
|
753
|
+
const ret = wasm._ADAPTIVE_FEE_CONTROL_FACTOR_DENOMINATOR();
|
|
754
|
+
return ret >>> 0;
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
module.exports._POSITION_BUNDLE_SIZE = function() {
|
|
758
|
+
const ret = wasm._POSITION_BUNDLE_SIZE();
|
|
759
|
+
return ret >>> 0;
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
module.exports._NUM_REWARDS = function() {
|
|
763
|
+
const ret = wasm._NUM_REWARDS();
|
|
764
|
+
return ret >>> 0;
|
|
765
|
+
};
|
|
766
|
+
|
|
421
767
|
module.exports._FEE_RATE_DENOMINATOR = function() {
|
|
422
768
|
const ret = wasm._FEE_RATE_DENOMINATOR();
|
|
423
769
|
return ret >>> 0;
|
|
@@ -498,6 +844,59 @@ module.exports.isPositionBundleEmpty = function(bitmap) {
|
|
|
498
844
|
return ret !== 0;
|
|
499
845
|
};
|
|
500
846
|
|
|
847
|
+
/**
|
|
848
|
+
* Check if a position is in range.
|
|
849
|
+
* When a position is in range it is earning fees and rewards
|
|
850
|
+
*
|
|
851
|
+
* # Parameters
|
|
852
|
+
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
853
|
+
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
854
|
+
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
855
|
+
*
|
|
856
|
+
* # Returns
|
|
857
|
+
* - A boolean value indicating if the position is in range
|
|
858
|
+
*/
|
|
859
|
+
module.exports.isPositionInRange = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
860
|
+
const ret = wasm.isPositionInRange(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
|
|
861
|
+
return ret !== 0;
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
/**
|
|
865
|
+
* Calculate the status of a position
|
|
866
|
+
* The status can be one of three values:
|
|
867
|
+
* - InRange: The position is in range
|
|
868
|
+
* - BelowRange: The position is below the range
|
|
869
|
+
* - AboveRange: The position is above the range
|
|
870
|
+
*
|
|
871
|
+
* # Parameters
|
|
872
|
+
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
873
|
+
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
874
|
+
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
875
|
+
*
|
|
876
|
+
* # Returns
|
|
877
|
+
* - A PositionStatus enum value indicating the status of the position
|
|
878
|
+
*/
|
|
879
|
+
module.exports.positionStatus = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
880
|
+
const ret = wasm.positionStatus(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
|
|
881
|
+
return takeObject(ret);
|
|
882
|
+
};
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* Calculate the token_a / token_b ratio of a (ficticious) position
|
|
886
|
+
*
|
|
887
|
+
* # Parameters
|
|
888
|
+
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
889
|
+
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
890
|
+
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
891
|
+
*
|
|
892
|
+
* # Returns
|
|
893
|
+
* - A PositionRatio struct containing the ratio of token_a and token_b
|
|
894
|
+
*/
|
|
895
|
+
module.exports.positionRatio = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
896
|
+
const ret = wasm.positionRatio(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
|
|
897
|
+
return takeObject(ret);
|
|
898
|
+
};
|
|
899
|
+
|
|
501
900
|
/**
|
|
502
901
|
* Convert a price into a sqrt priceX64
|
|
503
902
|
* IMPORTANT: floating point operations can reduce the precision of the result.
|
|
@@ -588,16 +987,6 @@ module.exports.priceToTickIndex = function(price, decimals_a, decimals_b) {
|
|
|
588
987
|
return ret;
|
|
589
988
|
};
|
|
590
989
|
|
|
591
|
-
module.exports._NUM_REWARDS = function() {
|
|
592
|
-
const ret = wasm._NUM_REWARDS();
|
|
593
|
-
return ret >>> 0;
|
|
594
|
-
};
|
|
595
|
-
|
|
596
|
-
module.exports._POSITION_BUNDLE_SIZE = function() {
|
|
597
|
-
const ret = wasm._POSITION_BUNDLE_SIZE();
|
|
598
|
-
return ret >>> 0;
|
|
599
|
-
};
|
|
600
|
-
|
|
601
990
|
module.exports._TICK_ARRAY_NOT_EVENLY_SPACED = function() {
|
|
602
991
|
try {
|
|
603
992
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
@@ -683,418 +1072,125 @@ module.exports._TICK_SEQUENCE_EMPTY = function() {
|
|
|
683
1072
|
};
|
|
684
1073
|
|
|
685
1074
|
module.exports._SQRT_PRICE_LIMIT_OUT_OF_BOUNDS = function() {
|
|
686
|
-
try {
|
|
687
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
688
|
-
wasm._SQRT_PRICE_LIMIT_OUT_OF_BOUNDS(retptr);
|
|
689
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
690
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
691
|
-
return getStringFromWasm0(r0, r1);
|
|
692
|
-
} finally {
|
|
693
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
694
|
-
}
|
|
695
|
-
};
|
|
696
|
-
|
|
697
|
-
module.exports._INVALID_SQRT_PRICE_LIMIT_DIRECTION = function() {
|
|
698
|
-
try {
|
|
699
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
700
|
-
wasm._INVALID_SQRT_PRICE_LIMIT_DIRECTION(retptr);
|
|
701
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
702
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
703
|
-
return getStringFromWasm0(r0, r1);
|
|
704
|
-
} finally {
|
|
705
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
706
|
-
}
|
|
707
|
-
};
|
|
708
|
-
|
|
709
|
-
module.exports._ZERO_TRADABLE_AMOUNT = function() {
|
|
710
|
-
try {
|
|
711
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
712
|
-
wasm._ZERO_TRADABLE_AMOUNT(retptr);
|
|
713
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
714
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
715
|
-
return getStringFromWasm0(r0, r1);
|
|
716
|
-
} finally {
|
|
717
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
718
|
-
}
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
module.exports._INVALID_TIMESTAMP = function() {
|
|
722
|
-
try {
|
|
723
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
724
|
-
wasm._INVALID_TIMESTAMP(retptr);
|
|
725
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
726
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
727
|
-
return getStringFromWasm0(r0, r1);
|
|
728
|
-
} finally {
|
|
729
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
730
|
-
}
|
|
731
|
-
};
|
|
732
|
-
|
|
733
|
-
module.exports._INVALID_TRANSFER_FEE = function() {
|
|
734
|
-
try {
|
|
735
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
736
|
-
wasm._INVALID_TRANSFER_FEE(retptr);
|
|
737
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
738
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
739
|
-
return getStringFromWasm0(r0, r1);
|
|
740
|
-
} finally {
|
|
741
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
742
|
-
}
|
|
743
|
-
};
|
|
744
|
-
|
|
745
|
-
module.exports._INVALID_SLIPPAGE_TOLERANCE = function() {
|
|
746
|
-
try {
|
|
747
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
748
|
-
wasm._INVALID_SLIPPAGE_TOLERANCE(retptr);
|
|
749
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
750
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
751
|
-
return getStringFromWasm0(r0, r1);
|
|
752
|
-
} finally {
|
|
753
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
754
|
-
}
|
|
755
|
-
};
|
|
756
|
-
|
|
757
|
-
module.exports._TICK_INDEX_NOT_IN_ARRAY = function() {
|
|
758
|
-
try {
|
|
759
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
760
|
-
wasm._TICK_INDEX_NOT_IN_ARRAY(retptr);
|
|
761
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
762
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
763
|
-
return getStringFromWasm0(r0, r1);
|
|
764
|
-
} finally {
|
|
765
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
766
|
-
}
|
|
767
|
-
};
|
|
768
|
-
|
|
769
|
-
/**
|
|
770
|
-
* Check if a position is in range.
|
|
771
|
-
* When a position is in range it is earning fees and rewards
|
|
772
|
-
*
|
|
773
|
-
* # Parameters
|
|
774
|
-
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
775
|
-
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
776
|
-
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
777
|
-
*
|
|
778
|
-
* # Returns
|
|
779
|
-
* - A boolean value indicating if the position is in range
|
|
780
|
-
*/
|
|
781
|
-
module.exports.isPositionInRange = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
782
|
-
const ret = wasm.isPositionInRange(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
|
|
783
|
-
return ret !== 0;
|
|
784
|
-
};
|
|
785
|
-
|
|
786
|
-
/**
|
|
787
|
-
* Calculate the status of a position
|
|
788
|
-
* The status can be one of three values:
|
|
789
|
-
* - InRange: The position is in range
|
|
790
|
-
* - BelowRange: The position is below the range
|
|
791
|
-
* - AboveRange: The position is above the range
|
|
792
|
-
*
|
|
793
|
-
* # Parameters
|
|
794
|
-
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
795
|
-
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
796
|
-
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
797
|
-
*
|
|
798
|
-
* # Returns
|
|
799
|
-
* - A PositionStatus enum value indicating the status of the position
|
|
800
|
-
*/
|
|
801
|
-
module.exports.positionStatus = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
802
|
-
const ret = wasm.positionStatus(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
|
|
803
|
-
return takeObject(ret);
|
|
804
|
-
};
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* Calculate the token_a / token_b ratio of a (ficticious) position
|
|
808
|
-
*
|
|
809
|
-
* # Parameters
|
|
810
|
-
* - `sqrt_price` - A u128 integer representing the sqrt price of the pool
|
|
811
|
-
* - `tick_index_1` - A i32 integer representing the first tick index of the position
|
|
812
|
-
* - `tick_index_2` - A i32 integer representing the second tick index of the position
|
|
813
|
-
*
|
|
814
|
-
* # Returns
|
|
815
|
-
* - A PositionRatio struct containing the ratio of token_a and token_b
|
|
816
|
-
*/
|
|
817
|
-
module.exports.positionRatio = function(current_sqrt_price, tick_index_1, tick_index_2) {
|
|
818
|
-
const ret = wasm.positionRatio(addHeapObject(current_sqrt_price), tick_index_1, tick_index_2);
|
|
819
|
-
return takeObject(ret);
|
|
820
|
-
};
|
|
821
|
-
|
|
822
|
-
/**
|
|
823
|
-
* Calculate the amount A delta between two sqrt_prices
|
|
824
|
-
*
|
|
825
|
-
* # Parameters
|
|
826
|
-
* - `sqrt_price_1`: The first square root price
|
|
827
|
-
* - `sqrt_price_2`: The second square root price
|
|
828
|
-
* - `liquidity`: The liquidity
|
|
829
|
-
* - `round_up`: Whether to round up or not
|
|
830
|
-
*
|
|
831
|
-
* # Returns
|
|
832
|
-
* - `u64`: The amount delta
|
|
833
|
-
*/
|
|
834
|
-
module.exports.tryGetAmountDeltaA = function(sqrt_price_1, sqrt_price_2, liquidity, round_up) {
|
|
835
|
-
try {
|
|
836
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
837
|
-
wasm.tryGetAmountDeltaA(retptr, addHeapObject(sqrt_price_1), addHeapObject(sqrt_price_2), addHeapObject(liquidity), round_up);
|
|
838
|
-
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
839
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
840
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
841
|
-
if (r3) {
|
|
842
|
-
throw takeObject(r2);
|
|
843
|
-
}
|
|
844
|
-
return BigInt.asUintN(64, r0);
|
|
1075
|
+
try {
|
|
1076
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1077
|
+
wasm._SQRT_PRICE_LIMIT_OUT_OF_BOUNDS(retptr);
|
|
1078
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1079
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1080
|
+
return getStringFromWasm0(r0, r1);
|
|
845
1081
|
} finally {
|
|
846
1082
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
847
1083
|
}
|
|
848
1084
|
};
|
|
849
1085
|
|
|
850
|
-
|
|
851
|
-
* Calculate the amount B delta between two sqrt_prices
|
|
852
|
-
*
|
|
853
|
-
* # Parameters
|
|
854
|
-
* - `sqrt_price_1`: The first square root price
|
|
855
|
-
* - `sqrt_price_2`: The second square root price
|
|
856
|
-
* - `liquidity`: The liquidity
|
|
857
|
-
* - `round_up`: Whether to round up or not
|
|
858
|
-
*
|
|
859
|
-
* # Returns
|
|
860
|
-
* - `u64`: The amount delta
|
|
861
|
-
*/
|
|
862
|
-
module.exports.tryGetAmountDeltaB = function(sqrt_price_1, sqrt_price_2, liquidity, round_up) {
|
|
1086
|
+
module.exports._INVALID_SQRT_PRICE_LIMIT_DIRECTION = function() {
|
|
863
1087
|
try {
|
|
864
1088
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
865
|
-
wasm.
|
|
866
|
-
var r0 = getDataViewMemory0().
|
|
867
|
-
var
|
|
868
|
-
|
|
869
|
-
if (r3) {
|
|
870
|
-
throw takeObject(r2);
|
|
871
|
-
}
|
|
872
|
-
return BigInt.asUintN(64, r0);
|
|
1089
|
+
wasm._INVALID_SQRT_PRICE_LIMIT_DIRECTION(retptr);
|
|
1090
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1091
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1092
|
+
return getStringFromWasm0(r0, r1);
|
|
873
1093
|
} finally {
|
|
874
1094
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
875
1095
|
}
|
|
876
1096
|
};
|
|
877
1097
|
|
|
878
|
-
|
|
879
|
-
* Calculate the next square root price
|
|
880
|
-
*
|
|
881
|
-
* # Parameters
|
|
882
|
-
* - `current_sqrt_price`: The current square root price
|
|
883
|
-
* - `current_liquidity`: The current liquidity
|
|
884
|
-
* - `amount`: The amount
|
|
885
|
-
* - `specified_input`: Whether the input is specified
|
|
886
|
-
*
|
|
887
|
-
* # Returns
|
|
888
|
-
* - `u128`: The next square root price
|
|
889
|
-
*/
|
|
890
|
-
module.exports.tryGetNextSqrtPriceFromA = function(current_sqrt_price, current_liquidity, amount, specified_input) {
|
|
1098
|
+
module.exports._ZERO_TRADABLE_AMOUNT = function() {
|
|
891
1099
|
try {
|
|
892
1100
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
893
|
-
wasm.
|
|
1101
|
+
wasm._ZERO_TRADABLE_AMOUNT(retptr);
|
|
894
1102
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
895
1103
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
896
|
-
|
|
897
|
-
if (r2) {
|
|
898
|
-
throw takeObject(r1);
|
|
899
|
-
}
|
|
900
|
-
return takeObject(r0);
|
|
1104
|
+
return getStringFromWasm0(r0, r1);
|
|
901
1105
|
} finally {
|
|
902
1106
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
903
1107
|
}
|
|
904
1108
|
};
|
|
905
1109
|
|
|
906
|
-
|
|
907
|
-
* Calculate the next square root price
|
|
908
|
-
*
|
|
909
|
-
* # Parameters
|
|
910
|
-
* - `current_sqrt_price`: The current square root price
|
|
911
|
-
* - `current_liquidity`: The current liquidity
|
|
912
|
-
* - `amount`: The amount
|
|
913
|
-
* - `specified_input`: Whether the input is specified
|
|
914
|
-
*
|
|
915
|
-
* # Returns
|
|
916
|
-
* - `u128`: The next square root price
|
|
917
|
-
*/
|
|
918
|
-
module.exports.tryGetNextSqrtPriceFromB = function(current_sqrt_price, current_liquidity, amount, specified_input) {
|
|
1110
|
+
module.exports._INVALID_TIMESTAMP = function() {
|
|
919
1111
|
try {
|
|
920
1112
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
921
|
-
wasm.
|
|
1113
|
+
wasm._INVALID_TIMESTAMP(retptr);
|
|
922
1114
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
923
1115
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
924
|
-
|
|
925
|
-
if (r2) {
|
|
926
|
-
throw takeObject(r1);
|
|
927
|
-
}
|
|
928
|
-
return takeObject(r0);
|
|
1116
|
+
return getStringFromWasm0(r0, r1);
|
|
929
1117
|
} finally {
|
|
930
1118
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
931
1119
|
}
|
|
932
1120
|
};
|
|
933
1121
|
|
|
934
|
-
|
|
935
|
-
* Apply a transfer fee to an amount
|
|
936
|
-
* e.g. You send 10000 amount with 100 fee rate. The fee amount will be 100.
|
|
937
|
-
* So the amount after fee will be 9900.
|
|
938
|
-
*
|
|
939
|
-
* # Parameters
|
|
940
|
-
* - `amount`: The amount to apply the fee to
|
|
941
|
-
* - `transfer_fee`: The transfer fee to apply
|
|
942
|
-
*
|
|
943
|
-
* # Returns
|
|
944
|
-
* - `u64`: The amount after the fee has been applied
|
|
945
|
-
*/
|
|
946
|
-
module.exports.tryApplyTransferFee = function(amount, transfer_fee) {
|
|
1122
|
+
module.exports._INVALID_TRANSFER_FEE = function() {
|
|
947
1123
|
try {
|
|
948
1124
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
949
|
-
wasm.
|
|
950
|
-
var r0 = getDataViewMemory0().
|
|
951
|
-
var
|
|
952
|
-
|
|
953
|
-
if (r3) {
|
|
954
|
-
throw takeObject(r2);
|
|
955
|
-
}
|
|
956
|
-
return BigInt.asUintN(64, r0);
|
|
1125
|
+
wasm._INVALID_TRANSFER_FEE(retptr);
|
|
1126
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1127
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1128
|
+
return getStringFromWasm0(r0, r1);
|
|
957
1129
|
} finally {
|
|
958
1130
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
959
1131
|
}
|
|
960
1132
|
};
|
|
961
1133
|
|
|
962
|
-
|
|
963
|
-
* Reverse the application of a transfer fee to an amount
|
|
964
|
-
* e.g. You received 9900 amount with 100 fee rate. The fee amount will be 100.
|
|
965
|
-
* So the amount before fee will be 10000.
|
|
966
|
-
*
|
|
967
|
-
* # Parameters
|
|
968
|
-
* - `amount`: The amount to reverse the fee from
|
|
969
|
-
* - `transfer_fee`: The transfer fee to reverse
|
|
970
|
-
*
|
|
971
|
-
* # Returns
|
|
972
|
-
* - `u64`: The amount before the fee has been applied
|
|
973
|
-
*/
|
|
974
|
-
module.exports.tryReverseApplyTransferFee = function(amount, transfer_fee) {
|
|
1134
|
+
module.exports._INVALID_SLIPPAGE_TOLERANCE = function() {
|
|
975
1135
|
try {
|
|
976
1136
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
977
|
-
wasm.
|
|
978
|
-
var r0 = getDataViewMemory0().
|
|
979
|
-
var
|
|
980
|
-
|
|
981
|
-
if (r3) {
|
|
982
|
-
throw takeObject(r2);
|
|
983
|
-
}
|
|
984
|
-
return BigInt.asUintN(64, r0);
|
|
1137
|
+
wasm._INVALID_SLIPPAGE_TOLERANCE(retptr);
|
|
1138
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1139
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1140
|
+
return getStringFromWasm0(r0, r1);
|
|
985
1141
|
} finally {
|
|
986
1142
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
987
1143
|
}
|
|
988
1144
|
};
|
|
989
1145
|
|
|
990
|
-
|
|
991
|
-
* Get the maximum amount with a slippage tolerance
|
|
992
|
-
* e.g. Your estimated amount you send is 10000 with 100 slippage tolerance. The max you send will be 10100.
|
|
993
|
-
*
|
|
994
|
-
* # Parameters
|
|
995
|
-
* - `amount`: The amount to apply the fee to
|
|
996
|
-
* - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
|
|
997
|
-
*
|
|
998
|
-
* # Returns
|
|
999
|
-
* - `u64`: The maximum amount
|
|
1000
|
-
*/
|
|
1001
|
-
module.exports.tryGetMaxAmountWithSlippageTolerance = function(amount, slippage_tolerance_bps) {
|
|
1146
|
+
module.exports._TICK_INDEX_NOT_IN_ARRAY = function() {
|
|
1002
1147
|
try {
|
|
1003
1148
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1004
|
-
wasm.
|
|
1005
|
-
var r0 = getDataViewMemory0().
|
|
1006
|
-
var
|
|
1007
|
-
|
|
1008
|
-
if (r3) {
|
|
1009
|
-
throw takeObject(r2);
|
|
1010
|
-
}
|
|
1011
|
-
return BigInt.asUintN(64, r0);
|
|
1149
|
+
wasm._TICK_INDEX_NOT_IN_ARRAY(retptr);
|
|
1150
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1151
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1152
|
+
return getStringFromWasm0(r0, r1);
|
|
1012
1153
|
} finally {
|
|
1013
1154
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1014
1155
|
}
|
|
1015
1156
|
};
|
|
1016
1157
|
|
|
1017
|
-
|
|
1018
|
-
* Get the minimum amount with a slippage tolerance
|
|
1019
|
-
* e.g. Your estimated amount you receive is 10000 with 100 slippage tolerance. The min amount you receive will be 9900.
|
|
1020
|
-
*
|
|
1021
|
-
* # Parameters
|
|
1022
|
-
* - `amount`: The amount to apply the fee to
|
|
1023
|
-
* - `slippage_tolerance_bps`: The slippage tolerance in bps (should be in range 0..BPS_DENOMINATOR)
|
|
1024
|
-
*
|
|
1025
|
-
* # Returns
|
|
1026
|
-
* - `u64`: The minimum amount
|
|
1027
|
-
*/
|
|
1028
|
-
module.exports.tryGetMinAmountWithSlippageTolerance = function(amount, slippage_tolerance_bps) {
|
|
1158
|
+
module.exports._INVALID_TICK_ARRAY_SEQUENCE = function() {
|
|
1029
1159
|
try {
|
|
1030
1160
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1031
|
-
wasm.
|
|
1032
|
-
var r0 = getDataViewMemory0().
|
|
1033
|
-
var
|
|
1034
|
-
|
|
1035
|
-
if (r3) {
|
|
1036
|
-
throw takeObject(r2);
|
|
1037
|
-
}
|
|
1038
|
-
return BigInt.asUintN(64, r0);
|
|
1161
|
+
wasm._INVALID_TICK_ARRAY_SEQUENCE(retptr);
|
|
1162
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1163
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1164
|
+
return getStringFromWasm0(r0, r1);
|
|
1039
1165
|
} finally {
|
|
1040
1166
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1041
1167
|
}
|
|
1042
1168
|
};
|
|
1043
1169
|
|
|
1044
|
-
|
|
1045
|
-
* Apply a swap fee to an amount
|
|
1046
|
-
* e.g. You send 10000 amount with 10000 fee rate. The fee amount will be 100.
|
|
1047
|
-
* So the amount after fee will be 9900.
|
|
1048
|
-
*
|
|
1049
|
-
* # Parameters
|
|
1050
|
-
* - `amount`: The amount to apply the fee to
|
|
1051
|
-
* - `fee_rate`: The fee rate to apply denominated in 1e6
|
|
1052
|
-
*
|
|
1053
|
-
* # Returns
|
|
1054
|
-
* - `u64`: The amount after the fee has been applied
|
|
1055
|
-
*/
|
|
1056
|
-
module.exports.tryApplySwapFee = function(amount, fee_rate) {
|
|
1170
|
+
module.exports._INVALID_ADAPTIVE_FEE_INFO = function() {
|
|
1057
1171
|
try {
|
|
1058
1172
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1059
|
-
wasm.
|
|
1060
|
-
var r0 = getDataViewMemory0().
|
|
1061
|
-
var
|
|
1062
|
-
|
|
1063
|
-
if (r3) {
|
|
1064
|
-
throw takeObject(r2);
|
|
1065
|
-
}
|
|
1066
|
-
return BigInt.asUintN(64, r0);
|
|
1173
|
+
wasm._INVALID_ADAPTIVE_FEE_INFO(retptr);
|
|
1174
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1175
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1176
|
+
return getStringFromWasm0(r0, r1);
|
|
1067
1177
|
} finally {
|
|
1068
1178
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1069
1179
|
}
|
|
1070
1180
|
};
|
|
1071
1181
|
|
|
1072
1182
|
/**
|
|
1073
|
-
*
|
|
1074
|
-
* e.g. You received 9900 amount with 10000 fee rate. The fee amount will be 100.
|
|
1075
|
-
* So the amount before fee will be 10000.
|
|
1183
|
+
* Check if the whirlpool is initialized with adaptive fee
|
|
1076
1184
|
*
|
|
1077
|
-
* #
|
|
1078
|
-
* - `
|
|
1079
|
-
* - `fee_rate`: The fee rate to reverse denominated in 1e6
|
|
1185
|
+
* # Paramters
|
|
1186
|
+
* - `whirlpool`: The whirlpool state
|
|
1080
1187
|
*
|
|
1081
1188
|
* # Returns
|
|
1082
|
-
* -
|
|
1189
|
+
* - A boolean value indicating if the whirlpool is initialized with adaptive fee
|
|
1083
1190
|
*/
|
|
1084
|
-
module.exports.
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
wasm.tryReverseApplySwapFee(retptr, amount, fee_rate);
|
|
1088
|
-
var r0 = getDataViewMemory0().getBigInt64(retptr + 8 * 0, true);
|
|
1089
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1090
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1091
|
-
if (r3) {
|
|
1092
|
-
throw takeObject(r2);
|
|
1093
|
-
}
|
|
1094
|
-
return BigInt.asUintN(64, r0);
|
|
1095
|
-
} finally {
|
|
1096
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1097
|
-
}
|
|
1191
|
+
module.exports.isInitializedWithAdaptiveFee = function(whirlpool) {
|
|
1192
|
+
const ret = wasm.isInitializedWithAdaptiveFee(addHeapObject(whirlpool));
|
|
1193
|
+
return ret !== 0;
|
|
1098
1194
|
};
|
|
1099
1195
|
|
|
1100
1196
|
/**
|
|
@@ -1105,17 +1201,19 @@ module.exports.tryReverseApplySwapFee = function(amount, fee_rate) {
|
|
|
1105
1201
|
* - `specified_token_a`: If `true`, the input token is token A. Otherwise, it is token B.
|
|
1106
1202
|
* - `slippage_tolerance`: The slippage tolerance in basis points.
|
|
1107
1203
|
* - `whirlpool`: The whirlpool state.
|
|
1204
|
+
* - `oracle`: The oracle data for the whirlpool.
|
|
1108
1205
|
* - `tick_arrays`: The tick arrays needed for the swap.
|
|
1206
|
+
* - `timestamp`: The timestamp for the swap.
|
|
1109
1207
|
* - `transfer_fee_a`: The transfer fee for token A.
|
|
1110
1208
|
* - `transfer_fee_b`: The transfer fee for token B.
|
|
1111
1209
|
*
|
|
1112
1210
|
* # Returns
|
|
1113
1211
|
* The exact input or output amount for the swap transaction.
|
|
1114
1212
|
*/
|
|
1115
|
-
module.exports.swapQuoteByInputToken = function(token_in, specified_token_a, slippage_tolerance_bps, whirlpool, tick_arrays, transfer_fee_a, transfer_fee_b) {
|
|
1213
|
+
module.exports.swapQuoteByInputToken = function(token_in, specified_token_a, slippage_tolerance_bps, whirlpool, oracle, tick_arrays, timestamp, transfer_fee_a, transfer_fee_b) {
|
|
1116
1214
|
try {
|
|
1117
1215
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1118
|
-
wasm.swapQuoteByInputToken(retptr, token_in, specified_token_a, slippage_tolerance_bps, addHeapObject(whirlpool), addHeapObject(tick_arrays), isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
|
|
1216
|
+
wasm.swapQuoteByInputToken(retptr, token_in, specified_token_a, slippage_tolerance_bps, addHeapObject(whirlpool), isLikeNone(oracle) ? 0 : addHeapObject(oracle), addHeapObject(tick_arrays), timestamp, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
|
|
1119
1217
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1120
1218
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1121
1219
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
@@ -1136,17 +1234,19 @@ module.exports.swapQuoteByInputToken = function(token_in, specified_token_a, sli
|
|
|
1136
1234
|
* - `specified_token_a`: If `true`, the output token is token A. Otherwise, it is token B.
|
|
1137
1235
|
* - `slippage_tolerance`: The slippage tolerance in basis points.
|
|
1138
1236
|
* - `whirlpool`: The whirlpool state.
|
|
1237
|
+
* - `oracle`: The oracle data for the whirlpool.
|
|
1139
1238
|
* - `tick_arrays`: The tick arrays needed for the swap.
|
|
1239
|
+
* - `timestamp`: The timestamp for the swap.
|
|
1140
1240
|
* - `transfer_fee_a`: The transfer fee for token A.
|
|
1141
1241
|
* - `transfer_fee_b`: The transfer fee for token B.
|
|
1142
1242
|
*
|
|
1143
1243
|
* # Returns
|
|
1144
1244
|
* The exact input or output amount for the swap transaction.
|
|
1145
1245
|
*/
|
|
1146
|
-
module.exports.swapQuoteByOutputToken = function(token_out, specified_token_a, slippage_tolerance_bps, whirlpool, tick_arrays, transfer_fee_a, transfer_fee_b) {
|
|
1246
|
+
module.exports.swapQuoteByOutputToken = function(token_out, specified_token_a, slippage_tolerance_bps, whirlpool, oracle, tick_arrays, timestamp, transfer_fee_a, transfer_fee_b) {
|
|
1147
1247
|
try {
|
|
1148
1248
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1149
|
-
wasm.swapQuoteByOutputToken(retptr, token_out, specified_token_a, slippage_tolerance_bps, addHeapObject(whirlpool), addHeapObject(tick_arrays), isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
|
|
1249
|
+
wasm.swapQuoteByOutputToken(retptr, token_out, specified_token_a, slippage_tolerance_bps, addHeapObject(whirlpool), isLikeNone(oracle) ? 0 : addHeapObject(oracle), addHeapObject(tick_arrays), timestamp, isLikeNone(transfer_fee_a) ? 0 : addHeapObject(transfer_fee_a), isLikeNone(transfer_fee_b) ? 0 : addHeapObject(transfer_fee_b));
|
|
1150
1250
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1151
1251
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1152
1252
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
@@ -1375,38 +1475,6 @@ module.exports.increaseLiquidityQuoteB = function(token_amount_b, slippage_toler
|
|
|
1375
1475
|
}
|
|
1376
1476
|
};
|
|
1377
1477
|
|
|
1378
|
-
/**
|
|
1379
|
-
* Calculate rewards owed for a position
|
|
1380
|
-
*
|
|
1381
|
-
* # Paramters
|
|
1382
|
-
* - `whirlpool`: The whirlpool state
|
|
1383
|
-
* - `position`: The position state
|
|
1384
|
-
* - `tick_lower`: The lower tick state
|
|
1385
|
-
* - `tick_upper`: The upper tick state
|
|
1386
|
-
* - `current_timestamp`: The current timestamp
|
|
1387
|
-
* - `transfer_fee_1`: The transfer fee for token 1
|
|
1388
|
-
* - `transfer_fee_2`: The transfer fee for token 2
|
|
1389
|
-
* - `transfer_fee_3`: The transfer fee for token 3
|
|
1390
|
-
*
|
|
1391
|
-
* # Returns
|
|
1392
|
-
* - `CollectRewardsQuote`: The rewards owed for the 3 reward tokens.
|
|
1393
|
-
*/
|
|
1394
|
-
module.exports.collectRewardsQuote = function(whirlpool, position, tick_lower, tick_upper, current_timestamp, transfer_fee_1, transfer_fee_2, transfer_fee_3) {
|
|
1395
|
-
try {
|
|
1396
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1397
|
-
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));
|
|
1398
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1399
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1400
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1401
|
-
if (r2) {
|
|
1402
|
-
throw takeObject(r1);
|
|
1403
|
-
}
|
|
1404
|
-
return takeObject(r0);
|
|
1405
|
-
} finally {
|
|
1406
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1407
|
-
}
|
|
1408
|
-
};
|
|
1409
|
-
|
|
1410
1478
|
module.exports.__wbg_String_eecc4a11987127d6 = function(arg0, arg1) {
|
|
1411
1479
|
const ret = String(getObject(arg1));
|
|
1412
1480
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|