Let's take this Transaction as an example.
Here we have events:
287 Transfer 289 Transfer 291 Swap
We can associate those two
Transfer events with
Swap event by looking at the sequence of events and addresses that show
Transfer being sent either to or out of the Liquidity Pool. Every time we encounter a new
Swap event, we would just increment Swap-index and associate following
Transfer events with the next
Swap, if any.
(The number of
Transfer events will vary per contract, i.e. it is not safe to assume that there will always be 2
Transfer events before
However, the same logic breaks in this very same transaction. Later we have:
297 Transfer 298 Transfer 299 Transfer 302 SwapAndLiquify 303 Transfer 305 Transfer 307 Swap
If we used earlier logic,
Transfer events 297, 298 and 299 would be wrongly associated with 307
SwapAndLiquify is a non-standard event here.
Then you also have transactions such as this one, where I am not sure what's going on.