Derive a Uniswap v4 pool ID for singleton event indexing

Many v4 pools share one PoolManager address. Grouping swaps only by the event emitter collapses unrelated pools into one time series.

Reconstruct the complete pool key

Read the initialization event from the configured PoolManager and retain both ordered currencies, the fee field, signed tick spacing and hook address. Compute the hash of the five ABI words as specified by PoolIdLibrary.

PoolId = keccak256(abi.encode(currency0, currency1, fee, tickSpacing, hooks))

Two pools with the same currencies and fee can still differ by tick spacing or hooks. A packed encoding that concatenates the short integer fields directly will hash different bytes. Compare the derived ID with the event’s indexed ID.

Scope the ID to its deployment

Use chain ID, PoolManager address and pool ID as the indexing context. Identical keys on different chains or managers can yield the same ID. Preserve the original key because a hash alone cannot recover its field values. github.com PoolId.sol