Skip to content

Commit

Permalink
Merge pull request #163 from keep-network/better-api
Browse files Browse the repository at this point in the history
SortitionPool.withdrawRewards returns the amount of rewards withdrawn
  • Loading branch information
Beau Shinkle authored Apr 25, 2022
2 parents a07bcec + 8f4d2a4 commit 0e44a05
Showing 1 changed file with 11 additions and 0 deletions.
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;
}

/// @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

0 comments on commit 0e44a05

Please # to comment.