From 4129a12a63587606062eecdc842e21368927f57d Mon Sep 17 00:00:00 2001 From: sibghatullah1997 Date: Wed, 3 Jan 2024 03:51:05 +0500 Subject: [PATCH 01/10] swap functionality for native currency added --- contracts/common/{uniswap => }/IWETH.sol | 0 contracts/upgradeable-Bridge/FiberRouter.sol | 72 ++++++++++++++++++++ 2 files changed, 72 insertions(+) rename contracts/common/{uniswap => }/IWETH.sol (100%) diff --git a/contracts/common/uniswap/IWETH.sol b/contracts/common/IWETH.sol similarity index 100% rename from contracts/common/uniswap/IWETH.sol rename to contracts/common/IWETH.sol diff --git a/contracts/upgradeable-Bridge/FiberRouter.sol b/contracts/upgradeable-Bridge/FiberRouter.sol index b504712..954982d 100644 --- a/contracts/upgradeable-Bridge/FiberRouter.sol +++ b/contracts/upgradeable-Bridge/FiberRouter.sol @@ -6,6 +6,7 @@ import "../common/tokenReceiveable.sol"; import "../common/SafeAmount.sol"; import "../common/oneInch/OneInchDecoder.sol"; import "../common/oneInch/IOneInchSwap.sol"; +import "../common/IWETH.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; /** @@ -16,6 +17,8 @@ contract FiberRouter is Ownable, TokenReceivable { using SafeERC20 for IERC20; address public pool; address public oneInchAggregatorRouter; + address public weth; + event Swap( address sourceToken, @@ -104,6 +107,18 @@ contract FiberRouter is Ownable, TokenReceivable { oneInchAggregatorRouter = _newRouterAddress; } + // Function to set the weth address + function setWeth(address _weth) + external + onlyOwner + { + require( + _weth != address(0), + "weth address cannot be zero" + ); + weth = _weth; + } + /* @notice Initiate an x-chain swap. @param token The source token to be swaped @@ -370,6 +385,63 @@ contract FiberRouter is Ownable, TokenReceivable { ); } + /** + @notice Performs a local ETH swap and generates a cross-chain swap + @param amountOut Expected output amount on oneInch + @param crossTargetNetwork Target network for the cross-chain swap + @param crossTargetToken Token address on the target network + @param crossTargetAddress Address receiving the tokens on the target network + @param oneInchData Encoded data for oneInch swap + @param foundryToken Foundry token address involved in the swap + @param withdrawalData Data related to withdrawal in the swap process + */ + function swapAndCrossOneInchETH( + uint256 amountOut, // amountOut on oneInch + uint256 crossTargetNetwork, + address crossTargetToken, + address crossTargetAddress, + bytes memory oneInchData, + address foundryToken, + bytes32 withdrawalData + ) external payable { + uint256 amountIn = msg.value; + + // Validation checks + require(amountIn != 0, "FR: Amount in must be greater than zero"); + require(amountOut != 0, "FR: Amount out must be greater than zero"); + require(crossTargetToken != address(0), "FR: Cross target token address cannot be zero"); + require(bytes(oneInchData).length != 0, "FR: 1inch data cannot be empty"); + require(foundryToken != address(0), "FR: Foundry token address cannot be zero"); + require(withdrawalData != 0, "FR: Withdraw data cannot be empty"); + + // Deposit ETH and get WETH + IWETH(weth).deposit{value: amountIn}(); + + // Execute swap and cross-chain operation + uint256 settledAmount = _swapAndCrossOneInch( + amountIn, + amountOut, + crossTargetNetwork, + crossTargetAddress, + oneInchData, + weth, + foundryToken + ); + + // Emit Swap event + emit Swap( + weth, + crossTargetToken, + block.chainid, + crossTargetNetwork, + amountIn, + _msgSender(), + crossTargetAddress, + settledAmount, + withdrawalData + ); + } + /* @notice Withdraws funds based on a multisig @dev For signature swapToToken must be the same as token From 8665bed74db26da5fb4af418a228c2b8752cdbe9 Mon Sep 17 00:00:00 2001 From: sibghatullah1997 Date: Wed, 3 Jan 2024 04:00:51 +0500 Subject: [PATCH 02/10] weth address type changed to constant --- contracts/upgradeable-Bridge/FiberRouter.sol | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/contracts/upgradeable-Bridge/FiberRouter.sol b/contracts/upgradeable-Bridge/FiberRouter.sol index 954982d..447c075 100644 --- a/contracts/upgradeable-Bridge/FiberRouter.sol +++ b/contracts/upgradeable-Bridge/FiberRouter.sol @@ -17,8 +17,7 @@ contract FiberRouter is Ownable, TokenReceivable { using SafeERC20 for IERC20; address public pool; address public oneInchAggregatorRouter; - address public weth; - + address public constant WETH = 0xc778417E063141139Fce010982780140Aa0cD5Ab; //need to change for every blockchain event Swap( address sourceToken, @@ -107,18 +106,6 @@ contract FiberRouter is Ownable, TokenReceivable { oneInchAggregatorRouter = _newRouterAddress; } - // Function to set the weth address - function setWeth(address _weth) - external - onlyOwner - { - require( - _weth != address(0), - "weth address cannot be zero" - ); - weth = _weth; - } - /* @notice Initiate an x-chain swap. @param token The source token to be swaped From b3d3e0243ef388d428983ebbde48c52919d9dbea Mon Sep 17 00:00:00 2001 From: sibghatullah1997 Date: Wed, 3 Jan 2024 04:09:56 +0500 Subject: [PATCH 03/10] WETH typos issuse fixed --- contracts/upgradeable-Bridge/FiberRouter.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/upgradeable-Bridge/FiberRouter.sol b/contracts/upgradeable-Bridge/FiberRouter.sol index 447c075..0884fdf 100644 --- a/contracts/upgradeable-Bridge/FiberRouter.sol +++ b/contracts/upgradeable-Bridge/FiberRouter.sol @@ -402,7 +402,7 @@ contract FiberRouter is Ownable, TokenReceivable { require(withdrawalData != 0, "FR: Withdraw data cannot be empty"); // Deposit ETH and get WETH - IWETH(weth).deposit{value: amountIn}(); + IWETH(WETH).deposit{value: amountIn}(); // Execute swap and cross-chain operation uint256 settledAmount = _swapAndCrossOneInch( @@ -411,13 +411,13 @@ contract FiberRouter is Ownable, TokenReceivable { crossTargetNetwork, crossTargetAddress, oneInchData, - weth, + WETH, foundryToken ); // Emit Swap event emit Swap( - weth, + WETH, crossTargetToken, block.chainid, crossTargetNetwork, From bb42364873a4706042163a1ecbc766acfe1b961d Mon Sep 17 00:00:00 2001 From: sibghatullah1997 Date: Wed, 3 Jan 2024 11:56:27 +0500 Subject: [PATCH 04/10] constructor added to setting the values in contract --- contracts/upgradeable-Bridge/FiberRouter.sol | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/contracts/upgradeable-Bridge/FiberRouter.sol b/contracts/upgradeable-Bridge/FiberRouter.sol index 0884fdf..cabb2b0 100644 --- a/contracts/upgradeable-Bridge/FiberRouter.sol +++ b/contracts/upgradeable-Bridge/FiberRouter.sol @@ -17,7 +17,7 @@ contract FiberRouter is Ownable, TokenReceivable { using SafeERC20 for IERC20; address public pool; address public oneInchAggregatorRouter; - address public constant WETH = 0xc778417E063141139Fce010982780140Aa0cD5Ab; //need to change for every blockchain + address public WETH; //need to change for every blockchain event Swap( address sourceToken, @@ -82,6 +82,23 @@ contract FiberRouter is Ownable, TokenReceivable { uint256 amountOut ); + + /** + * @dev Constructor that sets the WETH address, oneInchAggregator address, and the pool address. + * @param _wethAddress Address of the WETH token contract. + * @param _oneInchAggregator Address of the oneInchAggregator. + * @param _poolAddress Address of the pool. + */ + constructor(address _wethAddress, address _oneInchAggregator, address _poolAddress) { + require(_wethAddress != address(0), "WETH address cannot be the zero address"); + require(_oneInchAggregator != address(0), "oneInchAggregator address cannot be the zero address"); + require(_poolAddress != address(0), "Pool address cannot be the zero address"); + + WETH = _wethAddress; + oneInchAggregatorRouter = _oneInchAggregator; + pool = _poolAddress; + } + /** @notice Sets the fund manager contract. @param _pool The fund manager From 9eefc866baed68be93faf0d15081a0d05c2047e4 Mon Sep 17 00:00:00 2001 From: sibghatullah1997 Date: Wed, 3 Jan 2024 12:19:02 +0500 Subject: [PATCH 05/10] extra comment removed --- contracts/upgradeable-Bridge/FiberRouter.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/upgradeable-Bridge/FiberRouter.sol b/contracts/upgradeable-Bridge/FiberRouter.sol index cabb2b0..09093f7 100644 --- a/contracts/upgradeable-Bridge/FiberRouter.sol +++ b/contracts/upgradeable-Bridge/FiberRouter.sol @@ -17,7 +17,7 @@ contract FiberRouter is Ownable, TokenReceivable { using SafeERC20 for IERC20; address public pool; address public oneInchAggregatorRouter; - address public WETH; //need to change for every blockchain + address public WETH; event Swap( address sourceToken, From 9f5de08806282754205bbd8cfb0148f1ec0b3c77 Mon Sep 17 00:00:00 2001 From: sibghatullah1997 Date: Wed, 3 Jan 2024 19:01:23 +0500 Subject: [PATCH 06/10] ferrum deployer added now the contract should be deployed by ferrum deployer and contract verion is upgraded --- contracts/common/FerrumDeployer.sol | 52 +++++++++++++++++ contracts/common/IFerrumDeployer.sol | 6 ++ contracts/common/IVersioned.sol | 6 ++ contracts/common/ReferenceForTest.sol | 12 ++++ contracts/common/SafeAmount.sol | 2 +- contracts/common/WithAdmin.sol | 2 +- contracts/common/tokenReceiveable.sol | 2 +- contracts/upgradeable-Bridge/FiberRouter.sol | 16 ++--- contracts/upgradeable-Bridge/FundManager.sol | 8 ++- hardhat.config.js | 9 +++ scripts/deploy/deployFundManager.js | 46 ++++++++++----- scripts/deploy/deployRouter.js | 61 ++++++++++++++++---- 12 files changed, 181 insertions(+), 41 deletions(-) create mode 100644 contracts/common/FerrumDeployer.sol create mode 100644 contracts/common/IFerrumDeployer.sol create mode 100644 contracts/common/IVersioned.sol create mode 100644 contracts/common/ReferenceForTest.sol diff --git a/contracts/common/FerrumDeployer.sol b/contracts/common/FerrumDeployer.sol new file mode 100644 index 0000000..5ef19cc --- /dev/null +++ b/contracts/common/FerrumDeployer.sol @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; +import "@openzeppelin/contracts/utils/Create2.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "./IFerrumDeployer.sol"; +import "./IVersioned.sol"; +import "hardhat/console.sol"; + +contract FerrumDeployer is IFerrumDeployer, IVersioned { + string constant public override VERSION = "0.0.1"; + uint256 constant EXTERNAL_HASH = 0x0ddafcd8600839ce553cacb17e362c83ea42ccfd1e8c8b3cb4d075124196dfc0; + uint256 constant INTERNAL_HASH = 0x27fd0863a54f729686099446389b11108e6e34e7364d1f8e38a43e1661a07f3a; + bytes public override initData; + event Deployed(address); + event DeployedWithData(address conAddr, address owner); + + function deploy(bytes32 salt, bytes calldata bytecode) + public returns (address) { + bytes32 _data = keccak256(abi.encode(salt, INTERNAL_HASH, msg.sender)); + address deployed = Create2.deploy(0, _data, bytecode); + emit Deployed(deployed); + return deployed; + } + + function deployOwnable(bytes32 salt, address owner, bytes calldata data, bytes calldata bytecode) + external returns (address) { + // Contract should get the date using IFerrumDeployer(this).initData(); + initData = data; + bytes32 _data = keccak256(abi.encode(salt, EXTERNAL_HASH, owner, data)); + address addr = Create2.deploy(0, _data, bytecode); + if (owner != address(0)) { + Ownable(addr).transferOwnership(owner); + } + emit DeployedWithData(addr, owner); + delete initData; + return addr; + } + + function computeAddressOwnable(bytes32 salt, address owner, bytes calldata data, bytes32 bytecodeHash) + external view returns (address) { + bytes32 _data = keccak256(abi.encode(salt, EXTERNAL_HASH, owner, data)); + return Create2.computeAddress(_data, bytecodeHash); + } + + function computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) + external view returns (address) { + bytes32 _data = keccak256( + abi.encodePacked(salt, INTERNAL_HASH, deployer) + ); + return Create2.computeAddress(_data, bytecodeHash); + } +} \ No newline at end of file diff --git a/contracts/common/IFerrumDeployer.sol b/contracts/common/IFerrumDeployer.sol new file mode 100644 index 0000000..79eee9b --- /dev/null +++ b/contracts/common/IFerrumDeployer.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +interface IFerrumDeployer { + function initData() external returns (bytes memory); +} \ No newline at end of file diff --git a/contracts/common/IVersioned.sol b/contracts/common/IVersioned.sol new file mode 100644 index 0000000..1bd9b2c --- /dev/null +++ b/contracts/common/IVersioned.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +interface IVersioned { + function VERSION() external view returns (string memory); +} \ No newline at end of file diff --git a/contracts/common/ReferenceForTest.sol b/contracts/common/ReferenceForTest.sol new file mode 100644 index 0000000..704856b --- /dev/null +++ b/contracts/common/ReferenceForTest.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT + +/** + * This file is to allow refencing the imported contracts, in the test code, because it will trigger + * hardhat to create the relavant artifacts. + */ + +pragma solidity ^0.8.0; + +import "./FerrumDeployer.sol"; + +contract FerrumDeployer_ is FerrumDeployer {} \ No newline at end of file diff --git a/contracts/common/SafeAmount.sol b/contracts/common/SafeAmount.sol index 569ff06..c7c306b 100644 --- a/contracts/common/SafeAmount.sol +++ b/contracts/common/SafeAmount.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.2; +pragma solidity 0.8.12; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; // import "@openzeppelin//contracts/token/ERC20/IERC20.sol"; diff --git a/contracts/common/WithAdmin.sol b/contracts/common/WithAdmin.sol index aa39516..37cb77c 100644 --- a/contracts/common/WithAdmin.sol +++ b/contracts/common/WithAdmin.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.2; +pragma solidity 0.8.12; import "@openzeppelin/contracts/access/Ownable.sol"; contract WithAdmin is Ownable { diff --git a/contracts/common/tokenReceiveable.sol b/contracts/common/tokenReceiveable.sol index e7f7a3b..48d3393 100644 --- a/contracts/common/tokenReceiveable.sol +++ b/contracts/common/tokenReceiveable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.2; +pragma solidity 0.8.12; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; diff --git a/contracts/upgradeable-Bridge/FiberRouter.sol b/contracts/upgradeable-Bridge/FiberRouter.sol index 09093f7..f6fa153 100644 --- a/contracts/upgradeable-Bridge/FiberRouter.sol +++ b/contracts/upgradeable-Bridge/FiberRouter.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.2; +pragma solidity 0.8.12; import "./FundManager.sol"; import "../common/tokenReceiveable.sol"; @@ -7,6 +7,7 @@ import "../common/SafeAmount.sol"; import "../common/oneInch/OneInchDecoder.sol"; import "../common/oneInch/IOneInchSwap.sol"; import "../common/IWETH.sol"; +import "../common/IFerrumDeployer.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; /** @@ -83,20 +84,15 @@ contract FiberRouter is Ownable, TokenReceivable { ); - /** + /** * @dev Constructor that sets the WETH address, oneInchAggregator address, and the pool address. - * @param _wethAddress Address of the WETH token contract. - * @param _oneInchAggregator Address of the oneInchAggregator. - * @param _poolAddress Address of the pool. */ - constructor(address _wethAddress, address _oneInchAggregator, address _poolAddress) { + constructor() { + bytes memory initData = IFerrumDeployer(msg.sender).initData(); + (WETH, oneInchAggregatorRouter, pool) = abi.decode(initData, (address, address, address)); require(_wethAddress != address(0), "WETH address cannot be the zero address"); require(_oneInchAggregator != address(0), "oneInchAggregator address cannot be the zero address"); require(_poolAddress != address(0), "Pool address cannot be the zero address"); - - WETH = _wethAddress; - oneInchAggregatorRouter = _oneInchAggregator; - pool = _poolAddress; } /** diff --git a/contracts/upgradeable-Bridge/FundManager.sol b/contracts/upgradeable-Bridge/FundManager.sol index 7c8a768..12a8538 100644 --- a/contracts/upgradeable-Bridge/FundManager.sol +++ b/contracts/upgradeable-Bridge/FundManager.sol @@ -1,11 +1,12 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.2; +pragma solidity 0.8.12; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "../common/signature/SigCheckable.sol"; import "../common/WithAdmin.sol"; import "../common/SafeAmount.sol"; import "../common/tokenReceiveable.sol"; +import "../common/IFerrumDeployer.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; contract FundManager is SigCheckable, WithAdmin, TokenReceivable { @@ -62,7 +63,10 @@ contract FundManager is SigCheckable, WithAdmin, TokenReceivable { } //initialize function is constructor for upgradeable smart contract - constructor() EIP712(NAME, VERSION) {} + constructor() EIP712(NAME, VERSION) { + bytes memory initData = IFerrumDeployer(msg.sender).initData(); + + } /** *************** Owner only operations *************** diff --git a/hardhat.config.js b/hardhat.config.js index cd05f5a..897f17d 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -16,6 +16,15 @@ module.exports = { }, }, }, + { + version: "0.8.12", + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, { version: "0.8.17", settings: { diff --git a/scripts/deploy/deployFundManager.js b/scripts/deploy/deployFundManager.js index 1a6e099..1878af6 100644 --- a/scripts/deploy/deployFundManager.js +++ b/scripts/deploy/deployFundManager.js @@ -1,28 +1,46 @@ -const { ethers, upgrades } = require("hardhat"); +const { ethers } = require("hardhat"); async function main() { - const FiberRouter = await hre.ethers.getContractFactory("FiberRouter"); - const fiberRouter = await FiberRouter.deploy(); + // Compile the contracts + await hre.run('compile'); - await fiberRouter.deployed(); + // Attach to the already deployed FerrumDeployer contract + const ferrumDeployerAddress = "ferrumDeployerAddress"; + const FerrumDeployer = await ethers.getContractFactory("FerrumDeployer"); + const ferrumDeployer = await FerrumDeployer.attach(ferrumDeployerAddress); - console.log("FiberRouter deployed to:", fiberRouter.address); + // Get the contract factory for FundManager + const FundManager = await ethers.getContractFactory("FundManager"); - if (network.name == "hardhat") return; - await fundManager.deployTransaction.wait(6); + // Prepare the initialization data for FundManager + // Replace these addresses with the actual configuration data needed for FundManager + const initData = '0x'; + + + // Compute the bytecode of FundManager + const bytecode = FundManager.bytecode; + + // Compute a unique salt for deployment + const salt = ethers.utils.formatBytes32String(new Date().getTime().toString()); + + // Specify the owner address to which the ownership of the contract will be transferred + const ownerAddress = "0x466B45AF0B58eAF2B98Bed61E07a423ba7828E44"; // Replace with the desired owner address + + // Deploy FundManager using FerrumDeployer's deployOwnable + const deploymentTx = await ferrumDeployer.deployOwnable(salt, ownerAddress, initData, bytecode); + const receipt = await deploymentTx.wait(); + + const fundManagerAddress = receipt.events.find((event) => event.event === 'DeployedWithData').args[0]; + console.log("FundManager deployed to:", fundManagerAddress); console.log("Verifing..."); await hre.run("verify:verify", { - address: fundManager.address, + address: fundManagerAddress, constructorArguments: [], }); console.log("Contract verified successfully !"); } -// npx hardhat verify --network bscMainnet 0x37D6421b1D5724421444dD33338d3043921594dB "Constructor argument 1" -// We recommend this pattern to be able to use async/await everywhere -// and properly handle errors. main().catch((error) => { - console.error(error); - process.exitCode = 1; + console.error(error); + process.exitCode = 1; }); -//npx hardhat run --network sepolia scripts/deploy.js diff --git a/scripts/deploy/deployRouter.js b/scripts/deploy/deployRouter.js index 8189294..42b971d 100644 --- a/scripts/deploy/deployRouter.js +++ b/scripts/deploy/deployRouter.js @@ -1,26 +1,63 @@ -const { ethers, upgrades } = require("hardhat"); +const { ethers } = require("hardhat"); async function main() { - const FiberRouter = await hre.ethers.getContractFactory("FiberRouter"); - const fiberRouter = await FiberRouter.deploy(); + // Compile the contracts and libraries + await hre.run('compile'); - await fiberRouter.deployed(); + // Deploy the OneInchDecoder library + const OneInchDecoder = await ethers.getContractFactory("OneInchDecoder"); + const oneInchDecoder = await OneInchDecoder.deploy(); + await oneInchDecoder.deployed(); + console.log("OneInchDecoder library deployed to:", oneInchDecoder.address); - console.log("FiberRouter deployed to:", fiberRouter.address); + // Attach to the already deployed FerrumDeployer contract + const ferrumDeployerAddress = "ferrumDeployerAddress"; + const FerrumDeployer = await ethers.getContractFactory("FerrumDeployer"); + const ferrumDeployer = await FerrumDeployer.attach(ferrumDeployerAddress); - if (network.name == "hardhat") return; - await fiberRouter.deployTransaction.wait(21); + // Prepare the initialization data for FiberRouter + const initData = ethers.utils.defaultAbiCoder.encode( + ["address", "address", "address"], + ["WETH", "oneInchAggregator", "poolAddress"] + ); + + // Get the contract factory for FiberRouter, linking the OneInchDecoder library + const FiberRouter = await ethers.getContractFactory("FiberRouter", { + libraries: { + "contracts/common/oneInch/OneInchDecoder.sol:OneInchDecoder": oneInchDecoder.address + } + }); + + // Compute the bytecode of FiberRouter with initData + const bytecodeWithInitData = FiberRouter.bytecode + initData.slice(2); + + // Compute a unique salt for deployment + const salt = ethers.utils.formatBytes32String(new Date().getTime().toString()); + + // Deploy FiberRouter using FerrumDeployer's deployOwnable function + const ownerAddress = "ownerAdddress"; // Replace with the desired owner address + const deploymentTx = await ferrumDeployer.deployOwnable(salt, ownerAddress, initData, bytecodeWithInitData); + const receipt = await deploymentTx.wait(); + + const fiberRouterAddress = receipt.events.find((event) => event.event === 'DeployedWithData').args[0]; + console.log("FiberRouter deployed to:", fiberRouterAddress); console.log("Verifing..."); await hre.run("verify:verify", { - address: fiberRouter.address, + address: oneInchDecoder.address, constructorArguments: [], }); + await hre.run("verify:verify", { + address: fiberRouterAddress, + constructorArguments: [], + libraries: { + OneInchDecoder : oneInchDecoder.address, + }, + }); console.log("Contract verified successfully !"); } -// We recommend this pattern to be able to use async/await everywhere -// and properly handle errors. + main().catch((error) => { - console.error(error); - process.exitCode = 1; + console.error(error); + process.exitCode = 1; }); From 98fd87805e9262bbcf58a641abf15512c1295496 Mon Sep 17 00:00:00 2001 From: sibghatullah1997 Date: Tue, 9 Jan 2024 19:23:22 +0500 Subject: [PATCH 07/10] withdrawal event variable name added --- contracts/upgradeable-Bridge/FiberRouter.sol | 30 ++++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/contracts/upgradeable-Bridge/FiberRouter.sol b/contracts/upgradeable-Bridge/FiberRouter.sol index f6fa153..7b75318 100644 --- a/contracts/upgradeable-Bridge/FiberRouter.sol +++ b/contracts/upgradeable-Bridge/FiberRouter.sol @@ -41,14 +41,14 @@ contract FiberRouter is Ownable, TokenReceivable { ); event WithdrawOneInch( - address, - uint256, - uint256, - address, - address, - bytes, - bytes32, - bytes + address to, + uint256 amountIn, + uint256 amountOutOneInch, + address foundryToken, + address targetToken, + bytes oneInchData, + bytes32 salt, + bytes multiSignature ); event NonEvmSwap( @@ -89,10 +89,16 @@ contract FiberRouter is Ownable, TokenReceivable { */ constructor() { bytes memory initData = IFerrumDeployer(msg.sender).initData(); - (WETH, oneInchAggregatorRouter, pool) = abi.decode(initData, (address, address, address)); - require(_wethAddress != address(0), "WETH address cannot be the zero address"); - require(_oneInchAggregator != address(0), "oneInchAggregator address cannot be the zero address"); - require(_poolAddress != address(0), "Pool address cannot be the zero address"); + (WETH, oneInchAggregatorRouter, pool) = abi.decode( + initData, + (address, address, address) + ); + require(WETH != address(0), "WETH address cannot be the zero address"); + require( + oneInchAggregatorRouter != address(0), + "oneInchAggregator address cannot be the zero address" + ); + require(pool != address(0), "Pool address cannot be the zero address"); } /** From 1d80b498e4949f27575c66503baad3fa70f92762 Mon Sep 17 00:00:00 2001 From: sibghatullah1997 Date: Tue, 16 Jan 2024 20:15:29 +0500 Subject: [PATCH 08/10] compiler version downgraded to 0.8.2 --- contracts/common/SafeAmount.sol | 2 +- contracts/common/WithAdmin.sol | 2 +- contracts/common/tokenReceiveable.sol | 2 +- contracts/upgradeable-Bridge/FiberRouter.sol | 2 +- contracts/upgradeable-Bridge/FundManager.sol | 2 +- package.json | 7 ++++--- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/contracts/common/SafeAmount.sol b/contracts/common/SafeAmount.sol index c7c306b..96e5f2c 100644 --- a/contracts/common/SafeAmount.sol +++ b/contracts/common/SafeAmount.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.12; +pragma solidity 0.8.2 import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; // import "@openzeppelin//contracts/token/ERC20/IERC20.sol"; diff --git a/contracts/common/WithAdmin.sol b/contracts/common/WithAdmin.sol index 37cb77c..e06c166 100644 --- a/contracts/common/WithAdmin.sol +++ b/contracts/common/WithAdmin.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.12; +pragma solidity 0.8.2 import "@openzeppelin/contracts/access/Ownable.sol"; contract WithAdmin is Ownable { diff --git a/contracts/common/tokenReceiveable.sol b/contracts/common/tokenReceiveable.sol index 48d3393..2094926 100644 --- a/contracts/common/tokenReceiveable.sol +++ b/contracts/common/tokenReceiveable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.12; +pragma solidity 0.8.2 import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; diff --git a/contracts/upgradeable-Bridge/FiberRouter.sol b/contracts/upgradeable-Bridge/FiberRouter.sol index 7b75318..d776cd5 100644 --- a/contracts/upgradeable-Bridge/FiberRouter.sol +++ b/contracts/upgradeable-Bridge/FiberRouter.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.12; +pragma solidity 0.8.2 import "./FundManager.sol"; import "../common/tokenReceiveable.sol"; diff --git a/contracts/upgradeable-Bridge/FundManager.sol b/contracts/upgradeable-Bridge/FundManager.sol index 12a8538..3ca8ed6 100644 --- a/contracts/upgradeable-Bridge/FundManager.sol +++ b/contracts/upgradeable-Bridge/FundManager.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.12; +pragma solidity 0.8.2 import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "../common/signature/SigCheckable.sol"; diff --git a/package.json b/package.json index d2a553b..fa71e0f 100644 --- a/package.json +++ b/package.json @@ -15,9 +15,10 @@ "@cosmjs/proto-signing": "^0.29.2", "@cosmjs/stargate": "^0.29.2", "@nomiclabs/hardhat-web3": "^2.0.0", - "@openzeppelin/contracts": "^4.0.0", - "@openzeppelin/contracts-upgradeable": "^4.8.0-rc.1", - "@openzeppelin/hardhat-upgrades": "^1.21.0", + "@openzeppelin/contracts": "4.1.0", + "@openzeppelin/contracts-upgradeable": "4.3.2", + "@openzeppelin/hardhat-upgrades": "1.10.0", + "@openzeppelin/upgrades-core":"1.9.0", "axios": "^1.1.3", "dotenv": "^16.0.0", "ethereumjs-util": "^7.1.5", From a5b70443ee2710fd79c423ba3362d9f15a16790e Mon Sep 17 00:00:00 2001 From: sibghatullah1997 Date: Tue, 16 Jan 2024 20:25:13 +0500 Subject: [PATCH 09/10] compiler version downgraded to 0.8.2 --- contracts/common/SafeAmount.sol | 2 +- contracts/common/WithAdmin.sol | 2 +- contracts/common/tokenReceiveable.sol | 2 +- contracts/upgradeable-Bridge/FiberRouter.sol | 2 +- contracts/upgradeable-Bridge/FundManager.sol | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/common/SafeAmount.sol b/contracts/common/SafeAmount.sol index 96e5f2c..569ff06 100644 --- a/contracts/common/SafeAmount.sol +++ b/contracts/common/SafeAmount.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.2 +pragma solidity 0.8.2; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; // import "@openzeppelin//contracts/token/ERC20/IERC20.sol"; diff --git a/contracts/common/WithAdmin.sol b/contracts/common/WithAdmin.sol index e06c166..aa39516 100644 --- a/contracts/common/WithAdmin.sol +++ b/contracts/common/WithAdmin.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.2 +pragma solidity 0.8.2; import "@openzeppelin/contracts/access/Ownable.sol"; contract WithAdmin is Ownable { diff --git a/contracts/common/tokenReceiveable.sol b/contracts/common/tokenReceiveable.sol index 2094926..e7f7a3b 100644 --- a/contracts/common/tokenReceiveable.sol +++ b/contracts/common/tokenReceiveable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.2 +pragma solidity 0.8.2; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; diff --git a/contracts/upgradeable-Bridge/FiberRouter.sol b/contracts/upgradeable-Bridge/FiberRouter.sol index d776cd5..a8887b7 100644 --- a/contracts/upgradeable-Bridge/FiberRouter.sol +++ b/contracts/upgradeable-Bridge/FiberRouter.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.2 +pragma solidity 0.8.2; import "./FundManager.sol"; import "../common/tokenReceiveable.sol"; diff --git a/contracts/upgradeable-Bridge/FundManager.sol b/contracts/upgradeable-Bridge/FundManager.sol index 3ca8ed6..a35c992 100644 --- a/contracts/upgradeable-Bridge/FundManager.sol +++ b/contracts/upgradeable-Bridge/FundManager.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.2 +pragma solidity 0.8.2; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "../common/signature/SigCheckable.sol"; From 47d0f4ecc2142bbc97a927c334b80659a9097c2f Mon Sep 17 00:00:00 2001 From: sibghatullah1997 Date: Tue, 23 Jan 2024 13:46:55 +0500 Subject: [PATCH 10/10] Ferrum deployer getting from foundry contract --- contracts/common/FerrumDeployer.sol | 52 -------------------- contracts/common/IFerrumDeployer.sol | 6 --- contracts/common/IVersioned.sol | 6 --- contracts/common/ReferenceForTest.sol | 2 +- contracts/upgradeable-Bridge/FiberRouter.sol | 2 +- contracts/upgradeable-Bridge/FundManager.sol | 2 +- package.json | 6 +-- 7 files changed, 6 insertions(+), 70 deletions(-) delete mode 100644 contracts/common/FerrumDeployer.sol delete mode 100644 contracts/common/IFerrumDeployer.sol delete mode 100644 contracts/common/IVersioned.sol diff --git a/contracts/common/FerrumDeployer.sol b/contracts/common/FerrumDeployer.sol deleted file mode 100644 index 5ef19cc..0000000 --- a/contracts/common/FerrumDeployer.sol +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; -import "@openzeppelin/contracts/utils/Create2.sol"; -import "@openzeppelin/contracts/access/Ownable.sol"; -import "./IFerrumDeployer.sol"; -import "./IVersioned.sol"; -import "hardhat/console.sol"; - -contract FerrumDeployer is IFerrumDeployer, IVersioned { - string constant public override VERSION = "0.0.1"; - uint256 constant EXTERNAL_HASH = 0x0ddafcd8600839ce553cacb17e362c83ea42ccfd1e8c8b3cb4d075124196dfc0; - uint256 constant INTERNAL_HASH = 0x27fd0863a54f729686099446389b11108e6e34e7364d1f8e38a43e1661a07f3a; - bytes public override initData; - event Deployed(address); - event DeployedWithData(address conAddr, address owner); - - function deploy(bytes32 salt, bytes calldata bytecode) - public returns (address) { - bytes32 _data = keccak256(abi.encode(salt, INTERNAL_HASH, msg.sender)); - address deployed = Create2.deploy(0, _data, bytecode); - emit Deployed(deployed); - return deployed; - } - - function deployOwnable(bytes32 salt, address owner, bytes calldata data, bytes calldata bytecode) - external returns (address) { - // Contract should get the date using IFerrumDeployer(this).initData(); - initData = data; - bytes32 _data = keccak256(abi.encode(salt, EXTERNAL_HASH, owner, data)); - address addr = Create2.deploy(0, _data, bytecode); - if (owner != address(0)) { - Ownable(addr).transferOwnership(owner); - } - emit DeployedWithData(addr, owner); - delete initData; - return addr; - } - - function computeAddressOwnable(bytes32 salt, address owner, bytes calldata data, bytes32 bytecodeHash) - external view returns (address) { - bytes32 _data = keccak256(abi.encode(salt, EXTERNAL_HASH, owner, data)); - return Create2.computeAddress(_data, bytecodeHash); - } - - function computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) - external view returns (address) { - bytes32 _data = keccak256( - abi.encodePacked(salt, INTERNAL_HASH, deployer) - ); - return Create2.computeAddress(_data, bytecodeHash); - } -} \ No newline at end of file diff --git a/contracts/common/IFerrumDeployer.sol b/contracts/common/IFerrumDeployer.sol deleted file mode 100644 index 79eee9b..0000000 --- a/contracts/common/IFerrumDeployer.sol +++ /dev/null @@ -1,6 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -interface IFerrumDeployer { - function initData() external returns (bytes memory); -} \ No newline at end of file diff --git a/contracts/common/IVersioned.sol b/contracts/common/IVersioned.sol deleted file mode 100644 index 1bd9b2c..0000000 --- a/contracts/common/IVersioned.sol +++ /dev/null @@ -1,6 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -interface IVersioned { - function VERSION() external view returns (string memory); -} \ No newline at end of file diff --git a/contracts/common/ReferenceForTest.sol b/contracts/common/ReferenceForTest.sol index 704856b..0f89805 100644 --- a/contracts/common/ReferenceForTest.sol +++ b/contracts/common/ReferenceForTest.sol @@ -7,6 +7,6 @@ pragma solidity ^0.8.0; -import "./FerrumDeployer.sol"; +import "foundry-contracts/contracts/common/FerrumDeployer.sol"; contract FerrumDeployer_ is FerrumDeployer {} \ No newline at end of file diff --git a/contracts/upgradeable-Bridge/FiberRouter.sol b/contracts/upgradeable-Bridge/FiberRouter.sol index a8887b7..12512b4 100644 --- a/contracts/upgradeable-Bridge/FiberRouter.sol +++ b/contracts/upgradeable-Bridge/FiberRouter.sol @@ -7,7 +7,7 @@ import "../common/SafeAmount.sol"; import "../common/oneInch/OneInchDecoder.sol"; import "../common/oneInch/IOneInchSwap.sol"; import "../common/IWETH.sol"; -import "../common/IFerrumDeployer.sol"; +import "foundry-contracts/contracts/common/FerrumDeployer.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; /** diff --git a/contracts/upgradeable-Bridge/FundManager.sol b/contracts/upgradeable-Bridge/FundManager.sol index a35c992..9ff6fa7 100644 --- a/contracts/upgradeable-Bridge/FundManager.sol +++ b/contracts/upgradeable-Bridge/FundManager.sol @@ -6,7 +6,7 @@ import "../common/signature/SigCheckable.sol"; import "../common/WithAdmin.sol"; import "../common/SafeAmount.sol"; import "../common/tokenReceiveable.sol"; -import "../common/IFerrumDeployer.sol"; +import "foundry-contracts/contracts/common/FerrumDeployer.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; contract FundManager is SigCheckable, WithAdmin, TokenReceivable { diff --git a/package.json b/package.json index fa71e0f..7df0a83 100644 --- a/package.json +++ b/package.json @@ -10,12 +10,11 @@ "author": "", "license": "ISC", "dependencies": { - "@chainlink/contracts": "^0.5.1", "@cosmjs/cosmwasm-stargate": "^0.29.2", "@cosmjs/proto-signing": "^0.29.2", "@cosmjs/stargate": "^0.29.2", "@nomiclabs/hardhat-web3": "^2.0.0", - "@openzeppelin/contracts": "4.1.0", + "@openzeppelin/contracts": "^4.1.0", "@openzeppelin/contracts-upgradeable": "4.3.2", "@openzeppelin/hardhat-upgrades": "1.10.0", "@openzeppelin/upgrades-core":"1.9.0", @@ -23,6 +22,7 @@ "dotenv": "^16.0.0", "ethereumjs-util": "^7.1.5", "ethers": "^5.7.2", + "foundry-contracts": "git+https://github.com/ferrumnet/foundry-contracts#develop", "web3": "^1.8.0" }, "devDependencies": { @@ -36,7 +36,7 @@ "@types/chai": "^4.3.4", "@types/mocha": "^9.1.1", "chai": "^4.3.6", - "hardhat": "^2.14.0", + "hardhat": "^2.19.4", "hardhat-gas-reporter": "^1.0.9", "mocha": "^10.0.0", "solidity-coverage": "^0.8.2",