-
Notifications
You must be signed in to change notification settings - Fork 475
fix: release voter epoch rewards CELO to LockedGold #11699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pahor167
wants to merge
7
commits into
release/core-contracts/17
Choose a base branch
from
pahor/EpochManagerRelease
base: release/core-contracts/17
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+94
−0
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ec380e9
fix: release voter epoch rewards CELO to LockedGold
2be06ce
Merge branch 'release/core-contracts/16' into pahor/EpochManagerRelease
pahor167 f3bc3b2
fix: correct version bump to patch (1.1.0.3)
3f99d13
fix: release only distributed voter rewards to LockedGold
f5a5cd1
fix: move totalDistributedVoterRewards out of struct to preserve stor…
5832af3
Merge branch 'release/core-contracts/16' into pahor/EpochManagerRelease
pahor167 a9b7271
fix: revert version bump to 1.1.0.3 (release diff is against v14 base…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ contract EpochManagerTest is TestWithUtils08 { | |
| address carbonOffsettingPartner; | ||
| address communityRewardFund; | ||
| address reserveAddress; | ||
| address lockedGoldAddress; | ||
| address scoreManagerAddress; | ||
|
|
||
| uint256 firstEpochNumber = 3; | ||
|
|
@@ -90,6 +91,7 @@ contract EpochManagerTest is TestWithUtils08 { | |
| scoreManagerAddress = actor("scoreManagerAddress"); | ||
|
|
||
| reserveAddress = actor("reserve"); | ||
| lockedGoldAddress = actor("lockedGold"); | ||
|
|
||
| carbonOffsettingPartner = actor("carbonOffsettingPartner"); | ||
| communityRewardFund = actor("communityRewardFund"); | ||
|
|
@@ -108,6 +110,7 @@ contract EpochManagerTest is TestWithUtils08 { | |
| registry.setAddressFor(ScoreManagerContract, address(scoreManager)); | ||
| registry.setAddressFor(StableTokenContract, address(stableToken)); | ||
| registry.setAddressFor(ReserveContract, reserveAddress); | ||
| registry.setAddressFor(LockedGoldContract, lockedGoldAddress); | ||
| registry.setAddressFor(ElectionContract, address(election)); | ||
|
|
||
| celoUnreleasedTreasury.setRegistry(REGISTRY_ADDRESS); | ||
|
|
@@ -576,6 +579,56 @@ contract EpochManagerTest_finishNextEpochProcess is EpochManagerTest { | |
|
|
||
| assertEq(celoToken.balanceOf(communityRewardFund), epochRewards.totalRewardsCommunity()); | ||
| assertEq(celoToken.balanceOf(carbonOffsettingPartner), epochRewards.totalRewardsCarbonFund()); | ||
| // LockedGold receives the sum of voter rewards actually distributed to groups, | ||
| // which for this fixture is `groupEpochRewards` (a single elected group). | ||
| assertEq( | ||
| celoToken.balanceOf(lockedGoldAddress), | ||
| groupEpochRewards, | ||
| "LockedGold should receive distributed voter rewards" | ||
| ); | ||
| } | ||
|
|
||
| function test_ReleasesOnlyDistributedVoterRewards_WhenSlashed() public { | ||
| // Simulate a slashed/score-reduced group where Election distributes less than | ||
| // the target voter bucket. Release must match the distributed amount (not the | ||
| // target), otherwise excess CELO would be stranded in LockedGold. | ||
| uint256 reducedRewards = groupEpochRewards / 4; | ||
| election.setGroupEpochRewardsBasedOnScore(group, reducedRewards); | ||
|
|
||
| ( | ||
| address[] memory groups, | ||
| address[] memory lessers, | ||
| address[] memory greaters | ||
| ) = getGroupsWithLessersAndGreaters(); | ||
|
|
||
| epochManagerContract.startNextEpochProcess(); | ||
| epochManagerContract.finishNextEpochProcess(groups, lessers, greaters); | ||
|
|
||
| assertEq( | ||
| celoToken.balanceOf(lockedGoldAddress), | ||
| reducedRewards, | ||
| "LockedGold should receive only the distributed (reduced) voter rewards" | ||
| ); | ||
| } | ||
|
|
||
| function test_ReleasesNothingToLockedGold_WhenAllGroupsIneligible() public { | ||
| // Group is ineligible / fully slashed -> distributed amount is 0. | ||
| election.setGroupEpochRewardsBasedOnScore(group, 0); | ||
|
|
||
| ( | ||
| address[] memory groups, | ||
| address[] memory lessers, | ||
| address[] memory greaters | ||
| ) = getGroupsWithLessersAndGreaters(); | ||
|
|
||
| epochManagerContract.startNextEpochProcess(); | ||
| epochManagerContract.finishNextEpochProcess(groups, lessers, greaters); | ||
|
|
||
| assertEq( | ||
| celoToken.balanceOf(lockedGoldAddress), | ||
| 0, | ||
| "LockedGold should receive nothing when no voter rewards were distributed" | ||
| ); | ||
| } | ||
|
|
||
| function test_TransfersToValidatorGroup() public { | ||
|
|
@@ -741,6 +794,29 @@ contract EpochManagerTest_processGroup is EpochManagerTest { | |
|
|
||
| assertEq(celoToken.balanceOf(communityRewardFund), epochRewards.totalRewardsCommunity()); | ||
| assertEq(celoToken.balanceOf(carbonOffsettingPartner), epochRewards.totalRewardsCarbonFund()); | ||
| assertEq( | ||
| celoToken.balanceOf(lockedGoldAddress), | ||
| groupEpochRewards, | ||
| "LockedGold should receive distributed voter rewards via processGroup path" | ||
| ); | ||
| } | ||
|
|
||
| function test_ReleasesOnlyDistributedVoterRewards_WhenSlashed() public { | ||
| // Regression: per-group score / slashing multiplier reduces the distributed | ||
| // amount below the target voter bucket. Release must match what was actually | ||
| // distributed via the processGroup path. | ||
|
Comment on lines
+805
to
+807
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if comment is necessary. Do we need an in-code history of which unit tests were for regressions? |
||
| uint256 reducedRewards = groupEpochRewards / 4; | ||
| election.setGroupEpochRewardsBasedOnScore(group, reducedRewards); | ||
|
|
||
| epochManagerContract.startNextEpochProcess(); | ||
| epochManagerContract.setToProcessGroups(); | ||
| epochManagerContract.processGroup(group, address(0), address(0)); | ||
|
|
||
| assertEq( | ||
| celoToken.balanceOf(lockedGoldAddress), | ||
| reducedRewards, | ||
| "LockedGold should receive only the distributed (reduced) voter rewards" | ||
| ); | ||
| } | ||
|
|
||
|
pahor167 marked this conversation as resolved.
|
||
| function test_TransfersToValidatorGroup() public { | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.