Skip to content

fix: make webhooks and price trackers network-aware (#188) - #205

Merged
Miracle656 merged 1 commit into
Miracle656:mainfrom
Ingenious-02:feat/issue-188-network-aware-webhooks-price-trackers
Sep 30, 2026
Merged

Miracle656 merged 1 commit into
Miracle656:mainfrom
Ingenious-02:feat/issue-188-network-aware-webhooks-price-trackers

Conversation

@Ingenious-02

Copy link
Copy Markdown
Contributor

Summary

Closes #188

Fixes the dual-network seam where price trackers and webhooks were network-blind:

  1. Network-scoped lastPrice maps: Keyed module-level lastPrice maps in src/ingesters/sdex.ts, src/ingesters/amm.ts, src/ingesters/soroswap.ts, and src/ingest/venues/aquarius.ts by (network, pairKey) rather than pairKey alone. A tick on testnet now never pollutes or supplies the "previous price" for a mainnet threshold crossing (and vice versa).
  2. Network-aware webhook dispatching: Updated dispatchPriceUpdate in src/webhookDispatcher.ts to accept network and filter webhooks specifically by the network that emitted the price event, rather than filtering by the process's activeNetwork.
  3. Network-aware ingester dispatch: All ingesters (sdex, amm snapshot + trades, soroswap, and aquarius) now forward their active network into dispatchPriceUpdate.
  4. Network-aware webhook subscription: POST /webhooks now supports explicit network selection from req.body.network (validated against allowed networks), falling back to req.network or activeNetwork.
  5. Fixed AMM pool snapshot network tag: In src/ingesters/amm.ts, snapshotPool was writing network: activeNetwork to prisma.poolSnapshot.create, now properly tags with the network parameter.

Acceptance Criteria Verification

  • A tick on one network never supplies the previous price for the other: Verified in src/__tests__/dualNetworkAlerts.test.ts.
  • A webhook fires for the network whose event triggered it: Verified in src/__tests__/dualNetworkAlerts.test.ts and src/__tests__/webhooks.test.ts.
  • A test drives both networks through the same pair and asserts the alerts do not cross: Tested across SDEX, AMM, Soroswap, and Aquarius with interleaved trades on the same pair.
  • No remaining module-level price state is keyed by pairKey alone: All in-memory lastPrice state is keyed by ${network}:${pairKey}.

Test Verification

  • All 48 test files (411 passing tests) pass cleanly.
  • npx tsc --noEmit passes with 0 errors.

@drips-wave

drips-wave Bot commented Sep 30, 2026

Copy link
Copy Markdown

@Ingenious-02 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Miracle656
Miracle656 merged commit 3c43cfe into Miracle656:main Sep 30, 2026
1 check passed
Miracle656 added a commit that referenced this pull request Sep 30, 2026
Every function in src/aggregator/vwap.ts now takes a required network and
filters price_points and pool_snapshots on it, getAMMPrice filters both
legs of its pool lookup, /price/:assetA/:assetB passes req.network through
to the aggregator, and the aggregate refresh worker runs once per enabled
network instead of pinning itself to whichever network the instance
happens to be indexing.

Merged locally: src/__tests__/price.test.ts conflicted only because #184
and 1c7e200 appended test blocks to the same tail; resolved as a union.
The README paragraph was corrected on merge — #195, #202 and #205 landed
network scoping for /screener, /pools, /depth and /prices/history after
this branch was written, so the list of still-unscoped endpoints was
stale.

Claude-Session: https://claude.ai/code/session_01USgemLt4Rnz4SGB1Srf3GB
Miracle656 added a commit that referenced this pull request Sep 30, 2026
#193 replaced db.getIndexerCursor with getIndexerState, which returns
{cursor, ledger} so an ingester can fall back to the last stored ledger
when a Horizon trade id will not parse as a TOID. It branched before
tests/ingestMetrics.test.ts (#203) and dualNetworkAlerts.test.ts (#205)
landed, so those two files still mocked the old name. The merge is clean
and tsc passes, but at runtime getIndexerState is undefined and 11 tests
fail.

Both suites use synthetic paging tokens that carry no TOID, so they now
supply a stored ledger and exercise the documented fallback path.

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.

Webhooks and the price trackers are network-blind

2 participants