A specialized blockchain indexer built with Subsquid framework to track LP token positions and swaps in Uniswap V2-compatible DEXes (including Velodrome).
This project is a blockchain indexer designed to track and record:
- LP token positions (time-weighted balances)
- Swap events
- LP token pricing based on underlying token reserves
The indexer processes blockchain events in real-time, maintains historical balance records with time-weighted windows, and includes price computation for LP tokens.
- Processor: Configures and runs the Subsquid processor for listening to EVM events
- Data Model: Handles LP token balances, time windows, and transaction records
- Price Engine: Calculates LP token prices based on underlying reserves and Coingecko price data
- API Client: Sends indexed data to an external API for storage
- Listen for LP token transfers and pool sync events
- Track LP token balances for each account
- Record time-weighted balance windows
- Calculate LP token pricing based on underlying token reserves
- Send data to Absinthe API
- Time-weighted Balance Tracking: Records how long users hold LP positions
- Real-time Price Calculation: Computes LP token prices from reserves and underlying asset prices
- Windowed Data Storage: Creates periodic snapshots of LP token balances
- Robust Error Handling: Includes retry mechanisms for API requests
- Configurable Indexing: Supports different blockchains and pool contracts
The indexer requires the following environment variables:
# Blockchain RPC
RPC_URL=<blockchain_rpc_endpoint>
GATEWAY_URL=<subsquid_gateway>
FROM_BLOCK=<starting_block>
TO_BLOCK=<optional_ending_block>
# Contract info
CONTRACT_ADDRESS=<lp_token_contract>
TOKEN0_COINGECKO_ID=<token0_id>
TOKEN1_COINGECKO_ID=<token1_id>
# API credentials
ABSINTHE_API_URL=<api_endpoint>
ABSINTHE_API_KEY=<api_key>
COINGECKO_API_KEY=<coingecko_key>
- LP tokens follow the ERC-20 standard with Transfer events
- Pool contracts emit Sync events when reserves change
- Price data is available via Coingecko API
- The processor starts indexing from the beginning of the pool's history
- Node.js (v16+)
- pnpm
- PostgreSQL database
npx squid-evm-typegen src/abi ./abi/<abi.json>
# npx squid-typeorm-codegen
# npx squid-typeorm-migration generate
sqd typegen # for abi
sqd codegen # for db
sqd migration:clean # clean
sqd migration:generate # creating migration filesBefore running npx squid-typeorm-migration generate make sure your database is running and is clear
sqd down; sqd up;pnpm installpnpm build
sqd process:prodGenerate sample data with test cases:
node src/__tests__/generate-test-data.jsThe indexer tracks:
- Active Balances: Current LP token holdings per user
- History Windows: Time-weighted balance records
- Pool State: Reserves and total supply
- Pricing Data: USD values of LP tokens
- LP token transfers trigger balance updates
- Records time-weighted balances in periodic windows
- Handles mints, burns, and transfers
- Retrieves price data from Coingecko
- Calculates LP token price based on:
- Token reserves
- Underlying token prices
- LP token total supply
- Sends data to external API endpoint
- Implements exponential backoff for retry logic
- Handles rate limiting via Bottleneck
This project is licensed under the MIT License - see the LICENSE file for details.