This squid indexer tracks events emitted by Uniswap V4 smart contracts. It provides a comprehensive view of the Uniswap V4 ecosystem, including pools, positions, tokens, and various metrics. The squid is configured to support multiple chains, currently including Ethereum, Unichain and Base.
Dependencies: Node.js, Git, Docker.
Here are the commands to run the squid:
# Prerequisite - Install Squid CLI:
npm i -g @subsquid/cli
# 1. Clone the repository
git clone https://github.com/SQD-Boost/uniswap-v4-squid
cd uniswap-v4-squid
# 2. Install dependencies
npm ci
# 3. Generate entities class and types
sqd codegen
sqd typegen
# 4. Create a .env file with custom configuration
cp .env.example .env
# (Don't forget to add your RPC endpoints to the .env file when running locally)
# 5. Start a Postgres database container
sqd up
# 6. Generate database migrations
sqd migration:generate
# 7. Run the squid
# For a specific chain:
sqd process:{CHAIN_TAG} # e.g., sqd process:eth or sqd process:base
# For all configured chains:
sqd run .
# 8. (in a separate terminal) Start the GraphQL server (only needed for single-chain mode)
sqd serveGraphiQL playground will be available at localhost:{GQL_PORT}/graphql once the database and the GraphQL server are started.
To add support for a new network to the squid, follow these steps:
-
Configure Network Constants
-
Create a new file
./config/{CHAIN_TAG}/network.constant.ts:mkdir -p ./config/{CHAIN_TAG} touch ./config/{CHAIN_TAG}/network.constant.ts -
Add the new network configuration with required parameters in the created file
-
-
Generate Indexer Files
npm network:add {CHAIN_TAG} -
Update Networks List
- Open
./scripts/genfiles - Add the new chain tag to the networks array
- Open
-
Generate Files
npm run gen
-
Prefetch Token States
sqd get-tokens:{CHAIN_TAG} -
Run the Squid
- For the new chain only:
sqd process:{CHAIN_TAG} - For all chains including the new one:
sqd run .
- For the new chain only:
The squid implements a permission control system through the permissionReccordTx configuration, which allows fine-grained control over which types of transactions are recorded in the database. This system offers several benefits:
-
Performance Optimization
- Reduces database load by selectively recording only necessary transactions
- Improves indexing speed by skipping non-essential data
-
Customizable Data Collection
- Control recording of specific transaction types:
modifyLiquidity: Liquidity modification eventsswap: Token swap eventsdonate: Donation eventspoolhourdata: Hourly pool statisticspooldaydata: Daily pool statisticstokenhourdata: Hourly token statisticstokendaydata: Daily token statistics
- Control recording of specific transaction types:
The squid also implements configurable block intervals for certain operations:
export const block_intervals = {
poolsTvlUSD: 10, // Update TVL every 10 blocks
coreTotalUSD: 15, // Update core totals every 15 blocks
};This configuration helps optimize performance by controlling how frequently certain calculations are performed, reducing the computational load.
The squid implements an efficient token state caching mechanism through the tokensRetriever tool. This system provides several key benefits:
-
Persistent Token Data
- Token information (address, name, symbol, decimals) is stored in a JSON file
- Data is persisted between indexing runs
- Eliminates the need to re-fetch token data on each reindexing
-
RPC Call Optimization
- Reduces the number of RPC calls to the blockchain
- Only fetches token data for new tokens
- Caches token metadata to avoid repeated lookups
-
Performance Benefits
- Significantly faster reindexing times
- Reduced network load
- Lower RPC endpoint usage
The token state is stored in ./assets/{CHAIN_TAG}/tokens.json and is automatically managed by the squid. This caching mechanism is particularly important for networks with a large number of tokens, as it prevents unnecessary RPC calls during reindexing operations.