diff --git a/script/deploys/DeployEtherFiRewardsRouter.s.sol b/script/deploys/DeployEtherFiRewardsRouter.s.sol new file mode 100644 index 00000000..b32a3d32 --- /dev/null +++ b/script/deploys/DeployEtherFiRewardsRouter.s.sol @@ -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)); + } +} diff --git a/src/EtherFiRewardsRouter.sol b/src/EtherFiRewardsRouter.sol index 4531eb35..57bf8333 100644 --- a/src/EtherFiRewardsRouter.sol +++ b/src/EtherFiRewardsRouter.sol @@ -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"); @@ -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 { @@ -40,8 +39,6 @@ contract EtherFiRewardsRouter is OwnableUpgradeable, UUPSUpgradeable { } function withdrawToLiquidityPool() external { - if (!roleRegistry.hasRole(ETHERFI_ROUTER_ADMIN, msg.sender)) revert IncorrectRole(); - uint256 balance = address(this).balance; require(balance > 0, "Contract balance is zero"); (bool success, ) = liquidityPool.call{value: balance}(""); @@ -51,7 +48,7 @@ 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); @@ -59,7 +56,7 @@ contract EtherFiRewardsRouter is OwnableUpgradeable, UUPSUpgradeable { } 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); @@ -69,4 +66,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; + } + } diff --git a/test/EtherFiRewardsRouter.t.sol b/test/EtherFiRewardsRouter.t.sol index 37a0f165..4b90e153 100644 --- a/test/EtherFiRewardsRouter.t.sol +++ b/test/EtherFiRewardsRouter.t.sol @@ -14,12 +14,11 @@ contract EtherFiRewardsRouterTest is TestSetup { setUpTests(); initializeRealisticFork(MAINNET_FORK); vm.startPrank(owner); - etherfiRewardsRouterImplementation = new EtherFiRewardsRouter(address(liquidityPoolInstance), address(roleRegistry)); + etherfiRewardsRouterImplementation = new EtherFiRewardsRouter(address(liquidityPoolInstance), admin); etherfiRewardsRouterProxy = new UUPSProxy(address(etherfiRewardsRouterImplementation), ""); etherfiRewardsRouterInstance = EtherFiRewardsRouter(payable(address(etherfiRewardsRouterProxy))); etherfiRewardsRouterInstance.initialize(); vm.startPrank(superAdmin); - roleRegistry.grantRole(etherfiRewardsRouterInstance.ETHERFI_ROUTER_ADMIN(), admin); vm.stopPrank(); liquidityPoolAddress = address(liquidityPoolInstance); @@ -38,7 +37,7 @@ contract EtherFiRewardsRouterTest is TestSetup { function test_elRouterUpgrade() public { vm.startPrank(owner); - EtherFiRewardsRouter newEtherfiRewardsRouterImplementation = new EtherFiRewardsRouter(address(liquidityPoolInstance), address(roleRegistry)); + EtherFiRewardsRouter newEtherfiRewardsRouterImplementation = new EtherFiRewardsRouter(address(liquidityPoolInstance), admin); address oldImplementation = etherfiRewardsRouterInstance.getImplementation(); etherfiRewardsRouterInstance.upgradeTo(address(newEtherfiRewardsRouterImplementation)); address newImplementation = etherfiRewardsRouterInstance.getImplementation();