Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
proletesseract committed Oct 24, 2023
1 parent 1d5fcac commit c597a9f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 40 deletions.
13 changes: 5 additions & 8 deletions src/child/ChildERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract ChildERC20Bridge is
address public constant NATIVE_ETH = address(0xeee);

IChildERC20BridgeAdaptor public bridgeAdaptor;

/// @dev The address that will be sending messages to, and receiving messages from, the child chain.
string public rootERC20BridgeAdaptor;
/// @dev The address of the token template that will be cloned to create tokens.
Expand All @@ -67,12 +67,9 @@ contract ChildERC20Bridge is
string memory newRootERC20BridgeAdaptor,
address newChildTokenTemplate,
string memory newRootChain,
address newRootIMXToken)
public initializer
{
if (newBridgeAdaptor == address(0)
|| newChildTokenTemplate == address(0)
|| newRootIMXToken == address(0)) {
address newRootIMXToken
) public initializer {
if (newBridgeAdaptor == address(0) || newChildTokenTemplate == address(0) || newRootIMXToken == address(0)) {
revert ZeroAddress();
}

Expand Down Expand Up @@ -175,7 +172,7 @@ contract ChildERC20Bridge is
revert NotMapped();
}
}

if (address(childToken).code.length == 0) {
revert EmptyTokenContract();
}
Expand Down
7 changes: 1 addition & 6 deletions src/interfaces/child/IChildERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ interface IChildERC20BridgeEvents {
address indexed receiver,
uint256 amount
);
event IMXDeposit(
address indexed rootToken,
address depositor,
address indexed receiver,
uint256 amount
);
event IMXDeposit(address indexed rootToken, address depositor, address indexed receiver, uint256 amount);
event NativeEthDeposit(
address indexed rootToken,
address indexed childToken,
Expand Down
7 changes: 1 addition & 6 deletions src/interfaces/root/IRootERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ interface IRootERC20BridgeEvents {
address indexed receiver,
uint256 amount
);
event IMXDeposit(
address indexed rootToken,
address depositor,
address indexed receiver,
uint256 amount
);
event IMXDeposit(address indexed rootToken, address depositor, address indexed receiver, uint256 amount);
event NativeEthDeposit(
address indexed rootToken,
address indexed childToken,
Expand Down
4 changes: 2 additions & 2 deletions src/root/RootERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ contract RootERC20Bridge is
}

uint256 expectedBalance = address(this).balance - (msg.value - amount);

_deposit(IERC20Metadata(NATIVE_ETH), receiver, amount);

// invariant check to ensure that the root native balance has increased by the amount deposited
Expand Down Expand Up @@ -190,7 +190,7 @@ contract RootERC20Bridge is
// TODO We can call _mapToken here, but ordering in the GMP is not guaranteed.
// Therefore, we need to decide how to handle this and it may be a UI decision to wait until map token message is executed on child chain.
// Discuss this, and add this decision to the design doc.
if (address(rootToken) != NATIVE_ETH) {
if (address(rootToken) != NATIVE_ETH) {
if (address(rootToken) != rootIMXToken) {
childToken = rootTokenToChildToken[address(rootToken)];
if (childToken == address(0)) {
Expand Down
6 changes: 5 additions & 1 deletion test/integration/child/ChildAxelarBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ contract ChildERC20BridgeIntegrationTest is Test, IChildERC20BridgeEvents, IChil
new ChildAxelarBridgeAdaptor(address(mockChildAxelarGateway), address(childERC20Bridge));

childERC20Bridge.initialize(
address(childAxelarBridgeAdaptor), ROOT_ADAPTOR_ADDRESS, address(childERC20), ROOT_CHAIN_NAME, IMX_TOKEN_ADDRESS
address(childAxelarBridgeAdaptor),
ROOT_ADAPTOR_ADDRESS,
address(childERC20),
ROOT_CHAIN_NAME,
IMX_TOKEN_ADDRESS
);
}

Expand Down
26 changes: 15 additions & 11 deletions test/unit/child/ChildERC20Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B

childTokenTemplate = new ChildERC20();
childTokenTemplate.initialize(address(123), "Test", "TST", 18);

childBridge = new ChildERC20Bridge();
childBridge.initialize(address(this), ROOT_BRIDGE_ADAPTOR, address(childTokenTemplate), ROOT_CHAIN_NAME, ROOT_IMX_TOKEN);
childBridge.initialize(
address(this), ROOT_BRIDGE_ADAPTOR, address(childTokenTemplate), ROOT_CHAIN_NAME, ROOT_IMX_TOKEN
);
}

function test_Initialize() public {
Expand All @@ -50,7 +52,9 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B

function test_RevertIfInitializeTwice() public {
vm.expectRevert("Initializable: contract is already initialized");
childBridge.initialize(address(this), ROOT_BRIDGE_ADAPTOR, address(childTokenTemplate), ROOT_CHAIN_NAME, ROOT_IMX_TOKEN);
childBridge.initialize(
address(this), ROOT_BRIDGE_ADAPTOR, address(childTokenTemplate), ROOT_CHAIN_NAME, ROOT_IMX_TOKEN
);
}

function test_RevertIf_InitializeWithAZeroAddressAdapter() public {
Expand Down Expand Up @@ -187,17 +191,13 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B
}

function test_RevertIf_mapTokenCalledWithIMXAddress() public {
bytes memory data = abi.encode(
childBridge.MAP_TOKEN_SIG(), ROOT_IMX_TOKEN, "ImmutableX", "IMX", 18
);
bytes memory data = abi.encode(childBridge.MAP_TOKEN_SIG(), ROOT_IMX_TOKEN, "ImmutableX", "IMX", 18);
vm.expectRevert(CantMapIMX.selector);
childBridge.onMessageReceive(ROOT_CHAIN_NAME, ROOT_BRIDGE_ADAPTOR, data);
}

function test_RevertIf_mapTokenCalledWithETHAddress() public {
bytes memory data = abi.encode(
childBridge.MAP_TOKEN_SIG(), NATIVE_ETH, "Ethereum", "ETH", 18
);
bytes memory data = abi.encode(childBridge.MAP_TOKEN_SIG(), NATIVE_ETH, "Ethereum", "ETH", 18);
vm.expectRevert(CantMapETH.selector);
childBridge.onMessageReceive(ROOT_CHAIN_NAME, ROOT_BRIDGE_ADAPTOR, data);
}
Expand Down Expand Up @@ -258,12 +258,16 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B
address predictedChildETHToken = Clones.predictDeterministicAddress(
address(childTokenTemplate), keccak256(abi.encodePacked(NATIVE_ETH)), address(childBridge)
);

uint256 receiverPreBal = ChildERC20(predictedChildETHToken).balanceOf(receiver);

childBridge.onMessageReceive(ROOT_CHAIN_NAME, ROOT_BRIDGE_ADAPTOR, depositData);

assertEq(ChildERC20(predictedChildETHToken).balanceOf(receiver), receiverPreBal + amount, "receiver balance not increased");
assertEq(
ChildERC20(predictedChildETHToken).balanceOf(receiver),
receiverPreBal + amount,
"receiver balance not increased"
);
}

function test_onMessageReceive_DepositETH_IncreasesTotalSupply() public {
Expand Down
19 changes: 13 additions & 6 deletions test/unit/root/RootERC20Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ contract RootERC20BridgeUnitTest is Test, IRootERC20BridgeEvents, IRootERC20Brid

function test_depositETHCallsSendMessage() public {
uint256 amount = 1000;
(, bytes memory predictedPayload) = setupDeposit(ERC20PresetMinterPauser(NATIVE_ETH), rootBridge, mapTokenFee, depositFee, amount, false);
(, bytes memory predictedPayload) =
setupDeposit(ERC20PresetMinterPauser(NATIVE_ETH), rootBridge, mapTokenFee, depositFee, amount, false);

vm.expectCall(
address(mockAxelarAdaptor),
Expand All @@ -226,7 +227,7 @@ contract RootERC20BridgeUnitTest is Test, IRootERC20BridgeEvents, IRootERC20Brid

vm.expectEmit();
emit NativeEthDeposit(NATIVE_ETH, CHILD_ETH_TOKEN, address(this), address(this), amount);
rootBridge.depositETH{value: amount+depositFee}(amount);
rootBridge.depositETH{value: amount + depositFee}(amount);
}

function test_RevertIf_depositETHInsufficientValue() public {
Expand All @@ -244,7 +245,9 @@ contract RootERC20BridgeUnitTest is Test, IRootERC20BridgeEvents, IRootERC20Brid
function test_depositToETHCallsSendMessage() public {
uint256 amount = 1000;
address receiver = address(12345);
(, bytes memory predictedPayload) = setupDepositTo(ERC20PresetMinterPauser(NATIVE_ETH), rootBridge, mapTokenFee, depositFee, amount, receiver, false);
(, bytes memory predictedPayload) = setupDepositTo(
ERC20PresetMinterPauser(NATIVE_ETH), rootBridge, mapTokenFee, depositFee, amount, receiver, false
);
vm.expectCall(
address(mockAxelarAdaptor),
depositFee,
Expand All @@ -257,17 +260,21 @@ contract RootERC20BridgeUnitTest is Test, IRootERC20BridgeEvents, IRootERC20Brid
function test_depositToETHEmitsNativeEthDepositEvent() public {
uint256 amount = 1000;
address receiver = address(12345);
setupDepositTo(ERC20PresetMinterPauser(NATIVE_ETH), rootBridge, mapTokenFee, depositFee, amount, receiver, false);
setupDepositTo(
ERC20PresetMinterPauser(NATIVE_ETH), rootBridge, mapTokenFee, depositFee, amount, receiver, false
);

vm.expectEmit();
emit NativeEthDeposit(NATIVE_ETH, CHILD_ETH_TOKEN, address(this), receiver, amount);
rootBridge.depositToETH{value: amount+depositFee}(receiver, amount);
rootBridge.depositToETH{value: amount + depositFee}(receiver, amount);
}

function test_RevertIf_depositToETHInsufficientValue() public {
uint256 amount = 1000;
address receiver = address(12345);
setupDepositTo(ERC20PresetMinterPauser(NATIVE_ETH), rootBridge, mapTokenFee, depositFee, amount, receiver, false);
setupDepositTo(
ERC20PresetMinterPauser(NATIVE_ETH), rootBridge, mapTokenFee, depositFee, amount, receiver, false
);

vm.expectRevert(InsufficientValue.selector);
rootBridge.depositToETH{value: (amount / 2) + depositFee}(receiver, amount);
Expand Down

0 comments on commit c597a9f

Please sign in to comment.