From 180724b554c4bcb4e45a4590a818995b79dee724 Mon Sep 17 00:00:00 2001 From: botbikamordehai2-sketch Date: Thu, 28 May 2026 07:21:29 +0000 Subject: [PATCH 1/4] fix: avoid duplicate WETH in swap path when input/output is WETH (closes #363) --- uniswap/uniswap.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/uniswap/uniswap.py b/uniswap/uniswap.py index 183c349b..22e42716 100644 --- a/uniswap/uniswap.py +++ b/uniswap/uniswap.py @@ -742,11 +742,17 @@ def _token_to_token_swap_input( ) else: func = self.router.functions.swapExactTokensForTokens + weth_address = self.get_weth_address() + if is_same_address(input_token, weth_address) or is_same_address(output_token, weth_address): + path = [input_token, output_token] + else: + path = [input_token, weth_address, output_token] + return self._build_and_send_tx( func( qty, min_tokens_bought, - [input_token, self.get_weth_address(), output_token], + path, recipient, self._deadline(), ), From 34bbc2534ef4d0c7f61aeff4bdbcfa463065c5ff Mon Sep 17 00:00:00 2001 From: botbikamordehai2-sketch Date: Thu, 28 May 2026 07:48:30 +0000 Subject: [PATCH 2/4] fix: also avoid duplicate WETH in _token_to_token_swap_output (closes #363) --- uniswap/uniswap.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/uniswap/uniswap.py b/uniswap/uniswap.py index 22e42716..5726f7d6 100644 --- a/uniswap/uniswap.py +++ b/uniswap/uniswap.py @@ -1010,11 +1010,17 @@ def _token_to_token_swap_output( input_token, output_token, qty, fee=fee ) amount_in_max = int((1 + slippage) * cost) + weth = self.get_weth_address() + path = ( + [input_token, output_token] + if input_token == weth or output_token == weth + else [input_token, weth, output_token] + ) return self._build_and_send_tx( self.router.functions.swapTokensForExactTokens( qty, amount_in_max, - [input_token, self.get_weth_address(), output_token], + path, recipient, self._deadline(), ), From 4716d944eee5c8002252bcafabb5ac09a935a30e Mon Sep 17 00:00:00 2001 From: botbikamordehai2-sketch Date: Thu, 28 May 2026 08:30:34 +0000 Subject: [PATCH 3/4] fix: use is_same_address() for WETH comparison in _token_to_token_swap_output Raw == fails when input_token/output_token is bytes or lowercase hex, falling through to the wrong 3-hop path. Consistent with the rest of the codebase (line 746 and the v3 path use is_same_address). --- uniswap/uniswap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uniswap/uniswap.py b/uniswap/uniswap.py index 5726f7d6..39b332f7 100644 --- a/uniswap/uniswap.py +++ b/uniswap/uniswap.py @@ -1013,7 +1013,7 @@ def _token_to_token_swap_output( weth = self.get_weth_address() path = ( [input_token, output_token] - if input_token == weth or output_token == weth + if is_same_address(input_token, weth) or is_same_address(output_token, weth) else [input_token, weth, output_token] ) return self._build_and_send_tx( From c2e0aaeabf85ce314f10409a241f9109b97c194c Mon Sep 17 00:00:00 2001 From: Yohan K <72107640+liquid-8@users.noreply.github.com> Date: Wed, 29 Jul 2026 02:51:17 +0300 Subject: [PATCH 4/4] Update uniswap/uniswap.py Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>