tl;dr: If I execute a swap transaction between two tokens (native or ERC-20 on either side) that is subject to fees/slippage, is there a deterministic way to tell how much the user received from that swap after it has happened?
My app offers swaps from a few different sources. We check to see if Paraswap or 1inch support the trading pairs, and if not, we fall back to Uniswap v2. The issue is, whether from fees or slippage, we never know how much the user will actually receive from the swap until after it has happened.
Our current implementation checks the user's balance before and after the transaction to determine how much he received, but this could technically be thwarted by a race condition where the user's balance changes for unrelated reasons between the checks.
Is there a way to poll an RPC for balances on a particular block or ways to decode the result of a transaction? Something else that I'm not aware of?