feat(holders): add is_contract flag on /v1/evm/holders#534
Merged
Conversation
Adds an is_contract boolean field to /v1/evm/holders and /v1/evm/holders/native, derived from the indexed contracts table. Lets consumers compute accurate concentration metrics without per-address eth_getCode round trips against an external RPC. The SQL pattern materializes top-N balances once into a row array then expands via arrayJoin, reusing the address list to pre-filter the contracts lookup via primary key. Avoids the full-table hash build a plain JOIN would trigger. Closes #523 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
is_contract: booleanto/v1/evm/holdersand/v1/evm/holders/nativeresponses, derived from the existing indexedcontractstable.eth_getCoderound trips. Top-10 holder lists routinely look catastrophic (90%+ concentration) until you discount addresses that are bridges, staking modules, LP pools, or vesting timelocks — this flag closes that gap server-side.SQL pattern
A straightforward
LEFT ANY JOIN contracts AS c ON c.address = b.addresscauses ClickHouse to build a hash from the full contracts table regardless of how few left-side addresses we have. Runtime filter pushdown happens after the read, not at the primary-key index level.To avoid that, the new SQL:
groupArray(tuple(...)).arrayJoin(arrayMap(...))) as a constantINpredicate on the contracts table — small literal set, primary-key index pruning kicks in.arrayJoinin the mainFROM— no secondbalances FINALpass.Result:
balances FINALruns once; the contracts read is bounded by the looked-up addresses.🤖 Generated with Claude Code