Skip to content

Commit 079299f

Browse files
authored
Merge pull request #216 from r4topunk/chore/remove-mor-diag
chore(stake): remove temp MOR diagnostics (root cause: Base-only key)
2 parents 61d2360 + 447103a commit 079299f

2 files changed

Lines changed: 7 additions & 13 deletions

File tree

src/app/api/stake-graph/route.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { NextResponse } from "next/server";
2-
import { getStakeGraph, lastMorNote } from "@/services/stake-graph";
2+
import { getStakeGraph } from "@/services/stake-graph";
33

44
// Recompute at most once a minute; serve stale for 5 more while revalidating.
55
export const revalidate = 60;
66

77
export async function GET() {
88
try {
99
const graph = await getStakeGraph();
10-
// Diagnostic: is the Etherscan key present in this deploy's env? (temporary)
11-
const _etherscanKey = Boolean(process.env.ETHERSCAN_API_KEY || process.env.BASESCAN_API_KEY);
12-
return NextResponse.json({ ...graph, _etherscanKey, _morNote: lastMorNote() }, {
10+
return NextResponse.json(graph, {
1311
headers: { "Cache-Control": "public, s-maxage=60, stale-while-revalidate=300" },
1412
});
1513
} catch {

src/services/stake-graph.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,9 @@ const ETHERSCAN_KEY = process.env.ETHERSCAN_API_KEY || process.env.BASESCAN_API_
143143
const USER_REFERRED_SIG = keccak256(toHex("UserReferred(uint256,address,address,uint256)"));
144144
const pad32 = (a: Address) => `0x000000000000000000000000${a.slice(2).toLowerCase()}`;
145145

146-
// Temporary: capture the last Etherscan response so /api/stake-graph can expose
147-
// why the MOR scan came back empty (rate limit vs bad key vs no records).
148-
let _morNote = "init";
149-
export function lastMorNote() { return _morNote; }
150-
151-
/** A rider's referred stakes on a pool, straight from the UserReferred events. */
146+
/** A rider's referred stakes on a pool, straight from the UserReferred events.
147+
* Needs a mainnet-capable Etherscan key (a Basescan-only key returns NOTOK for
148+
* chainid=1) — set ETHERSCAN_API_KEY in the env. */
152149
async function etherscanReferred(pool: Address, referrer: Address, key: string): Promise<Array<{ user: Address; amount: bigint }>> {
153150
const url =
154151
`https://api.etherscan.io/v2/api?chainid=1&module=logs&action=getLogs&address=${pool}` +
@@ -158,13 +155,12 @@ async function etherscanReferred(pool: Address, referrer: Address, key: string):
158155
try {
159156
const res = await fetch(url, { cache: "no-store" });
160157
const j = (await res.json()) as { status?: string; message?: string; result?: unknown };
161-
_morNote = `${j.status ?? "?"}|${String(j.message ?? "?").slice(0, 30)}|${Array.isArray(j.result) ? `n=${j.result.length}` : String(j.result).slice(0, 70)}`;
162158
if (j.status === "1" && Array.isArray(j.result)) {
163159
return (j.result as Array<{ topics: string[]; data: string }>).map((l) => ({ user: getAddress(`0x${l.topics[2].slice(26)}`), amount: BigInt(l.data) }));
164160
}
165161
if (typeof j.message === "string" && /rate limit/i.test(j.message)) { await sleep(500); continue; }
166-
return []; // "No records found"
167-
} catch (e) { _morNote = `throw|${String(e).slice(0, 40)}`; await sleep(300); }
162+
return []; // "No records found" / bad key
163+
} catch { await sleep(300); }
168164
}
169165
return [];
170166
}

0 commit comments

Comments
 (0)