@@ -143,6 +143,11 @@ const ETHERSCAN_KEY = process.env.ETHERSCAN_API_KEY || process.env.BASESCAN_API_
143143const USER_REFERRED_SIG = keccak256 ( toHex ( "UserReferred(uint256,address,address,uint256)" ) ) ;
144144const 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+
146151/** A rider's referred stakes on a pool, straight from the UserReferred events. */
147152async function etherscanReferred ( pool : Address , referrer : Address , key : string ) : Promise < Array < { user : Address ; amount : bigint } > > {
148153 const url =
@@ -151,16 +156,15 @@ async function etherscanReferred(pool: Address, referrer: Address, key: string):
151156 `&fromBlock=0&toBlock=latest&page=1&offset=1000&apikey=${ key } ` ;
152157 for ( let i = 0 ; i < 3 ; i ++ ) {
153158 try {
154- // no-store so each retry is a real call — the route's own cache (60s)
155- // handles caching, and a transient rate-limit won't stick in the data cache.
156159 const res = await fetch ( url , { cache : "no-store" } ) ;
157- const j = ( await res . json ( ) ) as { status ?: string ; message ?: string ; result ?: Array < { topics : string [ ] ; data : string } > } ;
160+ const j = ( await res . json ( ) ) as { status ?: string ; message ?: string ; result ?: unknown } ;
161+ _morNote = `${ j . status ?? "?" } |${ String ( j . message ?? "?" ) . slice ( 0 , 40 ) } |${ Array . isArray ( j . result ) ? j . result . length : typeof j . result } ` ;
158162 if ( j . status === "1" && Array . isArray ( j . result ) ) {
159- return j . result . map ( ( l ) => ( { user : getAddress ( `0x${ l . topics [ 2 ] . slice ( 26 ) } ` ) , amount : BigInt ( l . data ) } ) ) ;
163+ return ( j . result as Array < { topics : string [ ] ; data : string } > ) . map ( ( l ) => ( { user : getAddress ( `0x${ l . topics [ 2 ] . slice ( 26 ) } ` ) , amount : BigInt ( l . data ) } ) ) ;
160164 }
161165 if ( typeof j . message === "string" && / r a t e l i m i t / i. test ( j . message ) ) { await sleep ( 500 ) ; continue ; }
162166 return [ ] ; // "No records found"
163- } catch { await sleep ( 300 ) ; }
167+ } catch ( e ) { _morNote = `throw| ${ String ( e ) . slice ( 0 , 40 ) } ` ; await sleep ( 300 ) ; }
164168 }
165169 return [ ] ;
166170}
0 commit comments