@bananapus/router-terminal-v6 0.0.54 → 0.0.56

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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@bananapus/router-terminal-v6",
3
- "version": "0.0.54",
3
+ "version": "0.0.56",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/Bananapus/nana-router-terminal-v6"
7
+ "url": "git+https://github.com/Bananapus/nana-router-terminal-v6.git"
8
8
  },
9
9
  "files": [
10
10
  "foundry.toml",
@@ -24,10 +24,10 @@
24
24
  "artifacts": "source ./.env && npx sphinx artifacts --org-id 'ea165b21-7cdc-4d7b-be59-ecdd4c26bee4' --project-name 'nana-router-terminal-v6'"
25
25
  },
26
26
  "dependencies": {
27
- "@bananapus/buyback-hook-v6": "^0.0.55",
28
- "@bananapus/core-v6": "^0.0.68",
27
+ "@bananapus/buyback-hook-v6": "^0.0.58",
28
+ "@bananapus/core-v6": "^0.0.72",
29
29
  "@bananapus/permission-ids-v6": "^0.0.27",
30
- "@bananapus/univ4-router-v6": "^0.0.40",
30
+ "@bananapus/univ4-router-v6": "^0.0.46",
31
31
  "@openzeppelin/contracts": "5.6.1",
32
32
  "@uniswap/permit2": "github:Uniswap/permit2#cc56ad0f3439c502c246fc5cfcc3db92bb8b7219",
33
33
  "@uniswap/v3-core": "github:Uniswap/v3-core#6562c52e8f75f0c10f9deaf44861847585fc8129",
@@ -2532,6 +2532,7 @@ contract JBRouterTerminal is
2532
2532
  sourceProjectId: sourceProjectId,
2533
2533
  destProjectId: destProjectId,
2534
2534
  amount: amount,
2535
+ metadata: i == 0 ? metadata : bytes(""),
2535
2536
  preferredToken: preferredToken
2536
2537
  });
2537
2538
 
@@ -2559,12 +2560,14 @@ contract JBRouterTerminal is
2559
2560
  /// @param sourceProjectId The project to cash out tokens from.
2560
2561
  /// @param destProjectId The final destination project to pay.
2561
2562
  /// @param amount The amount of source-project tokens to cash out.
2563
+ /// @param metadata Metadata forwarded into the source terminal preview for this hop.
2562
2564
  /// @return tokenToReclaim The token that would be reclaimed from the source terminal.
2563
2565
  /// @return reclaimAmount The amount of that token that would be reclaimed.
2564
2566
  function _previewCashOutStep(
2565
2567
  uint256 sourceProjectId,
2566
2568
  uint256 destProjectId,
2567
2569
  uint256 amount,
2570
+ bytes memory metadata,
2568
2571
  address preferredToken
2569
2572
  )
2570
2573
  internal
@@ -2587,7 +2590,7 @@ contract JBRouterTerminal is
2587
2590
  cashOutCount: amount,
2588
2591
  tokenToReclaim: tokenToReclaim,
2589
2592
  beneficiary: payable(address(this)),
2590
- metadata: ""
2593
+ metadata: metadata
2591
2594
  });
2592
2595
 
2593
2596
  // Deployment config makes this router a feeless cash-out beneficiary, so previews use the terminal's raw
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.0;
2
+ pragma solidity 0.8.28;
3
3
 
4
4
  import {IJBTerminal} from "@bananapus/core-v6/src/interfaces/IJBTerminal.sol";
5
5
  import {IJBForwardingTerminal} from "../interfaces/IJBForwardingTerminal.sol";
@@ -11,22 +11,22 @@ import {TickMath} from "@uniswap/v3-core/contracts/libraries/TickMath.sol";
11
11
  /// @dev Uses continuous sigmoid formula instead of stepped if/else brackets for smoother slippage tolerance across all
12
12
  /// swap sizes. Floor of 2% (or pool fee + 1%), ceiling of 88%.
13
13
  library JBSwapLib {
14
- /// @notice The denominator used for slippage tolerance basis points.
15
- uint256 internal constant SLIPPAGE_DENOMINATOR = 10_000;
16
-
17
- /// @notice The maximum slippage ceiling (88%).
18
- uint256 internal constant MAX_SLIPPAGE = 8800;
19
-
20
14
  /// @notice The precision multiplier for impact calculations.
21
- /// @dev Using 1e18 instead of 1e5 (10 * SLIPPAGE_DENOMINATOR) gives 13 extra orders of magnitude,
15
+ /// @dev Using 1e18 instead of 1e5 (10 * _SLIPPAGE_DENOMINATOR) gives 13 extra orders of magnitude,
22
16
  /// preventing small-swap-in-deep-pool impacts from rounding to zero.
23
- uint256 internal constant IMPACT_PRECISION = 1e18;
17
+ uint256 internal constant _IMPACT_PRECISION = 1e18;
24
18
 
25
- /// @notice The K parameter for the sigmoid curve, scaled to match IMPACT_PRECISION.
19
+ /// @notice The maximum slippage ceiling (88%).
20
+ uint256 internal constant _MAX_SLIPPAGE = 8800;
21
+
22
+ /// @notice The K parameter for the sigmoid curve, scaled to match _IMPACT_PRECISION.
26
23
  /// @dev Preserves the same sigmoid shape as the original K=5000 with amplifier=1e5:
27
- /// K_new / IMPACT_PRECISION = K_old / (10 * SLIPPAGE_DENOMINATOR)
24
+ /// K_new / _IMPACT_PRECISION = K_old / (10 * _SLIPPAGE_DENOMINATOR)
28
25
  /// → K_new = 5000 * 1e18 / 1e5 = 5e16
29
- uint256 internal constant SIGMOID_K = 5e16;
26
+ uint256 internal constant _SIGMOID_K = 5e16;
27
+
28
+ /// @notice The denominator used for slippage tolerance basis points.
29
+ uint256 internal constant _SLIPPAGE_DENOMINATOR = 10_000;
30
30
 
31
31
  //*********************************************************************//
32
32
  // -------------------- Slippage Tolerance -------------------------- //
@@ -35,27 +35,27 @@ library JBSwapLib {
35
35
  /// @notice Compute a continuous sigmoid slippage tolerance based on swap impact and pool fee.
36
36
  /// @dev tolerance = minSlippage + (maxSlippage - minSlippage) * impact / (impact + K)
37
37
  /// When impact is 0 (negligible swap in deep pool), returns minSlippage.
38
- /// @param impact The estimated price impact from calculateImpact (scaled by IMPACT_PRECISION).
38
+ /// @param impact The estimated price impact from calculateImpact (scaled by _IMPACT_PRECISION).
39
39
  /// @param poolFeeBps The pool fee in basis points (e.g., 30 for 0.3%).
40
- /// @return tolerance The slippage tolerance in basis points of SLIPPAGE_DENOMINATOR.
40
+ /// @return tolerance The slippage tolerance in basis points of _SLIPPAGE_DENOMINATOR.
41
41
  function getSlippageTolerance(uint256 impact, uint256 poolFeeBps) internal pure returns (uint256) {
42
42
  // If pool fee alone meets/exceeds the ceiling, return the ceiling.
43
- if (poolFeeBps >= MAX_SLIPPAGE) return MAX_SLIPPAGE;
43
+ if (poolFeeBps >= _MAX_SLIPPAGE) return _MAX_SLIPPAGE;
44
44
 
45
45
  // Minimum slippage: at least pool fee + 1% buffer, with a floor of 2%.
46
46
  uint256 minSlippage = poolFeeBps + 100;
47
47
  if (minSlippage < 200) minSlippage = 200;
48
- if (minSlippage >= MAX_SLIPPAGE) return MAX_SLIPPAGE;
48
+ if (minSlippage >= _MAX_SLIPPAGE) return _MAX_SLIPPAGE;
49
49
 
50
50
  // When impact is 0, sigmoid returns minSlippage directly.
51
51
  if (impact == 0) return minSlippage;
52
52
 
53
53
  // For extreme impact values, cap to prevent overflow in (impact + K).
54
- if (impact > type(uint256).max - SIGMOID_K) return MAX_SLIPPAGE;
54
+ if (impact > type(uint256).max - _SIGMOID_K) return _MAX_SLIPPAGE;
55
55
 
56
56
  // Sigmoid: minSlippage + (maxSlippage - minSlippage) * impact / (impact + K)
57
- uint256 range = MAX_SLIPPAGE - minSlippage;
58
- uint256 tolerance = minSlippage + mulDiv({x: range, y: impact, denominator: impact + SIGMOID_K});
57
+ uint256 range = _MAX_SLIPPAGE - minSlippage;
58
+ uint256 tolerance = minSlippage + mulDiv({x: range, y: impact, denominator: impact + _SIGMOID_K});
59
59
 
60
60
  // Return the bounded tolerance implied by the sigmoid curve.
61
61
  return tolerance;
@@ -65,13 +65,13 @@ library JBSwapLib {
65
65
  // -------------------- Impact Calculation -------------------------- //
66
66
  //*********************************************************************//
67
67
 
68
- /// @notice Estimate the price impact of a swap, scaled by IMPACT_PRECISION.
68
+ /// @notice Estimate the price impact of a swap, scaled by _IMPACT_PRECISION.
69
69
  /// @dev Uses 1e18 precision to capture sub-basis-point impacts for small swaps in deep pools.
70
70
  /// @param amountIn The amount of tokens to swap in.
71
71
  /// @param liquidity The pool's in-range liquidity.
72
72
  /// @param sqrtP The sqrt price in Q96 format.
73
73
  /// @param zeroForOne Whether the swap is token0 → token1.
74
- /// @return impact The estimated price impact scaled by IMPACT_PRECISION.
74
+ /// @return impact The estimated price impact scaled by _IMPACT_PRECISION.
75
75
  function calculateImpact(
76
76
  uint256 amountIn,
77
77
  uint128 liquidity,
@@ -86,7 +86,7 @@ library JBSwapLib {
86
86
  if (liquidity == 0 || sqrtP == 0) return 0;
87
87
 
88
88
  // Scale the input amount against the pool liquidity so impact is expressed in the library's precision space.
89
- uint256 base = mulDiv({x: amountIn, y: IMPACT_PRECISION, denominator: uint256(liquidity)});
89
+ uint256 base = mulDiv({x: amountIn, y: _IMPACT_PRECISION, denominator: uint256(liquidity)});
90
90
 
91
91
  // Convert the liquidity-scaled input into a direction-aware price impact estimate.
92
92
  impact = zeroForOne