States Analytics API
Access detailed position and transaction data using Merkl States Analytics API
The Merkl States Analytics API provides detailed position and transaction data for users across different DeFi protocols. This service is particularly useful for building analytics dashboards, tracking position history, and computing PnL (Profit and Loss) for user positions.
Base URL and Documentation
Base URL: https://merkl-states-analytics-default-17958766110.europe-west1.run.app
Full API Documentation: Swagger Documentation
Authentication
This API requires a bearer authentication token for beta access. Contact the Merkl team to request your access token.
Include your bearer token in the authorization header for all requests:
curl 'https://merkl-states-analytics-default-17958766110.europe-west1.run.app/v0/positions/{userAddress}/{chainId}' \
--header 'authorization: Bearer your-token-here'Available Endpoints
Get User Position History
Fetch historical position data for a user across opportunities (pools, lending markets, etc.):
GET /v0/positions/{userAddress}/{chainId}Path Parameters:
userAddress(required): The user's wallet addresschainId(required): Chain ID to query
Query Parameters:
opportunityIds(optional): Comma-separated opportunity IDs to filter (pool address/ID, token address, vault address, market ID, etc.)enrichPositions(optional, boolean): Set totrueto enrich CLAMM positions with formatted token amounts and global state data. Defaults tofalsefetchHistory(optional, boolean): Set totrueto include history snapshots. Defaults tofalsemaxTimestamp(optional, numeric): Maximum timestamp to fetch data untildaily(optional, boolean): Set totrueto generate daily snapshots from history. Defaults tofalseprotocol(optional, string): Filter positions by protocol name (e.g., "uniswap"). Case-insensitive partial matchfilterByIds(optional, array): Array of specific position IDs to filterpage(optional, numeric): Page number (1-indexed). Defaults to 1items(optional, numeric): Items per page. Defaults to 50
Behavior:
If no
maxTimestampis provided and current time is >1 day ahead of most recent data, uses most recent timestampWhen
daily=true, generates daily snapshots at 86400-second intervals per positionWhen
enrichPositions=true, CLAMM positions (those withpositionId) are automatically enriched with global states and formatted token amountsWhen
protocolis specified, only positions matching that protocol are returned
Examples:
All positions for a user on Ethereum:
Only Uniswap positions with enrichment:
Daily snapshots for specific opportunities:
Get Uniswap Positions for a Pool
Fetch all positions for a specific Uniswap pool on a chain:
Path Parameters:
chainId(required): Chain ID to querypoolId(required): Pool identifier - either an EVM address (0x...) or bytes32 format
Query Parameters:
Same as the user position endpoint: enrichPositions, fetchHistory, maxTimestamp, daily, filterByIds, page, items
Example:
Get all positions for a Uniswap pool on Ethereum with history:
Get Transactions
Fetch state data associated with specific transaction hashes:
Path Parameters:
chainId(required): Chain ID to query transactions from
Query Parameters:
txHashes(required): Comma-separated transaction hashes (e.g., "0x123abc...,0x456def...")reasonFilter(optional): Substring filter for the reason field to narrow results
Response:
Returns an array of state objects, each containing:
blockNumber: Block number where the state was recordedblockTimestamp: Timestamp of the blockchainId: Chain IDprotocol: Protocol identifier (e.g., "uniswap-v3", "aave-v3")campaignType: Campaign type identifierreason: Reason identifier (typically poolAddress_positionId or similar)storingId: Storing identifier for the state setstate: The actual state data (structure varies by protocol)txHashes: Array of transaction hashes associated with this state
Use Cases:
Track state changes caused by specific transactions
Get states impacted by a particular transaction
Examples:
Single transaction:
Multiple transactions:
With reason filter:
Response Format
All position endpoints return data in the following structure:
Use Cases
Position Tracking: Monitor user positions across multiple protocols and chains
PnL Analytics: Calculate profit and loss using historical position data with
fetchHistory=trueanddaily=truePortfolio Visualization: Display user holdings with enriched token amounts using
enrichPositions=trueProtocol Analytics: Aggregate data by protocol using the
protocolfilterPool-Specific Insights: Analyze all positions in a specific pool using the Uniswap pool endpoint
Last updated