@bananapus/router-terminal-v6 0.0.12 → 0.0.13
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 +1 -1
- package/src/JBRouterTerminal.sol +56 -41
package/package.json
CHANGED
package/src/JBRouterTerminal.sol
CHANGED
|
@@ -300,6 +300,50 @@ contract JBRouterTerminal is
|
|
|
300
300
|
return token == JBConstants.NATIVE_TOKEN ? address(WETH) : token;
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
+
/// @notice Get a minimum-amount-out quote at the given tick, applying dynamic slippage.
|
|
304
|
+
/// @param amount The input amount.
|
|
305
|
+
/// @param liquidity The pool's in-range liquidity.
|
|
306
|
+
/// @param tokenIn The input token address (used for token sorting and quoting).
|
|
307
|
+
/// @param tokenOut The output token address (used for token sorting and quoting).
|
|
308
|
+
/// @param tick The tick to quote at (TWAP mean tick or spot tick).
|
|
309
|
+
/// @param poolFeeBps The pool fee in basis points.
|
|
310
|
+
/// @return minAmountOut The quoted output amount after slippage.
|
|
311
|
+
function _quoteWithSlippage(
|
|
312
|
+
uint256 amount,
|
|
313
|
+
uint128 liquidity,
|
|
314
|
+
address tokenIn,
|
|
315
|
+
address tokenOut,
|
|
316
|
+
int24 tick,
|
|
317
|
+
uint256 poolFeeBps
|
|
318
|
+
)
|
|
319
|
+
internal
|
|
320
|
+
pure
|
|
321
|
+
returns (uint256 minAmountOut)
|
|
322
|
+
{
|
|
323
|
+
uint256 slippageTolerance = _getSlippageTolerance({
|
|
324
|
+
amountIn: amount,
|
|
325
|
+
liquidity: liquidity,
|
|
326
|
+
tokenOut: tokenOut,
|
|
327
|
+
tokenIn: tokenIn,
|
|
328
|
+
arithmeticMeanTick: tick,
|
|
329
|
+
poolFeeBps: poolFeeBps
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
if (slippageTolerance >= SLIPPAGE_DENOMINATOR) return 0;
|
|
333
|
+
|
|
334
|
+
if (amount > type(uint128).max) revert JBRouterTerminal_AmountOverflow(amount);
|
|
335
|
+
|
|
336
|
+
minAmountOut = OracleLibrary.getQuoteAtTick({
|
|
337
|
+
tick: tick,
|
|
338
|
+
// forge-lint: disable-next-line(unsafe-typecast)
|
|
339
|
+
baseAmount: uint128(amount),
|
|
340
|
+
baseToken: tokenIn,
|
|
341
|
+
quoteToken: tokenOut
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
minAmountOut -= (minAmountOut * slippageTolerance) / SLIPPAGE_DENOMINATOR;
|
|
345
|
+
}
|
|
346
|
+
|
|
303
347
|
//*********************************************************************//
|
|
304
348
|
// ---------------------- external transactions ---------------------- //
|
|
305
349
|
//*********************************************************************//
|
|
@@ -1074,29 +1118,14 @@ contract JBRouterTerminal is
|
|
|
1074
1118
|
|
|
1075
1119
|
if (liquidity == 0) revert JBRouterTerminal_NoLiquidity();
|
|
1076
1120
|
|
|
1077
|
-
{
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
});
|
|
1086
|
-
|
|
1087
|
-
if (slippageTolerance >= SLIPPAGE_DENOMINATOR) return 0;
|
|
1088
|
-
|
|
1089
|
-
if (amount > type(uint128).max) revert JBRouterTerminal_AmountOverflow(amount);
|
|
1090
|
-
minAmountOut = OracleLibrary.getQuoteAtTick({
|
|
1091
|
-
tick: arithmeticMeanTick,
|
|
1092
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
1093
|
-
baseAmount: uint128(amount),
|
|
1094
|
-
baseToken: normalizedTokenIn,
|
|
1095
|
-
quoteToken: normalizedTokenOut
|
|
1096
|
-
});
|
|
1097
|
-
|
|
1098
|
-
minAmountOut -= (minAmountOut * slippageTolerance) / SLIPPAGE_DENOMINATOR;
|
|
1099
|
-
}
|
|
1121
|
+
minAmountOut = _quoteWithSlippage({
|
|
1122
|
+
amount: amount,
|
|
1123
|
+
liquidity: liquidity,
|
|
1124
|
+
tokenIn: normalizedTokenIn,
|
|
1125
|
+
tokenOut: normalizedTokenOut,
|
|
1126
|
+
tick: arithmeticMeanTick,
|
|
1127
|
+
poolFeeBps: feeBps
|
|
1128
|
+
});
|
|
1100
1129
|
}
|
|
1101
1130
|
|
|
1102
1131
|
/// @notice Get a spot-price-based quote with dynamic slippage for a V4 pool.
|
|
@@ -1141,28 +1170,14 @@ contract JBRouterTerminal is
|
|
|
1141
1170
|
normalizedTokenIn = normalizedTokenIn == address(WETH) ? address(0) : normalizedTokenIn;
|
|
1142
1171
|
normalizedTokenOut = normalizedTokenOut == address(WETH) ? address(0) : normalizedTokenOut;
|
|
1143
1172
|
|
|
1144
|
-
|
|
1145
|
-
|
|
1173
|
+
minAmountOut = _quoteWithSlippage({
|
|
1174
|
+
amount: amount,
|
|
1146
1175
|
liquidity: liquidity,
|
|
1147
|
-
tokenOut: normalizedTokenOut,
|
|
1148
1176
|
tokenIn: normalizedTokenIn,
|
|
1149
|
-
|
|
1150
|
-
poolFeeBps: uint256(key.fee) / 100
|
|
1151
|
-
});
|
|
1152
|
-
|
|
1153
|
-
if (slippageTolerance >= SLIPPAGE_DENOMINATOR) return 0;
|
|
1154
|
-
|
|
1155
|
-
if (amount > type(uint128).max) revert JBRouterTerminal_AmountOverflow(amount);
|
|
1156
|
-
|
|
1157
|
-
minAmountOut = OracleLibrary.getQuoteAtTick({
|
|
1177
|
+
tokenOut: normalizedTokenOut,
|
|
1158
1178
|
tick: tick,
|
|
1159
|
-
|
|
1160
|
-
baseAmount: uint128(amount),
|
|
1161
|
-
baseToken: normalizedTokenIn,
|
|
1162
|
-
quoteToken: normalizedTokenOut
|
|
1179
|
+
poolFeeBps: uint256(key.fee) / 100
|
|
1163
1180
|
});
|
|
1164
|
-
|
|
1165
|
-
minAmountOut -= (minAmountOut * slippageTolerance) / SLIPPAGE_DENOMINATOR;
|
|
1166
1181
|
}
|
|
1167
1182
|
|
|
1168
1183
|
/// @notice Execute a Uniswap swap from tokenIn to tokenOut (V3 or V4).
|