fix(explorer): fix token holder count for high-volume tokens like PathUSD#789
Open
fix(explorer): fix token holder count for high-volume tokens like PathUSD#789
Conversation
Bundle Size Report
Chunk changes (>1KB)
Compared against main branch (baseline from 2/4/2026, 5:13:51 PM) |
Cloudflare Deployments
|
Member
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…hUSD Replace GROUP BY (from, to) with two separate queries grouped by individual holder (GROUP BY to for received, GROUP BY from for sent). This reduces row count from O(unique_transfer_pairs) to O(unique_holders), avoiding truncation by tidx's 10k row hard limit. Co-authored-by: o-az <23618431+o-az@users.noreply.github.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d2c9a-d957-714c-add1-f823c928ddfe
PathUSD has more unique senders than tidx's 10k row limit, so even with the GROUP BY holder fix, results were still truncated. Add a fetchAllPages helper that paginates through the limit using LIMIT/OFFSET. Co-authored-by: o-az <23618431+o-az@users.noreply.github.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d2c9a-d957-714c-add1-f823c928ddfe
The LIMIT/OFFSET approach causes tidx to return empty results for all tokens, likely due to interaction with the CTE-based query rewriting. The GROUP BY holder fix alone already fixes most tokens (USDC.e went from 3,168 to 7,943 holders). PathUSD still needs a tidx-side fix for tokens with >10k unique senders. Co-authored-by: o-az <23618431+o-az@users.noreply.github.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d2c9a-d957-714c-add1-f823c928ddfe
d07408b to
eaf2d02
Compare
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
PathUSD shows 0 holders on the tokens list page while USDC.e was undercounted at 3,168 (correct count: ~7,942).
Motivation
The token holder count query used
GROUP BY (from, to)to aggregate Transfer events, producing one row per unique transfer pair. For high-volume tokens, this creates far more rows than tidx's 10,000-row hard limit. The query silently truncates, and the incomplete data aggregates to incorrect holder counts.Changes
GROUP BY (from, to)query into two separate queries: one for received amounts (GROUP BY to) and one for sent amounts (GROUP BY from)O(unique_transfer_pairs)toO(unique_senders + unique_receivers)fetchTokenHolderBalances(single token) andfetchTokenHoldersCountRows(batch)Results
USDC.e holders: 3,168 → 7,942 (correct count restored)
PathUSD still shows 0 because it has >10k unique senders (every tx on Tempo pays fees in PathUSD). Fixing this fully requires raising tidx's hard limit or adding server-side pagination support in tidx.
Screenshots
Preview URL: https://15d92daa-explorer-mainnet.porto.workers.dev/tokens
Testing
pnpm check:typespassespnpm checkpassesPrompted by: omar