Calculating DEX Liquidity Pool Fees and Volumes

Decentralized exchanges are playing an increasingly important role in supporting cryptoasset trading, particularly when it comes to tokens using the ERC-20 standard. Coin Metrics has been actively working on collecting data from major DeFi protocols. For our first release, we have added support for all major liquidity pools on Uniswap v2, Uniswap v3, and Sushiswap v1.

Resources

This notebook demonstrates basic functionality offered by the Coin Metrics Python API Client and DEX Market Data.

Coin Metrics offers a vast assortment of data for hundreds of cryptoassets. The Python API Client allows for easy access to this data using Python without needing to create your own wrappers using requests and other such libraries.

To understand the data that Coin Metrics offers, feel free to peruse the resources below.

File Download

Download the entire notebook as either a jupyter notebook to run yourself or as a pdf from the two links below

Setup

DEX Market Catalog

The catalog/markets endpoint returns a list of available markets along with time ranges of available data. Users can pass in a list of markets, exchanges, or market types (spot, futures, options).

We can retrieve our DEX markets by fetching a list of all 'spot' markets, then filtering for the markets where the 'experimental' parameter equals true.

market
exchange
base
quote
pair
symbol
type
size_asset
margin_asset
strike
...
order_price_increment
order_price_min
order_price_max
order_size_min
order_taker_fee
order_maker_fee
margin_trading_enabled
experimental
base_native
quote_native

0

uniswap_v3_eth-1-1inch-dai-spot

uniswap_v3_eth

1inch

dai

1inch-dai

<NA>

spot

<NA>

<NA>

<NA>

...

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

True

<NA>

<NA>

1

uniswap_v3_eth-1-1inch-usdc-spot

uniswap_v3_eth

1inch

usdc

1inch-usdc

<NA>

spot

<NA>

<NA>

<NA>

...

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

True

<NA>

<NA>

2

uniswap_v3_eth-1-1inch-weth-spot

uniswap_v3_eth

1inch

weth

1inch-weth

<NA>

spot

<NA>

<NA>

<NA>

...

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

True

<NA>

<NA>

3

uniswap_v3_eth-1-ageur_eth-eurcv_eth-spot

uniswap_v3_eth

ageur_eth

eurcv_eth

ageur_eth-eurcv_eth

<NA>

spot

<NA>

<NA>

<NA>

...

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

True

<NA>

<NA>

4

uniswap_v3_eth-1-ageur_eth-usdc-spot

uniswap_v3_eth

ageur_eth

usdc

ageur_eth-usdc

<NA>

spot

<NA>

<NA>

<NA>

...

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

True

<NA>

<NA>

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

220

sushiswap_v1_eth-yfi-sushi-spot

sushiswap_v1_eth

yfi

sushi

yfi-sushi

<NA>

spot

<NA>

<NA>

<NA>

...

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

True

<NA>

<NA>

221

sushiswap_v1_eth-yfi-usdc-spot

sushiswap_v1_eth

yfi

usdc

yfi-usdc

<NA>

spot

<NA>

<NA>

<NA>

...

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

True

<NA>

<NA>

222

sushiswap_v1_eth-yfi-usdt_eth-spot

sushiswap_v1_eth

yfi

usdt_eth

yfi-usdt_eth

<NA>

spot

<NA>

<NA>

<NA>

...

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

True

<NA>

<NA>

223

sushiswap_v1_eth-yfi-wbtc-spot

sushiswap_v1_eth

yfi

wbtc

yfi-wbtc

<NA>

spot

<NA>

<NA>

<NA>

...

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

True

<NA>

<NA>

224

sushiswap_v1_eth-yfi-weth-spot

sushiswap_v1_eth

yfi

weth

yfi-weth

<NA>

spot

<NA>

<NA>

<NA>

...

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

<NA>

True

<NA>

<NA>

2544 rows × 39 columns

0

market

uniswap_v3_eth-1-1inch-dai-spot

exchange

uniswap_v3_eth

base

1inch

quote

dai

pair

1inch-dai

type

spot

pool_config_id

1

contract_address

063332bbf9f8385e4106919b5c6ae2e6a4f72228

fee

0.01

price_includes_fee

False

variable_fee

False

base_address

111111111117dc0aa78b770fa6a738034120c302

quote_address

6b175474e89094c44da98b954eedeac495271d0f

experimental

True

DEX markets include metadata for 3 different smart contracts:

  • contract_address: The address of the liquidity pool contract. Each liquidity pool is a unique instance of a smart contract, deployed at a dedicated address. The pool contract holds both the base and the quote asset.

  • base_address: The address of the ERC-20 token contract associated with the base asset.

  • quote_address: The address of the ERC-20 token contract associated with the quote asset.

pool_config_id
contract_address
base_address
quote_address
fee

0

1

063332bbf9f8385e4106919b5c6ae2e6a4f72228

111111111117dc0aa78b770fa6a738034120c302

6b175474e89094c44da98b954eedeac495271d0f

0.01

1

1

2ee7e6e459fffbbc655f09f2e1b3131abf98c397

111111111117dc0aa78b770fa6a738034120c302

a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48

0.01

2

1

1d1284e43da1de5ee8dd6acbb03f3624cfbd872c

111111111117dc0aa78b770fa6a738034120c302

c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

0.01

3

1

f339217aa24e70eddf900f3b1a78eb9efcdea115

1a7e4e63778b4f12a199c062f3efdd288afcbce8

5f7827fdeb7c20b443265fc2f40845b715385ff2

0.01

4

1

735a26a57a0a0069dfabd41595a970faf5e1ee8b

1a7e4e63778b4f12a199c062f3efdd288afcbce8

a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48

0.01

...

...

...

...

...

...

220

<NA>

f173a7a055340c91dbdf3083ce3babaa7535a03c

0bc529c00c6401aef6d220be8c6ea1667f6ad93e

6b3595068778dd592e39a122f4f5a5cf09c90fe2

0.3

221

<NA>

3a5747cf4e21861e2d0d3d51a0e8737ab4dfadc8

0bc529c00c6401aef6d220be8c6ea1667f6ad93e

a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48

0.3

222

<NA>

f5fbc6ca5c677f1c977ed3a064b9dda14c5e241b

0bc529c00c6401aef6d220be8c6ea1667f6ad93e

dac17f958d2ee523a2206206994597c13d831ec7

0.3

223

<NA>

1d108372a83fbc3a0bfb7ca4d0e427449e7a5ca2

0bc529c00c6401aef6d220be8c6ea1667f6ad93e

2260fac5e5542a773aa44fbcfedf7c193bc2c599

0.3

224

<NA>

088ee5007c98a9677165d78dd2109ae4a3d04d0c

0bc529c00c6401aef6d220be8c6ea1667f6ad93e

c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

0.3

2544 rows × 5 columns

Each liquidity pool is also associated with a corresponding fee percentage. With each trade, fees are distributed pro-rata to the pool's liquidity providers.

0

0

0.01

1

0.05

2

0.3

3

1.0

Due to the permissionless nature of provisioning a liquidity pool, users can easily add arbitrary ERC-20 tokens to the decentralized exchange. There are over 50,000 trading pairs available on Uniswap today. To prioritize only the most relevant and liquid markets, we cover the subset of markets where both tokens are part of Coin Metrics reference rate coverage.

The majority of DEX assets trade against Wrapped Ether (WETH). Note that Ethereum's native asset ETH is not supported in Uniswap V2/V3, as the asset was created prior to the ERC-20 standard. From the Uniswap documentation:

"Unlike Uniswap V1 pools, V2 pairs do not support ETH directly, so ETH⇄ERC-20 pairs must be emulated with WETH. The motivation behind this choice was to remove ETH-specific code in the core, resulting in a leaner codebase. End users can be kept fully ignorant of this implementation detail, however, by simply wrapping/unwrapping ETH in the periphery." docs.uniswap.org

Using the min_time parameter, we can filter for the newest DEX liquidity pool deployed in our coverage

2016

index

656

market

uniswap_v3_eth-3-usdt_eth-crvusd_eth-spot

min_time

2024-09-28 07:12:59+00:00

max_time

2024-10-03 18:50:35+00:00

DEX Swaps Data

Swaps data is served through our existing /timeseries/market-trades endpoint because swaps are conceptually identical to a trade. Users can see all the standard trade fields for a swap such as time, price, and volume but can also see defi-specific fields such as the block height, block hash, transaction id, addresses involved in the swap, and more.

market
time
coin_metrics_id
amount
price
database_time
side
block_hash
block_height
txid
initiator
sender
beneficiary

0

uniswap_v3_eth-2-weth-usdt_eth-spot

2024-09-30 15:53:23+00:00

04V5RQT2E04FT3C4GH7U1MGVR9VR7AUFALO31HO6QSOKR9...

0.128299

2607.212871

2024-09-30 15:53:34.441041+00:00

sell

a27008fe8d84844fe0da1fda7fb3abcf557030c706d731...

20864491

ae1fd1a682a4acfaddd474f06d9cbc7fe903435b465b65...

8249187b3b1f22da84b1c82eb876a2004d60e5a7

3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad

3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad

1

uniswap_v3_eth-2-weth-usdt_eth-spot

2024-09-30 15:55:11+00:00

04V5RT664167K4H7OBE0IQ00JBU0GG2K0O9O102M1TS37N...

8.010022

2605.89657

2024-09-30 15:55:23.154367+00:00

sell

c6204c7a1227c2dc0968009afc08405406138080560f78...

20864500

a585c10e6fa329213cfc758189b3dee4fbdd11f84b0090...

a172577031eafd8b03dce022533863fe988159cd

51c72848c68a965f66fa7a88855f9f7784502a7f

51c72848c68a965f66fa7a88855f9f7784502a7f

2

uniswap_v3_eth-2-weth-usdt_eth-spot

2024-09-30 15:55:35+00:00

04V5RTJ008QUN6D495DB7M93HLAHH6RUCO7GALPGLR6JRU...

3.275656

2605.139188

2024-09-30 15:55:48.193560+00:00

buy

600235eb99a4495ab3d9238d55189b7e660f055730aecd...

20864502

983dd154bcd17d715def39a8a46e36d5b8f765f73bde82...

8ae57a027c63fca8070d1bf38622321de8004c67

ef1c6e67703c7bd7107eed8303fbe6ec2554bf6b

ef1c6e67703c7bd7107eed8303fbe6ec2554bf6b

3

uniswap_v3_eth-2-weth-usdt_eth-spot

2024-09-30 15:55:59+00:00

04V5RU5PJI877ESIO9ET0AAEOBK5UBINH6ER8NCIB3U2KG...

6.002656

2604.703261

2024-09-30 15:56:09.664424+00:00

sell

b99c9073bb92c25dd0294ec2e85f2e57899db45d9258fc...

20864504

cb9eda573eef860fe7019837c23a66b881e5e4b28549e7...

d1fa51f2db23a9fa9d7bb8437b89fb2e70c60cb7

d4bc53434c5e12cb41381a556c3c47e1a86e80e3

d4bc53434c5e12cb41381a556c3c47e1a86e80e3

4

uniswap_v3_eth-2-weth-usdt_eth-spot

2024-09-30 15:56:11+00:00

04V5RUDJMTR74RDCP4JUIDIL6UN9UTSE7MEBP0BR3USP60...

0.399800

2603.679987

2024-09-30 15:56:23.744604+00:00

sell

b3b776726dacc927e9365537ae9f778e3d9cbc817b1fb9...

20864505

0083045534c1203964355113751c48cb79f262f70edcf7...

81fe73a6fb28c49c14c82fcae2a4fe19f57d150c

3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad

3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad

0

market

uniswap_v3_eth-2-weth-usdt_eth-spot

time

2024-09-30 15:53:23+00:00

coin_metrics_id

04V5RQT2E04FT3C4GH7U1MGVR9VR7AUFALO31HO6QSOKR9...

amount

0.128299

price

2607.212871

database_time

2024-09-30 15:53:34.441041+00:00

side

sell

block_hash

a27008fe8d84844fe0da1fda7fb3abcf557030c706d731...

block_height

20864491

txid

ae1fd1a682a4acfaddd474f06d9cbc7fe903435b465b65...

initiator

8249187b3b1f22da84b1c82eb876a2004d60e5a7

sender

3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad

beneficiary

3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad

Unlike centralized exchanges, where there is an unknown buyer and a seller, each swap is associated with 3 different Ethereum addresses:

  • Initiator is the ethereum address which submitted the transaction as a result of which the swap/liquidity action occurred

  • Sender is the ethereum address that invoked the uniswap pool smart contract's function for swapping or adding/removing liquidity

  • Beneficiary is the ethereum address that got credited with the output tokens (in case of a swap or liquidity removal) or with liquidity (in case of liquidity addition)

2628

market

uniswap_v3_eth-2-weth-usdt_eth-spot

time

2024-10-07 18:39:35+00:00

coin_metrics_id

04VIAJ3J2LDTBQKN8T3DB7MJM1EP7SID408V74DL4USTFL...

amount

1192.565431

price

2274.221925

database_time

2024-10-07 18:39:54.427105+00:00

side

buy

block_hash

73155bd5ea974746d59ed3b05d93f24d2011f391b527b9...

block_height

20915532

txid

cb93842f093812b85469b576914d02907345d2624e1eee...

initiator

b5eaac5a8649142dcdd13f981767913bcdf7ee42

sender

ddc25c965443834179438c2eb30e70f34b854a04

beneficiary

ddc25c965443834179438c2eb30e70f34b854a04

DEX Volume (USD)

2712158.449637

Datetime

2024-10-07 18:00:00

ATLAS by Coin Metrics Blockchain Search Engine BUYER ADDRESS: https://atlas.coinmetrics.io/address-details?asset=weth&address=ddc25c965443834179438c2eb30e70f34b854a04 TRANSACTION INFO: https://atlas.coinmetrics.io/transaction-details?asset=weth&tx_hash=cb93842f093812b85469b576914d02907345d2624e1eee463999bade940a8851 BlOCK INFO: https://atlas.coinmetrics.io/block-details?asset=weth&block_hash=73155bd5ea974746d59ed3b05d93f24d2011f391b527b9d7d5c42e59752c6d41 For more info on ATLAS visit: https://coinmetrics.io/atlas/

DEX Volume (USD)

Datetime

2024-10-06 11:00:00

217166.26046

2024-10-06 12:00:00

438390.416765

2024-10-06 13:00:00

533070.744054

2024-10-06 14:00:00

1163987.797628

2024-10-06 15:00:00

705547.880282

...

...

2024-10-09 06:00:00

625096.999423

2024-10-09 07:00:00

485056.495087

2024-10-09 08:00:00

553334.67282

2024-10-09 09:00:00

462252.636566

2024-10-09 10:00:00

102118.526838

72 rows × 1 columns

Retrieving volume for a centralized exchange via the market-candles endpoint

DEX Volume (USD)
CEX Volume (USD)

Datetime

2024-10-06 12:00:00

438390

946175

2024-10-06 13:00:00

533070

1258087

2024-10-06 14:00:00

1163987

3316466

2024-10-06 15:00:00

705547

2654936

2024-10-06 16:00:00

551985

1881551

...

...

...

2024-10-09 05:00:00

550504

1912136

2024-10-09 06:00:00

625096

2814167

2024-10-09 07:00:00

485056

4493300

2024-10-09 08:00:00

553334

2393424

2024-10-09 09:00:00

462252

2559575

70 rows × 2 columns

Last updated

Was this helpful?