Skip to content

Commit

Permalink
fix PR comments and add natspec for events and add eth withdraw event
Browse files Browse the repository at this point in the history
  • Loading branch information
tsnewnami committed Nov 15, 2023
1 parent 8de8c5d commit 96146d9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
13 changes: 12 additions & 1 deletion src/interfaces/root/IRootERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,40 @@ interface IRootERC20BridgeEvents {
address indexed receiver,
uint256 amount
);
/// @notice Emitted when an IMX deposit is initated on the root chain.
event IMXDeposit(address indexed rootToken, address depositor, address indexed receiver, uint256 amount);
/// @notice Emitted when a WETH deposit is initiated on the root chain.
event WETHDeposit(
address indexed rootToken,
address indexed childToken,
address depositor,
address indexed receiver,
uint256 amount
);
/// @notice Emitted when an ETH deposit initiated on the root chain.
event NativeEthDeposit(
address indexed rootToken,
address indexed childToken,
address depositor,
address indexed receiver,
uint256 amount
);

/// @notice Emitted when an ERC20 withdrawal is executed on the root chain.
event RootChainERC20Withdraw(
address indexed rootToken,
address indexed childToken,
address withdrawer,
address indexed receiver,
uint256 amount
);
/// @notice Emitted when an ETH withdrawal is executed on the root chain.
event RootChainETHWithdraw(
address indexed rootToken,
address indexed childToken,
address withdrawer,
address indexed receiver,
uint256 amount
);
}

interface IRootERC20BridgeErrors {
Expand Down
3 changes: 2 additions & 1 deletion src/root/RootERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,11 @@ contract RootERC20Bridge is
// Tests for this NATIVE_ETH branch not yet written. This should come as part of that PR.
if (rootToken == NATIVE_ETH) {
Address.sendValue(payable(receiver), amount);
emit RootChainETHWithdraw(NATIVE_ETH, childToken, withdrawer, receiver, amount);
} else {
IERC20Metadata(rootToken).safeTransfer(receiver, amount);
emit RootChainERC20Withdraw(rootToken, childToken, withdrawer, receiver, amount);
}
// slither-disable-next-line reentrancy-events
emit RootChainERC20Withdraw(rootToken, childToken, withdrawer, receiver, amount);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.19;
pragma solidity 0.8.19;

import {Test, console2} from "forge-std/Test.sol";
import {ERC20PresetMinterPauser} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";
Expand Down Expand Up @@ -30,7 +30,6 @@ contract ChildERC20BridgeWithdrawETHIntegrationTest is

ChildERC20Bridge public childBridge;
ChildAxelarBridgeAdaptor public axelarAdaptor;
ChildERC20 public childTokenTemplate;
MockAxelarGasService public mockAxelarGasService;
MockAxelarGateway public mockAxelarGateway;
ChildERC20 public childETHToken;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.19;
pragma solidity 0.8.19;

import {Test, console2} from "forge-std/Test.sol";
import {ERC20PresetMinterPauser} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ contract RootERC20BridgeWithdrawIntegrationTest is
axelarAdaptor.execute(commandId, CHILD_CHAIN_NAME, sourceAddress, data);
}

function test_withdrawETH_EmitsRootChainERC20WithdrawEvent() public {
function test_withdrawETH_EmitsRootChainETHWithdrawEvent() public {
bytes memory data = abi.encode(WITHDRAW_SIG, NATIVE_ETH, address(this), address(this), withdrawAmount);

bytes32 commandId = bytes32("testCommandId");
string memory sourceAddress = rootBridge.childBridgeAdaptor();

vm.expectEmit();
emit RootChainERC20Withdraw(
emit RootChainETHWithdraw(
NATIVE_ETH, address(rootBridge.childETHToken()), address(this), address(this), withdrawAmount
);
axelarAdaptor.execute(commandId, CHILD_CHAIN_NAME, sourceAddress, data);
Expand Down Expand Up @@ -293,15 +293,15 @@ contract RootERC20BridgeWithdrawIntegrationTest is
axelarAdaptor.execute(commandId, CHILD_CHAIN_NAME, sourceAddress, data);
}

function test_withdrawETH_EmitsRootChainERC20WithdrawEvent_DifferentReceiver() public {
function test_withdrawETH_EmitsRootChainETHWithdrawEvent_DifferentReceiver() public {
address receiver = address(987654321);
bytes memory data = abi.encode(WITHDRAW_SIG, NATIVE_ETH, address(this), receiver, withdrawAmount);

bytes32 commandId = bytes32("testCommandId");
string memory sourceAddress = rootBridge.childBridgeAdaptor();

vm.expectEmit();
emit RootChainERC20Withdraw(
emit RootChainETHWithdraw(
NATIVE_ETH, address(rootBridge.childETHToken()), address(this), receiver, withdrawAmount
);
axelarAdaptor.execute(commandId, CHILD_CHAIN_NAME, sourceAddress, data);
Expand Down
8 changes: 4 additions & 4 deletions test/unit/root/withdrawals/RootERC20BridgeWithdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ contract RootERC20BridgeWithdrawUnitTest is Test, IRootERC20BridgeEvents, IRootE
rootBridge.onMessageReceive(CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, data);
}

function test_onMessageReceive_EmitsRootChainERC20WithdrawEventForETH() public {
function test_onMessageReceive_EmitsRootChainETHWithdrawEventForETH() public {
// Give bridge some ETH
deal(address(rootBridge), 100 ether);

bytes memory data = abi.encode(WITHDRAW_SIG, NATIVE_ETH, address(this), address(this), withdrawAmount);
vm.expectEmit();
emit RootChainERC20Withdraw(
emit RootChainETHWithdraw(
NATIVE_ETH, address(rootBridge.childETHToken()), address(this), address(this), withdrawAmount
);
vm.prank(address(mockAxelarAdaptor));
Expand Down Expand Up @@ -302,14 +302,14 @@ contract RootERC20BridgeWithdrawUnitTest is Test, IRootERC20BridgeEvents, IRootE
rootBridge.onMessageReceive(CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, data);
}

function test_onMessageReceive_EmitsRootChainERC20WithdrawEventForETH_DifferentReceiver() public {
function test_onMessageReceive_EmitsRootChainETHWithdrawEventForETH_DifferentReceiver() public {
address receiver = address(123456);
// Give bridge some ETH
deal(address(rootBridge), 100 ether);

bytes memory data = abi.encode(WITHDRAW_SIG, NATIVE_ETH, address(this), receiver, withdrawAmount);
vm.expectEmit();
emit RootChainERC20Withdraw(
emit RootChainETHWithdraw(
NATIVE_ETH, address(rootBridge.childETHToken()), address(this), receiver, withdrawAmount
);
vm.prank(address(mockAxelarAdaptor));
Expand Down

0 comments on commit 96146d9

Please sign in to comment.