Earn While Hodling
RealmAi's 'Earn While Hodling' Staking Program: Technical Documentation
1. Introduction
The 'Earn While Hodling' staking program is a key feature of the RealmAi ecosystem, designed to incentivize long-term holding of $RAi tokens while contributing to the network's security and decentralization. This document outlines the technical specifications and mechanisms of the staking program.
2. Program Overview
The 'Earn While Hodling' program allows $RAi token holders to lock their tokens in a smart contract for a specified period, during which they earn additional $RAi tokens as rewards. This mechanism encourages token retention, reduces circulating supply, and provides a steady income stream for participants.
3. Smart Contract Architecture
3.1 Core Contracts
StakingPool.sol
: Main contract handling stake deposits, withdrawals, and reward distributions.RewardCalculator.sol
: Calculates rewards based on staking duration and amount.TokenVault.sol
: Securely stores staked tokens and manages reward token supply.
3.2 Auxiliary Contracts
Governance.sol
: Handles parameter updates and program governance.EmergencyProtocol.sol
: Implements safety measures for unexpected scenarios.
4. Staking Mechanism
4.1 Staking Process
Users approve the
StakingPool
contract to spend their $RAi tokens.Users call the
stake(uint256 amount, uint256 duration)
function.Tokens are transferred to the
TokenVault
.A staking position is created and recorded in the user's account.
4.2 Reward Calculation
Rewards are calculated using the following formula:
Where:
stakedAmount
is the number of tokens stakedstakingDuration
is the lock-up period in daysrewardRate
is the annual percentage yield (APY)
5. Reward Distribution
5.1 Reward Accrual
Rewards accrue in real-time but are not minted until claimed. This approach saves gas and allows for more flexible reward adjustments.
5.2 Claiming Process
Users call the
claimRewards()
function.The contract calculates the total rewards accrued.
New $RAi tokens are minted and transferred to the user.
The reward balance is reset to zero.
6. Unstaking Process
6.1 Regular Unstaking
After the lock-up period, users call
unstake(uint256 positionId)
.The contract verifies the lock-up period has ended.
Staked tokens and any unclaimed rewards are transferred to the user.
6.2 Early Unstaking
Early unstaking is discouraged but allowed with penalties:
Users call
earlyUnstake(uint256 positionId)
.A penalty is calculated based on the remaining lock-up time.
The penalty is deducted from the staked amount.
Remaining tokens are returned, but all accrued rewards are forfeited.
7. Security Measures
7.1 Reentrancy Protection
All state-changing functions implement the "checks-effects-interactions" pattern and use OpenZeppelin's ReentrancyGuard
.
7.2 Access Control
Contract functions use OpenZeppelin's AccessControl
to manage permissions.
7.3 Emergency Pause
The EmergencyProtocol
contract can pause staking, unstaking, and reward claiming in case of detected vulnerabilities.
8. Upgradability
The staking program uses the OpenZeppelin UUPS (Universal Upgradeable Proxy Standard) pattern, allowing for future improvements while maintaining contract addresses.
9. Gas Optimization
Batch processing for rewards calculation and distribution.
Use of mappings for efficient data storage and retrieval.
Minimize on-chain storage by using events for historical data.
10. Testing and Auditing
Comprehensive unit tests covering all functions and edge cases.
Integration tests simulating various staking scenarios.
External audit to be conducted by a reputable blockchain security firm (details TBA).
11. Future Enhancements
Implementation of a tiered staking system with boosted rewards for longer lock-up periods.
Integration with RealmAi's governance system, allowing stakers to participate in protocol decisions.
Cross-chain staking capabilities to enhance interoperability with other blockchain networks.
12. Conclusion
The 'Earn While Hodling' staking program is designed to provide a secure, efficient, and rewarding experience for $RAi token holders. By incentivizing long-term holding and active participation in the network, this program aims to contribute to the overall stability and growth of the RealmAi ecosystem.
Last updated