Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/registry/erc8004.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,23 +615,19 @@ export async function getRegisteredAgentsByEvents(
return true;
});

// Extract token IDs and owners, most recent first
// Extract token IDs and owners, sorted by tokenId descending (most recent first).
// tokenIds are monotonically increasing on mint, so this gives correct
// newest-first ordering regardless of chunk collection order.
const agents = uniqueLogs
.map((log) => ({
tokenId: (log.args.tokenId!).toString(),
owner: log.args.to as string,
}))
.reverse()
.sort((a, b) => {
const diff = BigInt(b.tokenId) - BigInt(a.tokenId);
return diff > 0n ? 1 : diff < 0n ? -1 : 0;
})
.slice(0, limit);

// The chunks were scanned newest-first, but within each chunk logs are
// ascending. A simple .reverse() no longer yields a correct descending
// order, so re-sort by tokenId descending (tokenIds are monotonically
// increasing on mint).
agents.sort((a, b) => {
const diff = BigInt(b.tokenId) - BigInt(a.tokenId);
return diff > 0n ? 1 : diff < 0n ? -1 : 0;
});

logger.info(`Event scan found ${agents.length} minted agents (scanned ${allLogs.length} Transfer events across ${Math.ceil(Number(currentBlock - earliestBlock) / Number(MAX_BLOCK_RANGE))} chunks)`);
return agents;
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1347,15 +1347,15 @@ export interface MessageValidationResult {

export interface DiscoveryConfig {
ipfsGateway: string; // default: "https://ipfs.io"
maxScanCount: number; // default: 20
maxScanCount: number; // default: 100
maxConcurrentFetches: number; // default: 5
maxCardSizeBytes: number; // default: 64000
fetchTimeoutMs: number; // default: 10000
}

export const DEFAULT_DISCOVERY_CONFIG: DiscoveryConfig = {
ipfsGateway: "https://ipfs.io",
maxScanCount: 20,
maxScanCount: 100,
maxConcurrentFetches: 5,
maxCardSizeBytes: 64_000,
fetchTimeoutMs: 10_000,
Expand Down
Loading