fix(discovery): binary search fallback when totalSupply() reverts#241
Merged
unifiedh merged 2 commits intoConway-Research:mainfrom Feb 27, 2026
Merged
Conversation
The ERC-8004 proxy contract on Base does not implement ERC-721 Enumerable, so totalSupply() reverts. The existing code returns 0 and falls back to Transfer event scanning, which is slow and unreliable due to RPC block-range limits and timeouts. Add estimateTotalByBinarySearch() that probes ownerOf() to find the highest minted tokenId. Token IDs are sequential, so the max ID equals the total supply. The binary search takes ~15 RPC calls (O(log n)) and completes in seconds, enabling the main discovery path to iterate by tokenId directly. Tested against Base mainnet: correctly found ~20,900 registered agents where the previous code found 0.
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.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
totalSupply()revertsestimateTotalByBinarySearch()that probesownerOf(tokenId)to find the highest minted tokenId in ~15 RPC calls (O(log n))discoverAgents()path iterates by tokenId directly — fast and reliableTested against Base mainnet: correctly discovered ~20,900+ registered agents where the previous code found 0.
Complements #228 (paginated event scanning) and #239 (RPC timeout tuning) — this PR provides a faster primary path while those improve the event-scanning fallback.
Test plan
pnpm typecheckpassesdiscoverAgents()returns real agent cards (e.g. "MontraFi Agent")