Skip to content

Commit

Permalink
chore: rename function names and update permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
blockgroot committed Jul 9, 2024
1 parent 04c0697 commit 7a5d7ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
17 changes: 9 additions & 8 deletions contracts/L2/ETHxPoolV5.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ contract ETHxPoolV5 is AccessControlUpgradeable, ReentrancyGuardUpgradeable {

/// @notice Role hash of BRIDGER
bytes32 public constant BRIDGER_ROLE = keccak256("BRIDGER_ROLE");
/// @notice Base rate of ETHx/ETH
uint256 public constant ETHX_BASE_RATE = 1e18;
/// @notice Conversion factor from ether to wei
uint256 public constant ETHER_TO_WEI = 1e18;
/// @notice Address of ETHx token
IERC20 public ETHx;
/// @notice Basis points for fees
Expand All @@ -39,7 +39,7 @@ contract ETHxPoolV5 is AccessControlUpgradeable, ReentrancyGuardUpgradeable {
/// @notice Emitted when accumulated fees is withdrawn
event FeesWithdrawn(uint256 feeEarnedInETH);
/// @notice Emitted when deposited ETH is withdrawn
event AssetsMovedForBridging(uint256 ethBalanceMinusFees);
event WithdrawCollectedETH(uint256 ethBalanceMinusFees);
/// @notice Emitted when basis fee is updated
event FeeBpsSet(uint256 feeBps);
/// @notice Emitted when oracle address is updated
Expand Down Expand Up @@ -83,6 +83,7 @@ contract ETHxPoolV5 is AccessControlUpgradeable, ReentrancyGuardUpgradeable {

_grantRole(DEFAULT_ADMIN_ROLE, _admin);
_setupRole(BRIDGER_ROLE, _bridger);
_setupRole(BRIDGER_ROLE, _admin);

ETHx = IERC20(_ethx);
feeBps = _feeBps;
Expand All @@ -91,7 +92,7 @@ contract ETHxPoolV5 is AccessControlUpgradeable, ReentrancyGuardUpgradeable {

/// @dev Swaps ETH for ETHx
/// @param _referralId The referral id
function deposit(string memory _referralId) external payable nonReentrant {
function swapETHToETHx(string memory _referralId) external payable nonReentrant {
uint256 amount = msg.value;

if (amount == 0) revert InvalidAmount();
Expand All @@ -116,7 +117,7 @@ contract ETHxPoolV5 is AccessControlUpgradeable, ReentrancyGuardUpgradeable {
(, int256 ethxToEthRate,,,) = AggregatorV3Interface(ethxOracle).latestRoundData();

// Calculate the final ETHx amount
ethxAmount = amountAfterFee * ETHX_BASE_RATE / uint256(ethxToEthRate);
ethxAmount = amountAfterFee * ETHER_TO_WEI / uint256(ethxToEthRate);
}

/*//////////////////////////////////////////////////////////////
Expand All @@ -134,15 +135,15 @@ contract ETHxPoolV5 is AccessControlUpgradeable, ReentrancyGuardUpgradeable {
emit FeesWithdrawn(amountToSendInETH);
}

/// @dev Withdraws assets from the contract for bridging
function moveAssetsForBridging() external onlyRole(BRIDGER_ROLE) {
/// @dev Withdraws collected ETH from the contract
function withdrawCollectedETH() external onlyRole(BRIDGER_ROLE) {
// withdraw ETH - fees
uint256 ethBalanceMinusFees = address(this).balance - feeEarnedInETH;

(bool success,) = msg.sender.call{ value: ethBalanceMinusFees }("");
if (!success) revert TransferFailed();

emit AssetsMovedForBridging(ethBalanceMinusFees);
emit WithdrawCollectedETH(ethBalanceMinusFees);
}

/// @dev Sets the fee basis points
Expand Down
10 changes: 5 additions & 5 deletions test/L2/ETHxPoolV5.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ contract ETHxPoolV5Test is Test {
function testDepositRequiresNonZeroAmount() public {
vm.prank(admin);
vm.expectRevert(ETHxPoolV5.InvalidAmount.selector);
eTHxPoolV5.deposit{ value: 0 }("referral");
eTHxPoolV5.swapETHToETHx{ value: 0 }("referral");
}

function testSwapETHForETHx(uint256 ethAmount) public {
Expand All @@ -109,7 +109,7 @@ contract ETHxPoolV5Test is Test {
vm.prank(admin);
ERC20Mock(ETHx).mint(address(eTHxPoolV5), ethAmount);
vm.prank(user);
eTHxPoolV5.deposit{ value: ethAmount }("referral");
eTHxPoolV5.swapETHToETHx{ value: ethAmount }("referral");
uint256 expectedBalance = ethAmount - (ethAmount * FEE_BPS / 10_000);
assertEq(ERC20Mock(ETHx).balanceOf(user), expectedBalance);
(uint256 _amtLessFee,) = eTHxPoolV5.viewSwapETHxAmountAndFee(ethAmount);
Expand All @@ -133,7 +133,7 @@ contract ETHxPoolV5Test is Test {
ERC20Mock(ETHx).mint(address(eTHxPoolV5), ethAmount);
vm.deal(user, ethAmount);
vm.prank(user);
eTHxPoolV5.deposit{ value: ethAmount }("referral");
eTHxPoolV5.swapETHToETHx{ value: ethAmount }("referral");
uint256 expectedBalance = ethAmount - (ethAmount * FEE_BPS / 10_000);
assertEq(ERC20Mock(ETHx).balanceOf(user), expectedBalance);
(, uint256 feeAmnt) = eTHxPoolV5.viewSwapETHxAmountAndFee(ethAmount);
Expand All @@ -157,10 +157,10 @@ contract ETHxPoolV5Test is Test {
vm.deal(user, ethAmount);
ERC20Mock(ETHx).mint(address(eTHxPoolV5), ethAmount);
vm.prank(user);
eTHxPoolV5.deposit{ value: ethAmount }("referral");
eTHxPoolV5.swapETHToETHx{ value: ethAmount }("referral");
uint256 feeEarned = eTHxPoolV5.feeEarnedInETH();
vm.prank(bridger);
eTHxPoolV5.moveAssetsForBridging();
eTHxPoolV5.withdrawCollectedETH();
assertEq(bridger.balance, ethAmount - feeEarned);
}

Expand Down

0 comments on commit 7a5d7ef

Please sign in to comment.