Skip to main content

A deployless multicall library for fetching DEX pool metadata

Project description

DexMetadata 🦄

Quickly fetch metadata for DEX pools with a single function call!

Usage 🚀

from dexmetadata import fetch

POOL_ADDRESSES = [
    "0x31f609019d0CC0b8cC865656142d6FeD69853689",  # POPCAT/WETH on uniswap v2
    "0xfBB6Eed8e7aa03B138556eeDaF5D271A5E1e43ef",  # cbBTC/USDC on uniswap v3
    "0x6cDcb1C4A4D1C3C6d054b27AC5B77e89eAFb971d",  # AERO/USDC on Aerodrome
    "0x323b43332F97B1852D8567a08B1E8ed67d25A8d5",  # msETH/WETH on Pancake Swap
    # Add hundreds more without worry!
]

# Fetch metadata with automatic batching and progress bars
metadata = fetch(
    POOL_ADDRESSES, 
    network="base", 
    batch_size=30,
    max_concurrent_batches=25,
    show_progress=True,
)

# [
#   {
#     'pool_address': '0x31f609019d0cc0b8cc865656142d6fed69853689',
#     'token0_address': '0x4200000000000000000000000000000000000006',
#     'token0_decimals': 18,
#     'token0_name': 'Wrapped Ether',
#     'token0_symbol': 'WETH',
#     'token1_address': '0x64fcfe0b4430b878cfd00d6539ac244f2e1e9d29',
#     'token1_decimals': 18,
#     'token1_name': 'Popcat',
#     'token1_symbol': 'POPCAT'
#   },
#   # ...more pools
# ]

Installation 📥

uv add dexmetadata

How It Works 🔍

  1. On each eth_call we "deploy" a special contract using the deployless multicall trick
  2. Contract executes with a batch of pool addresses in the EVM and fetches both tokens in each pool
  3. Then for each token we get token name, symbol, and decimals using optimized assembly calls
  4. The result is decoded in Python and returned as a list of dictionaries
  5. For async execution, multiple batches are processed concurrently using asyncio

Performance

The parameter optimizer finds good settings for your RPC provider:

$ uv run examples/optimize.py --rpm 1800 --rpc https://rpc.ankr.com/base

Measuring response time with optimal batch size...
Average response time: 2.51s

Optimal parameters:
  batch_size: 30
  max_concurrent_batches: 25

In real-world testing, the fetch script processed 1000 pools in ~6s (~160 pools/s).

The default parameters (batch_size=30, max_concurrent_batches=25) are optimized for ankr and deliver good performance while staying within rate limits.

Alternative Approaches

In the end it's all about deciding the main trade offs regarding where and when to process the data, at a node, off-chain in a data lake, on the client, during the query or in advance, etc ...

Event cache

Build a cache for all pools and tokens metadata.

  • ❌ Requires custom decoding logic for each DEX
  • ❌ Needs historical data access
  • ❌ Need to maintain potentially large metadata cache
  • ❌ Inneficient processing of large numbers of pools / block ranges that wont be queried
  • ✅ Fast offchain lookups once cached

Naive web3.py

  • ❌ Requires ABI setup for each DEX
  • ❌ Slow for large numbers of pools (1 RPC call per operation)
  • ✅ Simple implementation, no event scanning
  • ✅ Works on any EVM chain with basic RPC support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dexmetadata-0.1.0.tar.gz (14.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dexmetadata-0.1.0-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file dexmetadata-0.1.0.tar.gz.

File metadata

  • Download URL: dexmetadata-0.1.0.tar.gz
  • Upload date:
  • Size: 14.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.1

File hashes

Hashes for dexmetadata-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d410123def92ea8013f4cb821ce76af492890b89635103f8b2d948da9171dd92
MD5 d3c3ae605def2e3e4e1d5a2e2e56e6dd
BLAKE2b-256 a9d23c38c348a0ac9333505b5c0bca71210980f7924bd8eea613e7122761c8cd

See more details on using hashes here.

File details

Details for the file dexmetadata-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dexmetadata-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85de63c8671af98142de5fbc80bb296427f5aa713b68f0967cd7dd86fda47f36
MD5 29517b2917b241d3785b5b6aec6a4dd5
BLAKE2b-256 932b4363f2a7675f31269a56315fdb0ff3b51b77fc92718776efe3f682bcf16d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page