Skip to content
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

Apply second review changes #6

Merged
merged 4 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
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
14 changes: 10 additions & 4 deletions src/FeeRewardsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "@openzeppelin/contracts/access/Ownable.sol";
contract RewardsCollector is Ownable {
event CollectedReward(
address withdrawalCredential,
uint256 withdrawalFee,
uint256 withdrawnAmount,
address owner,
uint256 ownerFee
);
Expand Down Expand Up @@ -53,7 +53,7 @@ contract RewardsCollector is Ownable {
feeNumerator = _feeNumerator;
}

function changeFee(uint32 _newFeeNumerator) public onlyOwner {
function changeFeeNumerator(uint32 _newFeeNumerator) public onlyOwner {
feeNumerator = _newFeeNumerator;
}
}
Expand Down Expand Up @@ -88,6 +88,12 @@ contract FeeRewardsManager is Ownable {
return payable(addr);
}

// Predicts the address of a new contract that will be a `fee_recipient` of
// an Ethereum validator.
// Given the `_withdrawalCredential` we can instantiate a contract that will
// be deployed at a deterministic address, calculated given the
// `_withdrawalCredential`, the current contract address and the current
// contract's bytecode.
function predictFeeContractAddress(
address _withdrawalCredential
) public view returns (address) {
Expand All @@ -110,11 +116,11 @@ contract FeeRewardsManager is Ownable {
return address(uint160(uint(hash)));
}

function changeFee(
function changeFeeNumerator(
address payable _feeContract,
uint32 _newFee
) public onlyOwner {
RewardsCollector(_feeContract).changeFee(_newFee);
RewardsCollector(_feeContract).changeFeeNumerator(_newFee);
}

function batchCollectRewards(
Expand Down
30 changes: 13 additions & 17 deletions test/FeeRewardsManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ contract FeeRewardsTest is Test {
// We've got the ether.
assertEq(address(feeRewardsManager).balance, 0 ether);
assertEq(address(101).balance, 2.8 ether);

vm.deal(derivedAddr, 10 ether);
RewardsCollector(payable(addr)).collectRewards();
assertEq(addr.balance, 0 ether);
assertEq(withdrawalCredential.balance, 7.2 ether + 7.2 ether);
assertEq(address(101).balance, 2.8 ether);
}

function createWithdrawalSimulateRewards(
Expand Down Expand Up @@ -95,6 +101,10 @@ contract FeeRewardsTest is Test {
}
feeRewardsManager.batchCollectRewards(addrs);
assertEq(address(feeRewardsManager).balance, 280 ether);

for (uint256 i = 0; i < 100; ++i) {
assertEq(address(uint160(i + 100)).balance, 7.2 ether);
}
}

function testChangeDefaultFee() public {
Expand All @@ -114,7 +124,7 @@ contract FeeRewardsTest is Test {
address addr = address(
createWithdrawalSimulateRewards(address(100), 10 ether)
);
feeRewardsManager.changeFee(payable(addr), 10000);
feeRewardsManager.changeFeeNumerator(payable(addr), 10000);
RewardsCollector(payable(addr)).collectRewards();
assertEq(address(100).balance, 0 ether);
// We receive 100%.
Expand Down Expand Up @@ -177,28 +187,14 @@ contract FeeRewardsTest is Test {
}

function testSendToContractWithdrawalCredential() public {
WithdrawalContract withdrawalCredentialContract = new WithdrawalContract();
address addr = address(
createWithdrawalSimulateRewards(
address(withdrawalCredentialContract),
10 ether
)
);
RewardsCollector(payable(addr)).collectRewards();
assertEq(address(feeRewardsManager).balance, 2.8 ether);
assertEq(address(withdrawalCredentialContract).balance, 7.2 ether);
}

function testChangeOwnerWithContract() public {
WithdrawalContract withdrawalCredentialContract = new WithdrawalContract();
ChangeOwnerContract withdrawalCredentialContract = new ChangeOwnerContract();
address addr = address(
createWithdrawalSimulateRewards(
address(withdrawalCredentialContract),
10 ether
)
);
vm.expectRevert("Failed to send Ether back to withdrawal credential");
RewardsCollector(payable(addr)).collectRewards();
assertEq(address(feeRewardsManager).balance, 2.8 ether);
assertEq(address(withdrawalCredentialContract).balance, 7.2 ether);
}
}