Skip to content

feat: add price alert webhook registration for creator key price thresholds#427

Open
ogazboiz wants to merge 1 commit into
accesslayerorg:mainfrom
playground-ogazboiz:feat/price-alert-webhooks
Open

feat: add price alert webhook registration for creator key price thresholds#427
ogazboiz wants to merge 1 commit into
accesslayerorg:mainfrom
playground-ogazboiz:feat/price-alert-webhooks

Conversation

@ogazboiz

Copy link
Copy Markdown

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 via src/utils/prisma.utils.ts, and the same delivery/retry/backoff approach driven by WEBHOOK_RETRY_MAX_ATTEMPTS / WEBHOOK_RETRY_BASE_DELAY_MS.

Changes

  • POST /api/v1/alerts registers an alert { creator_id, wallet_address, target_price, direction, callback_url } (directionabove | below) and returns a unique alert ID.
  • DELETE /api/v1/alerts/:id cancels a pending alert before it fires.
  • Price-cross evaluation is wired into the trade-event processing path. A new processTradeEvent orchestrator (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.
    • above fires when the new price rises to/past the target; below fires when it drops to/past the target. Opposite movement does not fire.
  • Trigger payload: { creator_id, triggered_price, target_price, direction, timestamp }.
  • Successful delivery deletes the alert (one-shot). Failed delivery is retried with exponential backoff up to the configured max attempts, after which the alert is marked FAILED.
  • New Alert Prisma 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).
  • Integration tests cover: above trigger, below trigger, cancellation, and failed-delivery retry (Prisma + fetch mocked, following the suite's existing mocking approach so no live DB is required).
  • Pre-existing DB-dependent suites (and one unrelated baseline async-logging test) fail locally only because no Postgres is available; they are unchanged by this PR.

Closes #423

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
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.

Add price alert webhook registration for creator key price thresholds

1 participant