Skip to content

feat(schema): store discreteOrder executed amounts as bigint - #124

Merged
yvesfracari merged 1 commit into
mainfrom
feat/executed-amounts-bigint
Jul 23, 2026
Merged

feat(schema): store discreteOrder executed amounts as bigint#124
yvesfracari merged 1 commit into
mainfrom
feat/executed-amounts-bigint

Conversation

@yvesfracari

Copy link
Copy Markdown
Contributor

Stacked on #123 (which is stacked on #122).

What

discreteOrder.executedSellAmount / executedBuyAmount / executedFee move from t.text() to t.bigint() — numeric(78) in Postgres, JS bigint in code.

Why

Amounts stored as text can't be sorted or aggregated without casts (the TWAP totals query needed ::numeric on every sum), and the SQL-over-HTTP client returned them as opaque strings.

Boundaries

  • Orderbook API → DB: decimal strings convert via a single toBigIntOrNull helper (filterAndProcess, fetchOrderStatusByUids, fetchOwnerOrderStatuses, durable-cache remap).
  • cow_cache keeps TEXT columns (it survives reindexes and is shared with older builds); toCacheRow / cacheUidStatuses stringify on write, reads convert back.
  • REST /orders-by-owner stringifies for JSON, same as creationDate / blockNumber already did.
  • additionalData totals stay decimal strings — JSON can't represent bigint.

Heads-up

GraphQL responses look the same as before: Ponder exposes bigint columns as the BigInt scalar, which serializes as a quoted decimal string in JSON (uint256 doesn't fit a JSON number — updatedAtBlock behaves the same today). The gain is the DB-side type, ordering, and cast-free aggregation.

The flash-loan order table still stores text amounts; happy to convert it in a follow-up for consistency.

Verification

pnpm codegen, pnpm typecheck, pnpm lint, pnpm test (159) all green. Also smoke-tested by running the indexer from a ~1-day-old start block (results in the PR conversation of #122).

Base automatically changed from fix/stale-executed-fee-cache to main July 23, 2026 14:45
executedSellAmount / executedBuyAmount / executedFee move from t.text()
to t.bigint() (numeric(78) in Postgres), so the DB sorts and aggregates
them as numbers and the TWAP totals query no longer needs ::numeric
casts.

Conversions happen at the boundaries:
- orderbook API strings -> bigint via toBigIntOrNull (filterAndProcess,
  fetchOrderStatusByUids, fetchOwnerOrderStatuses, remap)
- cow_cache tables keep TEXT columns; toCacheRow / cacheUidStatuses
  stringify on write, reads convert back
- the /orders-by-owner REST endpoint stringifies for JSON (same
  treatment as creationDate/blockNumber)

Note: GraphQL output is unchanged — Ponder exposes bigint columns as
the BigInt scalar, which serializes as a decimal string in JSON (JSON
numbers can't hold uint256). The flash-loan order table still stores
text amounts; converting it is a separate change if wanted.
@yvesfracari
yvesfracari force-pushed the feat/executed-amounts-bigint branch from 0b23167 to c25b907 Compare July 23, 2026 14:47
@yvesfracari
yvesfracari merged commit c4260a8 into main Jul 23, 2026
2 checks passed
@yvesfracari
yvesfracari deleted the feat/executed-amounts-bigint branch July 23, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant