@bananapus/suckers-v6 0.0.60 → 0.0.61
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 +3 -3
- package/src/libraries/JBSwapLib.sol +15 -15
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bananapus/suckers-v6",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.61",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/Bananapus/nana-suckers-v6"
|
|
7
|
+
"url": "git+https://github.com/Bananapus/nana-suckers-v6.git"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"foundry.toml",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@arbitrum/nitro-contracts": "3.2.0",
|
|
29
|
-
"@bananapus/core-v6": "^0.0.
|
|
29
|
+
"@bananapus/core-v6": "^0.0.72",
|
|
30
30
|
"@bananapus/permission-ids-v6": "^0.0.27",
|
|
31
31
|
"@chainlink/contracts-ccip": "1.6.4",
|
|
32
32
|
"@chainlink/local": "0.2.7",
|
|
@@ -9,19 +9,19 @@ import {TickMath} from "@uniswap/v3-core/contracts/libraries/TickMath.sol";
|
|
|
9
9
|
/// @dev Uses continuous sigmoid formula for smooth slippage tolerance across all swap sizes.
|
|
10
10
|
library JBSwapLib {
|
|
11
11
|
/// @notice The denominator used for slippage tolerance basis points.
|
|
12
|
-
uint256 internal constant
|
|
12
|
+
uint256 internal constant _SLIPPAGE_DENOMINATOR = 10_000;
|
|
13
13
|
|
|
14
14
|
/// @notice The maximum slippage ceiling (88%).
|
|
15
|
-
uint256 internal constant
|
|
15
|
+
uint256 internal constant _MAX_SLIPPAGE = 8800;
|
|
16
16
|
|
|
17
17
|
/// @notice The precision multiplier for impact calculations.
|
|
18
18
|
/// @dev Using 1e18 instead of 1e5 gives 13 extra orders of magnitude,
|
|
19
19
|
/// preventing small-swap-in-deep-pool impacts from rounding to zero.
|
|
20
|
-
uint256 internal constant
|
|
20
|
+
uint256 internal constant _IMPACT_PRECISION = 1e18;
|
|
21
21
|
|
|
22
|
-
/// @notice The K parameter for the sigmoid curve, scaled to match
|
|
22
|
+
/// @notice The K parameter for the sigmoid curve, scaled to match _IMPACT_PRECISION.
|
|
23
23
|
/// @dev K_new = 5000 * 1e18 / 1e5 = 5e16
|
|
24
|
-
uint256 internal constant
|
|
24
|
+
uint256 internal constant _SIGMOID_K = 5e16;
|
|
25
25
|
|
|
26
26
|
//*********************************************************************//
|
|
27
27
|
// -------------------- Slippage Tolerance -------------------------- //
|
|
@@ -29,22 +29,22 @@ library JBSwapLib {
|
|
|
29
29
|
|
|
30
30
|
/// @notice Compute a continuous sigmoid slippage tolerance based on swap impact and pool fee.
|
|
31
31
|
/// @dev tolerance = minSlippage + (maxSlippage - minSlippage) * impact / (impact + K)
|
|
32
|
-
/// @param impact The estimated price impact from calculateImpact (scaled by
|
|
32
|
+
/// @param impact The estimated price impact from calculateImpact (scaled by _IMPACT_PRECISION).
|
|
33
33
|
/// @param poolFeeBps The pool fee in basis points (e.g., 30 for 0.3%).
|
|
34
|
-
/// @return tolerance The slippage tolerance in basis points of
|
|
34
|
+
/// @return tolerance The slippage tolerance in basis points of _SLIPPAGE_DENOMINATOR.
|
|
35
35
|
function getSlippageTolerance(uint256 impact, uint256 poolFeeBps) internal pure returns (uint256) {
|
|
36
|
-
if (poolFeeBps >=
|
|
36
|
+
if (poolFeeBps >= _MAX_SLIPPAGE) return _MAX_SLIPPAGE;
|
|
37
37
|
|
|
38
38
|
uint256 minSlippage = poolFeeBps + 100;
|
|
39
39
|
if (minSlippage < 200) minSlippage = 200;
|
|
40
|
-
if (minSlippage >=
|
|
40
|
+
if (minSlippage >= _MAX_SLIPPAGE) return _MAX_SLIPPAGE;
|
|
41
41
|
|
|
42
42
|
if (impact == 0) return minSlippage;
|
|
43
43
|
|
|
44
|
-
if (impact > type(uint256).max -
|
|
44
|
+
if (impact > type(uint256).max - _SIGMOID_K) return _MAX_SLIPPAGE;
|
|
45
45
|
|
|
46
|
-
uint256 range =
|
|
47
|
-
uint256 tolerance = minSlippage + mulDiv({x: range, y: impact, denominator: impact +
|
|
46
|
+
uint256 range = _MAX_SLIPPAGE - minSlippage;
|
|
47
|
+
uint256 tolerance = minSlippage + mulDiv({x: range, y: impact, denominator: impact + _SIGMOID_K});
|
|
48
48
|
|
|
49
49
|
return tolerance;
|
|
50
50
|
}
|
|
@@ -53,12 +53,12 @@ library JBSwapLib {
|
|
|
53
53
|
// -------------------- Impact Calculation -------------------------- //
|
|
54
54
|
//*********************************************************************//
|
|
55
55
|
|
|
56
|
-
/// @notice Estimate the price impact of a swap, scaled by
|
|
56
|
+
/// @notice Estimate the price impact of a swap, scaled by _IMPACT_PRECISION.
|
|
57
57
|
/// @param amountIn The amount of tokens to swap in.
|
|
58
58
|
/// @param liquidity The pool's in-range liquidity.
|
|
59
59
|
/// @param sqrtP The sqrt price in Q96 format.
|
|
60
60
|
/// @param zeroForOne Whether the swap is token0 -> token1.
|
|
61
|
-
/// @return impact The estimated price impact scaled by
|
|
61
|
+
/// @return impact The estimated price impact scaled by _IMPACT_PRECISION.
|
|
62
62
|
function calculateImpact(
|
|
63
63
|
uint256 amountIn,
|
|
64
64
|
uint128 liquidity,
|
|
@@ -71,7 +71,7 @@ library JBSwapLib {
|
|
|
71
71
|
{
|
|
72
72
|
if (liquidity == 0 || sqrtP == 0) return 0;
|
|
73
73
|
|
|
74
|
-
uint256 base = mulDiv({x: amountIn, y:
|
|
74
|
+
uint256 base = mulDiv({x: amountIn, y: _IMPACT_PRECISION, denominator: uint256(liquidity)});
|
|
75
75
|
|
|
76
76
|
impact = zeroForOne
|
|
77
77
|
? mulDiv({x: base, y: uint256(sqrtP), denominator: uint256(1) << 96})
|