Skip to content

feat(contracts): implement NFT certificate staking and rewards system… - #205

Closed
Sendi0011 wants to merge 2 commits into
StellarDevHub:mainfrom
Sendi0011:feat/nft-certificate-staking-rewards
Closed

feat(contracts): implement NFT certificate staking and rewards system…#205
Sendi0011 wants to merge 2 commits into
StellarDevHub:mainfrom
Sendi0011:feat/nft-certificate-staking-rewards

Conversation

@Sendi0011

Copy link
Copy Markdown
Contributor

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-stake
  • unstake_certificates — enforces 7-day minimum stake duration, initiates 3-day cooldown
  • complete_unstake — finalizes unstake after cooldown expires
  • emergency_unstake — immediate exit with 20% penalty on pending rewards
  • claim_rewards — claims all accumulated + pending rewards, resets accumulator
  • calculate_pending_rewards — view-only pending reward preview
  • get_voting_power — returns staked weight for governance integration
  • get_staker_tier — Bronze / Silver / Gold / Platinum based on total weight

Certificate tiers & multipliers:

Tier Multiplier
Basic 1x
Intermediate 1.5x
Advanced 2x
Expert 3x

Reward formula: total_weight × duration_in_ledgers × rate / PRECISION

Uses 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 ✅).

… (#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
@drips-wave

drips-wave Bot commented Apr 23, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@ayomideadeniran

Copy link
Copy Markdown
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.

@Sendi0011

Copy link
Copy Markdown
Contributor Author

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

Gm @ayomideadeniran i have fix the failing issues, and updated the pr. you can do well to review

@ayomideadeniran

Copy link
Copy Markdown
Contributor

Pr under review, i will get back to you if i find any wrong implementations.

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.

2 participants