From c597a9f758e086eb0bf7fb176429e1aef537e3db Mon Sep 17 00:00:00 2001 From: Craig M Date: Tue, 24 Oct 2023 14:55:01 +1300 Subject: [PATCH] formatting --- src/child/ChildERC20Bridge.sol | 13 ++++------ src/interfaces/child/IChildERC20Bridge.sol | 7 +---- src/interfaces/root/IRootERC20Bridge.sol | 7 +---- src/root/RootERC20Bridge.sol | 4 +-- .../integration/child/ChildAxelarBridge.t.sol | 6 ++++- test/unit/child/ChildERC20Bridge.t.sol | 26 +++++++++++-------- test/unit/root/RootERC20Bridge.t.sol | 19 +++++++++----- 7 files changed, 42 insertions(+), 40 deletions(-) diff --git a/src/child/ChildERC20Bridge.sol b/src/child/ChildERC20Bridge.sol index 251d4005..41b096e8 100644 --- a/src/child/ChildERC20Bridge.sol +++ b/src/child/ChildERC20Bridge.sol @@ -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. @@ -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(); } @@ -175,7 +172,7 @@ contract ChildERC20Bridge is revert NotMapped(); } } - + if (address(childToken).code.length == 0) { revert EmptyTokenContract(); } diff --git a/src/interfaces/child/IChildERC20Bridge.sol b/src/interfaces/child/IChildERC20Bridge.sol index 94945b5b..90bffc19 100644 --- a/src/interfaces/child/IChildERC20Bridge.sol +++ b/src/interfaces/child/IChildERC20Bridge.sol @@ -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, diff --git a/src/interfaces/root/IRootERC20Bridge.sol b/src/interfaces/root/IRootERC20Bridge.sol index 1c104563..6e09c715 100644 --- a/src/interfaces/root/IRootERC20Bridge.sol +++ b/src/interfaces/root/IRootERC20Bridge.sol @@ -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, diff --git a/src/root/RootERC20Bridge.sol b/src/root/RootERC20Bridge.sol index ec58af89..71789528 100644 --- a/src/root/RootERC20Bridge.sol +++ b/src/root/RootERC20Bridge.sol @@ -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 @@ -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)) { diff --git a/test/integration/child/ChildAxelarBridge.t.sol b/test/integration/child/ChildAxelarBridge.t.sol index 01144366..d5c660b7 100644 --- a/test/integration/child/ChildAxelarBridge.t.sol +++ b/test/integration/child/ChildAxelarBridge.t.sol @@ -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 ); } diff --git a/test/unit/child/ChildERC20Bridge.t.sol b/test/unit/child/ChildERC20Bridge.t.sol index d1b37edb..f8fb5505 100644 --- a/test/unit/child/ChildERC20Bridge.t.sol +++ b/test/unit/child/ChildERC20Bridge.t.sol @@ -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 { @@ -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 { @@ -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); } @@ -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 { diff --git a/test/unit/root/RootERC20Bridge.t.sol b/test/unit/root/RootERC20Bridge.t.sol index 0ca62f8f..4dd5abdf 100644 --- a/test/unit/root/RootERC20Bridge.t.sol +++ b/test/unit/root/RootERC20Bridge.t.sol @@ -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), @@ -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 { @@ -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, @@ -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);