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:
@@ -97,13 +97,12 @@ contract TychoRouter is
|
|||||||
* - For ERC20 tokens, Permit2 is used to approve and transfer tokens from the caller to the router.
|
* - 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.
|
* - 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.
|
* - 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 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 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 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. If it's 0, no check is performed.
|
||||||
* @param minAmountOut The minimum acceptable amount of the output token. Reverts if this condition is not met.
|
|
||||||
* @param wrapEth If true, treats the input token as native ETH and wraps it into WETH.
|
* @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 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).
|
* @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,
|
uint256 amountIn,
|
||||||
address tokenIn,
|
address tokenIn,
|
||||||
address tokenOut,
|
address tokenOut,
|
||||||
bool checkMinAmount,
|
|
||||||
uint256 minAmountOut,
|
uint256 minAmountOut,
|
||||||
bool wrapEth,
|
bool wrapEth,
|
||||||
bool unwrapEth,
|
bool unwrapEth,
|
||||||
@@ -131,8 +129,7 @@ contract TychoRouter is
|
|||||||
// For native ETH, assume funds already in our router. Else, transfer and handle approval.
|
// For native ETH, assume funds already in our router. Else, transfer and handle approval.
|
||||||
if (wrapEth) {
|
if (wrapEth) {
|
||||||
_wrapETH(amountIn);
|
_wrapETH(amountIn);
|
||||||
} else {
|
} else if (tokenIn != address(0)) {
|
||||||
if (tokenIn != address(0)) {
|
|
||||||
permit2.permit(msg.sender, permitSingle, signature);
|
permit2.permit(msg.sender, permitSingle, signature);
|
||||||
permit2.transferFrom(
|
permit2.transferFrom(
|
||||||
msg.sender,
|
msg.sender,
|
||||||
@@ -141,7 +138,6 @@ contract TychoRouter is
|
|||||||
permitSingle.details.token
|
permitSingle.details.token
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
amountOut = _splitSwap(amountIn, nTokens, swaps);
|
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);
|
revert TychoRouter__NegativeSlippage(amountOut, minAmountOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -351,7 +351,6 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
amount_in,
|
amount_in,
|
||||||
WETH_ADDR,
|
WETH_ADDR,
|
||||||
DAI_ADDR,
|
DAI_ADDR,
|
||||||
true,
|
|
||||||
minAmountOut,
|
minAmountOut,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
@@ -403,7 +402,6 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
amount_in,
|
amount_in,
|
||||||
WETH_ADDR,
|
WETH_ADDR,
|
||||||
DAI_ADDR,
|
DAI_ADDR,
|
||||||
true,
|
|
||||||
minAmountOut,
|
minAmountOut,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
@@ -449,7 +447,6 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
amount_in,
|
amount_in,
|
||||||
WETH_ADDR,
|
WETH_ADDR,
|
||||||
DAI_ADDR,
|
DAI_ADDR,
|
||||||
false,
|
|
||||||
0,
|
0,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
@@ -498,7 +495,6 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
amount_in,
|
amount_in,
|
||||||
address(0),
|
address(0),
|
||||||
DAI_ADDR,
|
DAI_ADDR,
|
||||||
false,
|
|
||||||
0,
|
0,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
@@ -542,7 +538,6 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
amount_in,
|
amount_in,
|
||||||
DAI_ADDR,
|
DAI_ADDR,
|
||||||
address(0),
|
address(0),
|
||||||
false,
|
|
||||||
0,
|
0,
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
|
|||||||
Reference in New Issue
Block a user