[Contract] Implement Staking Rewards Decay Rate Calculation with Epoch Snapshots (#637) - #742
Open
iexwr wants to merge 2 commits into
Open
[Contract] Implement Staking Rewards Decay Rate Calculation with Epoch Snapshots (#637)#742iexwr wants to merge 2 commits into
iexwr wants to merge 2 commits into
Conversation
…ission rate (SoroLabs#637) Replace continuous per-block decay with epoch-based decay using on-chain snapshots. Changes: - StakingConfig: replace decay_rate with epoch_decay_percent + epoch_length - New EpochSnapshot struct stored per epoch (rate, start_block) - ensure_epoch_snapshots lazily creates snapshots up to current block - calculate_multiplier uses epoch-based rate (constant within epoch) - initialize creates epoch 0 snapshot at deployment - Fixed pre-existing bug: total_staked not updated in withdraw() - Fixed pre-existing bug: total_staked not tracked in stake() - 12 tests: all passing, including epoch_boundary_decay, epoch_snapshot_storage, multi_epoch_accumulation - Updated README with epoch snapshot documentation
|
@iexwr 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! 🚀 |
Author
|
@EDOHWARES Hello |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #637
Summary
Replaces the previous continuous per-block decay model with an epoch snapshot system. The reward emission rate is constant within each epoch and decays by a configured percentage at epoch boundaries, providing predictable per-epoch rates and reducing computational overhead.
Changes
StakingConfig
decay_ratewithepoch_decay_percent: Fixed(percentage reduction per epoch)epoch_length: u32(blocks per epoch)New: EpochSnapshot storage
rateandstart_blockon-chainensure_epoch_snapshotsinitializecreates epoch 0 snapshot at deploymentReward calculation
calculate_multiplieriterates over epochs betweent1andt2rate = initial_rate * (1 - epoch_decay_percent)^epochexp(rate * blocks_in_epoch)per epochfixed_pow_intcalls previously needed for continuous decayBug fixes
withdraw()not persistingtotal_stakedupdate (pre-existing)total_stakedtracking tostake()(was missing, pre-existing)Testing
All 12 tests pass:
test_initializationtest_stake_and_yield_accumulation_no_decaytest_stake_and_yield_accumulation_with_decaytest_epoch_boundary_decaytest_epoch_snapshot_storagetest_compounding_interesttest_zero_stake_securitytest_multi_epoch_accumulationtest_emergency_withdrawtest_pause_safeguards_staketest_pause_safeguards_withdrawtest_pause_safeguards_claim