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

EFIP-9 Nethermind: Execution Layer Rewards Router #154

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions script/deploys/DeployEtherFiRewardsRouter.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Script.sol";

import "src/EtherFiRewardsRouter.sol";
import "src/UUPSProxy.sol";

/*
* source .env && forge script ./script/deploys/DeployEtherFiRewardsRouter.s.sol:DeployEtherFiRewardsRouter --rpc-url $TENDERLY_RPC_URL --broadcast --etherscan-api-key $TENDERLY_ACCESS_CODE --verify --verifier-url $TENDERLY_VERIFIER_URL
*/

contract DeployEtherFiRewardsRouter is Script {

function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
address lp_address = address(0x308861A430be4cce5502d0A12724771Fc6DaF216);
address admin = address(0); //after deployed use correct role registry address
vm.startBroadcast(deployerPrivateKey);

EtherFiRewardsRouter etherFiRewardsRouterImplementation = new EtherFiRewardsRouter(lp_address, admin);
UUPSProxy etherFiRewardsRouterProxy = new UUPSProxy(address(etherFiRewardsRouterImplementation), "");
EtherFiRewardsRouter etherFiRewardsRouterInstance = EtherFiRewardsRouter(payable(etherFiRewardsRouterProxy));
}
}
18 changes: 11 additions & 7 deletions src/EtherFiRewardsRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import "./RoleRegistry.sol";

contract EtherFiRewardsRouter is OwnableUpgradeable, UUPSUpgradeable {
using SafeERC20 for IERC20;

address public immutable treasury;
address public immutable liquidityPool;
RoleRegistry public immutable roleRegistry;
address public admin;

bytes32 public constant ETHERFI_ROUTER_ADMIN = keccak256("ETHERFI_ROUTER_ADMIN");

Expand All @@ -24,10 +23,10 @@ contract EtherFiRewardsRouter is OwnableUpgradeable, UUPSUpgradeable {

error IncorrectRole();

constructor(address _liquidityPool, address _roleRegistry) {
constructor(address _liquidityPool, address _admin) {
_disableInitializers();
liquidityPool = _liquidityPool;
roleRegistry = RoleRegistry(_roleRegistry);
admin = _admin;
}

receive() external payable {
Expand All @@ -40,7 +39,7 @@ contract EtherFiRewardsRouter is OwnableUpgradeable, UUPSUpgradeable {
}

function withdrawToLiquidityPool() external {
if (!roleRegistry.hasRole(ETHERFI_ROUTER_ADMIN, msg.sender)) revert IncorrectRole();
if (msg.sender != admin) revert IncorrectRole();
Copy link
Contributor

Choose a reason for hiding this comment

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

@vvalecha519 I think we can make this function withdrawToLiquidityPool permission-less


uint256 balance = address(this).balance;
require(balance > 0, "Contract balance is zero");
Expand All @@ -51,15 +50,15 @@ contract EtherFiRewardsRouter is OwnableUpgradeable, UUPSUpgradeable {
}

function recoverERC20(address _token, uint256 _amount) external {
if (!roleRegistry.hasRole(ETHERFI_ROUTER_ADMIN, msg.sender)) revert IncorrectRole();
if (msg.sender != admin) revert IncorrectRole();

IERC20(_token).safeTransfer(treasury, _amount);

emit Erc20Sent(msg.sender, _token, _amount);
}

function recoverERC721(address _token, uint256 _tokenId) external {
if (!roleRegistry.hasRole(ETHERFI_ROUTER_ADMIN, msg.sender)) revert IncorrectRole();
if (msg.sender != admin) revert IncorrectRole();

IERC721(_token).transferFrom(address(this), treasury, _tokenId);

Expand All @@ -69,4 +68,9 @@ contract EtherFiRewardsRouter is OwnableUpgradeable, UUPSUpgradeable {
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}

function getImplementation() external view returns (address) {return _getImplementation();}

function setAdmin(address _admin) external onlyOwner {
admin = _admin;
}

}