This API retrieves information about all of the actions that occurred for a specific liquidity pool on the protocol within a certain timespan.
Time Range Limit
The maximum time range (difference between endDate and startDate) is 60 days.
Not specifying startDate and endDate
If the startDate and endDate query parameters are not provided, the API will return data from the current date - 30 days.
So if the date-time today is 2022-12-20T00:00:00, then the first object in payload.data would start from at least 2022-11-20T00:00:00.
Understanding Actions in Uniswap
There are many different types of actions in Uniswap, as you'll see in the action property for each item of the payload.data
array. The guide below will help you understand the possible actions.
Swap (v2)
Within the liquidity pool denoted by poolAddress, the protocol is executing a trade that swaps amount0In of token0 for amount1Out of token1. The recipient of the token1 quantity is denoted by the to address.
Normalized amounts are computed using the decimal count for the respective tokens. In this example, token0 is USDC with 6 decimals. Hence amount0Normalized is amount0 shifted 6 decimals from the right. token1 is WETH with 18 decimals. Hence amount1Normalized is amount1 shifted 18 decimals from the right.
In other words, the address to received 7.1 ETH after swapping 26,823 USDC in Uniswap v2.
{
"action": "Swap",
"event": "Swap(index_topic_1 address sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, index_topic_2 address to)",
"timestamp": "2022-01-03 23:36:52 000",
"blockNumber": 13935536,
"transactionHash": "0x0b5a9fd5544757f00ff257c543614653eaa12c2e6d6b7428daf4380125c9de46",
"logIndex": 6,
"poolAddress": "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc",
"token0": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"token1": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"sender": "0xdef171fe48cf0115b1d80b88dc8eab59176fee57",
"amount0In": "26823361137",
"amount1In": "0",
"amount0Out": "0",
"amount1Out": "7118283966568551127",
"amount0InNormalized": "26823.361137",
"amount1InNormalized": "0.0",
"amount0OutNormalized": "0.0",
"amount1OutNormalized": "7.118283966568551",
"to": "0xdef171fe48cf0115b1d80b88dc8eab59176fee57"
}
property | type |
---|---|
action | string |
event | string |
timestamp | string | number |
blockNumber | number |
transactionHash | string |
logIndex | number |
poolAddress | string |
token0 | string |
token1 | string |
sender | string |
amount0In | string |
amount1In | string |
amount0Out | string |
amount1Out | string |
amount0InNormalized | string |
amount1InNormalized | string |
amount0OutNormalized | string |
amount1OutNormalized | string |
to | string |
Mint (v2)
Creates amount0 and amount1 liquidity pool tokens for token0 and token1 because liquidity was provided for the pool at poolAddress.
{
"action": "Mint",
"event": "Mint(index_topic_1 address sender, uint256 amount0, uint256 amount1)",
"timestamp": "2022-01-04 14:54:24 000",
"blockNumber": 13939620,
"transactionHash": "0x23e9246ac4035aa48a3ade2702870fca88d7256ecd0f8a17424f92c29628d7aa",
"logIndex": 411,
"poolAddress": "0x4cedf45d496e5bc36beda9197b0edc4957d98080",
"token0": "0x74edaf28fc4b9e6a1618d613839daaf6a9d075db",
"token1": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"sender": "0x7a250d5630b4cf539739df2c5dacb4c659f2488d",
"amount0": "13987749186848981681050",
"amount1": "225028717662222390",
"amount0Normalized": "1.3987749186848982E13",
"amount1Normalized": "0.22502871766222238"
}
Swap (v3)
Within the liquidity pool denoted by poolAddress, the protocol is executing a trade that swaps amount0 of token0 for amount1 of token1. The recipient of the token1 quantity is denoted by the recipient address.
Note that amount1 is negative. This indicates that amount1 of token1 was removed from the liquidity pool and that at least amount0 of token0 was added, vice-versa if amount0 was negative.
Normalized amounts are computed using the decimal count for the respective tokens. In this example, token1Address is USDC with 6 decimals. Hence amount1Normalized is amount1 shifted 6 decimals from the right. token0Address is DAI with 18 decimals. Hence amount0Normalized is amount0 shifted 18 decimals from the right.
In other words, the address recipient received 2136.125 USDC after swapping 2,136.290 DAI in Uniswap v3.
walletAddress is the initiator of this swap.
{
"blockNumber": 15066199,
"transactionHash": "0xa779935b68b544a055d2caae5bcb1a162b0c440e8577320c9f6027a8b689f923",
"logIndex": 191,
"timestamp": "2022-07-03 00:07:07 000",
"factoryAddress": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
"poolAddress": "0x5777d92f208679db4b9778590fa3cab3ac9e2168",
"event": "Swap(address indexed sender, address indexed recipient, uint256 amount0, uint256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick)",
"action": "Swap",
"walletAddress": "0x9af79773f619f6d68e35ec8fe62660649b011a90",
"tick": "-276324",
"sender": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
"amount0": "2136290387768991186457",
"amount1": "-2136125245",
"liquidity": "3557659723537831479985487",
"recipient": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
"sqrtPriceX96": "79229061675456427773788",
"amount0Normalized": "2136.2903877689911864570",
"amount1Normalized": "-2136.1252450",
"token0Address": "0x6b175474e89094c44da98b954eedeac495271d0f",
"token1Address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
}
property | type |
---|---|
blockNumber | number |
transactionHash | string |
logIndex | number |
timestamp | string | number |
factoryAddress | string |
poolAddress | string |
event | string |
action | string |
walletAddress | string |
tick | string |
sender | string |
amount0 | string |
amount1 | string |
liquidity | string |
recipient | string |
sqrtPriceX96 | string |
amount0Normalized | string |
amount1Normalized | string |
token0Address | string |
token1Address | string |
Calculating Price from tick
Take for example the following Swap in the WBTC/ETH 0.3% pool
{
"blockNumber": "16673343",
"transactionHash": "0x8a3ff1d0eaaa02a1e38d73068bd68a87e73f441b7e817f2d94f02295e9cbfb7d",
"logIndex": 380,
"timestamp": "2023-02-21 00:32:11 000",
"factoryAddress": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
"poolAddress": "0xcbcdf9626bc03e24f779434178a73a0b4bad62ed",
"event": "Swap(address indexed sender, address indexed recipient, uint256 amount0, uint256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick)",
"action": "Swap",
"walletAddress": "0xa52eb11b9b28dfa542e8c31d5ea834a793eaf6ac",
"tick": "257062",
"sender": "0xef1c6e67703c7bd7107eed8303fbe6ec2554bf6b",
"amount0": "-3215566",
"amount1": "470000000000000000",
"liquidity": "2300696624878817708",
"recipient": "0xef1c6e67703c7bd7107eed8303fbe6ec2554bf6b",
"sqrtPriceX96": "30244574474409459448480531536110269",
"amount0Normalized": "-0.032155660",
"amount1Normalized": "0.4700000000000000000",
"token0Address": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
"token1Address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
}
It's quite simple to calculate the price that this trade/swap occured at.
In Uniswap v3, the price at a tick i is defined as p(i) = 1.0001i, thus for the property tick above, with the value of 257062, the price will be
1.0001257062 = 145,714,457,877.4906
Now, we take this resulting value and multiply it by the token decimal ratio, which is defined as 10token0_decimals / 10token1_decimals.
token0 is WBTC with 8 decimals and token1 is ETH with 18 decimals. Hence the token decimal ratio is
108/1018 = 10-10
Multiplying the price and token decimal ratio, we have
145,714,457,877.4906 * 10-10 = 14.571
14.571 is the price as measured in token0/token1. Hence 1 WBTC = 14.571 ETH and 1 ETH = 1/14.571 = 0.0686 WBTC
Mint (v3)
{
"blockNumber": 13659033,
"transactionHash": "0x77cc6275f6807fec3159c3fbf5bff8ac025427a419b0a3cbefd4d2f9c7be52d6",
"logIndex": 125,
"timestamp": "2021-11-21 15:41:04 000",
"factoryAddress": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
"poolAddress": "0x5777d92f208679db4b9778590fa3cab3ac9e2168",
"event": "Mint(address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1)",
"action": "Mint",
"walletAddress": "0xcaacebe2fdac9d3783563b9b80c714df82705226",
"owner": "0xc36442b4a4522e871399cd717abdd847ab11fe88",
"amount": "407110841443516028943",
"sender": "0xc36442b4a4522e871399cd717abdd847ab11fe88",
"amount0": "26356922330371906206695",
"amount1": "34704623518",
"tickLower": "16500891",
"tickUpper": "16500894",
"amount0Normalized": "26356.9223303719062066950",
"amount1Normalized": "34704.6235180",
"token0Address": "0x6b175474e89094c44da98b954eedeac495271d0f",
"token1Address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
}
property | type |
---|---|
blockNumber | number |
transactionHash | string |
logIndex | number |
timestamp | string | number |
factoryAddress | string |
poolAddress | string |
event | string |
action | string |
walletAddress | string |
owner | string |
amount | string |
sender | string |
amount0 | string |
amount1 | string |
tickLower | string |
tickUpper | string |
amount0Normalized | string |
amount1Normalized | string |
token0Address | string |
token1Address | string |