Skip to content

Commit

Permalink
Fix linting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ermyas committed Nov 13, 2023
1 parent 43f8499 commit 1cc475d
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 72 deletions.
14 changes: 4 additions & 10 deletions src/interfaces/root/flowrate/IRootERC20BridgeFlowRate.sol
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
);

/**
Expand All @@ -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);
}

16 changes: 8 additions & 8 deletions src/root/RootERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
24 changes: 11 additions & 13 deletions src/root/flowrate/FlowRateWithdrawalQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
69 changes: 39 additions & 30 deletions src/root/flowrate/RootERC20BridgeFlowRate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ 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,
FlowRateWithdrawalQueue,
IRootERC20BridgeFlowRateEvents,
IRootERC20BridgeFlowRateErrors
{

// Constants used for access control
bytes32 private constant RATE_CONTROL_ROLE = keccak256("RATE");

Expand All @@ -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
);

Expand All @@ -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();
}

Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
Expand All @@ -242,5 +252,4 @@ contract RootERC20BridgeFlowRate is

// slither-disable-next-line unused-state,naming-convention
uint256[50] private __gapRootERC20PredicateFlowRate;

}
}
16 changes: 12 additions & 4 deletions test/integration/root/RootERC20Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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,
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -61,8 +60,7 @@ contract RootERC20BridgeWithdrawIntegrationTest is
UNLIMITED_DEPOSIT_LIMIT
);

console2.log('after rootIntegrationSetup');

console2.log("after rootIntegrationSetup");

imxToken = integration.imxToken;
token = integration.token;
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion test/utils.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 1cc475d

Please sign in to comment.