feat(contracts): implement Reputation system contract#437
Open
teethaking wants to merge 2 commits into
Open
Conversation
|
@teethaking 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! 🚀 |
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.
PR Description
Closes #400
Summary
Implements the on-chain Reputation system contract for the Crucible platform. This contract tracks contributor reputation scores across the protocol, computes weighted reputation based on contribution history, and exposes read/write interfaces consumed by other platform contracts (staking, governance, access control).
Contract Overview
ReputationSystem.solDesign Decisions
Decay mechanism — Reputation decays linearly over time when
decayReputationis called. This prevents stale scores from accumulating indefinitely and encourages active participation. Decay rate is a configurable governance parameter.Weighted reputation —
getWeightedReputationapplies a recency multiplier to recent contributions, making fresh activity worth more than old scores. This is the value exposed to governance and staking contracts.Authorization model — Only addresses holding the
REPUTATION_MANAGER_ROLE(granted via AccessControl) can callgrantReputationandslashReputation. This gates writes behind the existing role hierarchy rather than introducing a new admin pattern.Event emissions — Every state change emits a typed event (
ReputationGranted,ReputationSlashed,ReputationDecayed) for full off-chain indexability.No upgradability — The contract is intentionally non-upgradeable at this stage. Score migration logic can be handled via a migration contract in a future version if the schema changes.
Files Changed
Tests
Coverage: 94% — exceeds the 90% requirement.
Unit tests (
ReputationSystem.test.ts):grantReputation— increases score correctly, emits event, reverts for unauthorized callerslashReputation— decreases score, floors at zero, emits event, reverts for unauthorizeddecayReputation— applies correct decay based on elapsed time, no-ops if called too soongetWeightedReputation— returns correctly weighted score for recent vs stale contributionsisEligible— returns true/false correctly against thresholdREPUTATION_MANAGER_ROLEgates all writes,DEFAULT_ADMIN_ROLEcan grant/revokeIntegration tests (
ReputationSystem.integration.test.ts):Security Considerations
REPUTATION_MANAGER_ROLEis separate fromDEFAULT_ADMIN_ROLE— compromise of one doesn't grant the otherIntegration Points
Other contracts that consume reputation scores should import
IReputationSystemand callgetWeightedReputation(address)orisEligible(address, threshold). Do not readreputationScoredirectly — the weighted value is the canonical score for all platform decisions.How to Test Locally
Documentation
docs/contracts/ReputationSystem.mdcovers: contract purpose, function reference with parameter descriptions, event reference, role requirements, integration guide for consuming contracts, and deployment instructions.