Uniswap V3 on Amberdata.io — How to deep dive into actionable DEX data
TLDR; Amberdata supports Uniswap v3 DEX! Access the entire suite of assets deployed, with actionable APIs and metrics. Learn more →
Uniswap V3 is here!
As of last week, Uniswap v3 is supported in Amberdata APIs, Websockets & more. This brings a big upgrade to the Uniswap ecosystem, building off of the foundation previously highlighted last year. The biggest change for V3 is the liquidity logic that allows liquidity providers to focus collateral on a range of the constant product, rather than bearing exposure to the wider range of prices.
Concentrated Liquidity: liquidity that is allocated within a custom price range. In earlier versions, liquidity was distributed uniformly along the price curve between 0 and infinity.
You can read more about that here.
Why Uniswap V3?
No other platform provides deep actionable APIs for accessing DEX & DeFi like Amberdata.
Uniswap has a track record of being the largest growth and best UX of Ethereum DeFi, as previously highlighted here. With the deep integration available in Amberdata APIs, anyone can easily integrate the best DeFi data with the fastest time to market and lowest learning curve.
Uniswap is for:
- Institutional Investors: Liquidity Provider
- Traders: Swaps, Range Trades
- dApps: Dynamic Collateral
Get In On The Action: Using the APIs
Before we dive into the data & metrics, let’s look at how to access the underlying data, so you can draw your own conclusions and follow along:
- OHLCV Supported Pairs & Exchanges Information
- OHLCV Latest By Pair
- OHLCV Historical By Pair
- Trades Supported Pairs & Exchanges Information
- Trades Historical By Pair
NOTE: For Uniswap V3, you need to use a query including:
exchange=uniswapv3
A quick example of how that works:
curl --request GET \
--url 'https://web3api.io/api/v2/market/defi/ohlcv/information/?exchange=uniswapv3' \
--header 'Accept: application/json' \
--header 'x-api-key: YOUR_API_KEY'
Analyzing Deployed Tokens
With Uniswap v3, there is a way to migrate tokens. This allows tokens traded on V2 to utilize a quick method for upgrade & transfer into V3 compatible pairs. This is interesting, since we can now have both completely new liquidity positions in V3 while also having migrated pairs.
Let’s look at an example:
DAI_WETH
This pair represents a stablecoin and wrapped Ether, that should follow closely to the value of Ether in USD. In V3 the new contract is:
0xc2e9f25be6257c210d7adf0d4cd6e3e881ba25f8
In v2, the pair address was:
0xa478c2975ab1ea89e8196811f51a7b7ade33eb11
Taking a look at the migration transaction 0x52c8d13aca777d527c2da0021859f6953e67a405e9348d9b4f5ce5d5f452c0c5 you can see a string of events where the liquidity from V2 was migrated into V3, burning DAI holdings on V2 and then minting DAI holdings in V3. Lastly, you will see an NFT being created to represent the liquidity position of the V3 collateral.
It’s worth noting — not all tokens in V2 need to be migrated, as they can still operate with V2 code deployed on chain. Similarly, V3 holds newly created pairs that don’t exist on V2.
Trade, Price & Top Tokens
To easily understand DEX data, there is a general flow:
1. Trade — The raw price event
2. Price — The price established from trade(s)
3. OHLCV — The price aggregated across trades for a period of time (1 minute)
To get trades for a pair, we can do:
curl --request GET \
--url https://web3api.io/api/v2/market/defi/trades/0xcd9dab5e666de980cecdc180cb31f296733e2587/historical/?exchange=uniswapv3 \
--header 'Accept: application/json' \
--header 'x-api-key: YOUR_API_KEY'
This data shows all of the prices for individual trades, which makes things quite volatile. Let’s look at OHLCV to see a better view of how the market is establishing price over time. To get this, we need to use:
curl --request GET \
--url 'https://web3api.io/api/v2/market/defi/ohlcv/0xcd9dab5e666de980cecdc180cb31f296733e2587/historical/?exchange=uniswapv3&timeInterval=hours' \
--header 'Accept: application/json' \
--header 'x-api-key: YOUR_API_KEY'
Quick pro-tip: Add format=csv
to get the response payload in CSV for easier use in spreadsheets.
Here’s what the OHLCV looks like for our DEX data:
With OHLCV, understanding price is much easier, and incorporates market volatility in a context that keeps the extremes while being representative of the greater market outlook.
Going Further: Realtime DEX Token Streams
Amberdata supports realtime websockets for all DEX data, including Uniswap V3 pairs. It is simple to get started, you only need to create a connection:
$ npm install -g wscat
$ npx wscat -c "wss://ws.web3api.io" -H "x-api-key: <api-key>" -H "x-amberdata-blockchain-id: ethereum-mainnet"connected (press CTRL+C to quit)
Then make sure to configure the exchange in each of the subscriptions to use Uniswap V3 exchange address:
{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["market:dex:trades",{"exchangeId":"0x1f98431c8ad98523631ae4a59f267346ea31f984"}]}
Available Streams:
Reminder: DEX Best practices
In Ethereum, the ERC20 standard allows for duplicate token symbols, which actually breaks the traditional pair and ticker symbol standards. The important takeaway for using DEX data: Use Contract Addresses rather than Pair Names
Example:
DAI_WETH — This pair name covers assets that trade on both Uniswap, Sushiswap and others. On Uniswap itself, DAI & WETH separately have several cloned/same symbol ERC20s. If you just request DAI_WETH the data will include assets that are not the popularly traded “DAI” or “WETH”.
A quick example of asset ordering in Uniswap for a pair: DAI_WETH
0x6b175474e89094c44da98b954eedeac495271d0f (DAI) < 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 (WETH) = true
It’s very important to use the pair address when accessing DEX data!
Make sure you use the information endpoints to get the most accurate data:
"🍣_🦄": {
"baseAddress": "0x5668879873dd1023032af68ed898ea82027587c5",
"quoteAddress": "0xb94b6784f970982a14bafa3d5b7a0407c49112b9",
"address": "0xe3744cc992073549794de98c82152d1aefbb2175"
}
Get Started with Amberata
If you haven’t already, grab a free API key here, and get started using DEX data in your business!
- Website: Amberdata.io
- Twitter: Amberdataio