Skip to content

fix(discovery): binary search fallback when totalSupply() reverts#241

Merged
unifiedh merged 2 commits intoConway-Research:mainfrom
tyxben:fix/discovery-binary-search-fallback
Feb 27, 2026
Merged

fix(discovery): binary search fallback when totalSupply() reverts#241
unifiedh merged 2 commits intoConway-Research:mainfrom
tyxben:fix/discovery-binary-search-fallback

Conversation

@tyxben
Copy link
Contributor

@tyxben tyxben commented Feb 27, 2026

Summary

  • The ERC-8004 proxy contract on Base does not implement ERC-721 Enumerable, so totalSupply() reverts
  • The existing fallback (Transfer event scanning) is slow and unreliable due to public RPC block-range limits and per-chunk timeouts
  • Adds estimateTotalByBinarySearch() that probes ownerOf(tokenId) to find the highest minted tokenId in ~15 RPC calls (O(log n))
  • Once the total is known, the main discoverAgents() path iterates by tokenId directly — fast and reliable

Tested 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 typecheck passes
  • Manual test: binary search returns ~20,900 on Base mainnet
  • Manual test: discoverAgents() returns real agent cards (e.g. "MontraFi Agent")
  • CI passes

Open with Devin

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.
devin-ai-integration[bot]

This comment was marked as resolved.

Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@unifiedh unifiedh merged commit 5ed12fd into Conway-Research:main Feb 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants