Links
🦄

Retrieve Uniswap's Fee and Treasury data

TL;DR

You can only query metrics together that share the same aggregation levels. You have to use the Get project info endpoint's metric_availability data point to determine whether two metrics support same aggregation levels.
Here's an example query to get you started. The query fetches Uniswap' historical Fee and Treasury data on a daily granularity, aggregated on chain-level.
cURL
Python
1
# Set your API Key here.
2
API_TOKEN="d3adb33f-c123-45b6-7890-c0ff33"
3
curl \
4
-H "content-type: application/json" \
5
-H "authorization: Bearer $API_TOKEN" \
6
"https://api.tokenterminal.com/v2/projects/uniswap/metrics?metrics=fees,treasury&aggregate_by=chain"
1
import requests
2
# Set your API Key here.
3
API_TOKEN="d3adb33f-c123-45b6-7890-c0ff33"
4
params = {"metrics": "fees,treasury", "aggregate_by": "chain"}
5
headers = {"Authorization": f"Bearer {API_TOKEN}"}
6
r = requests.get("https://api.tokenterminal.com/v2/projects/uniswap/metrics", params=params, headers=headers)
7
r.json()

Deep dive

Uniswap is a non-custodial exchange protocol built on Ethereum. Liquidity providers deposit funds into Uniswap and receive trading fees from traders (supply-side fees). Uniswap currently takes a cut of the total trading fees paid by traders (revenue).
By using the Project info endpoint we can first check which aggregation levels are possible for Uniswap.
cURL
Python
# Set your API Key here.
API_TOKEN="d3adb33f-c123-45b6-7890-c0ff33"
curl \
-H "content-type: application/json" \
-H "authorization: Bearer $API_TOKEN" \
"https://api.tokenterminal.com/v2/projects/uniswap"
1
import requests, json
2
# Set your API Key here.
3
API_TOKEN="d3adb33f-c123-45b6-7890-c0ff33"
4
headers = {"Authorization": f"Bearer {API_TOKEN}"}
5
r = requests.get("https://api.tokenterminal.com/v2/projects/uniswap", headers=headers)
6
print(r.json())
Looking at the fees section we can see that all aggregation-levels are possible. Invalid aggregation-levels would be showing an empty array.
{
"data": {
"metric_availability": {
"fees": {
"chain": [
"ethereum",
"arbitrum",
"polygon",
"optimism"
],
"version": [
"v2",
"v3"
],
"business_line": [
"exchange_amm"
],
"business_type": [
"transaction"
]
},
...
}
}
}
Let's query the fees data on chain and version granularity.
cURL
Python
1
# Set your API Key here.
2
API_TOKEN="d3adb33f-c123-45b6-7890-c0ff33"
3
curl \
4
-H "content-type: application/json" \
5
-H "authorization: Bearer $API_TOKEN" \
6
"https://api.tokenterminal.com/v2/projects/uniswap/metrics?metrics=fees&aggregate_by=chain,version"
1
import requests
2
# Set your API Key here.
3
API_TOKEN="d3adb33f-c123-45b6-7890-c0ff33"
4
params = {"metrics": "fees", "aggregate_by": "chain,version"}
5
headers = {"Authorization": f"Bearer {API_TOKEN}"}
6
r = requests.get("https://api.tokenterminal.com/v2/projects/uniswap/metrics", params=params, headers=headers)
7
r.json()
We can see clearly how fees are split between Uniswap's V2 and V3 versions and also between different chains.
{
"data": [
{
"timestamp": "2022-10-12T00:00:00.000Z",
"project_name": "Uniswap",
"chain": "ethereum",
"version": "v2",
"fees": "51588.985195643"
},
{
"timestamp": "2022-10-12T00:00:00.000Z",
"project_name": "Uniswap",
"chain": "polygon",
"version": "v3",
"fees": "31738.262878018"
},
{
"timestamp": "2022-10-12T00:00:00.000Z",
"project_name": "Uniswap",
"chain": "arbitrum",
"version": "v3",
"fees": "36049.815028978"
},
{
"timestamp": "2022-10-12T00:00:00.000Z",
"project_name": "Uniswap",
"chain": "ethereum",
"version": "v3",
"fees": "339050.944022027"
},
...
]
}
Since we can, let's also get the data for treasury data within the same query.
curl \
-H "content-type: application/json" \
-H "authorization: Bearer $API_TOKEN" \
"https://api.tokenterminal.com/v2/projects/uniswap/metrics?metrics=fees,treasury&aggregate_by=chain,version"
Unfortunately, we get the following error.
{
"message": "metric treasury cannot be aggregated by version. available aggregations: chain"
}
Let's go back and see what the project info query gave us for the treasury metric.
{
"data": {
"metric_availability": {
"treasury": {
"chain": [
"ethereum"
],
"version": [],
"business_line": [],
"business_type": []
},
...
}
}
}
We can confirm that treasury data can only be aggregated on chain-level. This makes sense because at least for now each version of the protocol doesn't manage its own treasury. It's the protocol managing the treasury separately for each chain.
Let's do another query with chain-level aggregation only.
cURL
Python
1
# Set your API Key here.
2
API_TOKEN="d3adb33f-c123-45b6-7890-c0ff33"
3
curl \
4
-H "content-type: application/json" \
5
-H "authorization: Bearer $API_TOKEN" \
6
"https://api.tokenterminal.com/v2/projects/uniswap/metrics?metrics=fees,treasury&aggregate_by=chain"
1
import requests
2
# Set your API Key here.
3
API_TOKEN="d3adb33f-c123-45b6-7890-c0ff33"
4
params = {"metrics": "fees,treasury", "aggregate_by": "chain"}
5
headers = {"Authorization": f"Bearer {API_TOKEN}"}
6
r = requests.get("https://api.tokenterminal.com/v2/projects/uniswap/metrics", params=params, headers=headers)
7
r.json()
We can successfully see that both fee and treasury data can be aggregated on chain-level.
{
"data": [
{
"timestamp": "2022-10-12T00:00:00.000Z",
"project_name": "Uniswap",
"chain": "ethereum",
"fees": "390639.92921767",
"treasury": 2529389205.1545696
},
{
"timestamp": "2022-10-12T00:00:00.000Z",
"project_name": "Uniswap",
"chain": "polygon",
"fees": "31738.262878018",
"treasury": null
},
{
"timestamp": "2022-10-12T00:00:00.000Z",
"project_name": "Uniswap",
"chain": "arbitrum",
"fees": "36049.815028978",
"treasury": null
},
...
]
}
Interestingly, we can see treasury data only for Ethereum, but not for Polygon and Arbitrum. The reason is that Uniswap's treasury is managed only on top of Ethereum.