fix: Remove checkMinAmount

If minAmountOut == 0, then skip the check

--- don't change below this line ---
ENG-4041 Took 35 minutes
This commit is contained in:
Diana Carvalho
2025-01-28 10:26:38 +00:00
parent 50429ad05c
commit d8de65aedf
2 changed files with 4 additions and 13 deletions

View File

@@ -97,13 +97,12 @@ contract TychoRouter is
* - For ERC20 tokens, Permit2 is used to approve and transfer tokens from the caller to the router.
* - Swaps are executed sequentially using the `_splitSwap` function.
* - A fee is deducted from the output token if `fee > 0`, and the remaining amount is sent to the receiver.
* - Reverts with `TychoRouter__NegativeSlippage` if the output amount is less than `minAmountOut` and `checkMinAmount` is true.
* - Reverts with `TychoRouter__NegativeSlippage` if the output amount is less than `minAmountOut` and `minAmountOut` is bigger than 0.
*
* @param amountIn The input token amount to be swapped.
* @param tokenIn The address of the input token. Use `address(0)` for native ETH when `wrapEth` is true.
* @param tokenOut The address of the output token. Use `address(0)` for native ETH when `unwrapEth` is true.
* @param checkMinAmount A boolean indicating whether to enforce the `minAmountOut` check.
* @param minAmountOut The minimum acceptable amount of the output token. Reverts if this condition is not met.
* @param minAmountOut The minimum acceptable amount of the output token. Reverts if this condition is not met. If it's 0, no check is performed.
* @param wrapEth If true, treats the input token as native ETH and wraps it into WETH.
* @param unwrapEth If true, unwraps the resulting WETH into native ETH and sends it to the receiver.
* @param nTokens The total number of tokens involved in the swap graph (used to initialize arrays for internal calculations).
@@ -118,7 +117,6 @@ contract TychoRouter is
uint256 amountIn,
address tokenIn,
address tokenOut,
bool checkMinAmount,
uint256 minAmountOut,
bool wrapEth,
bool unwrapEth,
@@ -131,8 +129,7 @@ contract TychoRouter is
// For native ETH, assume funds already in our router. Else, transfer and handle approval.
if (wrapEth) {
_wrapETH(amountIn);
} else {
if (tokenIn != address(0)) {
} else if (tokenIn != address(0)) {
permit2.permit(msg.sender, permitSingle, signature);
permit2.transferFrom(
msg.sender,
@@ -140,7 +137,6 @@ contract TychoRouter is
uint160(amountIn),
permitSingle.details.token
);
}
}
amountOut = _splitSwap(amountIn, nTokens, swaps);
@@ -154,7 +150,7 @@ contract TychoRouter is
}
}
if (checkMinAmount && amountOut < minAmountOut) {
if (minAmountOut > 0 && amountOut < minAmountOut) {
revert TychoRouter__NegativeSlippage(amountOut, minAmountOut);
}