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

Use Ownable2Step #12

Merged
merged 2 commits into from
Jan 17, 2024
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
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@

Contracts for managing validator's rewards fees

## How it works on a high-level
## Overview

- The repo contains 2 contracts: `FeeRewardsManager` and `RewardsCollector`
- Fee manager contract `FeeRewardsManager` will be deployed once per environment
- The repo contains 2 contracts: `FeeRewardsManager` and `RewardsCollector` and a library `CalculateAndSendRewards`
- Fee manager contract `FeeRewardsManager` will be deployed once per environment.
- `FeeRewardsManager` creates one `RewardsCollector` contract per withdrawal credentials (some users may have more than 1)
- On creation `FeeRewardsManager` sets a default commission fee and has permission to change that fee
- `RewardsCollector` address will be derived from `withdrawal credentials`
- `RewardsCollector` address will be set as `fee_recipient` for customers validators and earn execution rewards
- `collectRewards` function in `RewardsCollector` contract can be triggered to send rewards minus commission fee to withdrawal address
- On creation `FeeRewardsManager` sets a default commission fee and has permission to change that fee.
- `RewardsCollector` address will be derived from `withdrawal credentials`.
- `RewardsCollector` address will be set as `fee_recipient` for customers validators and earn execution rewards.
- `collectRewards` function in `RewardsCollector` contract can be triggered to send rewards minus commission fee to withdrawal .address.

### `RewardsCollector` Contract

- **Ownership**: This contract does not explicitly use an ownership model. Instead, it references a `parentContract`, the contract that deployed it, the `FeeRewardsManager` contract.
- **withdrawalCredential**: A crucial address that is set upon contract deployment, determining where a portion of the fees are sent.
- **feeNumerator**: A value determining the fee percentage, modifiable only by the `parentContract`.

### `FeeRewardsManager` Contract

- **Ownership**: Inherits from `Ownable2Step`, a variant of the OpenZeppelin `Ownable` contract, which provides a secure ownership model with a two-step transfer process to prevent accidental loss of ownership. The part that is receiving
the ownership on the transfer must confirm it with a transaction.
- **defaultFeeNumerator**: Set upon deployment and modifiable by the contract owner.
- **Eth Withdrawal**: Only the owner can withdraw Eth from the contract.

## Walkthrough a normal execution

Expand Down
4 changes: 2 additions & 2 deletions src/FeeRewardsManager.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.13;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/Ownable2Step.sol";

// We use a library for the `calculateRewards` function because the less code in
// `RewardsCollector` the less expensive it it to deploy the collector contract.
Expand Down Expand Up @@ -86,7 +86,7 @@ contract RewardsCollector {
}
}

contract FeeRewardsManager is Ownable {
contract FeeRewardsManager is Ownable2Step {
uint32 public defaultFeeNumerator;

constructor(uint32 _defaultFeeNumerator) {
Expand Down
9 changes: 9 additions & 0 deletions test/FeeRewardsManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,13 @@ contract FeeRewardsTest is Test {
vm.expectRevert("Failed to send Ether back to withdrawal credential");
RewardsCollector(payable(addr)).collectRewards();
}

function testChangeOwnership() public {
enriquefynn marked this conversation as resolved.
Show resolved Hide resolved
feeRewardsManager.transferOwnership(address(0x105));
assertEq(feeRewardsManager.pendingOwner(), address(0x105));
vm.startPrank(address(0x105));
feeRewardsManager.acceptOwnership();
vm.stopPrank();
assertEq(feeRewardsManager.owner(), address(0x105));
}
}