Skip to content

Question, why [input_token, weth, output_token] #405

Open

Description

@weestack

Hello not a bug, but however a question from a newbie in dex swapping.

[input_token, self.get_weth_address(), output_token],

There on line 1011:
[input_token, self.get_weth_address(), output_token],

why are the default for v2 a 3 way path, I debugged the code yesterday, because I already had some WETH in my meta account, so naturally I set the input to weth, and output to what I wanted to swap i for, which kept failing with "SAME ADDRESS" error.

Are there any perks of using a 3-way route over a 2-way route on Uniswap V2, in my own clumsy and logic (VERY new to defi) it should be faster and cheaper with a 2-way router rather than a 3-way route, right?

Can someone explain the implementation reason to me, as I cant find it in the documentation and neither that it defaults to weth as middle route, perhaps i just used it wrong.... but it would be great to get some perspective on the matter

uniswap = Uniswap(address=address, default_slippage=0.5, private_key=private_key, version=version, provider=provider)

web3 = Web3(Web3.HTTPProvider(mainnet_url))
token_meta = uniswap.get_token(token, 'erc20')
spend_eth = '0.001'
spend = web3.to_wei(spend_eth, 'ether')
Amount = uniswap.get_price_input(WETH_PAIR_ADDRESS, token, spend)
uniswap.make_trade(WETH_PAIR_ADDRESS, token, spend, fee_on_transfer=True)

Activity

  1. nigeldelviero commented on Aug 12, 2024

    @nigeldelviero

    Hello not a bug, but however a question from a newbie in dex swapping.

    [input_token, self.get_weth_address(), output_token],

    There on line 1011: [input_token, self.get_weth_address(), output_token],

    why are the default for v2 a 3 way path, I debugged the code yesterday, because I already had some WETH in my meta account, so naturally I set the input to weth, and output to what I wanted to swap i for, which kept failing with "SAME ADDRESS" error.

    Are there any perks of using a 3-way route over a 2-way route on Uniswap V2, in my own clumsy and logic (VERY new to defi) it should be faster and cheaper with a 2-way router rather than a 3-way route, right?

    Can someone explain the implementation reason to me, as I cant find it in the documentation and neither that it defaults to weth as middle route, perhaps i just used it wrong.... but it would be great to get some perspective on the matter

    uniswap = Uniswap(address=address, default_slippage=0.5, private_key=private_key, version=version, provider=provider)
    
    web3 = Web3(Web3.HTTPProvider(mainnet_url))
    token_meta = uniswap.get_token(token, 'erc20')
    spend_eth = '0.001'
    spend = web3.to_wei(spend_eth, 'ether')
    Amount = uniswap.get_price_input(WETH_PAIR_ADDRESS, token, spend)
    uniswap.make_trade(WETH_PAIR_ADDRESS, token, spend, fee_on_transfer=True)

    I'll try to help answer your question

    1. Why the middle of path is WETH address instead direct into target token?
      The most significant reason is liquidity, WETH pairs generally have the most liquidity on Uniswap. When you swap from one token to another, going through WETH often gives you access to deeper liquidity pools, which can result in better pricing. For example, if you want to swap Token A for Token B, there might not be a direct pair (or enough liquidity in the direct pair) for that swap. However, both Token A/WETH and WETH/Token B pools might have substantial liquidity, making the swap through WETH more efficient.

    2. By routing through WETH, you reduce the price impact of your trade. Direct swaps between less liquid pairs can cause significant slippage

    3. Can we input route like [input_token, output_token]?

    • If there is sufficient liquidity in the [input_token, output_token] pair, then using this route could potentially be cheaper because you're avoiding an extra swap step. However, this is only beneficial if the liquidity is high enough to avoid significant slippage.
    • If the direct pair is not very liquid, it could be more costly due to slippage, and routing through WETH might actually result in a better price, even with the additional swap step.
    • directly to the target token will be faster? it does not affect the transaction speed

    Summary

    • Use [input_token, output_token]: If you are confident that the direct pair has enough liquidity to minimize slippage and you can use it if there is pair about the tokens on Uniswap Pool.
    • Use [input_token, WETH, output_token]: If the liquidity in the direct pair is low, or if the route through WETH gives you better pricing due to deeper liquidity pools.

    In my opinion, which is the safest and best option out of them? Default to [input_token, WETH, output_token] Route**

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions