From dc65a2de9c8b9c98c119dc10f1ddec00c20801ca Mon Sep 17 00:00:00 2001 From: satyakwok Date: Fri, 8 May 2026 21:51:50 +0200 Subject: [PATCH] =?UTF-8?q?feat(api):=20/contracts/pioneers=20=E2=80=94=20?= =?UTF-8?q?earliest=20deploys=20(inverse=20of=20/recent)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /contracts/recent shows newest user-deployed contracts first (rank 1 = freshest deploy). The natural-language reading of "rank 1" is often "the first ever to deploy" though, which is the opposite — earliest, not latest. Add /contracts/pioneers as the ASC counterpart so consumers wanting first-mover / historical leaderboards have the right sort surface and rank 1 actually means "the actual pioneer". Same response shape, same WHERE filter (is_contract=true), only ORDER BY direction flips (DESC → ASC). Ranking is array-position based as before. Endpoint name picked over /first / /oldest because it's punchier + matches the dev-positioning brand voice ("real chain, real blocks, real code"). --- apps/api/src/routes/native.ts | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/apps/api/src/routes/native.ts b/apps/api/src/routes/native.ts index a6b2005..6926b36 100644 --- a/apps/api/src/routes/native.ts +++ b/apps/api/src/routes/native.ts @@ -325,6 +325,49 @@ export function registerNativeRoutes( } ); + // ── /contracts/pioneers ─────────────────────────────────── + // Inverse of /contracts/recent — earliest user-deployed contracts + // first. Useful for "first movers" / historical leaderboards + // (e.g. who deployed the very first FactoryToken on Sentrix). + // rank 1 here = oldest first_seen_block, the actual pioneer. + app.get<{ Querystring: { limit?: string } }>( + "/contracts/pioneers", + async (req) => { + const limit = clampLimit(req.query.limit); + const rows = await ctx.db.execute<{ + address: string; + first_seen_block: string; + last_seen_block: string; + code_hash: string | null; + }>( + sql` + SELECT address, + first_seen_block::text, + last_seen_block::text, + code_hash + FROM ${addresses} + WHERE is_contract = true + ORDER BY ${addresses}.first_seen_block ASC + LIMIT ${limit} + ` + ); + return { + contracts: (rows as unknown as Array<{ + address: string; + first_seen_block: string; + last_seen_block: string; + code_hash: string | null; + }>).map((r, i) => ({ + rank: i + 1, + address: r.address, + first_seen_block: Number(r.first_seen_block), + last_seen_block: Number(r.last_seen_block), + code_hash: r.code_hash, + })), + }; + } + ); + // ── /whale/tx ───────────────────────────────────────────── // Whale transfers: top tx by `value` (native SRX in wei via numeric). // Used by scan leaderboard /whale/recent. Default threshold is the