feat(schema): store discreteOrder executed amounts as bigint - #124
Merged
Conversation
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
force-pushed
the
feat/executed-amounts-bigint
branch
from
July 23, 2026 14:47
0b23167 to
c25b907
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
discreteOrder.executedSellAmount/executedBuyAmount/executedFeemove fromt.text()tot.bigint()— numeric(78) in Postgres, JSbigintin code.Why
Amounts stored as text can't be sorted or aggregated without casts (the TWAP totals query needed
::numericon every sum), and the SQL-over-HTTP client returned them as opaque strings.Boundaries
toBigIntOrNullhelper (filterAndProcess,fetchOrderStatusByUids,fetchOwnerOrderStatuses, durable-cache remap).toCacheRow/cacheUidStatusesstringify on write, reads convert back./orders-by-ownerstringifies for JSON, same ascreationDate/blockNumberalready did.additionalDatatotals 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 —
updatedAtBlockbehaves 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).