From 353861f7385b8dff191a8a9e73657f1e226bc481 Mon Sep 17 00:00:00 2001 From: royvardhan Date: Wed, 26 Feb 2025 20:49:19 +0530 Subject: [PATCH] refactor: update unwrapEth to only check 0 amount --- foundry/src/TychoRouter.sol | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/foundry/src/TychoRouter.sol b/foundry/src/TychoRouter.sol index c29ad40..6ae3e55 100644 --- a/foundry/src/TychoRouter.sol +++ b/foundry/src/TychoRouter.sol @@ -56,6 +56,7 @@ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; // ✷✷✷✷✷✷ ✷✷✷✷✷ ✷✷✷✷✷✷✷✷ ✷✷✷✷✷✷ ✷✷✷✷✷✷ ✷✷✷✷✷✷✷✷ error TychoRouter__AddressZero(); +error TychoRouter__AmountZero(); error TychoRouter__EmptySwaps(); error TychoRouter__NegativeSlippage(uint256 amount, uint256 minAmount); error TychoRouter__AmountInNotFullySpent(uint256 leftoverAmount); @@ -440,13 +441,14 @@ contract TychoRouter is AccessControl, Dispatcher, Pausable, ReentrancyGuard { * @param amount of WETH to unwrap. */ function _unwrapETH(uint256 amount) internal { - uint256 unwrapAmount = - amount == 0 ? _weth.balanceOf(address(this)) : amount; - _weth.withdraw(unwrapAmount); + if (amount == 0) { + revert TychoRouter__AmountZero(); + } + _weth.withdraw(amount); } /** - * @dev Allows this contract to receive native token + * @dev Allows this contract to receive native token from contracts */ receive() external payable { require(msg.sender.code.length != 0);