Skip to content
Open
10 changes: 10 additions & 0 deletions BRANCH-[SC-REP-053]-Reputation-Recovery.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Branch: [SC-REP-053] Reputation System Robustness Auditing - Step 53

Summary of changes:
- Added `last_activity` to `Profile` to track inactivity.
- Updated reputation update paths to set `last_activity` on changes (reviews, manual deltas, slashes, blacklist, metadata updates).
- Implemented `recover_score` API to recover scores after inactivity using safe fixed-point math.
- Added `compute_recovery_towards_default` helper.
- Added unit tests `test_recover_after_inactivity` and `test_recover_requires_authorized_contract`.

Note: Please create a git branch with this exact title and commit these changes locally.
5 changes: 5 additions & 0 deletions apps/web/lib/reputation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ReputationMetrics {
reviews: number;
starRating: number;
averageStars: number;
badgeLevel?: number;
}

export interface ReputationViewMetrics {
Expand All @@ -42,6 +43,7 @@ interface ContractReputationScore {
total_jobs: number | string | bigint;
total_points: number | string | bigint;
reviews: number | string | bigint;
badge_level?: number | string | bigint;
}

interface ContractReputationView {
Expand All @@ -66,6 +68,7 @@ function fallbackMetrics(): ReputationMetrics {
reviews: 0,
starRating: toStarRating(scoreBps),
averageStars: 2.5,
badgeLevel: 0,
};
}

Expand All @@ -82,6 +85,7 @@ function metricsFromScore(score: ContractReputationScore): ReputationMetrics {
const totalPoints = normalizeNumber(score.total_points);
const reviews = normalizeNumber(score.reviews);
const averageStars = reviews > 0 ? totalPoints / reviews : toStarRating(scoreBps);
const badgeLevel = normalizeNumber(score.badge_level);

return {
scoreBps,
Expand All @@ -90,6 +94,7 @@ function metricsFromScore(score: ContractReputationScore): ReputationMetrics {
reviews,
starRating: toStarRating(scoreBps),
averageStars,
badgeLevel,
};
}

Expand Down
Loading
Loading