From 78de7dd15c341ae133bb4ac7e697b4540ab06e1f Mon Sep 17 00:00:00 2001 From: mpetrun5 <matija.petrunic@gmail.com> Date: Mon, 18 Mar 2024 17:51:55 +0100 Subject: [PATCH 1/7] Fix missing custom errors --- src/contracts/handlers/ERCHandlerHelpers.sol | 29 +++++++++++--------- src/contracts/libraries/MerkleTrie.sol | 3 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/contracts/handlers/ERCHandlerHelpers.sol b/src/contracts/handlers/ERCHandlerHelpers.sol index def207e6..811fa963 100755 --- a/src/contracts/handlers/ERCHandlerHelpers.sol +++ b/src/contracts/handlers/ERCHandlerHelpers.sol @@ -28,9 +28,11 @@ abstract contract ERCHandlerHelpers is IERCHandler { Decimals decimals; } + error SenderNotBridgeContract(); + error SenderNotExecutorContract(); + error SenderNotRouterContract(); error ContractAddressNotWhitelisted(address contractAddress); error DepositAmountTooSmall(uint256 depositAmount); - error SenderNotBridgeRouterOrExecutor(); // resourceID => token contract address mapping(bytes32 => address) public _resourceIDToTokenContractAddress; @@ -53,6 +55,19 @@ abstract contract ERCHandlerHelpers is IERCHandler { _; } + function _onlyBridge() private view { + if (msg.sender != _bridgeAddress) revert SenderNotBridgeContract(); + } + + function _onlyExecutor() private view { + if (msg.sender != _executorAddress) revert SenderNotExecutorContract(); + } + + function _onlyRouter() private view { + if (msg.sender != _routerAddress) revert SenderNotRouterContract(); + } + + /** @param bridgeAddress Contract address of previously deployed Bridge. @param routerAddress Contract address of previously deployed Router. @@ -64,18 +79,6 @@ abstract contract ERCHandlerHelpers is IERCHandler { _executorAddress = executorAddress; } - function _onlyBridge() private view { - require(msg.sender == _bridgeAddress, "sender must be bridge contract"); - } - - function _onlyRouter() private view { - require(msg.sender == _routerAddress, "sender must be router contract"); - } - - function _onlyExecutor() private view { - require(msg.sender == _executorAddress, "sender must be executor contract"); - } - /** @notice First verifies {contractAddress} is whitelisted, then sets {_tokenContractAddressToTokenProperties[contractAddress].isBurnable} to true. diff --git a/src/contracts/libraries/MerkleTrie.sol b/src/contracts/libraries/MerkleTrie.sol index 9c522d9b..9127a1b0 100644 --- a/src/contracts/libraries/MerkleTrie.sol +++ b/src/contracts/libraries/MerkleTrie.sol @@ -33,6 +33,7 @@ library MerkleTrie { error MerkleTrieValueLengthIsZero(); error MerkleTrieNodeWithUnknownPrefix(); error MerkleTrieUnparsableNode(); + error MerkleTrieRanOutOfProofElements(); /// @notice Determines the number of elements per branch node. uint256 internal constant TREE_RADIX = 16; @@ -185,7 +186,7 @@ library MerkleTrie { } } - revert("MerkleTrie: ran out of proof elements"); + revert MerkleTrieRanOutOfProofElements(); } /// @notice Parses an array of proof elements into a new array that contains both the original From 146cafedd0e7a41efc3616882846b4ad2a769add Mon Sep 17 00:00:00 2001 From: mpetrun5 <matija.petrunic@gmail.com> Date: Mon, 18 Mar 2024 17:59:45 +0100 Subject: [PATCH 2/7] Update tests --- test/handlers/erc20/admin.test.ts | 35 ++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/test/handlers/erc20/admin.test.ts b/test/handlers/erc20/admin.test.ts index bbcc556d..81193e77 100644 --- a/test/handlers/erc20/admin.test.ts +++ b/test/handlers/erc20/admin.test.ts @@ -66,34 +66,49 @@ describe("ERC20Handler - [constructor]", function () { it("[sanity] should revert if deposit is not called by Router", async () => { await expect( ERC20HandlerInstance.deposit(resourceID, depositorAccount, depositData), - ).to.be.revertedWith("sender must be router contract"); + ).to.be.revertedWithCustomError( + ERC20HandlerInstance, + "SenderNotRouterContract()", + ); }); - it("[sanity] should revert if deposit is not called by Router", async () => { + it("[sanity] should revert if execution is not called by Executor", async () => { await expect( ERC20HandlerInstance.executeProposal(resourceID, depositData), - ).to.be.revertedWith("sender must be executor contract"); + ).to.be.revertedWithCustomError( + ERC20HandlerInstance, + "SenderNotExecutorContract()", + ); }); - it("[sanity] should revert if deposit is not called by Router", async () => { + it("[sanity] should revert if setResource is not called by Bridge", async () => { await expect( ERC20HandlerInstance.setResource( resourceID, await ERC20MintableInstance.getAddress(), "0x", ), - ).to.be.revertedWith("sender must be bridge contract"); + ).to.be.revertedWithCustomError( + ERC20HandlerInstance, + "SenderNotBridgeContract()", + ); }); - it("[sanity] should revert if deposit is not called by Router", async () => { + it("[sanity] should revert if setBurnable is not called by Bridge", async () => { await expect( ERC20HandlerInstance.setBurnable(await ERC20HandlerInstance.getAddress()), - ).to.be.revertedWith("sender must be bridge contract"); + ).to.be.revertedWithCustomError( + ERC20HandlerInstance, + "SenderNotBridgeContract()", + ); }); - it("[sanity] should revert if deposit is not called by Router", async () => { - await expect(ERC20HandlerInstance.withdraw("0x")).to.be.revertedWith( - "sender must be bridge contract", + it("[sanity] should revert if withdraw is not called by Bridge", async () => { + await expect( + ERC20HandlerInstance.withdraw("0x"), + ).to.be.revertedWithCustomError( + ERC20HandlerInstance, + "SenderNotBridgeContract()", ); }); }); From 46701d77cb4582b8f564f8dce8e836362c49a8b4 Mon Sep 17 00:00:00 2001 From: mpetrun5 <matija.petrunic@gmail.com> Date: Mon, 18 Mar 2024 18:06:37 +0100 Subject: [PATCH 3/7] fix: add renounce admin zero address check --- src/contracts/handlers/fee/BasicFeeHandler.sol | 1 + test/handlers/fee/basic/admin.test.ts | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/contracts/handlers/fee/BasicFeeHandler.sol b/src/contracts/handlers/fee/BasicFeeHandler.sol index d5b6033a..9a1224b0 100755 --- a/src/contracts/handlers/fee/BasicFeeHandler.sol +++ b/src/contracts/handlers/fee/BasicFeeHandler.sol @@ -72,6 +72,7 @@ contract BasicFeeHandler is IFeeHandler, AccessControl { @param newAdmin Address that admin role will be granted to. */ function renounceAdmin(address newAdmin) external { + if (newAdmin == address(0)) revert ZeroAddressProvided(); address sender = _msgSender(); if (sender == newAdmin) revert CannotRenounceOneself(); grantRole(DEFAULT_ADMIN_ROLE, newAdmin); diff --git a/test/handlers/fee/basic/admin.test.ts b/test/handlers/fee/basic/admin.test.ts index c1bbfc8a..784e0949 100755 --- a/test/handlers/fee/basic/admin.test.ts +++ b/test/handlers/fee/basic/admin.test.ts @@ -5,6 +5,7 @@ import { ethers } from "hardhat"; import { assert, expect } from "chai"; import type { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers"; +import { ZeroAddress } from "ethers"; import { createResourceID, deployBridgeContracts } from "../../../helpers"; import type { BasicFeeHandler, @@ -172,4 +173,13 @@ describe("BasicFeeHandler - [admin]", () => { await basicFeeHandlerInstance.hasRole(ADMIN_ROLE, currentFeeHandlerAdmin), ); }); + + it("BasicFeeHandler should not allow for renounced admin to be zero address", async () => { + await expect( + basicFeeHandlerInstance.renounceAdmin(ZeroAddress), + ).to.be.revertedWithCustomError( + basicFeeHandlerInstance, + "ZeroAddressProvided()", + ); + }); }); From 69b5afd0441ef3a379bf3073d236283cd4ce4e0d Mon Sep 17 00:00:00 2001 From: nmlinaric <nikola.mlinaric93@gmail.com> Date: Tue, 19 Mar 2024 16:03:46 +0100 Subject: [PATCH 4/7] Rearrange core contracts addresses and functions --- src/contracts/Bridge.sol | 12 ++++- src/contracts/TestContracts.sol | 9 ++-- src/contracts/handlers/ERC20Handler.sol | 48 ++++++++++++++--- src/contracts/handlers/ERCHandlerHelpers.sol | 55 +++----------------- src/contracts/interfaces/IBridge.sol | 12 +++++ 5 files changed, 73 insertions(+), 63 deletions(-) diff --git a/src/contracts/Bridge.sol b/src/contracts/Bridge.sol index 549f31dc..bcd249ce 100755 --- a/src/contracts/Bridge.sol +++ b/src/contracts/Bridge.sol @@ -20,8 +20,10 @@ contract Bridge is Pausable, Context { uint8 public immutable _domainID; IFeeHandler public _feeHandler; - IAccessControlSegregator public _accessControl; + address public _executorAddress; + address public _routerAddress; + // resourceID => handler address mapping(bytes32 => address) public _resourceIDToHandlerAddress; @@ -140,4 +142,12 @@ contract Bridge is Pausable, Context { IERCHandler handler = IERCHandler(handlerAddress); handler.withdraw(data); } + + function adminChangeRouterAddress(address routerAddress) external onlyAllowed { + _routerAddress = routerAddress; + } + + function adminChangeExecutorAddress(address executorAddress) external onlyAllowed { + _executorAddress = executorAddress; + } } diff --git a/src/contracts/TestContracts.sol b/src/contracts/TestContracts.sol index adf6b304..56999a01 100755 --- a/src/contracts/TestContracts.sol +++ b/src/contracts/TestContracts.sol @@ -5,6 +5,7 @@ pragma solidity 0.8.11; import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol"; import "./handlers/ERCHandlerHelpers.sol"; import "./interfaces/IERC20Plus.sol"; +import "./interfaces/IBridge.sol"; contract NoArgument { event NoArgumentCalled(); @@ -58,13 +59,9 @@ abstract contract HandlerRevert is ERCHandlerHelpers { uint256 private _totalAmount; constructor( - address bridgeAddress, - address routerAddress, - address executorAddress + IBridge bridgeAddress ) ERCHandlerHelpers( - bridgeAddress, - routerAddress, - executorAddress + bridgeAddress ) {} function executeProposal(bytes32, bytes calldata) external view { diff --git a/src/contracts/handlers/ERC20Handler.sol b/src/contracts/handlers/ERC20Handler.sol index b0db4212..bae3100c 100755 --- a/src/contracts/handlers/ERC20Handler.sol +++ b/src/contracts/handlers/ERC20Handler.sol @@ -13,18 +13,41 @@ import "../ERC20Safe.sol"; */ contract ERC20Handler is IHandler, ERCHandlerHelpers, ERC20Safe { /** - @param bridgeAddress Contract address of previously deployed Bridge. + @param bridge Contract address of previously deployed Bridge. */ constructor( - address bridgeAddress, - address routerAddress, - address executorAddress + IBridge bridge ) ERCHandlerHelpers( - bridgeAddress, - routerAddress, - executorAddress + bridge ) {} + modifier onlyBridge() { + _onlyBridge(); + _; + } + + modifier onlyRouter() { + _onlyRouter(); + _; + } + + modifier onlyExecutor() { + _onlyExecutor(); + _; + } + + function _onlyBridge() private { + if (msg.sender != address(_bridge)) revert SenderNotBridgeContract(); + } + + function _onlyExecutor() private { + if (msg.sender != _bridge._executorAddress()) revert SenderNotExecutorContract(); + } + + function _onlyRouter() private { + if (msg.sender != _bridge._routerAddress()) revert SenderNotRouterContract(); + } + /** @notice A deposit is initiated by making a deposit in the Bridge contract. @param resourceID ResourceID used to find address of token to be used for deposit. @@ -114,7 +137,7 @@ contract ERC20Handler is IHandler, ERCHandlerHelpers, ERC20Safe { recipient address bytes 32 - 64 amount uint256 bytes 64 - 96 */ - function withdraw(bytes memory data) external override onlyBridge { + function withdraw(bytes memory data) external onlyBridge { address tokenAddress; address recipient; uint256 amount; @@ -142,4 +165,13 @@ contract ERC20Handler is IHandler, ERCHandlerHelpers, ERC20Safe { _setDecimals(contractAddress, externalTokenDecimals); } } + + /** + @notice First verifies {contractAddress} is whitelisted, then sets + {_tokenContractAddressToTokenProperties[contractAddress].isBurnable} to true. + @param contractAddress Address of contract to be used when making or executing deposits. + */ + function setBurnable(address contractAddress) external onlyBridge { + _setBurnable(contractAddress); + } } diff --git a/src/contracts/handlers/ERCHandlerHelpers.sol b/src/contracts/handlers/ERCHandlerHelpers.sol index 811fa963..97a9bf31 100755 --- a/src/contracts/handlers/ERCHandlerHelpers.sol +++ b/src/contracts/handlers/ERCHandlerHelpers.sol @@ -3,16 +3,16 @@ pragma solidity 0.8.11; import "../interfaces/IERCHandler.sol"; +import "../interfaces/IBridge.sol"; + /** @title Function used across handler contracts. @author ChainSafe Systems. @notice This contract is intended to be used with the Bridge contract. */ -abstract contract ERCHandlerHelpers is IERCHandler { - address public immutable _bridgeAddress; - address public immutable _routerAddress; - address public immutable _executorAddress; +contract ERCHandlerHelpers { + IBridge public _bridge; uint8 public constant DEFAULT_DECIMALS = 18; @@ -40,52 +40,11 @@ abstract contract ERCHandlerHelpers is IERCHandler { // token contract address => ERCTokenContractProperties mapping(address => ERCTokenContractProperties) public _tokenContractAddressToTokenProperties; - modifier onlyBridge() { - _onlyBridge(); - _; - } - - modifier onlyRouter() { - _onlyRouter(); - _; - } - - modifier onlyExecutor() { - _onlyExecutor(); - _; - } - - function _onlyBridge() private view { - if (msg.sender != _bridgeAddress) revert SenderNotBridgeContract(); - } - - function _onlyExecutor() private view { - if (msg.sender != _executorAddress) revert SenderNotExecutorContract(); - } - - function _onlyRouter() private view { - if (msg.sender != _routerAddress) revert SenderNotRouterContract(); - } - - /** - @param bridgeAddress Contract address of previously deployed Bridge. - @param routerAddress Contract address of previously deployed Router. - @param executorAddress Contract address of previously deployed Executor. - */ - constructor(address bridgeAddress, address routerAddress, address executorAddress) { - _bridgeAddress = bridgeAddress; - _routerAddress = routerAddress; - _executorAddress = executorAddress; - } - - /** - @notice First verifies {contractAddress} is whitelisted, then sets - {_tokenContractAddressToTokenProperties[contractAddress].isBurnable} to true. - @param contractAddress Address of contract to be used when making or executing deposits. + @param bridge Contract address of previously deployed Bridge. */ - function setBurnable(address contractAddress) external override onlyBridge { - _setBurnable(contractAddress); + constructor(IBridge bridge) { + _bridge = bridge; } function _setResource(bytes32 resourceID, address contractAddress) internal { diff --git a/src/contracts/interfaces/IBridge.sol b/src/contracts/interfaces/IBridge.sol index 3a4c8f22..bef54800 100755 --- a/src/contracts/interfaces/IBridge.sol +++ b/src/contracts/interfaces/IBridge.sol @@ -22,6 +22,18 @@ interface IBridge { */ function _feeHandler() external returns (IFeeHandler); + /** + @notice Exposing getter for {_routerAddress} instead of forcing the use of call. + @return address The {_routerAddress} that is currently set for the Bridge contract. + */ + function _routerAddress() external returns (address); + + /** + @notice Exposing getter for {_executorAddress} instead of forcing the use of call. + @return address The {_executorAddress} that is currently set for the Bridge contract. + */ + function _executorAddress() external returns (address); + /** @notice Exposing getter for {_accessControl} instead of forcing the use of call. @return IAccessControlSegregator The {_accessControl} that is currently set for the Bridge contract. From 276aca90d6fbca9615103557b2cda498bd1dec64 Mon Sep 17 00:00:00 2001 From: nmlinaric <nikola.mlinaric93@gmail.com> Date: Tue, 19 Mar 2024 16:07:15 +0100 Subject: [PATCH 5/7] Update tests after core addresses and functions rearrangement --- test/contractBridge/admin.test.ts | 32 ++++++++++++++----- test/contractBridge/depositERC20.test.ts | 14 ++++---- .../executeProposalERC20.test.ts | 2 -- test/contractBridge/executeProposals.test.ts | 2 -- .../decimals/bothChainsNot18Decimals.test.ts | 4 --- .../decimals/oneChainNot18Decimals.test.ts | 4 --- .../decimals/oneChainWith0Decimals.test.ts | 4 --- test/e2e/erc20/decimals/roundingLoss.test.ts | 4 --- test/e2e/erc20/differentChainsMock.test.ts | 4 --- test/e2e/erc20/sameChain.test.ts | 2 -- test/handlers/erc20/admin.test.ts | 9 +----- test/handlers/erc20/constructor.test.ts | 11 +------ test/handlers/erc20/decimals.test.ts | 12 +++---- test/handlers/erc20/deposit.test.ts | 10 +++--- test/handlers/erc20/depositBurn.test.ts | 9 +----- test/handlers/erc20/isBurnable.test.ts | 9 +----- test/handlers/erc20/isWhitelisted.test.ts | 9 +----- .../setResourceIdAndContractAddress.test.ts | 11 +------ test/handlers/fee/basic/calculateFee.test.ts | 10 +++--- test/handlers/fee/basic/collectFee.test.ts | 10 +++--- test/handlers/fee/basic/distributeFee.test.ts | 10 +++--- .../fee/percentage/calculateFee.test.ts | 12 +++---- .../fee/percentage/collectFee.test.ts | 12 +++---- .../fee/percentage/distributeFee.test.ts | 12 +++---- test/helpers.ts | 8 +++++ 25 files changed, 79 insertions(+), 147 deletions(-) diff --git a/test/contractBridge/admin.test.ts b/test/contractBridge/admin.test.ts index 4f493c04..fafb3aa8 100644 --- a/test/contractBridge/admin.test.ts +++ b/test/contractBridge/admin.test.ts @@ -54,8 +54,6 @@ describe("Bridge - [admin]", () => { ERC20HandlerContract = await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); }); @@ -116,8 +114,6 @@ describe("Bridge - [admin]", () => { ); const ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); await expect( @@ -189,8 +185,6 @@ describe("Bridge - [admin]", () => { ); const ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); await expect( @@ -244,8 +238,6 @@ describe("Bridge - [admin]", () => { ); const ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); await expect( @@ -388,4 +380,28 @@ describe("Bridge - [admin]", () => { executorInstance.connect(tokenOwnerAccount).adminChangeSlotIndex(3, 1), ).not.to.be.reverted; }); + + it("Should require admin role to change router address", async () => { + await expect( + bridgeInstance + .connect(nonAdminAccount) + .adminChangeRouterAddress("0x388C818CA8B9251b393131C08a736A67ccB19297"), + ).to.be.revertedWithCustomError( + routerInstance, + "AccessNotAllowed(address,bytes4)", + ); + }); + + it("Should require admin role to change executor address", async () => { + await expect( + bridgeInstance + .connect(nonAdminAccount) + .adminChangeExecutorAddress( + "0x388C818CA8B9251b393131C08a736A67ccB19297", + ), + ).to.be.revertedWithCustomError( + routerInstance, + "AccessNotAllowed(address,bytes4)", + ); + }); }); diff --git a/test/contractBridge/depositERC20.test.ts b/test/contractBridge/depositERC20.test.ts index 8163610d..802d3c65 100755 --- a/test/contractBridge/depositERC20.test.ts +++ b/test/contractBridge/depositERC20.test.ts @@ -6,11 +6,10 @@ import { assert, expect } from "chai"; import { ethers } from "hardhat"; import type { Bridge, - Depositor, + Router, ERC20Handler, ERC20PresetMinterPauser, ERC20Safe__factory, - Executor, } from "../../typechain-types"; import { createERCDepositData, @@ -31,8 +30,7 @@ describe("Bridge - [deposit - ERC20]", () => { const routerAddress = "0x1a60efB48c61A79515B170CA61C84DD6dCA80418"; let bridgeInstance: Bridge; - let routerInstance: Depositor; - let executorInstance: Executor; + let routerInstance: Router; let ERC20MintableInstance1: ERC20PresetMinterPauser; let ERC20MintableInstance2: ERC20PresetMinterPauser; let ERC20HandlerInstance: ERC20Handler; @@ -47,8 +45,10 @@ describe("Bridge - [deposit - ERC20]", () => { beforeEach(async () => { [, depositorAccount, recipientAccount] = await ethers.getSigners(); - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(originDomainID, routerAddress); + [bridgeInstance, routerInstance] = await deployBridgeContracts( + originDomainID, + routerAddress, + ); const ERC20MintableContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", ); @@ -64,8 +64,6 @@ describe("Bridge - [deposit - ERC20]", () => { await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); resourceID1 = createResourceID( diff --git a/test/contractBridge/executeProposalERC20.test.ts b/test/contractBridge/executeProposalERC20.test.ts index a7b4e49c..259ac067 100755 --- a/test/contractBridge/executeProposalERC20.test.ts +++ b/test/contractBridge/executeProposalERC20.test.ts @@ -76,8 +76,6 @@ describe("Bridge - [execute proposal - ERC20]", () => { await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); resourceID = diff --git a/test/contractBridge/executeProposals.test.ts b/test/contractBridge/executeProposals.test.ts index 4c0705cd..0d481aaa 100755 --- a/test/contractBridge/executeProposals.test.ts +++ b/test/contractBridge/executeProposals.test.ts @@ -70,8 +70,6 @@ describe("Bridge - [execute proposals]", () => { await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); erc20ResourceID = diff --git a/test/e2e/erc20/decimals/bothChainsNot18Decimals.test.ts b/test/e2e/erc20/decimals/bothChainsNot18Decimals.test.ts index 741814cf..68c974d8 100755 --- a/test/e2e/erc20/decimals/bothChainsNot18Decimals.test.ts +++ b/test/e2e/erc20/decimals/bothChainsNot18Decimals.test.ts @@ -117,13 +117,9 @@ describe("E2E ERC20 - Two EVM Chains both with decimal places != 18", () => { await ethers.getContractFactory("ERC20Handler"); originERC20HandlerInstance = await ERC20HandlerContract.deploy( await originBridgeInstance.getAddress(), - await originRouterInstance.getAddress(), - await originExecutorInstance.getAddress(), ); destinationERC20HandlerInstance = await ERC20HandlerContract.deploy( await destinationBridgeInstance.getAddress(), - await destinationRouterInstance.getAddress(), - await destinationExecutorInstance.getAddress(), ); originResourceID = "0x0000000000000000000000000000000000000000000000000000000000000000"; diff --git a/test/e2e/erc20/decimals/oneChainNot18Decimals.test.ts b/test/e2e/erc20/decimals/oneChainNot18Decimals.test.ts index ab31652e..6d6218ef 100755 --- a/test/e2e/erc20/decimals/oneChainNot18Decimals.test.ts +++ b/test/e2e/erc20/decimals/oneChainNot18Decimals.test.ts @@ -129,13 +129,9 @@ describe("E2E ERC20 - Two EVM Chains, one with decimal places == 18, other with await ethers.getContractFactory("ERC20Handler"); originERC20HandlerInstance = await ERC20HandlerContract.deploy( await originBridgeInstance.getAddress(), - await originRouterInstance.getAddress(), - await originExecutorInstance.getAddress(), ); destinationERC20HandlerInstance = await ERC20HandlerContract.deploy( await destinationBridgeInstance.getAddress(), - await destinationRouterInstance.getAddress(), - await destinationExecutorInstance.getAddress(), ); originResourceID = diff --git a/test/e2e/erc20/decimals/oneChainWith0Decimals.test.ts b/test/e2e/erc20/decimals/oneChainWith0Decimals.test.ts index 9461a3dd..10354067 100755 --- a/test/e2e/erc20/decimals/oneChainWith0Decimals.test.ts +++ b/test/e2e/erc20/decimals/oneChainWith0Decimals.test.ts @@ -129,13 +129,9 @@ describe("E2E ERC20 - Two EVM Chains, one with decimal places == 18, other with await ethers.getContractFactory("ERC20Handler"); originERC20HandlerInstance = await ERC20HandlerContract.deploy( await originBridgeInstance.getAddress(), - await originRouterInstance.getAddress(), - await originExecutorInstance.getAddress(), ); destinationERC20HandlerInstance = await ERC20HandlerContract.deploy( await destinationBridgeInstance.getAddress(), - await destinationRouterInstance.getAddress(), - await destinationExecutorInstance.getAddress(), ); originResourceID = diff --git a/test/e2e/erc20/decimals/roundingLoss.test.ts b/test/e2e/erc20/decimals/roundingLoss.test.ts index 0d14bb5d..9f15edc4 100755 --- a/test/e2e/erc20/decimals/roundingLoss.test.ts +++ b/test/e2e/erc20/decimals/roundingLoss.test.ts @@ -129,13 +129,9 @@ describe("E2E ERC20 - Two EVM Chains both with decimal places != 18 with roundin await ethers.getContractFactory("ERC20Handler"); originERC20HandlerInstance = await ERC20HandlerContract.deploy( await originBridgeInstance.getAddress(), - await originRouterInstance.getAddress(), - await originExecutorInstance.getAddress(), ); destinationERC20HandlerInstance = await ERC20HandlerContract.deploy( await destinationBridgeInstance.getAddress(), - await destinationRouterInstance.getAddress(), - await destinationExecutorInstance.getAddress(), ); originResourceID = diff --git a/test/e2e/erc20/differentChainsMock.test.ts b/test/e2e/erc20/differentChainsMock.test.ts index a6d5bdc9..ce4240d6 100755 --- a/test/e2e/erc20/differentChainsMock.test.ts +++ b/test/e2e/erc20/differentChainsMock.test.ts @@ -118,13 +118,9 @@ describe("E2E ERC20 - Two EVM Chains", () => { await ethers.getContractFactory("ERC20Handler"); originERC20HandlerInstance = await ERC20HandlerContract.deploy( await originBridgeInstance.getAddress(), - await originRouterInstance.getAddress(), - await originExecutorInstance.getAddress(), ); destinationERC20HandlerInstance = await ERC20HandlerContract.deploy( await destinationBridgeInstance.getAddress(), - await destinationRouterInstance.getAddress(), - await destinationExecutorInstance.getAddress(), ); originResourceID = diff --git a/test/e2e/erc20/sameChain.test.ts b/test/e2e/erc20/sameChain.test.ts index 65e83c53..4257ab3b 100755 --- a/test/e2e/erc20/sameChain.test.ts +++ b/test/e2e/erc20/sameChain.test.ts @@ -73,8 +73,6 @@ describe("E2E ERC20 - Same Chain", () => { await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); resourceID = "0x0000000000000000000000000000000000000000000000000000000000000000"; diff --git a/test/handlers/erc20/admin.test.ts b/test/handlers/erc20/admin.test.ts index 81193e77..d245d724 100644 --- a/test/handlers/erc20/admin.test.ts +++ b/test/handlers/erc20/admin.test.ts @@ -6,8 +6,6 @@ import { expect } from "chai"; import type { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers"; import type { Bridge, - Router, - Executor, ERC20Handler, ERC20Handler__factory, ERC20PresetMinterPauser, @@ -27,8 +25,6 @@ describe("ERC20Handler - [constructor]", function () { let resourceID: string; let bridgeInstance: Bridge; - let routerInstance: Router; - let executorInstance: Executor; let ERC20HandlerContract: ERC20Handler__factory; let ERC20MintableInstance: ERC20PresetMinterPauser; let ERC20HandlerInstance: ERC20Handler; @@ -37,8 +33,7 @@ describe("ERC20Handler - [constructor]", function () { beforeEach(async () => { [, depositorAccount, recipientAccount] = await ethers.getSigners(); - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(domainID, routerAddress); + [bridgeInstance] = await deployBridgeContracts(domainID, routerAddress); const ERC20MintableContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", @@ -47,8 +42,6 @@ describe("ERC20Handler - [constructor]", function () { ERC20HandlerContract = await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); resourceID = createResourceID( diff --git a/test/handlers/erc20/constructor.test.ts b/test/handlers/erc20/constructor.test.ts index dfb4998c..488affe2 100755 --- a/test/handlers/erc20/constructor.test.ts +++ b/test/handlers/erc20/constructor.test.ts @@ -5,8 +5,6 @@ import { ethers } from "hardhat"; import { assert, expect } from "chai"; import type { Bridge, - Router, - Executor, ERC20Handler, ERC20Handler__factory, ERC20PresetMinterPauser, @@ -22,8 +20,6 @@ describe("ERC20Handler - [constructor]", function () { let initialContractAddresses: Array<string> = []; let bridgeInstance: Bridge; - let routerInstance: Router; - let executorInstance: Executor; let ERC20HandlerContract: ERC20Handler__factory; let ERC20MintableInstance1: ERC20PresetMinterPauser; let ERC20MintableInstance2: ERC20PresetMinterPauser; @@ -31,8 +27,7 @@ describe("ERC20Handler - [constructor]", function () { let ERC20HandlerInstance: ERC20Handler; beforeEach(async () => { - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(domainID, routerAddress); + [bridgeInstance] = await deployBridgeContracts(domainID, routerAddress); const ERC20MintableContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", @@ -43,8 +38,6 @@ describe("ERC20Handler - [constructor]", function () { ERC20HandlerContract = await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); initialResourceIDs = [ @@ -88,8 +81,6 @@ describe("ERC20Handler - [constructor]", function () { it("initialResourceIDs should be parsed correctly and corresponding resourceID mappings should have expected values", async () => { const ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); for (let i = 0; i < initialResourceIDs.length; i++) { await expect( diff --git a/test/handlers/erc20/decimals.test.ts b/test/handlers/erc20/decimals.test.ts index 120bab0a..eb4d6c00 100755 --- a/test/handlers/erc20/decimals.test.ts +++ b/test/handlers/erc20/decimals.test.ts @@ -7,8 +7,6 @@ import type { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signer import { deployBridgeContracts, createResourceID } from "../../helpers"; import type { Bridge, - Router, - Executor, ERC20Handler, ERC20PresetMinterPauser, } from "../../../typechain-types"; @@ -17,8 +15,6 @@ describe("ERC20Handler - [decimals]", () => { const originDomainID = 1; let bridgeInstance: Bridge; - let routerInstance: Router; - let executorInstance: Executor; let ERC20MintableInstance: ERC20PresetMinterPauser; let ERC20HandlerInstance: ERC20Handler; let depositorAccount: HardhatEthersSigner; @@ -33,8 +29,10 @@ describe("ERC20Handler - [decimals]", () => { beforeEach(async () => { [, depositorAccount] = await ethers.getSigners(); - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(originDomainID, routerAddress); + [bridgeInstance] = await deployBridgeContracts( + originDomainID, + routerAddress, + ); const ERC20MintableContract = await ethers.getContractFactory( "ERC20PresetMinterPauserDecimals", ); @@ -47,8 +45,6 @@ describe("ERC20Handler - [decimals]", () => { await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); resourceID = createResourceID( diff --git a/test/handlers/erc20/deposit.test.ts b/test/handlers/erc20/deposit.test.ts index 9e41b261..21746bd4 100755 --- a/test/handlers/erc20/deposit.test.ts +++ b/test/handlers/erc20/deposit.test.ts @@ -12,7 +12,6 @@ import { import type { Bridge, Router, - Executor, ERC20Handler, ERC20PresetMinterPauser, ERC20Safe__factory, @@ -30,7 +29,6 @@ describe("ERC20Handler - [Deposit ERC20]", () => { let bridgeInstance: Bridge; let routerInstance: Router; - let executorInstance: Executor; let ERC20MintableInstance: ERC20PresetMinterPauser; let ERC20HandlerInstance: ERC20Handler; let erc20SafeContract: ERC20Safe__factory; @@ -42,8 +40,10 @@ describe("ERC20Handler - [Deposit ERC20]", () => { beforeEach(async () => { [adminAccount, depositorAccount] = await ethers.getSigners(); - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(originDomainID, routerAddress); + [bridgeInstance, routerInstance] = await deployBridgeContracts( + originDomainID, + routerAddress, + ); const ERC20MintableContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", ); @@ -52,8 +52,6 @@ describe("ERC20Handler - [Deposit ERC20]", () => { await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); resourceID = createResourceID( diff --git a/test/handlers/erc20/depositBurn.test.ts b/test/handlers/erc20/depositBurn.test.ts index d872dba6..fe672a7a 100755 --- a/test/handlers/erc20/depositBurn.test.ts +++ b/test/handlers/erc20/depositBurn.test.ts @@ -7,8 +7,6 @@ import type { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signer import { deployBridgeContracts, createResourceID } from "../../helpers"; import type { Bridge, - Router, - Executor, ERC20Handler, ERC20PresetMinterPauser, } from "../../../typechain-types"; @@ -20,8 +18,6 @@ describe("ERC20Handler - [Deposit Burn ERC20]", () => { const routerAddress = "0x1a60efB48c61A79515B170CA61C84DD6dCA80418"; let bridgeInstance: Bridge; - let routerInstance: Router; - let executorInstance: Executor; let ERC20MintableInstance1: ERC20PresetMinterPauser; let ERC20MintableInstance2: ERC20PresetMinterPauser; let ERC20HandlerInstance: ERC20Handler; @@ -34,8 +30,7 @@ describe("ERC20Handler - [Deposit Burn ERC20]", () => { beforeEach(async () => { [, depositorAccount] = await ethers.getSigners(); - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(Number(domainID), routerAddress); + [bridgeInstance] = await deployBridgeContracts(domainID, routerAddress); const ERC20MintableContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", ); @@ -45,8 +40,6 @@ describe("ERC20Handler - [Deposit Burn ERC20]", () => { await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); resourceID1 = createResourceID( diff --git a/test/handlers/erc20/isBurnable.test.ts b/test/handlers/erc20/isBurnable.test.ts index 14a23855..9e36b6fc 100755 --- a/test/handlers/erc20/isBurnable.test.ts +++ b/test/handlers/erc20/isBurnable.test.ts @@ -6,8 +6,6 @@ import { assert, expect } from "chai"; import { deployBridgeContracts } from "../../helpers"; import type { Bridge, - Router, - Executor, ERC20Handler, ERC20PresetMinterPauser, } from "../../../typechain-types"; @@ -18,8 +16,6 @@ describe("ERC20Handler - [Burn ERC20]", () => { const routerAddress = "0x1a60efB48c61A79515B170CA61C84DD6dCA80418"; let bridgeInstance: Bridge; - let routerInstance: Router; - let executorInstance: Executor; let ERC20HandlerInstance: ERC20Handler; let ERC20MintableInstance1: ERC20PresetMinterPauser; let ERC20MintableInstance2: ERC20PresetMinterPauser; @@ -31,8 +27,7 @@ describe("ERC20Handler - [Burn ERC20]", () => { let burnableContractAddresses: Array<string>; beforeEach(async () => { - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(domainID, routerAddress); + [bridgeInstance] = await deployBridgeContracts(domainID, routerAddress); const ERC20MintableContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", ); @@ -42,8 +37,6 @@ describe("ERC20Handler - [Burn ERC20]", () => { await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); resourceID1 = ethers.zeroPadValue( (await ERC20MintableInstance1.getAddress()) + diff --git a/test/handlers/erc20/isWhitelisted.test.ts b/test/handlers/erc20/isWhitelisted.test.ts index cbad0a58..da6e3939 100755 --- a/test/handlers/erc20/isWhitelisted.test.ts +++ b/test/handlers/erc20/isWhitelisted.test.ts @@ -6,8 +6,6 @@ import { assert, expect } from "chai"; import { deployBridgeContracts } from "../../helpers"; import type { Bridge, - Router, - Executor, ERC20Handler, ERC20PresetMinterPauser, } from "../../../typechain-types"; @@ -18,16 +16,13 @@ describe("ERC20Handler - [isWhitelisted]", () => { const routerAddress = "0x1a60efB48c61A79515B170CA61C84DD6dCA80418"; let bridgeInstance: Bridge; - let routerInstance: Router; - let executorInstance: Executor; let ERC20MintableInstance: ERC20PresetMinterPauser; let ERC20HandlerInstance: ERC20Handler; let resourceID1: string; beforeEach(async () => { - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(domainID, routerAddress); + [bridgeInstance] = await deployBridgeContracts(domainID, routerAddress); const ERC20MintableContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", ); @@ -36,8 +31,6 @@ describe("ERC20Handler - [isWhitelisted]", () => { await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); resourceID1 = ethers.zeroPadValue( diff --git a/test/handlers/erc20/setResourceIdAndContractAddress.test.ts b/test/handlers/erc20/setResourceIdAndContractAddress.test.ts index 27f079bc..f19216c2 100755 --- a/test/handlers/erc20/setResourceIdAndContractAddress.test.ts +++ b/test/handlers/erc20/setResourceIdAndContractAddress.test.ts @@ -6,8 +6,6 @@ import { assert } from "chai"; import { createResourceID, deployBridgeContracts } from "../../helpers"; import type { Bridge, - Router, - Executor, ERC20Handler, ERC20PresetMinterPauser, } from "../../../typechain-types"; @@ -18,8 +16,6 @@ describe("ERC20Handler - [setResourceIDAndContractAddress]", () => { const routerAddress = "0x1a60efB48c61A79515B170CA61C84DD6dCA80418"; let bridgeInstance: Bridge; - let routerInstance: Router; - let executorInstance: Executor; let ERC20MintableInstance1: ERC20PresetMinterPauser; let ERC20MintableInstance2: ERC20PresetMinterPauser; let ERC20HandlerInstance1: ERC20Handler; @@ -28,8 +24,7 @@ describe("ERC20Handler - [setResourceIDAndContractAddress]", () => { let resourceID1: string; beforeEach(async () => { - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(domainID, routerAddress); + [bridgeInstance] = await deployBridgeContracts(domainID, routerAddress); const ERC20MintableContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", ); @@ -39,13 +34,9 @@ describe("ERC20Handler - [setResourceIDAndContractAddress]", () => { await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance1 = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); ERC20HandlerInstance2 = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); resourceID1 = createResourceID( diff --git a/test/handlers/fee/basic/calculateFee.test.ts b/test/handlers/fee/basic/calculateFee.test.ts index 3429c049..82ea890a 100755 --- a/test/handlers/fee/basic/calculateFee.test.ts +++ b/test/handlers/fee/basic/calculateFee.test.ts @@ -16,7 +16,6 @@ import type { ERC20PresetMinterPauser, FeeHandlerRouter, Router, - Executor, } from "../../../../typechain-types"; describe("BasicFeeHandler - [calculateFee]", () => { @@ -30,7 +29,6 @@ describe("BasicFeeHandler - [calculateFee]", () => { let bridgeInstance: Bridge; let routerInstance: Router; - let executorInstance: Executor; let ERC20MintableInstance: ERC20PresetMinterPauser; let ERC20HandlerInstance: ERC20Handler; let feeHandlerRouterInstance: FeeHandlerRouter; @@ -44,8 +42,10 @@ describe("BasicFeeHandler - [calculateFee]", () => { beforeEach(async () => { [, , recipientAccount, relayer1] = await ethers.getSigners(); - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(originDomainID, routerAddress); + [bridgeInstance, routerInstance] = await deployBridgeContracts( + originDomainID, + routerAddress, + ); const ERC20MintableContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", ); @@ -54,8 +54,6 @@ describe("BasicFeeHandler - [calculateFee]", () => { await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); const FeeHandlerRouterContract = await ethers.getContractFactory("FeeHandlerRouter"); diff --git a/test/handlers/fee/basic/collectFee.test.ts b/test/handlers/fee/basic/collectFee.test.ts index df2cfbd3..eaccb70c 100755 --- a/test/handlers/fee/basic/collectFee.test.ts +++ b/test/handlers/fee/basic/collectFee.test.ts @@ -13,7 +13,6 @@ import type { BasicFeeHandler, Bridge, Router, - Executor, ERC20Handler, ERC20PresetMinterPauser, FeeHandlerRouter, @@ -31,7 +30,6 @@ describe("BasicFeeHandler - [collectFee]", () => { let bridgeInstance: Bridge; let routerInstance: Router; - let executorInstance: Executor; let ERC20MintableInstance: ERC20PresetMinterPauser; let basicFeeHandlerInstance: BasicFeeHandler; let ERC20HandlerInstance: ERC20Handler; @@ -44,8 +42,10 @@ describe("BasicFeeHandler - [collectFee]", () => { beforeEach(async () => { [, depositorAccount, recipientAccount] = await ethers.getSigners(); - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(originDomainID, routerAddress); + [bridgeInstance, routerInstance] = await deployBridgeContracts( + originDomainID, + routerAddress, + ); const ERC20MintableContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", ); @@ -54,8 +54,6 @@ describe("BasicFeeHandler - [collectFee]", () => { await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); const FeeHandlerRouterContract = await ethers.getContractFactory("FeeHandlerRouter"); diff --git a/test/handlers/fee/basic/distributeFee.test.ts b/test/handlers/fee/basic/distributeFee.test.ts index 937683d6..ec24ba49 100755 --- a/test/handlers/fee/basic/distributeFee.test.ts +++ b/test/handlers/fee/basic/distributeFee.test.ts @@ -13,7 +13,6 @@ import type { BasicFeeHandler, Bridge, Router, - Executor, ERC20Handler, ERC20PresetMinterPauser, FeeHandlerRouter, @@ -33,7 +32,6 @@ describe("BasicFeeHandler - [distributeFee]", () => { let depositData: string; let bridgeInstance: Bridge; let routerInstance: Router; - let executorInstance: Executor; let basicFeeHandlerInstance: BasicFeeHandler; let ERC20HandlerInstance: ERC20Handler; let ERC20MintableInstance: ERC20PresetMinterPauser; @@ -52,8 +50,10 @@ describe("BasicFeeHandler - [distributeFee]", () => { nonAdminAccount, ] = await ethers.getSigners(); - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(originDomainID, routerAddress); + [bridgeInstance, routerInstance] = await deployBridgeContracts( + originDomainID, + routerAddress, + ); const ERC20MintableContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", ); @@ -62,8 +62,6 @@ describe("BasicFeeHandler - [distributeFee]", () => { await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); const FeeHandlerRouterContract = await ethers.getContractFactory("FeeHandlerRouter"); diff --git a/test/handlers/fee/percentage/calculateFee.test.ts b/test/handlers/fee/percentage/calculateFee.test.ts index 49be4c33..fad9ac08 100755 --- a/test/handlers/fee/percentage/calculateFee.test.ts +++ b/test/handlers/fee/percentage/calculateFee.test.ts @@ -10,12 +10,11 @@ import { } from "../../../helpers"; import type { Bridge, + Router, ERC20Handler, ERC20PresetMinterPauser, - Executor, FeeHandlerRouter, PercentageERC20FeeHandlerEVM, - Router, } from "../../../../typechain-types"; describe("PercentageFeeHandler - [calculateFee]", () => { @@ -28,7 +27,6 @@ describe("PercentageFeeHandler - [calculateFee]", () => { let bridgeInstance: Bridge; let routerInstance: Router; - let executorInstance: Executor; let percentageFeeHandlerInstance: PercentageERC20FeeHandlerEVM; let ERC20MintableInstance: ERC20PresetMinterPauser; let ERC20HandlerInstance: ERC20Handler; @@ -41,8 +39,10 @@ describe("PercentageFeeHandler - [calculateFee]", () => { beforeEach(async () => { [, recipientAccount, relayer] = await ethers.getSigners(); - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(originDomainID, routerAddress); + [bridgeInstance, routerInstance] = await deployBridgeContracts( + originDomainID, + routerAddress, + ); const ERC20MintableContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", ); @@ -50,8 +50,6 @@ describe("PercentageFeeHandler - [calculateFee]", () => { await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); ERC20MintableInstance = await ERC20MintableContract.deploy("Token", "TOK"); const FeeHandlerRouterContract = diff --git a/test/handlers/fee/percentage/collectFee.test.ts b/test/handlers/fee/percentage/collectFee.test.ts index 3e9b39c9..5ef0ac2e 100755 --- a/test/handlers/fee/percentage/collectFee.test.ts +++ b/test/handlers/fee/percentage/collectFee.test.ts @@ -11,12 +11,11 @@ import { } from "../../../helpers"; import type { Bridge, + Router, ERC20Handler, ERC20PresetMinterPauser, - Executor, FeeHandlerRouter, PercentageERC20FeeHandlerEVM, - Router, } from "../../../../typechain-types"; describe("PercentageFeeHandler - [collectFee]", () => { @@ -36,7 +35,6 @@ describe("PercentageFeeHandler - [collectFee]", () => { let bridgeInstance: Bridge; let routerInstance: Router; - let executorInstance: Executor; let ERC20MintableInstance: ERC20PresetMinterPauser; let ERC20HandlerInstance: ERC20Handler; let feeHandlerRouterInstance: FeeHandlerRouter; @@ -50,14 +48,14 @@ describe("PercentageFeeHandler - [collectFee]", () => { beforeEach(async () => { [, depositorAccount, recipientAccount] = await ethers.getSigners(); - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(originDomainID, routerAddress); + [bridgeInstance, routerInstance] = await deployBridgeContracts( + originDomainID, + routerAddress, + ); const ERC20HandlerContract = await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); const ERC20MintableContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", diff --git a/test/handlers/fee/percentage/distributeFee.test.ts b/test/handlers/fee/percentage/distributeFee.test.ts index b9eca9ff..3b298125 100644 --- a/test/handlers/fee/percentage/distributeFee.test.ts +++ b/test/handlers/fee/percentage/distributeFee.test.ts @@ -11,12 +11,11 @@ import { } from "../../../helpers"; import type { Bridge, + Router, ERC20Handler, ERC20PresetMinterPauser, - Executor, FeeHandlerRouter, PercentageERC20FeeHandlerEVM, - Router, } from "../../../../typechain-types"; describe("PercentageFeeHandler - [distributeFee]", () => { @@ -34,7 +33,6 @@ describe("PercentageFeeHandler - [distributeFee]", () => { let bridgeInstance: Bridge; let routerInstance: Router; - let executorInstance: Executor; let ERC20MintableInstance: ERC20PresetMinterPauser; let ERC20HandlerInstance: ERC20Handler; let feeHandlerRouterInstance: FeeHandlerRouter; @@ -56,8 +54,10 @@ describe("PercentageFeeHandler - [distributeFee]", () => { nonAdminAccount, ] = await ethers.getSigners(); - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(originDomainID, routerAddress); + [bridgeInstance, routerInstance] = await deployBridgeContracts( + originDomainID, + routerAddress, + ); const ERC20MintableContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", ); @@ -65,8 +65,6 @@ describe("PercentageFeeHandler - [distributeFee]", () => { await ethers.getContractFactory("ERC20Handler"); ERC20HandlerInstance = await ERC20HandlerContract.deploy( await bridgeInstance.getAddress(), - await routerInstance.getAddress(), - await executorInstance.getAddress(), ); ERC20MintableInstance = await ERC20MintableContract.deploy("Token", "TOK"); const FeeHandlerRouterContract = diff --git a/test/helpers.ts b/test/helpers.ts index 9c9d6c69..9924df65 100755 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -148,6 +148,14 @@ export async function deployBridgeContracts( await stateRootStorageInstance.getAddress(), ]); + await bridgeInstance.adminChangeRouterAddress( + await routerInstance.getAddress(), + ); + + await bridgeInstance.adminChangeExecutorAddress( + await executorInstance.getAddress(), + ); + return [ bridgeInstance, routerInstance, From 1c6809438f3d5d39ecbe0e0a6c91b6f575697535 Mon Sep 17 00:00:00 2001 From: nmlinaric <nikola.mlinaric93@gmail.com> Date: Tue, 26 Mar 2024 09:53:01 +0100 Subject: [PATCH 6/7] set getters as views in IBridge --- src/contracts/interfaces/IBridge.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/contracts/interfaces/IBridge.sol b/src/contracts/interfaces/IBridge.sol index bef54800..de96bf94 100755 --- a/src/contracts/interfaces/IBridge.sol +++ b/src/contracts/interfaces/IBridge.sol @@ -14,13 +14,13 @@ interface IBridge { @notice Exposing getter for {_domainID} instead of forcing the use of call. @return uint8 The {_domainID} that is currently set for the Bridge contract. */ - function _domainID() external returns (uint8); + function _domainID() external view returns (uint8); /** @notice Exposing getter for {_feeHandler} instead of forcing the use of call. @return IFeeHandler The {_feeHandler} that is currently set for the Bridge contract. */ - function _feeHandler() external returns (IFeeHandler); + function _feeHandler() external view returns (IFeeHandler); /** @notice Exposing getter for {_routerAddress} instead of forcing the use of call. @@ -38,7 +38,7 @@ interface IBridge { @notice Exposing getter for {_accessControl} instead of forcing the use of call. @return IAccessControlSegregator The {_accessControl} that is currently set for the Bridge contract. */ - function _accessControl() external returns (IAccessControlSegregator); + function _accessControl() external view returns (IAccessControlSegregator); /**IFeeHandler @notice Exposing getter for {_resourceIDToHandlerAddress}. @@ -51,5 +51,5 @@ interface IBridge { @notice Exposing getter for {paused} instead of forcing the use of call. @return bool The {paused} status that is currently set for the Bridge contract. */ - function paused() external returns (bool); + function paused() external view returns (bool); } From 9fcc97b10ebb4a0904f58a85bdfd6c132368fc53 Mon Sep 17 00:00:00 2001 From: nmlinaric <nikola.mlinaric93@gmail.com> Date: Wed, 27 Mar 2024 11:26:14 +0100 Subject: [PATCH 7/7] Set Bridge as single source of truth for Router and Executor addresses --- package.json | 6 ++-- src/contracts/handlers/FeeHandlerRouter.sol | 13 ++++---- .../handlers/PermissionlessGenericHandler.sol | 18 +++++------ .../handlers/fee/BasicFeeHandler.sol | 20 ++++++------ .../fee/PercentageERC20FeeHandlerEVM.sol | 13 ++++---- test/handlers/fee/basic/admin.test.ts | 5 +-- test/handlers/fee/basic/calculateFee.test.ts | 5 +-- test/handlers/fee/basic/changeFee.test.ts | 5 +-- test/handlers/fee/basic/collectFee.test.ts | 3 +- test/handlers/fee/basic/constructor.test.ts | 6 +--- test/handlers/fee/basic/distributeFee.test.ts | 3 +- test/handlers/fee/handlerRouter.test.ts | 32 ++++++++++++++----- test/handlers/fee/percentage/admin.test.ts | 5 +-- .../fee/percentage/calculateFee.test.ts | 5 +-- .../handlers/fee/percentage/changeFee.test.ts | 10 +----- .../fee/percentage/collectFee.test.ts | 3 +- .../fee/percentage/distributeFee.test.ts | 3 +- .../generic/permissionlessDeposit.test.ts | 9 +++--- .../executionWithEvents.test.ts | 1 - .../gasTooSmall.test.ts | 1 - .../packedDepositData.test.ts | 1 - .../unpackedDepositData.test.ts | 1 - yarn.lock | 2 +- 23 files changed, 73 insertions(+), 97 deletions(-) diff --git a/package.json b/package.json index 8edefdbd..cbfba5ff 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "@metamask/eth-sig-util": "^7.0.0", "@nomicfoundation/hardhat-chai-matchers": "^2.0.2", "@nomicfoundation/hardhat-ethers": "^3.0.4", - "@nomicfoundation/hardhat-network-helpers": "^1.0.9", + "@nomicfoundation/hardhat-network-helpers": "^1.0.10", "@nomicfoundation/hardhat-toolbox": "^3.0.0", "@nomicfoundation/hardhat-verify": "^1.0.0", "@openzeppelin/contracts": "4.9.3", @@ -39,6 +39,7 @@ "@typescript-eslint/parser": "^7.3.1", "chai": "^4.2.0", "chain": "^0.4.0", + "dotenv": "^16.4.1", "eslint": "^8.57.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.1", @@ -53,8 +54,7 @@ "solidity-coverage": "^0.8.0", "ts-node": ">=8.0.0", "tslint-config-prettier": "^1.18.0", - "typescript": "5.3.3", - "dotenv": "^16.4.1" + "typescript": "5.3.3" }, "dependencies": { "hardhat": "^2.17.4", diff --git a/src/contracts/handlers/FeeHandlerRouter.sol b/src/contracts/handlers/FeeHandlerRouter.sol index 727a71ea..79c90aa6 100755 --- a/src/contracts/handlers/FeeHandlerRouter.sol +++ b/src/contracts/handlers/FeeHandlerRouter.sol @@ -3,6 +3,7 @@ pragma solidity 0.8.11; import "../interfaces/IFeeHandler.sol"; +import "../interfaces/IBridge.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; /** @@ -11,7 +12,7 @@ import "@openzeppelin/contracts/access/AccessControl.sol"; @notice This contract is intended to be used with the Bridge contract. */ contract FeeHandlerRouter is IFeeHandler, AccessControl { - address public immutable _routerAddress; + IBridge public immutable _bridge; // domainID => resourceID => securityModel => feeHandlerAddress mapping(uint8 => mapping(bytes32 => mapping(uint8 => IFeeHandler))) public @@ -32,8 +33,8 @@ contract FeeHandlerRouter is IFeeHandler, AccessControl { _; } - function _onlyRouter() private view { - if (msg.sender != _routerAddress) revert SenderNotRouterContract(); + function _onlyRouter() private { + if (msg.sender != _bridge._routerAddress()) revert SenderNotRouterContract(); } modifier onlyAdmin() { @@ -46,10 +47,10 @@ contract FeeHandlerRouter is IFeeHandler, AccessControl { } /** - @param routerAddress Contract address of previously deployed Router. + @param bridge Contract address of previously deployed Bridge. */ - constructor(address routerAddress) { - _routerAddress = routerAddress; + constructor(IBridge bridge) { + _bridge = bridge; _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); } diff --git a/src/contracts/handlers/PermissionlessGenericHandler.sol b/src/contracts/handlers/PermissionlessGenericHandler.sol index cf966e37..f91c99c1 100755 --- a/src/contracts/handlers/PermissionlessGenericHandler.sol +++ b/src/contracts/handlers/PermissionlessGenericHandler.sol @@ -3,6 +3,7 @@ pragma solidity 0.8.11; import "../interfaces/IHandler.sol"; +import "../interfaces/IBridge.sol"; /** @title Handles generic deposits and deposit executions. @@ -12,8 +13,7 @@ import "../interfaces/IHandler.sol"; contract PermissionlessGenericHandler is IHandler { uint256 public constant MAX_FEE = 1000000; - address public immutable _bridgeAddress; - address public immutable _executorAddress; + IBridge public immutable _bridge; modifier onlyBridge() { _onlyBridge(); @@ -27,7 +27,7 @@ contract PermissionlessGenericHandler is IHandler { error InvalidExecutioDataDepositor(address executioDataDepositor); function _onlyBridge() private view { - if (msg.sender != _bridgeAddress) revert SenderNotBridgeContract(); + if (msg.sender != address(_bridge)) revert SenderNotBridgeContract(); } modifier onlyExecutor() { @@ -35,17 +35,15 @@ contract PermissionlessGenericHandler is IHandler { _; } - function _onlyExecutor() private view { - if (msg.sender != _executorAddress) revert SenderNotExecutorContract(); + function _onlyExecutor() private { + if (msg.sender != _bridge._executorAddress()) revert SenderNotExecutorContract(); } /** - @param bridgeAddress Contract address of previously deployed Bridge. - @param executorAddress Contract address of previously deployed Executor. + @param bridge Contract address of previously deployed Bridge. */ - constructor(address bridgeAddress, address executorAddress) { - _bridgeAddress = bridgeAddress; - _executorAddress = executorAddress; + constructor(IBridge bridge) { + _bridge = bridge; } /** diff --git a/src/contracts/handlers/fee/BasicFeeHandler.sol b/src/contracts/handlers/fee/BasicFeeHandler.sol index 9a1224b0..7bb6eb04 100755 --- a/src/contracts/handlers/fee/BasicFeeHandler.sol +++ b/src/contracts/handlers/fee/BasicFeeHandler.sol @@ -3,6 +3,7 @@ pragma solidity 0.8.11; import "../../interfaces/IFeeHandler.sol"; +import "../../interfaces/IBridge.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; import "../FeeHandlerRouter.sol"; @@ -13,9 +14,8 @@ import "../FeeHandlerRouter.sol"; @notice This contract is intended to be used with the Bridge contract. */ contract BasicFeeHandler is IFeeHandler, AccessControl { - address public immutable _bridgeAddress; + IBridge public immutable _bridge; address public immutable _feeHandlerRouterAddress; - address public immutable _routerAddress; // domainID => resourceID => securityModel => fee mapping (uint8 => mapping(bytes32 => mapping(uint8 => uint256))) public _domainResourceIDSecurityModelToFee; @@ -44,25 +44,23 @@ contract BasicFeeHandler is IFeeHandler, AccessControl { _; } - function _onlyRouterOrFeeRouter() private view { + function _onlyRouterOrFeeRouter() private { if (msg.sender != _feeHandlerRouterAddress && - msg.sender != _routerAddress + msg.sender != _bridge._routerAddress() ) revert SenderNotBridgeOrRouter(); } /** - @param bridgeAddress Contract address of previously deployed Bridge. + @param bridge Contract address of previously deployed Bridge. @param feeHandlerRouterAddress Contract address of previously deployed FeeHandlerRouter. */ - constructor(address bridgeAddress, address feeHandlerRouterAddress, address routerAddress) { - if (bridgeAddress == address(0) || - feeHandlerRouterAddress == address(0) || - routerAddress == address(0) + constructor(IBridge bridge, address feeHandlerRouterAddress) { + if (address(bridge) == address(0) || + feeHandlerRouterAddress == address(0) ) revert ZeroAddressProvided(); - _bridgeAddress = bridgeAddress; + _bridge = bridge; _feeHandlerRouterAddress = feeHandlerRouterAddress; - _routerAddress = routerAddress; _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); } diff --git a/src/contracts/handlers/fee/PercentageERC20FeeHandlerEVM.sol b/src/contracts/handlers/fee/PercentageERC20FeeHandlerEVM.sol index 0d4d0a4a..f05411b8 100755 --- a/src/contracts/handlers/fee/PercentageERC20FeeHandlerEVM.sol +++ b/src/contracts/handlers/fee/PercentageERC20FeeHandlerEVM.sol @@ -34,14 +34,13 @@ contract PercentageERC20FeeHandlerEVM is BasicFeeHandler, ERC20Safe { error NewBoundsEqualCurrentBounds(uint128 currentLowerBound, uint128 currentUpperBound); /** - @param bridgeAddress Contract address of previously deployed Bridge. + @param bridge Contract address of previously deployed Bridge. @param feeHandlerRouterAddress Contract address of previously deployed FeeHandlerRouter. */ constructor( - address bridgeAddress, - address feeHandlerRouterAddress, - address routerAddress - ) BasicFeeHandler(bridgeAddress, feeHandlerRouterAddress, routerAddress) {} + IBridge bridge, + address feeHandlerRouterAddress + ) BasicFeeHandler(bridge, feeHandlerRouterAddress) {} // Admin functions @@ -86,7 +85,7 @@ contract PercentageERC20FeeHandlerEVM is BasicFeeHandler, ERC20Safe { bytes calldata depositData, bytes calldata feeData ) internal view returns (uint256 fee, address tokenAddress) { - address tokenHandler = IBridge(_bridgeAddress)._resourceIDToHandlerAddress(resourceID); + address tokenHandler = _bridge._resourceIDToHandlerAddress(resourceID); tokenAddress = IERCHandler(tokenHandler)._resourceIDToTokenContractAddress(resourceID); Bounds memory bounds = _resourceIDToFeeBounds[resourceID]; @@ -182,7 +181,7 @@ contract PercentageERC20FeeHandlerEVM is BasicFeeHandler, ERC20Safe { addrs.length, amounts.length ); - address tokenHandler = IBridge(_bridgeAddress)._resourceIDToHandlerAddress(resourceID); + address tokenHandler = _bridge._resourceIDToHandlerAddress(resourceID); address tokenAddress = IERCHandler(tokenHandler)._resourceIDToTokenContractAddress(resourceID); for (uint256 i = 0; i < addrs.length; i++) { releaseERC20(tokenAddress, addrs[i], amounts[i]); diff --git a/test/handlers/fee/basic/admin.test.ts b/test/handlers/fee/basic/admin.test.ts index 1a530ce5..8b27dbdb 100755 --- a/test/handlers/fee/basic/admin.test.ts +++ b/test/handlers/fee/basic/admin.test.ts @@ -9,7 +9,6 @@ import { ethers } from "hardhat"; import type { BasicFeeHandler, Bridge, - Router, FeeHandlerRouter, ERC20PresetMinterPauser, } from "../../../../typechain-types"; @@ -22,7 +21,6 @@ describe("BasicFeeHandler - [admin]", () => { const securityModel = 1; let bridgeInstance: Bridge; - let routerInstance: Router; let basicFeeHandlerInstance: BasicFeeHandler; let originERC20MintableInstance: ERC20PresetMinterPauser; let feeHandlerRouterInstance: FeeHandlerRouter; @@ -37,7 +35,7 @@ describe("BasicFeeHandler - [admin]", () => { [currentFeeHandlerAdmin, newBasicFeeHandlerAdmin, nonAdminAccount] = await ethers.getSigners(); - [bridgeInstance, routerInstance] = await deployBridgeContracts( + [bridgeInstance] = await deployBridgeContracts( originDomainID, routerAddress, ); @@ -51,7 +49,6 @@ describe("BasicFeeHandler - [admin]", () => { basicFeeHandlerInstance = await BasicFeeHandlerContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); const ERC20PresetMinterPauserContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", diff --git a/test/handlers/fee/basic/calculateFee.test.ts b/test/handlers/fee/basic/calculateFee.test.ts index 453aa45c..85497c69 100755 --- a/test/handlers/fee/basic/calculateFee.test.ts +++ b/test/handlers/fee/basic/calculateFee.test.ts @@ -11,7 +11,6 @@ import type { ERC20Handler, ERC20PresetMinterPauser, FeeHandlerRouter, - Router, } from "../../../../typechain-types"; import { deployBridgeContracts, @@ -29,7 +28,6 @@ describe("BasicFeeHandler - [calculateFee]", () => { const securityModel = 1; let bridgeInstance: Bridge; - let routerInstance: Router; let ERC20MintableInstance: ERC20PresetMinterPauser; let ERC20HandlerInstance: ERC20Handler; let feeHandlerRouterInstance: FeeHandlerRouter; @@ -43,7 +41,7 @@ describe("BasicFeeHandler - [calculateFee]", () => { beforeEach(async () => { [, , recipientAccount, relayer1] = await ethers.getSigners(); - [bridgeInstance, routerInstance] = await deployBridgeContracts( + [bridgeInstance] = await deployBridgeContracts( originDomainID, routerAddress, ); @@ -66,7 +64,6 @@ describe("BasicFeeHandler - [calculateFee]", () => { basicFeeHandlerInstance = await BasicFeeHandlerContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); resourceID = createResourceID( diff --git a/test/handlers/fee/basic/changeFee.test.ts b/test/handlers/fee/basic/changeFee.test.ts index 3d7fe053..8376c64c 100755 --- a/test/handlers/fee/basic/changeFee.test.ts +++ b/test/handlers/fee/basic/changeFee.test.ts @@ -8,7 +8,6 @@ import { ethers } from "hardhat"; import type { BasicFeeHandler, Bridge, - Router, FeeHandlerRouter, ERC20PresetMinterPauser, } from "../../../../typechain-types"; @@ -21,7 +20,6 @@ describe("BasicFeeHandler - [changeFee]", () => { const securityModel = 1; let bridgeInstance: Bridge; - let routerInstance: Router; let basicFeeHandlerInstance: BasicFeeHandler; let originERC20MintableInstance: ERC20PresetMinterPauser; let feeHandlerRouterInstance: FeeHandlerRouter; @@ -32,7 +30,7 @@ describe("BasicFeeHandler - [changeFee]", () => { beforeEach(async () => { [, nonAdminAccount] = await ethers.getSigners(); - [bridgeInstance, routerInstance] = await deployBridgeContracts( + [bridgeInstance] = await deployBridgeContracts( originDomainID, routerAddress, ); @@ -46,7 +44,6 @@ describe("BasicFeeHandler - [changeFee]", () => { basicFeeHandlerInstance = await BasicFeeHandlerContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); const ERC20PresetMinterPauserContract = await ethers.getContractFactory( "ERC20PresetMinterPauser", diff --git a/test/handlers/fee/basic/collectFee.test.ts b/test/handlers/fee/basic/collectFee.test.ts index 910666b0..54bb66fe 100755 --- a/test/handlers/fee/basic/collectFee.test.ts +++ b/test/handlers/fee/basic/collectFee.test.ts @@ -59,14 +59,13 @@ describe("BasicFeeHandler - [collectFee]", () => { const FeeHandlerRouterContract = await ethers.getContractFactory("FeeHandlerRouter"); feeHandlerRouterInstance = await FeeHandlerRouterContract.deploy( - await routerInstance.getAddress(), + await bridgeInstance.getAddress(), ); const BasicFeeHandlerContract = await ethers.getContractFactory("BasicFeeHandler"); basicFeeHandlerInstance = await BasicFeeHandlerContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); erc20ResourceID = createResourceID( await ERC20MintableInstance.getAddress(), diff --git a/test/handlers/fee/basic/constructor.test.ts b/test/handlers/fee/basic/constructor.test.ts index 6601be6d..3da4844e 100644 --- a/test/handlers/fee/basic/constructor.test.ts +++ b/test/handlers/fee/basic/constructor.test.ts @@ -9,11 +9,7 @@ describe("BasicFeeHandler - [constructor]", () => { const BasicFeeHandlerContract = await ethers.getContractFactory("BasicFeeHandler"); await expect( - BasicFeeHandlerContract.deploy( - ethers.ZeroAddress, - ethers.ZeroAddress, - ethers.ZeroAddress, - ), + BasicFeeHandlerContract.deploy(ethers.ZeroAddress, ethers.ZeroAddress), ).to.be.revertedWithCustomError( BasicFeeHandlerContract, "ZeroAddressProvided", diff --git a/test/handlers/fee/basic/distributeFee.test.ts b/test/handlers/fee/basic/distributeFee.test.ts index 97f85a3a..d0c72b75 100755 --- a/test/handlers/fee/basic/distributeFee.test.ts +++ b/test/handlers/fee/basic/distributeFee.test.ts @@ -67,14 +67,13 @@ describe("BasicFeeHandler - [distributeFee]", () => { const FeeHandlerRouterContract = await ethers.getContractFactory("FeeHandlerRouter"); feeHandlerRouterInstance = await FeeHandlerRouterContract.deploy( - await routerInstance.getAddress(), + await bridgeInstance.getAddress(), ); const BasicFeeHandlerContract = await ethers.getContractFactory("BasicFeeHandler"); basicFeeHandlerInstance = await BasicFeeHandlerContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); resourceID = createResourceID( diff --git a/test/handlers/fee/handlerRouter.test.ts b/test/handlers/fee/handlerRouter.test.ts index 4ed9d684..c016774e 100755 --- a/test/handlers/fee/handlerRouter.test.ts +++ b/test/handlers/fee/handlerRouter.test.ts @@ -2,11 +2,16 @@ // SPDX-License-Identifier: LGPL-3.0-only import type { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers"; +import { + impersonateAccount, + setBalance, +} from "@nomicfoundation/hardhat-network-helpers"; import { assert, expect } from "chai"; import { ethers } from "hardhat"; import type { BasicFeeHandler, + Bridge, ERC20PresetMinterPauser, FeeHandlerRouter, Router, @@ -24,6 +29,7 @@ describe("FeeHandlerRouter", () => { const routerAddress = "0x1a60efB48c61A79515B170CA61C84DD6dCA80418"; const securityModel = 1; + let bridgeInstance: Bridge; let routerInstance: Router; let ERC20MintableInstance: ERC20PresetMinterPauser; let feeHandlerRouterInstance: FeeHandlerRouter; @@ -33,7 +39,6 @@ describe("FeeHandlerRouter", () => { let whitelistedAccount: HardhatEthersSigner; let nonWhitelistedAccount: HardhatEthersSigner; let recipientAccount: HardhatEthersSigner; - let bridgeInstance: HardhatEthersSigner; let resourceID: string; @@ -45,10 +50,9 @@ describe("FeeHandlerRouter", () => { nonAdminAccount, whitelistedAccount, nonWhitelistedAccount, - bridgeInstance, ] = await ethers.getSigners(); - [, routerInstance] = await deployBridgeContracts( + [bridgeInstance, routerInstance] = await deployBridgeContracts( originDomainID, routerAddress, ); @@ -67,7 +71,6 @@ describe("FeeHandlerRouter", () => { basicFeeHandlerInstance = await BasicFeeHandlerContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); resourceID = createResourceID( await ERC20MintableInstance.getAddress(), @@ -189,6 +192,13 @@ describe("FeeHandlerRouter", () => { }); it("should revert if whitelisted address provides fee", async () => { + // this is used to impersonate a call from Router contract + // because ethersjs requires a signer to be passed into connect function + const routerInstanceAddress = await routerInstance.getAddress(); + const routerContractSigner = await ethers.getSigner(routerInstanceAddress); + await setBalance(routerInstanceAddress, 10n ** 18n); + await impersonateAccount(routerInstanceAddress); + await feeHandlerRouterInstance.adminSetWhitelist( await whitelistedAccount.getAddress(), true, @@ -213,7 +223,7 @@ describe("FeeHandlerRouter", () => { ); await expect( feeHandlerRouterInstance - .connect(bridgeInstance) + .connect(routerContractSigner) .collectFee( await whitelistedAccount.getAddress(), originDomainID, @@ -233,7 +243,7 @@ describe("FeeHandlerRouter", () => { await expect( feeHandlerRouterInstance - .connect(bridgeInstance) + .connect(routerContractSigner) .collectFee( nonWhitelistedAccount.getAddress(), originDomainID, @@ -250,6 +260,13 @@ describe("FeeHandlerRouter", () => { }); it("should not collect fee from whitelisted address", async () => { + // this is used to impersonate a call from Router contract + // because ethersjs requires a signer to be passed into connect function + const routerInstanceAddress = await routerInstance.getAddress(); + const routerContractSigner = await ethers.getSigner(routerInstanceAddress); + await setBalance(routerInstanceAddress, 10n ** 18n); + await impersonateAccount(routerInstanceAddress); + await feeHandlerRouterInstance.adminSetWhitelist( await whitelistedAccount.getAddress(), true, @@ -274,7 +291,7 @@ describe("FeeHandlerRouter", () => { ); await expect( feeHandlerRouterInstance - .connect(bridgeInstance) + .connect(routerContractSigner) .collectFee( await whitelistedAccount.getAddress(), originDomainID, @@ -284,7 +301,6 @@ describe("FeeHandlerRouter", () => { depositData, feeData, { - from: await bridgeInstance.getAddress(), value: "0", }, ), diff --git a/test/handlers/fee/percentage/admin.test.ts b/test/handlers/fee/percentage/admin.test.ts index 4163df31..f4d3acb3 100755 --- a/test/handlers/fee/percentage/admin.test.ts +++ b/test/handlers/fee/percentage/admin.test.ts @@ -10,7 +10,6 @@ import type { ERC20PresetMinterPauser, FeeHandlerRouter, PercentageERC20FeeHandlerEVM, - Router, } from "../../../../typechain-types"; import { deployBridgeContracts, createResourceID } from "../../../helpers"; @@ -21,7 +20,6 @@ describe("PercentageFeeHandler - [admin]", () => { const securityModel = 1; let bridgeInstance: Bridge; - let routerInstance: Router; let percentageFeeHandlerInstance: PercentageERC20FeeHandlerEVM; let ERC20MintableInstance: ERC20PresetMinterPauser; let feeHandlerRouterInstance: FeeHandlerRouter; @@ -36,7 +34,7 @@ describe("PercentageFeeHandler - [admin]", () => { [currentFeeHandlerAdmin, newPercentageFeeHandlerAdmin, nonAdminAccount] = await ethers.getSigners(); - [bridgeInstance, routerInstance] = await deployBridgeContracts( + [bridgeInstance] = await deployBridgeContracts( originDomainID, routerAddress, ); @@ -55,7 +53,6 @@ describe("PercentageFeeHandler - [admin]", () => { await PercentageERC20FeeHandlerEVMContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); ADMIN_ROLE = await percentageFeeHandlerInstance.DEFAULT_ADMIN_ROLE(); diff --git a/test/handlers/fee/percentage/calculateFee.test.ts b/test/handlers/fee/percentage/calculateFee.test.ts index 431877b5..033a7c9d 100755 --- a/test/handlers/fee/percentage/calculateFee.test.ts +++ b/test/handlers/fee/percentage/calculateFee.test.ts @@ -6,7 +6,6 @@ import { ethers } from "hardhat"; import type { Bridge, - Router, ERC20Handler, ERC20PresetMinterPauser, FeeHandlerRouter, @@ -27,7 +26,6 @@ describe("PercentageFeeHandler - [calculateFee]", () => { const securityModel = 1; let bridgeInstance: Bridge; - let routerInstance: Router; let percentageFeeHandlerInstance: PercentageERC20FeeHandlerEVM; let ERC20MintableInstance: ERC20PresetMinterPauser; let ERC20HandlerInstance: ERC20Handler; @@ -40,7 +38,7 @@ describe("PercentageFeeHandler - [calculateFee]", () => { beforeEach(async () => { [, recipientAccount, relayer] = await ethers.getSigners(); - [bridgeInstance, routerInstance] = await deployBridgeContracts( + [bridgeInstance] = await deployBridgeContracts( originDomainID, routerAddress, ); @@ -64,7 +62,6 @@ describe("PercentageFeeHandler - [calculateFee]", () => { await PercentageERC20FeeHandlerEVMContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); resourceID = createResourceID( diff --git a/test/handlers/fee/percentage/changeFee.test.ts b/test/handlers/fee/percentage/changeFee.test.ts index b641f8ae..2cf60a1e 100755 --- a/test/handlers/fee/percentage/changeFee.test.ts +++ b/test/handlers/fee/percentage/changeFee.test.ts @@ -11,7 +11,6 @@ import type { FeeHandlerRouter, PercentageERC20FeeHandlerEVM, PercentageERC20FeeHandlerEVM__factory, - Router, } from "../../../../typechain-types"; import { deployBridgeContracts, createResourceID } from "../../../helpers"; @@ -22,7 +21,6 @@ describe("PercentageFeeHandler - [change fee and bounds]", () => { const securityModel = 1; let bridgeInstance: Bridge; - let routerInstance: Router; let percentageFeeHandlerInstance: PercentageERC20FeeHandlerEVM; let ERC20MintableInstance: ERC20PresetMinterPauser; let PercentageFeeHandlerContract: PercentageERC20FeeHandlerEVM__factory; @@ -33,7 +31,7 @@ describe("PercentageFeeHandler - [change fee and bounds]", () => { beforeEach(async () => { [, nonAdminAddress] = await ethers.getSigners(); - [bridgeInstance, routerInstance] = await deployBridgeContracts( + [bridgeInstance] = await deployBridgeContracts( originDomainID, routerAddress, ); @@ -52,7 +50,6 @@ describe("PercentageFeeHandler - [change fee and bounds]", () => { percentageFeeHandlerInstance = await PercentageFeeHandlerContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); resourceID = createResourceID( @@ -133,7 +130,6 @@ describe("PercentageFeeHandler - [change fee and bounds]", () => { await PercentageFeeHandlerContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); await percentageFeeHandlerInstance.changeFeeBounds(resourceID, 25, 50); await expect( @@ -149,7 +145,6 @@ describe("PercentageFeeHandler - [change fee and bounds]", () => { await PercentageFeeHandlerContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); await expect( percentageFeeHandlerInstance.changeFeeBounds(resourceID, 50, 25), @@ -165,7 +160,6 @@ describe("PercentageFeeHandler - [change fee and bounds]", () => { await PercentageFeeHandlerContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); await percentageFeeHandlerInstance.changeFeeBounds(resourceID, 25, 50); await percentageFeeHandlerInstance.changeFeeBounds( @@ -185,7 +179,6 @@ describe("PercentageFeeHandler - [change fee and bounds]", () => { await PercentageFeeHandlerContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); await percentageFeeHandlerInstance.changeFeeBounds(resourceID, 25, 50); await percentageFeeHandlerInstance.changeFeeBounds( @@ -204,7 +197,6 @@ describe("PercentageFeeHandler - [change fee and bounds]", () => { await PercentageFeeHandlerContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); await expect( percentageFeeHandlerInstance diff --git a/test/handlers/fee/percentage/collectFee.test.ts b/test/handlers/fee/percentage/collectFee.test.ts index 688d2418..99081da5 100755 --- a/test/handlers/fee/percentage/collectFee.test.ts +++ b/test/handlers/fee/percentage/collectFee.test.ts @@ -65,7 +65,7 @@ describe("PercentageFeeHandler - [collectFee]", () => { const FeeHandlerRouterContract = await ethers.getContractFactory("FeeHandlerRouter"); feeHandlerRouterInstance = await FeeHandlerRouterContract.deploy( - await routerInstance.getAddress(), + await bridgeInstance.getAddress(), ); const PercentageERC20FeeHandlerEVMContract = await ethers.getContractFactory("PercentageERC20FeeHandlerEVM"); @@ -73,7 +73,6 @@ describe("PercentageFeeHandler - [collectFee]", () => { await PercentageERC20FeeHandlerEVMContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); resourceID = createResourceID( diff --git a/test/handlers/fee/percentage/distributeFee.test.ts b/test/handlers/fee/percentage/distributeFee.test.ts index ca50f903..b1d6d492 100644 --- a/test/handlers/fee/percentage/distributeFee.test.ts +++ b/test/handlers/fee/percentage/distributeFee.test.ts @@ -71,7 +71,7 @@ describe("PercentageFeeHandler - [distributeFee]", () => { const FeeHandlerRouterContract = await ethers.getContractFactory("FeeHandlerRouter"); feeHandlerRouterInstance = await FeeHandlerRouterContract.deploy( - await routerInstance.getAddress(), + await bridgeInstance.getAddress(), ); const PercentageERC20FeeHandlerEVMContract = await ethers.getContractFactory("PercentageERC20FeeHandlerEVM"); @@ -79,7 +79,6 @@ describe("PercentageFeeHandler - [distributeFee]", () => { await PercentageERC20FeeHandlerEVMContract.deploy( await bridgeInstance.getAddress(), await feeHandlerRouterInstance.getAddress(), - await routerInstance.getAddress(), ); resourceID = createResourceID( diff --git a/test/handlers/generic/permissionlessDeposit.test.ts b/test/handlers/generic/permissionlessDeposit.test.ts index d55bb84a..63f87fd5 100755 --- a/test/handlers/generic/permissionlessDeposit.test.ts +++ b/test/handlers/generic/permissionlessDeposit.test.ts @@ -8,7 +8,6 @@ import { ethers } from "hardhat"; import type { Bridge, Router, - Executor, PermissionlessGenericHandler, TestStore, } from "../../../typechain-types"; @@ -32,7 +31,6 @@ describe("PermissionlessGenericHandler - [deposit]", () => { let bridgeInstance: Bridge; let routerInstance: Router; - let executorInstance: Executor; let permissionlessGenericHandlerInstance: PermissionlessGenericHandler; let testStoreInstance: TestStore; let depositorAccount: HardhatEthersSigner; @@ -45,14 +43,15 @@ describe("PermissionlessGenericHandler - [deposit]", () => { beforeEach(async () => { [, depositorAccount, invalidDepositorAccount] = await ethers.getSigners(); - [bridgeInstance, routerInstance, executorInstance] = - await deployBridgeContracts(originDomainID, routerAddress); + [bridgeInstance, routerInstance] = await deployBridgeContracts( + originDomainID, + routerAddress, + ); const PermissionlessGenericHandlerContract = await ethers.getContractFactory("PermissionlessGenericHandler"); permissionlessGenericHandlerInstance = await PermissionlessGenericHandlerContract.deploy( await bridgeInstance.getAddress(), - await executorInstance.getAddress(), ); const TestStoreContract = await ethers.getContractFactory("TestStore"); testStoreInstance = await TestStoreContract.deploy(); diff --git a/test/handlers/generic/permissionlessExecuteProposal/executionWithEvents.test.ts b/test/handlers/generic/permissionlessExecuteProposal/executionWithEvents.test.ts index 53fe9ea1..62e83545 100755 --- a/test/handlers/generic/permissionlessExecuteProposal/executionWithEvents.test.ts +++ b/test/handlers/generic/permissionlessExecuteProposal/executionWithEvents.test.ts @@ -76,7 +76,6 @@ describe("PermissionlessGenericHandler - [Execute Proposal] - TestStore", () => permissionlessGenericHandlerInstance = await PermissionlessGenericHandlerContract.deploy( await bridgeInstance.getAddress(), - await executorInstance.getAddress(), ); [testStoreInstance] = await deployMockTestContracts( diff --git a/test/handlers/generic/permissionlessExecuteProposal/gasTooSmall.test.ts b/test/handlers/generic/permissionlessExecuteProposal/gasTooSmall.test.ts index 4b661693..d869124c 100644 --- a/test/handlers/generic/permissionlessExecuteProposal/gasTooSmall.test.ts +++ b/test/handlers/generic/permissionlessExecuteProposal/gasTooSmall.test.ts @@ -75,7 +75,6 @@ describe("PermissionlessGenericHandler - [Execute Proposal] - Gas to small", () permissionlessGenericHandlerInstance = await PermissionlessGenericHandlerContract.deploy( await bridgeInstance.getAddress(), - await executorInstance.getAddress(), ); [testStoreInstance, testDepositInstance] = await deployMockTestContracts( diff --git a/test/handlers/generic/permissionlessExecuteProposal/packedDepositData.test.ts b/test/handlers/generic/permissionlessExecuteProposal/packedDepositData.test.ts index fa67a459..64f527ef 100644 --- a/test/handlers/generic/permissionlessExecuteProposal/packedDepositData.test.ts +++ b/test/handlers/generic/permissionlessExecuteProposal/packedDepositData.test.ts @@ -68,7 +68,6 @@ describe("PermissionlessGenericHandler - [Execute Proposal] - packed deposit dat permissionlessGenericHandlerInstance = await PermissionlessGenericHandlerContract.deploy( await bridgeInstance.getAddress(), - await executorInstance.getAddress(), ); [testStoreInstance, testDepositInstance] = await deployMockTestContracts( diff --git a/test/handlers/generic/permissionlessExecuteProposal/unpackedDepositData.test.ts b/test/handlers/generic/permissionlessExecuteProposal/unpackedDepositData.test.ts index bbacd759..e1697b37 100644 --- a/test/handlers/generic/permissionlessExecuteProposal/unpackedDepositData.test.ts +++ b/test/handlers/generic/permissionlessExecuteProposal/unpackedDepositData.test.ts @@ -69,7 +69,6 @@ describe("PermissionlessGenericHandler - [Execute Proposal] - Unpacked deposit d permissionlessGenericHandlerInstance = await PermissionlessGenericHandlerContract.deploy( await bridgeInstance.getAddress(), - await executorInstance.getAddress(), ); [testStoreInstance, testDepositInstance] = await deployMockTestContracts( diff --git a/yarn.lock b/yarn.lock index c9292f66..f6f06e99 100644 --- a/yarn.lock +++ b/yarn.lock @@ -815,7 +815,7 @@ debug "^4.1.1" lodash.isequal "^4.5.0" -"@nomicfoundation/hardhat-network-helpers@^1.0.9": +"@nomicfoundation/hardhat-network-helpers@^1.0.10": version "1.0.10" resolved "https://registry.yarnpkg.com/@nomicfoundation/hardhat-network-helpers/-/hardhat-network-helpers-1.0.10.tgz#c61042ceb104fdd6c10017859fdef6529c1d6585" integrity sha512-R35/BMBlx7tWN5V6d/8/19QCwEmIdbnA4ZrsuXgvs8i2qFx5i7h6mH5pBS4Pwi4WigLH+upl6faYusrNPuzMrQ==