Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 133
[C02] Rewards pay out incorrectly when the service provider has a pending “decrease stake” request#548
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
Closed
Uh oh!
There was an error while loading. Please reload this page.
Closed
[C02] Rewards pay out incorrectly when the service provider has a pending “decrease stake” request #548
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
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 |
|---|---|---|
| @@ -338,18 +338,19 @@ contract DelegateManager is InitializableV2 { | ||
| ( | ||
| uint totalBalanceInStaking, | ||
| uint totalBalanceInSPFactory, | ||
| uint totalBalanceOutsideStaking | ||
| uint totalActiveFunds, | ||
| uint spLockedStake, | ||
| uint totalRewards | ||
| ) = _validateClaimRewards(spFactory); | ||
| // No-op if balance is already equivalent | ||
| // This case can occur if no rewards due to bound violation or all stake is locked | ||
| if (totalBalanceInStaking == totalBalanceOutsideStaking) { | ||
| if (totalRewards == 0) { | ||
| return; | ||
| } | ||
| // Total rewards | ||
| // Equal to (balance in staking) - ((balance in sp factory) + (balance in delegate manager)) | ||
| uint totalRewards = totalBalanceInStaking.sub(totalBalanceOutsideStaking); | ||
| // Emit claim event | ||
| emit Claim(msg.sender, totalRewards, totalBalanceInStaking); | ||
| @@ -359,11 +360,6 @@ contract DelegateManager is InitializableV2 { | ||
| uint spDeployerCutRewards = 0; | ||
| uint totalDelegatedStakeIncrease = 0; | ||
| // Total valid funds used to calculate rewards distribution | ||
| uint totalActiveFunds = ( | ||
| totalBalanceOutsideStaking.sub(spDelegateInfo[msg.sender].totalLockedUpStake) | ||
| ); | ||
| // Traverse all delegates and calculate their rewards | ||
| // As each delegate reward is calculated, increment SP cut reward accordingly | ||
| for (uint i = 0; i < spDelegateInfo[msg.sender].delegators.length; i++) { | ||
| @@ -412,8 +408,10 @@ contract DelegateManager is InitializableV2 { | ||
| ); | ||
| // Rewards directly allocated to service provider for their stake | ||
| // Total active funds for direct deployer reward share | ||
| /// totalActiveDeployerFunds = totalBalanceInSPFactory.sub(spLockedStake); | ||
| uint spRewardShare = ( | ||
| totalBalanceInSPFactory.mul(totalRewards) | ||
| (totalBalanceInSPFactory.sub(spLockedStake)).mul(totalRewards) | ||
| ).div(totalActiveFunds); | ||
| spFactory.updateServiceProviderStake( | ||
| @@ -700,41 +698,56 @@ contract DelegateManager is InitializableV2 { | ||
| * @notice Helper function for claimRewards to get balances from Staking contract | ||
| and do validation | ||
| * @param spFactory - reference to ServiceProviderFactory contract | ||
| * @return (totalBalanceInStaking, totalBalanceInSPFactory, totalBalanceOutsideStaking) | ||
| * @return (totalBalanceInStaking, totalBalanceInSPFactory, totalActiveFunds, spLockedStake, totalRewards) | ||
| */ | ||
| function _validateClaimRewards(ServiceProviderFactory spFactory) | ||
| internal returns (uint totalBalanceInStaking, uint totalBalanceInSPFactory, uint totalBalanceOutsideStaking) | ||
| { | ||
| internal returns ( | ||
| uint totalBalanceInStaking, | ||
| uint totalBalanceInSPFactory, | ||
| uint totalActiveFunds, | ||
| uint spLockedStake, | ||
| uint totalRewards | ||
| ) | ||
| { | ||
| // Account for any pending locked up stake for the service provider | ||
| (uint spLockedStake,) = spFactory.getPendingDecreaseStakeRequest(msg.sender); | ||
| (spLockedStake,) = spFactory.getPendingDecreaseStakeRequest(msg.sender); | ||
| uint totalLockedUpStake = spDelegateInfo[msg.sender].totalLockedUpStake.add(spLockedStake); | ||
| // Process claim for msg.sender | ||
| // Total locked parameter is equal to delegate locked up stake + service provider locked up stake | ||
| ClaimsManager(claimsManagerAddress).processClaim( | ||
| uint mintedRewards = ClaimsManager(claimsManagerAddress).processClaim( | ||
| msg.sender, | ||
| (spDelegateInfo[msg.sender].totalLockedUpStake.add(spLockedStake)) | ||
| totalLockedUpStake | ||
| ); | ||
| // Amount stored in staking contract for owner | ||
| uint _totalBalanceInStaking = Staking(stakingAddress).totalStakedFor(msg.sender); | ||
| require(_totalBalanceInStaking > 0, "Stake required for claim"); | ||
| totalBalanceInStaking = Staking(stakingAddress).totalStakedFor(msg.sender); | ||
| require(totalBalanceInStaking > 0, "Stake required for claim"); | ||
| // Amount in sp factory for claimer | ||
| (uint _totalBalanceInSPFactory,,,,,) = spFactory.getServiceProviderDetails(msg.sender); | ||
| // Decrease total balance by any locked up stake | ||
| _totalBalanceInSPFactory = _totalBalanceInSPFactory.sub(spLockedStake); | ||
| (totalBalanceInSPFactory,,,,,) = spFactory.getServiceProviderDetails(msg.sender); | ||
| // Require active stake to claim any rewards | ||
| require(_totalBalanceInSPFactory > 0, "Service Provider stake required"); | ||
| require(totalBalanceInSPFactory.sub(spLockedStake) > 0, "Service Provider stake required"); | ||
| // Amount in delegate manager staked to service provider | ||
| uint _totalBalanceOutsideStaking = ( | ||
| _totalBalanceInSPFactory.add(spDelegateInfo[msg.sender].totalDelegatedStake) | ||
| uint totalBalanceOutsideStaking = ( | ||
| totalBalanceInSPFactory.add(spDelegateInfo[msg.sender].totalDelegatedStake) | ||
| ); | ||
| return (_totalBalanceInStaking, _totalBalanceInSPFactory, _totalBalanceOutsideStaking); | ||
| totalActiveFunds = totalBalanceOutsideStaking.sub(totalLockedUpStake); | ||
| require( | ||
SidSethi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| mintedRewards == totalBalanceInStaking.sub(totalBalanceOutsideStaking), | ||
| "Reward amount mismatch" | ||
| ); | ||
| return ( | ||
| totalBalanceInStaking, | ||
| totalBalanceInSPFactory, | ||
| totalActiveFunds, | ||
| spLockedStake, | ||
| mintedRewards | ||
| ); | ||
| } | ||
| /** | ||
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
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.