HexRewards White Paper

HexRewards - A Rewarding Experience for Hex Stakers

Introduction (NOTE: this white paper is a work in progress.)

HexRewards is an innovative smart contract designed to provide additional incentives for Hex stakers. By leveraging the power of the Hex staking system, HexRewards offers a unique opportunity for users to earn additional rewards based on their staking length of time. This white paper will explore the key features and benefits of the HexRewards contract, providing a comprehensive overview for potential users.

Registering - (Stake Claiming) - "New" Stakes Only

2.1 Stake ID Protection

To ensure the integrity of the rewarding system, HexRewards implements a stake ID protection mechanism. "New" stakes with a stakeID greater than the STAKEID_PROTECTION value (817340) are eligible for claiming rewards only after "Registering". This protection helps prevent abuse and ensures that the supply of the token doesn't grow infinitly. "Old" active stakes that have a stakeID lower than or equal to 817340 are eligible for claiming rewards without the need of "Registering" first.

2.2 Stake Tiers

HexRewards introduces a tiered system based on the amount of Hex staked for "New" stakes with a stake ID after the STAKEID_PROTECTION value (817340). There are nine tiers, each with a maximum number of stakes allowed (MAX_STAKES_PER_TIER = 369). The 9 tiers also have a Hex Stake Size requirement. Users can claim their stake by clicking on the "Register" button on the site which then calls the claimStake function in the contract, providing their stake index. The contract will determine the appropriate tier based on the Hex staked amount and register the stake accordingly consuming one of the available seats or slots of that tier. Once a tier has been consumed, where all the seats are "Registered" for that tier, then no more stakes can be "Registered" for that tier.

Reward Calculation

3.1 Reward Per Day

The contract defines a constant REWARD_PER_DAY = 0.00001 HXR, which represents the base reward amount earned per day of staking. The actual reward earned depends on the duration of the stake and whether it is a 5555-day stake or not.

3.2 5555-Day Stakes

For active stakes with a duration of 5555 days (MAX_STAKE_DAYS), the reward per day is multiplied by a factor of 10. If the 5555 day stake has finished all 5555 days, the user is to go to the Hex website and call the "Good Accounting" function to show the stake has completed its term. Then the normal reward per day for HXR is multiplied by a factor of 100 when "Claimed".

3.3 Stakes Fewer Than 5555 Days

For stakes with a duration less than 5555 days, the reward per day remains unchanged if the stake is still active. If the stake has finished all days for the stake, the user is to go to the Hex website and call the "Good Accounting" function to prove the stake has completed its term. Then the reward per day of HXR is multiplied by a factor of 10 when "Claimed".

Reward Claiming

4.1 Claiming Rewards

Users can claim their rewards by calling the claimReward function at any time while the stake is active. The contract checks if the stake is eligible for rewards and calculates the reward amount based on the consumed days and stake duration. The reward is then minted to the user's address, and the claimed amount is recorded in the claimed mapping. If the user ends the stake on the Hex website, or calls the "Emergency End Stake" function, the HXR contract will not be able to find that Hex stake anymore and will not be able to reward that Hex stake any HXR tokens.

4.2 Hex Stake "Good Accounting" for 10x HXR Bonus Reward

When the Hex stake has reached the full term of the stake, the user is to go to the Hex website and call the "Good Accounting" function to show the stake has completed its term. Then the user can call the claimReward function in the HXR contract to claim the 10x bonus reward. The reward is then minted to the user's address, and the claimed amount is recorded in the claimed mapping. If the user ends the stake on the Hex website, or calls the "Emergency End Stake" function, or ends the stake before claiming the HXR reward, the HXR contract will not be able to find that Hex stake anymore and will not be able to reward that Hex stake any HXR tokens.

4.3 Returning Rewards

The Return function in the HexRewards contract allows users to return their previously claimed rewards in exchange for higher rewards at a later date. By returning the claimed rewards along with an additional fee, users can re-activate their stake and accumulate more HXR tokens based on the extended time their stake has been active. This feature provides flexibility, enabling users to optimize their reward strategy based on their stake progress and investment goals. Be mindful of the agressiveness of the fee. The fee is calculated by looking at the current number of days you've already consumed, then it multiplies that number of days times the daily HXR reward amount and adds an additional 30% on top. So when you claim, as each day passes, the return fee increases such that by 170 days after you've claimed, the return amount would equate to the entire 10x bonus you would have received had you waited to claim instead. There would be no point returning your claim after 170 days.

Example:

Returning Rewards for a Standard Non-5555 Day Stake

Stake Duration: 1000 days

Initial Claim

You claim rewards at day 100 of your 1000-day stake, receiving 0.001 HXR calculated as follows:

  • Calculation: 100 days consumed of stake × 0.00001 HXR/day = 0.001 HXR

Return the same day that you claimed:

You decide to return the claim on the same day you claimed, you return 0.0013 HXR:

  • Calculation: (100 days consumed of stake) × 0.00001 HXR/day = 0.001 HXR + (30% of 0.001 HXR) = 0.0013 HXR
  • Return Amount: 0.001 HXR + (30% of 0.001 HXR) = 0.0013 HXR

Return 100 days after claiming:

You decide to return the rewards 100 days after you claimed (200 days consumed of your Hex stake). The return amount is HXR calculated as follows:

  • Calculation: (200 days consumed of stake) × 0.00001 HXR/day = 0.002 HXR
  • Return Amount: 0.002 HXR + (30% of 0.002 HXR) = 0.0026 HXR

Final Claim

5.1 Final Claim - "Good Accounting"

Upon completing the full 1000-day stake: First call the "Good Accounting" function for the stake on Hex.com website. Then the final claim reward is calculated as a 10x bonus:

  • Calculation: (1000 days consumed × 0.00001 HXR/day) × 10 = 0.1 HXR

Continuous Interaction

6.1 Continuous Interaction

Flexibility: The "Claim", "Return", and "Claim" cycle can be repeated an unlimited number of times for the same stake, as long as it is active (not ended), allowing you to optimize your reward strategy based on stake progress and changes in your investment approach.

7. Important: Index Management and Stake Protection

7.1 Understanding the Interaction

There is a critical interaction issue between HEX's stake management system and HexRewards' reward tracking mechanism. This issue stems from how HEX manages its stake array and how HexRewards tracks claimed rewards.

7.2 How HEX Manages Stakes

When you end a stake in HEX, the contract uses a "pop-and-swap" mechanism for efficiency:

  • The ended stake is removed from its position in the array
  • The LAST stake in your array is moved to fill the gap
  • This changes the index positions of stakes

7.3 The Problem

HexRewards tracks claimed rewards by stake index: mapping(address => mapping(uint256 => uint256)) claimed

When a stake moves to a new index position due to pop-and-swap, it may inherit the claim status of the previous stake at that index. This can result in:

  • Stakes appearing as "already claimed" when they haven't claimed any rewards
  • Loss of ability to claim legitimate rewards
  • Valuable stakes (including 5555-day stakes) becoming "contaminated"

7.4 The Sacrificial Stake Solution

Before ending any stake (except your last one), create a "sacrificial" stake:

  1. Create a minimal HEX stake (minimum amount based on current shareRate, typically ~0.1-1 HEX)
  2. Stake for just 1 day
  3. This becomes your new "last stake"
  4. When you end another stake, the sacrificial stake gets moved via pop-and-swap
  5. Your valuable stakes remain in their positions, preserving their reward eligibility

7.5 Implementation in the UI

The HexRewards interface includes automatic protection:

  • Orange Warning: Appears when ending a stake would affect a valuable stake
  • One-Click Solution: "Create Sacrificial Stake" button automatically creates the minimum stake needed
  • Smart Detection: Only warns when the last stake has unclaimed HexRewards value

7.6 Best Practices

  • Always maintain a small sacrificial stake as your last stake
  • Before ending stakes, check if your last stake has value
  • Use the automated protection system in the UI
  • Remember: losing 0.1 HEX is better than losing rewards on 50,000 HEX
⚠️ Warning: This is not a bug in HexRewards itself, but rather an unavoidable interaction between HEX's efficient array management and HexRewards' index-based tracking. The sacrificial stake workaround is currently the best solution to protect your valuable stakes.

Conclusion

HexRewards offers an exciting opportunity for Hex stakers to earn additional rewards based on their staking activity. With its tiered system, stake protection, and flexible reward calculation, HexRewards aims to incentivize long-term staking and provide a rewarding experience for users. By leveraging the power of smart contracts and the Hex staking system, HexRewards seeks to enhance the value proposition for Hex stakers and contribute to the growth and adoption of the Hex ecosystem.

Users should be aware of the pop-and-swap interaction and use the provided protection mechanisms to ensure they can always claim their earned rewards. The small cost of maintaining a sacrificial stake is negligible compared to the potential loss of rewards on larger stakes.