I would like to get the price of a token after a swap. For example the price is now $1, and I would like to see how much will be the price after my swap. Is the execution price what I need in this case?
Let's use this transaction as an example:
172054109197 Zombie tokens were transferred to Zombie / BUSD LP in exchange for
6357581284196624466 BUSD tokens.
Here is the Swap event:
amount0In: 172054109197 amount1In: 0 amount0Out: 0 amount1Out: 6357581284196624466
0.000000172 Zombie traded for
To understand the price impact, we need to look at the Zombie / BUSD LP reserves before and after the transaction.
reserve0: 1203765031 reserve1: 6402195517789394391
reserve0: 173257874228 reserve1: 44614233592769925
We know (by looking at the LP contract) that
reserve0 represents Zombie token and
reserve1 represents BUSD token.
As we traded Zombie for BUSD, we have to add the amount being traded in to the first reserve and deduct the amount being traded for from the second reserve, i.e.
reserve0: 1203765031+172054109197=173257874228 reserve1: 6402195517789394391+6357581284196624466=44614233592769925
This is how the Swap affected the reserves and therefore the price ratio.