Dune Analytics
Partner Program

How to easily analyse Uniswap data with Dune Analytics 🦄

TLDR

You can now super easily query Uniswap data with SQL, visualise your results and share them with the world at duneanalytics.com. All events have USD values baked in and one single SELECT statement will give you stats from the entire Uniswap system, across all contracts. You also have human readable ticker symbols for all major tokens which means you don't have to work with abstract token symbols.

Dune Analytics is a platform for doing smart contract analysis using SQL.

Uniswap is an automated liquidity protocol on Ethereum.

Dune and Uniswap have partnered to make it as easy as possible to query, visualise and share the Uniswap data. This quick start guide assumes you have basic familiarity with SQL and smart contracts.

If at any time during this guide you feel confused, feel free to peek into the growing Dune Analytics documentation, Uniswap's documentation, or ask questions directly in the Dune Telegram or Uniswap Discord channels.

In order to get started analyzing Uniswap on Dune Analytics, you'll need a free account.

Understanding Uniswap

From the Uniswap docs:

The Uniswap V1 protocol is made of up a series of ERC20/ETH trading pairs. All ER20 tokens are paired with ETH and there is unique smart contract per pair. If an ERC20 token does not yet have a pair it can be created by anyone using the Uniswap factory contract. The factory serves as a public registry and is used to look up all token and pair addresses added to the system.

Each pair holds reserves of both ETH and its associated ERC20 token. Anyone can become a liquidity provider on a pair and contribute to its liquidity reserves. This is different than buying or selling; it requires depositing an equivalent value of both ETH and the relevant ERC20 token. Liquidity is pooled across all providers and an internal “pool token” (ERC20) is used to track each providers relative contribution. Pool tokens are minted when liquidity is deposited into the system and can be burned at any time to withdraw a proportional share of the reserves.

Each pair contract acts as an automated liquidity provider between ETH an ERC20 token. Traders can swap between the two in either direction by adding to the liquidity reserve of one and withdrawing from the reserve of the other. Since ETH is a common pair for all ERC20 tokens, it can be used as an intermediary allowing direct ERC20-ERC20 trades in a single transaction. Users can specify a recipient address if they want to receive purchased tokens at a different address from the one used to make a transaction.

For more info on how the protocol works see the Uniswap docs.

Key actions on Uniswap

  • Add Liquidity- add ETH and an ERC20 token to a pool.
  • Remove liquidity - add ETH and an ERC20 token to a pool.
  • ETH purchase -Buy ETH with an ERC20 token.
  • Token purchase - Buy an ERC20 token with ETH.
  • New exchange - If there's no exchange for a specific ERC20 token anyone can create a new one. This happens from the factory contract as opposed to all the above which happens at the respective token exchange contracts.

Most interesting events and data tables

From the actions described above we have created these corresponding views that you can easily query:

  • Add Liquidity- uniswap.view_add_liquidity
  • Remove liquidity - uniswap.view_remove_liquidity
  • ETH purchase - uniswap.view_eth_purchase
  • Token purchase - uniswap.view_token_purchase
  • New exchange - uniswap.view_new_exchange

More details on what the tables can be found in the "Underlying Data" section below.

📝 Examples

With the tables above you can do a SQL query like:

SELECT
date_trunc('day', block_time),
SUM(usd_value_of_eth)
FROM
(
       SELECT block_time, usd_value_of_eth FROM uniswap."view_eth_purchase"
           UNION ALL
       SELECT block_time, usd_value_of_eth FROM uniswap."view_token_purchase"
) AS eth_usd
WHERE block_time > now() - interval '7 days'
GROUP BY 1
ORDER BY 1;

Which gives you a chart like this:

💡Ideas for what to build

Uniswap overview

What's the overall volume of Uniswap? What are the top markets? What are the top liquidity providers? How many new exchanges are deployed per week? How many new pairs are deployed per week?

Similar to what 1inch have done at duneanalytics.com/1inch

Movement in and out of liquidity pools

Which pools are the most active in terms of gaining or losing liquidity lately?

Liquidity provider fees

How much are various pools earning? Who's getting the best ROI?

Revealed USD prices

By using the USD value of ETH (prices.usd table) you can calculate what implied token value are for trades on Uniswap. This could be benchmarked with centralized exchange price data.

User Data

What's the average size ($) of a uniswap transaction? How often are most addresses using uniswap over a given period of time?

Slippage

Which pools experienced the biggest slippage over the last 24 hours?

Trends

Which Uniswap pools are growing the fastest in either liquidity or transaction volume?

Note that for any query you can use {{}} to make it "parameterised" i.e. a user can input a token address or their own address and filter for those results. Simply put WHERE address = '{{}} ' in your query.

The underlying data

The created views are created from the underlying smart contract data. The key benefits of these views are that you get USD value of events and the token symbol out of the box.

The source of these views are tracked here, and are built on top of Dune Analytics state-of-the art smart contract data.

If, for your use case, you find that the above abstractions aren't a good fit, you can use the underlying tables that are generated directly from the smart contract ABIs. These are available in the uniswap - schema, and the Dune Analytics documentation will help you dive deeper into the data.

You can ask any questions directly in the Dune Telegram or Uniswap Discord channels.