Skip to content

feat: implement staking module with minting and burning functionality for tokens#449

Merged
Devsol-01 merged 1 commit intoDevsol-01:mainfrom
Shredder401k:feat/contract
Mar 27, 2026
Merged

feat: implement staking module with minting and burning functionality for tokens#449
Devsol-01 merged 1 commit intoDevsol-01:mainfrom
Shredder401k:feat/contract

Conversation

@Shredder401k
Copy link
Copy Markdown
Contributor

Token Economics Implementation

Overview

This PR implements comprehensive token economics for the Nestera protocol, including minting, burning, rewards distribution, and staking mechanisms.

Changes

#376 - Token Minting Logic

  • Added mint_tokens(caller, to, amount) function for controlled token minting
  • Restricted minting to governance and admin roles only
  • Updates total supply on mint
  • Emits TokenMinted event with recipient, amount, and new total supply
  • Validates amount is positive
  • Uses checked arithmetic for overflow protection

#377 - Token Burning Mechanism

  • Added burn(from, amount) function for deflationary mechanics
  • Reduces total supply on burn
  • Emits TokenBurned event with sender, amount, and new total supply
  • Validates amount is positive
  • Uses checked arithmetic for underflow protection

#441 - Rewards Distribution in Token

  • Integrated existing rewards system with token minting
  • claim_rewards() function transfers native tokens to users
  • Tracks claimed vs unclaimed rewards in UserRewards struct
  • Emits RewardsClaimed event on successful claim
  • Prevents double-claiming by zeroing unclaimed_tokens before transfer
  • Uses checked arithmetic for all calculations

#442 - Staking Mechanism

  • Created new staking module with full staking functionality
  • stake(user, amount) - stakes tokens for a user
  • unstake(user, amount) - unstakes tokens for a user
  • claim_staking_rewards(user) - claims accumulated staking rewards
  • Stake struct tracks:
    • amount - staked tokens
    • start_time - when stake was created
    • last_update_time - last reward calculation
    • reward_per_share - accumulated rewards
  • StakingConfig struct for configuration:
    • min_stake_amount - minimum stake required
    • max_stake_amount - maximum stake per user
    • reward_rate_bps - APY in basis points
    • enabled - whether staking is active
    • lock_period_seconds - optional lock period
  • Emits events: StakeCreated, StakeWithdrawn, StakingRewardsClaimed
  • Supports optional lock period for staked tokens
  • Calculates pending rewards based on time and stake amount

Files Modified

  • contracts/src/token.rs - Added mint and burn functions with events
  • contracts/src/lib.rs - Added contract functions for mint, burn, and staking
  • contracts/src/staking/mod.rs - New staking module
  • contracts/src/staking/storage_types.rs - Staking data structures
  • contracts/src/staking/storage.rs - Staking logic implementation
  • contracts/src/staking/events.rs - Staking event helpers
  • contracts/src/token_tests.rs - Tests for minting and burning
  • contracts/src/staking_tests.rs - Tests for staking mechanism

Tests

All new functionality includes comprehensive tests:

  • Token minting tests (admin, unauthorized, invalid amounts)
  • Token burning tests (user, invalid amounts, insufficient supply)
  • Staking tests (stake, unstake, rewards, lock periods, edge cases)

Acceptance Criteria Met

#376 - Token Minting Logic

  • ✅ Only authorized minting allowed (governance/admin)
  • ✅ Supply updated correctly
  • ✅ Tests validate restrictions

#377 - Token Burning Mechanism

  • ✅ Burning reduces supply
  • ✅ Cannot burn more than balance
  • ✅ Tests pass

#441 - Rewards Distribution in Token

  • ✅ Rewards claim works correctly
  • ✅ No double claiming
  • ✅ Accurate accounting

#442 - Staking Mechanism

  • ✅ Stake/unstake works correctly
  • ✅ Balances updated properly
  • ✅ Tests validate flows

Closes

Closes #376
Closes #377
Closes #441
Closes #442

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 27, 2026

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

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nestera Ready Ready Preview, Comment Mar 27, 2026 3:01pm

@Devsol-01 Devsol-01 merged commit c7ce1c7 into Devsol-01:main Mar 27, 2026
2 of 3 checks passed
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.

[Contract] Staking Mechanism [Contract] Rewards Distribution in Token [contract]- Token Burning Mechanism [contract] - Token Minting Logic

2 participants