@bananapus/router-terminal-v6 0.0.3 → 0.0.4

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/foundry.toml CHANGED
@@ -1,7 +1,7 @@
1
1
  [profile.default]
2
2
  solc = '0.8.26'
3
3
  evm_version = 'cancun'
4
- optimizer_runs = 100000000
4
+ optimizer_runs = 200
5
5
  libs = ["node_modules", "lib"]
6
6
  fs_permissions = [{ access = "read-write", path = "./"}]
7
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bananapus/router-terminal-v6",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -71,16 +71,20 @@ contract JBRouterTerminal is
71
71
  /// @notice The default TWAP window used for auto-discovered pools.
72
72
  uint256 public constant DEFAULT_TWAP_WINDOW = 10 minutes;
73
73
 
74
+ /// @notice The denominator used for slippage tolerance basis points.
75
+ uint256 public constant SLIPPAGE_DENOMINATOR = 10_000;
76
+
77
+ //*********************************************************************//
78
+ // ---------------------- internal stored properties ----------------- //
79
+ //*********************************************************************//
80
+
74
81
  /// @notice The fee tiers to search when auto-discovering V3 pools, ordered by commonality.
75
82
  /// 3000 = 0.3%, 500 = 0.05%, 10000 = 1%, 100 = 0.01%.
76
- uint24[4] public FEE_TIERS = [uint24(3000), uint24(500), uint24(10_000), uint24(100)];
83
+ uint24[4] internal _FEE_TIERS = [uint24(3000), uint24(500), uint24(10_000), uint24(100)];
77
84
 
78
85
  /// @notice The fee/tickSpacing pairings to search for V4 vanilla pools.
79
- uint24[4] public V4_FEES = [uint24(3000), uint24(500), uint24(10_000), uint24(100)];
80
- int24[4] public V4_TICK_SPACINGS = [int24(60), int24(10), int24(200), int24(1)];
81
-
82
- /// @notice The denominator used for slippage tolerance basis points.
83
- uint256 public constant SLIPPAGE_DENOMINATOR = 10_000;
86
+ uint24[4] internal _V4_FEES = [uint24(3000), uint24(500), uint24(10_000), uint24(100)];
87
+ int24[4] internal _V4_TICK_SPACINGS = [int24(60), int24(10), int24(200), int24(1)];
84
88
 
85
89
  //*********************************************************************//
86
90
  // ---------------- public immutable stored properties --------------- //
@@ -607,46 +611,32 @@ contract JBRouterTerminal is
607
611
  function _bestPoolLiquidity(address tokenA, address tokenB) internal view returns (uint128 bestLiquidity) {
608
612
  // Search V3.
609
613
  for (uint256 i; i < 4; i++) {
610
- address poolAddr = FACTORY.getPool(tokenA, tokenB, FEE_TIERS[i]);
614
+ address poolAddr = FACTORY.getPool(tokenA, tokenB, _FEE_TIERS[i]);
611
615
  if (poolAddr == address(0)) continue;
612
616
 
613
617
  uint128 liquidity = IUniswapV3Pool(poolAddr).liquidity();
614
618
  if (liquidity > bestLiquidity) bestLiquidity = liquidity;
615
619
  }
616
620
 
617
- // Search V4.
618
- uint128 v4Best = _bestV4PoolLiquidity(tokenA, tokenB);
619
- if (v4Best > bestLiquidity) bestLiquidity = v4Best;
620
- }
621
-
622
- /// @notice Find the highest liquidity across V4 vanilla pools for a token pair.
623
- /// @param tokenA One token in the pair.
624
- /// @param tokenB The other token in the pair.
625
- /// @return bestLiquidity The highest liquidity found across V4 pools.
626
- function _bestV4PoolLiquidity(address tokenA, address tokenB) internal view returns (uint128 bestLiquidity) {
627
- if (address(POOL_MANAGER) == address(0)) return 0;
628
-
629
- // Convert WETH -> address(0) for V4 native ETH representation.
630
- address v4A = tokenA == address(WETH) ? address(0) : tokenA;
631
- address v4B = tokenB == address(WETH) ? address(0) : tokenB;
632
-
633
- // Sort currencies (currency0 < currency1).
634
- (address sorted0, address sorted1) = v4A < v4B ? (v4A, v4B) : (v4B, v4A);
635
-
636
- for (uint256 i; i < 4; i++) {
637
- PoolKey memory key = PoolKey({
638
- currency0: Currency.wrap(sorted0),
639
- currency1: Currency.wrap(sorted1),
640
- fee: V4_FEES[i],
641
- tickSpacing: V4_TICK_SPACINGS[i],
642
- hooks: IHooks(address(0))
643
- });
644
-
645
- (uint160 sqrtPriceX96,,,) = POOL_MANAGER.getSlot0(key.toId());
646
- if (sqrtPriceX96 == 0) continue;
647
-
648
- uint128 liquidity = POOL_MANAGER.getLiquidity(key.toId());
649
- if (liquidity > bestLiquidity) bestLiquidity = liquidity;
621
+ // Search V4 — reuse _discoverV4Pool with current best.
622
+ PoolInfo memory v4Result = _discoverV4Pool(
623
+ tokenA,
624
+ tokenB,
625
+ bestLiquidity,
626
+ PoolInfo({
627
+ isV4: false,
628
+ v3Pool: IUniswapV3Pool(address(0)),
629
+ v4Key: PoolKey({
630
+ currency0: Currency.wrap(address(0)),
631
+ currency1: Currency.wrap(address(0)),
632
+ fee: 0,
633
+ tickSpacing: 0,
634
+ hooks: IHooks(address(0))
635
+ })
636
+ })
637
+ );
638
+ if (v4Result.isV4) {
639
+ bestLiquidity = POOL_MANAGER.getLiquidity(v4Result.v4Key.toId());
650
640
  }
651
641
  }
652
642
 
@@ -986,7 +976,7 @@ contract JBRouterTerminal is
986
976
 
987
977
  // Search V3.
988
978
  for (uint256 i; i < 4; i++) {
989
- address poolAddr = FACTORY.getPool(normalizedTokenIn, normalizedTokenOut, FEE_TIERS[i]);
979
+ address poolAddr = FACTORY.getPool(normalizedTokenIn, normalizedTokenOut, _FEE_TIERS[i]);
990
980
 
991
981
  if (poolAddr == address(0)) continue;
992
982
 
@@ -994,7 +984,17 @@ contract JBRouterTerminal is
994
984
 
995
985
  if (poolLiquidity > bestLiquidity) {
996
986
  bestLiquidity = poolLiquidity;
997
- bestPool = PoolInfo({isV4: false, v3Pool: IUniswapV3Pool(poolAddr), v4Key: _emptyPoolKey()});
987
+ bestPool = PoolInfo({
988
+ isV4: false,
989
+ v3Pool: IUniswapV3Pool(poolAddr),
990
+ v4Key: PoolKey({
991
+ currency0: Currency.wrap(address(0)),
992
+ currency1: Currency.wrap(address(0)),
993
+ fee: 0,
994
+ tickSpacing: 0,
995
+ hooks: IHooks(address(0))
996
+ })
997
+ });
998
998
  }
999
999
  }
1000
1000
 
@@ -1030,8 +1030,8 @@ contract JBRouterTerminal is
1030
1030
  PoolKey memory key = PoolKey({
1031
1031
  currency0: Currency.wrap(sorted0),
1032
1032
  currency1: Currency.wrap(sorted1),
1033
- fee: V4_FEES[i],
1034
- tickSpacing: V4_TICK_SPACINGS[i],
1033
+ fee: _V4_FEES[i],
1034
+ tickSpacing: _V4_TICK_SPACINGS[i],
1035
1035
  hooks: IHooks(address(0))
1036
1036
  });
1037
1037
 
@@ -1309,17 +1309,6 @@ contract JBRouterTerminal is
1309
1309
  PERMIT2.transferFrom(from, to, uint160(amount), token);
1310
1310
  }
1311
1311
 
1312
- /// @notice Returns an empty PoolKey for use in V3-only PoolInfo structs.
1313
- function _emptyPoolKey() internal pure returns (PoolKey memory) {
1314
- return PoolKey({
1315
- currency0: Currency.wrap(address(0)),
1316
- currency1: Currency.wrap(address(0)),
1317
- fee: 0,
1318
- tickSpacing: 0,
1319
- hooks: IHooks(address(0))
1320
- });
1321
- }
1322
-
1323
1312
  //*********************************************************************//
1324
1313
  // ---------------------------- receive ----------------------------- //
1325
1314
  //*********************************************************************//