Skip to content

Commit

Permalink
Merge pull request #204 from etherfi-protocol/vaibhav/merge-rewards-r…
Browse files Browse the repository at this point in the history
…outer

update master with deployed contracts rewardsrouter
  • Loading branch information
vvalecha519 authored Nov 20, 2024
2 parents 4e421df + 4830893 commit aca4568
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
40 changes: 40 additions & 0 deletions script/deploys/DeployEtherFiRewardsRouter.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Script.sol";

import "src/EtherFiRewardsRouter.sol";
import "src/UUPSProxy.sol";
import "../../src/helpers/AddressProvider.sol";
import "forge-std/console.sol";

/* Deploy Command
* source .env && forge script ./script/deploys/DeployEtherFiRewardsRouter.s.sol:DeployEtherFiRewardsRouter --rpc-url MAINNET_RPC_URL --broadcast --etherscan-api-key $ETHERSCAN_API_KEY --verify --slow -vvvv
*/

contract DeployEtherFiRewardsRouter is Script {

AddressProvider public addressProvider;
///////////////////////////////////////
address roleRegistryProxyAddress = address(0x1d3Af47C1607A2EF33033693A9989D1d1013BB50); //replace with deployed RoleRegistryProxy address
address treasuryGnosisSafeAddress = address(0x0c83EAe1FE72c390A02E426572854931EefF93BA);
address etherfiRouterAdmin = address(0xc13C06899a9BbEbB3E2b38dBe86e4Ea8852AFC9b);
//////////////////////////////////////

function run() external {

address addressProviderAddress = vm.envAddress("CONTRACT_REGISTRY");

vm.startBroadcast();

RoleRegistry roleRegistryInstance = RoleRegistry(roleRegistryProxyAddress);
roleRegistryInstance.grantRole(keccak256("ETHERFI_ROUTER_ADMIN"), etherfiRouterAdmin);

addressProvider = AddressProvider(addressProviderAddress);

address liquidityPoolProxyAddress = addressProvider.getContractAddress("LiquidityPool");
bytes memory initializerData = abi.encodeWithSelector(EtherFiRewardsRouter.initialize.selector);
EtherFiRewardsRouter etherFiRewardsRouterImplementation = new EtherFiRewardsRouter(liquidityPoolProxyAddress, treasuryGnosisSafeAddress, roleRegistryProxyAddress);
UUPSProxy etherFiRewardsRouterProxy = new UUPSProxy(address(etherFiRewardsRouterImplementation), initializerData);
}
}
31 changes: 31 additions & 0 deletions script/deploys/DeployRoleRegistry.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

import "forge-std/Script.sol";

import "src/RoleRegistry.sol";
import "src/UUPSProxy.sol";
import "../../src/helpers/AddressProvider.sol";


/* deploy command
* source .env && forge script ./script/deploys/DeployRoleRegistry.s.sol:DeployRoleRegistry --rpc-url MAINNET_RPC_URL --broadcast --etherscan-api-key $ETHERSCAN_API_KEY --verify --slow -vvvv
*/

contract DeployRoleRegistry is Script {

AddressProvider public addressProvider;
///////////////////////////////////////
address superAdmin = address(0x8D5AAc5d3d5cda4c404fA7ee31B0822B648Bb150); //replace with actual super admin address
//////////////////////////////////////

function run() external {
vm.startBroadcast();

RoleRegistry roleRegistryImplementation = new RoleRegistry();
bytes memory initializerData = abi.encodeWithSelector(RoleRegistry.initialize.selector, superAdmin);
UUPSProxy roleRegistryProxy = new UUPSProxy(address(roleRegistryImplementation), initializerData);

vm.stopBroadcast();
}
}
73 changes: 73 additions & 0 deletions src/EtherFiRewardsRouter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
pragma solidity ^0.8.24;

import "@openzeppelin-upgradeable/contracts/access/OwnableUpgradeable.sol";
import "@openzeppelin-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol";
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;

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

event EthReceived(address indexed from, uint256 value);
event EthSent(address indexed from, address indexed to, uint256 value);
event UpdatedTreasury(address indexed treasury);
event Erc20Sent(address indexed caller, address indexed token, uint256 amount);
event Erc721Sent(address indexed caller, address indexed token, uint256 tokenId);

error IncorrectRole();

constructor(address _liquidityPool, address _treasury, address _roleRegistry) {
_disableInitializers();
liquidityPool = _liquidityPool;
treasury = _treasury;
roleRegistry = RoleRegistry(_roleRegistry);
}

receive() external payable {
emit EthReceived(msg.sender, msg.value);
}

function initialize() public initializer {
__Ownable_init();
__UUPSUpgradeable_init();
}

function withdrawToLiquidityPool() external {

uint256 balance = address(this).balance;
require(balance > 0, "Contract balance is zero");
(bool success, ) = liquidityPool.call{value: balance}("");
require(success, "TRANSFER_FAILED");

emit EthSent(address(this), liquidityPool, balance);
}

function recoverERC20(address _token, uint256 _amount) external {
if (!roleRegistry.hasRole(ETHERFI_ROUTER_ADMIN, msg.sender)) 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();

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

emit Erc721Sent(msg.sender, _token, _tokenId);
}

function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}

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

0 comments on commit aca4568

Please sign in to comment.