Title: Fails when swapping USDT=>WBNB · Issue #363 · uniswap-python/uniswap-python · GitHub
Open Graph Title: Fails when swapping USDT=>WBNB · Issue #363 · uniswap-python/uniswap-python
X Title: Fails when swapping USDT=>WBNB · Issue #363 · uniswap-python/uniswap-python
Description: I was trying to swap from USDT => BNB but had incorrectly set the address of BNB to WBNB address by mistake. I came across an error from pancake swap saying IDENTICAL ADDRESSES and after stepping through the call stack I could see when i...
Open Graph Description: I was trying to swap from USDT => BNB but had incorrectly set the address of BNB to WBNB address by mistake. I came across an error from pancake swap saying IDENTICAL ADDRESSES and after stepping t...
X Description: I was trying to swap from USDT => BNB but had incorrectly set the address of BNB to WBNB address by mistake. I came across an error from pancake swap saying IDENTICAL ADDRESSES and after steppin...
Opengraph URL: https://github.com/uniswap-python/uniswap-python/issues/363
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fails when swapping USDT=\u003eWBNB","articleBody":"I was trying to swap from USDT =\u003e BNB but had incorrectly set the address of BNB to WBNB address by mistake. I came across an error from pancake swap saying IDENTICAL ADDRESSES and after stepping through the call stack I could see when its building the txn the second element is the same as the last 3rd element in the routing list. This doesn't cause problems when swapping from USDT to native BNB, but it does cause problems when swapping USDT =\u003e WBNB.\r\n\r\nIs there a reason weth have to be in the routing chain? Can't it just be a chain input/output?\r\n\r\n```python\r\n#v2 uniswap being used here\r\n elif self.version == 2:\r\n min_tokens_bought = int(\r\n (1 - slippage)\r\n * self._get_token_token_input_price(\r\n input_token, output_token, qty, fee=fee\r\n )\r\n )\r\n if fee_on_transfer:\r\n func = (\r\n self.router.functions.swapExactTokensForTokensSupportingFeeOnTransferTokens\r\n )\r\n else:\r\n func = self.router.functions.swapExactTokensForTokens\r\n\r\n return self._build_and_send_tx(\r\n func(\r\n qty,\r\n min_tokens_bought,\r\n [input_token, self.get_weth_address(), output_token],\r\n recipient,\r\n self._deadline(),\r\n ),\r\n )\r\n```\r\n\r\nFull function\r\n```python\r\n def _token_to_token_swap_input(\r\n self,\r\n input_token: AddressLike,\r\n output_token: AddressLike,\r\n qty: int,\r\n recipient: Optional[AddressLike],\r\n fee: int,\r\n slippage: float,\r\n fee_on_transfer: bool = False,\r\n ) -\u003e HexBytes:\r\n \"\"\"Convert tokens to tokens given an input amount.\"\"\"\r\n # Balance check\r\n input_balance = self.get_token_balance(input_token)\r\n if qty \u003e input_balance:\r\n raise InsufficientBalance(input_balance, qty)\r\n\r\n if recipient is None:\r\n recipient = self.address\r\n\r\n if input_token == ETH_ADDRESS:\r\n raise ValueError\r\n elif output_token == ETH_ADDRESS:\r\n raise ValueError\r\n\r\n if self.version == 1:\r\n token_funcs = self._exchange_contract(input_token).functions\r\n # TODO: This might not be correct\r\n min_tokens_bought, min_eth_bought = self._calculate_max_output_token(\r\n input_token, qty, output_token\r\n )\r\n func_params = [\r\n qty,\r\n min_tokens_bought,\r\n min_eth_bought,\r\n self._deadline(),\r\n output_token,\r\n ]\r\n if not recipient:\r\n function = token_funcs.tokenToTokenSwapInput(*func_params)\r\n else:\r\n func_params.insert(len(func_params) - 1, recipient)\r\n function = token_funcs.tokenToTokenTransferInput(*func_params)\r\n return self._build_and_send_tx(function)\r\n elif self.version == 2:\r\n min_tokens_bought = int(\r\n (1 - slippage)\r\n * self._get_token_token_input_price(\r\n input_token, output_token, qty, fee=fee\r\n )\r\n )\r\n if fee_on_transfer:\r\n func = (\r\n self.router.functions.swapExactTokensForTokensSupportingFeeOnTransferTokens\r\n )\r\n else:\r\n func = self.router.functions.swapExactTokensForTokens\r\n \r\n return self._build_and_send_tx(\r\n func(\r\n qty,\r\n min_tokens_bought,\r\n [input_token, self.get_weth_address(), output_token],\r\n recipient,\r\n self._deadline(),\r\n ),\r\n )\r\n elif self.version == 3:\r\n if fee_on_transfer:\r\n raise Exception(\"fee on transfer not supported by Uniswap v3\")\r\n\r\n min_tokens_bought = int(\r\n (1 - slippage)\r\n * self._get_token_token_input_price(\r\n input_token, output_token, qty, fee=fee\r\n )\r\n )\r\n sqrtPriceLimitX96 = 0\r\n\r\n return self._build_and_send_tx(\r\n self.router.functions.exactInputSingle(\r\n {\r\n \"tokenIn\": input_token,\r\n \"tokenOut\": output_token,\r\n \"fee\": fee,\r\n \"recipient\": recipient,\r\n \"deadline\": self._deadline(),\r\n \"amountIn\": qty,\r\n \"amountOutMinimum\": min_tokens_bought,\r\n \"sqrtPriceLimitX96\": sqrtPriceLimitX96,\r\n }\r\n ),\r\n self._get_tx_params(),\r\n )\r\n else:\r\n raise ValueError # pragma: no cover\r\n```","author":{"url":"https://github.com/RoscoeTheDog","@type":"Person","name":"RoscoeTheDog"},"datePublished":"2023-12-24T07:53:58.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/363/uniswap-python/issues/363"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:128586e6-c415-b802-7ac7-55745eb47aad |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B9F2:2C3E22:376C430:485E1EC:696B9BDE |
| html-safe-nonce | 461a680b380b0e038c20e96e89c3c7ffee32be35e6b22d4e790c2a62db61ce3d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOUYyOjJDM0UyMjozNzZDNDMwOjQ4NUUxRUM6Njk2QjlCREUiLCJ2aXNpdG9yX2lkIjoiODcwMjExMTc1NjQ5MTM5ODExMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7d6d0c6c0abadb1647715c9a7f47617f072230dd60d158699d1eee8bfa619994 |
| hovercard-subject-tag | issue:2055018106 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/uniswap-python/uniswap-python/363/issue_layout |
| twitter:image | https://opengraph.githubassets.com/181166ba6288c51b095d29e503dde3591957b640231939f4c4762d428352adef/uniswap-python/uniswap-python/issues/363 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/181166ba6288c51b095d29e503dde3591957b640231939f4c4762d428352adef/uniswap-python/uniswap-python/issues/363 |
| og:image:alt | I was trying to swap from USDT => BNB but had incorrectly set the address of BNB to WBNB address by mistake. I came across an error from pancake swap saying IDENTICAL ADDRESSES and after stepping t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RoscoeTheDog |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/uniswap-python/uniswap-python git https://github.com/uniswap-python/uniswap-python.git |
| octolytics-dimension-user_id | 84646677 |
| octolytics-dimension-user_login | uniswap-python |
| octolytics-dimension-repository_id | 163547548 |
| octolytics-dimension-repository_nwo | uniswap-python/uniswap-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 163547548 |
| octolytics-dimension-repository_network_root_nwo | uniswap-python/uniswap-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width