Skip to content

fix: update rewards before direct claim - #7

Open
sirakinb wants to merge 1 commit into
etherisc:developfrom
sirakinb:codex/fix-claim-rewards-before-unstake
Open

sirakinb wants to merge 1 commit into
etherisc:developfrom
sirakinb:codex/fix-claim-rewards-before-unstake

Conversation

@sirakinb

Copy link
Copy Markdown

Fixes #2.

StakingV01.claimRewards paid only the stored rewardBalance. If a staker called claimRewards() before any unstake or owner reward update, accrued rewards were not first materialized into the stake info, so the claim could emit/pay 0 even though calculateRewardsIncrement() was positive.

This updates rewards before claiming in the base V1 implementation, matching the later V2 behavior and the expectation that a direct claim pays currently accrued rewards.

Also adds a regression test against the V1 staking fixture that:

  • creates a stake
  • advances time so rewards accrue
  • verifies rewardBalance is still 0 before claim
  • calls claimRewards() without unstaking first
  • asserts a positive reward payout and a zero remaining reward balance

Verification performed locally:

  • git diff --check
  • python3 -m py_compile tests/test_staking_unstake_claim_rewards.py
  • npx --yes solhint@3.6.2 contracts/staking/StakingV01.sol (0 errors; existing custom-error warnings only)

I could not run brownie test locally because Brownie is not installed on this machine, pip install eth-brownie is blocked by its pinned PyYAML==5.4.1 build on the local macOS/Python setup, and Docker is installed but the daemon is not running for the repository devcontainer.

@openzeppelin-code

Copy link
Copy Markdown

fix: update rewards before direct claim

Generated at commit: 28b48ceca81ebc3815cdcd07e8fbc0214c323ee2

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
0
1
0
7
22
30
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
1
8
9

For more details view the full report in OpenZeppelin Code Inspector

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.

[Bug]: claimRewards() is always sending 0 DIP rewards and resets user's rewardsBalance when called before unstake()

2 participants