From 1cc475d842edd9330a4832dd98b6dad93848e817 Mon Sep 17 00:00:00 2001 From: Ermyas Abebe Date: Tue, 14 Nov 2023 10:37:52 +1100 Subject: [PATCH] Fix linting issue --- .../flowrate/IRootERC20BridgeFlowRate.sol | 14 ++-- src/root/RootERC20Bridge.sol | 16 ++--- src/root/flowrate/FlowRateWithdrawalQueue.sol | 24 +++---- src/root/flowrate/RootERC20BridgeFlowRate.sol | 69 +++++++++++-------- test/integration/root/RootERC20Bridge.t.sol | 16 +++-- .../RootERC20BridgeWithdraw.t.sol | 13 ++-- test/utils.t.sol | 1 - 7 files changed, 81 insertions(+), 72 deletions(-) diff --git a/src/interfaces/root/flowrate/IRootERC20BridgeFlowRate.sol b/src/interfaces/root/flowrate/IRootERC20BridgeFlowRate.sol index 6978fc82..3ab76cb8 100644 --- a/src/interfaces/root/flowrate/IRootERC20BridgeFlowRate.sol +++ b/src/interfaces/root/flowrate/IRootERC20BridgeFlowRate.sol @@ -1,12 +1,10 @@ // SPDX-License-Identifier: Apache 2.0 pragma solidity ^0.8.19; -interface IRootERC20BridgeFlowRate { - -} +interface IRootERC20BridgeFlowRate {} interface IRootERC20BridgeFlowRateEvents { - /** + /** * @notice Indicates rate control thresholds have been set for a certain token. * @param token The token thresholds applied to. * @param capacity The size of the bucket in tokens. @@ -15,10 +13,7 @@ interface IRootERC20BridgeFlowRateEvents { * and will be put in the withdrawal queue. */ event RateControlThresholdSet( - address indexed token, - uint256 capacity, - uint256 refillRate, - uint256 largeTransferThreshold + address indexed token, uint256 capacity, uint256 refillRate, uint256 largeTransferThreshold ); /** @@ -44,11 +39,10 @@ interface IRootERC20BridgeFlowRateEvents { } interface IRootERC20BridgeFlowRateErrors { - // Error if the RootERC20Predicate initializer is called, and not the one for this contract. + // Error if the RootERC20Predicate initializer is called, and not the one for this contract. error WrongInitializer(); // finaliseQueuedWithdrawalsAggregated was called with a zero length indices array. error ProvideAtLeastOneIndex(); // The expected and actual token did not match for an aggregated withdrawal. error MixedTokens(address token, address actualToken); } - diff --git a/src/root/RootERC20Bridge.sol b/src/root/RootERC20Bridge.sol index f4e65cf7..f5d58f7a 100644 --- a/src/root/RootERC20Bridge.sol +++ b/src/root/RootERC20Bridge.sol @@ -84,15 +84,15 @@ contract RootERC20Bridge is string memory newChildChain, uint256 newImxCumulativeDepositLimit ) external virtual initializer { - __RootERC20Bridge_init( + __RootERC20Bridge_init( newRoles, - newRootBridgeAdaptor, - newChildERC20Bridge, - newChildBridgeAdaptor, - newChildTokenTemplate, - newRootIMXToken, - newRootWETHToken, - newChildChain, + newRootBridgeAdaptor, + newChildERC20Bridge, + newChildBridgeAdaptor, + newChildTokenTemplate, + newRootIMXToken, + newRootWETHToken, + newChildChain, newImxCumulativeDepositLimit ); } diff --git a/src/root/flowrate/FlowRateWithdrawalQueue.sol b/src/root/flowrate/FlowRateWithdrawalQueue.sol index 8f43b01d..51e8f2cf 100644 --- a/src/root/flowrate/FlowRateWithdrawalQueue.sol +++ b/src/root/flowrate/FlowRateWithdrawalQueue.sol @@ -32,6 +32,7 @@ abstract contract FlowRateWithdrawalQueue { uint256 timestamp; } // Mapping of user addresses to withdrawal queue. + mapping(address => PendingWithdrawal[]) private pendingWithdrawals; // Information found in a search. @@ -61,11 +62,7 @@ abstract contract FlowRateWithdrawalQueue { // Indicates a withdrawal has been processed. event ProcessedWithdrawal( - address indexed token, - address indexed withdrawer, - address indexed receiver, - uint256 amount, - uint256 index + address indexed token, address indexed withdrawer, address indexed receiver, uint256 amount, uint256 index ); // Indicates that the new withdrawal delay. @@ -128,10 +125,10 @@ abstract contract FlowRateWithdrawalQueue { * @return token The token to transfer to the receiver. * @return amount The number of tokens to transfer to the receiver. */ - function _processWithdrawal( - address receiver, - uint256 index - ) internal returns (address withdrawer, address token, uint256 amount) { + function _processWithdrawal(address receiver, uint256 index) + internal + returns (address withdrawer, address token, uint256 amount) + { PendingWithdrawal[] storage withdrawals = pendingWithdrawals[receiver]; // Check if the request is beyond the end of the array. uint256 length = pendingWithdrawals[receiver].length; @@ -178,10 +175,11 @@ abstract contract FlowRateWithdrawalQueue { * @param indices Offsets into withdrawal queue to fetch information for. * @return pending Array of pending withdrawals. Zero fill are returned if the index is beyond the end of the queue. */ - function getPendingWithdrawals( - address receiver, - uint256[] calldata indices - ) external view returns (PendingWithdrawal[] memory pending) { + function getPendingWithdrawals(address receiver, uint256[] calldata indices) + external + view + returns (PendingWithdrawal[] memory pending) + { PendingWithdrawal[] storage withdrawals = pendingWithdrawals[receiver]; uint256 withdrawalsLength = withdrawals.length; pending = new PendingWithdrawal[](indices.length); diff --git a/src/root/flowrate/RootERC20BridgeFlowRate.sol b/src/root/flowrate/RootERC20BridgeFlowRate.sol index 63b9aca7..144ece00 100644 --- a/src/root/flowrate/RootERC20BridgeFlowRate.sol +++ b/src/root/flowrate/RootERC20BridgeFlowRate.sol @@ -7,9 +7,12 @@ import "./FlowRateDetection.sol"; import "./FlowRateWithdrawalQueue.sol"; import "../RootERC20Bridge.sol"; -import {IRootERC20BridgeFlowRateEvents, IRootERC20BridgeFlowRateErrors} from "../../interfaces/root/flowrate/IRootERC20BridgeFlowRate.sol"; +import { + IRootERC20BridgeFlowRateEvents, + IRootERC20BridgeFlowRateErrors +} from "../../interfaces/root/flowrate/IRootERC20BridgeFlowRate.sol"; -contract RootERC20BridgeFlowRate is +contract RootERC20BridgeFlowRate is RootERC20Bridge, ReentrancyGuardUpgradeable, FlowRateDetection, @@ -17,7 +20,6 @@ contract RootERC20BridgeFlowRate is IRootERC20BridgeFlowRateEvents, IRootERC20BridgeFlowRateErrors { - // Constants used for access control bytes32 private constant RATE_CONTROL_ROLE = keccak256("RATE"); @@ -27,26 +29,25 @@ contract RootERC20BridgeFlowRate is function initialize( InitializationRoles memory newRoles, - address newRootBridgeAdaptor, - address newChildERC20Bridge, - string memory newChildBridgeAdaptor, - address newChildTokenTemplate, - address newRootIMXToken, - address newRootWETHToken, - string memory newChildChain, + address newRootBridgeAdaptor, + address newChildERC20Bridge, + string memory newChildBridgeAdaptor, + address newChildTokenTemplate, + address newRootIMXToken, + address newRootWETHToken, + string memory newChildChain, uint256 newImxCumulativeDepositLimit, address rateAdmin - ) external initializer { - + ) external initializer { __RootERC20Bridge_init( newRoles, - newRootBridgeAdaptor, - newChildERC20Bridge, - newChildBridgeAdaptor, - newChildTokenTemplate, - newRootIMXToken, - newRootWETHToken, - newChildChain, + newRootBridgeAdaptor, + newChildERC20Bridge, + newChildBridgeAdaptor, + newChildTokenTemplate, + newRootIMXToken, + newRootWETHToken, + newChildChain, newImxCumulativeDepositLimit ); @@ -55,8 +56,18 @@ contract RootERC20BridgeFlowRate is _grantRole(RATE_CONTROL_ROLE, rateAdmin); } - // Ensure initialize from RootERC20Predicate can not be called. - function initialize(InitializationRoles memory, address, address, string memory, address, address, address, string memory, uint256) external pure override { + // Ensure initialize from RootERC20Predicate can not be called. + function initialize( + InitializationRoles memory, + address, + address, + string memory, + address, + address, + address, + string memory, + uint256 + ) external pure override { revert WrongInitializer(); } @@ -80,7 +91,7 @@ contract RootERC20BridgeFlowRate is _deactivateWithdrawalQueue(); } - /** + /** * @notice Set the time in the queue for queued withdrawals. * @param delay The number of seconds between when the ExitHelper is called to * complete a crosschain transfer and when finaliseHeldTransfers can be @@ -144,7 +155,7 @@ contract RootERC20BridgeFlowRate is emit RateControlThresholdSet(token, capacity, refillRate, largeTransferThreshold); } - /** + /** * @notice Complete crosschain transfer of funds. * @param data Contains the crosschain transfer information: * - token: Token address on the root chain. @@ -217,11 +228,10 @@ contract RootERC20BridgeFlowRate is * Note that withdrawer in the ERC20Withdraw event emitted in the _executeTransfer function * will represent the withdrawer of the last bridge transfer. */ - function finaliseQueuedWithdrawalsAggregated( - address receiver, - address token, - uint256[] calldata indices - ) external nonReentrant { + function finaliseQueuedWithdrawalsAggregated(address receiver, address token, uint256[] calldata indices) + external + nonReentrant + { if (indices.length == 0) { revert ProvideAtLeastOneIndex(); } @@ -242,5 +252,4 @@ contract RootERC20BridgeFlowRate is // slither-disable-next-line unused-state,naming-convention uint256[50] private __gapRootERC20PredicateFlowRate; - -} \ No newline at end of file +} diff --git a/test/integration/root/RootERC20Bridge.t.sol b/test/integration/root/RootERC20Bridge.t.sol index decaef92..cd35875a 100644 --- a/test/integration/root/RootERC20Bridge.t.sol +++ b/test/integration/root/RootERC20Bridge.t.sol @@ -224,7 +224,9 @@ contract RootERC20BridgeIntegrationTest is Test, IRootERC20BridgeEvents, IRootAx // Check that tokens are transferred assertEq(thisPreBal - tokenAmount, imxToken.balanceOf(address(this)), "Tokens not transferred from user"); assertEq( - bridgePreBal + tokenAmount, imxToken.balanceOf(address(rootBridgeFlowRate)), "Tokens not transferred to bridge" + bridgePreBal + tokenAmount, + imxToken.balanceOf(address(rootBridgeFlowRate)), + "Tokens not transferred to bridge" ); // Check that native asset transferred to gas service assertEq(thisNativePreBal - depositFee, address(this).balance, "ETH not paid from user"); @@ -241,7 +243,9 @@ contract RootERC20BridgeIntegrationTest is Test, IRootERC20BridgeEvents, IRootAx vm.expectEmit(address(axelarAdaptor)); emit AxelarMessageSent(CHILD_CHAIN_NAME, childBridgeAdaptorString, predictedPayload); vm.expectEmit(address(rootBridgeFlowRate)); - emit WETHDeposit(address(WRAPPED_ETH), rootBridgeFlowRate.childETHToken(), address(this), address(this), tokenAmount); + emit WETHDeposit( + address(WRAPPED_ETH), rootBridgeFlowRate.childETHToken(), address(this), address(this), tokenAmount + ); vm.expectCall( address(axelarAdaptor), depositFee, @@ -338,7 +342,9 @@ contract RootERC20BridgeIntegrationTest is Test, IRootERC20BridgeEvents, IRootAx // Check that tokens are transferred assertEq(thisPreBal - tokenAmount, token.balanceOf(address(this)), "Tokens not transferred from user"); - assertEq(bridgePreBal + tokenAmount, token.balanceOf(address(rootBridgeFlowRate)), "Tokens not transferred to bridge"); + assertEq( + bridgePreBal + tokenAmount, token.balanceOf(address(rootBridgeFlowRate)), "Tokens not transferred to bridge" + ); // Check that native asset transferred to gas service assertEq(thisNativePreBal - depositFee, address(this).balance, "ETH not paid from user"); assertEq(gasServiceNativePreBal + depositFee, address(axelarGasService).balance, "ETH not paid to adaptor"); @@ -394,7 +400,9 @@ contract RootERC20BridgeIntegrationTest is Test, IRootERC20BridgeEvents, IRootAx // Check that tokens are transferred assertEq(thisPreBal - tokenAmount, token.balanceOf(address(this)), "Tokens not transferred from user"); - assertEq(bridgePreBal + tokenAmount, token.balanceOf(address(rootBridgeFlowRate)), "Tokens not transferred to bridge"); + assertEq( + bridgePreBal + tokenAmount, token.balanceOf(address(rootBridgeFlowRate)), "Tokens not transferred to bridge" + ); // Check that native asset transferred to gas service assertEq(thisNativePreBal - depositFee, address(this).balance, "ETH not paid from user"); assertEq(gasServiceNativePreBal + depositFee, address(axelarGasService).balance, "ETH not paid to adaptor"); diff --git a/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol b/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol index b50c6522..5283872a 100644 --- a/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol +++ b/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol @@ -47,9 +47,8 @@ contract RootERC20BridgeWithdrawIntegrationTest is RootERC20BridgeFlowRate public rootBridgeFlowRate; function setUp() public { + console2.log("root withdraw setUp"); - console2.log('root withdraw setUp'); - deployCodeTo("WETH.sol", abi.encode("Wrapped ETH", "WETH"), WRAPPED_ETH); RootIntegration memory integration = rootIntegrationSetup( @@ -61,8 +60,7 @@ contract RootERC20BridgeWithdrawIntegrationTest is UNLIMITED_DEPOSIT_LIMIT ); - console2.log('after rootIntegrationSetup'); - + console2.log("after rootIntegrationSetup"); imxToken = integration.imxToken; token = integration.token; @@ -79,7 +77,6 @@ contract RootERC20BridgeWithdrawIntegrationTest is // And give the bridge some tokens token.transfer(address(rootBridgeFlowRate), 100 ether); imxToken.transfer(address(rootBridgeFlowRate), 100 ether); - } function test_RevertsIf_WithdrawWithInvalidSourceChain() public { @@ -235,7 +232,11 @@ contract RootERC20BridgeWithdrawIntegrationTest is vm.expectEmit(); emit RootChainERC20Withdraw( - address(token), rootBridgeFlowRate.rootTokenToChildToken(address(token)), address(this), receiver, withdrawAmount + address(token), + rootBridgeFlowRate.rootTokenToChildToken(address(token)), + address(this), + receiver, + withdrawAmount ); axelarAdaptor.execute(commandId, CHILD_CHAIN_NAME, sourceAddress, data); } diff --git a/test/utils.t.sol b/test/utils.t.sol index 9d0b1710..2bb8adeb 100644 --- a/test/utils.t.sol +++ b/test/utils.t.sol @@ -82,7 +82,6 @@ contract Utils is Test { address wethTokenAddress, uint256 imxCumulativeDepositLimit ) public returns (RootIntegration memory integrationTest) { - integrationTest.token = new ERC20PresetMinterPauser("Test", "TST"); integrationTest.token.mint(address(this), 1000000 ether);