feat(contracts): implement NFT certificate staking and rewards system… - #205
Closed
Sendi0011 wants to merge 2 commits into
Closed
feat(contracts): implement NFT certificate staking and rewards system…#205Sendi0011 wants to merge 2 commits into
Sendi0011 wants to merge 2 commits into
Conversation
… (#203) - Add CertificateTier enum (Basic/Intermediate/Advanced/Expert) with tier multipliers (1x/1.5x/2x/3x) - Add StakerTier enum (Bronze/Silver/Gold/Platinum) based on total staked weight thresholds - Add StakePosition and CertificateWeight structs matching issue spec - Add UnstakeRequest struct for cooldown tracking - Implement stake_certificates: multi-cert staking, weight computation, reward snapshot on re-stake - Implement unstake_certificates: min duration enforcement, cooldown initiation, partial unstake support - Implement complete_unstake: finalizes unstake after cooldown period - Implement emergency_unstake: immediate exit with 20% penalty on pending rewards - Implement claim_rewards: accumulator reset, ledger-based reward calculation - Implement calculate_pending_rewards: view function for pending reward preview - Implement get_voting_power: returns total staked weight for governance integration - Implement get_staker_tier: tier classification from staked weight - Add admin functions: init, set_reward_rate, set_certificate_weight - Use ledger sequence numbers for time (Soroban-native, no timestamp drift) - MIN_STAKE_DURATION: 120,960 ledgers (~7 days), UNSTAKE_COOLDOWN: 51,840 ledgers (~3 days) - Reward formula: total_weight * duration * rate / PRECISION - Global staked weight tracking for proportional reward distribution - Comprehensive unit tests: 18 test cases covering all staking scenarios Closes #203
|
@Sendi0011 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! 🚀 |
Contributor
|
@Sendi0011 Hi, all checks must pass before I can merge the PR. Please review the failing checks, fix the issues, and update the PR once everything is passing. |
Contributor
Author
Gm @ayomideadeniran i have fix the failing issues, and updated the pr. you can do well to review |
Contributor
|
Pr under review, i will get back to you if i find any wrong implementations. |
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.
feat(contracts): Implement NFT Certificate Staking and Rewards System
Closes #203
Summary
Implements a full NFT certificate staking system on Soroban where students can stake their certificates to earn rewards, gain governance voting power, and unlock tier-based benefits.
What's changed
contracts/src/staking.rs— complete rewrite from the old RS-Token voting staker to the NFT certificate staking system specified in #203.Key features implemented:
stake_certificates— stake multiple certs in one tx, computes weighted rewards on re-stakeunstake_certificates— enforces 7-day minimum stake duration, initiates 3-day cooldowncomplete_unstake— finalizes unstake after cooldown expiresemergency_unstake— immediate exit with 20% penalty on pending rewardsclaim_rewards— claims all accumulated + pending rewards, resets accumulatorcalculate_pending_rewards— view-only pending reward previewget_voting_power— returns staked weight for governance integrationget_staker_tier— Bronze / Silver / Gold / Platinum based on total weightCertificate tiers & multipliers:
Reward formula:
total_weight × duration_in_ledgers × rate / PRECISIONUses ledger sequence numbers (not timestamps) for all time tracking — Soroban-native and drift-free.
Tests: 18 unit tests covering staking, unstaking, cooldown enforcement, emergency exit, reward calculation, tier classification, voting power, and global weight tracking. Build verified clean (
cargo build✅).