You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/registry/erc8004.ts
+7-11Lines changed: 7 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -631,23 +631,19 @@ export async function getRegisteredAgentsByEvents(
631
631
returntrue;
632
632
});
633
633
634
-
// Extract token IDs and owners, most recent first
634
+
// Extract token IDs and owners, sorted by tokenId descending (most recent first).
635
+
// tokenIds are monotonically increasing on mint, so this gives correct
636
+
// newest-first ordering regardless of chunk collection order.
635
637
constagents=uniqueLogs
636
638
.map((log)=>({
637
639
tokenId: (log.args.tokenId!).toString(),
638
640
owner: log.args.toasstring,
639
641
}))
640
-
.reverse()
642
+
.sort((a,b)=>{
643
+
constdiff=BigInt(b.tokenId)-BigInt(a.tokenId);
644
+
returndiff>0n ? 1 : diff<0n ? -1 : 0;
645
+
})
641
646
.slice(0,limit);
642
-
643
-
// The chunks were scanned newest-first, but within each chunk logs are
644
-
// ascending. A simple .reverse() no longer yields a correct descending
645
-
// order, so re-sort by tokenId descending (tokenIds are monotonically
646
-
// increasing on mint).
647
-
agents.sort((a,b)=>{
648
-
constdiff=BigInt(b.tokenId)-BigInt(a.tokenId);
649
-
returndiff>0n ? 1 : diff<0n ? -1 : 0;
650
-
});
651
647
652
648
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)`);
0 commit comments