Skip to content

fix: make VWAP route network-aware and sync openapi.json (#235) - #605

Merged
Miracle656 merged 1 commit into
Divinity-Labs:mainfrom
Nwapu-TrustJah:main
Oct 23, 2026
Merged

Miracle656 merged 1 commit into
Divinity-Labs:mainfrom
Nwapu-TrustJah:main

Conversation

@Nwapu-TrustJah

Copy link
Copy Markdown
Contributor

Description

Resolves #235 by ensuring the VWAP pricing route respects and enforces network scoping throughout the request cycle.

Summary of Changes

  • Route Threading: Updated src/routes/price.ts to extract network (req.network ?? activeNetwork), pass it to computeVWAP, and echo it in the response payload.
  • SQL Query Conjunction: Confirmed src/aggregator/vwap.ts applies a strict WHERE network = $1 AND source = $2 logical conjunction to leverage the leading (network, pairKey, timestamp) index on price_points.
  • TDD Test Coverage: Added Vitest tests in src/__tests__/vwapRoute.test.ts verifying cross-network isolation and default network fallback.
  • OpenAPI Specs: Updated openapi.yaml and synchronized openapi.json to keep API schema validation passing.

Verification

  • Ran full test suite (1,235 passing, 1 skipped).
  • Verified tests/openapi.test.ts passes cleanly against regenerated openapi.json.

@Miracle656
Miracle656 merged commit f15e3b2 into Divinity-Labs:main Oct 23, 2026
@Miracle656

Copy link
Copy Markdown
Collaborator

Merged to main as f15e3b2.

This is a better catch than the title suggests. computeTWAP already accepted a network and filtered on it (AND network = $2) — the routes simply never passed one, so the figures were computed for whatever the default happened to be rather than the network the caller asked for. That's the same class of bug #584 found in /candles, /basket and /benchmark earlier today: a price that silently mixes or mistakes chains, which looks entirely plausible in a response.

Resolving req.network ?? query.network ?? activeNetwork and then echoing the network back in the response is the right shape — a caller can see which chain answered instead of assuming.

Conflicts, all additive against work that landed today: #542 added decimal-format handling in the same query schema and handler blocks you're adding network to. I unioned them, so the schema now carries decimals, decimalFormat and network, and the handler does both.

Two things I regenerated rather than merged by hand, worth knowing for next time:

I also took main's package-lock.json: this PR changes no dependency, and main's copy is the one carrying the @rolldown Linux binding that CI needs.

Lens: 116 files, 1,426 tests passing, typecheck clean.

Miracle656 added a commit that referenced this pull request Oct 23, 2026
listPairs returned bare strings, so a client wanting the assets, the network
or a price had to parse the pair key and then ask again. `pairs` returns the
structured form, and listPairs stays — deprecated with a reason rather than
removed, which is the right call for a published API.

The resolver is good: one query per request using a LATERAL join to pull the
latest price for each active pair, rather than a query per pair, and scoped by
`network = $1` so it cannot blend chains — the bug #584 and #605 both had to
fix elsewhere today.

Conflicts, resolved by keeping main's richer side and adding this PR's:

- imports: kept main's (NetworkName, the oracle adapter and comparison) and
  added getActivePairs
- the schema declaration: kept main's `export const schema`, which the SDL
  artifact generator depends on, and added the Asset and Pair types
- the Query block: kept main's documented getPriceHistory with its from/to
  range and the oracle query, and added `pairs` plus the @deprecated marker on
  listPairs

Regenerated schema.graphql afterwards. src/__tests__/graphqlSchemaDrift.test.ts
compares the committed SDL against the code-defined schema, so adding types
without regenerating fails it — the same generated-artifact guard as
openapi.json and the TypeScript client.

Lens: 118 files, 1,432 tests passing, typecheck clean.

Claude-Session: https://claude.ai/code/session_01USgemLt4Rnz4SGB1Srf3GB
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.

VWAP's route drops the network the aggregator supports

2 participants