- Notifications
You must be signed in to change notification settings - Fork386
Open
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 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 => WBNB.
Is there a reason weth have to be in the routing chain? Can't it just be a chain input/output?
#v2 uniswap being used hereelifself.version==2:min_tokens_bought=int( (1-slippage)*self._get_token_token_input_price(input_token,output_token,qty,fee=fee ) )iffee_on_transfer:func= (self.router.functions.swapExactTokensForTokensSupportingFeeOnTransferTokens )else:func=self.router.functions.swapExactTokensForTokensreturnself._build_and_send_tx(func(qty,min_tokens_bought, [input_token,self.get_weth_address(),output_token],recipient,self._deadline(), ), )
Full function
def_token_to_token_swap_input(self,input_token:AddressLike,output_token:AddressLike,qty:int,recipient:Optional[AddressLike],fee:int,slippage:float,fee_on_transfer:bool=False, )->HexBytes:"""Convert tokens to tokens given an input amount."""# Balance checkinput_balance=self.get_token_balance(input_token)ifqty>input_balance:raiseInsufficientBalance(input_balance,qty)ifrecipientisNone:recipient=self.addressifinput_token==ETH_ADDRESS:raiseValueErrorelifoutput_token==ETH_ADDRESS:raiseValueErrorifself.version==1:token_funcs=self._exchange_contract(input_token).functions# TODO: This might not be correctmin_tokens_bought,min_eth_bought=self._calculate_max_output_token(input_token,qty,output_token )func_params= [qty,min_tokens_bought,min_eth_bought,self._deadline(),output_token, ]ifnotrecipient:function=token_funcs.tokenToTokenSwapInput(*func_params)else:func_params.insert(len(func_params)-1,recipient)function=token_funcs.tokenToTokenTransferInput(*func_params)returnself._build_and_send_tx(function)elifself.version==2:min_tokens_bought=int( (1-slippage)*self._get_token_token_input_price(input_token,output_token,qty,fee=fee ) )iffee_on_transfer:func= (self.router.functions.swapExactTokensForTokensSupportingFeeOnTransferTokens )else:func=self.router.functions.swapExactTokensForTokensreturnself._build_and_send_tx(func(qty,min_tokens_bought, [input_token,self.get_weth_address(),output_token],recipient,self._deadline(), ), )elifself.version==3:iffee_on_transfer:raiseException("fee on transfer not supported by Uniswap v3")min_tokens_bought=int( (1-slippage)*self._get_token_token_input_price(input_token,output_token,qty,fee=fee ) )sqrtPriceLimitX96=0returnself._build_and_send_tx(self.router.functions.exactInputSingle( {"tokenIn":input_token,"tokenOut":output_token,"fee":fee,"recipient":recipient,"deadline":self._deadline(),"amountIn":qty,"amountOutMinimum":min_tokens_bought,"sqrtPriceLimitX96":sqrtPriceLimitX96, } ),self._get_tx_params(), )else:raiseValueError# pragma: no cover