diff --git a/uniswap/uniswap.py b/uniswap/uniswap.py index 183c349b..39b332f7 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(), ), @@ -1004,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 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( self.router.functions.swapTokensForExactTokens( qty, amount_in_max, - [input_token, self.get_weth_address(), output_token], + path, recipient, self._deadline(), ),