Skip to content

fix(api): floor NFT price rolling average to keep wei strings BigInt-safe#2023

Merged
pikonha merged 1 commit into
mainfrom
hotfix/nouns-nft-price-bigint
Jul 6, 2026
Merged

fix(api): floor NFT price rolling average to keep wei strings BigInt-safe#2023
pikonha merged 1 commit into
mainfrom
hotfix/nouns-nft-price-bigint

Conversation

@brunod-e

@brunod-e brunod-e commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Hotfix for the production outage where every Nouns request through Gateful returned {"error":"DAO service temporarily unavailable"}. Root cause: GET /token/historical-data on NFT-priced DAOs (NOUNS, LIL_NOUNS) crashed with SyntaxError: Cannot convert 0.00000000000000000000 to a BigInt on every call, and five consecutive 500s open the per-DAO gateway circuit breaker, taking the whole DAO offline for 5–40 min.

Context

  • 🔥 Hotfix branched from main (no ticket — found live-debugging prod; Railway logs confirmed the crash in nouns-api production)
  • 🌿 Branch: hotfix/nouns-nft-price-bigint

What changed

  • API: NFTPriceRepository.getHistoricalNFTPrice now wraps the rolling-average window in FLOOR(...) before CAST(... AS TEXT). Postgres AVG() over NUMERIC always emits decimal text (e.g. "200.5000000000000000"), which BigInt() rejects in NFTPriceService — so the endpoint failed on any data. Flooring keeps the contract (integer wei string); precision loss is <1 wei.
  • Tests: PGlite-backed regression test inserts prices 100 and 301 (rolling avg 200.5) and asserts every returned price string is BigInt-parseable and floored ("200").

Self-review summary

  • ✅ QA pass: 6 scenarios verified (decimal avg, integer avg exactness, empty table, offset/limit vs window, getTokenPrice path, huge wei values — no scientific notation)
  • ✅ Engineer pass: fix at the right layer (repairs the repo's sql<string> wei contract for all consumers); FLOOR(numeric) is standard Postgres and PGlite exercises identical semantics
  • ✅ Verification: 705 unit tests pass, typecheck + lint clean
  • ⚠️ Known limitations (deferred, out of hotfix scope):
    • No defensive parse around BigInt(price) in NFTPriceService — a future repo regression would re-trigger the circuit-breaker failure mode
    • Pre-existing: timestamp is sql<number> but cast to TEXT at runtime (string typed as number) — follow-up candidate
    • Related but separate bug: /fluid/token/historical-data 500s with a CoinGecko 404 (coin id), same breaker-opening effect

Changeset

  • @anticapture/api: patch — endpoint bugfix, response schema unchanged (no gateful cascade needed)

🤖 Generated with Claude Code

…safe

Postgres AVG() over NUMERIC always emits decimal text (e.g.
"200.5000000000000000"), and NFTPriceService converts the repository's
price strings straight through BigInt(), which rejects decimals. Every
/token/historical-data request on Nouns/Lil Nouns 500'd, and five
consecutive failures opened the gateway circuit breaker, taking the
whole DAO offline with "DAO service temporarily unavailable".

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
anticapture-storybook Ready Ready Preview, Comment Jul 6, 2026 3:26pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
anticapture Ignored Ignored Jul 6, 2026 3:26pm

Request Review

@github-actions github-actions Bot added the API label Jul 6, 2026
@railway-app railway-app Bot temporarily deployed to anticapture-infra / anticapture-pr-2023 July 6, 2026 15:28 Destroyed

Copy link
Copy Markdown
Collaborator

🎨 UI Review

Automated review · scope check only

This PR only touches .changeset/nouns-nft-price-bigint.md, apps/api/src/repositories/token/nft.ts, and apps/api/src/repositories/token/nft.unit.test.ts — a backend SQL fix (flooring a rolling-average price) in the API repository layer, no rendered UI surface (no .tsx/component/style files, no dashboard-facing copy). Out of scope for a UI review; no findings to report.


Generated by Claude Code

@pikonha pikonha merged commit 0983a9f into main Jul 6, 2026
48 of 55 checks passed
@pikonha pikonha deleted the hotfix/nouns-nft-price-bigint branch July 6, 2026 16:21
@github-actions github-actions Bot mentioned this pull request Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants