feat: add reputation system with staking mechanics - #103
Open
Primex-hub wants to merge 1 commit into
Open
Conversation
Implement the full reputation/staking smart contract for the Hello-world idea-sharing platform: - stake_tokens: lock tokens to participate (minimum stake required for idea creation) - unstake_tokens: withdraw staked tokens (blocked if slashed) - create_idea: post an idea (requires staked tokens, awards +10 rep) - vote_idea: upvote/downvote with reputation-weighted voting (1/2/3 weight based on voter rep: 0-49/50-99/100+) - get_reputation / get_user_data: query user stats - refresh_leaderboard / get_leaderboard: top-N users by reputation - slash_user: admin action to halve reputation and flag user - set_admin: one-time admin bootstrap Includes comprehensive test suite covering staking, ideas, voting weights, slashing, leaderboard ordering, and full lifecycle. Closes Exquisify#102
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
Implements the full reputation system with staking mechanics for the Hello-world idea-sharing platform, as specified in Issue #102.
Changes
src/lib.rs— New Soroban smart contractStaking:
stake_tokens(user, amount)— lock tokens to participate; requires amount > 0unstake_tokens(user, amount)— withdraw staked tokens (blocked if slashed)get_staked_balance(user)— query staked balanceIdeas:
create_idea(author, title, content, tags)— post an idea (requires staked tokens, awards +10 reputation)get_idea(idea_id)— retrieve idea dataVoting:
vote_idea(idea_id, voter, is_upvote)— upvote/downvote with reputation-weighted votingReputation & Leaderboard:
get_reputation(user)/get_user_data(user)— query user statsrefresh_leaderboard(users)— rebuild leaderboard snapshot (selection sort by rep descending)get_leaderboard(limit)— return top-N users by reputationSlashing:
slash_user(caller, target, reason)— admin-only; halves reputation, flags user to prevent unstakingget_slash_count()— audit trail countAdmin:
set_admin(admin)— one-time admin bootstrapCargo.toml[dev-dependencies]withsoroban-sdktestutils featureTests (19 test cases)
Closes #102