PublishedEngineering
Using dbt for Onchain Data
Decoded tables are a transform. Canonical tables are a model. dbt is the right tool for the second, and the wrong tool for the first.
Context
The decoder is a Rust writer against a live head. dbt runs after the raw and decoded tables are already in ClickHouse.
Method
Canonical models are incremental, filtered by block_number, and unique on (tx_hash, log_index). A reorg deletes the range and the next dbt run fills it.
Findings
dbt tests catch schema drift between decoders — a Uniswap decoder that names amount_in differently from a fork decoder is a failed uniqueness test, not a late-night surprise.
Implications for the data model
Protocol-specific decoding stays out of dbt. Domain unions (dex.trades, token.transfers) live in dbt, where they can be reviewed as SQL.