Definition
Can we use Agnostic as a backend for Uniswap analytics?
The example
Can we display a price curve of ETH/USDC projected from swap happening on-chain over time to thousands of users with the freshest data?
It shouldn't be an issue with a well-designed protocol like Uniswap and Agnostic powerful live aggregation and serving capabilities.
The Uniswap V3 data model
Fortunately, Uniswap publishes many valuable Events, allowing us to track the protocol activity with our `evm_event_*` data collection. Let's explore the documentation and find the Swap event signature; it's the one we are looking for here.
In this version of Uniswap, we have very interesting values: sqrtPriceX96
and tick
. In the previous versions, we had to calculate the price from the amounts directly. Let's try to look at the tick
.
So, with this explanation from the documentation:
Name | Type | Description |
---|---|---|
| address | The address that initiated the swap call, and that received the callback |
| address | The address that received the output of the swap |
| int256 | The delta of the token0 balance of the pool |
| int256 | The delta of the token1 balance of the pool |
| uint160 | The sqrt(price) of the pool after the swap, as a Q64.96 |
| uint128 | The liquidity of the pool after the swap |
| int24 | The log base 1.0001 of price of the pool after the swap |
We should be able to get the price with this simple formula:
Last updated