Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UniswapV2 swapExactTokensForTokens Question #173

Open
Xardesso opened this issue Dec 10, 2023 · 1 comment
Open

UniswapV2 swapExactTokensForTokens Question #173

Xardesso opened this issue Dec 10, 2023 · 1 comment

Comments

@Xardesso
Copy link

I have question does UniswapV2 swapExactTokensForTokens function charge fees ? And if yes does expected amount input should be like this Expected price after fee subtraction?

@Saswankar1
Copy link

Yes, UniswapV2's swapExactTokensForTokens function does charge fees. The fee is approx 0.3% of the transaction amount and it's automatically deducted from the amount of output tokens. Therefore, the expected amount input should be the expected price after fee subtraction.

When you use the swapExactTokensForTokens function, you specify the exact amount of input tokens you are willing to spend, and the minimum amount of output tokens you expect to receive. The function will revert (fail) if the amount of output tokens is less than the minimum specified due to price changes or fees.

As an example, if you're swapping 100 tokens A for tokens B, and the current price of token A in terms of token B is 1 (1 token A = 1 token B), you would expect to receive 100 tokens B. However, Uniswap will charge a 0.3% fee, so you will actually receive 99.7 tokens B.

If you want to ensure that you receive at least 99 tokens B, you would set your amountOutMin parameter to 99. If the actual amount of tokens B you would receive after fees is less than this (due to price changes or fees), the transaction will revert.

In summary, when using swapExactTokensForTokens, you provide the exact input amount and specify the minimum acceptable output amount, and the Uniswap contract handles the fee calculation during the swap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants