Skip to content

feat(contracts/credit-score): implement credit scoring Soroban contract (#360) - #366

Draft
s6pa1rta3n-lab wants to merge 1 commit into
nexoraorg:mainfrom
s6pa1rta3n-lab:fix-issue-360
Draft

s6pa1rta3n-lab wants to merge 1 commit into
nexoraorg:mainfrom
s6pa1rta3n-lab:fix-issue-360

Conversation

@s6pa1rta3n-lab

Copy link
Copy Markdown

Summary

Resolves #360. Ground-up production implementation of the Credit Scoring Soroban contract (contracts/credit-score) aligning with the ModelResult specification from packages/chenai-mlflow and ml/README.md.

Key Changes

  • Contracts / Common Utils (contracts/common-utils):
    • Implemented reusable role-based access control and writer registry (roles.rs) providing Role, RiskLevel, RoleKey, and RoleRegistry.
    • Exported primitives for contract-wide access management and cross-contract risk evaluations.
  • Contracts / Credit Score (contracts/credit-score):
    • Implemented ScoreBand (Poor, Fair, Good, Excellent) derived from normalized scores 0..=1000.
    • Implemented ScoreRecord matching ModelResult with subject, score, band, model_version, evidence_hash, computed_at, and expires_at.
    • Implemented core administrative and scoring operations:
      • initialize(admin)
      • set_admin(admin, new_admin)
      • set_writer(admin, writer, authorized)
      • set_expiry_window(admin, ledger_count)
      • set_fraud_contract(admin, fraud_contract)
      • submit_score(caller, subject, score, model_version, evidence_hash)
      • get_score(subject)
      • get_score_history(subject, limit)
      • is_score_valid(subject)
      • validate_score(score)
    • Added bounded ring-buffer history tracking per subject (MAX_HISTORY_CAPACITY = 50).
    • Added cross-contract risk verification against companion fraud contract (RiskLevel::Critical rejection).
    • Configured state tiering with explicit TTL extension (SCORE_LIFETIME_THRESHOLD = 30 days, SCORE_BUMP_AMOUNT = 90 days).
    • Emitted score_submitted events on every evaluation.
    • Implemented comprehensive unit test suite in contracts/credit-score/src/test.rs covering happy path, auth rejection, expiry, double-init, admin rotation, history pagination, boundary scores, empty model versions, and cross-contract fraud calls (15/15 tests passing).
  • Documentation (docs/contracts/credit-score.md):
    • Added technical reference covering data types, storage keys, TTL strategy, function specifications, validity semantics, and integration code samples.

Verification

  • cargo test -p common-utils: 6 passed, 0 failed.
  • cargo test -p credit-score: 15 passed, 0 failed.
  • cargo clippy -p credit-score --all-targets -- -D warnings: passed with 0 warnings.
  • cargo clippy -p common-utils --all-targets -- -D warnings: passed with 0 warnings.
  • cargo build --package credit-score --release --target wasm32-unknown-unknown: compiled release wasm (credit_score.wasm, 21 KB).

Payout Routing

  • EVM (Base/Arbitrum/Polygon/ETH): 0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89
  • Stellar: GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC

@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown

@s6pa1rta3n-lab is attempting to deploy a commit to the Isaac Gellu's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

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

Implement the Credit Scoring Soroban contract (contracts/credit-score)

1 participant