feat: design backend risk scoring model interfaces#61
Closed
spartan124 wants to merge 7 commits intoCreditra:mainfrom
Closed
feat: design backend risk scoring model interfaces#61spartan124 wants to merge 7 commits intoCreditra:mainfrom
spartan124 wants to merge 7 commits intoCreditra:mainfrom
Conversation
Contributor
|
please resolve the conflicts |
Contributor
Author
|
resolved |
Contributor
|
@spartan124 Can you resolve the conflicts? |
Contributor
Author
|
All conflicts resolved. Other merges messed with the package.json, package-lock.json and other critical files in the code base. You should avoid this by resolving merge conflicts yourself, as a contributor might not fully understand the implications of picking one implementation over another and some just accept both changes ending up breaking both syntax and code base. @greatest0fallt1me Merge as soon as possible, before other PRs gets merged. |
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
Closes #13
Designs and stubs the backend risk scoring model — defining all TypeScript types/interfaces for inputs, outputs, and weights; implementing a documented placeholder scoring function; and wiring it into the risk service. All acceptance criteria from issue #13 are met.
Changes
New Files
src/risk/types.tsRiskInputs,RiskOutput,RiskTier,RiskWeightsinterfaces with full JSDoc on every fieldsrc/risk/riskModel.tsclamp,normalise,validateWeights,classifyRiskTierhelpers, and fully documentedscoreWallet()stubsrc/risk/riskService.tsevaluateRisk()wrapper — intentionally async so the route layer requires zero changes when a real engine replaces the stubsrc/risk/index.tssrc/risk/__tests__/riskModel.test.tssrc/risk/__tests__/riskService.test.tsevaluateRisk()including concurrency and rejection casesvitest.config.tssrc/risk/**Modified Files
src/routes/risk.tsevaluateRisk(), proper 400/500 error handlingpackage.jsonvitest,@vitest/coverage-v8dev dependencies andtest,test:watch,test:coveragescriptsUnchanged Files
src/index.ts✅src/routes/credit.ts✅Risk Model Design
Inputs (
RiskInputs)walletAddressstringtransactionCountnumberwalletAgeDaysnumberdefiActivityVolumeUsdnumbercurrentBalanceUsdnumberhasHighRiskInteractionbooleanOutputs (
RiskOutput)walletAddressstringriskScorenumbercreditLimitUsdnumberinterestRateBpsnumberriskTierRiskTierLOW/MEDIUM/HIGH/BLOCKEDisStubbooleantrueuntil real engine is connectedScoring Algorithm (Documented, Pending Real Engine)
RiskWeights(validated to sum to 1.0 at runtime)+40 bpsflat penalty ifhasHighRiskInteraction === trueRisk Tiers & Credit Terms
Test Results
Coverage (
src/risk/**— executable files only)API
POST /api/risk/evaluateRequest body:
{ "walletAddress": "0xabc...123", "transactionCount": 250, "walletAgeDays": 365, "defiActivityVolumeUsd": 12000, "currentBalanceUsd": 8000, "hasHighRiskInteraction": false }200 Response:
{ "walletAddress": "0xabc...123", "riskScore": 50, "creditLimitUsd": 300000, "interestRateBps": 1500, "riskTier": "MEDIUM", "isStub": true }400 Response (missing fields):
{ "error": "Missing required fields", "fields": ["transactionCount", "walletAgeDays"] }400 Response (invalid types):
{ "error": "Fields must be non-negative finite numbers", "fields": ["currentBalanceUsd"] }Notes for Reviewers
isStub: trueis present on every response — consumers must check this flag and treat output as non-binding until a real engine is wired inevaluateRisk()is intentionallyasyncfor forward compatibility — swapping in a real HTTP/oracle engine requires changing onlyriskService.tsvalidateWeights()— misconfiguration throws immediately rather than silently producing wrong scores