Skip to content

feat: add anomaly threshold checks for scoring (#45)#60

Open
Escelit wants to merge 1 commit into
Kalebtron1:mainfrom
Escelit:feat/scoring-anomaly-alerts
Open

feat: add anomaly threshold checks for scoring (#45)#60
Escelit wants to merge 1 commit into
Kalebtron1:mainfrom
Escelit:feat/scoring-anomaly-alerts

Conversation

@Escelit
Copy link
Copy Markdown

@Escelit Escelit commented May 30, 2026

Closes #45

What this does

Adds a lightweight anomaly signal to the scoring pipeline. When a score
or retention ratio falls outside the expected normal range, the system
logs a server-side warning, blocks minting, and shows an alert banner
in the UI.

Normal behavior

  • Score range: 0–~1000 for real testnet wallets (Platino is the ceiling).
  • Retention ratio: 0–1 (on-chain balance ≤ total ever deposited).
  • No anomaly field in the response → no banner, minting proceeds normally.

Thresholds (api/calculate-score.js)

Constant Value Rationale
SCORE_ANOMALY_THRESHOLD 2000 2× above Platino; unreachable under normal use
RETENTION_ANOMALY_THRESHOLD 5 Balance > 5× deposited is implausible

Changes

  • api/calculate-score.js — checks both thresholds, emits console.warn,
    adds anomaly: true to the response JSON.
  • api/evaluate-and-mint.js — reads the flag; returns HTTP 422
    (status: "anomaly") and blocks minting when set.
  • src/context/AppContext.tsx — exposes scoreAnomaly / setScoreAnomaly
    globally.
  • src/components/CreditSection.tsx — reads data.anomaly from the
    polling response and renders an amber AlertCircle banner.

How to simulate the trigger

curl -X POST http://localhost:3000/api/calculate-score \
  -H 'Content-Type: application/json' \
  -d '{"address": "<any_testnet_wallet_with_balance>", "totalDeposited": 1}'

If the wallet's on-chain balance exceeds 5 XLM, retention > 5 and the
anomaly fires. Look for [ANOMALY] in the server log and "anomaly": true
in the JSON response.

Signal to watch after deploy

Monitor server logs for [ANOMALY]. A spike for a single wallet or across
many wallets in a short window is the operational signal to investigate.

Threshold review note

Both constants are at the top of api/calculate-score.js with inline
comments. Re-evaluate them in a future PR once a baseline of real score
distributions is available from production traffic.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

@Escelit is attempting to deploy a commit to the alankcr1-6443's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@Escelit 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

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.

Alertas de anomalias en scoring

1 participant