In Uniswap v3, the Swap event is emitted when a trade occurs in a liquidity pool.
It provides key details of the swap, including the address of the sender initiating the swap,
the recipient of the swapped tokens, and the amounts of token0 and token1 involved in the trade.
Additionally, the event logs updated state parameters such as the square root price (sqrtPriceX96),
current liquidity, and the tick after the swap, thereby reflecting the pool's state changes.
This event is essential for on-chain tracking of trades, liquidity dynamics, and price updates.
Price Calculation:
Uniswap V3 represents the current pool price using a square root price value, sqrtPriceX96,
stored as a Q64.96 fixed-point number (with 64 bits for the integer part and 96 bits for the fraction).
To compute the actual price of token0 in terms of token1, the value is squared and then divided by 2^192:
Conversely, to determine the price of token1 in terms of token0, take the reciprocal of the computed price.
This calculation method provides high precision and efficient on-chain computation of price ratios.