Skip to content

Commit 15dd5f7

Browse files
committed
non-zero fee recipient check in setter
1 parent 18f69fc commit 15dd5f7

File tree

2 files changed

+10
-61
lines changed

2 files changed

+10
-61
lines changed

src/contracts/core/RewardsCoordinator.sol

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ contract RewardsCoordinator is
549549
function _setFeeRecipient(
550550
address _feeRecipient
551551
) internal {
552+
require(_feeRecipient != address(0), InvalidAddressZero());
552553
emit FeeRecipientSet(feeRecipient, _feeRecipient);
553554
feeRecipient = _feeRecipient;
554555
}
@@ -662,7 +663,7 @@ contract RewardsCoordinator is
662663

663664
// Take the protocol fee (if the submitter is opted in for protocol fees).
664665
uint256 feeAmount = submission.operatorRewards[i].amount * PROTOCOL_FEE_BIPS / ONE_HUNDRED_IN_BIPS;
665-
if (feeOn && feeRecipient != address(0) && feeAmount != 0) {
666+
if (feeOn && feeAmount != 0) {
666667
submission.operatorRewards[i].amount -= feeAmount;
667668
}
668669

@@ -794,7 +795,7 @@ contract RewardsCoordinator is
794795
) internal returns (uint256 amountAfterFee) {
795796
uint256 feeAmount = amountBeforeFee * PROTOCOL_FEE_BIPS / ONE_HUNDRED_IN_BIPS;
796797
if (isOptedInForProtocolFee[submitter]) {
797-
if (feeRecipient != address(0) && feeAmount != 0) {
798+
if (feeAmount != 0) {
798799
token.safeTransfer(feeRecipient, feeAmount);
799800
return amountBeforeFee - feeAmount;
800801
}
@@ -812,10 +813,7 @@ contract RewardsCoordinator is
812813
uint256 amountAfterFee
813814
) internal {
814815
if (amountAfterFee != amountBeforeFee) {
815-
uint256 feeAmount = amountBeforeFee - amountAfterFee;
816-
if (feeRecipient != address(0)) {
817-
token.safeTransfer(feeRecipient, feeAmount);
818-
}
816+
token.safeTransfer(feeRecipient, amountBeforeFee - amountAfterFee);
819817
}
820818
}
821819

src/test/unit/RewardsCoordinatorUnit.t.sol

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,12 @@ contract RewardsCoordinatorUnitTests_initializeAndSetters is RewardsCoordinatorU
445445
cheats.expectRevert("Ownable: caller is not the owner");
446446
rewardsCoordinator.setFeeRecipient(newFeeRecipient);
447447
}
448+
449+
function test_setFeeRecipient_Revert_WhenAddressZero() public {
450+
cheats.prank(rewardsCoordinator.owner());
451+
cheats.expectRevert(InvalidAddressZero.selector);
452+
rewardsCoordinator.setFeeRecipient(address(0));
453+
}
448454
}
449455

450456
contract RewardsCoordinatorUnitTests_setOptInForProtocolFee is RewardsCoordinatorUnitTests {
@@ -1540,61 +1546,6 @@ contract RewardsCoordinatorUnitTests_createAVSRewardsSubmission is RewardsCoordi
15401546
assertEq(rewardToken.balanceOf(feeRecipient), feeBalanceBefore, "Fee recipient balance should not change");
15411547
}
15421548
}
1543-
1544-
/// @notice Test fee deduction when fee recipient is address(0)
1545-
function testFuzz_createAVSRewardsSubmission_WithProtocolFee_FeeRecipientZero(
1546-
address avs,
1547-
uint startTimestamp,
1548-
uint duration,
1549-
uint amount
1550-
) public filterFuzzedAddressInputs(avs) {
1551-
cheats.assume(avs != address(0));
1552-
1553-
// 1. Set fee recipient to address(0)
1554-
cheats.prank(rewardsCoordinator.owner());
1555-
rewardsCoordinator.setFeeRecipient(address(0));
1556-
1557-
// 2. Bound fuzz inputs to valid ranges and amounts
1558-
IERC20 rewardToken = new ERC20PresetFixedSupply("dog wif hat", "MOCK1", mockTokenInitialSupply, avs);
1559-
amount = bound(amount, 1, mockTokenInitialSupply);
1560-
duration = bound(duration, CALCULATION_INTERVAL_SECONDS, MAX_REWARDS_DURATION);
1561-
duration = duration - (duration % CALCULATION_INTERVAL_SECONDS);
1562-
startTimestamp = bound(
1563-
startTimestamp,
1564-
uint(_maxTimestamp(GENESIS_REWARDS_TIMESTAMP, uint32(block.timestamp) - MAX_RETROACTIVE_LENGTH)) + CALCULATION_INTERVAL_SECONDS
1565-
- 1,
1566-
block.timestamp + uint(MAX_FUTURE_LENGTH)
1567-
);
1568-
startTimestamp = startTimestamp - (startTimestamp % CALCULATION_INTERVAL_SECONDS);
1569-
1570-
// 3. Opt in for protocol fees
1571-
cheats.prank(avs);
1572-
rewardsCoordinator.setOptInForProtocolFee(avs, true);
1573-
1574-
// 4. Create rewards submission and verify balances
1575-
RewardsSubmission[] memory rewardsSubmissions = new RewardsSubmission[](1);
1576-
rewardsSubmissions[0] = RewardsSubmission({
1577-
strategiesAndMultipliers: defaultStrategyAndMultipliers,
1578-
token: rewardToken,
1579-
amount: amount,
1580-
startTimestamp: uint32(startTimestamp),
1581-
duration: uint32(duration)
1582-
});
1583-
1584-
{
1585-
uint avsBalanceBefore = rewardToken.balanceOf(avs);
1586-
uint rcBalanceBefore = rewardToken.balanceOf(address(rewardsCoordinator));
1587-
1588-
cheats.startPrank(avs);
1589-
rewardToken.approve(address(rewardsCoordinator), amount);
1590-
rewardsCoordinator.createAVSRewardsSubmission(rewardsSubmissions);
1591-
cheats.stopPrank();
1592-
1593-
// Verify balances - no fee transferred when feeRecipient is address(0)
1594-
assertEq(rewardToken.balanceOf(avs), avsBalanceBefore - amount, "AVS balance incorrect");
1595-
assertEq(rewardToken.balanceOf(address(rewardsCoordinator)), rcBalanceBefore + amount, "RC balance incorrect");
1596-
}
1597-
}
15981549
}
15991550

16001551
contract RewardsCoordinatorUnitTests_createRewardsForAllSubmission is RewardsCoordinatorUnitTests {

0 commit comments

Comments
 (0)