Skip to content

Commit

Permalink
flow rate initial port complete
Browse files Browse the repository at this point in the history
flow rate ported, intergration tests for rootBridge switched over to rootBridgeFlowRate. flowRate controls not yet in effect
  • Loading branch information
proletesseract committed Nov 8, 2023
1 parent c5bef71 commit d0326eb
Show file tree
Hide file tree
Showing 36 changed files with 11,513 additions and 453 deletions.
10,705 changes: 10,705 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/child/ChildAxelarBridgeAdaptor.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import {AxelarExecutable} from "@axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol";
import {IAxelarGasService} from "@axelar-cgp-solidity/contracts/interfaces/IAxelarGasService.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/child/ChildERC20.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache 2.0
// Adapted from OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "../lib/EIP712MetaTransaction.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/child/ChildERC20Bridge.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/child/WIMX.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import {IWIMX} from "../interfaces/child/IWIMX.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/child/IChildAxelarBridgeAdaptor.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

interface IChildAxelarBridgeAdaptorErrors {
/// @notice Error when a zero address is given when not valid.
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/child/IChildERC20.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache 2.0
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import {IERC20MetadataUpgradeable} from
"@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/child/IChildERC20Bridge.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/child/IChildERC20BridgeAdaptor.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

interface IChildERC20BridgeAdaptor {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/child/IWIMX.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/root/IRootAxelarBridgeAdaptor.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

interface IRootAxelarBridgeAdaptorErrors {
/// @notice Error when a zero address is given when not valid.
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/root/IRootERC20Bridge.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/root/IRootERC20BridgeAdaptor.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

// TODO: This is likely able to become a generic bridge adaptor, not just for ERC20 tokens.
interface IRootERC20BridgeAdaptor {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/root/IWETH.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/root/flowrate/IRootERC20BridgeFlowRate.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

interface IRootERC20BridgeFlowRate {

Expand Down
2 changes: 1 addition & 1 deletion src/lib/EIP712MetaTransaction.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import "./EIP712Upgradeable.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/lib/EIP712Upgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// slither-disable-start naming-convention
// Adapted from OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/EIP712.sol)

pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/root/RootAxelarBridgeAdaptor.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import {AxelarExecutable} from "@axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol";
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
Expand Down
12 changes: 6 additions & 6 deletions src/root/RootERC20Bridge.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
// import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import {IAxelarGateway} from "@axelar-cgp-solidity/contracts/interfaces/IAxelarGateway.sol";
import {IRootERC20Bridge, IERC20Metadata} from "../interfaces/root/IRootERC20Bridge.sol";
import {IRootERC20BridgeEvents, IRootERC20BridgeErrors} from "../interfaces/root/IRootERC20Bridge.sol";
Expand All @@ -25,8 +25,8 @@ import {IWETH} from "../interfaces/root/IWETH.sol";
*/

contract RootERC20Bridge is
Ownable2Step,
Initializable,
PausableUpgradeable,
IRootERC20Bridge,
IRootERC20BridgeEvents,
IRootERC20BridgeErrors
Expand Down Expand Up @@ -137,7 +137,7 @@ contract RootERC20Bridge is
* @param newRootBridgeAdaptor Address of new root bridge adaptor.
* @dev Can only be called by owner.
*/
function updateRootBridgeAdaptor(address newRootBridgeAdaptor) external onlyOwner {
function updateRootBridgeAdaptor(address newRootBridgeAdaptor) external { // @TODO needs access control
if (newRootBridgeAdaptor == address(0)) {
revert ZeroAddress();
}
Expand All @@ -153,7 +153,7 @@ contract RootERC20Bridge is
* @dev Can only be called by owner.
* @dev The limit can decrease, but it can never decrease to below the contract's IMX balance.
*/
function updateImxCumulativeDepositLimit(uint256 newImxCumulativeDepositLimit) external onlyOwner {
function updateImxCumulativeDepositLimit(uint256 newImxCumulativeDepositLimit) external { // @TODO needs access control
if (
newImxCumulativeDepositLimit != NO_DEPOSIT_LIMIT
&& newImxCumulativeDepositLimit < IERC20Metadata(rootIMXToken).balanceOf(address(this))
Expand Down
2 changes: 1 addition & 1 deletion src/root/flowrate/FlowRateDetection.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright Immutable Pty Ltd 2018 - 2023
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

/**
* @title Flow Rate Detection
Expand Down
2 changes: 1 addition & 1 deletion src/root/flowrate/FlowRateWithdrawalQueue.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright Immutable Pty Ltd 2018 - 2023
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

/**
* @title Flow Rate Withdrawal Queue
Expand Down
18 changes: 11 additions & 7 deletions src/root/flowrate/RootERC20BridgeFlowRate.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
Expand Down Expand Up @@ -34,7 +34,7 @@ contract RootERC20BridgeFlowRate is
address newRootIMXToken,
address newRootWETHToken,
string memory newChildChain,
address newImxCumulativeDepositLimit,
uint256 newImxCumulativeDepositLimit,
address rateAdmin
) external initializer {

Expand Down Expand Up @@ -153,14 +153,18 @@ contract RootERC20BridgeFlowRate is
* @dev Called by the ExitHelper.
* Only when not paused.
*/
function _withdraw(bytes calldata data) internal override {
function _withdraw(bytes memory data) internal override {
(address rootToken, address withdrawer, address receiver, uint256 amount) =
abi.decode(data, (address, address, address, uint256));
address childToken = rootTokenToChildToken[rootToken];
if (childToken == address(0)) {
revert NotMapped();
address childToken;
if (address(rootToken) == rootIMXToken) {
childToken = NATIVE_IMX;
} else {
childToken = rootTokenToChildToken[rootToken];
if (childToken == address(0)) {
revert NotMapped();
}
}

_executeTransfer(rootToken, childToken, withdrawer, receiver, amount);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/child/ChildERC20FailOnBurn.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache 2.0
// Adapted from OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import "../../child/ChildERC20.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/test/child/MockChildAxelarGasService.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

contract MockChildAxelarGasService {
function payNativeGasForContractCall(
Expand Down
2 changes: 1 addition & 1 deletion src/test/child/MockChildAxelarGateway.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

contract MockChildAxelarGateway {
function validateContractCall(bytes32, string calldata, string calldata, bytes32) external pure returns (bool) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/child/MockChildERC20Bridge.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

contract MockChildERC20Bridge {
function onMessageReceive(string calldata, string calldata, bytes calldata) external {}
Expand Down
2 changes: 1 addition & 1 deletion src/test/root/MockAdaptor.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

// @dev A contract for ensuring the Axelar Bridge Adaptor is called correctly during unit tests.
contract MockAdaptor {
Expand Down
2 changes: 1 addition & 1 deletion src/test/root/MockAxelarGasService.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

// @dev A contract for ensuring the Axelar gas service is called correctly during unit tests.
contract MockAxelarGasService {
Expand Down
2 changes: 1 addition & 1 deletion src/test/root/MockAxelarGateway.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

// @dev A contract for ensuring the Axelar Gateway is called correctly during unit tests.
contract MockAxelarGateway {
Expand Down
2 changes: 1 addition & 1 deletion src/test/root/StubRootBridge.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/test/root/WETH.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.21;
pragma solidity ^0.8.19;

import {IWETH} from "../../interfaces/root/IWETH.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
Expand Down
Loading

0 comments on commit d0326eb

Please sign in to comment.