fix: validate DexScreener response before caching (M7)#95
fix: validate DexScreener response before caching (M7)#950x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
Conversation
DexScreener responses were cached before validation. A 200 OK response with empty pairs, zero liquidity, or invalid price was cached for 10s, suppressing fresh fetches even if DexScreener would return valid data on retry. Move cache write to after all validation gates pass. Only responses that produce a valid price (non-null pairs, above MIN_LIQUIDITY_USD, finite positive priceUsd) are now cached. Bad responses allow immediate retry on the next call. Safe for rate limits: BM2 in-flight deduplication prevents concurrent requests, and the 5s push rate limit caps query frequency. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughUpdated Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/services/oracle.ts (1)
95-96: Use insertion-time timestamp for cache freshness.Line 140 stores
fetchedAt: now, butnowis captured before the HTTP call (Line 95). Slow responses shrink effective TTL and reduce rate-limit protection. Prefer capturingfetchedAtimmediately before cache insertion.Suggested patch
- dexScreenerCache.delete(mint); - dexScreenerCache.set(mint, { data: json, fetchedAt: now }); + const fetchedAt = Date.now(); + dexScreenerCache.delete(mint); + dexScreenerCache.set(mint, { data: json, fetchedAt });Also applies to: 140-140
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/services/oracle.ts` around lines 95 - 96, The cache uses a timestamp captured before the HTTP call (const now = Date.now() near dexScreenerCache.get(mint)) which can make fetchedAt stale for slow requests; update the code to compute the insertion timestamp (e.g., const fetchedAt = Date.now()) immediately before inserting into dexScreenerCache.set(...) and store that fetchedAt instead of the earlier now value so TTL/rate-limit logic uses the actual cache insertion time; adjust any references to fetchedAt/now in the same function (where you build the cache entry for mint) accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/services/oracle.ts`:
- Around line 95-96: The cache uses a timestamp captured before the HTTP call
(const now = Date.now() near dexScreenerCache.get(mint)) which can make
fetchedAt stale for slow requests; update the code to compute the insertion
timestamp (e.g., const fetchedAt = Date.now()) immediately before inserting into
dexScreenerCache.set(...) and store that fetchedAt instead of the earlier now
value so TTL/rate-limit logic uses the actual cache insertion time; adjust any
references to fetchedAt/now in the same function (where you build the cache
entry for mint) accordingly.
Summary
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit