@bananapus/router-terminal-v6 0.0.55 → 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.
|
|
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.
|
|
28
|
-
"@bananapus/core-v6": "^0.0.
|
|
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.
|
|
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",
|
|
@@ -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 *
|
|
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
|
|
17
|
+
uint256 internal constant _IMPACT_PRECISION = 1e18;
|
|
24
18
|
|
|
25
|
-
/// @notice The
|
|
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 /
|
|
24
|
+
/// K_new / _IMPACT_PRECISION = K_old / (10 * _SLIPPAGE_DENOMINATOR)
|
|
28
25
|
/// → K_new = 5000 * 1e18 / 1e5 = 5e16
|
|
29
|
-
uint256 internal constant
|
|
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
|
|
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
|
|
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 >=
|
|
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 >=
|
|
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 -
|
|
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 =
|
|
58
|
-
uint256 tolerance = minSlippage + mulDiv({x: range, y: impact, denominator: impact +
|
|
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
|
|
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
|
|
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:
|
|
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
|