alchemistcoin / sandwiched-backend

GNU General Public License v3.0
25 stars 7 forks source link

Only fetch pool/token info when needed #21

Closed henridf closed 3 years ago

henridf commented 3 years ago

As of #4, we fetch token/pool info for every swap we retrieve in the initial getSwaps() call. But we do not need this info when searching for sandwiches. We only need it after a sandwich has been identified. Furthermore, the majority of swaps are not sandwiched. This all means that we are doing a lot of contract read requests for nothing, and this noticeably slows down the initial phase, especially for addresses with many swaps (such as 0x3328f5f2cEcAF00a2443082B657CedEAf70bfAEf).

We should instead fetch this info only after a sandwich has been detected. We can remove the pool field from the SwapLog, and just look it up locally in findSandwich().