0

What is the way to exchange token 0 for token 1 without using the router in Solidity? Does it interact with the token pair?

1
  • 1
    You can call swap of the pair (if this is v2) or the pool (if this is v3) directly.
    – kfx
    Commented Jul 26, 2022 at 9:12

2 Answers 2

0

As kfx mentioned, you can call the swap on the pair contract directly. I recommend extreme caution with this though, since the router adds the checks to not shoot yourself in the foot. The direct swap function on the pair will not check things like your slippage, if your output is way lower than requested and whatnot. Make sure you understand how the uniswap pair and swap function is working very well before using a direct swap on a pair.

0

It isn't too complicated or scary. You do have to be sure about your amount calculations but it will fail it can't give what you ask for.

Essentially you transfer the tokens you are selling directly to the pool by calling transfer on the token contract, and then you call swap with the amount out at the pool contract.

You only pass the amount you want out, and swap logs will show both amounts (they will show any change on pool, it's possible to fill them all if you transfer both tokens in and call out for both sides within the one function).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.