Search code examples
ethereumweb3jsuniswap

web3js Uniswap handle event log data


I am building a scraper to get all Swap data from Uniswap using web3js. So far I subscribe to the log and filter topics by Swap() event. then I decode the data and get amount0In, amount1In, amount0Out, amount1Out.

My problem is in the swapExactETHForTokensSupportingFeeOnTransferTokens() function. Normally a swap has token0 in and token1 out, but this function gives me values for 3 of the 4 and I can not seem to understand how to handle that. eventually what I want is to know what they spend, what they got and what I need to update the new reserves of that pair.

If someone has the understanding of the Uniswap RouterV2 contract swap functions, I would like to get some pointers on how to handle the data to get my calculations right.


Solution

  • I found the solution here ethereum.stackexchange Anyone with the same question gets a very detailed answer there.

    some contracts actually transfers to recipient specified amount of tokens minus 10% (5% tax fee and 5% liquidity fee) 208940457743532637 - 10% = 188046411969179375 and emits Transfer event. Then, PancakePair _swap function emits Swap event with base value of Amount0Out 208940457743532637

    Amount0In is greater than zero because the token contract returns part of tokens as a liquidity pair on Pancake Swap.