@alcorexchange/alcor-swap-sdk 1.1.4 → 1.1.5

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.
@@ -440,8 +440,14 @@ let Trade = exports.Trade = /*#__PURE__*/function () {
440
440
  value: function bestTradeExactIn(routes, currencyAmountIn, maxNumResults = 1) {
441
441
  (0, _tinyInvariant.default)(routes.length > 0, 'ROUTES');
442
442
 
443
- // Pre-filter: remove routes with zero-liquidity pools
444
- const validRoutes = routes.filter(route => route.pools.every(pool => pool.active && pool.liquidity > _internalConstants.ZERO));
443
+ // Pre-filter: drop routes touching empty pools (no positions at all).
444
+ // Use ticks presence, NOT current in-range liquidity: a pool can have
445
+ // liquidity === 0 at the current tick while all positions are out of range,
446
+ // yet still be tradeable (the swap crosses the gap into a position).
447
+ const validRoutes = routes.filter(route => route.pools.every(pool => {
448
+ var _ticks$length, _pool$tickDataProvide;
449
+ return pool.active && ((_ticks$length = (_pool$tickDataProvide = pool.tickDataProvider) === null || _pool$tickDataProvide === void 0 || (_pool$tickDataProvide = _pool$tickDataProvide.ticks) === null || _pool$tickDataProvide === void 0 ? void 0 : _pool$tickDataProvide.length) !== null && _ticks$length !== void 0 ? _ticks$length : 0) > 0;
450
+ }));
445
451
 
446
452
  // Helper: compute min liquidity (no overflow)
447
453
  const getMinLiquidity = route => {
@@ -493,8 +499,14 @@ let Trade = exports.Trade = /*#__PURE__*/function () {
493
499
  value: function bestTradeExactOut(routes, currencyAmountOut, maxNumResults = 1) {
494
500
  (0, _tinyInvariant.default)(routes.length > 0, 'ROUTES');
495
501
 
496
- // Pre-filter: remove routes with zero-liquidity pools
497
- const validRoutes = routes.filter(route => route.pools.every(pool => pool.active && pool.liquidity > _internalConstants.ZERO));
502
+ // Pre-filter: drop routes touching empty pools (no positions at all).
503
+ // Use ticks presence, NOT current in-range liquidity: a pool can have
504
+ // liquidity === 0 at the current tick while all positions are out of range,
505
+ // yet still be tradeable (the swap crosses the gap into a position).
506
+ const validRoutes = routes.filter(route => route.pools.every(pool => {
507
+ var _ticks$length2, _pool$tickDataProvide2;
508
+ return pool.active && ((_ticks$length2 = (_pool$tickDataProvide2 = pool.tickDataProvider) === null || _pool$tickDataProvide2 === void 0 || (_pool$tickDataProvide2 = _pool$tickDataProvide2.ticks) === null || _pool$tickDataProvide2 === void 0 ? void 0 : _pool$tickDataProvide2.length) !== null && _ticks$length2 !== void 0 ? _ticks$length2 : 0) > 0;
509
+ }));
498
510
 
499
511
  // Helper: compute min liquidity (no overflow)
500
512
  const getMinLiquidity = route => {
@@ -570,8 +582,14 @@ let Trade = exports.Trade = /*#__PURE__*/function () {
570
582
  (0, _tinyInvariant.default)(_routes.length > 0, 'ROUTES');
571
583
  (0, _tinyInvariant.default)(percents.length > 0, 'PERCENTS');
572
584
 
573
- // Pre-filter: remove routes with zero-liquidity or inactive pools
574
- const validRoutes = _routes.filter(route => route.pools.every(pool => pool.active && pool.liquidity > _internalConstants.ZERO));
585
+ // Pre-filter: drop routes touching empty pools (no positions at all).
586
+ // Use ticks presence, NOT current in-range liquidity: a pool can have
587
+ // liquidity === 0 at the current tick while all positions are out of range,
588
+ // yet still be tradeable (the swap crosses the gap into a position).
589
+ const validRoutes = _routes.filter(route => route.pools.every(pool => {
590
+ var _ticks$length3, _pool$tickDataProvide3;
591
+ return pool.active && ((_ticks$length3 = (_pool$tickDataProvide3 = pool.tickDataProvider) === null || _pool$tickDataProvide3 === void 0 || (_pool$tickDataProvide3 = _pool$tickDataProvide3.ticks) === null || _pool$tickDataProvide3 === void 0 ? void 0 : _pool$tickDataProvide3.length) !== null && _ticks$length3 !== void 0 ? _ticks$length3 : 0) > 0;
592
+ }));
575
593
 
576
594
  // Helper: compute min liquidity for a route (no overflow)
577
595
  const getMinLiquidity = route => {
@@ -431,8 +431,14 @@ export let Trade = /*#__PURE__*/function () {
431
431
  value: function bestTradeExactIn(routes, currencyAmountIn, maxNumResults = 1) {
432
432
  invariant(routes.length > 0, 'ROUTES');
433
433
 
434
- // Pre-filter: remove routes with zero-liquidity pools
435
- const validRoutes = routes.filter(route => route.pools.every(pool => pool.active && pool.liquidity > ZERO));
434
+ // Pre-filter: drop routes touching empty pools (no positions at all).
435
+ // Use ticks presence, NOT current in-range liquidity: a pool can have
436
+ // liquidity === 0 at the current tick while all positions are out of range,
437
+ // yet still be tradeable (the swap crosses the gap into a position).
438
+ const validRoutes = routes.filter(route => route.pools.every(pool => {
439
+ var _ticks$length, _pool$tickDataProvide;
440
+ return pool.active && ((_ticks$length = (_pool$tickDataProvide = pool.tickDataProvider) === null || _pool$tickDataProvide === void 0 || (_pool$tickDataProvide = _pool$tickDataProvide.ticks) === null || _pool$tickDataProvide === void 0 ? void 0 : _pool$tickDataProvide.length) !== null && _ticks$length !== void 0 ? _ticks$length : 0) > 0;
441
+ }));
436
442
 
437
443
  // Helper: compute min liquidity (no overflow)
438
444
  const getMinLiquidity = route => {
@@ -484,8 +490,14 @@ export let Trade = /*#__PURE__*/function () {
484
490
  value: function bestTradeExactOut(routes, currencyAmountOut, maxNumResults = 1) {
485
491
  invariant(routes.length > 0, 'ROUTES');
486
492
 
487
- // Pre-filter: remove routes with zero-liquidity pools
488
- const validRoutes = routes.filter(route => route.pools.every(pool => pool.active && pool.liquidity > ZERO));
493
+ // Pre-filter: drop routes touching empty pools (no positions at all).
494
+ // Use ticks presence, NOT current in-range liquidity: a pool can have
495
+ // liquidity === 0 at the current tick while all positions are out of range,
496
+ // yet still be tradeable (the swap crosses the gap into a position).
497
+ const validRoutes = routes.filter(route => route.pools.every(pool => {
498
+ var _ticks$length2, _pool$tickDataProvide2;
499
+ return pool.active && ((_ticks$length2 = (_pool$tickDataProvide2 = pool.tickDataProvider) === null || _pool$tickDataProvide2 === void 0 || (_pool$tickDataProvide2 = _pool$tickDataProvide2.ticks) === null || _pool$tickDataProvide2 === void 0 ? void 0 : _pool$tickDataProvide2.length) !== null && _ticks$length2 !== void 0 ? _ticks$length2 : 0) > 0;
500
+ }));
489
501
 
490
502
  // Helper: compute min liquidity (no overflow)
491
503
  const getMinLiquidity = route => {
@@ -561,8 +573,14 @@ export let Trade = /*#__PURE__*/function () {
561
573
  invariant(_routes.length > 0, 'ROUTES');
562
574
  invariant(percents.length > 0, 'PERCENTS');
563
575
 
564
- // Pre-filter: remove routes with zero-liquidity or inactive pools
565
- const validRoutes = _routes.filter(route => route.pools.every(pool => pool.active && pool.liquidity > ZERO));
576
+ // Pre-filter: drop routes touching empty pools (no positions at all).
577
+ // Use ticks presence, NOT current in-range liquidity: a pool can have
578
+ // liquidity === 0 at the current tick while all positions are out of range,
579
+ // yet still be tradeable (the swap crosses the gap into a position).
580
+ const validRoutes = _routes.filter(route => route.pools.every(pool => {
581
+ var _ticks$length3, _pool$tickDataProvide3;
582
+ return pool.active && ((_ticks$length3 = (_pool$tickDataProvide3 = pool.tickDataProvider) === null || _pool$tickDataProvide3 === void 0 || (_pool$tickDataProvide3 = _pool$tickDataProvide3.ticks) === null || _pool$tickDataProvide3 === void 0 ? void 0 : _pool$tickDataProvide3.length) !== null && _ticks$length3 !== void 0 ? _ticks$length3 : 0) > 0;
583
+ }));
566
584
 
567
585
  // Helper: compute min liquidity for a route (no overflow)
568
586
  const getMinLiquidity = route => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alcorexchange/alcor-swap-sdk",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "module": "build/esm/index.js",