2. buildProcessor – Absinthe Docs
Skip to content

2. buildProcessor

Purpose

The buildProcessor function configures Subsquid to fetch only the logs we care about. This is crucial for performance - we want to minimize the amount of data we're processing while ensuring we capture all relevant events.

Implementation

buildProcessor: (base) =>
  base.addLog({
    address: [params.poolAddress],
    topic0: [transferTopic, swapTopic],
  }),

How It Works

Log Filtering Strategy

Address Filtering:
  • address: [params.poolAddress] - Only listen to events from our specific Uniswap V2 pool
  • This dramatically reduces noise from other contracts on the blockchain
Topic Filtering:
  • topic0: [transferTopic, swapTopic] - Only capture Transfer and Swap events
  • topic0 is the first topic in Ethereum event logs (the event signature)

Event Topics

// ERC-20 Transfer event signature
const transferTopic = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
 
// Uniswap V2 Swap event signature
const swapTopic = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822e';

Performance Benefits

Why This Matters

  1. Reduced Data Volume: Only process events from the specific pool we're tracking
  2. Faster Processing: Less data means faster indexing and lower costs
  3. Network Efficiency: Minimize RPC calls and bandwidth usage

Real-World Impact

For a busy Uniswap V2 pool:

  • Without filtering: Could process thousands of irrelevant events per block
  • With filtering: Only processes events from that specific pool contract

Best Practices

Address Filtering

// ✅ Good: Exact pool address
address: ['0x1234567890123456789012345678901234567890']
 
// ❌ Bad: No filtering (processes all contracts)
address: undefined
 
// ❌ Bad: Too broad (multiple unrelated pools)
address: ['0x123...', '0x456...', '0x789...']

Topic Filtering

// ✅ Good: Only relevant events
topic0: [transferTopic, swapTopic]
 
// ❌ Bad: All events (massive overhead)
topic0: undefined
 
// ❌ Bad: Unnecessary events
topic0: [transferTopic, swapTopic, mintTopic, burnTopic]

Configuration Tips

Single Pool vs Multiple Pools

Single Pool (Recommended):
buildProcessor: (base) =>
  base.addLog({
    address: [params.poolAddress],
    topic0: [transferTopic, swapTopic],
  }),
Multiple Pools (Advanced):
buildProcessor: (base) =>
  base.addLog({
    address: params.poolAddresses, // Array of pool addresses
    topic0: [transferTopic, swapTopic],
  }),