Skip to content

feat: add reputation system with staking mechanics - #103

Open
Primex-hub wants to merge 1 commit into
Exquisify:mainfrom
Primex-hub:feat/issue-102-reputation-staking
Open

feat: add reputation system with staking mechanics#103
Primex-hub wants to merge 1 commit into
Exquisify:mainfrom
Primex-hub:feat/issue-102-reputation-staking

Conversation

@Primex-hub

Copy link
Copy Markdown

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 contract

Staking:

  • stake_tokens(user, amount) — lock tokens to participate; requires amount > 0
  • unstake_tokens(user, amount) — withdraw staked tokens (blocked if slashed)
  • get_staked_balance(user) — query staked balance

Ideas:

  • create_idea(author, title, content, tags) — post an idea (requires staked tokens, awards +10 reputation)
  • get_idea(idea_id) — retrieve idea data

Voting:

  • vote_idea(idea_id, voter, is_upvote) — upvote/downvote with reputation-weighted voting
    • 0-49 rep: weight 1
    • 50-99 rep: weight 2
    • 100+ rep: weight 3
  • Authors receive bonus reputation when receiving upvotes from high-rep users

Reputation & Leaderboard:

  • get_reputation(user) / get_user_data(user) — query user stats
  • refresh_leaderboard(users) — rebuild leaderboard snapshot (selection sort by rep descending)
  • get_leaderboard(limit) — return top-N users by reputation

Slashing:

  • slash_user(caller, target, reason) — admin-only; halves reputation, flags user to prevent unstaking
  • get_slash_count() — audit trail count

Admin:

  • set_admin(admin) — one-time admin bootstrap

Cargo.toml

  • Added [dev-dependencies] with soroban-sdk testutils feature

Tests (19 test cases)

  • Staking: accumulate, zero-panic, unstake, insufficient-balance panic
  • Ideas: create, create-without-stake panic, multiple ideas
  • Voting: basic upvote, high-rep weighted upvote, weight-2 upvote, downvote
  • Slashing: admin slash, non-admin panic, slashed-user-cannot-unstake
  • Leaderboard: ordering, limit
  • Full lifecycle integration test

Closes #102

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

Add Reputation System with Staking Mechanics

2 participants