Technical Docs
Overview
Staking: Users stake $EDU tokens into the
StakingRewardPool.sol
contract, which manages both staking and reward distribution. This contract keeps track of all user balances, the total amount of $EDU staked, and distributes rewards accordingly.Reward Allocation: The admin configures a reward period using
StakingRewardPool.sol
. This period defines how many reward tokens will be distributed and over what timeframe.Earning Rewards: Users who have staked $EDU tokens start earning rewards based on the proportional amount of their stake relative to the total pool. The rewards are distributed over time at a constant rate.
Claiming Rewards: Users can claim their rewards at any point through
StakingRewardPool.sol
and can also withdraw their staked $EDU tokens at any time.
StakingRewardPool.sol
Purpose: This contract serves as both the staking mechanism and the reward distribution system. It inherits the core staking functionality while adding the reward logic on top. Users deposit $EDU tokens into this contract, which manages both their staked amounts and the distribution of reward tokens.
Key Functions:
stake(uint256 amount)
: Allows users to deposit a specified amount of $EDU tokens into the pool. The contract tracks each user's staked amount.withdraw(uint256 amount)
: Allows users to withdraw their staked $EDU tokens from the pool. The user can withdraw either partially or fully, depending on how much they've staked.balanceOf(address user)
: Keeps track of how many $EDU tokens each user has staked.totalSupply()
: Tracks the total amount of $EDU tokens staked across all users in the pool.notifyRewardAmount(uint256 reward)
: Called by an admin to set the total reward amount for a given reward period. This function informs the contract how many reward tokens will be distributed to stakers.earned(address account)
: This function calculates how many reward tokens a staker has earned based on the staked amount and the staking duration. The longer the tokens are staked, the more rewards the staker earns.getReward()
: Allows users to claim the rewards they’ve accrued so far. After claiming, the reward balance for the user is reset.exit()
: Allows users to withdraw their staked $EDU tokens and claim any accrued rewards in one step, ending their staking session.
Reward Distribution Mechanism:
The StakingRewardPool.sol
contract uses a constant-rate distribution method, where reward tokens are distributed evenly over time during the reward period. Stakers receive rewards proportionally to the amount they’ve staked and the time their tokens have remained staked. For every second the reward period is active, a certain number of reward tokens are distributed among all stakers. This ensures a fair and transparent reward distribution.
Interaction:
Since StakingRewardPool.sol
inherits the staking logic from StakingPool.sol
, users interact directly with StakingRewardPool.sol
for both staking and reward management. The contract keeps track of staked balances and distributes rewards proportionally based on the user’s share in the total pool.
The combination of staking and reward logic within a single contract allows for flexibility in managing staking functionality while also providing dynamic reward distribution, all within one unified interface.
Last updated