Output
sf.substreams.sink.database.v1.DatabaseChanges

Package ref
clickhouse-polymarket@v0.1.2Run package
CLI
Run db_out from the command line.
substreams run clickhouse-polymarket@v0.1.2 db_out -e polygon --start-block -1substreams auth or directly on thegraph.market (see docs).README
This directory contains the ClickHouse schema for ingesting Polymarket event data from Substreams.
The schema is organized into layers, with numbered prefixes indicating the dependency order:
schema.0.*)schema.0.blocks.sql - Block metadata tableschema.0.templates.sql - Template tables for transactions and logs that other tables inherit fromschema.1.*)Event-specific tables that extend the template tables:
schema.1.conditional_tokens.sql - ConditionalTokens contract events (ConditionPreparation, ConditionResolution, PositionSplit, PositionsMerge, PayoutRedemption)schema.1.ctf_exchange.sql - CTFExchange contract events (OrderFilled, OrdersMatched, FeeCharged, etc.)schema.1.fee_module.sql - FeeModule contract eventsschema.1.negrisk_adapter.sql - NegRiskAdapter contract eventsschema.1.safe_proxy_factory.sql - SafeProxyFactory contract eventsschema.1.uma_ctf_adapter.sql - UmaCtfAdapter contract eventsschema.2.mv.*)AggregatingMergeTree tables with materialized views for real-time aggregation:
schema.2.mv.state_open_interest.sql - Open interest aggregated by condition and time intervalschema.2.mv.state_orderbook.sql - Order book metrics aggregated by asset and time intervalschema.2.mv.state_user_condition_position.sql - User positions by condition (from splits/merges/redemptions)schema.2.mv.state_user_position.sql - User positions by token (from exchange trades)schema.3.view.*)Convenience views that query the aggregated state tables:
schema.3.view.open_interest.sql - Open interest views (per-condition and global)schema.3.view.orderbook.sql - Order book views (per-asset and global)schema.3.view.user_condition_position.sql - User condition position viewsschema.3.view.user_position.sql - User position views with PNL calculationsThe materialized views aggregate data at multiple time intervals:
USDC has 6 decimals. The views provide both raw amounts (in base units) and scaled amounts (divided by 10^6) for convenience.
Modules
Output
sf.substreams.sink.database.v1.DatabaseChanges