Skip to content

Implement On-chain Agent Reputation System#230

Merged
GauravKarakoti merged 3 commits intoGauravKarakoti:mainfrom
Aditya8369:223
Feb 18, 2026
Merged

Implement On-chain Agent Reputation System#230
GauravKarakoti merged 3 commits intoGauravKarakoti:mainfrom
Aditya8369:223

Conversation

@Aditya8369
Copy link
Contributor

✅ Implementation Summary

1. Reputation Calculation Engine

Added comprehensive calculation functions in database.ts:

  • calculateReputationMetrics() - Computes metrics by user ID
  • calculateReputationMetricsByWallet() - Computes metrics by wallet address

Metrics Calculated:

  • Total swaps, successful swaps, failed swaps, pending swaps
  • Success rate (percentage)
  • Trust Score (0-100) - Weighted formula:
    • Success Rate: 60%
    • Volume: 20% (normalized to $10k baseline)
    • Swap Count: 10% (normalized to 50 swaps baseline)
    • Recency: 10% (active/moderate/inactive)
  • Average swap value & total volume
  • Last swap date & activity level (active/moderate/inactive)

2. API Endpoint

Created reputation.ts:

  • GET /api/reputation?userId=... or ?walletAddress=...
  • Returns trust score and all reputation metrics
  • Cached for 5 minutes to reduce database load

3. Frontend Hook

Created useReputation.ts:

  • React hook for fetching reputation data
  • Supports auto-refetch with configurable intervals
  • Error handling and loading states
  • Success/error callbacks

4. Beautiful UI Component

Created ReputationCard.tsx:

  • Full mode: Detailed card with all metrics (for profile page)
  • Compact mode: Essential info only (for sidebar)
  • Color-coded trust levels:
    • 🟢 Excellent (80+): Green
    • 🔵 Good (60-79): Cyan
    • 🟡 Fair (40-59): Yellow
    • 🟠 Building (1-39): Orange
  • Shows success rate, swap count, total volume, and activity status
  • "Top Tier" badge for exceptional reputation

5. Integration Points

  • Profile Page: Full reputation card with detailed metrics (right column)
  • Terminal/Dashboard: Compact reputation card in sidebar for quick reference

6. Documentation

Created comprehensive REPUTATION_SYSTEM.md with:

  • System architecture and data flow
  • API reference and usage examples
  • Trust score interpretation guide
  • Future enhancement ideas
  • Testing instructions

🎯 Key Features

Trust Score Algorithm: Balances success rate, volume, activity count, and recency
📊 Visual Indicators: Color-coded cards and progress bars for easy interpretation
Performance: API caching and optimized database queries
📱 Responsive Design: Works on all screen sizes with compact and full modes
🔒 Type-Safe: Full TypeScript implementation with proper interfaces

closes #223

@vercel
Copy link
Contributor

vercel bot commented Feb 17, 2026

@Aditya8369 is attempting to deploy a commit to the Gaurav's projects Team on Vercel.

A member of the Team first needs to authorize it.

@netlify
Copy link

netlify bot commented Feb 17, 2026

Deploy Preview for swapsmithminiapp canceled.

Name Link
🔨 Latest commit 758229d
🔍 Latest deploy log https://app.netlify.com/projects/swapsmithminiapp/deploys/6995c15d5830360008b42052

@vercel
Copy link
Contributor

vercel bot commented Feb 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
swap-smith Error Error Feb 18, 2026 1:40pm

@GauravKarakoti
Copy link
Owner

Let me try

@GauravKarakoti GauravKarakoti merged commit 1215607 into GauravKarakoti:main Feb 18, 2026
4 of 7 checks passed
@GauravKarakoti
Copy link
Owner

Build gave error

Type error: No overload matches this call.
  Overload 1 of 4, '(value: string | number | Date): Date', gave the following error.
    Argument of type 'Date | null' is not assignable to parameter of type 'string | number | Date'.
      Type 'null' is not assignable to type 'string | number | Date'.
  Overload 2 of 4, '(value: string | number): Date', gave the following error.
    Argument of type 'Date | null' is not assignable to parameter of type 'string | number'.
      Type 'null' is not assignable to type 'string | number'.
  827 |     // Get last swap date
  828 |     const lastSwap = userSwaps.reduce((latest, current) => {
> 829 |       const currentDate = new Date(current.createdAt);
      |                                    ^
  830 |       const latestDate = new Date(latest.createdAt);
  831 |       return currentDate > latestDate ? current : latest;
  832 |     });

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 On-chain Agent Reputation System

2 participants