Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fails when swapping USDT=>WBNB #363

Open
Labels
bugSomething isn't working
@RoscoeTheDog

Description

@RoscoeTheDog

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp