From 5352b81b6a969accfa2e3035994c3b007eb01c03 Mon Sep 17 00:00:00 2001 From: Salman Haider Date: Mon, 4 Mar 2024 18:43:32 +0500 Subject: [PATCH 1/8] Gas Optimisation & Fixes --- contracts/multiswap-contracts/FiberRouter.sol | 136 ++++++++++++------ .../multiswap-contracts/MultiswapForge.sol | 3 + scripts/deploy/configContracts.js | 84 ++++++++++- scripts/deploy/forge/deployMultiSwapForge.js | 21 +-- scripts/deploy/multiswap/deployFiberRouter.js | 29 +--- .../decode/decoder/1inchDecoderCall.js | 42 ++++++ .../decode/decoder/1inchDecoderLibrary.js | 104 ++++++++++++++ 7 files changed, 330 insertions(+), 89 deletions(-) create mode 100644 scripts/test-scripts/decode/decoder/1inchDecoderCall.js create mode 100644 scripts/test-scripts/decode/decoder/1inchDecoderLibrary.js diff --git a/contracts/multiswap-contracts/FiberRouter.sol b/contracts/multiswap-contracts/FiberRouter.sol index 74127f3..c9d7a1a 100644 --- a/contracts/multiswap-contracts/FiberRouter.sol +++ b/contracts/multiswap-contracts/FiberRouter.sol @@ -4,7 +4,6 @@ import "./FundManager.sol"; import "../common/tokenReceiveable.sol"; import "../common/SafeAmount.sol"; -import "../common/oneInch/OneInchDecoder.sol"; import "../common/oneInch/IOneInchSwap.sol"; import "../common/IWETH.sol"; import "foundry-contracts/contracts/common/FerrumDeployer.sol"; @@ -21,6 +20,43 @@ contract FiberRouter is Ownable, TokenReceivable { address public oneInchAggregatorRouter; address public WETH; + enum OneInchFunction { + unoswapTo, + uniswapV3SwapTo, + swap, + fillOrderTo, + fillOrderRFQTo + } + struct SwapDescription { + address srcToken; + address dstToken; + address payable srcReceiver; + address payable dstReceiver; + uint256 amount; + uint256 minReturnAmount; + uint256 flags; + } + struct Order { + uint256 salt; + address makerAsset; // targetToken + address takerAsset; // foundryToken + address maker; + address receiver; + address allowedSender; // equals to Zero address on public orders + uint256 makingAmount; + uint256 takingAmount; // destinationAmountIn + uint256 offsets; + bytes interactions; // concat(makerAssetData, takerAssetData, getMakingAmount, getTakingAmount, predicate, permit, preIntercation, postInteraction) + } + struct OrderRFQ { + uint256 info; // lowest 64 bits is the order id, next 64 bits is the expiration timestamp + address makerAsset; // targetToken + address takerAsset; // foundryToken + address maker; + address allowedSender; // equals to Zero address on public orders + uint256 makingAmount; + uint256 takingAmount; + } event Swap( address sourceToken, address targetToken, @@ -90,16 +126,18 @@ contract FiberRouter is Ownable, TokenReceivable { */ constructor() { bytes memory initData = IFerrumDeployer(msg.sender).initData(); - (WETH, oneInchAggregatorRouter, pool) = abi.decode( - initData, - (address, address, address) - ); - require(WETH != address(0), "WETH address cannot be the zero address"); + } + + /** + @dev Sets the WETH address. + @param _weth The WETH address + */ + function setWETH(address _weth) external onlyOwner { require( - oneInchAggregatorRouter != address(0), - "oneInchAggregator address cannot be the zero address" + _weth != address(0), + "_weth address cannot be zero" ); - require(pool != address(0), "Pool address cannot be the zero address"); + WETH = _weth; } /** @@ -272,7 +310,8 @@ contract FiberRouter is Ownable, TokenReceivable { bytes memory oneInchData, address fromToken, address foundryToken, - bytes32 withdrawalData + bytes32 withdrawalData, + OneInchFunction funcSelector ) external payable nonReentrant { // Validation checks require( @@ -311,7 +350,8 @@ contract FiberRouter is Ownable, TokenReceivable { crossTargetAddress, oneInchData, fromToken, - foundryToken + foundryToken, + funcSelector // Pass the enum parameter ); // Transfer the gas fee to the gasWallet payable(gasWallet).transfer(msg.value); @@ -349,7 +389,8 @@ contract FiberRouter is Ownable, TokenReceivable { bytes memory oneInchData, address foundryToken, bytes32 withdrawalData, - uint256 gasFee + uint256 gasFee, + OneInchFunction funcSelector // Add the enum parameter ) external payable { uint256 amountIn = msg.value - gasFee; // Validation checks @@ -372,7 +413,8 @@ contract FiberRouter is Ownable, TokenReceivable { crossTargetAddress, oneInchData, WETH, - foundryToken + foundryToken, + funcSelector // Pass the function selector ); // Transfer the gas fee to the gasWallet payable(gasWallet).transfer(gasFee); @@ -447,6 +489,7 @@ contract FiberRouter is Ownable, TokenReceivable { address foundryToken, address targetToken, bytes memory oneInchData, + OneInchFunction funcSelector, // Add the enum parameter bytes32 salt, uint256 expiry, bytes memory multiSignature @@ -483,7 +526,8 @@ contract FiberRouter is Ownable, TokenReceivable { foundryToken, amountIn, amountOut, - oneInchData + oneInchData, + funcSelector ); require(amountOutOneInch != 0, "FR: Bad amount out from oneInch"); emit WithdrawOneInch( @@ -512,28 +556,20 @@ contract FiberRouter is Ownable, TokenReceivable { address srcToken, uint256 amountIn, uint256 amountOut, - bytes memory oneInchData + bytes memory oneInchData, + OneInchFunction funcSelector // Add enum parameter to identify the function ) internal returns (uint256 returnAmount) { - // Extract the first 4 bytes from data - bytes4 receivedSelector; - assembly { - // Extract the first 4 bytes directly from the data - // Assuming 'data' starts with the 4-byte function selector - receivedSelector := mload(add(oneInchData, 32)) - } - // checking the function signature accoridng to oneInchData - if (receivedSelector == OneInchDecoder.selectorUnoswap) { + + if (funcSelector == OneInchFunction.unoswapTo) { returnAmount = handleUnoSwap(to, srcToken, amountIn, amountOut, oneInchData); - } else if (receivedSelector == OneInchDecoder.selectorUniswapV3Swap) { + } else if (funcSelector == OneInchFunction.uniswapV3SwapTo) { returnAmount = handleUniswapV3Swap(to, amountIn, amountOut, oneInchData); - } else if (receivedSelector == OneInchDecoder.selectorSwap) { + } else if (funcSelector == OneInchFunction.swap) { returnAmount = handleSwap(to, srcToken, amountIn, amountOut, oneInchData); - } else if (receivedSelector == OneInchDecoder.selectorFillOrderTo) { + } else if (funcSelector == OneInchFunction.fillOrderTo) { returnAmount = handleFillOrderTo(to, srcToken, amountIn, oneInchData); - } else if (receivedSelector == OneInchDecoder.selectorFillOrderRFQTo) { + } else if (funcSelector == OneInchFunction.fillOrderRFQTo) { returnAmount = handleFillOrderRFQTo(to, srcToken, amountIn, oneInchData); - } else { - revert("FR: incorrect oneInchData"); } } @@ -559,7 +595,10 @@ contract FiberRouter is Ownable, TokenReceivable { uint256 amount, uint256 minReturn, uint256[] memory poolsOneInch - ) = OneInchDecoder.decodeUnoswap(oneInchData); + ) = abi.decode( + oneInchData, + (address, address, uint256, uint256, uint256[]) + ); require(to == recipient, "FR: recipient address bad oneInch Data"); require(fromToken == srcToken, "FR: srcToken bad oneInch Data"); require(amountIn == amount, "FR: inputAmount bad oneInch Data"); @@ -600,7 +639,10 @@ contract FiberRouter is Ownable, TokenReceivable { uint256 amount, uint256 minReturn, uint256[] memory poolsOneInch - ) = OneInchDecoder.decodeUniswapV3Swap(oneInchData); + ) = abi.decode( + oneInchData, + (address, uint256, uint256, uint256[]) + ); require(to == recipient, "FR: recipient address bad oneInch Data"); require(amountIn == amount, "FR: inputAmount bad oneInch Data"); require(amountOut == minReturn, "FR: outAmount bad oneInch Data"); @@ -638,10 +680,13 @@ contract FiberRouter is Ownable, TokenReceivable { // Decoding oneInchData to get the required parameters ( address executor, - OneInchDecoder.SwapDescription memory desc, + SwapDescription memory desc, bytes memory permit, bytes memory swapData - ) = OneInchDecoder.decodeSwap(oneInchData); + ) = abi.decode( + oneInchData, + (address, SwapDescription, bytes, bytes) + ); // Manually create a new SwapDescription for IOneInchSwap IOneInchSwap.SwapDescription memory oneInchDesc = IOneInchSwap .SwapDescription({ @@ -701,14 +746,17 @@ contract FiberRouter is Ownable, TokenReceivable { ) internal returns (uint256 returnAmount) { // Decoding oneInchData to get the required parameters ( - OneInchDecoder.Order memory order_, + Order memory order_, bytes memory signature, bytes memory interaction, uint256 makingAmount, uint256 takingAmount, // destinationAmountIn uint256 skipPermitAndThresholdAmount, address target // receiverAddress - ) = OneInchDecoder.decodeFillOrderTo(oneInchData); + ) = abi.decode( + oneInchData, + (Order, bytes, bytes, uint256, uint256,uint256, address) + ); // Manually create a new Order for IOneInchSwap IOneInchSwap.Order memory oneInchOrder = IOneInchSwap @@ -767,11 +815,14 @@ contract FiberRouter is Ownable, TokenReceivable { ) internal returns (uint256 returnAmount) { // Decoding oneInchData to get the required parameters ( - OneInchDecoder.OrderRFQ memory order, + OrderRFQ memory order, bytes memory signature, uint256 flagsAndAmount, address target // receiverAddress - ) = OneInchDecoder.decodeFillOrderRFQTo(oneInchData); + ) = abi.decode( + oneInchData, + (OrderRFQ, bytes, uint256, address) + ); // Manually create a new OrderRFQ for IOneInchSwap IOneInchSwap.OrderRFQ memory oneInchOrderRFQ = IOneInchSwap.OrderRFQ({ @@ -825,8 +876,10 @@ contract FiberRouter is Ownable, TokenReceivable { address crossTargetAddress, bytes memory oneInchData, address fromToken, - address foundryToken - ) internal returns (uint256 FMAmountOut){ + address foundryToken, + OneInchFunction funcSelector // Add enum parameter to identify the function + ) internal returns (uint256 FMAmountOut) { + // Check if allowance is non-zero if (IERC20(fromToken).allowance(address(this), oneInchAggregatorRouter) != 0) { // Reset the allowance to zero @@ -840,7 +893,8 @@ contract FiberRouter is Ownable, TokenReceivable { fromToken, amountIn, amountOut, - oneInchData + oneInchData, + funcSelector // Pass the enum parameter ); FMAmountOut = FundManager(pool).swapToAddress( foundryToken, diff --git a/contracts/multiswap-contracts/MultiswapForge.sol b/contracts/multiswap-contracts/MultiswapForge.sol index 5cd7edf..cf55361 100644 --- a/contracts/multiswap-contracts/MultiswapForge.sol +++ b/contracts/multiswap-contracts/MultiswapForge.sol @@ -63,6 +63,7 @@ contract MultiSwapForge is FiberRouter { address foundryToken, address targetToken, bytes memory oneInchData, + OneInchFunction funcSelector, // Add the enum parameter bytes32 salt, uint256 expiry, bytes memory multiSignature @@ -78,6 +79,7 @@ contract MultiSwapForge is FiberRouter { address foundryToken, address targetToken, bytes memory oneInchData, + OneInchFunction funcSelector, // Add the enum parameter bytes32 salt, uint256 expiry, bytes memory multiSignature @@ -90,6 +92,7 @@ contract MultiSwapForge is FiberRouter { foundryToken, targetToken, oneInchData, + funcSelector, salt, expiry, multiSignature diff --git a/scripts/deploy/configContracts.js b/scripts/deploy/configContracts.js index d2b098d..f12b4bd 100644 --- a/scripts/deploy/configContracts.js +++ b/scripts/deploy/configContracts.js @@ -15,7 +15,13 @@ const fundManagerAddress = '0x'; const foundryArbitrum = "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8"; const foundryBinance = "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"; -const foundryEthereum = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" +const foundryEthereum = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; + +const wethArbitrum = "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"; +const wethBinance = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; +const wethEthereum = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"; + +const oneInchAggregatorRouter = "0x1111111254EEB25477B68fb85Ed929f73A960582"; const signerAddress = "0x"; @@ -51,13 +57,68 @@ async function main() { const fiberRouter = new ethers.Contract(fiberRouterAddress, fiberRouterABI.abi, provider); const fundManager = new ethers.Contract(fundManagerAddress, fundManagerABI.abi, provider); - // Call setRouter on ForgeManager with MultiswapForge address - const forgeSet = await forgeManager.connect(wallet).setRouter(multiswapForge.address); + // Call setWETH on FundManager with WETH address + const wethSet = await fiberRouter.connect(wallet).setWETH(wethBinance); // Wait for the transaction receipt - const receiptForgeSet = await forgeSet.wait(); + const receiptWethSet = await wethSet.wait(); - if (receiptForgeSet.status == 1) { - console.log("Forge added successfully in ForgeManager!"); + if (receiptWethSet.status == 1) { + console.log("WETH address added successfully in FiberRouter!"); + } else { + console.log("Transaction failed"); + } + + // Call setRouter on ForgeManager with WETH address + const wethForgeSet = await multiswapForge.connect(wallet).setWETH(wethBinance); + // Wait for the transaction receipt + const receiptWethForgeSet = await wethForgeSet.wait(); + + if (receiptWethForgeSet.status == 1) { + console.log("WETH address added successfully in MultiSwapForge!"); + } else { + console.log("Transaction failed"); + } + + // Call setPool on FiberRouter with FundManager address + const poolFundManagerSet = await fiberRouter.connect(wallet).setPool(fundManagerAddress); + // Wait for the transaction receipt + const receiptPoolFundManagerSet = await poolFundManagerSet.wait(); + + if (receiptPoolFundManagerSet.status == 1) { + console.log("Pool Fund Manager address added successfully in FiberRouter!"); + } else { + console.log("Transaction failed"); + } + + // Call setPool on MultiSwapForge with ForgeManager address + const poolForgeManagerSet = await multiswapForge.connect(wallet).setPool(forgeManagerAddress); + // Wait for the transaction receipt + const receiptPoolForgeManagerSet = await poolForgeManagerSet.wait(); + + if (receiptPoolForgeManagerSet.status == 1) { + console.log("Pool Fund Manager address added successfully in FiberRouter!"); + } else { + console.log("Transaction failed"); + } + + // Call setOneInchAggregatorRouter on FiberRouter with oneInchAggregatorRouter address + const oneInchAddressSet = await fiberRouter.connect(wallet).setOneInchAggregatorRouter(oneInchAggregatorRouter); + // Wait for the transaction receipt + const receiptOneInchAddressSet = await oneInchAddressSet.wait(); + + if (receiptOneInchAddressSet.status == 1) { + console.log("OneInch Aggregator address added successfully in FiberRouter!"); + } else { + console.log("Transaction failed"); + } + + // Call setOneInchAggregatorRouter on MultiSwap Forge with oneInchAggregatorRouter address + const oneInchAddressForgeSet = await multiswapForge.connect(wallet).setOneInchAggregatorRouter(oneInchAggregatorRouter); + // Wait for the transaction receipt + const receiptOneInchAddressForgeSet = await oneInchAddressForgeSet.wait(); + + if (receiptOneInchAddressForgeSet.status == 1) { + console.log("OneInch Aggregator address added successfully in MultiSwap Forge!"); } else { console.log("Transaction failed"); } @@ -72,6 +133,17 @@ async function main() { } else { console.log("Transaction failed"); } + + // Call setRouter on ForgeManager with MultiswapForge address + const forgeSet = await forgeManager.connect(wallet).setRouter(multiswapForge.address); + // Wait for the transaction receipt + const receiptForgeSet = await forgeSet.wait(); + + if (receiptForgeSet.status == 1) { + console.log("Forge added successfully in ForgeManager!"); + } else { + console.log("Transaction failed"); + } // Call allowTarget on FundManager with specified addresses const targetAllowed = await fundManager.connect(wallet).allowTarget(foundryBinance, ethereumChainID, foundryEthereum); diff --git a/scripts/deploy/forge/deployMultiSwapForge.js b/scripts/deploy/forge/deployMultiSwapForge.js index fbab6dd..496ae20 100644 --- a/scripts/deploy/forge/deployMultiSwapForge.js +++ b/scripts/deploy/forge/deployMultiSwapForge.js @@ -4,25 +4,16 @@ async function main() { // Compile the contracts and libraries await hre.run('compile'); - const oneInchDecoderAddress = "0x" - // Attach to the already deployed FerrumDeployer contract - const ferrumDeployerAddress = "0x"; + const ferrumDeployerAddress = "0x17EA1C55E2E16B57a34932d5b96A749Cd20A6104"; const FerrumDeployer = await ethers.getContractFactory("FerrumDeployer"); const ferrumDeployer = await FerrumDeployer.attach(ferrumDeployerAddress); // Prepare the initialization data for FiberRouter - const initData = ethers.utils.defaultAbiCoder.encode( - ["address", "address", "address"], - ["0x WETH", "0x-oneInchAggregator", "0x-poolAddress"] // Replace these addresses with real data - ); + const initData = "0x"; // Get the contract factory for MultiswapForge - const MultiswapForge = await ethers.getContractFactory("MultiswapForge", { - libraries: { - "contracts/common/oneInch/OneInchDecoder.sol:OneInchDecoder": oneInchDecoderAddress - } - }); + const MultiswapForge = await ethers.getContractFactory("MultiSwapForge"); // Compute the bytecode of MultiswapForge with initData (slicing 0x) const bytecodeWithInitData = MultiswapForge.bytecode + initData.slice(2); @@ -34,17 +25,13 @@ async function main() { const ownerAddress = "0x"; // Replace with the desired owner address const deploymentTx = await ferrumDeployer.deployOwnable(salt, ownerAddress, initData, bytecodeWithInitData); const receipt = await deploymentTx.wait(); - console.log('receipt: ', receipt); const multiswapForgeAddress = receipt.events.find((event) => event.event === 'DeployedWithData').args[0]; - console.log("ForgeFundManager deployed to:", multiswapForgeAddress); + console.log("multiswap forge deployed to:", multiswapForgeAddress); console.log("Verifing..."); await hre.run("verify:verify", { address: multiswapForgeAddress, constructorArguments: [], - libraries: { - OneInchDecoder : oneInchDecoderAddress, - }, }); console.log("Contract verified successfully !"); } diff --git a/scripts/deploy/multiswap/deployFiberRouter.js b/scripts/deploy/multiswap/deployFiberRouter.js index b5b9763..7353f35 100644 --- a/scripts/deploy/multiswap/deployFiberRouter.js +++ b/scripts/deploy/multiswap/deployFiberRouter.js @@ -4,34 +4,16 @@ async function main() { // Compile the contracts and libraries await hre.run('compile'); - // 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("Verifing..."); - await hre.run("verify:verify", { - address: oneInchDecoder.address, - constructorArguments: [], - }); - // Attach to the already deployed FerrumDeployer contract - const ferrumDeployerAddress = "0x-ferrumDeployerAddress"; + const ferrumDeployerAddress = "0x17EA1C55E2E16B57a34932d5b96A749Cd20A6104"; const FerrumDeployer = await ethers.getContractFactory("FerrumDeployer"); const ferrumDeployer = await FerrumDeployer.attach(ferrumDeployerAddress); // Prepare the initialization data for FiberRouter - const initData = ethers.utils.defaultAbiCoder.encode( - ["address", "address", "address"], - ["0x WETH", "0x-oneInchAggregator", "0x-poolAddress"] // Replace these addresses with real data - ); + const initData = "0x"; // 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 - } - }); + const FiberRouter = await ethers.getContractFactory("FiberRouter"); // Compute the bytecode of FiberRouter with initData const bytecodeWithInitData = FiberRouter.bytecode + initData.slice(2); @@ -40,7 +22,7 @@ async function main() { const salt = ethers.utils.formatBytes32String(new Date().getTime().toString()); // Deploy FiberRouter using FerrumDeployer's deployOwnable function - const ownerAddress = "0x-ownerAdddress"; // Replace with the desired owner address + const ownerAddress = ""; // Replace with the desired owner address const deploymentTx = await ferrumDeployer.deployOwnable(salt, ownerAddress, initData, bytecodeWithInitData); const receipt = await deploymentTx.wait(); @@ -50,9 +32,6 @@ async function main() { await hre.run("verify:verify", { address: fiberRouterAddress, constructorArguments: [], - libraries: { - OneInchDecoder : oneInchDecoder.address, - }, }); console.log("Contract verified successfully !"); } diff --git a/scripts/test-scripts/decode/decoder/1inchDecoderCall.js b/scripts/test-scripts/decode/decoder/1inchDecoderCall.js new file mode 100644 index 0000000..a644ed2 --- /dev/null +++ b/scripts/test-scripts/decode/decoder/1inchDecoderCall.js @@ -0,0 +1,42 @@ +const ethers = require('ethers'); +// Example ABI of the 1inchSwap contract + + const OneInchDecoder = require('./1inchDecoderLibrary.js'); // Adjust the path to 1inchDecoder script + + async function swapHelperForOneInch(oneInchData) { + + const functionSelector = oneInchData.slice(0, 10); + let func; + + switch (functionSelector) { + case OneInchDecoder.selectorUnoswap: + func = 0; + break; + case OneInchDecoder.selectorUniswapV3Swap: + func = 1; + break; + case OneInchDecoder.selectorSwap: + func = 2; + break; + case OneInchDecoder.selectorFillOrderTo: + func = 3; + break; + case OneInchDecoder.selectorFillOrderRFQTo: + func = 4; + break; + default: + throw new Error("Unknown function selector"); + } + + return func; +} + + const oneInchData = ""; + +async function main() { + const funcValue = await swapHelperForOneInch(to, srcToken, amountIn, amountOut, oneInchData); + console.log(`Function ENUM is: ${funcValue}`); +} + +main(); + diff --git a/scripts/test-scripts/decode/decoder/1inchDecoderLibrary.js b/scripts/test-scripts/decode/decoder/1inchDecoderLibrary.js new file mode 100644 index 0000000..3998d97 --- /dev/null +++ b/scripts/test-scripts/decode/decoder/1inchDecoderLibrary.js @@ -0,0 +1,104 @@ +const ethers = require('ethers'); + +const OneInchDecoder = { + decodeUnoswap: function (data) { + const decodedData = ethers.utils.defaultAbiCoder.decode( + ['address', 'address', 'uint256', 'uint256', 'uint256[]'], + data + ); + + return { + recipient: decodedData[0], + srcToken: decodedData[1], + amount: decodedData[2], + minReturn: decodedData[3], + pools: decodedData[4], + }; + }, + + decodeUniswapV3Swap: function (data) { + const decodedData = ethers.utils.defaultAbiCoder.decode( + ['address', 'uint256', 'uint256', 'uint256[]'], + data + ); + + return { + recipient: decodedData[0], + amount: decodedData[1], + minReturn: decodedData[2], + pools: decodedData[3], + }; + }, + + decodeSwap: function (data) { + const decodedData = ethers.utils.defaultAbiCoder.decode( + [ + 'address', + 'tuple(address,address,address,address,uint256,uint256,uint256)', + 'bytes', + 'bytes', + ], + data + ); + + return { + executor: decodedData[0], + desc: decodedData[1], + permit: decodedData[2], + swapData: decodedData[3], + }; + }, + + decodeFillOrderTo: function (data) { + const decodedData = ethers.utils.defaultAbiCoder.decode( + [ + 'tuple(uint256,address,address,address,address,address,uint256,uint256,uint256,bytes)', + 'bytes', + 'bytes', + 'uint256', + 'uint256', + 'uint256', + 'address', + ], + data + ); + + return { + order: decodedData[0], + signature: decodedData[1], + interaction: decodedData[2], + makingAmount: decodedData[3], + takingAmount: decodedData[4], + skipPermitAndThresholdAmount: decodedData[5], + target: decodedData[6], + }; + }, + + decodeFillOrderRFQTo: function (data) { + const decodedData = ethers.utils.defaultAbiCoder.decode( + [ + 'tuple(uint256,address,address,address,address,uint256,uint256)', + 'bytes', + 'uint256', + 'address', + ], + data + ); + + return { + order: decodedData[0], + signature: decodedData[1], + flagsAndAmount: decodedData[2], + target: decodedData[3], + }; + }, + + // Add constant selectors if needed + selectorUnoswap: '0xf78dc253', + selectorUniswapV3Swap: '0xbc80f1a8', + selectorSwap: '0x12aa3caf', + selectorFillOrderTo: '0xe5d7bde6', + selectorFillOrderRFQTo: '0x5a099843', +}; + +module.exports = OneInchDecoder; From 35f75641580a2dd76bd2d8e0853938dacc3f806c Mon Sep 17 00:00:00 2001 From: Salman Haider Date: Tue, 12 Mar 2024 17:10:08 +0500 Subject: [PATCH 2/8] Fixed Arithmetic Overflow/Underflow Error --- contracts/common/tokenReceiveable.sol | 6 ++++-- contracts/multiswap-contracts/FundManager.sol | 5 +---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/contracts/common/tokenReceiveable.sol b/contracts/common/tokenReceiveable.sol index e7f7a3b..73997b9 100644 --- a/contracts/common/tokenReceiveable.sol +++ b/contracts/common/tokenReceiveable.sol @@ -2,6 +2,7 @@ pragma solidity 0.8.2; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; +import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; /** @@ -9,6 +10,7 @@ import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; */ abstract contract TokenReceivable is ReentrancyGuard { using SafeERC20 for IERC20; + using SafeMath for uint256; mapping(address => uint256) public inventory; // Amount of received tokens that are accounted for /** @@ -19,7 +21,7 @@ abstract contract TokenReceivable is ReentrancyGuard { function sync(address token) internal nonReentrant returns (uint256 amount) { uint256 inv = inventory[token]; uint256 balance = IERC20(token).balanceOf(address(this)); - amount = balance - inv; + amount = balance.sub(inv); inventory[token] = balance; } @@ -30,7 +32,7 @@ abstract contract TokenReceivable is ReentrancyGuard { @param amount The amount */ function sendToken(address token, address payee, uint256 amount) internal nonReentrant { - inventory[token] = inventory[token] - amount; + inventory[token] = inventory[token].sub(amount); IERC20(token).safeTransfer(payee, amount); } } \ No newline at end of file diff --git a/contracts/multiswap-contracts/FundManager.sol b/contracts/multiswap-contracts/FundManager.sol index 5438bff..d833896 100644 --- a/contracts/multiswap-contracts/FundManager.sol +++ b/contracts/multiswap-contracts/FundManager.sol @@ -1,15 +1,12 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.2; -import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "../common/signature/SigCheckable.sol"; -import "../common/SafeAmount.sol"; -import "../common/tokenReceiveable.sol"; import "foundry-contracts/contracts/common/FerrumDeployer.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "./LiquidityManagerRole.sol"; -contract FundManager is SigCheckable, TokenReceivable, LiquidityManagerRole { +contract FundManager is SigCheckable, LiquidityManagerRole { using SafeERC20 for IERC20; address public router; From 7a6e8eb35c50570d15928abe1ded4c8e70964d81 Mon Sep 17 00:00:00 2001 From: Salman Haider Date: Tue, 12 Mar 2024 17:14:04 +0500 Subject: [PATCH 3/8] Improved LiquidityManagerRole with Sync Pattern --- .../LiquidityManagerRole.sol | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/contracts/multiswap-contracts/LiquidityManagerRole.sol b/contracts/multiswap-contracts/LiquidityManagerRole.sol index 0ed36fd..59b0be9 100644 --- a/contracts/multiswap-contracts/LiquidityManagerRole.sol +++ b/contracts/multiswap-contracts/LiquidityManagerRole.sol @@ -1,14 +1,17 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "../common/WithAdmin.sol"; +import "../common/SafeAmount.sol"; +import "../common/tokenReceiveable.sol"; -abstract contract LiquidityManagerRole is WithAdmin { +abstract contract LiquidityManagerRole is WithAdmin, TokenReceivable { using SafeERC20 for IERC20; address public liquidityManager; address public liquidityManagerBot; address public withdrawalAddress; + + event LiquidityAddedByManager(address token, uint256 amount); event LiquidityRemovedByManager(address token, uint256 amount, address withdrawalAddress); /** @@ -45,6 +48,21 @@ abstract contract LiquidityManagerRole is WithAdmin { withdrawalAddress = _withdrawalAddress; } + /** + * @dev Adds specified liquidity for the given token + * @param token Token address for liquidity addition + * @param amount Amount of tokens to be added + */ + function addLiquidityByManager(address token, uint256 amount) external onlyLiquidityManager { + require(amount != 0, "FM: Amount must be positive"); + require(token != address(0), "FM: Bad token"); + // Transfer tokens from the sender to the FundManager + SafeAmount.safeTransferFrom(token, msg.sender, address(this), amount); + // Update the inventory using sync + amount = TokenReceivable.sync(token); + emit LiquidityAddedByManager(token, amount); + } + /** * @dev Removes specified liquidity for the given token * @param token Token address for liquidity removal @@ -52,8 +70,14 @@ abstract contract LiquidityManagerRole is WithAdmin { * @return Actual amount of tokens removed */ function removeLiquidityByManager(address token, uint256 amount) external onlyLiquidityManager returns (uint256) { - IERC20(token).safeTransfer(withdrawalAddress, amount); + require(amount != 0, "FM: Amount must be positive"); + require(token != address(0), "FM: Bad token"); + // Check the Token balance of FundManager + require(IERC20(token).balanceOf(address(this)) >= amount, "FM: Insufficient balance"); + // Transfer tokens to the withdrawal address using sendToken + TokenReceivable.sendToken(token, withdrawalAddress, amount); emit LiquidityRemovedByManager(token, amount, withdrawalAddress); return amount; } + } From 8f8b1606ed760236cde88d7b6964044977e6d1a1 Mon Sep 17 00:00:00 2001 From: Salman Haider Date: Wed, 13 Mar 2024 18:39:55 +0500 Subject: [PATCH 4/8] config/deploy updates --- scripts/deploy/configContracts.js | 26 +++++++++---------- scripts/deploy/deployContracts.js | 42 ++++++------------------------- 2 files changed, 20 insertions(+), 48 deletions(-) diff --git a/scripts/deploy/configContracts.js b/scripts/deploy/configContracts.js index 755836b..34cbfc4 100644 --- a/scripts/deploy/configContracts.js +++ b/scripts/deploy/configContracts.js @@ -8,11 +8,11 @@ const fiberRouterABI = require("../../artifacts/contracts/multiswap-contracts/Fi const multiswapForgeABI = require('../../artifacts/contracts/multiswap-contracts/MultiswapForge.sol/MultiswapForge.json'); // Replace these with your actual contract addresses -const forgeManagerAddress = '0x1b94fe35B4303ec69de3617541002fFC9E4dDD36'; -const multiswapForgeAddress = '0xe259f6D87c9b9331031f9D0AD2A000206eFC3149'; +const forgeManagerAddress = '0x8490E6640047F6057D070bd5576A7725C25B7Bde'; +const multiswapForgeAddress = '0x5347D88B62573C9a3cCFf047C96314151e39d65d'; -const fiberRouterAddress = '0x7A32c872619DFE0f07d04ef8EBEe77C5d0622c58'; -const fundManagerAddress = '0xbD9D99bb2A136a1936B87031c7A8102831855289'; +const fiberRouterAddress = '0xfd595F8031f49b75CD0e85B902316f5F8a428C76'; +const fundManagerAddress = '0x4Ba81924a6D7DaF6Dba27783168E5b6345D6A896'; const foundryArbitrum = "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8"; const foundryBinance = "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"; @@ -24,7 +24,7 @@ const wethEthereum = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"; const oneInchAggregatorRouter = "0x1111111254EEB25477B68fb85Ed929f73A960582"; -const signerAddress = "0x0aee4E03645bB13b49Bb4e5784f7efB8Ee332073"; +const signerAddress = "0xF81f80C04C421F98c06232D2DF7E2aC8790bb19B"; const liquidityManager = "0x5dAC22dB4dEaCfab7e9A0A1425f25D6B18e9839C"; const liquidityManagerBot = "0x9B7C800DCca6273CB6DDb861764cFB95BDAb15cc" @@ -36,7 +36,7 @@ const settlementManagerAddress = "0x5912cE9327C2F8BE2Ffce1e8E521F6a65A870a19"; const gasWallet = "0xBFBFE0e25835625efa98161e3286Ca1290057E1a"; // the address that is allowed to call the estimate gas fee for withdrawal functions -const gasEstimationAddress = "0x896aa74980f510e17Ec22A9906b6ce82Ef84C49F" +const gasEstimationAddress = "0xF81f80C04C421F98c06232D2DF7E2aC8790bb19B" const binanceChainID = 56; const ethereumChainID = 1; @@ -47,7 +47,7 @@ async function main() { const arbiProvider = 'https://nd-829-997-700.p2pify.com/790712c620e64556719c7c9f19ef56e3'; const bscProvider = 'https://nd-049-483-298.p2pify.com/819ef21ecdd17a29a2ed1e856c7980ec'; - const provider = new ethers.providers.JsonRpcProvider(ethProvider); + const provider = new ethers.providers.JsonRpcProvider(arbiProvider); const wallet = new ethers.Wallet(process.env.PRIVATE_KEY0 , provider); // Connect to ForgeManager and MultiswapForge contracts @@ -59,7 +59,7 @@ async function main() { const fundManager = new ethers.Contract(fundManagerAddress, fundManagerABI.abi, provider); // Call setWETH on FundManager with WETH address - const wethSet = await fiberRouter.connect(wallet).setWETH(wethEthereum); + const wethSet = await fiberRouter.connect(wallet).setWETH(wethArbitrum); // Wait for the transaction receipt const receiptWethSet = await wethSet.wait(); @@ -70,7 +70,7 @@ async function main() { } // Call setRouter on ForgeManager with WETH address - const wethForgeSet = await multiswapForge.connect(wallet).setWETH(wethEthereum); + const wethForgeSet = await multiswapForge.connect(wallet).setWETH(wethArbitrum); // Wait for the transaction receipt const receiptWethForgeSet = await wethForgeSet.wait(); @@ -147,7 +147,7 @@ async function main() { } // Call allowTarget on FundManager with specified addresses - const targetAllowed = await fundManager.connect(wallet).allowTarget(foundryEthereum, arbitrumChainID, foundryArbitrum); + const targetAllowed = await fundManager.connect(wallet).allowTarget(foundryArbitrum, ethereumChainID, foundryEthereum); // Wait for the transaction receipt const receiptTargetAllowed = await targetAllowed.wait(); @@ -159,7 +159,7 @@ async function main() { // Call allowTarget on FundManager with specified addresses - const targetAllowed2 = await fundManager.connect(wallet).allowTarget(foundryEthereum, binanceChainID, foundryBinance); + const targetAllowed2 = await fundManager.connect(wallet).allowTarget(foundryArbitrum, binanceChainID, foundryBinance); // Wait for the transaction receipt const receiptTargetAllowed2 = await targetAllowed2.wait(); @@ -181,7 +181,7 @@ async function main() { } // Call addFoundryAsset on FundManager - const foundryAdded = await fundManager.connect(wallet).addFoundryAsset(foundryEthereum); + const foundryAdded = await fundManager.connect(wallet).addFoundryAsset(foundryArbitrum); // Wait for the transaction receipt const receiptFoundryAdded = await foundryAdded.wait(); @@ -192,7 +192,7 @@ async function main() { } // Call addFoundryAsset on ForgeManager - const forgeFoundryAdded = await forgeManager.connect(wallet).addFoundryAsset(foundryEthereum); + const forgeFoundryAdded = await forgeManager.connect(wallet).addFoundryAsset(foundryArbitrum); // Wait for the transaction receipt const receiptForgeFoundryAdded = await forgeFoundryAdded.wait(); diff --git a/scripts/deploy/deployContracts.js b/scripts/deploy/deployContracts.js index 1f83497..c349ba9 100644 --- a/scripts/deploy/deployContracts.js +++ b/scripts/deploy/deployContracts.js @@ -31,65 +31,37 @@ async function main() { }); console.log("Contract verified successfully !"); - // Deploy OneInchDecoder library - const OneInchDecoder = await ethers.getContractFactory('OneInchDecoder'); - const oneInchDecoder = await OneInchDecoder.deploy(); - await oneInchDecoder.deployed(); - console.log('OneInchDecoder library deployed to:', oneInchDecoder.address); - // Replace these with actual values - const wethAddress = "0x"; + const wethAddress = "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"; const oneInchAggregatorRouterAddress = "0x1111111254EEB25477B68fb85Ed929f73A960582"; const poolFundManager = fundManager.address; const poolForge = forgeManager.address; // Deploy FiberRouter with the address of OneInchDecoder and other parameters - const FiberRouter = await ethers.getContractFactory('FiberRouter', { - libraries: { - OneInchDecoder: oneInchDecoder.address, - }, - }); - const fiberRouter = await FiberRouter.deploy(wethAddress, oneInchAggregatorRouterAddress, poolFundManager); + const FiberRouter = await ethers.getContractFactory('FiberRouter'); + const fiberRouter = await FiberRouter.deploy(); await fiberRouter.deployed(); console.log('FiberRouter deployed to:', fiberRouter.address); console.log("Verifing..."); - await hre.run("verify:verify", { - address: oneInchDecoder.address, - constructorArguments: [], - }); await hre.run("verify:verify", { address: fiberRouter.address, - constructorArguments: [wethAddress, oneInchAggregatorRouterAddress, poolFundManager], - libraries: { - OneInchDecoder : oneInchDecoder.address, - }, + constructorArguments: [] }); console.log("Contract verified successfully !"); // Deploy MultiswapForge with the address of FiberRouter and other parameters - const MultiswapForge = await ethers.getContractFactory('MultiSwapForge', { - libraries: { - OneInchDecoder: oneInchDecoder.address, - }, - }); - - const multiswapForge = await MultiswapForge.deploy(wethAddress, oneInchAggregatorRouterAddress, poolForge); + const MultiswapForge = await ethers.getContractFactory('MultiSwapForge'); + const multiswapForge = await MultiswapForge.deploy(); await multiswapForge.deployed(); console.log('MultiswapForge deployed to:', multiswapForge.address); await hre.run("verify:verify", { address: multiswapForge.address, - constructorArguments: [wethAddress, oneInchAggregatorRouterAddress, poolForge], - libraries: { - OneInchDecoder : oneInchDecoder.address, - }, + constructorArguments: [], }); console.log("Contract verified successfully !"); } - - - main() .then(() => process.exit(0)) .catch((error) => { From 31724b029d21bde9032ac2dbec965e6f93b382d8 Mon Sep 17 00:00:00 2001 From: Salman Haider Date: Mon, 1 Apr 2024 15:48:10 +0500 Subject: [PATCH 5/8] same-network-swap --- contracts/multiswap-contracts/FiberRouter.sol | 144 +++++++- .../LiquidityManagerRole.sol | 4 - hardhat.config.js | 27 +- ...nfigContracts.js => configContractsDev.js} | 82 ++++- scripts/deploy/configContractsProd.js | 322 ++++++++++++++++++ scripts/deploy/deployContracts.js | 8 - 6 files changed, 557 insertions(+), 30 deletions(-) rename scripts/deploy/{configContracts.js => configContractsDev.js} (76%) create mode 100644 scripts/deploy/configContractsProd.js diff --git a/contracts/multiswap-contracts/FiberRouter.sol b/contracts/multiswap-contracts/FiberRouter.sol index c9d7a1a..bb5f719 100644 --- a/contracts/multiswap-contracts/FiberRouter.sol +++ b/contracts/multiswap-contracts/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"; @@ -70,6 +70,16 @@ contract FiberRouter is Ownable, TokenReceivable { uint256 gasAmount ); + // Emit Swap event + event SwapSameNetwork( + address sourceToken, + address targetToken, + uint256 sourceAmount, + uint256 settledAmount, + address sourceAddress, + address targetAddress + ); + event Withdraw( address token, address receiver, @@ -122,7 +132,7 @@ contract FiberRouter is Ownable, TokenReceivable { ); /** - * @dev Constructor that sets the WETH address, oneInchAggregator address, and the pool address. + * @dev Constructor that sets FerrumDeployer InitData */ constructor() { bytes memory initData = IFerrumDeployer(msg.sender).initData(); @@ -179,6 +189,136 @@ contract FiberRouter is Ownable, TokenReceivable { oneInchAggregatorRouter = _newRouterAddress; } +/** + * @dev Perform a same network token swap using 1inch + * @param amountIn The input amount + * @param amountOut Equivalent to amountOut on oneInch + * @param fromToken The token to be swapped + * @param toToken The token to receive after the swap + * @param targetAddress The receiver address + * @param oneInchData The data containing information for the 1inch swap + * @param funcSelector selector enum for deciding which 1inch fucntion to call + */ +function swapOnSameNetwork( + uint256 amountIn, + uint256 amountOut, // amountOut on oneInch + address fromToken, + address toToken, + address targetAddress, + bytes memory oneInchData, + OneInchFunction funcSelector +) external nonReentrant { + // Validation checks + require(fromToken != address(0), "FR: From token address cannot be zero"); + require(toToken != address(0), "FR: To token address cannot be zero"); + require(amountIn != 0, "FR: Amount in must be greater than zero"); + require(amountOut != 0, "FR: Amount out must be greater than zero"); + require(targetAddress != address(0), "FR: Target address cannot be zero"); + require(bytes(oneInchData).length != 0, "FR: 1inch data cannot be empty"); + + // Perform the token swap using 1inch + uint256 settledAmount = _swapOnSameNetwork( + amountIn, + amountOut, + fromToken, + targetAddress, + oneInchData, + funcSelector // Pass the enum parameter + ); + + // Emit Swap event + emit SwapSameNetwork( + fromToken, + toToken, + amountIn, + settledAmount, + _msgSender(), + targetAddress + ); +} + +/** + * @dev Performs a native currency swap and cross to another token on the same network using 1inch + * @param amountOut The expected amount of output tokens after the swap on 1inch + * @param oneInchData The data containing information for the 1inch swap + * @param toToken The token to receive after the swap + * @param funcSelector Enum parameter to identify the function for 1inch swap + */ +function swapOnSameNetworkETH( + uint256 amountOut, // amountOut on oneInch + address toToken, + address targetAddress, + bytes memory oneInchData, + OneInchFunction funcSelector // Add the enum parameter +) external payable { + uint256 amountIn = msg.value; + // Validation checks + require(toToken != address(0), "FR: To token address cannot be zero"); + require(amountIn != 0, "FR: Amount in must be greater than zero"); + require(amountOut != 0, "FR: Amount out must be greater than zero"); + require(targetAddress != address(0), "FR: Target address cannot be zero"); + require(bytes(oneInchData).length != 0, "FR: 1inch data cannot be empty"); + + // Deposit ETH and get WETH + IWETH(WETH).deposit{value: amountIn}(); + + // Execute swap and cross-chain operation + uint256 settledAmount = _swapOnSameNetwork( + amountIn, + amountOut, + WETH, + targetAddress, + oneInchData, + funcSelector // Pass the function selector + ); + + // Emit Swap event + emit SwapSameNetwork( + WETH, + toToken, + amountIn, + settledAmount, + _msgSender(), + targetAddress + ); +} + +/** + * @dev Perform a same network token swap using 1inch + * @param amountIn The input amount + * @param amountOut Equivalent to amountOut on oneInch + * @param fromToken The token to be swapped + * @param targetAddress The receiver address + * @param oneInchData The data containing information for the 1inch swap + * @param funcSelector selector enum for deciding which 1inch fucntion to call + */ +function _swapOnSameNetwork( + uint256 amountIn, + uint256 amountOut, + address fromToken, + address targetAddress, + bytes memory oneInchData, + OneInchFunction funcSelector +) internal returns (uint256 settledAmount) { + // Check if allowance is non-zero + if (IERC20(fromToken).allowance(address(this), oneInchAggregatorRouter) != 0) { + // Reset the allowance to zero + IERC20(fromToken).safeApprove(oneInchAggregatorRouter, 0); + } + // Set the allowance to the swap amount + IERC20(fromToken).safeApprove(oneInchAggregatorRouter, amountIn); + + // Perform the token swap using 1inch + settledAmount = swapHelperForOneInch( + payable(targetAddress), + fromToken, + amountIn, + amountOut, + oneInchData, + funcSelector // Pass the enum parameter + ); +} + /** * @dev Initiate an x-chain swap. * @param token The token to be swapped diff --git a/contracts/multiswap-contracts/LiquidityManagerRole.sol b/contracts/multiswap-contracts/LiquidityManagerRole.sol index fdc96fc..59b0be9 100644 --- a/contracts/multiswap-contracts/LiquidityManagerRole.sol +++ b/contracts/multiswap-contracts/LiquidityManagerRole.sol @@ -80,8 +80,4 @@ abstract contract LiquidityManagerRole is WithAdmin, TokenReceivable { return amount; } -<<<<<<< HEAD } -======= -} ->>>>>>> 7a6e8eb35c50570d15928abe1ded4c8e70964d81 diff --git a/hardhat.config.js b/hardhat.config.js index 25b6853..1e6ba14 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -38,7 +38,11 @@ module.exports = { accounts: [process.env.PRIVATE_KEY0], }, sepolia: { - url: `https://sepolia.infura.io/v3/${process.env.INFURA_API_KEY}`, + url: `https://ethereum-sepolia-rpc.publicnode.com`, + accounts: [process.env.PRIVATE_KEY0] + }, + mumbai: { + url: `https://polygon-mumbai-pokt.nodies.app`, accounts: [process.env.PRIVATE_KEY0] }, polygon: { @@ -58,7 +62,7 @@ module.exports = { accounts: [process.env.PRIVATE_KEY0] }, optimismMainnet: { - url: 'https://mainnet.optimism.io', + url: 'https://optimism-mainnet.core.chainstack.com/7cb5109bd1c125224315d9b753cc0e45', accounts: [process.env.PRIVATE_KEY0] }, ethereum: { @@ -68,12 +72,25 @@ module.exports = { arbitrum: { url: 'https://nd-829-997-700.p2pify.com/790712c620e64556719c7c9f19ef56e3', accounts: [process.env.PRIVATE_KEY0] + }, + scroll: { + url: 'https://scroll-mainnet.core.chainstack.com/26406aa9a6209c7577a5ab1ff15243cd', + accounts: [process.env.PRIVATE_KEY0] + }, + zksync: { + url: 'https://nd-559-202-193.p2pify.com/43eb159adcbe7f31f7f192309025670e', + accounts: [process.env.PRIVATE_KEY0] + }, + base: { + url: 'https://base-mainnet.core.chainstack.com/e7aa01c976c532ebf8e2480a27f18278', + accounts: [process.env.PRIVATE_KEY0] } }, etherscan: { // apiKey: process.env.ARBITRUM_API_KEY, - // apiKey: process.env.BINANCE_API_KEY, - apiKey: process.env.ETHEREUM_API_KEY, - + apiKey: process.env.BINANCE_API_KEY, + // apiKey: process.env.MUMBAI_API_KEY, + // apiKey: process.env.AVALANCHE_API_KEY, + // apiKey: process.env.OPTIMISM_API_KEY, }, }; \ No newline at end of file diff --git a/scripts/deploy/configContracts.js b/scripts/deploy/configContractsDev.js similarity index 76% rename from scripts/deploy/configContracts.js rename to scripts/deploy/configContractsDev.js index 34cbfc4..96e0b0d 100644 --- a/scripts/deploy/configContracts.js +++ b/scripts/deploy/configContractsDev.js @@ -8,19 +8,27 @@ const fiberRouterABI = require("../../artifacts/contracts/multiswap-contracts/Fi const multiswapForgeABI = require('../../artifacts/contracts/multiswap-contracts/MultiswapForge.sol/MultiswapForge.json'); // Replace these with your actual contract addresses -const forgeManagerAddress = '0x8490E6640047F6057D070bd5576A7725C25B7Bde'; -const multiswapForgeAddress = '0x5347D88B62573C9a3cCFf047C96314151e39d65d'; +const forgeManagerAddress = ''; +const multiswapForgeAddress = ''; -const fiberRouterAddress = '0xfd595F8031f49b75CD0e85B902316f5F8a428C76'; -const fundManagerAddress = '0x4Ba81924a6D7DaF6Dba27783168E5b6345D6A896'; +const fiberRouterAddress = ''; +const fundManagerAddress = ''; const foundryArbitrum = "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8"; const foundryBinance = "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"; const foundryEthereum = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; +const foundryOptimism = "0x0b2c639c533813f4aa9d7837caf62653d097ff85"; +const foundryAvalanche = "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E"; +const foundryBase = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"; +const foundryScroll = "0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4"; const wethArbitrum = "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"; const wethBinance = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; const wethEthereum = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"; +const wethOptimism = "0x4200000000000000000000000000000000000006"; +const wethAvalanche = "0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab"; +const wethBase = "0x4200000000000000000000000000000000000006"; +const wethScroll = "0x5300000000000000000000000000000000000004"; const oneInchAggregatorRouter = "0x1111111254EEB25477B68fb85Ed929f73A960582"; @@ -41,13 +49,21 @@ const gasEstimationAddress = "0xF81f80C04C421F98c06232D2DF7E2aC8790bb19B" const binanceChainID = 56; const ethereumChainID = 1; const arbitrumChainID = 42161; +const optimismChainID = 10; +const AvalancheChainID = 43114; +const baseChainID = 8453; +const scrollChainID = 534352; async function main() { const ethProvider = 'https://nd-611-696-948.p2pify.com/8a54d0bc389e645253087fd1a6c5fe3a'; const arbiProvider = 'https://nd-829-997-700.p2pify.com/790712c620e64556719c7c9f19ef56e3'; const bscProvider = 'https://nd-049-483-298.p2pify.com/819ef21ecdd17a29a2ed1e856c7980ec'; + const opProvider = "https://optimism-mainnet.core.chainstack.com/7cb5109bd1c125224315d9b753cc0e45"; + const avalancheProvider = "https://nd-118-315-546.p2pify.com/048dd2e7493f4804ffed70b2acfffe8b/ext/bc/C/rpc"; + const baseProvider = "https://base-mainnet.core.chainstack.com/e7aa01c976c532ebf8e2480a27f18278"; + const scrollProvider = "https://scroll-mainnet.core.chainstack.com/26406aa9a6209c7577a5ab1ff15243cd"; - const provider = new ethers.providers.JsonRpcProvider(arbiProvider); + const provider = new ethers.providers.JsonRpcProvider(avalancheProvider); const wallet = new ethers.Wallet(process.env.PRIVATE_KEY0 , provider); // Connect to ForgeManager and MultiswapForge contracts @@ -59,7 +75,7 @@ async function main() { const fundManager = new ethers.Contract(fundManagerAddress, fundManagerABI.abi, provider); // Call setWETH on FundManager with WETH address - const wethSet = await fiberRouter.connect(wallet).setWETH(wethArbitrum); + const wethSet = await fiberRouter.connect(wallet).setWETH(wethAvalanche); // Wait for the transaction receipt const receiptWethSet = await wethSet.wait(); @@ -70,7 +86,7 @@ async function main() { } // Call setRouter on ForgeManager with WETH address - const wethForgeSet = await multiswapForge.connect(wallet).setWETH(wethArbitrum); + const wethForgeSet = await multiswapForge.connect(wallet).setWETH(wethAvalanche); // Wait for the transaction receipt const receiptWethForgeSet = await wethForgeSet.wait(); @@ -147,7 +163,7 @@ async function main() { } // Call allowTarget on FundManager with specified addresses - const targetAllowed = await fundManager.connect(wallet).allowTarget(foundryArbitrum, ethereumChainID, foundryEthereum); + const targetAllowed = await fundManager.connect(wallet).allowTarget(foundryAvalanche, ethereumChainID, foundryEthereum); // Wait for the transaction receipt const receiptTargetAllowed = await targetAllowed.wait(); @@ -159,7 +175,7 @@ async function main() { // Call allowTarget on FundManager with specified addresses - const targetAllowed2 = await fundManager.connect(wallet).allowTarget(foundryArbitrum, binanceChainID, foundryBinance); + const targetAllowed2 = await fundManager.connect(wallet).allowTarget(foundryAvalanche, binanceChainID, foundryBinance); // Wait for the transaction receipt const receiptTargetAllowed2 = await targetAllowed2.wait(); @@ -169,6 +185,50 @@ async function main() { console.log("Transaction failed"); } + // Call allowTarget on FundManager with specified addresses + const targetAllowed3 = await fundManager.connect(wallet).allowTarget(foundryAvalanche, arbitrumChainID, foundryArbitrum); + // Wait for the transaction receipt + const receiptTargetAllowed3 = await targetAllowed3.wait(); + + if (receiptTargetAllowed3.status == 1) { + console.log("AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + // Call allowTarget on FundManager with specified addresses + const targetAllowed4 = await fundManager.connect(wallet).allowTarget(foundryAvalanche, optimismChainID, foundryOptimism); + // Wait for the transaction receipt + const receiptTargetAllowed4 = await targetAllowed4.wait(); + + if (receiptTargetAllowed4.status == 1) { + console.log("AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + // Call allowTarget on FundManager with specified addresses + const targetAllowed5 = await fundManager.connect(wallet).allowTarget(foundryAvalanche, baseChainID, foundryBase); + // Wait for the transaction receipt + const receiptTargetAllowed5 = await targetAllowed5.wait(); + + if (receiptTargetAllowed5.status == 1) { + console.log("AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + // Call allowTarget on FundManager with specified addresses + const targetAllowed6 = await fundManager.connect(wallet).allowTarget(foundryAvalanche, scrollChainID, foundryScroll); + // Wait for the transaction receipt + const receiptTargetAllowed6 = await targetAllowed6.wait(); + + if (receiptTargetAllowed6.status == 1) { + console.log("AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + // Call addSigner on FundManager with signer address const signerAdded = await fundManager.connect(wallet).addSigner(signerAddress); // Wait for the transaction receipt @@ -181,7 +241,7 @@ async function main() { } // Call addFoundryAsset on FundManager - const foundryAdded = await fundManager.connect(wallet).addFoundryAsset(foundryArbitrum); + const foundryAdded = await fundManager.connect(wallet).addFoundryAsset(foundryAvalanche); // Wait for the transaction receipt const receiptFoundryAdded = await foundryAdded.wait(); @@ -192,7 +252,7 @@ async function main() { } // Call addFoundryAsset on ForgeManager - const forgeFoundryAdded = await forgeManager.connect(wallet).addFoundryAsset(foundryArbitrum); + const forgeFoundryAdded = await forgeManager.connect(wallet).addFoundryAsset(foundryAvalanche); // Wait for the transaction receipt const receiptForgeFoundryAdded = await forgeFoundryAdded.wait(); diff --git a/scripts/deploy/configContractsProd.js b/scripts/deploy/configContractsProd.js new file mode 100644 index 0000000..fff255e --- /dev/null +++ b/scripts/deploy/configContractsProd.js @@ -0,0 +1,322 @@ +const { ethers } = require('ethers'); +require('dotenv').config(); + +// Import ABIs for contracts +const forgeManagerABI = require('../../artifacts/contracts/multiswap-contracts/ForgeManager.sol/ForgeFundManager.json'); +const fundManagerABI = require('../../artifacts/contracts/multiswap-contracts/FundManager.sol/FundManager.json'); +const fiberRouterABI = require("../../artifacts/contracts/multiswap-contracts/FiberRouter.sol/FiberRouter.json"); +const multiswapForgeABI = require('../../artifacts/contracts/multiswap-contracts/MultiswapForge.sol/MultiswapForge.json'); + +// Replace these with your actual contract addresses +const forgeManagerAddress = ''; +const multiswapForgeAddress = ''; + +const fiberRouterAddress = ''; +const fundManagerAddress = ''; + +const foundryArbitrum = "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8"; +const foundryBinance = "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"; +const foundryEthereum = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; +const foundryOptimism = "0x0b2c639c533813f4aa9d7837caf62653d097ff85"; +const foundryAvalanche = "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E"; +const foundryBase = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"; +const foundryScroll = "0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4"; + +const wethArbitrum = "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"; +const wethBinance = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; +const wethEthereum = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"; +const wethOptimism = "0x4200000000000000000000000000000000000006"; +const wethAvalanche = "0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab"; +const wethBase = "0x4200000000000000000000000000000000000006"; +const wethScroll = "0x5300000000000000000000000000000000000004"; + +const oneInchAggregatorRouter = "0x1111111254EEB25477B68fb85Ed929f73A960582"; + +const signerAddress = "0x0aee4E03645bB13b49Bb4e5784f7efB8Ee332073"; + +const liquidityManager = "0x5dAC22dB4dEaCfab7e9A0A1425f25D6B18e9839C"; +const liquidityManagerBot = "0x9B7C800DCca6273CB6DDb861764cFB95BDAb15cc" +const withdrawalAddress = "0x1370172Ed69Ec231cDB8E59d928D42824094c0C6" + +const settlementManagerAddress = "0x5912cE9327C2F8BE2Ffce1e8E521F6a65A870a19"; + +// The wallet where the gas received from sourceNetwork will be transferred +const gasWallet = "0xBFBFE0e25835625efa98161e3286Ca1290057E1a"; + +// the address that is allowed to call the estimate gas fee for withdrawal functions +const gasEstimationAddress = "0x896aa74980f510e17Ec22A9906b6ce82Ef84C49F" + +const binanceChainID = 56; +const ethereumChainID = 1; +const arbitrumChainID = 42161; +const optimismChainID = 10; +const AvalancheChainID = 43114; +const baseChainID = 8453; +const scrollChainID = 534352; + +async function main() { + const ethProvider = 'https://nd-611-696-948.p2pify.com/8a54d0bc389e645253087fd1a6c5fe3a'; + const arbiProvider = 'https://nd-829-997-700.p2pify.com/790712c620e64556719c7c9f19ef56e3'; + const bscProvider = 'https://nd-049-483-298.p2pify.com/819ef21ecdd17a29a2ed1e856c7980ec'; + const opProvider = "https://optimism-mainnet.core.chainstack.com/7cb5109bd1c125224315d9b753cc0e45"; + const avalancheProvider = "https://nd-118-315-546.p2pify.com/048dd2e7493f4804ffed70b2acfffe8b/ext/bc/C/rpc"; + const baseProvider = "https://base-mainnet.core.chainstack.com/e7aa01c976c532ebf8e2480a27f18278"; + const scrollProvider = "https://scroll-mainnet.core.chainstack.com/26406aa9a6209c7577a5ab1ff15243cd"; + + + const provider = new ethers.providers.JsonRpcProvider(opProvider); + const wallet = new ethers.Wallet(process.env.PRIVATE_KEY0 , provider); + + // Connect to ForgeManager and MultiswapForge contracts + const forgeManager = new ethers.Contract(forgeManagerAddress, forgeManagerABI.abi, provider); + const multiswapForge = new ethers.Contract(multiswapForgeAddress, multiswapForgeABI.abi, provider); + +// // Connect to FiberRouter and FundManager contracts + const fiberRouter = new ethers.Contract(fiberRouterAddress, fiberRouterABI.abi, provider); + const fundManager = new ethers.Contract(fundManagerAddress, fundManagerABI.abi, provider); + + // Call setWETH on FundManager with WETH address + const wethSet = await fiberRouter.connect(wallet).setWETH(wethOptimism); + // Wait for the transaction receipt + const receiptWethSet = await wethSet.wait(); + + if (receiptWethSet.status == 1) { + console.log("WETH address added successfully in FiberRouter!"); + } else { + console.log("Transaction failed"); + } + + // Call setRouter on ForgeManager with WETH address + const wethForgeSet = await multiswapForge.connect(wallet).setWETH(wethOptimism); + // Wait for the transaction receipt + const receiptWethForgeSet = await wethForgeSet.wait(); + + if (receiptWethForgeSet.status == 1) { + console.log("WETH address added successfully in MultiSwapForge!"); + } else { + console.log("Transaction failed"); + } + +// Call setPool on FiberRouter with FundManager address + const poolFundManagerSet = await fiberRouter.connect(wallet).setPool(fundManagerAddress); + // Wait for the transaction receipt + const receiptPoolFundManagerSet = await poolFundManagerSet.wait(); + + if (receiptPoolFundManagerSet.status == 1) { + console.log("Pool Fund Manager address added successfully in FiberRouter!"); + } else { + console.log("Transaction failed"); + } + + // Call setPool on MultiSwapForge with ForgeManager address + const poolForgeManagerSet = await multiswapForge.connect(wallet).setPool(forgeManagerAddress); + // Wait for the transaction receipt + const receiptPoolForgeManagerSet = await poolForgeManagerSet.wait(); + + if (receiptPoolForgeManagerSet.status == 1) { + console.log("Pool Forge Manager address added successfully in MultiSwap Forge!"); + } else { + console.log("Transaction failed"); + } + + // Call setOneInchAggregatorRouter on FiberRouter with oneInchAggregatorRouter address + const oneInchAddressSet = await fiberRouter.connect(wallet).setOneInchAggregatorRouter(oneInchAggregatorRouter); + // Wait for the transaction receipt + const receiptOneInchAddressSet = await oneInchAddressSet.wait(); + + if (receiptOneInchAddressSet.status == 1) { + console.log("OneInch Aggregator address added successfully in FiberRouter!"); + } else { + console.log("Transaction failed"); + } + + // Call setOneInchAggregatorRouter on MultiSwap Forge with oneInchAggregatorRouter address + const oneInchAddressForgeSet = await multiswapForge.connect(wallet).setOneInchAggregatorRouter(oneInchAggregatorRouter); + // Wait for the transaction receipt + const receiptOneInchAddressForgeSet = await oneInchAddressForgeSet.wait(); + + if (receiptOneInchAddressForgeSet.status == 1) { + console.log("OneInch Aggregator address added successfully in MultiSwap Forge!"); + } else { + console.log("Transaction failed"); + } + + // Call setRouter on FundManager with FiberRouter address + const routerSet = await fundManager.connect(wallet).setRouter(fiberRouter.address); + // Wait for the transaction receipt + const receiptRouterSet = await routerSet.wait(); + + if (receiptRouterSet.status == 1) { + console.log("Router added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + // Call setRouter on ForgeManager with MultiswapForge address + const forgeSet = await forgeManager.connect(wallet).setRouter(multiswapForge.address); + // Wait for the transaction receipt + const receiptForgeSet = await forgeSet.wait(); + + if (receiptForgeSet.status == 1) { + console.log("Forge added successfully in ForgeManager!"); + } else { + console.log("Transaction failed"); + } + + // Call allowTarget on FundManager with specified addresses + const targetAllowed = await fundManager.connect(wallet).allowTarget(foundryOptimism, ethereumChainID, foundryEthereum); + // Wait for the transaction receipt + const receiptTargetAllowed = await targetAllowed.wait(); + + if (receiptTargetAllowed.status == 1) { + console.log("AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + + // Call allowTarget on FundManager with specified addresses + const targetAllowed2 = await fundManager.connect(wallet).allowTarget(foundryOptimism, binanceChainID, foundryBinance); + // Wait for the transaction receipt + const receiptTargetAllowed2 = await targetAllowed2.wait(); + + if (receiptTargetAllowed2.status == 1) { + console.log("AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + // Call allowTarget on FundManager with specified addresses + const targetAllowed3 = await fundManager.connect(wallet).allowTarget(foundryOptimism, arbitrumChainID, foundryArbitrum); + // Wait for the transaction receipt + const receiptTargetAllowed3 = await targetAllowed3.wait(); + + if (receiptTargetAllowed3.status == 1) { + console.log("AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + // Call allowTarget on FundManager with specified addresses + const targetAllowed4 = await fundManager.connect(wallet).allowTarget(foundryOptimism, AvalancheChainID, foundryAvalanche); + // Wait for the transaction receipt + const receiptTargetAllowed4 = await targetAllowed4.wait(); + + if (receiptTargetAllowed4.status == 1) { + console.log("AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + // Call allowTarget on FundManager with specified addresses + const targetAllowed5 = await fundManager.connect(wallet).allowTarget(foundryOptimism, baseChainID, foundryBase); + // Wait for the transaction receipt + const receiptTargetAllowed5 = await targetAllowed5.wait(); + + if (receiptTargetAllowed5.status == 1) { + console.log("AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + // Call allowTarget on FundManager with specified addresses + const targetAllowed6 = await fundManager.connect(wallet).allowTarget(foundryOptimism, scrollChainID, foundryScroll); + // Wait for the transaction receipt + const receiptTargetAllowed6 = await targetAllowed6.wait(); + + if (receiptTargetAllowed6.status == 1) { + console.log("AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + // Call addSigner on FundManager with signer address + const signerAdded = await fundManager.connect(wallet).addSigner(signerAddress); + // Wait for the transaction receipt + const receiptSignerAdded = await signerAdded.wait(); + + if (receiptSignerAdded.status == 1) { + console.log("Signer added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + // Call addFoundryAsset on FundManager + const foundryAdded = await fundManager.connect(wallet).addFoundryAsset(foundryOptimism); + // Wait for the transaction receipt + const receiptFoundryAdded = await foundryAdded.wait(); + + if (receiptFoundryAdded.status == 1) { + console.log("USDC Foundry added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + // Call addFoundryAsset on ForgeManager + const forgeFoundryAdded = await forgeManager.connect(wallet).addFoundryAsset(foundryOptimism); + // Wait for the transaction receipt + const receiptForgeFoundryAdded = await forgeFoundryAdded.wait(); + + if (receiptForgeFoundryAdded.status == 1) { + console.log("USDC Foundry added successfully in ForgeManager!"); + } else { + console.log("Transaction failed"); + } + + // Call setGasWallet on FiberRouter with gasWallet address + const gasWalletAdded = await fiberRouter.connect(wallet).setGasWallet(gasWallet); + // Wait for the transaction receipt + const receiptGasWalletAdded = await gasWalletAdded.wait(); + + if (receiptGasWalletAdded.status == 1) { + console.log("GasWallet added successfully in FiberRouter!"); + } else { + console.log("Transaction failed"); + } + + // Call addSigner on FundManager with signer address + const gasEstimationAddressAdded = await multiswapForge.connect(wallet).setGasEstimationAddress(gasEstimationAddress); + // Wait for the transaction receipt + const receiptGasEstimationAddressAdded = await gasEstimationAddressAdded.wait(); + + if (receiptGasEstimationAddressAdded.status == 1) { + console.log("Gas Estimation Address added successfully in MultiSwapForge!"); + } else { + console.log("Transaction failed"); + } + + // Call setLiquidityManagers on FundManager with liquidity manager addresses + const liquidityManagerAdded = await fundManager.connect(wallet).setLiquidityManagers(liquidityManager, liquidityManagerBot); + // Wait for the transaction receipt + const receiptLiquidityManagerAdded = await liquidityManagerAdded.wait(); + + if (receiptLiquidityManagerAdded.status == 1) { + console.log("Liquidity Managers added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + // Call setWithdrawalAddress on FundManager with liquidity withdrawal addresses + const withdrawalAddressAdded = await fundManager.connect(wallet).setWithdrawalAddress(withdrawalAddress); + // Wait for the transaction receipt + const receiptWithdrawalAddressAdded = await withdrawalAddressAdded.wait(); + + if (receiptWithdrawalAddressAdded.status == 1) { + console.log("Liquidity Withdrawal Address added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + // Call setSettlementManager on FundManager with Settlement Manager address + const settlementManagerAddressAdded = await fundManager.connect(wallet).setSettlementManager(settlementManagerAddress); + // Wait for the transaction receipt + const receiptSettlementManagerAddressAdded = await settlementManagerAddressAdded.wait(); + + if (receiptSettlementManagerAddressAdded.status == 1) { + console.log("Settlement Manager address added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } +} + +main(); \ No newline at end of file diff --git a/scripts/deploy/deployContracts.js b/scripts/deploy/deployContracts.js index c349ba9..4e92dc1 100644 --- a/scripts/deploy/deployContracts.js +++ b/scripts/deploy/deployContracts.js @@ -2,8 +2,6 @@ const { ethers } = require('hardhat'); async function main() { -// Compile the contracts and libraries - await hre.run('compile'); // Deploy FundManager (Parent) const FundManager = await ethers.getContractFactory('FundManager'); @@ -31,12 +29,6 @@ async function main() { }); console.log("Contract verified successfully !"); - // Replace these with actual values - const wethAddress = "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"; - const oneInchAggregatorRouterAddress = "0x1111111254EEB25477B68fb85Ed929f73A960582"; - const poolFundManager = fundManager.address; - const poolForge = forgeManager.address; - // Deploy FiberRouter with the address of OneInchDecoder and other parameters const FiberRouter = await ethers.getContractFactory('FiberRouter'); const fiberRouter = await FiberRouter.deploy(); From 225506954b6f944e4179b38f3efbe7d3e0d57a2b Mon Sep 17 00:00:00 2001 From: Salman Haider Date: Mon, 1 Apr 2024 16:23:15 +0500 Subject: [PATCH 6/8] Same network swap fix --- contracts/multiswap-contracts/FiberRouter.sol | 6 ++ .../decode/decoder/1inchDecoder.js | 64 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 scripts/test-scripts/decode/decoder/1inchDecoder.js diff --git a/contracts/multiswap-contracts/FiberRouter.sol b/contracts/multiswap-contracts/FiberRouter.sol index bb5f719..fdaabb4 100644 --- a/contracts/multiswap-contracts/FiberRouter.sol +++ b/contracts/multiswap-contracts/FiberRouter.sol @@ -216,6 +216,12 @@ function swapOnSameNetwork( require(targetAddress != address(0), "FR: Target address cannot be zero"); require(bytes(oneInchData).length != 0, "FR: 1inch data cannot be empty"); + amountIn = SafeAmount.safeTransferFrom( + fromToken, + _msgSender(), + address(this), + amountIn + ); // Perform the token swap using 1inch uint256 settledAmount = _swapOnSameNetwork( amountIn, diff --git a/scripts/test-scripts/decode/decoder/1inchDecoder.js b/scripts/test-scripts/decode/decoder/1inchDecoder.js new file mode 100644 index 0000000..10a5207 --- /dev/null +++ b/scripts/test-scripts/decode/decoder/1inchDecoder.js @@ -0,0 +1,64 @@ +const ethers = require('ethers'); + + const selectorUnoswap = '0xf78dc253'; + const selectorUniswapV3Swap = '0xbc80f1a8'; + const selectorSwap = '0x12aa3caf'; + const selectorFillOrderTo = '0xe5d7bde6'; + const selectorFillOrderRFQTo = '0x5a099843'; + + +async function swapHelperForOneInch(oneInchData) { + + const functionSelector = oneInchData.slice(0, 10); + let func; + + switch (functionSelector) { + case selectorUnoswap: + func = 0; + console.log("UnoSwap function with ENUM", func); + break; + case selectorUniswapV3Swap: + func = 1; + console.log("UniSwapV3Swap function with ENUM", func); + break; + case selectorSwap: + func = 2; + console.log("Swap function with ENUM", func); + break; + case selectorFillOrderTo: + func = 3; + console.log("FillOrderTo function with ENUM", func); + break; + case selectorFillOrderRFQTo: + func = 4; + console.log("FillOrderRFQTo function with ENUM", func); + break; + default: + throw new Error("Unknown function selector"); + } + + return func; +} + +function removeSelector(oneInchData) { + // Assuming the selector is always 4 bytes (8 characters) + const slicedOneInchData = '0x' + oneInchData.slice(10); + return slicedOneInchData; +} + +const oneInchData = "0x12aa3caf000000000000000000000000e37e799d5077682fa0a244d46e5649f71457bd090000000000000000000000001af3f329e8be154074d8769d1ffa4ee058b1dbc30000000000000000000000008ac76a51cc950d9822d68b83fe1ad97b32cd580d000000000000000000000000e37e799d5077682fa0a244d46e5649f71457bd09000000000000000000000000b5d1e1ff700cfc0c687f1fc99284e94ab0ef63e50000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000dbd2a0fcefe0cc50000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008100000000000000000000000000000000000000000000000000000000006302a00000000000000000000000000000000000000000000000000dbd2a0fcefe0cc5ee63c1e581a47aca4dd3537d09e2b812aeee3bc7124921858a1af3f329e8be154074d8769d1ffa4ee058b1dbc31111111254eeb25477b68fb85ed929f73a9605820000000000000000000000000000000000000000000000000000000000000077d4f1b0"; + +// const oneInchData = "0xbc80f1a8000000000000000000000000b5d1e1ff700cfc0c687f1fc99284e94ab0ef63e500000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000033bf99bea351d680000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000057784919375274e60a49b6a0a0ae787de40e52b18b1ccac8" + +async function checkSwapFunction() { + console.log('\n') + await swapHelperForOneInch(oneInchData); + const pureOneInchData = removeSelector(oneInchData); + console.log('-----------------------------------------------------------------------------') + console.log('OneInchData without function signature / selector is generated:\n \n',pureOneInchData); + console.log('----------------------------------------------------------------------------- \n') + +} + +checkSwapFunction(); + From ba7eb3ed99a50b41b4b6034842a5698478c44070 Mon Sep 17 00:00:00 2001 From: Salman Haider Date: Wed, 3 Apr 2024 21:10:37 +0500 Subject: [PATCH 7/8] Same Network Swap --- contracts/multiswap-contracts/FiberRouter.sol | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/contracts/multiswap-contracts/FiberRouter.sol b/contracts/multiswap-contracts/FiberRouter.sol index fdaabb4..2ddb538 100644 --- a/contracts/multiswap-contracts/FiberRouter.sol +++ b/contracts/multiswap-contracts/FiberRouter.sol @@ -246,8 +246,9 @@ function swapOnSameNetwork( /** * @dev Performs a native currency swap and cross to another token on the same network using 1inch * @param amountOut The expected amount of output tokens after the swap on 1inch - * @param oneInchData The data containing information for the 1inch swap * @param toToken The token to receive after the swap + * @param targetAddress The receiver address for this token + * @param oneInchData The data containing information for the 1inch swap * @param funcSelector Enum parameter to identify the function for 1inch swap */ function swapOnSameNetworkETH( @@ -446,6 +447,7 @@ function _swapOnSameNetwork( * @param fromToken The token to be swapped * @param foundryToken The foundry token used for the swap * @param withdrawalData Data related to the withdrawal + * @param funcSelector selector enum for deciding which 1inch fucntion to call */ function swapAndCrossOneInch( uint256 amountIn, @@ -526,6 +528,7 @@ function _swapOnSameNetwork( * @param foundryToken The foundry token used for the swap * @param withdrawalData Data related to the withdrawal * @param gasFee The gas fee being charged on withdrawal + * @param funcSelector selector enum for deciding which 1inch fucntion to call */ function swapAndCrossOneInchETH( uint256 amountOut, // amountOut on oneInch @@ -624,6 +627,7 @@ function _swapOnSameNetwork( * @param foundryToken The token used in the Foundry * @param targetToken The target token for the swap * @param oneInchData The data containing information for the 1inch swap + * @param funcSelector selector enum for deciding which 1inch fucntion to call * @param salt The salt value for the signature * @param expiry The expiration time for the signature * @param multiSignature The multi-signature data @@ -695,6 +699,7 @@ function _swapOnSameNetwork( * @param amountIn The amount of input tokens to be swapped * @param amountOut The expected amount of output tokens after the swap * @param oneInchData The data containing information for the 1inch swap + * @param funcSelector selector enum for deciding which 1inch fucntion to call * @return returnAmount The amount of tokens received after the swap and transaction execution */ function swapHelperForOneInch( @@ -1013,6 +1018,7 @@ function _swapOnSameNetwork( * @param oneInchData The data containing information for the 1inch swap * @param fromToken The address of the input token for the swap * @param foundryToken The address of the token used as the foundry + * @param funcSelector selector enum for deciding which 1inch fucntion to call * @return FMAmountOut The amount of foundry tokens received after the cross-network transaction */ function _swapAndCrossOneInch( From 2427620b50b2214e1e349be65fe33648cd5c9564 Mon Sep 17 00:00:00 2001 From: Taha Abbasi Date: Thu, 4 Apr 2024 12:32:46 -0600 Subject: [PATCH 8/8] Gas Optimization and Same Network Swaps --- scripts/deploy/allowTarget.js | 115 ++++++ scripts/deploy/configContracts.js | 327 +++++++++--------- scripts/deploy/multiswap/deployFundManager.js | 7 +- 3 files changed, 283 insertions(+), 166 deletions(-) create mode 100644 scripts/deploy/allowTarget.js diff --git a/scripts/deploy/allowTarget.js b/scripts/deploy/allowTarget.js new file mode 100644 index 0000000..cb086a4 --- /dev/null +++ b/scripts/deploy/allowTarget.js @@ -0,0 +1,115 @@ +const { ethers } = require('ethers'); + +require('dotenv').config(); +const fundManagerABI = require('../../artifacts/contracts/multiswap-contracts/FundManager.sol/FundManager.json'); + +const fundManagerAddress = '0x5eBeF0bD015e4fAfe64172Ae00b9bB46a05906a7'; + +const foundryArbitrum = "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8"; +const foundryBinance = "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"; +const foundryEthereum = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; +const foundryOptimism = "0x0b2c639c533813f4aa9d7837caf62653d097ff85"; +const foundryAvalanche = "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E"; + +const optimismChainID = 10; +const AvalancheChainID = 43114; + +const ethProvider = 'https://nd-611-696-948.p2pify.com/8a54d0bc389e645253087fd1a6c5fe3a'; +const arbiProvider = 'https://nd-829-997-700.p2pify.com/790712c620e64556719c7c9f19ef56e3'; +const bscProvider = 'https://nd-049-483-298.p2pify.com/819ef21ecdd17a29a2ed1e856c7980ec'; + +async function main() { + // Assuming the command line arguments are: node allowTarget + // For Binance: node allowTarget.js bsc, + // For Aribtrum: node allowTarget.js arbitrum, + // For Ethereum: node allowTarget.js ethereum + + const networkArg = process.argv[2]; + + if (networkArg == 'ethereum') { + const provider = new ethers.providers.JsonRpcProvider(ethProvider); + const wallet = new ethers.Wallet(process.env.PRIVATE_KEY0 , provider); + + const fundManager = new ethers.Contract(fundManagerAddress, fundManagerABI.abi, provider); + + // Call allowTarget on FundManager with specified addresses + const targetAllowed = await fundManager.connect(wallet).allowTarget(foundryEthereum, AvalancheChainID, foundryAvalanche); + // Wait for the transaction receipt + const receiptTargetAllowed = await targetAllowed.wait(); + + if (receiptTargetAllowed.status == 1) { + console.log("ETHEREUM: AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + // Call allowTarget on FundManager with specified addresses + const targetAllowed2 = await fundManager.connect(wallet).allowTarget(foundryEthereum, optimismChainID, foundryOptimism); + // Wait for the transaction receipt + const receiptTargetAllowed2 = await targetAllowed2.wait(); + + if (receiptTargetAllowed2.status == 1) { + console.log("ETHEREUM: AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + } else if(networkArg == 'bsc') { + const provider = new ethers.providers.JsonRpcProvider(bscProvider); + const wallet = new ethers.Wallet(process.env.PRIVATE_KEY0 , provider); + + const fundManager = new ethers.Contract(fundManagerAddress, fundManagerABI.abi, provider); + + + // Call allowTarget on FundManager with specified addresses + const targetAllowed = await fundManager.connect(wallet).allowTarget(foundryBinance, AvalancheChainID, foundryAvalanche); + // Wait for the transaction receipt + const receiptTargetAllowed = await targetAllowed.wait(); + + if (receiptTargetAllowed.status == 1) { + console.log("BSC: AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + // Call allowTarget on FundManager with specified addresses + const targetAllowed2 = await fundManager.connect(wallet).allowTarget(foundryBinance, optimismChainID, foundryOptimism); + // Wait for the transaction receipt + const receiptTargetAllowed2 = await targetAllowed2.wait(); + + if (receiptTargetAllowed2.status == 1) { + console.log("BSC: AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + + } else if(networkArg == 'arbitrum') { + + const provider = new ethers.providers.JsonRpcProvider(arbiProvider); + const wallet = new ethers.Wallet(process.env.PRIVATE_KEY0 , provider); + + const fundManager = new ethers.Contract(fundManagerAddress, fundManagerABI.abi, provider); + + // Call allowTarget on FundManager with specified addresses + const targetAllowed = await fundManager.connect(wallet).allowTarget(foundryArbitrum, AvalancheChainID, foundryAvalanche); + // Wait for the transaction receipt + const receiptTargetAllowed = await targetAllowed.wait(); + + if (receiptTargetAllowed.status == 1) { + console.log("ARBITRUM: AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + // Call allowTarget on FundManager with specified addresses + const targetAllowed2 = await fundManager.connect(wallet).allowTarget(foundryArbitrum, optimismChainID, foundryOptimism); + // Wait for the transaction receipt + const receiptTargetAllowed2 = await targetAllowed2.wait(); + + if (receiptTargetAllowed2.status == 1) { + console.log("ARBITRUM: AllowTarget added successfully in FundManager!"); + } else { + console.log("Transaction failed"); + } + } + +} + +main(); \ No newline at end of file diff --git a/scripts/deploy/configContracts.js b/scripts/deploy/configContracts.js index 755836b..2c7c45b 100644 --- a/scripts/deploy/configContracts.js +++ b/scripts/deploy/configContracts.js @@ -12,7 +12,8 @@ const forgeManagerAddress = '0x1b94fe35B4303ec69de3617541002fFC9E4dDD36'; const multiswapForgeAddress = '0xe259f6D87c9b9331031f9D0AD2A000206eFC3149'; const fiberRouterAddress = '0x7A32c872619DFE0f07d04ef8EBEe77C5d0622c58'; -const fundManagerAddress = '0xbD9D99bb2A136a1936B87031c7A8102831855289'; +// const fundManagerAddress = '0xbD9D99bb2A136a1936B87031c7A8102831855289'; // Old +const fundManagerAddress = '0x5eBeF0bD015e4fAfe64172Ae00b9bB46a05906a7'; const foundryArbitrum = "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8"; const foundryBinance = "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"; @@ -50,37 +51,37 @@ async function main() { const provider = new ethers.providers.JsonRpcProvider(ethProvider); const wallet = new ethers.Wallet(process.env.PRIVATE_KEY0 , provider); - // Connect to ForgeManager and MultiswapForge contracts - const forgeManager = new ethers.Contract(forgeManagerAddress, forgeManagerABI.abi, provider); - const multiswapForge = new ethers.Contract(multiswapForgeAddress, multiswapForgeABI.abi, provider); +// // Connect to ForgeManager and MultiswapForge contracts +// const forgeManager = new ethers.Contract(forgeManagerAddress, forgeManagerABI.abi, provider); +// const multiswapForge = new ethers.Contract(multiswapForgeAddress, multiswapForgeABI.abi, provider); - // Connect to FiberRouter and FundManager contracts +// // Connect to FiberRouter and FundManager contracts const fiberRouter = new ethers.Contract(fiberRouterAddress, fiberRouterABI.abi, provider); const fundManager = new ethers.Contract(fundManagerAddress, fundManagerABI.abi, provider); // Call setWETH on FundManager with WETH address - const wethSet = await fiberRouter.connect(wallet).setWETH(wethEthereum); - // Wait for the transaction receipt - const receiptWethSet = await wethSet.wait(); +// const wethSet = await fiberRouter.connect(wallet).setWETH(wethEthereum); +// // Wait for the transaction receipt +// const receiptWethSet = await wethSet.wait(); - if (receiptWethSet.status == 1) { - console.log("WETH address added successfully in FiberRouter!"); - } else { - console.log("Transaction failed"); - } - - // Call setRouter on ForgeManager with WETH address - const wethForgeSet = await multiswapForge.connect(wallet).setWETH(wethEthereum); - // Wait for the transaction receipt - const receiptWethForgeSet = await wethForgeSet.wait(); +// if (receiptWethSet.status == 1) { +// console.log("WETH address added successfully in FiberRouter!"); +// } else { +// console.log("Transaction failed"); +// } + +// // Call setRouter on ForgeManager with WETH address +// const wethForgeSet = await multiswapForge.connect(wallet).setWETH(wethEthereum); +// // Wait for the transaction receipt +// const receiptWethForgeSet = await wethForgeSet.wait(); - if (receiptWethForgeSet.status == 1) { - console.log("WETH address added successfully in MultiSwapForge!"); - } else { - console.log("Transaction failed"); - } +// if (receiptWethForgeSet.status == 1) { +// console.log("WETH address added successfully in MultiSwapForge!"); +// } else { +// console.log("Transaction failed"); +// } - // Call setPool on FiberRouter with FundManager address +// Call setPool on FiberRouter with FundManager address const poolFundManagerSet = await fiberRouter.connect(wallet).setPool(fundManagerAddress); // Wait for the transaction receipt const receiptPoolFundManagerSet = await poolFundManagerSet.wait(); @@ -92,170 +93,170 @@ async function main() { } // Call setPool on MultiSwapForge with ForgeManager address - const poolForgeManagerSet = await multiswapForge.connect(wallet).setPool(forgeManagerAddress); - // Wait for the transaction receipt - const receiptPoolForgeManagerSet = await poolForgeManagerSet.wait(); +// const poolForgeManagerSet = await multiswapForge.connect(wallet).setPool(forgeManagerAddress); +// // Wait for the transaction receipt +// const receiptPoolForgeManagerSet = await poolForgeManagerSet.wait(); - if (receiptPoolForgeManagerSet.status == 1) { - console.log("Pool Forge Manager address added successfully in MultiSwap Forge!"); - } else { - console.log("Transaction failed"); - } +// if (receiptPoolForgeManagerSet.status == 1) { +// console.log("Pool Forge Manager address added successfully in MultiSwap Forge!"); +// } else { +// console.log("Transaction failed"); +// } // Call setOneInchAggregatorRouter on FiberRouter with oneInchAggregatorRouter address - const oneInchAddressSet = await fiberRouter.connect(wallet).setOneInchAggregatorRouter(oneInchAggregatorRouter); - // Wait for the transaction receipt - const receiptOneInchAddressSet = await oneInchAddressSet.wait(); +// const oneInchAddressSet = await fiberRouter.connect(wallet).setOneInchAggregatorRouter(oneInchAggregatorRouter); +// // Wait for the transaction receipt +// const receiptOneInchAddressSet = await oneInchAddressSet.wait(); - if (receiptOneInchAddressSet.status == 1) { - console.log("OneInch Aggregator address added successfully in FiberRouter!"); - } else { - console.log("Transaction failed"); - } +// if (receiptOneInchAddressSet.status == 1) { +// console.log("OneInch Aggregator address added successfully in FiberRouter!"); +// } else { +// console.log("Transaction failed"); +// } // Call setOneInchAggregatorRouter on MultiSwap Forge with oneInchAggregatorRouter address - const oneInchAddressForgeSet = await multiswapForge.connect(wallet).setOneInchAggregatorRouter(oneInchAggregatorRouter); - // Wait for the transaction receipt - const receiptOneInchAddressForgeSet = await oneInchAddressForgeSet.wait(); +// const oneInchAddressForgeSet = await multiswapForge.connect(wallet).setOneInchAggregatorRouter(oneInchAggregatorRouter); +// // Wait for the transaction receipt +// const receiptOneInchAddressForgeSet = await oneInchAddressForgeSet.wait(); - if (receiptOneInchAddressForgeSet.status == 1) { - console.log("OneInch Aggregator address added successfully in MultiSwap Forge!"); - } else { - console.log("Transaction failed"); - } - - // Call setRouter on FundManager with FiberRouter address - const routerSet = await fundManager.connect(wallet).setRouter(fiberRouter.address); - // Wait for the transaction receipt - const receiptRouterSet = await routerSet.wait(); +// if (receiptOneInchAddressForgeSet.status == 1) { +// console.log("OneInch Aggregator address added successfully in MultiSwap Forge!"); +// } else { +// console.log("Transaction failed"); +// } + +// // Call setRouter on FundManager with FiberRouter address +// const routerSet = await fundManager.connect(wallet).setRouter(fiberRouter.address); +// // Wait for the transaction receipt +// const receiptRouterSet = await routerSet.wait(); - if (receiptRouterSet.status == 1) { - console.log("Router added successfully in FundManager!"); - } else { - console.log("Transaction failed"); - } +// if (receiptRouterSet.status == 1) { +// console.log("Router added successfully in FundManager!"); +// } else { +// console.log("Transaction failed"); +// } // Call setRouter on ForgeManager with MultiswapForge address - const forgeSet = await forgeManager.connect(wallet).setRouter(multiswapForge.address); - // Wait for the transaction receipt - const receiptForgeSet = await forgeSet.wait(); +// const forgeSet = await forgeManager.connect(wallet).setRouter(multiswapForge.address); +// // Wait for the transaction receipt +// const receiptForgeSet = await forgeSet.wait(); - if (receiptForgeSet.status == 1) { - console.log("Forge added successfully in ForgeManager!"); - } else { - console.log("Transaction failed"); - } +// if (receiptForgeSet.status == 1) { +// console.log("Forge added successfully in ForgeManager!"); +// } else { +// console.log("Transaction failed"); +// } - // Call allowTarget on FundManager with specified addresses - const targetAllowed = await fundManager.connect(wallet).allowTarget(foundryEthereum, arbitrumChainID, foundryArbitrum); - // Wait for the transaction receipt - const receiptTargetAllowed = await targetAllowed.wait(); +// // Call allowTarget on FundManager with specified addresses +// const targetAllowed = await fundManager.connect(wallet).allowTarget(foundryBinance, ethereumChainID, foundryEthereum); +// // Wait for the transaction receipt +// const receiptTargetAllowed = await targetAllowed.wait(); - if (receiptTargetAllowed.status == 1) { - console.log("AllowTarget added successfully in FundManager!"); - } else { - console.log("Transaction failed"); - } +// if (receiptTargetAllowed.status == 1) { +// console.log("AllowTarget added successfully in FundManager!"); +// } else { +// console.log("Transaction failed"); +// } - // Call allowTarget on FundManager with specified addresses - const targetAllowed2 = await fundManager.connect(wallet).allowTarget(foundryEthereum, binanceChainID, foundryBinance); - // Wait for the transaction receipt - const receiptTargetAllowed2 = await targetAllowed2.wait(); +// // Call allowTarget on FundManager with specified addresses +// const targetAllowed2 = await fundManager.connect(wallet).allowTarget(foundryBinance, arbitrumChainID, foundryArbitrum); +// // Wait for the transaction receipt +// const receiptTargetAllowed2 = await targetAllowed2.wait(); - if (receiptTargetAllowed2.status == 1) { - console.log("AllowTarget added successfully in FundManager!"); - } else { - console.log("Transaction failed"); - } - - // Call addSigner on FundManager with signer address - const signerAdded = await fundManager.connect(wallet).addSigner(signerAddress); - // Wait for the transaction receipt - const receiptSignerAdded = await signerAdded.wait(); +// if (receiptTargetAllowed2.status == 1) { +// console.log("AllowTarget added successfully in FundManager!"); +// } else { +// console.log("Transaction failed"); +// } + +// // Call addSigner on FundManager with signer address +// const signerAdded = await fundManager.connect(wallet).addSigner(signerAddress); +// // Wait for the transaction receipt +// const receiptSignerAdded = await signerAdded.wait(); - if (receiptSignerAdded.status == 1) { - console.log("Signer added successfully in FundManager!"); - } else { - console.log("Transaction failed"); - } - - // Call addFoundryAsset on FundManager - const foundryAdded = await fundManager.connect(wallet).addFoundryAsset(foundryEthereum); - // Wait for the transaction receipt - const receiptFoundryAdded = await foundryAdded.wait(); +// if (receiptSignerAdded.status == 1) { +// console.log("Signer added successfully in FundManager!"); +// } else { +// console.log("Transaction failed"); +// } + +// // Call addFoundryAsset on FundManager +// const foundryAdded = await fundManager.connect(wallet).addFoundryAsset(foundryBinance); +// // Wait for the transaction receipt +// const receiptFoundryAdded = await foundryAdded.wait(); - if (receiptFoundryAdded.status == 1) { - console.log("USDC Foundry added successfully in FundManager!"); - } else { - console.log("Transaction failed"); - } - - // Call addFoundryAsset on ForgeManager - const forgeFoundryAdded = await forgeManager.connect(wallet).addFoundryAsset(foundryEthereum); - // Wait for the transaction receipt - const receiptForgeFoundryAdded = await forgeFoundryAdded.wait(); +// if (receiptFoundryAdded.status == 1) { +// console.log("USDC Foundry added successfully in FundManager!"); +// } else { +// console.log("Transaction failed"); +// } + +// // Call addFoundryAsset on ForgeManager +// const forgeFoundryAdded = await forgeManager.connect(wallet).addFoundryAsset(foundryEthereum); +// // Wait for the transaction receipt +// const receiptForgeFoundryAdded = await forgeFoundryAdded.wait(); - if (receiptForgeFoundryAdded.status == 1) { - console.log("USDC Foundry added successfully in ForgeManager!"); - } else { - console.log("Transaction failed"); - } - - // Call setGasWallet on FiberRouter with gasWallet address - const gasWalletAdded = await fiberRouter.connect(wallet).setGasWallet(gasWallet); - // Wait for the transaction receipt - const receiptGasWalletAdded = await gasWalletAdded.wait(); +// if (receiptForgeFoundryAdded.status == 1) { +// console.log("USDC Foundry added successfully in ForgeManager!"); +// } else { +// console.log("Transaction failed"); +// } + +// // Call setGasWallet on FiberRouter with gasWallet address +// const gasWalletAdded = await fiberRouter.connect(wallet).setGasWallet(gasWallet); +// // Wait for the transaction receipt +// const receiptGasWalletAdded = await gasWalletAdded.wait(); - if (receiptGasWalletAdded.status == 1) { - console.log("GasWallet added successfully in FiberRouter!"); - } else { - console.log("Transaction failed"); - } - - // Call addSigner on FundManager with signer address - const gasEstimationAddressAdded = await multiswapForge.connect(wallet).setGasEstimationAddress(gasEstimationAddress); - // Wait for the transaction receipt - const receiptGasEstimationAddressAdded = await gasEstimationAddressAdded.wait(); +// if (receiptGasWalletAdded.status == 1) { +// console.log("GasWallet added successfully in FiberRouter!"); +// } else { +// console.log("Transaction failed"); +// } + +// // Call addSigner on FundManager with signer address +// const gasEstimationAddressAdded = await multiswapForge.connect(wallet).setGasEstimationAddress(gasEstimationAddress); +// // Wait for the transaction receipt +// const receiptGasEstimationAddressAdded = await gasEstimationAddressAdded.wait(); - if (receiptGasEstimationAddressAdded.status == 1) { - console.log("Gas Estimation Address added successfully in MultiSwapForge!"); - } else { - console.log("Transaction failed"); - } - - // Call setLiquidityManagers on FundManager with liquidity manager addresses - const liquidityManagerAdded = await fundManager.connect(wallet).setLiquidityManagers(liquidityManager, liquidityManagerBot); - // Wait for the transaction receipt - const receiptLiquidityManagerAdded = await liquidityManagerAdded.wait(); +// if (receiptGasEstimationAddressAdded.status == 1) { +// console.log("Gas Estimation Address added successfully in MultiSwapForge!"); +// } else { +// console.log("Transaction failed"); +// } + +// // Call setLiquidityManagers on FundManager with liquidity manager addresses +// const liquidityManagerAdded = await fundManager.connect(wallet).setLiquidityManagers(liquidityManager, liquidityManagerBot); +// // Wait for the transaction receipt +// const receiptLiquidityManagerAdded = await liquidityManagerAdded.wait(); - if (receiptLiquidityManagerAdded.status == 1) { - console.log("Liquidity Managers added successfully in FundManager!"); - } else { - console.log("Transaction failed"); - } - - // Call setWithdrawalAddress on FundManager with liquidity withdrawal addresses - const withdrawalAddressAdded = await fundManager.connect(wallet).setWithdrawalAddress(withdrawalAddress); - // Wait for the transaction receipt - const receiptWithdrawalAddressAdded = await withdrawalAddressAdded.wait(); +// if (receiptLiquidityManagerAdded.status == 1) { +// console.log("Liquidity Managers added successfully in FundManager!"); +// } else { +// console.log("Transaction failed"); +// } + +// // Call setWithdrawalAddress on FundManager with liquidity withdrawal addresses +// const withdrawalAddressAdded = await fundManager.connect(wallet).setWithdrawalAddress(withdrawalAddress); +// // Wait for the transaction receipt +// const receiptWithdrawalAddressAdded = await withdrawalAddressAdded.wait(); - if (receiptWithdrawalAddressAdded.status == 1) { - console.log("Liquidity Withdrawal Address added successfully in FundManager!"); - } else { - console.log("Transaction failed"); - } +// if (receiptWithdrawalAddressAdded.status == 1) { +// console.log("Liquidity Withdrawal Address added successfully in FundManager!"); +// } else { +// console.log("Transaction failed"); +// } - // Call setSettlementManager on FundManager with Settlement Manager address - const settlementManagerAddressAdded = await fundManager.connect(wallet).setSettlementManager(settlementManagerAddress); - // Wait for the transaction receipt - const receiptSettlementManagerAddressAdded = await settlementManagerAddressAdded.wait(); +// // Call setSettlementManager on FundManager with Settlement Manager address +// const settlementManagerAddressAdded = await fundManager.connect(wallet).setSettlementManager(settlementManagerAddress); +// // Wait for the transaction receipt +// const receiptSettlementManagerAddressAdded = await settlementManagerAddressAdded.wait(); - if (receiptSettlementManagerAddressAdded.status == 1) { - console.log("Settlement Manager address added successfully in FundManager!"); - } else { - console.log("Transaction failed"); - } +// if (receiptSettlementManagerAddressAdded.status == 1) { +// console.log("Settlement Manager address added successfully in FundManager!"); +// } else { +// console.log("Transaction failed"); +// } } main(); \ No newline at end of file diff --git a/scripts/deploy/multiswap/deployFundManager.js b/scripts/deploy/multiswap/deployFundManager.js index 7543628..f042cb1 100644 --- a/scripts/deploy/multiswap/deployFundManager.js +++ b/scripts/deploy/multiswap/deployFundManager.js @@ -34,7 +34,8 @@ async function main() { // Compute a unique salt for deployment // const salt = ethers.utils.formatBytes32String(new Date().getTime().toString()); - const salt = "0x3137303931363530323534373000000000000000000000000000000000000000"; + // const salt = "0x3137303931363530323534373000000000000000000000000000000000000000"; + const salt = "0x3137313032363838383636353800000000000000000000000000000000000000"; // Latest Deployment console.log('Salt: ', salt); // Specify the owner address to which the ownership of the contract will be transferred @@ -47,8 +48,8 @@ async function main() { const fundManagerAddress = receipt.events.find((event) => event.event === 'DeployedWithData').args[0]; console.log("FundManager deployed to:", fundManagerAddress); - // Wait for 25 seconds before verification - await logCountdown(25); // This logs the countdown and waits + // Wait for 30 seconds before verification + await logCountdown(60); // This logs the countdown and waits console.log("Verifing..."); await hre.run("verify:verify", {