Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

SortitionPool.withdrawRewards returns the amount of rewards withdrawn #163

Merged
merged 2 commits into from
Apr 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions contracts/SortitionPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,27 @@ contract SortitionPool is SortitionTree, Rewards, Ownable, IReceiveApproval {
Rewards.addRewards(uint96(amount), uint32(root.sumWeight()));
}

/// @notice Withdraws all available rewards for the given operator to the
/// given beneficiary.
/// @dev Can be called only be the owner. Does not validate if the provided
/// beneficiary is associated with the provided operator - this needs to
/// be done by the owner calling this function.
/// @return The amount of rewards withdrawn in this call.
function withdrawRewards(address operator, address beneficiary)
public
onlyOwner
returns (uint96)
{
uint32 id = getOperatorID(operator);
Rewards.updateOperatorRewards(id, uint32(getPoolWeight(operator)));
uint96 earned = Rewards.withdrawOperatorRewards(id);
rewardToken.transfer(beneficiary, uint256(earned));
return earned;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not going to block this PR for it, but I just merged #162 that uses this function in tests.

Now that we have a return value, we should assert that the return value of withdrawRewards is correct!

}

/// @notice Withdraws rewards not allocated to operators marked as ineligible
/// to the given recipient address.
/// @dev Can be called only by the owner.
function withdrawIneligible(address recipient) public onlyOwner {
uint96 earned = Rewards.withdrawIneligibleRewards();
rewardToken.transfer(recipient, uint256(earned));
Expand Down