feat: Verify that no amount in is left in the router
--- don't change below this line --- ENG-4087 Took 1 hour 41 minutes Took 2 minutes
This commit is contained in:
@@ -18,6 +18,7 @@ import {LibSwap} from "../lib/LibSwap.sol";
|
||||
error TychoRouter__WithdrawalFailed();
|
||||
error TychoRouter__AddressZero();
|
||||
error TychoRouter__NegativeSlippage(uint256 amount, uint256 minAmount);
|
||||
error TychoRouter__AmountInNotFullySpent(uint256 leftoverAmount);
|
||||
error TychoRouter__MessageValueMismatch(uint256 value, uint256 amount);
|
||||
|
||||
contract TychoRouter is
|
||||
@@ -153,6 +154,7 @@ contract TychoRouter is
|
||||
// For native ETH, assume funds already in our router. Else, transfer and handle approval.
|
||||
if (wrapEth) {
|
||||
_wrapETH(amountIn);
|
||||
tokenIn = address(_weth);
|
||||
} else if (tokenIn != address(0)) {
|
||||
permit2.permit(msg.sender, permitSingle, signature);
|
||||
permit2.transferFrom(
|
||||
@@ -175,6 +177,11 @@ contract TychoRouter is
|
||||
revert TychoRouter__NegativeSlippage(amountOut, minAmountOut);
|
||||
}
|
||||
|
||||
uint256 leftoverAmountIn = IERC20(tokenIn).balanceOf(address(this));
|
||||
if (leftoverAmountIn > 0) {
|
||||
revert TychoRouter__AmountInNotFullySpent(leftoverAmountIn);
|
||||
}
|
||||
|
||||
if (unwrapEth) {
|
||||
_unwrapETH(amountOut);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user