feat: add price alert webhook registration for creator key price thresholds#427
Open
ogazboiz wants to merge 1 commit into
Open
feat: add price alert webhook registration for creator key price thresholds#427ogazboiz wants to merge 1 commit into
ogazboiz wants to merge 1 commit into
Conversation
Register one-shot price alerts that fire a callback when a creator key
price crosses a target threshold during indexer trade processing.
- POST /alerts registers an alert ({ creator_id, wallet_address,
target_price, direction, callback_url }) and returns a unique alert ID
- DELETE /alerts/:id cancels a pending alert before it fires
- Alerts are evaluated on the indexer trade-event path: an `above` alert
fires when the new price rises to/past the target, a `below` alert when
it drops to/past the target; opposite movement does not fire
- Successful delivery deletes the alert (one-shot); failed delivery is
retried with exponential backoff up to WEBHOOK_RETRY_MAX_ATTEMPTS, then
the alert is marked FAILED
- Adds an Alert Prisma model + migration; reuses the trade-webhook
delivery/retry conventions and is fanned out alongside webhook dispatch
via a single processTradeEvent entry point
Closes accesslayerorg#423
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.
Summary
Adds a price-alert system so fans can register a target price and a callback URL, and the server fires the webhook when a creator's key price crosses that threshold. Alerts are one-shot: they fire once when the threshold is crossed, then are removed.
This mirrors the conventions of the recently merged trade-webhook feature (
src/modules/webhooks/): zod validation, controller/router/service split, Prisma access viasrc/utils/prisma.utils.ts, and the same delivery/retry/backoff approach driven byWEBHOOK_RETRY_MAX_ATTEMPTS/WEBHOOK_RETRY_BASE_DELAY_MS.Changes
POST /api/v1/alertsregisters an alert{ creator_id, wallet_address, target_price, direction, callback_url }(direction∈above|below) and returns a unique alert ID.DELETE /api/v1/alerts/:idcancels a pending alert before it fires.processTradeEventorchestrator (src/utils/trade-event.utils.ts) fans a single trade event out to both webhook dispatch and alert evaluation, so alerts are not a parallel pipeline.abovefires when the new price rises to/past the target;belowfires when it drops to/past the target. Opposite movement does not fire.{ creator_id, triggered_price, target_price, direction, timestamp }.FAILED.AlertPrisma model (prisma/schema/alert.prisma) + migration (20260619000000_add_price_alerts).Test plan
pnpm build— passes.pnpm lint— passes.pnpm test -- src/modules/alerts— 17 tests pass (service unit tests + integration tests).fetchmocked, following the suite's existing mocking approach so no live DB is required).Closes #423